DAQ

From PrattWiki
Revision as of 19:31, 18 August 2017 by DukeEgr93 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page will contain information about how to use the session-based data acquisition tools in MATLAB.

Turning on analog outs and measuring with analog ins

% Clear out workspace
clear

% Create a session
s = daq.createSession('ni');

% Create Analog Input Object
% Add channels to Analog Input Object
addAnalogInputChannel(s, 'Dev1', 0:7, 'Voltage')

% Create Analog Output Object
addAnalogOutputChannel(s, 'Dev1', [0 1], 'Voltage')

% Write values to output channels (turns on, waits for a return, turns off)
outputSingleScan(s, [5 5])
pause
outputSingleScan(s, [0 0])

% Use loop to set several different voltages
for k=1:300
    % Calculate voltages for each channel
    Vout0 = 2.5+2.5*sin(2*pi*k/100);
    Vout1 = 2.5+2.5*cos(2*pi*k/100);
    % Put voltages to each output channel
    outputSingleScan(s, [Vout0 Vout1])
    % Read voltages from all input channels
    Voltages(k,:) = s.inputSingleScan;
    pause(0.02)
end

% Plot voltages versus index
figure(1); clf
for k=1:8
    subplot(4, 2, k)
    plot(Voltages(:,k));
    title(sprintf('%d',k))
end
figure(2);
plot(Voltages)
    

% Turn all outputs off
outputSingleScan(s, [0 0])