main content

generate voltage signals using ni devices -凯发k8网页登录

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 the daqlist command. 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"    "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{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 the rate property (the default is 1000 scans per second), and add analog output channels using addoutput.

dq = daq("ni");
dq.rate = 8000;
addoutput(dq, "cdaq1mod2", "ao0", "voltage");
addoutput(dq, "cdaq1mod2", "ao1", "voltage");

generate a single scan

use write to 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

use write to generate the output waveforms.

write(dq, outputsignal)
网站地图