Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 

That system automatically factors in all overheads AND self corrects them.

But for clocks it's main beauty is that the 1 second is derived from a single value constant, so you can just "tweak" that one constant to perform any xtal compensation you like, for example adding a few parts per million to make the clock more accurate.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top