Example Code

Simultaneous DAQmx Analog and Digital Input Plotted to a Single Graph

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

Code and Documents

Attachment

Overview
To demonstrate how to merge the acquisition of the analog and digital signals into one graph

Description:
The attached code is designed to do something that sounds really easy, but is deceptively tricky. It sets up and synchronises two tasks an analogue and a digital task; both with multiple channels acquiring continuous data. Both tasks output waveform data.
This is the tricky part! Digital waveform data cannot be plotted together on the same graph or chart as analogue waveform data (the digital data can't be plotted on an ordinary chart or graph). LabVIEW does have something called a combination analogue and digital waveform graph, but this still doesn't plot the digital and analogue data on the same axes.
The project attached below contains a subVI called "Convert Digital Waveforms to analog waveform.vi". This VI takes an input of the DAQmx Digital task refnum and the digital waveform. It determines how many channels were in the task, separates each channel of digital data from the others and turns it into an array of analogue waveforms. These can then be output to the main VI where they can be plotted on a graph alongside the analogue waveforms or processed as needed.
This code was designed with a compactDAQ chassis containing an analogue and a digital card in mind, but would work on an X-series card or a PXI chassis with an analogue and a digital card too. Each folder contains a .ini file that can be used to set up a simulated device on your PC to make the code work.

Steps to implement or execute code
To implement this example:

  1. Define the Analog Channel Parameters and Digital Channel Parameters to be used. Select your analog and digital channels on the front panel. Then go to the block diagram.
  2. Set the Timing Parameters as needed
  3. Run the VI
  4. (Optional) Turn on the Highlight Execution to see the flow of the VI

To execute this example:

  1. Install the required software.
  2. Connect the DAQ hardware that supports the Digital IO and Analog Input features
  3. Confirm the connection with the MAX with TestPanel
  4. Open the VI and refer the Implement Steps


Requirements
Software
LabVIEW 2012 or compatible
NI-DAQmx 9.0 or compatible

Hardware
cDAQ with C series Analog Input and Digital IO Module

 

bd.JPGfp.JPG

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

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

Comments
apollo_s
Member
Member
on

Hello Vsenior,

I am attempting to use your VI as a template for plotting AI and DI on the same waveform chart but I am encountering an "Error 1806 at DWDT Digital Signal Subset.vi" within "Convert Digital Waveforms to analog waveform.vi" saying "Signal value input is outside the range of the digital data." Can you provide any insight as to why this error might be occuring?

Vsenior
NI Employee (retired)
on

HI Apollo_s,

I don't know why it's giving that exact error but the message "Signal value input is outside the range of the digital data" suggests that something about the waveform that you've wired in isn't quite right. I'd check what you've wired in to see if there's anything that's different from what I posted.

You might consider getting in touch with your local NI office for technical support if you can't resoolve the problem. They can take a look at your VI and advise you.