14.02.2016

Timers and Tables for Prescalers

Table for concrete prescaler

Timers

Timer0

TCCR0B CS02 CS01 CS00 Prescaler
0x0 0 0 0 (TC stopped)
0x1 0 0 1 1
0x2 0 1 0 8
0x3 0 1 1 64
0x4 1 0 0 256
0x5 1 0 1 1024

Timer1

TCCR1B CS12 CS11 CS10 Prescaler
0x0 0 0 0 (TC stopped)
0x1 0 0 1 1
0x2 0 1 0 8
0x3 0 1 1 64
0x4 1 0 0 256
0x5 1 0 1 1024

Timer2

TCCR2B[b2:0] CS22 CS21 CS20 Prescaler
0x0 0 0 0 (TC stopped)
0x1 0 0 1 1
0x2 0 1 0 8
0x3 0 1 1 32
0x4 1 0 0 64
0x5 1 0 1 128
0x6 1 1 0 256
0x7 1 1 1 1024

 

Formulas

compare match register = [ 16,000,000Hz/ (prescaler * desired interrupt frequency) ] - 1

For 8 bit timers (e.g. 0 and 2 on atmega328)
TCNT_8bit = 255 - compare match register

For 16 bit timers (e.g. 1 on atmega328)
TCNT_16bit = 65535 - compare match register


References:
http://arduinomega.blogspot.cz/p/arduino-code.html
http://www.avrbeginners.net/architecture/timers/timers.html