Graphical Programming and Data Acquisition - X

advertisement
Graphical Programming and Data
Acquisition
Use LabVIEW to create a “virtual instrument” (VI) that will collect data from a voltage sensor.
CONTENTS
1
2
Objectives ............................................................................................................................................. 2
1.1
Prerequisite Skills and Knowledge ............................................................................................... 2
1.2
Research Skills .............................................................................................................................. 2
1.3
Learning Objectives ...................................................................................................................... 2
Pre-Experiment ..................................................................................................................................... 2
2.1
2.1.1
For a windows operating system ........................................................................................... 2
2.1.2
For an Apple operating system ............................................................................................. 2
2.2
Creating a LabVIEW Project in Windows .................................................................................... 2
2.2.1
Your First LabVIEW Program .............................................................................................. 5
2.2.2
Second Program: Arithmetic Operations and Logic ............................................................. 6
2.3
3
Install LabVIEW ........................................................................................................................... 2
Creating a LabVIEW Project on a Mac ........................................................................................ 7
2.3.1
Your First LabVIEW Program .............................................................................................. 8
2.3.2
Second Program: Arithmetic Operations and Logic ............................................................. 9
Laboratory Manual.............................................................................................................................. 10
3.1
Materials Check Off List............................................................................................................. 10
3.2
Safety and Waste Disposal Protocols.......................................................................................... 11
3.3
Experimental Procedure .............................................................................................................. 11
3.3.1
Third Program: Conditional Statements.............................................................................. 11
3.3.2
Fourth Program: Using the Vernier Sensor DAQ ............................................................... 12
3.4
Post-Lab: Putting it all Together ................................................................................................. 13
© 2016 X-Laboratory.org
2|Graphical Programming
1
1.1
OBJECTIVES
PREREQUISITE SKILLS AND KNOWLEDGE
No prerequisite skills needed.
1.2
RESEARCH SKILLS
After this lab, students will have had practice in:
o
o
1.3
Using LabVIEW
Programming
LEARNING OBJECTIVES
After this lab, students will be able to:
•
•
•
•
•
•
Create a Numeric Constant, Numeric Indicator, and Numeric control on 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 Sensor
DAQ.
2
2.1
PRE-EXPERIMENT
INSTALL LABVIEW
If you have not already done so, download and install the Student LabVIEW Suite. Follow these
instructions:
2.1.1
For a windows operating system
Click on the link sent in the email from Engineering Software Licensing. If you did not receive an email
from Engineering Software Licensing, please contact your instructor or the X-Lab Coordinator as soon as
possible.
The link is also reproduced here:
http://search.ni.com/nisearch/app/main/p/ap/tech/lang/en/pg/1/sn/n8:12156,ssnav:pdl/
Click on the Download link next to the “LabVIEW 2013 Student Suite English”. Choose “Current user of
Academic Site License?” Follow the instructions to create a new user account and download the Student
Suite. When asked for it, enter the serial number sent to you by Engineering Software Licensing. Proceed
to Section 2.2 Creating a LabVIEW Project in Windows to create your LabVIEW project.
2.1.2
For an Apple operating system
You will need to visit the Engineering Software Licensing office in Weil Hall, room 360 to pick up an
installation disk. Follow the instructions to install the software. Proceed to Section 2.3 Creating a
LabVIEW Project on a Mac to create your first LabVIEW project.
2.2
CREATING A LABVIEW PROJECT IN WINDOWS
1. Start LabVIEW
© 2016 X-Laboratory.org
Graphical Programming |3
2. Click on
3. Select “Blank Project” and click “Finish”.
4. Go to the file menu and click “New VI”. (VI stands for virtual instrument)
© 2016 X-Laboratory.org
4|Graphical Programming
5. LabVIEW will provide you with two windows. One is called the “Front Panel” the other is called
the “Block Diagram”. Arrange these windows so that they are side by side.
6. Right-click on any blank space in the Front Panel. This gives you the “Controls” menu. The
things you create using this menu will be the user interface to the LabVIEW program.
7. Right click on the blank space in the Block Diagram to get the “Functions” menu. The things you
create with this menu will be the actual programming elements such as variables, control
structures, and arithmetic/logical operators.
© 2016 X-Laboratory.org
Graphical Programming |5
2.2.1
Your First LabVIEW Program
You will make a simple program to display a number on the Front Panel.
1. Right click on the Front Panel. Find the option for adding a Numeric Indicator and double click
on it. You should see a text field appear in the Front Panel and a new icon in the Block Diagram.
2. Notice that the icon in the Block Diagram has a Terminal on the left hand side in the shape of an
arrow or triangle. Hover your mouse over this Terminal, notice that the shape of the cursor
changes.
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 button,
window to start the program.
, on the Front Panel
Did anything happen when you started the program? If not, find out what must be changed to get a
different result, and how to change it
© 2016 X-Laboratory.org
6|Graphical Programming
Right now the Numeric Indicator has the 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?
Delete the Numeric Constant and the Wire. 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? Test your answer by running
the program. (Press the
2.2.2
button on the Front Panel window.)
Second Program: Arithmetic Operations and Logic
Now you are going to use LabVIEW to manipulate data. You will write a program which multiplies two
numbers and reports whether their product is greater than 15.
2.2.2.1 Multiplying Numbers
1. Right click on the Block Diagram and find the
symbol. This is called the multiplication operator.
There are two input terminals on the left hand side of the multiplication operator, which will be connected
to the Numeric Constants you will multiply together. 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 values for the Numeric Constants. Verify that you get
sensible results for the product of these numbers.
2.2.2.2 Comparison
1. Right click on the Block Diagram. Look under “Comparisons” to find the “Greater?” operator
.
The “Greater?” operator is similar to the multiplication operator in that it has two input terminals and on
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 us 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, such as “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
© 2016 X-Laboratory.org
.
Graphical Programming |7
Figure 1a: This is what your Block Diagram should look like at this stage.
1. 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
?
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.3
CREATING A LABVIEW PROJECT ON A MAC
1. Start LabVIEW
2. Click on “New > Blank VI” from the opening page menu. VI stands for Virtual Instrument.
3. LabVIEW will provide you with two windows. One is called the “Front Panel” the other is called
the “Block Diagram”. Arrange these windows so that they are side by side.
© 2016 X-Laboratory.org
8|Graphical Programming
4. Right-click on any blank space in the Front Panel. This gives you the “Controls” menu. The
things you create using this menu will be the user interface to the LabVIEW program.
5. Right click on the blank space in the Block Diagram to get the “Functions” menu. The things you
create with this menu will be the actual programming elements such as variables, control
structures, and arithmetic/logical operators.
2.3.1
Your First LabVIEW Program
You will make a simple program to display a number on the Front Panel.
© 2016 X-Laboratory.org
Graphical Programming |9
1. Right click on the Front Panel. Find Numeric Indicator and drag it onto the Front Panel You
should see a text field appear in the Front Panel and a new icon in the Block Diagram.
2. Notice that the icon in the Block Diagram has a Terminal on the left hand side in the shape of an
arrow or triangle. Hover your mouse over this Terminal, notice that the shape of the cursor
changes.
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 button,
window to start the program.
, on the Front Panel
Did anything happen when you started the program? If not, find out what must be changed to get a
different result, and how to change it.
Right now the Numeric Indicator has the label “Numeric”; you can change this name by double 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?
Delete the Numeric Constant and the Wire from the Block Diagram by clicking on them and pressing the
“delete” key. 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? Test your answer by running
the program. (Press the
2.3.2
button on the Front Panel window.)
Second Program: Arithmetic Operations and Logic
Now you are going to use LabVIEW to manipulate data. You will write a program which multiplies two
numbers and reports whether their product is greater than 15.
2.3.2.1 Multiplying Numbers
1. Right click on the Block Diagram and find the
symbol. This is called the multiplication operator.
There are two input terminals on the left hand side of the multiplication operator, which will be connected
to the Numeric Constants you will multiply together. 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. Hover your mouse over the
symbol to see the input and output terminals.
3. Create a Numeric Constant for each of the input terminals.
4. Right click on the output terminal of the multiplication operator, create an Indicator for the product by
clicking on Create->Indicator
© 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
5. Try running your program with various values for the Numeric Constants. Verify that you get
sensible results for the product of these numbers.
2.3.2.2 Comparison
1. Right click on the Block Diagram. Look under “Comparisons” to find the “Greater?” operator
.
The “Greater?” operator is similar to the multiplication operator in that it has two input terminals and on
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 us 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 above or below the icon, such as “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 1b: This is what your Block Diagram should look like at this stage.
2. 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
?
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?
3
3.1
LABORATORY MANUAL
MATERIALS CHECK OFF LIST
Each small group of (2-3) students will have (in addition to the components provided in Circuits 2):
o
o
o
o
Laptop computer with LabVIEW.
Vernier SensorDAQ.
Differential Voltage Sensor.
1.5 V battery.
© 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
o
3.2
9 V battery.
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.
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:
o
o
o
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 to 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”.
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
3. Create two Numeric Controls in the Front Panel. Label one of these controls A and the other B.
4. Connect the output of A and B to the “Greater?” operator.
5. 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 (aka True/False, or 1/0) data. In programming jargon
textual data is called “String data”.
6. Right click inside the Case Structure and create a String Constant.
7. Type the value “A is bigger than B” into the String Constant.
© 2016 X-Laboratory.org
12 | G r a p h i c a l P r o g r a m m i n g
8. Create a String Indicator outside of the Case Structure body. Connect this indicator to the String
Constant.
9. Click on the dropdown menu at the top of the Case Structure, what happens if you change its value
from True to False?
10. Set up the Case Structure for the situation in which A is smaller than B. Create a String Constant in
the body and give it a value “A is not bigger than B”. Connect this constant to the String Indicator.
Q1. Is there difference between the statements “A is not bigger than B” and “A is smaller than B”?
Q2. Why are you typing “A is bigger than B” into this constant? How do you know that in this context
the numerical value of A is larger than the numerical value of B? (You may have to skip this
question and come back to it).
3.3.2
Fourth Program: Using the Vernier Sensor DAQ
At your lab station you have a Vernier Sensor DAQ (Data Acquisition Device) and voltage probe. You
can use LabVIEW to create an interface for reading data from the voltage probe.
1. Plug the voltage probe into Channel 1 (Ch 1) on the Sensor DAQ.
2. Plug the Sensor DAQ’s USB cable into the computer.
3. In LabVIEW, right click on the Block Diagram and select “Vernier SensorDAQ->Analog Express”.
Figure 3: This window will pop up when you place the Vernier SensorDAQ->Analog Express.
4. A window will appear (see Fig 3); click on “Set Timing” in the top left corner. Activate the checkbox
labeled “Repeat”. Click “Done”.
Q3. What do you think repeat does? (you may need to come back to this after some experimentation)
© 2016 X-Laboratory.org
G r a p h i c a l P r o g r a m m i n g | 13
5. 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
“CH1 Auto-ID” is the terminal which has the numeric value of the
voltage sensor reading.
o
“stop (F)” will stop reading data from the voltage sensor if it receives a
“True” value.
o
“stopped” has a value of “True” if LabVIEW has stopped reading data
from the sensor.
6. Create a Numeric Indicator for the CH1 terminal.
7. Run LabVIEW.
Q4. Roughly how long did the program run before it terminated? What
indicates that the program has terminated?
3.3.2.1 While Loops
Fig 4: Analog
Express Icon
To have the program run for longer than a few seconds you are going to 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 an Indicator for the “stop (F)” terminal.
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 voltage measurement. How can you adjust the Indicator
to let you read these digits?
5. Use the voltage sensor measure the voltage on the 1.5 V and 9 V
battery. Do the numbers you see indicated make sense?
Try changing the polarity of the voltage leads when measuring the battery.
Q8. What difference does change this make?
3.4
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.
POST-LAB: PUTTING IT ALL TOGETHER
Create a LabVIEW program that continues to read the voltage from a voltage sensor until it measures a
voltage greater than 4 Volts. Turn this virtual instrument in to your instructor.
© 2016 X-Laboratory.org
Download