Example Code

Generate a Finite Waveform and Read the Response 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.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview

This VI shows how to generate a finite waveform output on a card and then read the response or echo on the analog input after the output has finished.


Description
There are three parts of the VI.  The first and last are the analog output and the analog input.  The glue that ties these two together is a counter output.  The counter is used to trigger the AI to start just after the AO finishes.  This is done by triggering the AO on the rising edge of a counter pulse and the AI on the falling.  When the pulse has the right period, it will last if the AO and thus the AI will start at the correct time.  Here's a graph of how this works:

1.png2.png

 

Requirements

  • LabVIEW 2012 (or compatible)
  • NI DAQmx


Steps to Implement or Execute Code

Analog Output Steps:

  1. Create an Analog Output Voltage Channel.
  2. Call the DAQmx Timing (Use Waveform) VI which sets the sample clock rate based on the input waveform parameters, and set the sample mode to finite.
  3. Use the Write VI to Generate Multiple Samples to 1 Channel on the Data Acquisition Card. The auto start parameter is set to False, so the Start VI must explicitly be called to begin the Voltage 
  4. Set up a Start Trigger that triggers at the start of the counter pulse.
  5. Call the Start VI.
  6. Call the Wait Until Done VI, with a time limit of 10s, then clean up the task and check for errors.

Counter Output Steps:

  1. Get the frequency needed for the pulse by finding the period and inverting it.
  2. Create a task using this frequency and a 50% duty cycle.
  3. Get the output terminal of the counter for use with triggering.
  4. Set the timing to a finite, two pulses (just to ensure that we get a full, clean pulse
  5. Start the counter after the other tasks.
  6. Clean up the task and check for errors.

Analog Input Steps:

  1. Create the Analog Input channel and task.
  2. Set the clock to be continuous at the specified rate and samples per channel.
  3. Create a Start Trigger that triggers off of the counter output, which uses the falling edge so it occurs at the end of the pulse.
  4. Start this task before the counter.
  5. Read the data once started.
  6. Clean up the task and check for errors.

 

Additional Information or References
VI Snippet

3-185.png

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

Jared S.
Applications Engineering
National Instruments

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