AVR Timer Programming

Posted on at


Counter mode and Timer mode:

1) There are counter registers in microcontrollers to count an event or generate time delays.
 
2) When we connect the external event source to the clock pin of the counter register. This is counter mode.
 
3)  When we connect the oscillator to the clock pin of the counter. This is timer mode.
 
4) One way to generate a time delay is to clear the counter at the start time and wait until the counter reaches a certain number.
 
5) In the microcontrollers, there is a flag for each of the counters. The flag is set when the counter overflows, and is cleared by software.
 
6) The second method to generate a time delay is to load the counter register and wait until the counter overflows and the flag is set.
 
7) In ATmega32,ATmega16, there are three timers: Timer0, Timer1, and Timer2. TimerO and Timer2 are 8-bit, while Timer1 is 16-bit.
 
8) In AVR, for each of the timers, there is a TCNTn (timer/counter) register. In ATmega32 we have TCNTO, TCNT1, and TCNT2.
 
9) The TCNTn register is a counter. Upon reset, the TCNTn contains zero. It counts up with each pulse. The contents of the timers  and counters can be accessed using the TCNTn. You can load/read a value into the TCNTn register.
 
 
 


About the author

furqan-azam

Name: Furqan Azam
Education: BS electronic engineering (In Progress)
Profession: : freelance writer and blogger.
Hobby: Coins Collection.
I am crazy about playing video games like FIFA 14.

Subscribe 0
160