Microcontroller tutorial series: AVR and Arduino timer interrupts
Does your program seem like it’s trying to do too much at once? Are you using a lot of delay() or while() loops that are holding other things up? If so, your project is a good candidate to use timers. In this tutorial, we’ll discuss AVR and Arduino timers and how to use them to write better code. In our prior article, we covered interrupt basics and how to use external interrupts that are triggered by a pin change or similar event. Check it out if you’re looking to brush up on interrupts in general. This chapter moves on to timer interrupts and talks about their applications in Arduino projects or custom AVR circuits. What is a timer? You’re probably familiar with the general concept of a timer: something used to measure a given time interval. The beauty of timers is that just like external interrupts, they run asynchronously, or independently from your main program. For example, say you’re building a security robot. How do timers work? Our timer resolution is one millionth of a second.