Example Code

NI-DAQmx: Correlated Digital I/O with NI CompactDAQ and LabVIEW

Code and Documents

Attachment

Overview


Correlated Digital IO enables the coupling of buffered digital tasks with the analog, counter/timer, or external clocks. The CompactDAQ 9172 chassis includes the capability of synchronizing digital input and output. The cDAQ-9172 chassis includes two on-board counters that can be used as external signals to correlate digital input and output. This example program illustrates how to perform correlated DIO with a counter output task using the internal clock on the cDAQ-9172.


1. Create a Digital Input channel, a Digital Output channel, and a Counter Output channel to produce a pulse in terms of frequency.
2. Call the DAQmx Timing (Sample Clock) VI, which sets the sample clock rate for the digital tasks. Additionally, set the sample mode to continuous.
2a.  Call the Get Terminal Name with Device Prefix VI.  This will take a task and a terminal and create a properly formatted device + terminal name to use as the source of the digital sample clock.  The terminal used is Counter N's Internal Output.  The Match Pattern VI is used to determine which counter was specified.
2b.  Create a digital waveform to be outputted to the buffer.
3. Write the waveform to the output buffer.
4. Call the DAQmx Start Task VI on the digital tasks.
5. Call the DAQmx Start Task VI on the counter task. Use the sequence structure to ensure that both digital tasks are started before the counter task.
6. Read the digital waveform. Additionally, call the DAQmx Is Task Done VI to check for errors in the digital output and counter tasks.
7. Call the Clear Task VI to clear each task.
8. Use the pop-up dialog box to display any errors or warnings.

Note 1:  Make sure to select the internal counters on the cDAQ-9172 by selecting the appropriate I/O filtering name. 

By default, the DAQmx physical channel control drop down menu will not list internal channels.  To configure the DAQmx physical channel control drop down menu to include internal channels:

Right-click the DAQmx physical channel control in the front panel.
1.  Select I/O Name Filtering
2.  When the Filter Names dialog appears, check the Internal Channels check box.
3.  Click OK and select one of the two counters of the form: cDAQ1/_ctr0


Note 2:  Make sure to also verify that your DIO module is in slots 1 through 4 for buffered hardware tasks.

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

Contributors