Generate Signals on NI Devices That Output Current

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 a Output Current Channnel

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)