View Single Post
Old 07-21-2013, 06:06 PM   #33 (permalink)
t vago
MPGuino Supporter
 
t vago's Avatar
 
Join Date: Oct 2010
Location: Hungary
Posts: 1,807

iNXS - '10 Opel Zafira 111 Anniversary

Suzi - '02 Suzuki Swift GL
Thanks: 829
Thanked 708 Times in 456 Posts
Quote:
Originally Posted by nickdigger View Post
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.
  Reply With Quote