generate signals on ni devices that output current -凯发k8网页登录
this example shows how to generate signals on an analog current output channel of an ni device.
discover devices that can output current
to discover a device that outputs current, access the device in the table returned by the daqlist
command. this example uses an ni 9265 module in a national instruments® compactdaq chassis ni cdaq-9178. this is a 4-channel analog current output device and is module 8 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" "national instruments ni 9234" "ni 9234" [1×1 daq.deviceinfo] "cdaq1mod4" "national instruments ni 9201" "ni 9201" [1×1 daq.deviceinfo] "cdaq1mod5" "national instruments ni 9402" "ni 9402" [1×1 daq.deviceinfo] "cdaq1mod6" "national instruments ni 9213" "ni 9213" [1×1 daq.deviceinfo] "cdaq1mod7" "national instruments ni 9219" "ni 9219" [1×1 daq.deviceinfo] "cdaq1mod8" "national instruments ni 9265" "ni 9265" [1×1 daq.deviceinfo] "dev1" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo] "dev2" "national instruments ni elvis ii" "ni elvis ii" [1×1 daq.deviceinfo] "dev3" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo] "dev4" "national instruments pcie-6363" "pcie-6363" [1×1 daq.deviceinfo]
deviceinfo = d{8, "deviceinfo"}
deviceinfo = ni: national instruments ni 9265 (device id: 'cdaq1mod8') analog output supports: 0 to 0.020 a range rates from 0.6 to 100000.0 scans/sec 4 channels ('ao0','ao1','ao2','ao3') 'current' measurement type this module is in slot 8 of the 'cdaq-9178' chassis with the name 'cdaq1'.
add an output current channel
create a dataacquisition, and add two analog output channels.
dq = daq("ni"); dq.rate = 100; ch1 = addoutput(dq, "cdaq1mod8", "ao0", "current"); ch2 = addoutput(dq, "cdaq1mod8", "ao1", "current");
create and plot the output data
the channels of the ni 9265 have a range of 0 to 20 ma. produce a ramp from 0 to 20 ma on channel 1, and a constant 10 ma on channel 2. for each waveform, use enough points to generate 10 seconds of output data at the specified scan rate.
n = 10 * dq.rate; data1 = linspace(20e-6, 20e-3, n)'; data2 = repmat(10e-3, n, 1); data = [data1 data2]; plot(1:n, data) grid on xlabel('data points') ylabel('a') legend('data1','data2')
generate the channel output
use write
to generate the output waveforms.
write(dq, data)
changing the duration of the output
to reduce the duration of the output, increase the generation scan rate. for one second of output, change the rate
to the number of samples in the scan.
dq.rate = n; write(dq, data)