Timer interrupts – Arduino&stuff. This article will discuss AVR and Arduino timers and how to use them in Arduino projects or custom AVR circuits. What is a timer? Like in real life, in microcontrollers a timer is something you set to trigger an alert at a certain point in the future. When that point arrives, that alert interrupts the microprocessor, reminding it to do something, like run a specific piece of code. Timers, like external interrupts, run independently from your main program. Rather than running a loop or repeatedly calling millis(), you can let a timer do that work for you while your code does other things. So suppose you have a device that needs to do something –like blink an LED every 5 seconds.
How do timers work? Timers work by incrementing a counter variable known as a counter register. To increment the counter value at regular intervals, the timer must have a clock source. Since timers are dependent on the clock source, the smallest measurable unit of time will be the period of the clock. Timer0 Timer1.