ME 104

Sensors and Actuators

Fall 2002

Laboratory #1

Introduction to LabVIEW

Department of Mechanical and Environmental Engineering, University of California, Santa Barbara

October 1, 2002 Revision

By Aruna Ranaweera

Introduction

In this laboratory, you will learn how to use the LabVIEW development environment, which is based on the graphical programming language G. You will then write a LabVIEW program to acquire, display, and save an external voltage signal. As an extra credit exercise, you will investigate the effects of undersampling.

“LabVIEW is a programming language just like other programming languages, such as C, Basic, or Pascal, but LabVIEW is higher–level. In text-based programming languages, you are as concerned about the code as you are about what you are trying to do; you must pay close attention to the syntax (commas, periods, semicolons, square brackets, curly brackets, round brackets, etc.). LabVIEW is much more user-friendly —it uses icons to represent subroutines, and you wire these icons together in order to define the flow of data through your program. It is sort of like flow-charting your code as you are writing it—and the net effect is that you can write your program in a lot less time than if you did it in a text-based programming language.” [*]

LabVIEW software and hardware (data acquisition boards) have been installed on the PC’s in the Undergraduate Control Laboratory (Engineering 2, Room 2218). To launch LabVIEW, go to the Windows NT Start menu and proceed as follows:

Start>Programs>National Instruments LabVIEW 6i

or

Start>Programs>National Instruments>LabVIEW 6>LabVIEW.

LabVIEW software (without hardware) is also available in the CADLab (Room 2243).

Background Reading

Please read the following material prior to this laboratory:

  1. LabVIEW QuickStart Guide[†] (LVQSG) With Modifications, Chapter 1.

Experiment #0: Search for Examples.

In this experiment, you will use the Search Examples feature to find and run an example VI (Virtual Instrument).

  1. Follow the instructions on page 2-1 in the LVQSG.

Experiment #1: Build a Virtual Instrument

Part 1A

In this experiment, you will build a VI that generates random numbers and plots them to a strip chart.


  1. Follow the instructions on pages 2-4 to 2-13 in the LVQSG.

Part 1B

In this experiment, you will average the random data points you have collected and save your data to a spreadsheet file.

  1. Follow the instructions on pages 2-14 to 2-17 in the LVQSG.
  2. Click on File>Save As to save this latest version of your VI as yourname_lab1_ex1b.vi.


Experiment #2: Add Analog Input to Your VI

Part 2B

In this experiment, you will replace the random number generator from Part 1B with an analog input VI to acquire data from your DAQ (data acquisition) board, plot it to a strip chart, analyze it, and write it to a file. Analog Input Channel 0 (ACH0) on the DAQ board[‡] has already been configured to accept voltage signals in the range –10 V to +10 V.

  1. Follow the instructions on pages 3-15 to 3-18 in the LVQSG.


When you run the above VI, the strip chart will show (somewhat random) input voltage noise. This is because you have not provided your DAQ board with a specific input. To view a specific analog input, you can connect an external voltage signal to the CB-68LP connector block (Figure 2). The connector block is directly connected to the DAQ (data acquisition) board by a 2 meter, shielded I/O (input/output) cable. We will use the Tektronix CFG280 Function Generator to generate an external voltage signal.

  • Safety note: Before you connect an external voltage signal to the connector block, you should always use an oscilloscope to verify that your external voltage signal is well-behaved and has an amplitude of not more than 10 volts. Since the DAQ board is rated for voltages between –10 V and +10 V, application of a voltage outside that range could cause irreparable damage to the (expensive) DAQ circuitry. If you need help using your function generator or oscilloscope, please ask a TA for assistance.
  1. Using a BNC cable, connect the MAIN OUT terminal on the function generator to your oscilloscope.
  2. Turn on the oscilloscope and set its vertical scale to 1.00 volts/division and its horizontal scale to 1.00 seconds/division.
  3. On your function generator, select the “MAIN 0-2Vp-p” setting by pressing down that button. This will limit your voltage output to 2 volts, peak-to-peak[§].
  4. Find the FUNCTION selection buttons on your function generator. Select (press down) the sine wave function (◠◡) button. Make sure that none of the other buttons on that row are pressed down.
  5. Turn ON the function generator.
  6. Press the down MULTIPLIER ( ) button until the MULTIPLIER indicator (red light) shows 1 and the PERIOD indictor shows SEC. In this setting, the digital display shows the output period in seconds.
  7. Turn the FREQUENCYdial on the function generator until the digital display shows approximately 1.000. This indicates that the function generator is generating a signal with a period of approximately 1 second (and therefore, a frequency of approximately 1 Hz).
  8. Find the AMPLITUDE knob on the function generator. Turn it clockwise as far as you can to select the maximum (MAX) amplitude of 2V peak-to-peak.
  9. Verify on your oscilloscope that the output from your function generator is, in fact, a sine wave with an amplitude of 1 volt and a period of 1 second (frequency of 1 Hz). For safety purposes, please show your output signal to a TA before proceeding to the next step.
  10. Connect the analog voltage and analog ground from your function generator to the CB-68LP connector block as shown in Table 1. You should use wires with stripped ends[**] to make the indicated connections. Do not remove the connections to the oscilloscope.

You are now ready to run your VI.

  1. Go to the front panel. Using the Operating tool, click the Power toggle switch to the TRUE position and run the VI. Your Analog Input Chart should display a voltage signal that appears somewhat distorted due to graphical interpolation effects.
  2. When you turn off the Power toggle switch, a dialog box will appear as before. Type yourname_lab1_ex2b_1Hz_250ms.txt and click Save. This (long) name indicates that the data you saved is from Lab #1, Experiment #2B, in which you sampled a 1 Hz signal every 250 milliseconds.
  3. Disconnect your function generator from the CB-68LP connector block.

