Difference between revisions of "EGR 103/DAQ 2"

From PrattWiki
Jump to navigation Jump to search
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page contains pictures and graphs related to DAQ 2 for [[EGR 103]].  It has been updated for Spring, 2013.
+
<h1>This is the old page</h1>
 +
You probably want [[Python:DAQ 2]]
 +
 
 +
<!--
 +
This page contains pictures and graphs related to DAQ 2 for [[EGR 103]].  It has been updated for Spring 2018.
  
 
==Notes ==
 
==Notes ==
 +
 +
* As before, if the system seems to not recognize Dev1, try Dev2 instead.
 +
* Here is the web page for MATLAB default plot colors: [https://www.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html Link]
 +
* [[MATLAB:Flexible Programming]]
 +
 
=== Pauses ===
 
=== Pauses ===
 
There are <code>pause</code> 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.
 
There are <code>pause</code> 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 ===
 
=== Graph Labels ===
For this particular assignment, you do '''not''' need axis labels.  You need a title on each subplot, however.
+
For this assignment, you do not need labels or titles for graphsIn a later assignment, you will add them.
  
 
== Circuit for BasicAOutput ==
 
== Circuit for BasicAOutput ==
Circuit layout for BasicAOutput.
+
Circuit layout for BasicAOutput - '''You only need the left-most circuit, however'''
 
<center>
 
<center>
 
[[Image:Circuit1.jpg|400px]]
 
[[Image:Circuit1.jpg|400px]]
 
</center>
 
</center>
 
== Circuit for BasicAIO ==
 
== Circuit for BasicAIO ==
Circuit layout for BasicAIO (two measurements).
+
Circuit layout for BasicAIO - '''You only need the left-most circuit, however'''
 
<center>
 
<center>
 
[[Image:Circuit2.jpg|400px]]
 
[[Image:Circuit2.jpg|400px]]
Line 20: Line 29:
  
 
== Graph from BasicAIO ==
 
== Graph from BasicAIO ==
Graph showing outputs when
+
Graph showing output when
 
<source lang="matlab">
 
<source lang="matlab">
Vout0 = 2.5+2.5*sin(2*pi*k/100);
+
Vout = 2.5+2.5*sin(2*pi*k/100);
Vout1 = 2.5+2.5*cos(2*pi*k/100);
 
 
</source>
 
</source>
 
That is,
 
That is,
Line 29: Line 37:
 
<math>
 
<math>
 
\begin{align}
 
\begin{align}
V_{out,\,0}=2.5+2.5\sin\left(\frac{2\pi k}{100}\right)\\
+
V_{out}=2.5+2.5\sin\left(\frac{2\pi k}{100}\right)
V_{out,\,1}=2.5+2.5\cos\left(\frac{2\pi k}{100}\right)
 
 
\end{align}
 
\end{align}
 
</math>
 
</math>
 
</center>
 
</center>
 
<center>
 
<center>
[[Image:Circuit2Plot.png|500px]]
+
[[Image:Circuit2PlotX.png|500px]]
 
</center>
 
</center>
  
 
== Circuit for AIO ==
 
== Circuit for AIO ==
Circuit layout for AIO (six measurements).
+
Circuit layout for AIO - '''You only need the left-most circuit, however'''
 
<center>
 
<center>
 
[[Image:Circuit3.jpg|400px]]
 
[[Image:Circuit3.jpg|400px]]
 
</center>
 
</center>
 
== Graph from AIO ==
 
== Graph from AIO ==
Graph showing outputs from six measurement channels.
+
Graph showing outputs from three measurement channels. Note at the far left that they all start at either exactly -1 V or 0 V!
 
<center>
 
<center>
[[Image:VoltagesFigure.png|500 px]]
+
New Colors: Blue Orange Yellow Purple Green Cyan<br>
 +
[[Image:VoltagesFigureRed.png|300 px]]<br>
 
</center>
 
</center>
  
Line 54: Line 62:
 
=== BasicAOutput.m===
 
=== BasicAOutput.m===
 
<source lang="matlab">
 
<source lang="matlab">
% Clear out workspace
+
% Initialize workspace and graph
clear
+
clear; format short e; figure(1); clf; daqreset;
  
% Clear out DAQ objects
+
% Create a session
delete(daqfind)
+
s = daq.createSession('ni');
  
% Create Analog Output Object
+
% set sample rate
AO = analogoutput('nidaq', 'Dev1');
+
SampleRate = 1000;
 +
s.Rate = SampleRate;
  
% Change sample rate
+
% Add channel 0 to output
set(AO, 'SampleRate', 500);
+
chO = addAnalogOutputChannel(s,'Dev1',[0],'Voltage');  
  
% View Analog Output Object
+
% Review card information
AO
+
s
 
+
chO
% Add channels to Analog Output Object
+
addchannel(AO, [0 1])
+
% Write values to output channel
 
+
outputSingleScan(s, [5]);
 
+
fprintf('Press return to continue\n');
 
 
 
 
 
 
 
 
 
 
% Write values to output channels
 
putsample(AO, [5 5])
 
 
pause
 
pause
putsample(AO, [0 0])
+
outputSingleScan(s, [0])
  
 
% Use loop to set several different voltages
 
% Use loop to set several different voltages
 
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);
+
     Vout = 2.5+2.5*sin(2*pi*k/100);
    Vout1 = 2.5+2.5*cos(2*pi*k/100);
+
     % Put voltage to output channel
     % Put voltages to each output channel
+
     outputSingleScan(s, [Vout])
     putsample(AO, [Vout0 Vout1])
 
    % leave line 31 blank for now
 
    % leave line 32 blank for now
 
 
     pause(0.02)
 
     pause(0.02)
 
