RTC accuracy and settings


+ Reply to Thread
Results 1 to 15 of 15

Thread: RTC accuracy and settings17 days old

  1. #1
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default RTC accuracy and settings

    Most of the pic24's I used come with a 'free' RTC so I thought I would take advantage of that with some sensors that I'm using.

    In order to avoid data collisions I thought I would sync all my sensors to a central clock and then transmit their data at different times a few seconds apart.

    All the sensors have a unique number so they wake up every ten minutes triggered by an interrupt from the rtc then go back to sleep with the wdt enabled and an interval determined by the sensor number. This works very well and I thought I was home and dry.

    However I've realised that the rtc's accuracy is terrible, I can have them periodically update their rtc to keep them in sync but didn't really want to do that too often, I was thinking once a day or once a week but as it stands it would need to be every hour.

    I have the secondary oscillator enabled in the OSCCON register and in the fuses it is set to default power, have i missed something??

    Last night I set up a test and before I went to bed and by morning it had gained 200 seconds!

    Now I know that I can tune the rtc with the calibration register and I am indeed thinking of writing a routine to do this automaticaly when I sync the time but I didn't think the time would be so far off and I'd like to get any obvious schoolboy errors out of the way first.




    ...seconary osc uses a clock crystal (edit)
    Last edited by SimonJA; 22nd March 2020 at 11:31.

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    567
    Thumbs Up
    Received: 36
    Given: 26
    Total Downloaded
    4.47 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Simon,

    200 sec in less than 24 hours seems way over the top. Have you checked the clock crystal frequency? Duff crystal?

    Bob

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,318
    Thumbs Up
    Received: 80
    Given: 182
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Only as good as the clock.
    George.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Senior Member GAMBOA's Avatar
    Join Date
    Nov 2004
    Posts
    430
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    203.73 MB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    SimonJA,

    I use the PIC24JF64GA306 with RTC and 32768 kHz external crystal(EPSON TOYOCOM, PN:MC306-32.768KHZ) and the experience I have is very good. One drift less than 10 seconds in 6 months with the board without power and only with the 3V backup battery (CR1216).
    The precision of the RTC is given by the crystal and the working temperature.

    Regards,
    Gamboa

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Thanks for the replies.

    The crystal I have is an Abracon ABS07-120-32.768KHZ-T it is a pretty small smt package mounted close to the pic, it is a good spec with +/- 20ppm tolerance. I did try measuring the frequency and it measures 32.7635kHz though maybe measuring distorts things and would not be accurate, it's also shower and the rtc is gaining time.

    The crystal capacitors are supposed to be 6pF and I may have used something a little larger so I might change those and see if it makes any difference.

    Also I noticed some noise on the crystal lines caused by a radio module quite close by (868MHz) maybe that's adding a few false cycles? I could try testing with that off.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    I've also just noticed that I2C clock and data traces run close to the crystal on the underside of the board (my poor design), this is just a general development board that I was testing on and on the sensor boards I have a solid ground plane on the underside, maybe I will continue testing on those boards...

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Senior Member GAMBOA's Avatar
    Join Date
    Nov 2004
    Posts
    430
    Thumbs Up
    Received: 19
    Given: 0
    Total Downloaded
    203.73 MB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    SimonJA,
    Abracom is a good brand and 20ppm is good data.
    I have used 22pF capacitors. You can try other capacitor values to see if the drift changes.
    The radio doesn't seem very likely to cause the problem. You can remove power to the RF module and see what happens.
    Regards,
    Gamboa

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Junior Member david's Avatar
    Join Date
    Jan 2019
    Posts
    77
    Thumbs Up
    Received: 4
    Given: 1
    Total Downloaded
    174.52 MB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Hi,
    RTC crystals are usually tuning fork types but the same things apply to them. To get the rated frequency accuracy you must use the manufacturers specified loading capacitance and this also sets the crystal current and avoids the risk of hastened aging drift. Higher capacitance will produce higher crystal drive. The rated load capacitance also includes input capacitance and track strays.
    If the manufacturer only states the load capacitance (i.e. no accompanying circuit) then when they indicate 6pF load it usually means 2x 12pF capacitors less pin capacitance and strays (the load caps are effectively in series for the xtal) My guess is you would be looking at about 2x 8-10pF provided the tracks are short and direct.
    The fact that you are gaining time would seriously suggest that the input side to the oscillator, which is very high impedance, is being randomly spiked by data edges from adjacent tracks. A good fast edge will couple with almost no capacitance in to a high impedance input. I think you're already on to it and it may be worth trying some improvised shielding around the oscillator input to see if the timing is more accurate.
    Note also that the load capacitors should not be high dielectric disc types and ideally should be NPO SMT parts to avoid strange thermal drift.
    Good luck.

    Cheers,
    David

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Thanks David, I did a new test on a different board and that is much better laid out with the crystal rotated 45 degrees to the pic onto the corner pins with traces just over 1mm and the 0603 caps very close. The capacitors are 12pF on this board.

    Testing overnight again gave a drift of 2 seconds, not great but not terrible.

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Junior Member david's Avatar
    Join Date
    Jan 2019
    Posts
    77
    Thumbs Up
    Received: 4
    Given: 1
    Total Downloaded
    174.52 MB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Hi,
    That sounds much better. So that's about 23ppm? So hopefully that was now running slow?

    Cheers,
    David

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Yes it was running slow.

    I found a useful document Runtime Calibration of watch crystals (pdf). while I did get a bit lost on the procedures for calibration there is some interesting stuff in there.

    There's a graph showing how the crystal capacitors affect frequency (and it's quite a bit!). Before doing this little exercise I had thought that getting roughly the right capacitance was ok and once it was ticking over it was all down to the crystals own spec but that's not the case. Though it is possible to compensate for an incorrectly spec'd crystal with the calibration register.

    I tried another test adjusting the calibration (the RCFGCAL calibration bits). I think that 4ppm equates to 2 minutes a year (?) and I worked out I needed a value of 46 for the calibration bits, leaving it overnight it had perfect time in the morning!... but I'll leave it a bit longer.

    I'm not sure about setting the calibration bits, with my first attempt I set them at the beginning but when I read them in the main loop they were all cleared. Next I tried setting them in the main loop and that seemed to work but I assume they must be being reset at some point (reading the seconds register?). I really need to read up a bit more on that...

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,858
    Thumbs Up
    Received: 90
    Given: 34
    Total Downloaded
    4.60 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Another option is to put a small trimming variable cap in place of one of the fixed caps. Standard practice in ham radios in the good old days when we used crystals.
    John

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Junior Member david's Avatar
    Join Date
    Jan 2019
    Posts
    77
    Thumbs Up
    Received: 4
    Given: 1
    Total Downloaded
    174.52 MB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    Hi,
    With the 2x 12pf capacitors you will be somewhat over your specified 6pF xtal load due to pin capacitance and hence it will run a little slow. You could try 2x 10pF or even 10pF and 12pF. Just don't let the input/output capacitor ratio get too far from 1:1. I think you will find the right fixed values will give you a very reasonable accuracy but it's always a bit tricky estimating the pin capacitance and circuit strays so some trial and error is required. Avoid any measuring system that may present capacitance when trying to read the frequency. Putting the output through a divider stage or buffer will isolate it but at this frequency even a few k of resistance will work if connected closely to the output pin. Better still you could write a software divider driving a LED and compare it to some known time signals. Good luck with the project.

    Cheers,
    David

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,318
    Thumbs Up
    Received: 80
    Given: 182
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    If you want accurate time nothing beats GPS. The Blox modules are cheap as chips.
    George.

  28. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  29. #15
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    839
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: RTC accuracy and settings

    If you want accurate time nothing beats GPS. The Blox modules are cheap as chips.
    I do in fact use a gps module as the main clock source that all the sensors sync with but it would not be practical to put one on each sensor.

    I just need to be able to keep reasonably accurate time on the sensors for a day.

  30. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Math accuracy
    By John Drew in forum Proton 24
    Replies: 6
    Last Post: 28th November 2013, 13:20
  2. [SOLVED !] accuracy timing
    By Yoepieyoep in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 24th February 2009, 22:19
  3. NE555 Accuracy?
    By Darlington in forum The Lounge
    Replies: 12
    Last Post: 15th January 2009, 11:28
  4. Accuracy of Float calculations
    By John Drew in forum Wish List / Product Feedback
    Replies: 33
    Last Post: 7th January 2007, 14:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts