From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Archived: DAQmx - Synchronized AI/AO Shared Clock - LabVIEW - CVI - ANSI C - C#.NET - VB .NET

Code and Documents

Attachment

Overview


This document has been archived and is no longer updated by National Instruments.

Synchronized AI/AO Shared Clock

Description: This example demonstrates how to continuously acquire analog input and analog output at the same time, synchronized with one another on the same device.

Instructions for Running:
1. Select the physical channel to correspond to where your analog signal is input on the DAQ device. Also, select the channel to correspond to where your other analog signal is output on the DAQ device.
2. Enter the minimum and maximum voltage ranges.
Note: For better accuracy try to match the input range to the expected voltage level of the measured signal.
3. Set the sample rate of the acquisition.
Note: The rate should be at least twice as fast as the maximum frequency component of the signal being acquired.

Note: This example requires two DMA channels to run. If your hardware does not support two DMA channels, you need to set the Data Transfer Mechanism attribute for the Digital Input Task to use "Interrupts". Refer to your device documentation to determine how many DMA channels are supported for your hardware.

Steps:
1. Create a task.
2. Create an analog input voltage channel. Also, create an analog output channel.
3. Set the rate for the sample clocks. Additionally, define the sample modes to be continuous.
3a. Call the GetTerminalNameWithDevPrefix function. This will take a Task and a terminal and create a properly formatted device + terminal name to use as the source of the analog output sample clock.
4. Call the Start function to arm the two tasks. Make sure the digital input task is armed before the analog input task. This will ensure both will start at the same time.
5. Read the waveform data in a loop until the user hits the stop button or an error occurs.
6. Call the Stop function to stop the acquisition.
7. Call the Clear Task function to clear the task.
8. Display an error if any.

I/O Connections Overview:
Make sure your signal input terminals match the Physical Channel I/O controls.

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

Contributors