Difference between revisions of "EGR 103/DAQ 2"
Jump to navigation
Jump to search
m |
|||
(39 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | This page contains pictures and graphs related to DAQ 2 for EGR | + | <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 == | ||
+ | |||
+ | * 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 === | ||
+ | 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 === | ||
+ | For this assignment, you do not need labels or titles for graphs. In 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 | + | Circuit layout for BasicAIO - '''You only need the left-most circuit, however''' |
<center> | <center> | ||
[[Image:Circuit2.jpg|400px]] | [[Image:Circuit2.jpg|400px]] | ||
Line 13: | Line 29: | ||
== Graph from BasicAIO == | == Graph from BasicAIO == | ||
− | Graph showing | + | Graph showing output when |
<source lang="matlab"> | <source lang="matlab"> | ||
− | + | Vout = 2.5+2.5*sin(2*pi*k/100); | |
− | |||
</source> | </source> | ||
That is, | That is, | ||
Line 22: | Line 37: | ||
<math> | <math> | ||
\begin{align} | \begin{align} | ||
− | V_{out | + | V_{out}=2.5+2.5\sin\left(\frac{2\pi k}{100}\right) |
− | |||
\end{align} | \end{align} | ||
</math> | </math> | ||
</center> | </center> | ||
<center> | <center> | ||
− | [[Image: | + | [[Image:Circuit2PlotX.png|500px]] |
</center> | </center> | ||
== Circuit for AIO == | == Circuit for AIO == | ||
− | Circuit layout for AIO | + | 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 | + | 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: | + | New Colors: Blue Orange Yellow Purple Green Cyan<br> |
+ | [[Image:VoltagesFigureRed.png|300 px]]<br> | ||
</center> | </center> | ||
+ | == 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=== | ||
+ | <source lang="matlab"> | ||
+ | % 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]); | ||
+ | </source> | ||
+ | |||
+ | ===BasicAIO.m=== | ||
+ | <source lang="matlab"> | ||
+ | % 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') | ||
+ | |||
+ | </source> | ||
+ | --> | ||
+ | <!-- | ||
+ | === Function to Plot Curves === | ||
+ | <source lang="matlab"> | ||
+ | function CurvePlotter(Vin, MyAdjective) | ||
+ | subplot(1, 2, 1) | ||
+ | plot(Vin(:,1), Vin(:,1), 'k-',... | ||
+ | Vin(:,1), Vin(:,2), 'b-',... | ||
+ | Vin(:,1), Vin(:,3), 'g-') | ||
+ | axis([-1 5 -1 5]) | ||
+ | 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> | ||
+ | |||
+ | === Script to Plot All Three Figures === | ||
+ | |||
+ | <source lang="matlab"> | ||
+ | clear | ||
+ | |||
+ | % Small LEDs | ||
+ | load SmallData | ||
+ | figure(1); clf | ||
+ | CurvePlotter(Voltages, 'Small') | ||
+ | print -dpng SmallPlot % This will make SmallPlot.png | ||
+ | |||
+ | % Large LEDs | ||
+ | %% your code here | ||
+ | |||
+ | % Rectangular LEDs | ||
+ | %% your code here | ||
+ | </source> | ||
+ | --> | ||
== Questions == | == Questions == | ||
Line 52: | Line 195: | ||
<references /> | <references /> | ||
− | [[Category:EGR | + | [[Category:EGR 103]] |
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.