LABVIEW AND DATA ACQUISITION - Rutgers University School of

advertisement
Laboratory #3: LABVIEW 7 EXPRESS AND DATA ACQUISITION
MAE 650:431 Mechanical Engineering Laboratory
Department of Mechanical and Aerospace Engineering
Rutgers: The State University of New Jersey
Safety
1. Do not begin lab until the teaching assistant has gone over equipment with the students.
2. Before starting check that wires are properly connected and not worn.
3. Only use the floppy disk provided or if using your own disk make sure that it has been scanned
for viruses.
4. Do not store data on computer hard drive or make any changes to program.
1. PURPOSE
1. Introduction of the basics of data acquisition and computer controlled instrumentation.
2. Writing a simple LabVIEW programs
3. Program and use a data acquisition boards to measure:
a) a time varying signal
b) a thermocouple signal.
2. INTRODUCTION
Since their inception computers have been common place in the experimental laboratories
aiding in the analysis of data, speeding up the time required to conduct calculations, giving a
convenient method to store and search through large quantities of data, control instrumentation, data
acquisition, etc. The current laboratory will be concerned with the use of computers for
instrumentation control and data acquisition. The first question, which may be asked, is how
computers communicate with other instruments. Two common methods are serial communication
(i.e. RS-232, USB, Firewire) and parallel communication. A third method of transferring data from
an experiment to the computer is through a data acquisition (DAQ) board.
Assume that you have an instrument, sensor, or device, which outputs a continuous voltage
signal (termed an analog signal), which may vary in amplitude with time as shown in figure 1a. In
general the voltage may be proportional to some physical property (temperature, pressure, distance)
depending on the instrument. In order to convert the analog signal into a digital one, which can be
recognized and stored by a computer, an analog-to-digital (A/D) converter must be used. This
device converts analog signals to digital (figure 1b) where the signal amplitude is converted to an
integer value determined by the resolution of the A/D converter. Obviously as the resolution of the
device increases the voltage difference between successive voltage increments decreases leading
1
Time
Amplitude
Number
of Bits
Data Point
Figure 1. Schematic of analog (a) and digital (b) signals.
to more accurate measurements. In practice sources of random noise limit the ability to increase the
resolution simply by using an A/D converter with a larger number of bit resolution. In general the
output of the A/D converter is calibrated so that the output recorded by the computer is in the
appropriate property measured. The time difference between acquired data points is specified by the
sampling rate given as (samples per second), or may be expressed as the A/D converter bandwidth
(i.e. 100 kHz) which is the frequency at which measurements can be taken. The time between
sample points is equal to 1/bandwidth or 1/sampling rate. Generally the sampling rate is either the
maximum clock-speed of the A/D converter or may be a lower value specified by the software
controlling the device. Although analog-to-digital converter integrated circuits are available in a
single chip, the most common (and by far the easiest) method is to purchase a board, (DAQ) which
can be installed on the computer in one of the expansion slots of the motherboard. The DAQ boards,
which can be purchased generally, include multiple A/D channels, amplifiers, signal conditioners,
digital input and output channels as well as analog output channels (termed D/A converters).
The DAQ board is useless without software to control it. This laboratory will employ a
National Instruments DAQ board installed on a personal computer using LabVIEW software as the
graphical programming environment. LabVIEW uses terminology, icons, and ideas familiar to
technicians, scientists, and engineers, and relies on graphical symbols rather than textual language to
describe programming actions.
The activities in this laboratory include:
1. a short tutorial and exercises intended to familiarize with the basic functions and
2
programming using of LabVIEW
2. step-by-step instruction for writing a LabVIEW program for acquiring and analyzing
two different waveforms
3. writing a LabVIEW program for acquiring and displaying temperature using a
thermocouple
3. TUTORIAL AND EXERCISES (to be conducted by goups of one or two)
The tutorial gives a brief description of LabVIEW 7 and is intended to give a general idea of
its capabilities. There are many more detailed tutorials available in LabVIEW, or in books, which
can be referenced.
The tutorial will make use of Chapter 1 of “Getting Started with LabVIEW 7 Express”
published by National Instruments. Follow the step-by-step instructions and do all the steps in
Chapter 1. This will introduce you to LabVIEW 7 Express . This portion of the tutorial should take
approximately 40 to 50 minutes to complete.
4. WRITING A LabVIEW PROGRAM FOR ACQUIRING AND ANALYZING DIFFERENT
WAVEFROMS (to be conducted by groups of one or two)
This part requires writing a simple LabVIEW program to save view and analyze data
acquired by a DAQ card from a signal generator
4.1. Hardware
The major pieces of hardware include a personal computer running the Windows 2000
operating system, a National Instruments DAQ board (which has been installed in an empty PCI slot
of a personal computer), cable, a National Instruments BNC terminal block, and a miniature
thermocouple probe.
The National Instruments DAQ board (PCI-MIO-16E-4)
The multifunction DAQ board used in this experiment allows the user to utilize 16 singleended (0 to 10 VDC) or 8 differential (± 10 VDC) analog input channels with 12-bit resolution and a
multi-channel sampling rate of 250 kS/s (kilo-samples per second). The multifunction DAQ board
also allows the user to program 2 channels of analog output and 8 channels of digital I/O (input or
output) and allows external triggering. The board uses a PCI slot on a Windows based personal
computer and is connected to a BNC terminal block using a 68 pin cable. Software drivers (called
NIDAQ) control the board from Windows. The LabVIEW installation includes a program called
Measurement and Automation Explorer which can be called to list all the National Instruments
devices connected to the computer and allows the user to test each device and specify user define
calibrations for each channel.
The National Instruments BNC Terminal Block (2120)
The BNC terminal block provides convenient connection terminals (BNC and screw
connectors) from the DAQ board to the instrument you want to measure from or control. Figure 2
3
shows the items on the front panel of the BNC-2120. It has terminals for using a thermocouple (with
cold junction temperature compensation), 8 channels of analog input, terminals for resistance
measurements, two channels of analog output, 8 channels of digital I/O, and other user defined
terminals. In order to help diagnose problems the terminal block has a function generator and
quadrature encoder (to test motion control applications). The analog input channels allow the user to
select either a floating (FS) or ground (GS) reference for the source.
Before writing the LabVIEW program the BNC-2120 should be configured for utilizing the
built-in function generator and the thermocouple connector.
I) The FUNCTION GENERATOR is used to output sine or triangle waves which are then
acquired using LabVIEW through one of the A/D channels. The parts of the terminal block required
are analog input channel 6 (ACH6) and the FUNCTION GENERATOR, which are highlighted in
figure 3.
1. Verify that there is a BNC cable is connected between ACH6 and the Sine/Triangle BNC
on the FUNCTION GENERATOR.
2. Verify that the switch below the ACH6 BNC is all the way to the right in GS position. At
the top of the FUNCTION GENERATOR the frequency selection switch should be all the
way to the left (100 - 10kHz).
3. In the FUNCTION GENERATOR the Sine/Triangle switch will be used to select the
appropriate wave shape (sine or triangle). for the function type.
4.
Turn the Amplitude Adjust and Frequency Adjust knobs in the FUNCTION
GENERATOR all the way counter-clockwise so that they are set on LO.
II) The thermocouple connector to acquire and display the temperature from an attached
thermocouple.
1. Attach the miniature probe provided
2. Set the switches above Channels ACH0 and ACH1 to Thermocouple
3. Set switches below ACH1 an ACH1 to FS
5. Writing the LabVIEW Programs
First make sure that you can access the various palettes needed in the front panel and block
diagram as well as the areas to find the tools, controls, and functions. It should be noted that the
Controls pallet is only accessible in the Front Panel window and the Functions Palette is only
accessible in the Block Diagram window while the Tools Palette an be used in both. The palettes
can be selected while in the Front Panel or Block Diagram window at anytime from the Window
menu item. To start a new preogram:
1.
2.
Double-click the left mouse button on the [National Instruments LabVIEW 7] icon.
Press the New << Blank VI button with the left mouse button. Two windows appear
one with the name Untitled 1 at the top, which is the Front Panel window, and one with
Untitled 1 Diagram at the top, which is the Block Diagram window. The Tools palette
also appears when the
4
Figure 2. BNC-2120 terminal block. The Function generator and CH 6 are highlighted
5
program is started. To begin writing the LabVIEW program the tasks in the Front Panel
window should first be completed followed by the tasks in the Block Diagram window.
3. Access the Front Panel window by selecting the top of it (the window with Untitled 1 at the
top) with the cursor and pressing the left mouse button or by selecting the appropriate button
at the bottom of the Microsoft Windows Desktop. This window can be made to fill the
screen by selecting the box in the upper right corner of the window.
4. If it is not already displayed, the Controls palette can be brought up by selecting it from the
Window menu item at the top of the Front Panel with the left mouse button.
5.1. Writing a Waveform Acquisition Program.
Programming the Front Panel
There are two items, which will be placed on the Front Panel for this program: the two Waveform
Graphs. After placing these items on the Front Panel their appearance, position, titles and other
attributes will be modified.
.
1. Create a waveform graph by selecting Graph Inds>>Waveform Graph on the Controls
palette with the left mouse button. Make sure you select the Waveform Graph and not the
Waveform Chart.
2. Position the Waveform Graph (titled Waveform Graph) in the Front Panel.
3. Create a second waveform graph by selecting Graph Inds>>Waveform Graph on the
Controls palette with the left mouse button.
4. Position the second waveform graph (titled Waveform Graph 2) in the Front Panel and
press the left mouse button.
Modifying the X-scale on both of the Waveform Graphs
1. Move the cursor over the upper Waveform Graph and press the right mouse button to bring
up the graph properties menu. Select Scales<<Time (X-Axis) and uncheck the Auto scaling
feature for the X axis.
2. Select Format and Precision>>Time(X-Axis) and verify that the Floating Point is
selected. Change the Digits of Precision to 3 and press the OK button at the bottom of the
screen.
3. Select the Editing tool from the Tools Palette and using it select the largest number on the xscale of the Upper Waveform graph (which should now read 100.000) and press the left
mouse button. Type in the number (0.008) and press the Enter key on the keyboard.
4. Again select the Editing tool from the Tool Box and using it select the largest number on the
x-scale of the Lower Waveform graph (which should now read 100) and press the left mouse
button. Type in the number (4000) and press the Enter key on the keyboard.
Changing some of the titles and values of some of the items on the Front Panel
1. Select the Edit Text tool from the Tools palette.
2. All of the following changes can be made in the same way as that used for changing the
maximum value of the x-scale with the waveform graphs above.
- Select the value or text to be changed
-Type in the new value or text and press the enter key on the keyboard, or press the
left mouse key on a blank region of the panel.
3. Change the text and values as indicated in Table 1.
6
Table 1. Changes to the values or text of various items
Item
Old Text or Value
New Text or Value
x-scale title of top Waveform
Graph
Time
Time (Seconds)
x-scale title of bottom
Waveform Graph 2
Time
Frequency (Hz)
Title of bottom Waveform
Graph 2
Waveform Graph 2
Fast Fourier Transform
4. The Front Panel Diagram window should appear as in Fig. 3. Items can be moved by placing
the cursor over the item holding down the left mouse button and dragging the item to the new
location. In order to make the current values the default values for this laboratory select
Operate>>Make Current Values Default and press the left mouse button.
5. The work at this point should be saved by placing a disk in the A: drive of the computer and
selecting File>>Save from the top menu followed by selecting drive A: in the file dialog box
and typing in suitable name for the file.
6. Minimize the Front Panel by selecting the minus sign [-] at the top right corner of the window
with the left mouse button
Programming the Block Diagram
Items in the Block Diagram window allow the program to control and access channels on the
multi-channel DAQ board, to conduct calculations on the data, and to save the data to a text file.
1. Access the Block Diagram window by selecting the top of it (the window with the file name
followed by Diagram at the top) with the cursor, and pressing the left mouse button, or by
selecting the appropriate button at the bottom of the Microsoft Windows Desktop. This
window may be made to fill the screen by selecting the box in the upper right corner of the
window with the left mouse button.
2. Bring up the Functions palette by selecting “Show Functions Palette” from the Window
menu item at the top of the Block Diagram window.
7
Figure 3. Final arrangement of front panel controls and displays.
3. Create a While Loop by selecting Exec Ctrl>>While Loop from the Functions palette
using the left mouse button. Place the mouse cursor at the position on the block diagram
where you want to anchor the top-left corner of the While Loop and press and hold down the
left mouse button. When the button is released it will define the lower right corner of the
While Loop. Everything inside the While Loop will be executed continuously until stopped
by pressing the Stop button. Notice that a Stop button now appears both on the Block
diagram and the Front panel.
4. Use the Up navigation button on the Functions palette to navigate back to the main
Functions palette using the left mouse button.
8
Figure 4. Positions of display and control functions in block diagram
5. Select Input<<DAQ Assist vi and drag it inside the While Loop. The DAQ assistant menu
will automatically appear to configure the DAQ Assist vi:
a. Select Measurement << Analog Input.
b. Select Measurement<< Voltage.
c. Select Physical Channel<<ai6. Then select Finish.
d. A window will then appear with information about the measurement task. In the
Task Timing menu select Acquire N Samples and set the Samples to Read to
1,000. Also set the (sample) Rate at 10,000 Hz. The click OK to end the DAQ
configuration.
6. Use the Up navigation button on the Functions palette to navigate back to the main
Functions palette with the left mouse button.
7. Create an FFT analyzer by selecting Analysis>>Spectral from the Functions palette and
drag inside the While Loop. The Spectral Measurements menu will automatically appear to
configure the FFT vi:
a. Select Spectral Measurement<< Measurement (RMS), and Result <<Linear.
b. Select Window<<None. Then click OK to end the FFT analyzer configuration.
8. Use the Up navigation button on the Functions palette to navigate back to the main
Functions palette with the left mouse button.
9. Create a vi to save the data in a text file by selecting Output<<Write LVM (Write
LabVIEW Measurements) from the Functions palette and drag it onto a position outside and
to the right of the While Loop on the block diagram. The Write LVM menu will
automatically appear to configure the Measurements File (if it does not right click on the
Write LVM icon and select Properties):
9
a. Note and (modify) the path of the File Name.
b. Check Action<<Ask user to choose file<< Ask only once.
c. Check one of the options as desired in If a file already exists.
d. Ckeck Segment Headers<<One header per segment or as desired.
e. Check X Value Columns<< One column per channel
f. Check Delimiter<<Tab and then OK to end Configuration
g. Look at Figure 4 to see what the block diagram should look like at this point.
10. Close the Functions palette by selecting the X in the upper right corner of the palette with
the left mouse button.
11. Select the Connect Wire tool (spool of wire) on the Tools palette (if the Tools palette is not
visible select Window>>Show Tools Palette.
12. Now the components can be wired. The steps are as follows:
a. Place the cursor over the node of the output of the function until the correct node is
displayed.
b. Press the left mouse button.
c. Move the cursor to the other function you want to wire to. If you want to create a
bend in the wire simple press the left mouse button where you want the corner to be
and continue moving the cursor to the function you want to connect to.
d. Place the cursor over the node of the input of the other function you want to wire to
until the correct note is displayed.
e. Press the left mouse button, the wire should change to a patterned color
Note that if the function has only one node the entire function will blink
13. Wire the items listed in Table 2 together. Figure 5 shows what the completely wired Block
Diagram should look like.
Table 2. Components to be wired together
Function to be wired
From
Node
Function to be wired
To
Node
DAQ Assistant
Data
Waveform Graph
Anywhere on
function
DAQ Assistant
Data
Spectral
Measurements
signals
Spectral
Measurements
FFT-(RMS)
FFT graph
Anywhere on
function
Waveform Graph
Anywhere on
function
Anywhere on
function
Write LabVIEW
Measurements
Write LabVIEW
Measurements
signals
FFT Graph
signals
14. If there are no wires, which are shown as black dashed lines, and the Run arrow at the top
of the Block Diagram window is unbroken then you are finished and the program is ready
to run and be tested. You may want to select and move objects or wires using the
10
Position/Select/Sizing tool to improve the appearance of the diagram.
15. The work should be saved at this point with a disk in the A: drive of the computer by
selecting File>>Save from the top menu.
16. The program is now ready to run, so minimize the Block Diagram window by selecting the
minus sign [-] in the top right corner of the window.
Figure 5.Final arrangement of the block diagram
5.1a. Running the Waveform Acquisition Program
The program can now be run using as inputs sine or triangle waves at different frequencies
and saving the data. (A disk should be in the A drive). The program allows viewing the waveform
from the FUNCTION GENERATOR and when the Stop Button is pressed the last waveform(s)
displayed can be saved. The fast Fourier transform will display peaks at the frequencies needed to
create the waveform from a series of sine waves. If the waveform is a sine wave there is only one
11
peak, which is associated with the frequency of that sine wave.
1.
Start the LabVIEW Program by selecting the run arrow at the top left of the Front Panel
window of your program.
2.
A waveform should be displayed and will be continuously updated in both graphs on the
Front Panel.
Adjust the Amplitude Adjust knob on the FUNCTION GENERATOR until a sine wave
of amplitude of approximately ± 1 is displayed in the Waveform Graph. You will notice
that the Amplitude on the graph is automatically updated.
Adjust the Frequency Adjust knob on the FUNCTION GENERATOR until the peak in
the Fast Fourier Transform graph is at 500 Hz indicating the frequency of the sine wave that
is being used.
The data should now be saved, so select the Stop Button in your program and press the left
mouse button. A file dialog box will open asking for a file name file destination. Save the
data on drive A appending the suffix .txt to the file name.
Repeat Steps 1, 4 and 5 but for wave frequencies of 1000 and 3000 Hz (do not adjust the
amplitude). Notice as the frequency increases the sine wave distorts.
Repeat step 6 using first a sampling rate, which is half, and then 2.5 times the input wave
frequency. The sampling rate can be changed by right clicking on the DAQ Assistant icon
and selecting Properties. Note the change in FFT frequency with sampling rate.
Now switch the waveform type in the FUNCTION GENERATOR by moving the
Sine/Triangle switch to the right selecting a triangle wave for the function type (The
sampling rate should be set again at 10,000 samples/sec).
Start the LabVIEW Program again by selecting the Run arrow at the top left of the Front
Panel window of your program.
Adjust the Amplitude Adjust knob on the FUNCTION GENERATOR until a triangle
wave of amplitude of approximately ± 1 is displayed in the Waveform Graph. You will
notice that the Amplitude on the graph is automatically updated.
Adjust the Frequency Adjust knob on the FUNCTION GENERATOR until the highest
peak in the Fast Fourier Transform in the FFT graph is at 500 Hz, indicating the frequency of
the triangle wave, which is introduced. Note the frequencies and amplitudes of the peaks in
the FFT graph.
The data should now be saved, so select the Stop Button in your program and press the left
mouse button. When a file dialog box opens type in a file name and save the data on drive
A.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
5.1.b Saving Images of the Front panel and Diagram
It is possible to save the Front Panel and Block Diagram as an *.html file with *.png image format.
1. At the top menu of the LabVIEW program select File>>Print. with the left mouse button.
Press the Next button (3 times) on the bottom of the printing panel, which appears until the
“Destination” panel appears.
2. Select the option “HTML file” from the list with the left mouse button and press the Next
button at the bottom again with the left mouse button.
3. In the HTML panel the following settings should appear:
Image format: PNG (lossless)
Color depth: 256 colors
PNG compression: 5
4. Press the Save button with the left mouse button. In the file dialog box which appears select
the A: drive and type in a file name for the image of the Front Panel and Block Diagram and
12
press Save with the left mouse button. An HTML file is saved, which can be printed out by
any web page viewer (Netscape or Explorer).
5. Close your program and exit LabVIEW. You may want to check your files in a text editor
like Notepad or WordPad to make sure they can be read in correctly.
5.2. Writing the Thermocouple Data Acquisition Program
Following is an abbreviated principal step description for writing a simple LabVIEW 7 program for
acquiring and continuously displaying a thermocouple signal.
Suggestions for Programming the Front Panel.
1. Using the Controls<< Numerical Indicators palette create a Temperature Indicator to show
the numerical value of the temperature.
2. Using the Controls<<Graph Indicators palette create a Waveform Chart for displaying
the
temperature as a function of time
Programming the Diagram Panel
1. Use the Functions<<Input<<DAQ Assistant palette to acquire the temperature from
channel ai1. In the Properties menu select Acquire 1 sample.
2. Use the Functions<<Sig Manip<<From DDT function to convert the data to dynamic
form.
3. Use the Functions<<Exec Ctrl<<Time Dealy to set as 0.5 sec the time delay between
samples.
4. Wire the DAQ Assistant to the From DDT function and the From DDT function to
Graph Indicator.
5.2.a. Running the Thermocouple Data Acquisition Program
1. Run the thermocouple program to measure the room temperature for a period of 60 sec.
Save the front panel showing the temperature variation.
2. Run the thermocouple program for a period of 10 sec and then hold the thermocouple tip
between your fingers for 50 sec and note the temperature variation. Save and print the
front panel showing the temperature variation.
5.0.
REPORT
The report should at least include the following items:
A. For the waveform part.
1. Plots of the saved wave forms using the data saved:
• (Three sine waves at different frequencies, and one triangle wave for a data
acquisition rate of 10,000 samples per second) using a separate graph for each
waveform.
• Two sine waves for a wave frequency of 1000 Hz and sampling frequencies 2.5 and
0.5 times the wave frequency.
The y axis should be the amplitude, and the x axis the time, which should be set from 0 to
0.008 seconds for each graph (this will truncate some of the data points). Notice when
13
2.
3.
4.
5.
opening the text data file the first file is the time, the second column is the wave amplitude,
the third column is the FFT frequency, and the last column is the FFT amplitude
For the sine waves in (1) a discussion of how the shape of the waveform changes as the
frequency of the wave is increased and what might cause this.
Comments on the shape of the triangle wave in (1) and what you would expect to happen
if its frequency were increased.
A printout of your LabVIEW Front Panel and Block Diagrams.
An example printout of one of the save wave forms showing your name and the date
acquired.
B. For the Thermocouple part
1. The Front Panel waveform graphs showing the room temperature and the temperature
between you fingers.
2. A printout of your LabVIEW Front Panel and Block Diagrams.
14
Download