For a recent long-term data logging application, we needed to ensure the reported data included an accurate time stamp so that it could be compared to data from other independent systems.

Over time any system clock can drift away from actual time. Depending on the hardware and operating system in use this can be seconds per day, which soon adds up over weeks and months.

A common solution to this is to connect to external internet based time servers and use their time to correct the local clock. These are called servers Network Time Protocol (ntp) servers.

Option 1. Periodic Corrections.

One solution is to regularly connect to a ntp server and correct your time accordingly.

This has been adopted by PCs which would only read the hardware real time clock on power up. The OS would then maintain current time using a software based timer which was not very accurate. This was fine for office PCs but not so good for industrial applications. Today Microsoft Windows gets around this problem by regularly trying to connect to internet time servers and adjusting the clock accordingly.

Such a method can be adopted on any LabVIEW Real Time target by writing LabVIEW code, example code can be found on the internet.

The problem with regularly connecting is that the clock will periodically jump if the connections are made infrequently. The LabVIEW application also must schedule the checks and manage the updates.

We required a solution where the clock was always accurate, so this was not a satisfactory solution.

Option 2. Use Linux ntp library.

An alternative method for Linux based targets is take advantage of their ability to run Linux daemons in parallel with your LabVIEW application.

Advantages are:

  1. Once installed it runs all the time in the background whenever the device is powered.
  2. You do not have to write any LabVIEW
  3. The service makes continuous micro corrections to the clock rather than only correcting periodically after connecting to the time server.
  4. Over time the service learns how much the clock is drifting by and will keep making the corrections even if it is missing connections to the time server.

The downside is that the setup and configuration requires multiple steps and some general knowledge of Linux.

Once running this will only make big corrections to the clock on power up, after that it will only make very small corrections at a time.

We used this method which is itself based on an example from the National Instruments Code Exchange.

For this to function correctly with summer and winter time you must use NI Measurement and Automation Explorer (MAX) to tell the target which time zone it is in. If in the UK must use GMT, If time zone is left at UTC if will not work.

Using the Linux library is a reliable and effective method for keeping accurate time on a National Instruments CompactRIO. For our project, it is maintaining accurate time on a data logging system operating in a remote location for periods of months at a time.