Graphical Programming and Data Acquisition - X

VI_Programming_v10b.docx
GraphicalProgrammingandData
Acquisition
Use LabVIEW to create a “virtual instrument” (VI) that will collect data from a temperature sensor.
1
1.1
OBJECTIVES
PREREQUISITE SKILLS AND KNOWLEDGE
Students should have some experience using a balance.
1.2
RESEARCH SKILLS
After this lab, students will have had practice in:










1.3
following laboratory protocols
using a laboratory notebook
recording detailed software instructions into a laboratory notebook
using LabVIEW to control and collect data from a sensor
programming
propagating error
using a temperature probe to measure temperature
using a balance
measuring mass by difference
using a hotplate
LEARNING OBJECTIVES
After this lab, students will be able to:







Create a Numeric Constant, Numeric Indicator, and Numeric Control in LabVIEW
Test a Numeric condition
Perform arithmetic operations in LabVIEW
Create and run a simple Virtual Instrument in LabVIEW
Use a probe to determine the data contained in a “wire”
Use LabVIEW to display the readings from an instrument connected through the Vernier
SensorDAQ
Propagate the error in a quantity produced by the addition or subtraction of two measured
quantities
2
2.1
PRE-EXPERIMENT ASSIGNMENT
HOW TO PROPAGATE ERROR IN CALCULATED VALUES
There is a standard procedure for estimating the error in a quantity that is calculated from two or more
measured values. This procedure is called propagation of error. Just as you used a statistical method to
find the average error in your pipette measurements, there is a statistical method for propagating error for
each type of combination of measured values. In the X-Lab, you will only propagate error for addition
and subtraction and multiplication and division.
© 2016 X-Laboratory.org
2|Graphical Programming
When you combine measured values, whether by addition, subtraction, multiplication or division, the
uncertainty in the result tends to increase. Thus, the formula for combining the uncertainties is called an
error propagation formula.
2.1.1.1 Addition and Subtraction
To calculate the contribution of each uncertainty in addition or subtraction, use the formula given below.
Always add the squared uncertainties, even for subtraction problems.
(1)
In the above formula the notation
in y.
represents the uncertainty in
and
represents the uncertainty
Example: A P-1000 is used to pipette 980 µL of DI water into a 1.5 mL tube. Then a P-20 is used to
pipette 20 µL of red dye into the same tube. What is the total volume and what is the error1 in that
volume?
Answer: The total volume is the sum of the two volumes given:
Total volume in tube = 980 µL + 20 µL = 1000 µL
Using the typical errors given in the Measurement and Error lab manual and plugging them into formula
(1) above, the uncertainty in the sum is
10μL
0.4μL
100.16μL
10.008μL
This uncertainty is rounded off to 10 µL, and the total volume is reported as 1000 µL ± 10 µL.
Why is the uncertainty rounded to 10 µL?
Suppose you measure the mass of an empty beaker and a stir bar to be 81.168 g ±0.002 g. When you add
ice and a little water to the beaker the mass is 181.384 g ±0.002 g. Calculate the mass of ice water added
to the beaker. Calculate the uncertainty in the calculated mass of ice water.
2.2
INSTALL LABVIEW ON YOUR PERSONAL COMPUTER
If you have not already done so, download and install the Student LabVIEW Suite on your personal
computer. You will find the student license key and instructions with download links in the Installing
LabVIEW folder in Files>Student Resources>Labs>06.Graphical Programing. When you have installed
LabVIEW on your personal computer, continue with this assignment.
NOTE: If you do not have administrative access to the computer you are using for homework, please
contact your instructor or the lab coordinator, so that we can help you arrange a way to complete the
LabVIEW homework.
2.3
2.3.1
BUILD A SIMPLE LABVIEW PROJECT
The Front Panel and the Block Diagram
1. Start LabVIEW by clicking on the LabVIEW icon in your Start menu or Dock. Look for
or
.
2. Click on
.
3. Select “Blank VI” and click “Finish”.
1
Notice that the terms “error” and “uncertainty” are often used to mean the same thing: random error, or inaccuracy.
© 2016 X-Laboratory.org
Graphical Programming |3
4. LabVIEW will provide you with two windows. One is called the “Front Panel” and the other is called
the “Block Diagram”. Arrange these windows so they are side by side.
5. Bring up the “Controls” menu by right-clicking on any blank space in the Front Panel. The things you
create using this menu will act as the user interface to the LabVIEW program.
6. Right-click on a blank space in the Block Diagram to bring up the “Functions” menu. The things you
create with this menu will be the actual programming elements such as variables, control structures,
and arithmetic or logical operators.
2.3.2
Your First LabVIEW Program
Your first program will display a number on the Front Panel
1. Right-click on the Front Panel to bring up the “Controls” menu. Find the option for adding a Numeric
Indicator (not a Numeric Control) and double-click on it. You should see a text field appear in the
Front Panel, and a new icon in the Block Diagram.
© 2016 X-Laboratory.org
4|Graphical Programming
2. Notice that the icon in the Block Diagram has a Terminal on the left hand side in the shape of an
arrowhead or triangle. Hover your mouse over this Terminal and notice that the shape of the cursor
changes. (That’s your little spool of wire!)
3. Right-click on the Terminal and click on Create>Constant in the drop down menu. A new icon should
appear in the Block Diagram.
The new box that has appeared with a 0 in it is called a Numeric Constant. Notice that the Constant is
connected to the Indicator by a Wire. In the Block Diagram, Terminals on the left of an icon accept data
and Terminals on the right of an icon send data. Connecting an output Terminal to an input Terminal by a
Wire sends data from one to the other.
4. You are now ready to Run the LabVIEW program. Press the Run button,
start the program.
, on the Front Panel to
Did anything happen when you started the program? If not, what might you change to get a different
result? Try changing it.
Right now the Numeric Indicator has a label “Numeric”. You can change this name by clicking on the
text “Numeric” and typing a new name.
Does the name change in both the Block Diagram and the Front Panel when you do this?
5. Delete the Numeric Constant and the Wire.
6. Right-click on the Terminal of the Indicator and select Create>Control.
What do you see on the Front Panel? What do you think this element does?
7. Test your answer by running the program. (Press the Run
2.3.3
button on the Front Panel.)
Second Program: Arithmetic Operations and Logic
Now you will use LabVIEW to manipulate data. You will write a program that multiplies two numbers
and reports whether their product is greater than a third number.
2.3.3.1 The multiplication operator
1. Right-click on the Block Diagram and find the
operator.
symbol. This symbol is called the multiplication
There are two input terminals on the left hand side of the multiplication operator, which need to be
connected to two Numeric Constants, which will then be multiplied. The right hand terminal of the
multiplication operator is an output terminal; any wire coming from this terminal will carry information
about the product of these Numeric Constants.
2. Create a Numeric Constant for each of the input terminals.
3. Right-click on the output terminal of the multiplication operator, create an Indicator for the product
by clicking on Create>Indicator.
4. Try running your program with various different values for the Numeric Constants. Verify that you
get sensible results for the products of these numbers.
2.3.3.2 Comparison using the Greater? operator
1. Right-click on the Block Diagram. Look under “Comparisons? to find the “Greater?” operator
© 2016 X-Laboratory.org
.
Graphical Programming |5
The “Greater?” operator is similar to the multiplication operator in that it has two input terminals and one
output terminal. The difference is that the output terminal doesn’t carry numeric data, instead it holds a
True/False value.
Remember that your ultimate goal is for the program to tell you if the product of two numbers is greater
than 15.
2. Hover your mouse over the input and output terminals of the “Greater?” operator. You should see a
name for each terminal appear below the icon, e.g., “x”, “y”, and “x>y?”.
Which of the input terminals for
do you think should be connected to the number 15, “x” or “y”?
3. Create a Numeric Constant, with a value of 15, for this terminal.
4. Click on the remaining input terminal of
. Connect this wire to the outgoing wire from
.
Figure 1: This is what your Block Diagram should look like at
this stage.
5. Create an Indicator for the “Greater?” operator.
What does the Indicator of the “Greater?” operator look like? How does it indicate the value of the
output for
?
6. Right-click on each wire and create a “probe”. A new window will appear with the title “Probe Watch
Window”.
What do these probes do? Run the program; does anything within the “Probe Watch Window” change?
2.4
PREPARE FOR THIS EXPERIMENT
Save the VI you created and send it to yourself in an email. You may want to refer to it during the lab.
Make sure your lab notebook is up to date, including the visual programs (VI’s) you have already
developed. Read through the entire Lab Manual so that you can prepare your lab notebook. When you
feel ready, test your preparation with the Pre-Experiment Quiz.
.
© 2016 X-Laboratory.org
6|Graphical Programming
3
3.1
LABORATORY MANUAL
MATERIALS CHECK OFF LIST
Each group of (2 - 3) students will have:
Laptop computer with LabVIEW
Vernier Sensor DAQ
Vernier Temperature probe
200 mL beaker (tall form)
200 – 250 mL beaker
Magnetic stir bar
Stirring hot plate
Styrofoam container for ice
wash bottle with deionized water
2 large weighing boats
silicone pad
Each class will have access to



