Laboratory One The Measurement and Automation

advertisement
M.E. 401 – Mechatronics
Laboratory One
The Measurement and Automation Explorer
(MAX) and an Introduction to LabVIEW.
Required Materials
Hardware
P.C.
Multi-Function data acquisition board or USB DAQ board
One two-lead LED
One BNC connected LED (or second two-lead for USB DAQ users)
Software
Measurement and Automation eXplorer (MAX)
LabVIEW
Study Material
Course Text
LabVIEW Manual
Purpose
The purpose of this lab is to create and test virtual channels using MAX, and to gain a
basic understanding of programming in the LabVIEW environment.
Introduction
The Measurement and Automation eXplorer is a configuration wizard with many useful
capabilities. MAX can be used to configure a variety of National Instruments hardware
and software. MAX can be used to add new channels, interfaces, virtual instruments, and
execute system diagnostics. Using MAX you may also view devices and instruments that
are connected to your computer.
LabVIEW is a graphical programming language for virtual instrumentation. LabVIEW
was developed by National Instruments to program motion control and automation
systems in a way that allows for easy changes and improvements. Graphical
programming with LabVIEW can be used for a variety of applications including data
acquisition, instrument control, database and data analysis applications, and network
communication. LabVIEW makes use of drag and drop graphical icons to represent the
expressions and statements found in common text based programming languages.
The LabVIEW environment consists of a front panel and a block diagram. When
LabVIEW is launched the front panel window will appear with a gray background and
the block diagram window will appear with a white background. The front panel
represents an instrument (Virtual Instrument - VI) with gauges, knobs, switches and so
on. The block diagram displays the individual components of the instrument and is used
for wiringthe VI components and other objects used to build the program.
This laboratory will provide the opportunity to explore the basics of connecting your
computer to the real world using Data Acquisition DAQ Hardware
Input/Output Signals
Analog
Digital
Counter/Timer
Sensors
Data acquisition
hardware
Application and Driver
Software
DAQ System converts
signals into information
that your software can use
Information: State, Rate, Level,
Shape, Frequency Content
Your introduction to LabVIEW will begin with learning to control a light emitting diode
(LED). LED’s are frequently used in this course as they are an easy and inexpensive way
to visualize the output of your program. The LED represents all types of devices that you
wish to control.
Note: This first lab is written in tutorial fashion and will step you through the above
processes. The LabVIEW help files are quite extensive so please take advantage of these
resources, as well as the in-class reference library, and feel free to experiment on your
own.
Part 1: Measurement and Automation eXplorer (MAX)
Purpose: In the following tutorial you will create two virtual channels, an analog and a
digital channel, and test each one to verify its operational status. A successful test will
result in the emission of light from the corresponding LED.
To get started, connect LEDs to both the Analog and Digital ports.
(The black terminal of LED should go to Ground. Remember the channels
(normally 0 or 1) you have connected, you might need to select them
when you run Lab view ) Remember to SAVE your work on a thumb
drive, and to DOCUMENT your learning in your Mechatronics Notebook.
(I) Creating an analog channel.
1. Double click on the Measurement and Automation Explorer (MAX) icon on
the desktop. This will open up a window. The configuration window on the left
contains a Data Neighborhood icon.
2. Right click on this icon and select Create New.
3. Left click on NI-DAQmx Global Virtual Channel and click next.
4. Select “Generate Signals”, then select Analog Output, and select Voltage. New
window will pop up.
5. The DAQ hardware we are using is Device 1, (PCI-6024E or 6009USB). Select
the appropriate channel and click Next.
6. Name the channel Analog Channel 01, click through description, and then click
Finish.
(II) Creating a digital channel.
1. Right Click on the Data Neighborhood icon as before.
2. Left click on NI-DAQmx Global Virtual Channel and click next.
3. Select “Generate Signals”, then select Digital Output, and select Port Output.
New window will pop up.
4. The DAQ hardware we are using is Device 1, (PCI-6024E or 6009USB). Select
the appropriate channel and click next.
5. Name the channel Digital Channel 00, click through description, and then click
Finish.
(III) Test the analog channel.
1. Left Click on Analog Channel 1 in the configuration window of MAX, located
under Data Neighborhood.
2. Set the Signal Output Range between 0 – 5 volts.
3. Choose Run. Change the Output value. If the channel is configured properly and
the hardware is working correctly then the LED will light up (Some LEDs will
light up with a voltage over 2 volts.) To turn the LED off, change the output
value to zero and run, then STOP.
•
What happens to the LED when you click STOP? Why do you think
this happens?
(IV) Test the digital channel
1. Left Click on Digital Channel 1 in the configuration window of MAX, located
under Data Neighborhood.
2. Select the digital channel corresponding to the LED, and click to the Run
position. If the channel configured properly and the hardware is working
correctly, the LED will light up.
3. Turn LED off..
Part 2: LabVIEW
Purpose: The objective of this laboratory is to introduce and explore the LabVIEW
environment. Your goal is to create a simple VI that manipulates the LED attached to the
connector box. When the power to this instrument is on, the LED should turn on. With
no power supplied to the instrument, the LED should turn off. Use a Stop button to
terminate the program.
Lab Procedure:
1. Launch LabVIEW and select Blank VI.
2. Right Click in the Front Panel to bring up the controls panel, and select the
modern controls and then Boolean subpalette.
.1. Choose a control that will initiate your test of the LED (think of this as “power”
or “on/off”). Left click on this icon and then Left click on the front panel to
place the control. You will notice that once this control is selected and placed in
the front panel a Boolean variable— a switch that toggles between TRUE and
FALSE status— is passed into the block diagram.
.2. Similarly, add a STOP button
3. Right Click in the block diagram to bring up the Function Panel, and select the
Measurement I/O controls. Click on the NI-DAQmx subpalette and select the
DAQmx Create Virtual Channel.vi and place in block diagram. Left click on
the DAQmx Create Virtual Channel.vi and choose Digital output.
4. Move the cursor over the line terminal on DAQmx Create Virtual Channel.vi
and right click on it once. A pop-up menu will appear, go to Create and select
Control. Notice a new front panel control Lines.
5. Right Click in the block diagram to bring up the Functions Panel, and select
Programming Controls. Click on the Structures subpalette and select the While
loop structure and place it in block diagram.
6. Right Click in the block diagram to bring up the Functions Panel, and select the
Measurement I/O controls. Click on the NI-DAQmx subpalette and select the
DAQmx Write.vi and place this inside in while loop. Left click on the DAQmx
Write.vi and choose Digital → Single channel → Single sample → Boolean (1
line) from the popup menu.
7. Place the 2 Boolean variables created in step 2 inside the while loop.
8. Right Click in the block diagram to bring up the Functions Panel, select the
Measurement I/O controls. Click on the NI-DAQmx subpalette and select the DAQmx
Clear Task.vi and place in block diagram to the right of the While Loop.
9. The various blocks in the block diagram window must now be wired together.
The cursor will change to a “wiring spool”, when you hold the cursor over the
terminal if you have “Automatic Tool Selection enabled in the Tools Palette.
NOTICE: To wire two items together place the spool over one item and it will blink.
Left click to attach the wire and move to the second item. Left click again.
Remember to Show Context Help in order to view terminal descriptions in addition
to roll-over labels.
10. Now wire the task out of the DAQmx Create Virtual Channel.vi to the task in
of the DAQmx Write.vi. Do the same for the DAQmx Write.vi to the DAQmx
Clear Task.vi.
11. Now wire the error out of the DAQmx Create Virtual Channel.vi to the error in
of the DAQmx Write.vi. Do the same for the DAQmx Write.vi to the DAQmx
Clear Task.vi.
12. Wire the Stop Boolean control to the Conditional terminal inside the While
Loop. Wire the data terminal of the DAQmx Write.vi with the Power On/Off
Boolean control.
13. The virtual instrument should now be ready to run. In the Front Panel, select a
line, or virtual channel. Depress the “power” button. In the Block Diagram,
depress the Highlight Execution (light bulb),
, to observe the execution of
, in the front panel to
your virtual instrument program. Press the arrow,
begin the program. Notice the emission of light from the LED.
Press the power button on and off. Your LED should turn on and off.
Press the Stop
button on the Front Panel (or global
terminate the program. Now it should be looking like this:
•
Stop Button) to
Document your work and learning, plot the block diagram you connected
and describe the phenomenon you have seen.
Your report should follow the format described below:
1. Lab title
2. Hardware and Software
3. Objective
4. Descriptions of the problems you have experienced and how you solved them
5. Solutions to all the questions (will start with a bullet in the lab transcripts).
Note that brief explanations or descriptions after each plot are required.
6. Plots that need to be printed out (will start with a bullet in lab transcripts)
have to be attached with lab reports. Plots should be created by selecting
“File”-“Print”-“Next”-“icon, description, panel and diagram”-“Print”
options, which will also include your lab records such as time or date, etc.
7. Summary or conclusion
Download