Timing and Synchronization in NI LabVIEW

Overview

Timing is an essential element to all test, control, and design applications and should be a key consideration in any system. Timing and synchronization technologies correlate events in time, which is necessary to perform coordinated activities. For software to orchestrate these coordinated activities, the program needs to be synchronized and have a concept of time. NI LabVIEW software has timing constructs inherent to the language that you can use to synchronize your software within your system.

LabVIEW Timing Under the Hood – Nanosecond Engine and NI-TimeSync

LabVIEW uses a software component called the nanosecond engine to keep track of time within a program. The nanosecond engine runs behind the scenes and interfaces to the OS to manage time. There are a variety of functions and structures in LabVIEW that use the nanosecond engine for time keeping, such as the Wait function and the Timed Loop structure. The nanosecond engine can use a local real-time clock (RTC) or it can be driven by an external reference clock integrated through the NI Time Sync Framework (NI-TimeSync) (Figure 1).

Figure 1. The LabVIEW nanosecond timing mechanism and NI-TimeSync coordinate to provide a clock for your application.

LabVIEW 2010 introduces a new clock available to NI-TimeSync. The IEEE Standard 1588 plug-in available with NI-TimeSync 1.1 provides a clock reference that is synchronized with 1 ms resolution. You can configure multiple devices on a network to use the same IEEE 1588 reference clock, allowing multiple platforms to synchronize over a standard Ethernet network. You also can configure your device to use the Software 1588 Precision Time Protocol with the NI Measurement & Automation Explorer (MAX) utility (Figure 2).

Figure 2. Configuration of Time Synchronization Source for Device from MAX

 

LabVIEW Timing Structures – Timed Loop

The Timed Loop is a looping structure that executes when the configured timing source has an event. It has a wide range of timing sources that are described later in this tutorial. Use the Timed Loop when you want to develop applications that require multirate processing, precise timing and synchronization, feedback on loop execution, timing characteristics that change dynamically, or several levels of execution priority. In addition to the tight timing characteristics of the Timed Loop, the structure can be used to assign processor affinity for multicore programming. Using the Timed Loop, you can specify a variety of timing attributes including the period, priority, deadline, offset, and timeout. With the combination of these attributes and the wide range of timing sources, you can create sophisticated applications regardless of the required timing constraints (Figure 3).

Figure 3. LabVIEW Timed Loop Structure for Executing Code with Timing Constraints

 

 

Timed Loop Timing Sources

A timing source controls the execution of a timed structure. You can select from three classes of timing sources: internal, software-triggered, or external (Figure 4).

 

Figure 4. Timing Sources for the Timed Loop Structure: Built-In Internal Timing Sources, Software-Triggered Sources, and External Sources

Internal Timing Sources

The internal timing source uses the nanosecond engine to keep track of time. You can configure the Timed Loop to use a 1 kHz clock or a 1 MHz clock on a supported real-time (RT) target. Using the 1 kHz clock, you can schedule a timed structure with millisecond resolution. All LabVIEW platforms that can run a timed structure support the 1 kHz timing source. Targets that support the 1 MHz timing source can schedule a timed structure with microsecond resolution. You also can configure the Timed Loop structure to use either of these built-in timing sources as an absolute time reference to start the structure execution using timestamps. For example, you can configure the Timed Loop to start at a precise time each day.

An additional internal timing source is the Synchronize to Scan Engine. This synchronizes the timed structure to the NI Scan Engine. Using this timing source, the timed structure executes at the end of each scan. The period between iterations corresponds to the Scan Period (µS) setting you configure on the NI Scan Engine page.

Software-Triggered Timing Sources

You can create a software-triggered timing source to trigger a timed structure based on a software-defined event. Use the Create Timing Source VI to create a software-triggered timing source. Use the Fire Software-Triggered Timing Source VI to programmatically trigger a Timed Loop controlled by a software-triggered timing source. You can use a software-triggered timing source as an RT-compatible event handler or to notify a consumer Timed Loop when new data becomes available in a producer-consumer application.

External Timing Sources

You can create external timing sources for controlling a timed structure with NI-DAQmx Version 7.2 or later. Use the DAQmx Create Timing Source VI to programmatically select an external timing source. You also can use several types of NI-DAQmx timing sources, including frequency, digital edge counter, digital change detection, and signal from task sources, to control timed structures. Use the DAQmx - Data Acquisition VIs to create the following types of NI-DAQmx timing sources to control a timed structure.

Frequency – Creates a timing source that causes a timed structure to execute at a constant frequency.

Digital Edge Counter – Creates a timing source that causes a timed structure to execute on rising or falling edges of a digital signal.

Digital Change Detection – Creates a timing source that causes a timed structure to execute on rising or falling edges of one or more digital lines.

Signal from Task – Creates a timing source that uses the signal you specify to determine when a timed structure executes.

Timing and Synchronization in LabVIEW

With language-inherent timing constructs, the nanosecond timing engine, and the Timed Loop structure, LabVIEW provides essential timing and synchronization functionality for your system. 

 

New to synchronization? Visit Achieving Synchronization to learn more.

Back to top