I'm working on a project in which I need a series of very accurate pulses containing 2 shots in every pulse. The pulse should have 100µsec on time followed by 300ms off time. But when I'm programming the Arduino Due I'm getting random pulses of non-uniform width.But when I'm trying the same code in microsecond range I'm getting perfect wave. Here is the code that I'm using
#define LED 8 // Pin designated to give out the pulse
int cycles = 2; // No. of times you want it to give pulse
int high = 100; // High time in microseconds
int low = 300; // Low time in milliseconds
int i = 0;
int univ_cycle = 10;
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop(){
for (i ; i < univ_cycle; i ++){
pulse();
delay(100);
}
}
void pulse() {
// put your main code here, to run repeatedly:
for(int counter = 0;counter < cycles;counter++){
digitalWrite(LED, HIGH);
delayMicroseconds(high);
Serial.println("ontime");
digitalWrite(13, LOW);
Serial.println("offtime");
delay(low);
Serial.println(counter);
}
}
I would like to know how can I get the similar wave in microsecond also.