Because of the preemptive nature of the real-time operating system (RTOS) on RT targets, deterministic tasks can monopolize the processor on the target. A deterministic task might use all processor resources and not allow non-deterministic tasks in the application to execute. After separating the deterministic tasks from non-deterministic tasks, you can use timing methods to ensure deterministic performance for deterministic tasks while allowing non-deterministic tasks to execute as needed.
You can use the Real-Time Timing VIs, timed structures, or external timing sources to time and control loop execution rates.
![]() |
Note The millisecond timing engine in versions prior to version 8.0 of the Real-Time Module had a 0.07% error. The 0.07% error affected the values returned by the Real-Time Timing VIs, Time functions (Tick Count, Wait, and Wait Until Next ms Multiple), and the Timed Loop. The millisecond timing engine for the Real-Time Module 8.0 and later no longer contains the 0.07% error. If you included code in your application to account for the 0.07% error, you must remove the code or enable the pre-Real-Time Module 8.0 behavior with a token in the ni-rt.ini file of an RT target. Add the following token to the section of the ni-rt.ini file of an RT target to enable the pre-8.0 behavior of the millisecond timing engine: [SystemSettings] LegacyTickTimerPeriod = TRUE |
![]() |
Note Some RT targets automatically disable the millisecond timing engine. For more information, refer to the RT target device documentation. |
Use the Real-Time Timing VIs, Wait and Wait Until Next Multiple, to time loops on RT targets. With the Real-Time Timing VIs, you can use the millisecond or microsecond timer of the RTOS running on an RT target to control the resolution of loops.
The Wait VI causes a VI to sleep for the specified amount of time. For example, you can use the Wait VI with Counter Unit set to milliseconds in a VI running on the RT target to provide loop rates up to 1 kHz. If the millisecond timer value of the RTOS is 112 ms when the Wait VI executes and the Count input equals 10, then the VI sleeps and does not return until the millisecond timer value equals 122 ms.
The following figure shows the timing of a real-time application using the Wait VI. The application in the figure executes Function A, executes Function B, and then uses the Wait VI to sleep 10 ms after the execution of Function B.

The Wait Until Next Multiple VI causes a thread to sleep until the value of the RTOS millisecond or microsecond timer equals a multiple of the Count input. For example, if the Wait Until Next Multiple VI executes with a Count input of 10 ms and the RTOS millisecond timer value is 112 ms, the VI that calls the Wait Until Next Multiple VI sleeps until the millisecond timer value equals 120 ms because 120 ms is the first multiple of 10 ms after the execution of the Wait Until Next Multiple VI.
The following figure shows the timing of a real-time application using the Wait Until Next Multiple VI. The application executes Function A, executes Function B, and then sleeps until the value of the RTOS millisecond timer equals a multiple of 20 ms, which is the time specified by the Count input of the Wait Until Next Multiple VI.

In the preceding figure, the time of execution for the Wait Until Next Multiple VI varies depending on the execution of Function A and B. When Function A and B finish executing, the Wait Until Next Multiple VI executes until the operating system timer reaches the next multiple of 20 ms.
Avoid using the Wait VI or Wait Until Next Multiple VI in parallel with other LabVIEW code. Because of the preemptive nature of the RTOS, LabVIEW executes the Real-Time Timing VIs and the other code in a serialized order. For example, if the Wait VI executes first, the whole thread sleeps and the code in parallel does not execute until the Wait VI returns.
You can use a LabVIEW structure to force a specific execution sequence, such as in the next example. In the following block diagram, the Wait Until Next Multiple VI causes the VI to sleep until the millisecond timer reaches a multiple of 100 ms. When the VI returns from sleep, the VI begins to execute the Acquire and Output Data VI. If you have other VIs running on the target at lower priorities, the RTOS executes those VIs while the application waits for the current VI to return from sleep.

A timed structure executes a subdiagram in a specific order with time bounds at a priority you specify. The higher the priority of a timed structure, the higher the priority the structure has relative to other timed structures and code on the block diagram. All timed structures execute at a priority relative to the LabVIEW execution system, between high and time-critical priority. To avoid priority inversions, National Instruments recommends using timed structures only in VIs set to normal priority.
A Timed Loop executes a subdiagram, or frame, each iteration of the loop at the period you specify. Use the Timed Loop when you want to develop VIs with multirate timing capabilities, feedback on loop execution, timing characteristics that change dynamically, or several levels of execution priority.
Use the Configure Timed Loop dialog box to configure a timing source, period, priority, and other advanced options for the execution of the Timed Loop.
Because of the preemptive nature of Timed Loops, they can monopolize processor resources. A Timed Loop might use all of the processor resources, not allowing other tasks on the block diagram to execute. You must configure the highest priority Timed Loop with a period large enough to perform the deterministic task and have idle time during every iteration to allow lower priority loops to execute. The following Timed Loop contains a subVI that performs a data acquisition for 50 ms.

The Timed Loop has a period of 100 ms that allows the loop to remain idle for 50 ms during each iteration. During the time when the Timed Loop remains idle, LabVIEW can execute lower priority tasks on the block diagram.
A Timed Sequence consists of one or more task subdiagrams, or frames, that execute sequentially and can be timed with an internal or external timing source. Use the Timed Sequence when you want to develop VIs with execution feedback, timing characteristics that change dynamically, or several levels of execution priority.
Use the Configure Timed Sequence dialog box to configure a timing source, priority, and other advanced options for the execution of the Timed Sequence.
You can add frames to a Timed Loop to execute multiple subdiagrams in sequence. A Timed Loop with frames behaves like a regular Timed Loop with an embedded Sequence structure.
The National Instruments drivers that run on RT targets support VIs or functions that can cause sleep in the current LabVIEW thread and then return when the driver detects a specific event. For example, you can use NI-DAQmx and NI data acquisition hardware to time real-time applications. Refer to the specific NI driver documentation for information about VIs or functions that you can use to sleep and wait for driver events.
You can use NI data acquisition hardware with NI-DAQmx to match loop rates to match the rate of the hardware clock. With NI-DAQmx, you can use the following methods to time real-time applications:
Refer to the NI-DAQmx Help for more information about timing control loops using NI data acquisition hardware and NI-DAQmx software. Select Start»All Programs»National Instruments»NI-DAQ»NI-DAQmx Help to display the NI-DAQmx help.