Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Generating a Signal

Learning to receive signals is just the beginning. It is also important to understand how to send signals to motors, actuators, and indicators so you can communicate with the real world and automate tasks. An example of this is sending a varying analog voltage to a DC motor to power a fan. This requires a digital-to-analog converter to output the signal to the real world.

This module covers creating and outputting an analog signal on a DAQ device using NI LabVIEW software.


Step-by-Step Procedure

Download the Step-by-Step Procedure PDF

Use the exercise solution from the Taking a Measurement module to acquire the signal being output on the analog output pins of your USB DAQ device.

  1. Connect the USB DAQ device to your PC
  2. Connect Analog Output 0 (ao0) to Analog Input 0 (ai0)
    1. You can locate the device pinouts for a DAQ device by searching for your device online at ni.com
    2. The user guide and specifications contain this diagram
    3. Right-click your device in Measurement & Automation Explorer (MAX) configuration software and select Device Pinouts
  3. Create a new VI in LabVIE
    1. Open LabVIEW and select File»New VI
  4. Place a DAQ Assistant on the block diagram
    1. Right-click on the block diagram and select Express»Output»DAQ Assistant
    2. Place the DAQ Assistant on the block diagram by left-clicking
  5. Configure DAQ Assistant type
    1. Select Generate Signals»Analog Output»Voltage
    2. Select Dev1 (or the name of your device if not Dev1)
    3. Select ao0 
  6. Configure generation settings
    1. Select Continuous Samples for Generation Mode
    2. Enter 100 for the Samples to Write
    3. Ensure the Use Waveform Timing checkbox is checked
    4. Select OK to apply these settings
    5. Select Yes when prompted to automatically create a While Loop
  7. Place a Simulate SignalExpress VI on the block diagram
    1. Expand the While Loop to approximately double its original size
    2. Right-click the block diagram and select Express»Input»Simulate Signal
    3. Left-click to place the Simulate SignalExpress VI to the left of the DAQ Assistant
  8. Configure simulate signal settings
    1. Select Triangle for the Signal Type
    2. Select OK to configure the Express VI
  9. Wire the Triangle output to the Signals input of the DAQ Assistant
  10. Create the stop condition to include when the Stop button is pressed or an error is detected
    1. Unwire the Conditional Terminal from the Stopped output terminal of the analog output DAQ Assistant
    2. Right-click the block diagram and select Programming»Boolean»Or
    3. Wire the output from the Stop button control to the bottom input of the Or Boolean function
    4. Right-click the block diagram and select Programming»Cluster, Class, & Variant»Unbundle by Name and place this to the right of the analog output DAQ Assistant
    5. Wire the Error Out output terminal of the analog output DAQ Assistant to the input of the Unbundle by Name function and ensure Status is selected to be unbundled
    6. Wire the output of the Unbundle by Name function to the top input of the Or function
    7. Wire the output of the Or function to the input of the Conditional Terminal
  11. Run the VI to observe the signal being output on the waveform graph

You can convert your DAQ Assistant Express VIs into low-level NI-DAQmx functions by right-clicking the DAQ Assistant and selecting Generate NI-DAQmx Code. The low-level NI-DAQmx API exposes more functionality and customization options for programming.

LabVIEW Example Code

Right-click on the above VI snippet and select Save Image As... Locate the file on your hard disk and click and drag the file icon onto your LabVIEW block diagram. LabVIEW automatically generates the code from the VI snippet. For more information, read VI Snippets.

For a low-level NI-DAQmx driver example for this concept, open the NI Example Finder and browse to Hardware Input and Output»DAQmx»Analog Generation»Voltage»Cont Gen Voltage Wfm-Int Clk.vi. See detailed help on using the NI Example Finder and help within LabVIEW.

Don’t have NI-DAQmx installed on your PC?
Download the latest version of NI-DAQmx.

Module Exercise: Generating a Signal

Download the Module Exercise PDF

Exercise Goal
Use LabVIEW to generate a sine wave and your NI myDAQ device to continuously output the waveform to a sound device such as computer speakers or headphones. Before starting this exercise, you need to complete the exercise and use the solution in the Taking a Measurement module.

Required Hardware
1- NI myDAQ
1- 3.5 mm audio cable with MP3 or CD player
or
1- computer microphone

Things to Consider

  • What is the audible frequency range of the human ear? Then what should the sampling rate be, according to the Nyquist Sampling Theorem, to generate all of the frequencies? What is the sampling frequency of a CD player? Therefore, what should you use for the sampling rate of your NI myDAQ device?
  • Samples to Write should be 1/5 to 1/10 of your sampling rate. For example, Fs=10 kHz, Samples to Write = 1k or 2k samples. This is a good benchmarking relationship for buffered generation.
  • Use a voltage generation to read output to speakers or headphones on audioOutputLeft and audioOutputRight for a stereo output, or just one channel for a mono output.
  • The output range for the audio output is ±2 V.
  • Display the signal to a graph before outputting to the NI myDAQ device.
  • Use a Merge Signals function to create two audio channels for both right and left.
  • Create a control for the Frequency to adjust this value on the fly. Should this control be placed inside or outside the While Loop if you want to update while running the VI?
  • Vary the frequency of the generated signal to hear the change in pitch.

Here is an example of what the final signal should look like on a graph indicator:

View the exercise solution (Don’t cheat!).

Cumulative Exam:
LabVIEW and DAQ

Evaluate your understanding of LabVIEW and the basics of DAQ. This exam is recommended after you complete all of the modules for LabVIEW Basic Concepts and LabVIEW Basic Tasks. There are 26 multiple choice questions on the exam.

Take the exam


Cumulative Project:
LabVIEW and DAQ

Assess your working knowledge of building a complete system by acquiring, processing, and displaying data with LabVIEW and a DAQ device. This project is recommended after you complete all of the modules for LabVIEW Basic Concepts and LabVIEW Basic Tasks.

Start the project