


It keeps on counting until it reaches its maximum value of 0xFF. In normal mode, the content of the timer or counter is increased with each clock. Here the contents of OCRn are compared with the contents of TCNTn. It is used for setting up the modes of the timer.Another register of the timer is OCRn which is named as “Output Compare register”. These timers have also Timer/Counter Control Register. The TOVn flag is set when the timer overflows, where ‘n’ is the any number of a timer. We can read or load any value in the TCNTn register.Each of the timer has TOV called Time Overflow. For example, In Atmega32 we have TCNT0, TCNT1 and TCNT2. There is a TCNTn called timer/Counter Register for each of the timers in AVR. This expression is illustrated in the following diagram. In other words, the content of the register becomes $00 and the flag is set. In this case, after the first tick the content of the clock register increases to $FF and after the second tick it overflows. For example, in a microcontroller with a frequency of 1MHZ using 8-bit counter register, if we need a time delay of 2 seconds we just have to load the counter register with $FE and wait until the flag is set. The other technique to generate time delays is to load the counter register and wait for the time when the overflow of the counter takes place and flag is set. When the counter overflows the flag is set. There is also a flag for each counter in the microcontrollers. We can easily calculate the tick period as the speed of oscillator is known and we will recognize how much time has been over and done from the content of the register. This shows that how many ticks have been occurred when cleared the counter.

This results an increment in the content of the counter when an oscillator ticks. Now if we want to generate time delays then we can connect the oscillator to the clock pin of counter register. This increment shows that how many times an event has occurred. The content of the counter is incremented when an event is occurred. Timers can be used to generate time delays or as a counter to count events.If we want to use timer as counter then we can join the external source to the clock pin of counter register. Modes of operation of timers Timers of AVR microcontroller.
