Using LabVIEW to Read the Real-Time Clock (RTC) Directly From BIOS

Updated Apr 5, 2018

Reported In

Software

  • LabVIEW

Issue Details

Sometimes my system clock appears to drift, especially if I'm running a calculation intensive application for an extended period of time. How do I read the RTC clock value directly from the system BIOS?
 

Solution

Windows allows you to access the RTC directly using port I/O calls. The attached VI will allow you to read the RTC clock value in LabVIEW. 

Additional Information

The system BIOS maintains two clocks. The RTC clock is powered by the small battery installed on your motherboard and the system clock is typically maintained by the BIOS itself. In most circumstances the BIOS copies the RTC value at system startup and uses this as the system clock value. In some cases the system clock can drift several seconds per day depending on the BIOS and motherboard make and model. 

Windows allows you to access the RTC directly using port I/O calls. The attached VI will allow you to read the RTC clock value in LabVIEW. 

Note:
Using this method too often will cause the RTC clock to drift very slightly since the act of reading it takes a certain amount of time. It would be inappropriate to use this method to read the RTC in a loop. It would also be inappropriate to use the RTC value to set the system clock. This would cause an even larger error in the RTC clock setting.

Also, there is no way to directly set the RTC clock value using port I/O. Setting the system time in Windows will automatically set the RTC clock to the new value. 

The attached .zip file contains versions of the example that will work with both LabVIEW 5.0 and 7.0