"still on inaccurate timing"

Discussion in 'Embedded Systems and Microcontrollers' started by folorunsoa, Aug 25, 2014.

  1. folorunsoa

    Thread Starter New Member

    Aug 11, 2014
    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:

    //enable_interrupts(INT_TIMER2 );
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32); //1.0 s overflow
    enable_interrupts(INT_RB );

    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.
  2. NorthGuy

    Active Member

    Jun 28, 2014
    Are you sure you configured it to use crystal as a clock source?
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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: Aug 25, 2014
  4. NorthGuy

    Active Member

    Jun 28, 2014
    864,000 actually.
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Fixed. .
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    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;
    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;
    using an ebay $2 RTC module, that kept very accurate time right out of the box, and was tweakable.