Difference between revisions of "User:DukeEgr93/DAQ"

From PrattWiki
Jump to navigation Jump to search
 
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 = 2.5+2.5*sin(2*pi*k/100);
+
     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>
 
</source>

Revision as of 15:05, 26 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])