Welcome To Sculland.com

My Notes On The Atmel 8-bit AVR ATmega168 Microcontroller

Interrupts And Timers How to Control 30 LEDS With Only 6 Pins
Create Sounds Using A PC Speaker

Timers And Interrupts On The ATMEGA168 Microcontroller

There are three timers available to you on the ATmega168. There is one 16-bit timer, called Counter 1 and two 8-bit timers called Counter 0 and Counter 2. The 16-bit timer can count up from 0 to 65,535 (Which in Binary is 11111111 11111111). The 8-bit timers can only count up from 0 to 255 (Which in Binary is 11111111).

How To Setup The 8-bit Timers How To Setup The 16-bit Timers
Now For the Software End Of Things Timer Counting Speed Table
8-bit Timer Example - Use Software To Control A LED 16-bit Timer Example - Use Software To Control A LED
8-bit Timer Example - Use Hardware To Control A LED 16-bit Timer Example 2 - Use Software To Control A LED
Show All

Timer Counting Speed Table

How fast should the timer count, in relation to the clock speed of the microcontroller (Typically 8 MHz / 20 MHz)

Values for an 8 MHz clock

PrescalerDuration of one timer tickFrequency (timer ticks per second)Time until overflow 16-bitTime until overflow 8-bit
CLOCK_DIV_10.125 us ( 1 / 8000000 sec)8000.0000 kHz (8000000 / 1 Hz)8.192 ms0.032ms
CLOCK_DIV_81.000 us ( 8 / 8000000 sec)1000.0000 kHz (8000000 / 8 Hz)65.536 ms0.256ms
CLOCK_DIV_648.000 us ( 64 / 8000000 sec)125.0000 kHz (8000000 / 64 Hz)524.288 ms2.048ms
CLOCK_DIV_25632.000 us ( 256 / 8000000 sec)31.2500 kHz (8000000 / 256 Hz)2097.152 ms8.192ms
CLOCK_DIV_1024128.000 us (1024 / 8000000 sec)7.8125 kHz (8000000 / 1024 Hz)8388.608 ms32.768ms

Values for a 20 MHz clock

PrescalerDuration of one timer tickFrequency (timer ticks per second)Time until overflow 16-bitTime until overflow 8-bit
CLOCK_DIV_10.05 us ( 1 / 20000000 sec)20000.00000 kHz (20000000 / 1 Hz)3.2768 ms0.0128ms
CLOCK_DIV_80.40 us ( 8 / 20000000 sec)2500.00000 kHz (20000000 / 8 Hz)26.2144 ms0.1024ms
CLOCK_DIV_643.20 us ( 64 / 20000000 sec)312.50000 kHz (20000000 / 64 Hz)209.7152 ms0.8192ms
CLOCK_DIV_25612.80 us ( 256 / 20000000 sec)78.12500 kHz (20000000 / 256 Hz)838.8608 ms3.2768ms
CLOCK_DIV_102451.20 us (1024 / 20000000 sec)19.53125 kHz (20000000 / 1024 Hz)3355.4432 ms13.1072ms

References