"still on inaccurate timing"

Thread Starter

folorunsoa

Joined Aug 11, 2014
3
Thank you members for your posts. As stated in my previous thread, the timer source comprises 8Mhz Crystal with two 22pf ceramic capacitors connected to pins 13 & 14 of the PIC18F4550. I need an accuracy better than 1sec. in 10 days. For member timwhite, here is my setup timer code again:


//set_timer2(0);
//setup_timer_2(T2_DIV_BY_4,100,10);
//enable_interrupts(INT_TIMER2 );
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32); //1.0 s overflow
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RB );
enable_interrupts(global);

My initial setup was with timer2. This made my system to loose 10minutes daily. Then my trial with timer0 was worse with a loss of 60minutes daily. I would therefore prefer timer2 setup with an appropriate code.
Thank you.
folorunsoa
 

ErnieM

Joined Apr 24, 2011
8,377
What is your plan for timer 2? Forget the code, describe what you are doing in words.

What frequency goes in, how it gets divided, what frequenct comes out.

Next, ask yourelf: if 10 days have 864,000 seconds, what accuracy do I need to achieve 1 in 864,000?
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
That requires roughly 1 PPM (part per million) accuracy.

Standard PIC 8MHz xtals are likely to be only good to approx +/- 30 PPM.

So even with a xtal in the project it is still going to be maybe 30 times less accurate than desired.

The code examples on this page;
http://www.romanblack.com/one_sec.htm
use a long constant that can be adjusted in steps finer than 1 PPM so it can be tweaked with that one value in code to give accuracy close to 1 PPM.

Then the problem becomes the temperature coefficient of the xtal. They can vary >1 PPM from room temperature changes. Much worse than 1 PPm if used outdoors.

If you want a more accurate clock than a xtal I recently made a forum thread here;
http://forum.allaboutcircuits.com/showthread.php?t=99839
using an ebay $2 RTC module, that kept very accurate time right out of the box, and was tweakable.
:)
 
Top