Hi,
did anyone solve the problem DUE problem with micros() inside interrupts - Arduino Due - Arduino Forum? I think I have a similar problem.
I use the Due to generate triggered pulses on an output pin, either using a deayMicroseconds() in an interrupt, or by reading out micros() in the interrupt and changing output pins in the loop when micros()> storedTime.
While most pulses are accurate (observed with an oscilloscope), a fraction of pulses are actually much shorter (down to few microseconds) than the delay time.
The same code works fine with a Mega2560, same problems on another Due.
I used a function generator to trigger the interrupts, the pulses measured with an oscilloscope, I attach an image of the oscilloscope screen. A sample code based on blink is attached below.
If anyone has an idea, that would really help me.
Thanks a lot!
Jonas
The code:
int led = 12;
void setup() {
pinMode(led, OUTPUT);
attachInterrupt(2,blinking,RISING) ;
}
void loop() {
}
void blinking()
{
digitalWrite(led, HIGH);
delayMicroseconds(75);
digitalWrite(led, LOW);
delayMicroseconds(75);
}