Timer Modules in pic16f877 microcontroller

To be a successful programmer and working with PIC16f877, we should need clear idea on timer modules in pic16f877 microcontroller. By using this internal timer which is inbuilt in pic16f877 IC, we can do lots of work quite easily. Basically in 16F877 microcontroller has three timer modules. Those are (1)      Timer 0  (2)       Timer 1   (3)      Timer 2

Now we need to know what are those timer0,timer1 and timer2? And how we can use them?

The Timer0 module is a 8-bit timer and counter. It consist 8-bit register for that and we can easily read and write the register. It triggers an interrupt when it overflows from FFh to 00h.

As like Timer0, Timer1 module is also timer and counter but it is 16-bit. Farther this 16-bit register is divided by two 8-bit registers

1)      TMR1H (H for Higher nibble)

2)      TMR1L  (L for Lower nibble)

The TMR1 Register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The Timer1 Interrupt is generated on overflow.

As like Timer0, The Timer2 is also an 8-bit timer but it has three special purpose register towork on. Those are

1)      prescaler,

2)      postscaler,

3)      period register.

Using the Prescaler and postscaler we can set user defined overflow time to different label with different overflow time. Timer2 is the PWM time-base when the CCP module(s) is used in the PWM mode.


Timer 0

Now we start some detail discussion on timer0 how it activated and work?

We can starts or stops Timer0 by the T0CS bit of OPTION_REG. After starting execution of timer0 the incremental signal comes to the TMR0 register based on the value selected for a prescaler. When TMR0 register is overflow, the T0IF flag is set to indicate the overflow. There are two ways to monitor the overflow event of TMR0 polling the T0IF flag and Triggering the Timer0 interrupt.

As I mention earlier that timer0 can start and stop by the T0CS bit of OPTION_REG. So to know about Timer0 we have to know abour OPTION_REG register. The main control action of OPTION_REG register is to assign a prescaler value to Timer0 and start/stop the timer. Clearing T0CS bit starts the timer increment based on the prescaler value, assigned by clearing PSA bit and selected by the PS2:PS0 bits.

Timer Modules in pic16f877 microcontroller

The only other file register take important part for the Timer0 module operation is INTCON register. INTCON register means Interrupt control register. From this INTCON register only we can understand the complete interrupt status of that system.

Timer Modules in pic16f877 microcontroller

Timer1 Module

As I discuss erlier

The TMR1 Register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The Timer1 Interrupt is generated on overflow if interrupt is enabled which is latched in the TMR1IF interrupt flag bit.

Timer1 can operate in one of three modes as

1) synchronous timer,

2) synchronous counter,

3) asynchronous counter.

 

The operation of Timer1 is controlled by T1CON register.

 Timer Modules in pic16f877 microcontroller

Timer2 modules

The Timer2 is also an 8-bit timer but it has three special purpose register towork on. Those are

1)      prescaler,

2)      postscaler,

3)      period register.

Using the Prescaler and postscaler we can set user defined overflow time to different label with different overflow time. Timer2 is the PWM time-base when the CCP module(s) is used in the PWM mode.

The operation of timer2 is controlled by T2CON register. In bellow find the bit pattern of T2CON register.

Timer Modules in pic16f877 microcontroller