This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Generate Signals on NI devices that Output Current

This example shows how to generate signals on an analog output current channel for a NI device capable of current output using the Session based interface.

Discover Devices that can Output Current

To discover a device that outputs current, click the name of the device in the list in the Command window, or access the device in the array returned by daq.getDevices command. This example uses a NI 9265 device. This is a 4 channel analog output current module and is device 5 in our system.

devices = daq.getDevices
devices = 

Data acquisition devices:

index Vendor Device ID           Description           
----- ------ --------- --------------------------------
1     ni     cDAQ1Mod1 National Instruments NI 9205
2     ni     cDAQ1Mod2 National Instruments NI 9263
3     ni     cDAQ1Mod3 National Instruments NI 9234
4     ni     cDAQ1Mod4 National Instruments NI 9201
5     ni     cDAQ1Mod5 National Instruments NI 9402
6     ni     cDAQ1Mod6 National Instruments NI 9213
7     ni     cDAQ1Mod7 National Instruments NI 9219
8     ni     cDAQ1Mod8 National Instruments NI 9265
9     ni     Dev1      National Instruments PCIe-6363
10    ni     Dev2      National Instruments NI ELVIS II

ans = 

ni: National Instruments NI 9265 (Device ID: 'cDAQ1Mod8')
   Analog output subsystem 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'.

Create the Session and Add Channels

Create a session, and use the addAnalogOutputChannel command to add an analog output channel to the session for generation. For the purposes of this example, add two current channels and change the session Rate to 100 scans per second.

s = daq.createSession('ni')

addAnalogOutputChannel(s,'cDAQ1Mod8',0, 'Current');
addAnalogOutputChannel(s,'cDAQ1Mod8',1, 'Current');
s.Rate = 100
s = 

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   No channels have been added.

s = 

Data acquisition session using National Instruments hardware:
   No data queued.  Will run at 100 scans/second.
   Number of channels: 2
      index Type  Device   Channel MeasurementType     Range     Name
      ----- ---- --------- ------- --------------- ------------- ----
      1     ao   cDAQ1Mod8 ao0     Current         0 to +0.020 A
      2     ao   cDAQ1Mod8 ao1     Current         0 to +0.020 A

Create the Data for Output

The channels of the NI 9265 have a range of 0 to 20 mA. Ramp from 0 to 20 mA on one channel and set a constant 10 mA on the other channel. Generate 1000 points of data for each channel so that we get 10 seconds of output data.

data1 = (0.00002:0.00002:0.02)'; % ramp up
plot(data1)                      % plot the data for channel 1
hold on
grid on
xlabel('Data Points')
data2 = repmat(0.01, 1000);      % constant value matrix
data2 = data2(:, 1);              % take first column for constant 10 mA output
plot(data2, 'r')                 % plot the data for channel 2
data = [data1 data2];            % you must have one column of data for each output channel

Queue the Data

The queueOutputData command attaches the data to the session.

queueOutputData(s,data) % Queuing the data for output

Start the Output Channel

The startForeground command starts the session. Since this example session includes only analog output, this command starts the output, and waits for the operation to complete.


Changing the Duration of the Output

To reduce the duration of the output, you can increase the scan rate. For one second of output, change the Rate to 1000 samples per second. This will exhaust the queued data in one second.

s.Rate = 1000;
queueOutputData(s,data)        % Queue the output data again
s.startForeground();           % start the output
Was this topic helpful?