Example Code

Synchronizing Analog Output and Digital Output Signals Using LabVIEW with DAQmx

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

Code and Documents

Attachment

Overview

This VI demonstrates how to continuously acquire and generate data at the same time, synchronized with one another.

 
Description

There are many applications which require synchronization between analog output and digital output tasks.  The attached VI, for instance, shows how to output a pulse exactly when the analog output signal goes above 4.5V or when it goes below 0.5V.

In LabVIEW, this is as simple as sharing the clocks between the two tasks, and making sure that they start at the exact same time using same kind of trigger.  The attached VI titled Sync AO and DO.vi does this by specifying the AO Sample Clock as the Sample Clock for the digital output Task, and by creating a digital start trigger for the analog output task.  When the start trigger is received, both tasks start running at the exact same time, and run in a synchronized fashion until the user stops the VI.  The pulse trigger is created in the VI using a Counter Output Pulse task.

To verify that the two output signals are synchronized, use the attached Acq&Graph Voltage-Int Clk-Dig Ref-Analog&Dig.vi and connect the analog and digital output waveforms to the appropriate analog input channels.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Select the physical channel to correspond to where your signal is input on the DAQ device.  Also, select the corresponding channel for where your signal is being generated.
  2. Enter the minimum and maximum voltage ranges. Note:  For better accuracy try to match the input range to the expected voltage level of the measured signal.
  3. Set the sample rate of the acquisition. Note:  The rate should be at least twice as fast as the maximum frequency component of the signal being acquired. 
  4. Select the Rate for the generation
  5. Select what type of signal to generate and the amplitude. Note:  This example requires two DMA channels to run.  If your hardware does not support two DMA channels, you need to set the Data Transfer Mechanism property for the Analog Output Task to use "Interrupts".  The Data Transfer Mechanism property is located in the DAQmx Channel Property hierarchy at: DAQmx Channel Property Node>>Analog Output>>General Properties>>Advanced>>Data Transfer and Memory>>Data Transfer Mechanism. Refer to your device documentation to determine how many DMA channels are supported for your hardware.

 

 

Additional Information or References
VI Snippet

003.png 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Chris_G
Sr Test Engineer
Medtronic, Inc.

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

Comments
Nate@UT
Member
Member
on

This post describes exactly what I want to do:  generate an analog output along with a digital pulse which is synchronized with that AO task much in the same way a benchtop arbitrary waveform or function generator has a SYNC output line next to the main waveform output.

Problem is, the source code attached to this post fails when I run it.  I'm using a USB-6211.  The error I get is:

Error -200077 occurred at Property Node DAQmx Timing (arg 1) in DAQmx Timing (Sample Clock).vi:4730003->Sync AO and DO.vi

Possible reason(s):

Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.

Property: SampTimingType

Requested Value: Sample Clock

You Can Select: On Demand

Task Name: _unnamedTask<16>


Does anyone know of a fix for this code, or an alternate apporach to acheive the same goal?  I just want this USB device to be able to replace my existing 2-ch arb waveform generator with SYNC output.  (I need both AO channels for separate analog signals, so I can't use one of the AO channels as a pseudo-SYNC signal by programming a 5V square wave into its buffer.)

2010johnlee
Member
Member
on

 Hi, I have the same problem.

 

Anyone knows why? I am using pci-6110.

 

Thanks in advance.

John