Difference between revisions of "User:DukeEgr93/DAQ"
Jump to navigation
Jump to search
(2 intermediate revisions by the same user not shown) | |||
Line 27: | Line 27: | ||
% Write values to output channels | % Write values to output channels | ||
putsample(AO, [5]) | putsample(AO, [5]) | ||
− | pause | + | %pause |
putsample(AO, [0]) | putsample(AO, [0]) | ||
Line 33: | Line 33: | ||
for k=1:300 | for k=1:300 | ||
% Calculate voltages for each channel | % Calculate voltages for each channel | ||
− | Vout0 = | + | Vout0 = 4*sin(2*pi*k/100); |
% Put voltages to each output channel | % Put voltages to each output channel | ||
putsample(AO, [Vout0]) | putsample(AO, [Vout0]) | ||
Line 42: | Line 42: | ||
% Plot voltages versus index | % 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) | plot(Voltages) | ||
% Turn all outputs off | % Turn all outputs off | ||
putsample(AO, [0]) | putsample(AO, [0]) | ||
+ | </source> | ||
+ | |||
+ | == For MX == | ||
+ | <source lang='matlab'> | ||
+ | % 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 | ||
+ | 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*sin(2*pi*k/100); | ||
+ | Vout1 = 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]) | ||
</source> | </source> |
Latest revision as of 21:42, 27 October 2016
Channel Checker
% Clear out workspace
clear
% Clear out DAQ objects
delete(daqfind)
% Create Analog Output Object
AO = analogoutput('nidaq', 'Dev1');
% Change sample rate
set(AO, 'SampleRate', 500);
% View Analog Output Object
AO
% Add channels to Analog Output Object
addchannel(AO, [0])
% Create Analog Input Object
AI = analoginput('nidaq', 'Dev1')
% Add channels to Analog Input Object
addchannel(AI, [0 1 2 3 4 5 6 7])
% Write values to output channels
putsample(AO, [5])
%pause
putsample(AO, [0])
% Use loop to set several different voltages
for k=1:300
% Calculate voltages for each channel
Vout0 = 4*sin(2*pi*k/100);
% Put voltages to each output channel
putsample(AO, [Vout0])
% Read voltages from all input channels
Voltages(k,:) = getsample(AI);
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
putsample(AO, [0])
For MX
% 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
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*sin(2*pi*k/100);
Vout1 = 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])