Main Content

Generate Voltage Signals Using NI Devices

This example shows how to generate data using a National Instruments device.

Discover Devices That Can Output Voltage

To discover a device that supports analog outputs, access the device in the table returned by thedaqlistcommand. This example uses an NI 9263 module in National Instruments® CompactDAQ Chassis NI cDAQ-9178. This is module 2 in the chassis.

d = daqlist("ni")
d = 12×4 table DeviceID Description Model DeviceInfo ___________ __________________________________ _____________ ____________________ "cDAQ1Mod1" "National Instruments NI 9205" "NI 9205" [1×1 daq.DeviceInfo] "cDAQ1Mod2" "National Instruments NI 9263" "NI 9263" [1×1 daq.deviceinfo]“ cdaq1mod3”“国家仪器NI 9234”“ NI 9234” [1×1 DAQ.DEVICEINFO]“ CDAQ1MOD4”“ CDAQ1MOD4”“ NINATARTY INSTRANTMES NI Instruments NI 9201”““国家仪器NI 9402”“ NI 9402” [1×1 DAQ.deviceInfo]“ CDAQ1MOD6”“ NANTARTAL INSTROMEL NI 9213”“ NI 9213” [1×1 DAQ.Deviceinfo]NI 9219“ [1×1 DAQ.DeviceInfo]“ CDAQ1MOD8”““国家仪器NI 9265”“ NI 9265” [1×1 DAQ.DEVICEINFO] DEV1“ DEV1” DEV1“ DEV1”“ NANITAL ENTIANTION PCIE-6363”1 daq.deviceinfo]“ dev2”“国家仪器ni Elvis II”“ Ni Elvis II” [1×1 DAQ.DeviceInfo]“ Dev3”“ Dev3”“ National Instruments PCIE-6363”“ PCIE-6363”“ PCIE-6363” [1×1 daq.deviceinfo]“ dev4”“国家仪器PCIE-6363”“ PCIE-6363“ [1×1 daq.deviceinfo]
deviceInfo = d{2,"DeviceInfo"}
deviceInfo = ni: National Instruments NI 9263 (Device ID: 'cDAQ1Mod2') Analog output supports: -10 to +10 Volts range Rates from 0.6 to 100000.0 scans/sec 4 channels ('ao0','ao1','ao2','ao3') 'Voltage' measurement type This module is in slot 2 of the 'cDAQ-9178' chassis with the name 'cDAQ1'.

Create a DataAcquisition and Add Analog Output Channels

Create a DataAcquisition, set the generation scan rate by setting theRateproperty (the default is 1000 scans per second), and add analog output channels usingaddoutput.

dq = daq("ni");dq.rate = 8000;addOutput(dq,"cDAQ1Mod2","ao0","Voltage");addOutput(dq,"cDAQ1Mod2",“ AO1”,"Voltage");

Generate a Single Scan

Usewriteto generate a single scan (2 V on each channel). The output scan data is a 1-by-N matrix where N corresponds to the number of output channels.

output = 2; write(dq,[output output]);

Create and Plot the Output Data

Generate two output signals (a 1 Hz sine wave and a 1 Hz ramp) and plot them. The plot depicts the data generated on both channels for a device that supports simultaneous sampling.

n = dq.Rate; outputSignal1 = sin(linspace(0,2*pi,n)'); outputSignal2 = linspace(-1,1,n)'; outputSignal = [outputSignal1 outputSignal2]; plot(1:n, outputSignal); ylabel("Voltage (V)");legend("Analog Output 0","Analog Output 1");

Write Data

Usewriteto generate the output waveforms.

write(dq, outputSignal)