Author Topic: Running a clock in a controller without RTC  (Read 11317 times)

Offline 240glt

  • PLUS+1 Developer
  • ***
  • Posts: 35
  • Karma: +1/-0
Running a clock in a controller without RTC
« on: January 07, 2015, 01:22:10 PM »
We have a system with one display (with integrated hardware real time clock), and multiple controllers. What is the best way to keep a synchronized time in the other controllers when the display is off, but some of the other controllers are still running?

Consider that the display is sending the current date and time once a second when it is running.

How can the rest of the controllers (or at least one of them) keep the time when the messages from the display are stopped?

One thought was to just have separate counters for seconds, minutes, hours, days, months and years. With a one-second oscillator feeding the seconds counter, and the carry signal goes to the next counter. The problem is that that months have 28-31 days, and there are leap-years... So that will be complicated.

If there was possible to use the C or C++ functions for converting between a number of milliseconds since some epoch time and then back to a date, that would be simpler.

Someone have another idea? It is very useful for writing timestamped application logs in a machine when the machine is "off" but a least one controller is still running.

Offline Marbek_Elektronik

  • PLUS+1 Guru
  • *****
  • Posts: 352
  • Karma: +8/-0
    • Marbek Elektronik
Re: Running a clock in a controller without RTC
« Reply #1 on: January 07, 2015, 02:57:59 PM »
Real Time Clock is running with 10ppm.
If you use a controller, there will be a drift in time.
What is the time drift, you allow?

One simple way might be to use a small display like DP200 with a RTC on board?
Marbek Elektronik, Dipl.-Ing. Bernd Konrad
Dienstleistung, Entwicklung, Herstellung

Offline 240glt

  • PLUS+1 Developer
  • ***
  • Posts: 35
  • Karma: +1/-0
Re: Running a clock in a controller without RTC
« Reply #2 on: January 07, 2015, 04:30:05 PM »
Thanks for the answer Marbek,

My plan was to set the clock to the "display time" once a second, every time the controller receives a time message on the can bus. The display will probably be powered many times per day, so the total time the clock have to run "by itself" will almost always be less than 24 hours. The time should only be used to time-stamp logs, so some drift is OK.

Another display will add cost and complexity to the machine a little too much I think. Another option is to just count the time since last know time, like "2015-02-07 12:32:45 +18:21:02" Then I just have to count seconds, minutes and hours since last received time message. It will make the logs a bit harder to read, and, the worst: It will add many bytes to the limited application log memory.

Offline Marbek_Elektronik

  • PLUS+1 Guru
  • *****
  • Posts: 352
  • Karma: +8/-0
    • Marbek Elektronik
Re: Running a clock in a controller without RTC
« Reply #3 on: January 08, 2015, 08:46:54 AM »
Perhaps you can save a offset in your loggs?
You get the time from controller, then you logg the time without offset.
Then display is off for max. 1 24 hours.
Then you log the last time and the seconds (U32), which are maximum 86.400.
Or Time + h:min:sec.
Or you can add the actual time to offset and logg:
2015-01-08 + 26:33:25
if Display is running this would be:
2015-01-09 + 02:33:25
Marbek Elektronik, Dipl.-Ing. Bernd Konrad
Dienstleistung, Entwicklung, Herstellung

Offline spittet

  • PLUS+1 Guru
  • *****
  • Posts: 118
  • Karma: +6/-1
Re: Running a clock in a controller without RTC
« Reply #4 on: January 08, 2015, 03:17:16 PM »
Don't want to hijack your thread, by while we are on the RTC subject, does anyone can answer the following post?

http://www.plus1forum.danfoss.com/index.php?topic=748.msg2109#msg2109

Thanks!

Sam