Quote:
Originally Posted by nickdigger
Looking at this again, I thought cli also shuts off timers, thus preventing any undesired counter hijinks.
|
Nope. cli() only disables interrupts. The timers themselves will keep on going, with all that that implies.
For instance, say you disable interrupts inside MPGuino using cli(). Timer 2 is still merrily going on its way at 1/64th of the system clock, as it was configured. During the course of your routine, timer 2 overflows. It sets the overflow flag, but since interrupts are still disabled, your routine will continue to execute without any interruption. Once interrupts are re-enabled (via sei(), or restoring the SREG from a pre-cli() state), the timer 2 overflow interrupt will now fire.