3.2
ice
2 milligram balances with 400 g maximum
1 barometer
SAFETY AND WASTE DISPOSAL PROTOCOLS
While in the X-Laboratory, do not eat, drink or apply ointments to the skin, even if you are not working
directly with toxic substances. Clean up spills quickly, to avoid electrocution and damage to electronics.
When cooling down the beaker, there is danger of thermal shock cracking the glass. The temperature of a
hot beaker or flask should be lowered slowly in a controlled manner to minimize the risk. Students should
not sit with their laps directly underneath the hot plate.
Do not take the hot flask or beaker off the hotplate and place it directly on the table. The rapid change in
temperature could crack the glass. If you must take the beaker off the hotplate, place it onto the silicone
pad, or a stack of paper towels.
3.3
EXPERIMENTAL PROCEDURE
As you complete this procedure, be sure to record your actions in your lab notebook, including a drawing
of each visual program and its results.
3.3.1
Third Program: Conditional Statements
Sometimes you only want to perform an operation if a given condition is met.
You are going to make a program which:



Takes two numbers from the user, labelled A and B.
If A is larger than B the program will print the text “A is bigger than B”.
If A is smaller than B the program will print the text “A is not bigger than B”.
3.3.1.1 Case Structure
In order for your program to make decisions, you must use the Case Structure.
1. Right-click on the block diagram and click on “Structures>Case Structure”.
© 2016 X-Laboratory.org
Graphical Programming |7
2. Click and drag to create a rectangle for the Case Structure
Figure 2: The rectangle to the right is the case structure. The
interior of the case structure is the body, where the optional
operations will go. Notice the small “question mark” square
on the left hand side; this is an input terminal for the case
structure.
3.3.1.2 Case Structure Condition
1. Create two Numeric Controls in the Front Panel. Label one of these controls A and the other B.
2. Connect the output of the corresponding A and B terminals to a “Greater?” operator in the block
diagram. These structures should be outside of the Case Structure.
3. Connect the output of the “Greater?” operator to the question mark
on the Case Structure.
3.3.1.3 Case Structure Body
So far you have seen numeric data and Boolean (True/False, 1/0) data. In programming jargon, textual
data is called “String data”.
1. With the dropdown menu at the top of the Case Structure set to “True”, right-click inside the Case
Structure and create a String Constant.
2. Type the value “A is bigger than B” into the String Constant.
3. Place a string indicator in the front panel. This will correspond with a pink string indicator terminal
that appears in the block diagram. Place the string indicator terminal outside of the Case Structure,
then connect it to the String Constant within.
4. Click on the dropdown menu at the top of the Case Structure; change its value from True to False.
Now, you should see a blank interior to the Case Structure. Create a new string constant here that says
“A is not bigger than B”. Connect this string constant to the same outer string indicator terminal by
drawing a wire from the new constant to the terminal’s pink entry point on the outline of the Case
Structure.
5. Use the numeric controls in the front panel to create situations in which the values of A and B
compare differently to each other. Run the program and note what message the string indicator yields
after each situation.
Q1. What difference is there, if any, between the statements “A is not bigger than B” and “A is smaller
than B”?
Q2. Based on the results of your trials (instruction 5, above), describe the purpose for the Case
Structure. What was the purpose of the different messages in the “True” and “False” screens of the
Case Structure?
3.3.2
Fourth Program: Using the Vernier Sensor DAQ
At your lab station you have a Vernier temperature probe and a Vernier Sensor DAQ (Data Acquisition
Device). In this, and future labs, you will use LabVIEW to create an interface for reading data from a
probe.
1. Plug the temperature probe into Channel 1 (Ch 1) on the SensorDAQ.
2. Plug the SensorDAQ’s USB cable into the computer.
© 2016 X-Laboratory.org
8|Graphical Programming
3. Open a new Blank VI from the LabVIEW menu.
4. In LabVIEW, right-click on the Block Diagram and select Vernier SensorDAQ>Analog Express.
Once you click on Analog Express, you will need to drag it up to the Block Diagram.
A window will appear (Fig 3).
Figure 3: This window will pop up when you choose the Vernier SensorDAQ>Analog Express.
5. Click on “Set Timing” in the top left corner. Confirm that “Duration” is set for 10 seconds and the
Sampling Rate is set for 10 samples/s. Note that changing these values changes the frequency of the
program’s data collection when collection finally begins. For the following portion (steps 6-8), adjust
these values and see how this alters run time and data acquisition.
6. Click “OK” on the “Configure Analog Express” window.
For now there are three terminals on the Analog Express icon which you need to know about.
o
o
o
7.
8.
“CH1 Auto-ID” is the terminal which has the numeric value of the voltage
sensor reading.
“stop (F)” will stop reading data from the voltage sensor if it receives a “True”
value.
“stopped” has a value of “True” if LabVIEW has stopped reading data from
the sensor.
Create a Numeric Indicator for the CH1 terminal.
Run LabVIEW.
Q3.
Roughly how long did the program run before it terminated? What
indicates that the program has terminated?
Fig 4: Analog
Express
Go back to the “Set timing” window and activate the checkbox labeled “Repeat”. Click “Done”.
Run LabVIEW again.
Q4. What do you think repeat does? (You may need to come back to this after some experimentation.)
© 2016 X-Laboratory.org
Graphical Programming |9
3.3.2.1 While Loops
To have the program run for longer than a few seconds you will use a control structure called a While
Loop.
1. Right click on the Block Diagram and find the While Loop structure. Draw a rectangle around the
Analog Sensor icon.
2. Create a Control for the “stop (F)” terminal by right clicking on it and
looking under the “Create” menu.
3. Connect the “stopped” terminal of the Analog Sensor icon to the “red
stop sign” terminal in the bottom right corner of the While Loop.
4. Run LabVIEW.
Q5. What do you think a While Loop does?
Q6. How can you terminate the loop?
Q7. The default width of the Numeric Indicator is too small to read all
the digits in the temperature measurement. How can you adjust the
Indicator to let you read these digits?
3.3.2.2 Creating a Temperature vs. Time Waveform Chart
Now that you’ve worked with While Loops and simple numeric indicators,
you are ready to make LabVIEW display a waveform chart of the
temperature data, which plots temperature vs. time as measurements are
collected.
Figure 5: The While
Loop control structure.
The red stop sign in the
bottom right is an input
terminal, which will
cause the loop to stop
repeating if it receives a
“True” value.
1. Delete the numeric indicator and its connecting wires from the VI you just created, leaving just the
connected Analog Express Box and the stop(F) control in the While Loop.
2. Right click on the Block Diagram inside the While Loop. Select Timing>Wait (ms).
3. Wire a Numeric Constant to the input of the Wait icon. Give the constant a value which will produce
an interval of 1 second between samples.
Q8. What value did you enter?
4. Right click on the front panel and create a waveform chart. This can be found under
“Graph>Waveform chart”
5. Wire the waveform chart’s input terminal to “CH 1 Auto-ID” terminal on the analog express icon.
6. Right click on the waveform chart’s image in the front panel. Under “Visible Items” select “Digital
Display”.
7. Test run the program.
Hold the temperature probe in your hand, while the program is running.
Q9. How can you tell when the probe has reached the same temperature as your hand?
© 2016 X-Laboratory.org
10 | G r a p h i c a l P r o g r a m m i n g
3.3.2.3 Raw Signal
Right click on the x-axis (Time) of the Waveform Chart. Select “AutoScale X”.
Double click on the Analog Express icon in the block diagram to open the properties panel. Under
configured channels change the setting from Automatic to Manual.
1.
Now click on “Add Channel”. There will be 3 columns, under “CHANNEL 1” click on “0 to 5 V” so
that it is highlighted and click “OK”.
2. Run the LabVIEW program again, note the difference in the numbers indicated by the waveform
chart.
Q10. What is the new unit displayed on the y-axis when the program is run again? This is the signal
that the probe actually measures that is converted to a temperature reading.
3. Again double click on the Analog Express icon in the block diagram. Under configured channels
return the setting to Automatic.
4. Save the virtual instrument for use in your experiment.
3.3.3
Monitoring Phase Changes with a Temperature Probe
Now, you will use your LabVIEW program to monitor the temperature changes as a beaker of ice is
heated until boiling.
3.3.3.1 Set Up Ring Stand
1. Arrange your hotplate so it is next to the base of the ring
stand.
2. Connect the clamps so that your temperature probe,
hotplate, and 200 mL beaker can have an arrangement
similar to the image to the right. The temperature probe
should be resting loosely in the clamp.
3. Remove the 200 mL beaker for the next few steps.
4. Obtain ice from your instructor.
5. Add a magnetic stir bar to the beaker.
6. Record the mass of the beaker and stir bar.
7. Add about 100.00 g of ice to the beaker.
8. Use your wash bottle to add just enough deionized water
to force out the air gaps between the chunks of ice.
9. Mass the now full beaker. Subtract the mass of beaker +
stir bar from this mass to find the mass of water and ice
only. This is called “massing by difference.” Record this
mass, and the error in this mass, in your lab notebook.
10. Replace the beaker onto the center of the still cold hotplate.
11. Place the temperature probe into the clamp and lower it into the slurry. Place the tip of the probe
about midpoint between the stir bar and the surface of the slurry.
© 2016 X-Laboratory.org
G r a p h i c a l P r o g r a m m i n g | 11
NOTE: The temperature probe should not touch the bottom of the beaker or the stir bar. Keep the tip near
the middle of the slurry.
3.3.4
Record a Heating Curve
1. Turn on the stirrer—do not go above 350 rpm. Make sure your stir bar is stirring without hitting the
temperature probe.
2. Start data acquisition by starting your VI.
3. Turn the heating dial on the hotplate up to 350 C.
4. Record the time and temperature at the point when you turn on the hotplate.
Collect a temperature reading in your lab notebook once every two to five minutes. Record the actual time
the reading is recorded.
As you collect time and temperature points, record also your observations of the state of the water.
Q11. At what time and temperature point do you notice that all the ice has melted?
Q12. At what time and temperature point do you notice that the water is starting to boil? Look for a
“rolling” boil and not just bubbling.
Collect time and temperature points until your water has been boiling for five minutes.
NOTE: Bubbles forming on the bottom of the beaker are not necessarily a sign of boiling. They may just
be dissolved gasses coming out of solution.
Turn off the hot plate and let your water cool before moving the beaker.
3.4
POST-LAB: PUTTING IT ALL TOGETHER
Boolean is a form of logic where all output can be reduced to a value of “true” or “false.” T or F are
signified simply by 0 and 1 in computers, so Boolean logic is frequently used in programming. LabVIEW
is no exception, as Boolean indicators can be employed to tell if a given input is true or false. A Boolean
LED, which glows if the input is T, can be placed in the front panel by right clicking and hovering over
“Boolean.” The corresponding terminal in the Block Diagram will look like the image below, where the
input wire can be connected on the left.
For the post lab, modify the temperature sensing VI that you have already created so that the LED glows
when a certain temperature is reached by a water/ice slurry.
Q13. What might be a good temperature to have your indicator light-up at?
HINTS:


You should not need to delete any of the existing components to do this.
Try using a “greater than” operator to complete this task.
Turn in your VI together with your answers to the lab questions.
© 2016 X-Laboratory.org