Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Timing Deterministic Applications (Real-Time Module)

LabVIEW 2013 Real-Time Module Help

Edition Date: June 2013

Part Number: 370622L-01

»View Product Info

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  Some RT targets automatically disable the millisecond timing engine. For more information, refer to the RT target device documentation.
Note  The millisecond timing engine in versions prior to version 8.0 of the Real-Time Module had a 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. Refer to the KnowledgeBase for more information on this task.

Timing Control Loops Using the Real-Time Timing VIs

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.

Wait VI

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 illustration shows the timing of a real-time application using the Wait VI. The application executes Function A, executes Function B, and then uses the Wait VI to sleep 10 ms after the execution of Function B.

Wait Until Next Multiple VI

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 illustration 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 illustration, 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.

Defining the Order of Execution for Real-Time Timing VIs

Avoid using the Wait VI or Wait Until Next Multiple VI in parallel with other LabVIEW code, which can lead to unexpected timing behavior. Within a timed structure or a VI set to time-critical priority, only one thread is available, so the timing VI executes in sequence with the rest of the LabVIEW code despite being placed in parallel. In this case, LabVIEW serializes the parallel code paths while compiling the VI, and the execution order of the timing VI is subject to change from one compile to the next. On the other hand, when the code is not inside a timed structure or a time-critical VI, LabVIEW executes the timing VIs in parallel with the other LabVIEW code, which changes the effect of the timing VI.

To ensure well-defined timing behavior, use a Sequence structure to force a specific execution order. 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 next frame of the Sequence structure.

Timing RT Target VIs Using Timed Structures

A timed structure executes a subdiagram in a specific order with time bounds at a priority you specify. The priority setting of a timed structure specifies the priority of that timed structure relative to other timed structures executing on the target.

Caution  LabVIEW uses two separate but related priority schemes: VI priorities and timed structure priorities. Timed structure priorities are numeric, and a higher value represents a higher priority relative to other timed structures executing on the target. However, all timed structure priorities fall between the high and time-critical VI priority levels. To prevent undesired behavior, National Instruments recommends using only one priority scheme in your application. If the application uses timed structures, keep all VIs at normal priority.

Timed Loop

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.

Timed Sequence

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.

Timed Loop with Frames Structure

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.

Timing Deterministic Applications Using External Timing Sources

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.

Timing Real-Time Applications with NI-DAQmx

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:

  • Hardware-Timed Single-Point—NI-DAQmx supports hardware-timed, single-point sample mode in which samples are acquired or generated continuously using hardware timing and no buffering. You can use hardware-timed, single-point mode for control applications that require input and/or output within a deterministic period of time. Refer to the NI-DAQmx Single-Point Real-Time Applications topic of the NI-DAQmx Help for information about using hardware-timed, single-point operations to time your deterministic application.
  • Counter Timers—NI-DAQmx supports using hardware-timed counter input operations to drive a control loop. Use the Wait For Next Sample Clock VI to synchronize the counter operations with the counter's sample clock. Refer to the Hardware-Timed Counter Tasks topic of the NI-DAQmx Help for information about using counter input operations to time deterministic applications.
  • DAQmx Timing Sources for Timed Structures—Timed structures can be hardware-timed and are ideal for multirate applications. By default, timed structures use the 1 kHz clock on Windows or the real-time operating system of an RT target as a timing source. You also can use an external signal on a DAQ device as the timing source of a timed structure using NI-DAQmx. Use the DAQmx Create Timing Source VI to create a timing source that can synchronize the timed structure with the hardware clock. Refer to the Hardware-Timed Simultaneously Updated I/O Using the Timed Loop topic of the NI-DAQmx Help for information about using an external signal on a DAQ device to control a timed structure.

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.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit