Timers are standard features of almost every microcontroller. So it is very important
to learn their use. Since an AVR microcontroller has very powerful and multifunctional
timers, the topic of timer is somewhat “vast”. Moreover there are many different
timers on chip. So this section on timers will be multipart. I will be giving basic
What is a timer ?
A timer in simplest term is a register. Timers generally have a resolution of 8 or 16
Bits. So a 8 bit timer is 8Bits wide so capable of holding value withing 0-255. But this
register has a magical property ! Its value increases/decreases automatically at a
predefined rate (supplied by user). This is the timer clock. And this operation does
not need CPU’s intervention.
Since Timer works independently of CPU it can be used to measure time accurately.
Timer upon certain conditions take some action automatically or inform CPU. One of
the basic condition is the situation when timer OVERFLOWS i.e. its counted upto its
maximum value (255 for 8 BIT timers) and rolled back to 0. In this situation timer
can issue an interrupt and you must write an Interrupt Service Routine (ISR) to
handle the event.
Using The 8 BIT Timer (TIMER0)
The ATmega16 and ATmega32 has three different timers of which the simplest is
TIMER0. Its resolution is 8 BIT i.e. it can count from 0 to 255.
Please read the “Internal Peripherals of AVRs” to have the basic knowledge
of techniques used for using the OnChip peripherals(Like timer !)
8 BIT Counter Register
Timers - Introduction
AVR Tutorial Series
CPU Notified of Over Flow
The Prescaler is a mechanism for generating clock for timer by the CPU clock. As you
know that CPU has a clock source such as a external crystal of internal oscillator.
Normally these have the frequency like 1 MHz,8 MHz, 12 MHz or 16MHz(MAX).