TMR2 Very Accurate 1Second Routine

Status
Not open for further replies.

Suraj143

Active Member
Can somebody tell me how to do an accurate 1 second timing using TMR2.I’m using 4Mhz crystal.

Mike,K8LH is doing a nice error correction routine …………….Can somebody explain this to me.

No need code I can write.I need the idea how to do.

Thanks
 
Last edited:
When I use Timer2, I tend to setup a 10mS period and count 100ths of a second. To do this you set timer2 to prescaler=4, postscaler=10 and pr2=250. This gives a period of 4*250*10=10,000uS = 10mS.

Mike.
 
When I use Timer2, I tend to setup a 10mS period and count 100ths of a second. To do this you set timer2 to prescaler=4, postscaler=10 and pr2=250. This gives a period of 4*250*10=10,000uS = 10mS.

I agree, 10mS is a nice handy figure, and can also be used for display multiplexing.
 
Ok Guys thanks for the replies.

Is the above method good for a clock?

I'm going to use for my clock.
 
Last edited:
You have to fator-in the interrupt handler overhead.

For the program you are suggesting, the handler takes 16 bytes and is executed every 256 cycles.
 
You have to fator-in the interrupt handler overhead.

For the program you are suggesting, the handler takes 16 bytes and is executed every 256 cycles.

Timer2 is self running, you don't touch it in the ISR - that's why you use timer2.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…