Figure 2: CB-68LP connector block

Table 1: CB-68LP connector block pin assignments for measuring a voltage signal using Analog Input Channel 0.

External Signal (from Function Generator) / Connect to:
Analog voltage (Red probe) / Pin 68 (ACH0)
Analog ground (Black probe) / Pin 67[††] (AIGND)

Part 2A

In this experiment, you will replace the random number generator from Part 1A with an analog input VI to acquire data from your DAQ board and plot it to a strip chart.

  1. Open yourname_lab1_ex1a.vi and repeat the instructions on pages 3-15 to 3-18 of the LVQSG, but with the following modification:
  • For the last instruction, save the resulting VI as yourname_lab1_ex2a.vi. You will use this VI in subsequent labs.

Experiment #3: Debugging

In this experiment, you will learn how to use some of the debugging utilities in LabVIEW.

  1. Follow the instructions on pages 5-1 to 5-5 in the LVQSG

Saving Files

Before you leave, remember to save all of your files to a floppy disk (for later use and backup purposes). For this laboratory, you should save the following files from the Desktop:

yourname_lab1_ex1a.vi

yourname_lab1_ex1b.vi

yourname_lab1_ex2a.vi

yourname_lab1_ex2b.vi.

Also save the following text files for later use:

data.txt

yourname_lab1_ex2b_1Hz_250ms.txt.

Laboratory Report

  1. For each of the VI’s you wrote in this laboratory (listed in the preceding section), provide a printout that shows the front panel and block diagram, similar to Figure 3 above. Hints for obtaining these printouts are provided in the Laboratory #1 Supplemental Handout.[‡‡]
  2. Using your favorite graphing program (such as Matlab or MS Excel), plot your voltage data from the yourname_lab1_ex2b_1Hz_250ms.txt file. Comment on the appearance of your data plot. Is aliasing an issue? (Explain your response[§§]). Hints for plotting this data are provided in the Laboratory #1 Supplemental Handout.

Your Lab Report should clearly state your name, Lab Report number (#1 in this case), Lab date, and your laboratory partner’s name (if any). Your lab report should be thorough, but concise. You will be graded on quality, not quantity. Lab Report #1 is due at the beginning of Laboratory #2.

Additional Reading and Practice

  1. LVQSG, Chapter 6. Read this to learn about online help.
  2. LabVIEW User Manual, January 1998 Edition. Feel free to browse through this to explore the programming resources available in LabVIEW. Available online at
  3. If you would like to learn more about the PCI-6024E DAQ Board, you can find its DAQ Specifications at
  4. Feel free to experiment with LabVIEW programming in the CADLab. Doing so is an excellent way to reinforce and expand on the material you learned in today’s laboratory.

Extra Credit Exercise: Observe the Effects of Undersampling

In this extra credit experiment, you will observe aliasing due to undersampling.

  1. Make sure that your function generator is disconnected from the CB-68LP connector block.
  2. Open yourname_lab1_ex2b.vi.
  3. Go to the block diagram. Click on the millisecond multiple control and change it from 250 to 50. This will speed up your sampling (and display) frequency from 4 Hz to 20 Hz.[***]
  4. Following a process similar to what you did in Experiment #2B, generate a 1 Hz sine wave with a 1V amplitude and view it on your oscilloscope.
  5. As you did in Experiment #2B, connect the function generator to the CB-68LP connector block.
  6. Run the VI and save your data as yourname_lab1_extra_1Hz_50ms.txt.
  7. Disconnect the function generator from the CB-68LP connector block.
  8. Following a process similar to what you did in Experiment #2B, generate a 5 Hz sine wave with a 1V amplitude and view it on your oscilloscope. (A frequency of 5 Hz corresponds to a period of 0.2 seconds).
  9. As you did in Experiment #2B, connect the function generator to the CB-68LP connector block.
  10. Run the VI and save your data as yourname_lab1_extra_5Hz_50ms.txt.
  11. Disconnect the function generator from the CB-68LP connector block.
  12. Following a process similar to what you did in Experiment #2B, generate a 15 Hz sine wave with a 1V amplitude and view it on your oscilloscope. (A frequency of 15 Hz corresponds to a period of 0.067 seconds).
  13. As you did in Experiment #2B, connect the function generator to the CB-68LP connector block.
  14. Run the VI and save your data as yourname_lab1_extra_15Hz_50ms.txt.
  15. Disconnect the function generator from the CB-68LP connector block.
  16. Save each of the text files you generated above to your floppy disk.

Lab Report:

  1. Using your favorite graphing program, plot your voltage data from each of the above text files. What is the Nyquist frequency for each of the signals you generated? What is the sampling frequency? Comment on the appearance of your plots.

1

[*] Paragraph excerpts from LabVIEW—Proven Productivity, April 2000 Edition, National Instruments Corporation.

[†] Based on the LabVIEW QuickStart Guide, February 1999 Edition. Available online at

[‡] The PCI-6024E DAQ Board has sixteen 12-bit analog input channels, each with a maximum sampling rate of 200 kS/s.

[§] Therefore, the maximum amplitude will be 1 V.

[**] After inserting the wires, use your screwdriver to tighten the connection.

[††] In addition to pin 67, pin numbers 64, 59, 56, 24, 27, 29, and 32 can also be used for specifying analog input ground (AIGND). In practice, however, it is best to use the AIGND pin that is closest to the analog input.

[‡‡] This will be handed out during Laboratory #1.

[§§] Refer to Mechatronics textbook, Section 7.1.

[***]Because of limitations of the Windows operating system, you should not increase your sampling frequency above 20 Hz for this particular type of VI.