Example Code

DAQmx Multifunction Synchronization with Shared Start Trigger

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

    Driver

  • NI-DAQmx

Code and Documents

Attachment

Description

Part of the M Series Synchronization with LabVIEW and NI-DAQmx Example Set

 

When performing most multifunction synchronization, only a start trigger is needed. This is because the two operations derive their sample clocks from a common timebase internal to the device. In the LabVIEW example below that shows how to perform simultaneous analog voltage measurement and voltage generation, both analog operations derive their individual AI and AO sample clocks from the same internal 20 MHz or 100 kHz timebase inherent to the device. The operations will remain synchronous if given an identical rate. If the sample clock rates are set to different frequencies, the operations will be simultaneously started but not fully synchronized. Also note that the two operations can be configured to acquire different amounts of data.

 



Figure 1 Simultaneous Start Example


In the above example, there are two processes that occur concurrently. The top process controls the analog input and the bottom process controls the analog output. Each step, indicated by a number at the bottom of the figure, is described below.

 

  1. In step 1, both the analog input and analog output channels are created. The initialization procedure acquires the physical channel and the type of operation to perform (i.e. analog input on channel ai0 of Dev1).
  2. Step 2 is very important to the synchronization process. Using the DAQmx Timing VI, the two sample clocks are defined for finite acquisitions. Both this and the sample rate are determined by the specific application. For processes that start simultaneously but occur at different intervals, the sample clocks are assigned different rates. For operations in which the two processes are to occur in both a simultaneous and correlated manner, the samples clocks are assigned the same rate.
  3. In step 3, a Get Terminal Name with Device Prefix VI (C:\Program Files\National Instruments\LabVIEW 7.1\examples\DAQmx\_Utility\_Utility.llb) creates the terminal name to be used by the DAQmx Trigger VI. The purpose of this VI is for greater generalization in programming. Specifically this VI extracts the device name and appends the input string as a terminal name. Also in step 3, the DAQmx Trigger VI causes the analog output operation to wait for a digital trigger to begin executing. The source of this trigger is defined as the analog input start trigger, as derived by the Get Terminal Name with Device Prefix VI. The ai/StartTrigger signal is generated automatically as soon as the analog input operation is started. This trigger is then used to simultaneously start the analog output operation.
  4. Using the DAQmx Write VI, the analog output buffer is loaded with data.
  5. At this point, the analog output operation is started with the DAQmx Start Task VI. However, it has been configured to wait for a trigger and will not execute until the ai/StartTrigger goes high. Immediately thereafter, the other DAQmx Start Task VI is used to begin the analog input operation and sends the trigger signal. The sequence structure ensures that the analog output process has been started and is waiting for a digital trigger before the analog input process sends the trigger.
  6. The DAQmx Read VI will read a finite number of samples.
  7. Finally, the DAQmx Is Task Done VI checks that the program has completed writing the analog output, and the tasks are cleared. The error clusters are merged and passed to a simple error handler.

 

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

Contributors