In this mode, the timer keeps on counting until the contents of TCNT1 become equal to those of OCR1A. In this mode, the timer counts up until it reaches to its maximum value $FFFF. Similarly when TCNT2 is equal to the OCR1B, the OCF2 flag will be set on the next timer clock. When TCNT1 is equal to OCR1A, OCF1 flag will be set on the next timer clock. There are two separate flags for each of the OCR registers which are independent of each other. Whereas there are two output compare registers are OCR1A and OCR1B. Similarly timer overflow registers are TOV1 & TOV2 respectively. Timer1 has also two timer/counter control registers termed as TCCR1A & TCCR1B. In above case, the register vales from D0 to D7 are called TCNT1L and the register values ranging from D8 to D15 are called TCNT1H. TCNT1L is lower byte whereas TCNT1H is higher byte. TCNT1H TCNT1L D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0Īs Timer1 is 16 bit registers, it is split up into two bytes. Timer1 is 16 bit timer which is shown below: and OCFn is called the output compare flag of any timer/counter. Here ‘n’ is the number of the timer like TCNT0, TCNT1 etc. Then the timer is cleared and the OCFn flag is set when the next clock occurs. This increment goes on until a stage comes when the contents of the TCNTn register become equal to the contents of OCRn. In other words, the content of the timer increases with each clock. When it turns from 0xFF to 0x00, a flag bit is set up and overflow occurs. 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.