Will interupts trigger during a delayMicroseconds() function?
If so, when the interupt sub routine returns to the delay, will it cut the delay short, or finish the delay at it's full duration.
Example:
delayMicroseconds() (10); //pause code for 10 microseconds
//pretend an interupt fired at 2 microseconds into the delay
// when the code returns from the interrupt, we should have 8 microseconds left on the delay
//will the interupt cause the rest of the delay to be dropped? resulting in only a 2 microsecond delay?
//if so, maybe it's better to have only 4microsecond delays per line so I get more accurate readings if it's going to be cropping my delays off???
note, I modified my post to say delayMicroseconds, since that is the funciton I'm specifically interested in.
My ISR has a few microsecond time stamps, 4 if then statements concerning how much time since a timestamp occured, and a few increment variables if that happened.
I haven't looked at the code but I would be surprised if interrupts were disabled in delayMicroseconds(). If that's the case an interrupt will lengthen the delay as you'll add the interrupt overhead + the length of the ISR.
For a 10uS delay the extra will be significant. If it's important then disable interrupts for the duration of the delay.
Yes, interrupts occur, and are processed, during delay functions.
When the ISR finishes, and returns, the code that was executing resumes executing where it left off. If a delay was in process, the delay will be resumed. The delay will end at the same time it would have if the interrupt had not occurred.
The only exception is if the time taken to process the interrupt takes longer than the time remaining in the delay.
If you have delayMicroseconds(10), and no interrupt, 10 microseconds will elapse before the function returns.
If, at 3 microseconds after the start of the delay, an interrupt occurs, and takes 5 microseconds to process, the remaining 3 microsecond delay will occur after the interrupt.
If the interrupt occurs after 7 microseconds of the delay, and takes 5 microseconds to process, the delay will end immediately after the interrupt is processed. Well, as close to immediately as the Arduino can determine that time is up, and execute a return.
I was not aware that micro() timestamps still increment during a ISR?
thank you so much, that is very helpful. for those interested, the project in question is my arduino based laser tag system, ircombat. google it if you want to follow or join the facebook group.
The code in question is an ocsillating function 4micro second on, 14microseconds off, to give a 56khz on/off pulse while transmitting. If the ISR only adds a microsecond or so, then it will not really be too much of a concern. the reason I want to try to re-enable interrupts, is so that you are not invincible during that 26millisecond pulse when shooting (10 rounds/second = 26% invincibility, or more if it cuts off part way through a hit!!!).
So delayMicroseconds() uses a timer so interrupts don't affect it. In that case the only time it will affect you is if the interrupt occurs right near the end of the delay and the ISR is running when the timer times out.
Question then, for very short durations does the delayMicroseconds code allow for the call overhead?