end
 
end
  
 +
% Turn output off
 +
outputSingleScan(s, [0]); 
 +
</source>
  
 
 
 
 
 
 
% Turn all outputs off
 
putsample(AO, [0 0])
 
</source>
 
 
===BasicAIO.m===
 
===BasicAIO.m===
 
<source lang="matlab">
 
<source lang="matlab">
% Clear out workspace
+
% Initialize workspace and graph
clear
+
clear; format short e; figure(1); clf; daqreset;
 
 
% 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
+
% Create a session
AO
+
s = daq.createSession('ni');
  
% Add channels to Analog Output Object
+
% set sample rate
addchannel(AO, [0 1])
+
SampleRate = 1000;
 +
s.Rate = SampleRate;
  
% Create Analog Input Object
+
% Add channel 0 to output
AI = analoginput('nidaq', 'Dev1')
+
chO = addAnalogOutputChannel(s,'Dev1',[0],'Voltage');
 +
% Add channels 0-3 to input
 +
chI = addAnalogInputChannel(s,'Dev1',[0],'Voltage');
  
% Add channels to Analog Input Object
+
% Review card information
addchannel(AI, [0 4])
+
s
 +
chO
 +
chI
  
% Write values to output channels
+
% Write values to output channel
putsample(AO, [5 5])
+
outputSingleScan(s, [5]);
 +
fprintf('Press return to continue\n');
 
pause
 
pause
putsample(AO, [0 0])
+
outputSingleScan(s, [0])
  
 
% Use loop to set several different voltages
 
% Use loop to set several different voltages
 
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);
+
     Vout = 2.5+2.5*sin(2*pi*k/100);
    Vout1 = 2.5+2.5*cos(2*pi*k/100);
+
     % Put voltage to output channel
     % Put voltages to each output channel
+
     outputSingleScan(s, [Vout])
     putsample(AO, [Vout0 Vout1])
+
     % Read voltage from input channel
     % Read voltages from all input channels
+
     Voltages(k,:) = inputSingleScan(s);
     Voltages(k,:) = getsample(AI);
 
 
     pause(0.02)
 
     pause(0.02)
 
end
 
end
  
% Plot voltages versus index
+
% Turn output off
 +
outputSingleScan(s, [0]); 
 +
 
 +
% Plot voltage versus index
 
n = 1:k;
 
n = 1:k;
Vleft = Voltages(:,1);
+
Vtotal = Voltages(:,1);
Vright = Voltages(:,2);
+
plot(n, Vtotal, 'r')
plot(n, Vleft, 'g', n, Vright, 'r')
+
legend('Total Voltage', 'Location', 'Best')
legend('Green LED', 'Red LED', 0)
 
  
% Turn all outputs off
 
putsample(AO, [0 0])
 
 
</source>
 
</source>
=== Example Commands to Parse Data Set for Small Green and Red LEDs ===
+
-->
 +
<!--
 +
=== Function to Plot Curves ===
 
<source lang="matlab">
 
<source lang="matlab">
load SmallData
+
function CurvePlotter(Vin, MyAdjective)
SmallGreenTotal = SmallVoltages(:,1);
+
subplot(1, 2, 1)
SmallGreenRes  = SmallVoltages(:,2);
+
plot(Vin(:,1), Vin(:,1), 'k-',...
SmallGreenLED  = SmallVoltages(:,3);
+
    Vin(:,1), Vin(:,2), 'b-',...
SmallRedTotal  = SmallVoltages(:,4);
+
    Vin(:,1), Vin(:,3), 'g-')
SmallRedRes    = SmallVoltages(:,5);
+
axis([-1 5 -1 5])
SmallRedLED    = SmallVoltages(:,6);
+
grid on
 +
title(sprintf('%s Green', MyAdjective))
 +
subplot(1, 2, 2)
 +
plot(Vin(:,4), Vin(:,4), 'k-',...
 +
    Vin(:,4), Vin(:,5), 'm-',...
 +
    Vin(:,4), Vin(:,6), 'r-')
 +
axis([-1 5 -1 5])
 +
grid on
 +
title(sprintf('%s Red', MyAdjective))
 
</source>
 
</source>
  
=== Subplot Structure for Plotting Code===
+
=== Script to Plot All Three Figures ===
The code below includes the commands for the small green LED assuming the variable names given in the code above.
+
 
 
<source lang="matlab">
 
<source lang="matlab">
subplot(3,2,1)
+
clear
% small green plotting commands
 
plot(SmallGreenTotal, SmallGreenTotal, 'k-',...
 
    SmallGreenTotal, SmallGreenRes,  'b-',...
 
    SmallGreenTotal, SmallGreenLED,  'g-')
 
title('Small Green LED')
 
grid on
 
  
subplot(3,2,2)
+
% Small LEDs
% small red plotting commands
+
load SmallData
 
+
figure(1); clf
subplot(3,2,3)
+
CurvePlotter(Voltages, 'Small')
% large green plotting commands
+
print -dpng SmallPlot % This will make SmallPlot.png
 
 
subplot(3,2,4)
 
% large red plotting commands
 
  
subplot(3,2,5)
+
% Large LEDs
% rect green plotting commands
+
%% your code here
  
subplot(3,2,6)
+
% Rectangular LEDs
% rect red plotting commands
+
%% your code here
 
</source>
 
</source>
 +
-->
  
 
== Questions ==
 
== Questions ==

Latest revision as of 16:09, 3 April 2019

This is the old page

You probably want Python:DAQ 2


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