Lets say I have a timed interrupt that occurs every 50 us that has some calculations that are done. While I am inside the ISR, does the timer until the next timed interrupt continue to tick?
If the interrupt is supposed to occur every 50 us, and it takes 20 us to execute the code inside the ISR, does the interrupt occur every 50us, or 70us (50+20)?
I have interrupts(); as the first line of the ISR by the way. The arduino is a due, and I am using the DueTimer library to generate the timed interrupts.
On the Uno unless you re-enable interrupts inside your ISR no other interrupts can run until you return
from the ISR. All pending interrupts will then be run in priority order. Only one pending interrupt of each
type can be queued in this way.
On the Due I think (IIRC) it allows higher priority interrupts to interrupt lower priority ones, but the mapping
of interrupt types to priorities is configurable (you'd have to delve about in the source to see what is
the standard config).
Timers generally are independent hardware from the processor, they just clock whatever else is going on
unless you power them down or explicitly reprogram them or sleep/reset the whole chip.
You would need to double-check the DueTimer library itself, because it might do something
different from what I'd expect and use a single-shot timer mode (its a while since I played with Due timers).
Calling interrupts() at the beginning of an ISR is often problematic - I'd advise against this unless you
know what "reentrant code" is and how to get it right.
The interrupt will occur every 50us as long as the ISR has finished before the next interrupt occurs. If the ISR takes 20us, no problem, unless some other kind of interrupt(s) can also occur. Then it gets messy.
Soronemus:
I have interrupts(); as the first line of the ISR by the way.
This is generally not recommended. The processor turns interrupts off for a reason.
Timers are hardware devices that continue to run, at least they do on the AVR processors. If you have interrupts off for too long you may miss an overflow interrupt generated by a timer.
el_supremo:
The interrupt will occur every 50us as long as the ISR has finished before the next interrupt occurs. If the ISR takes 20us, no problem, unless some other kind of interrupt(s) can also occur. Then it gets messy.
Pete
Thank you! I have benchmarked the time it takes to complete the ISR and I always make sure I have 20 or so microseconds of backup time to make sure things don't get messy.
While there are sometimes reasons to allow an ISR to be interrupted, when you do that the ISR's first line of code should be detecting if another copy of itself is already running. After checking that, then you can enable interrupts()