Shop OBEX P1 Docs P2 Docs Learn Events
how to keep accurate time without RTC? — Parallax Forums

how to keep accurate time without RTC?

Hey everyone,
is there a way to keep accurate time(a few seconds a day) without an RTC, with only an external crystal?
Also, is there a way to automatically set the clock to the current date/time on every upload?
Thanks!

Comments

  • kwinnkwinn Posts: 8,697
    tad4shi wrote: »
    Hey everyone,
    is there a way to keep accurate time(a few seconds a day) without an RTC, with only an external crystal?
    Sure. The time can be maintained by counting the system clock pulses using the cnt register or one of the counters.
    Also, is there a way to automatically set the clock to the current date/time on every upload?
    Thanks!
    That's a bit trickier. No option to do that as part of any loader I am aware of. The simplest method I can think of is to have the downloaded software wait for you to manually enter the time/date using a terminal program on the PC you are using to download the program.
  • The Abracon ASTMK-0.001 is a tiny 1µA, 50ppm MEMS oscillator that generates a 1Hz output, so the Propeller can count off the seconds even when running in RCslow mode at 20kHz. Kick back up to the main crystal for real work or communications. SiTime makes similar almost microscopic MEMS oscillators that get down to 5ppm accuracy.

    By "upload" do you mean when programming the propeller, or is it when uploading data from a Propeller to a comms link? If the latter, you can program the Propeller to accept a time string send over the same link.

  • Some Propeller loaders can set variables to values at upload time. That may be a way to smuggle in the time and date.

    Some languages have macros or other means to put the compile time into the code. That may be another trick to do this.

    And you can automagically (Makefile?) manipulate your code to set some variable to the date and time e.g. using `sed` or generate a small code snippet with some `printf` or `echo` commands to be included as object, include file, ... or whatever makes your compiler happy.

    I'm not rating which solution may be the best.
  • jmgjmg Posts: 15,140
    tad4shi wrote: »
    is there a way to keep accurate time(a few seconds a day) without an RTC, with only an external crystal?
    First, you need to define 'a few', and a temperature range.

    One Second a day, is ~ 11.6ppm, which is tighter than an average crystal, but it is possible to calibrate each boards crystal, and store that in EEPROM.
    eg a GPS 1pps signal can calibrate to fractions of a ppm
    That drops you to drift levels, over time and temperature, and for modest ambient changes I would say sub 10ppm is possible.


    tad4shi wrote: »
    Also, is there a way to automatically set the clock to the current date/time on every upload?
    Sure, many ways to do that.
    If you wanted no other code running, you could place a signature in the binary file like 'HH:MM:SS' immediately before your time variable.
    A special downloader variant would look for that 64b string signature, and patch in the next 32b with the current time + delay correction.
    When the Prop exits reset and finishes loading, it simply starts from that patched time value.

  • jmg wrote:
    When the Prop exits reset and finishes loading, it simply starts from that patched time value.
    But you'll have to apply a correction factor to account for the loading and resetting time. Otherwise, your "few seconds a day" will get used up in one gulp.

    -Phil
  • jmgjmg Posts: 15,140
    jmg wrote:
    When the Prop exits reset and finishes loading, it simply starts from that patched time value.
    But you'll have to apply a correction factor to account for the loading and resetting time. Otherwise, your "few seconds a day" will get used up in one gulp.
    Yup, which is why I wrote this :
    "and patch in the next 32b with the current time + delay correction."

  • C compilers on other mcu's have __DATE__ and __TIME__

    It will use the PC's (local time) of compile,
    it will not update if no changes was made to the file, so you would always have to click refresh on the file that uses it.

    So getting outside access to grab current time is better.
  • RaymanRayman Posts: 13,803
    This uses a cog to act as an RTC...
  • MIchael_MichalskiMIchael_Michalski Posts: 138
    edited 2018-09-28 17:54
    perhaps something like this

    https://datasheets.maximintegrated.com/en/ds/DS1672.pdf

    It uses a single 32khz crystal and a backup battery and communicates via I2C. Thats three extra components on your board.
Sign In or Register to comment.