 Hello, Myself Ravindra Chavan, Assistant Professor, Department of Electronics Engineering, Walshand Institute of Technology, Solapur. In this session, we will see how timer 0 in peak 16F877 operates and how it can be implemented in different applications. At the end of this session, student can demonstrate the operation of timer 0 in peak 16F877. Also student can be able to implement the timer 0 in different applications. Outline of this session, the timers in peak 16F877 microcontrollers, the special function registers associating with the operation of timer 0 and the operation of timer 0. In peak 16F877 controller, there are three timers called timer 0, timer 1, timer 2. The timer 0 is the 8-bit timer and counter. Timer 1 is the 16-bit timer and counter. Timer 2 can be used only as an 8-bit timer. In this session, we will focus on the timer 0. The major features of the timer 0 are the first, it is the 8-bit timer slash counter. Hence the timer 0 can be used either as a timer or as a counter. The timer can operate in timer mode to get the required time delay. Counter mode can be used to count the some external events. The timer 0 register can be read also one can write it. Timer 0 register is having its 8-bit programmable pre-scaler. This pre-scaler is to be used to get the more amount of delay with the same clock frequency and same initial count. For timer 0, one can select either internal clock or external clock. When timer register overflows from ff to 00, the interrupt can be occurred. Also there is a facility to select the active edge for the external clock. The registers associated with the timer 0. The first register is named as tmr0 which is called the timer 0 register. Each can be read as well as which can be write. Now the timer 0 register is to be initialized with the initial count value. And this register increments in every instruction cycle in timer mode and increments either on every rising edge or falling edge of the clock applied on pin RA4 slash timer 0 clock input in counter mode. Means the timer 0 register operates on internal clock in timer mode and it operates on external clock in counter mode. Then the option register is to be used to control the operation of timer 0. This is the bit format defined for option register. Now out of these 8 bits, the lower 6 bits are associated with the timer 0. The timer 0 source clock select bit that is t0cs is to be used to decide either timer mode or as a counter mode. If we make this bit 1, the timer register will increment on the clock applied on the pin RA4 slash timer 0 clock input. If t0cs bit is reset that is it is 0, then the timer will operate on internal clock. So internal clock is to be used for the timer mode and external clock is to be select for the counter mode. But t0se bit which is called the source edge select bit. Now this is associating with the external clock. If you have selected the external clock that is the counter mode then one can decide the active edge of this clock. If t0se bit is 1, then timer will increment on high to low transition on the clock on timer 0 clock input. If this bit is 0, then timer will increment on low to high transition on the clock on timer 0 clock input pin. PSA bit is called the pre-scaler assignment bit. So in peak 16f877, the same pre-scaler can be assigned either to the timer 0 or to the watchdog timer. Now if we set the PSA bit, then pre-scaler is assigned to the watchdog timer. And now to assign the pre-scaler to the timer 0, reset the PSA bit. This pre-scaler is mainly used to get the more amount of delay. Now PS2 to PS0 these are called the pre-scaler rate select bits. Now operation of timer 0. Now timer 0 is increment either on every instruction cycle or on external clock at the pin RA4 slash timer 0 clock input pin. Now you pause the video and think how to select timer mode and counter mode of timer 0. Now to select the timer mode or counter mode, use timer 0 clock select bit from option register. Now to select the timer mode, make TOCS 0. And when we set the TOCS bit, it will select the counter mode means the timer will operate on either rising edge or falling edge of the external clock. Now this is the block diagram which shows the operation of timer 1. Now in this here you see this first multiplexer. Now this first 2 has to 1 multiplexer which is controlled by the timer 0 source select bit. Now this bit is to be this multiplexer is used to select either the internal clock which is the oscillator frequency divided by 4 or the external clock. Now when TOCS bit is 0, it will select the internal clock. When TOCS bit is 1, it will select the external clock. And this XOR gate is used to select either rising edge or falling edge of the external clock which is controlled by the timer 0 source edge select bit. Now this second multiplexer is used either the pre-scaled clock which is nothing but the output from the pre-scaler if pre-scaler is assigned to the timer 0 or the unpre-scaled clock which is either internal clock or external clock. And this multiplexer is controlled by the PSA bit. Since if PSA is 0, the pre-scaler is assigned to the timer 0, if PSA is 1, it will assign to the watchdog timer. Then the delay of 2 cycles is provided for the synchronization purpose and whatever the clock goes to the timer 0 register on that the timer 0 will increment. So during each clock period timer 0 register will start increment and goes up to its maximum value FF. When this register rolls over from FF to 00, then it will set the flag called timer 0 interrupt flag and whatever the delay is chosen that delay will be expired. Now to implement the timer 0, you follow these steps. First select timer or counter mode using timer 0 clock select bit from option register. Then use TOAC bit to select the edge for external clock. Use PSA bit to assign the pre-scaler to the timer 0 or PS2 to PS0 bit to decide the pre-scaler rate. Put the initial count in timer 0 register. Then timer 0 will increment and when timer 0 rolls over from FF to 00, then timer 0 interrupt flag will be set. References used for this the peak 16 of 877 datasheet and the microcontrollers by Ajay Deshmukh. Thank you.