Example Code

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

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

    Operating System

  • Windows

Code and Documents

Attachment

Description

This article explains what to do if your system clock appears to drift, especially when you are running a calculation intensive application for an extended period of time. Additionally, the article explains how you can read the RTC clock value directly from the system BIOS.

How to Use

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. 

With Windows you can 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

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, it is not possible 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

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors