Example Code

Synchronize Digital Tasks Using AO Sample Clock

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.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview:
Demonstrates on using Analog Output task to synchronize both digital input and output task.

Description:
This VI generates a digital signal on a DAQ card. Since the digital output or input lines of the M-series card does not have its own clock, an analog input or output task needs to be started in order use the clock from this source. Knowing this, you will need to set the Sample Clock to the ao/SampleClock. For the Digital Output and Input, select one line from available ports.

Requirements:
  1. LabVIEW 2012 or compatible.
  2. NI-DAQmx 15.5.1 or compatible.


Steps to Implement or Execute Code:

  1. Run this VI.
  2. Specify all the control values on the front panel corresponding to the Analog Output, Digital Input, and Output channels to be used in this program and click Enter.
    The Number of Digital Samples is the number of pulses to generate from Digital Output Channel. Set the Sample Clock to "ao/SampleClock" which will be used by digital channels for synchronization.
  3. Verify that both Digital Output Waveform and Digital Input Waveform are synchronized from the indicators.


Block Diagram Steps:

  1. Once the VI runs, it will wait until the user specifies all control values and clicks Enter.
  2. Creates channels to generate and acquire digital signals and also Analog Output channel which Sample Clock will be used to synchronize both digital channels.
  3. Sets the source of the Sample Clock for the all channels. In this case, digital channels will be using ao/Sample Clock as specified on the front panel.
  4. By calling the Start Task VI of the Digital Channels, it will prepare both channels to receive sample clock pulse from Analog Output channel. The analog task is started after the digital is ready to go, which will start the ao sample clock and in turn, start the digital tasks.  This is possible if you are controlling the start of the clock signal.
  5. Reading the control values in the While Loop using Local Variables enable the user to configure and generate new sets of data of the digital task on the fly. The loop will continue polling until the user clicks on the Stop button or if there is any error occurs.
  6. Clears all tasks and displays any error occurs.

Front Panel.PNG

 

bd.png

 

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

Jim St
National Instruments
RF Product Support Engineer

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