From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
NI-DAQmx supports hardware-timed single point sample mode in which samples are acquired or generated continuously using hardware timing and no buffer. Hardware-timed single point mode is commonly used on LabVIEW Real-Time platforms for control applications which require input and/or output within a deterministic period of time. In order to check if the software operations are keeping up with the hardware timing, it is necessary to do lateness checking. Changes introduced in NI-DAQmx 7.4 provide increased flexibility when performing hardware-timed single-point operations on real-time platforms. In NI-DAQmx 7.4 and later there are three options for lateness checking:
1) Strict Lateness Checking (Wait For Next Sample Clock)
2) FIFO Overflow Lateness Checking (Report Missed Samples)
3) No Lateness Checking
This tutorial briefly explains the three lateness checking modes and contains sample applications that demonstrate new functionality in NI-DAQmx 7.4. The applications are based on requirements common to real-time applications using single-point NI-DAQmx tasks. These samples are drawn from a basic set of example implementations meant to aid in the design of more complex applications. The examples pertain to control applications but are applicable to other single-point applications such as hardware-in-the-loop, event response tasks, and in-line signal manipulation.
Each application case contains a proposed solution that describes the use of the new features in NI-DAQmx 7.4, as well as a specific application example, a timing diagram, and a LabVIEW block diagram. Each application case also contains notes with advanced information to clarify implementation details, optimizations, and error conditions.
Among the new features introduced in NI-DAQmx 7.4 is the Wait For Next Sample Clock VI, which guarantees tight synchronization between the hardware layer and the software layers when performing hardware-timed single-point tasks. This VI provides an accurate way to correlate block diagram execution to hardware signals, such as the sample clock for the given task, while at the same time providing feedback on the overall real-time execution of the control loop.
'DAQmx Wait For Next Sample Clock.vi' waits until the next pulse of the Sample Clock occurs for the task to which it is wired. If an extra Sample Clock pulse occurs between calls to this VI, the second call returns an error or warning and waits for the next Sample Clock pulse. By placing calling this VI after other DAQmx functions you can guarantee that all of the functions completed prior to the next sample clock of the task wired to 'DAQmx Wait For Next Sample Clock.vi'. For more information on this VI, see the NI-DAQmx Help.
Note: The increased flexibility provided in NI-DAQmx 7.4 and later required changing behavior of the 'DAQmx Is Read or Write Late.vi' which was used in NI-DAQmx 7.3. In NI-DAQmx 7.4 the 'DAQmx Is Read or Write Late.vi' no longer performs any lateness checking. Applications using 'DAQmx Is Read or Write Late.vi' will continue to run, but this VI will not report lateness errors or warnings. It is recommended that the application be updated to use the 'DAQmx Wait for Next Sample Clock.vi' or another alternative described in this tutorial.
An alternative to doing strict lateness checking is to use the 'Report Missed Samples' property of the DAQmx Real-Time Property Node. Setting this property to TRUE for hardware-timed single point analog input will cause the DAQmx Read to check to where there was more than one sample available in the FIFO. If there is more that one sample is available in the FIFO, the DAQmx Read will return an error indicating that the software was not able to keep up with the hardware rate. This form of lateness checking only checks the analog input operation lateness and does not check to verify when other DAQmx operations completed with relationship to the analog input task.
Note: The 'Report Missed Samples' property is only supported for analog inputhardware-timed single point tasks. This property should not be used in conjunction with the 'DAQmx Wait For Next Sample Clock.vi' as only one form of lateness checking should be used.
A third alternative is to perform no lateness checking by not using the 'DAQmx Wait For Next Sample Clock.vi' or the 'Report Missed Samples' property. In this mode, NI-DAQmx does no lateness checking and no errors or warnings will be reported by DAQmx functions indicating if the software is not able to keep up with the hardware rate. For advanced users, this allows for optimized performance but would require external hardware to verify the system is keeping up with the hardware rates.
Requirement
"My I/O must be hardware-timed. All output values need to simultaneously update at the arrival of the sample clock edge."
Solution
Use the Wait For Next Sample Clock VI (WFNSC) to verify that a new sample clock edge has not yet occurred.
Advantages
Restrictions
Read, process, and write operations are confined to the time available between the moment the device starts acquiring data and the moment the next sample clock edge arrives.
Sample Application
An example of this kind of application is an analog control loop that reads samples from a specific number of analog input channels, processes the data using a control algorithm (such as PID), and writes new control values to the analog output channels.
Sample Implementation
Sample Block Diagram
Notes
Requirement
"My I/O needs to be hardware-timed. All output values need to simultaneously update at the arrival of the sample clock edge. I need to exchange data between my time-critical loop and my lower-priority processes."
Solution
Advantages
Restrictions
Read, process, and write operations are confined to the amount of time available between the moment the device starts acquiring data and the moment the next sample clock edge arrives.
Sample Application
An example of this kind of application is an analog control loop that reads samples from a specific number of analog input channels, processes the data using a control algorithm (such as PID), and writes the new control values to the analog output channels. The application uses a real-time FIFO to stop the control loop based on a Boolean value provided by a lower-priority process. A similar approach can employ the use of real-time FIFOs to vary the PID parameters on the fly, or to transfer acquired and control output values to lower-priority processes for data logging and remote monitoring.
Sample Timing Diagram
Sample Implementation
Sample Block Diagram
Notes
Requirement
"My analog input task needs to be hardware-timed. My output task does not need hardware synchronization with the sample clock edge."
Solution
Use the DAQmx Real-Time»Report Missed Samples property, which returns an error if new samples are available before the read operation finishes converting samples from the previous iteration.
Advantages
Restrictions
Output updates suffer from software jitter because they are not hardware-timed.
Sample Application
An example of this kind of application is an analog control loop that reads samples from a specific number of multiplexed analog input channels, processes the data using a control algorithm (such as PID), and writes the new control values to the analog output channels using a software-timed task.
Sample Timing Diagram
Sample Implementation
Sample Block Diagram
Notes
Requirement
"I want to use hardware-timed counter input operations to drive my control loop."
Solution
Use the Wait For Next Sample Clock VI to synchronize the counter operations with the counter's sample clock.
Advantages
Restrictions
Read, process, and write operations are confined to the time available between the moment the device starts acquiring data and the moment the next sample clock edge arrives.
Sample Application
An example of this kind of application is a control loop that uses a counter input task, such as count edges, while controlling digital lines based on some predefined control logic. This sample application performs communication through the use of real-time FIFOs.
Sample Timing Diagram
Sample Implementation
Sample Block Diagram
Sample Application 2
Another example application is a control loop that monitors discrete inputs and uses the values to update a counter output task, using pulse frequency mode to generate pulse-width modulation control signals. This example application performs communication through the use of real-time FIFOs.
Sample Timing Diagram
Sample Implementation
Sample Block Diagram
Notes
Requirement
"My I/O tasks are of types that do not support hardware-timed operations."
Solution
Apply software timing to your time-critical loop by using the Timed Loop. Configure your NI-DAQmx tasks to use on demand timing.
Advantages
Restrictions
I/O samples suffer from software jitter.
Sample Application
An example of this kind of application is a digital I/O control loop. The application monitors the state of several discrete inputs and toggles the corresponding output based on the control algorithm. Hardware timing is not available for single-point digital I/O tasks in NI-DAQmx.
Sample Timing Diagram
Sample Implementation
Sample Block Diagram
Notes
Requirement
"My I/O needs to be hardware-timed. All output values need to simultaneously update at the arrival of the sample clock edge. However, I would also like to use the Timed Loop in my application."
Solution
Use the DAQmx Create Timing Source VI to create a timing source that drives a Timed Loop that contains the I/O operations and the control algorithm.
Advantages
Restrictions
Minor increases in overhead when compared to a regular LabVIEW While Loop.
Sample Application
An example of this kind of application is an analog control loop that reads samples from a specific number of analog input channels, processes the data using a control algorithm (such as PID), and writes the new control values to the analog output channels.
Sample Timing Diagram
Sample Implementation
Notes