1

Generally you can set system clock using http://linux.die.net/man/1/date. However, it doesn't supply millisecond precision (it does have nanoseconds, but this isn't working on my system). Is there another way to set system clock, or will I need to write a C program to do it?

3 Answers 3

2

If ntpd is to heavy for you, try OpenNTPD. It doesn't claim to be sub-microsecond accurate, but does keep my servers' clocks in sync, below a milisecond's range of drift. It uses sntp, which is also a bit more lightweight.

As others have said, hardware clocks do drift, you can't just set them and be fine.

2

You should use ntpd which will keep your system accurate by syncing with time servers using NTP (Network Time Protocol).

2
  • Generally a good idea, but not in my case (an embedded system which can only talk to its own server). Nov 15, 2010 at 8:14
  • 1
    @Alexey Romanov Its own server can be NTP server for the device since same program can act as server and client. This way you could have a stratum 3 device which is very precise.
    – AndrejaKo
    Nov 15, 2010 at 8:51
1

Even if the embedded system in question doesn't support NTP, you're going to have to implement something a lot like it, or execute your C program pretty frequently, in order to counter the inevitable drift of the two clocks. Plus, your C program will have to account for its own execution time and the latency of the connection between the two computers (embedded system and server), particularly as sub-microsecond precision is what you need.

It may be quicker for you to find a ntpd instance you can configure between the two systems. The tools for this are always present in modern real-time operating systems (for some definition of "always").

1
  • 1. Sorry, millisecond (as in title), not microsecond. 2. Yes, I do take latency into account. Nov 15, 2010 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .