EGR 103/DAQ 2

From PrattWiki
Revision as of 03:40, 21 March 2018 by DukeEgr93 (talk | contribs)
Jump to navigation Jump to search

This page contains pictures and graphs related to DAQ 2 for EGR 103. It has been updated for Spring 2018.

Notes

  • As before, if the system seems to not recognize Dev1, try Dev2 instead.
  • Here is the web page for MATLAB default plot colors: Link
  • MATLAB:Flexible Programming

Pauses

There are pause commands in the code which will cause the program to...pause - specifically when the program first runs to check the lights. You will need to hit a key to un-pause the program. The way to see if the program is paused is to look at the bottom left corner of your MATLAB window - it will tell you if it is paused.

Graph Labels

For this assignment, you do not need labels or titles for graphs. In a later assignment, you will add them.

Circuit for BasicAOutput

Circuit layout for BasicAOutput - You only need the left-most circuit, however

Circuit1.jpg

Circuit for BasicAIO

Circuit layout for BasicAIO - You only need the left-most circuit, however

Circuit2.jpg

Graph from BasicAIO

Graph showing output when

Vout = 2.5+2.5*sin(2*pi*k/100);

That is,

\( \begin{align} V_{out}=2.5+2.5\sin\left(\frac{2\pi k}{100}\right) \end{align} \)

Circuit2PlotX.png

Circuit for AIO

Circuit layout for AIO - You only need the left-most circuit, however

Circuit3.jpg

Graph from AIO

Graph showing outputs from three measurement channels. Note at the far left that they all start at either exactly -1 V or 0 V!

New Colors: Blue Orange Yellow Purple Green Cyan
VoltagesFigureRed.png

Codes

Pasting codes from PDF files is...a bad idea. Here are the text versions of some of the codes in the assignment.

BasicAOutput.m

% Initialize workspace and graph
clear; format short e; figure(1); clf; daqreset;

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

% set sample rate
SampleRate = 1000;
s.Rate = SampleRate;

% Add channel 0 to output
chO = addAnalogOutputChannel(s,'Dev1',[0],'Voltage'); 

% Review card information
s
chO
 
% Write values to output channel
outputSingleScan(s, [5]); 
fprintf('Press return to continue\n');
pause
outputSingleScan(s, [0]);  

% Use loop to set several different voltages
for k=1:300
    % Calculate voltages for each channel
    Vout = 2.5+2.5*sin(2*pi*k/100);
    % Put voltage to output channel
    outputSingleScan(s, [Vout])
    pause(0.02)
end

% Turn output off
outputSingleScan(s, [0]);

BasicAIO.m

% Initialize workspace and graph
clear; format short e; figure(1); clf; daqreset;

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

% set sample rate
SampleRate = 1000;
s.Rate = SampleRate;

% Add channel 0 to output
chO = addAnalogOutputChannel(s,'Dev1',[0],'Voltage'); 
% Add channels 0-3 to input
chI = addAnalogInputChannel(s,'Dev1',[0],'Voltage');

% Review card information
s
chO
chI

% Write values to output channel
outputSingleScan(s, [5]); 
fprintf('Press return to continue\n');
pause
outputSingleScan(s, [0]);  

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

% Turn output off
outputSingleScan(s, [0]);  

% Plot voltage versus index
n = 1:k;
Vtotal  = Voltages(:,1);
plot(n, Vtotal, 'r')
legend('Total Voltage', 'Location', 'Best')


Questions

Post your questions by editing the discussion page of this article. Edit the page, then scroll to the bottom and add a question by putting in the characters *{{Q}}, followed by your question and finally your signature (with four tildes, i.e. ~~~~). Using the {{Q}} will automatically put the page in the category of pages with questions - other editors hoping to help out can then go to that category page to see where the questions are. See the page for Template:Q for details and examples.

External Links

References