Timer0 on PIC's

Status
Not open for further replies.

Hesam Kamalan

New Member
Hi,
Since I am beginner in PIC microcontrollers, I have a question for Timer0. in some PIC's for example 16F877, for enable and stop of timer1 we have TMR1ON in T1CON register. But I want to use timer0, but I do not know how can I start or stop timer0. Guide me which register have TMR0ON, Please.
Have lovely times
 
The peculiarity is that TMR0 is ALWAYS counting upwards.

Basically the situation that has any meaning for you is when it overflows and from 255 starts counting from 0 again.

Reread the datasheet with that in mind.
 
You might also consider using a more modern counter?, tmr0 is fairly limited, and presumably only included for backwards compatibility?. Tmr2 is generally much more useful and easier to use.
 
I agree with Nigel that Timer 2 is much easier to use with a lot more capability. You simply setup the TMR2 prescaler, postscaler, and PR2 period registers in your Main program for a "set and forget" timer source for interrupts.

By comparison, I had to use TMR0 recently to provide 104-usec interrupts for bit-banged serial I/O on a 12F675. Since TMR0 is free running, I had to add a value (256-104+2) to the TMR0 register during each interrupt cycle in order to maintain correct 104-usec interrupt timing. The ISR code below from my 12F675 demo simply isn't needed when using TMR2 (on a device that has a TMR2 module).
Code:
;
;  clear TMR0 interrupt flag, prep TMR0 for next interrupt
;
ISR_SET bcf     INTCON,T0IF     ; clear TMR0 interrupt flag       |B0
        movlw   -d'104'+2       ; setup for next 104-usec int     |B0
        addwf   TMR0,f          ;                                 |B0
;
I should mention TMR0 has one signicant advantage over the other timers when it's being used as an asynchronous counter or Frequency counter. It can clock external asynchronous signals with a period as short as 20-nsecs (50-MHz) with it's prescaler enabled. The other timers when used as asynchronous counters only handle up to about a 16-MHz input signal.

Regards, Mike
 
Actually there may be a way to turn off TMR0 (stop counting internal clock cycles) but I'm not sure it's all that practical.

Simply toggle the T0CS TMR0 Clock Source Select bit in OPTION_REG between Internal Clock Source and External T0CKI Clock Source. You should probably leave the T0CKI pin configured as an output.

Mike
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…