How to Synchronize NI-DAQmx Analog and Digital Tasks In LabVIEW

Updated Nov 18, 2020

Reported In

Software

  • LabVIEW

Driver

  • NI-DAQmx

Issue Details

  • I would like to synchronize my analog output and digital output tasks in LabVIEW so that I can output digital pulses exactly when my analog signal goes above/below a certain level.  How should I do this?
  • How do I synchronize my analog input and digital input task in LabVIEW so that I can correlate between two events?

Solution

There are many applications which require synchronization between analog input/output and digital input/output tasks.  For example, one might need to output a digital pulse whenever an analog output signal goes above 4.5V or when it goes below 0.5V, as shown in the mixed signal graph below:


To achieve this synchronized performance, we need to accomplish two goals:
  1. Generate two waveforms that correlate in desired ways. (e.g. create a digital waveform that is high whenever the analog waveform is outside of a specified range)
  2. Output these waveforms in two separate DAQmx tasks using some form of hardware-timed synchronization


In the VI example below, the correlated signals are generated by deriving a digital output waveform from the analog output waveform using the LabVIEW Comparison Nodes. Sample clock synchronization is achieved by specifying the analog output task's sample clock as the sample clock source for the digital output task. 

When the analog output task is started (assuming that the digital output task is already started and waiting for a sample clock), the tasks will run in a synchronized fashion, operating using the same sample clock, until the user stops the application.  

The following VI Snippet shows an example of Hardware synchronization between Digital and Analog Input tasks:


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram. 

The same concepts for analog output and digital output apply to the input example.

Additional Information

A start trigger is not needed in the above example since a sample clock is already being used to ensure that each output sample is synchronized between the tasks.
You can also find an example of analog input and synchronization at the following location: <Program Files>\National Instruments\<LabVIEW>\examples\DAQmx\Synchronization\