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:

Pommie

Well-Known Member
Most Helpful Member
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.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
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.
 

Suraj143

Active Member
Ok Guys thanks for the replies.

Is the above method good for a clock?

I'm going to use for my clock.
 
Last edited:

colin55

Well-Known Member
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.
 

Mr RB

Well-Known Member

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.

EE World Online Articles

Loading
Top