Introduction to Labview part 1




Yüklə 19.92 Kb.
tarix28.02.2016
ölçüsü19.92 Kb.
Introduction to LabVIEW - Part 1
As you are by now aware, LabVIEW is a digital data acquisition program that accepts digital data inputs from an A/D board, and processes and displays them in any number of ways. LabVIEW programs are called virtual instruments because the Display Panel (one of the LabVIEW) screens can be configured to look like the panel of an instrument. LabVIEW files are, for this reason, given the suffix .vi and LabVIEW programs are often called vi’s (virtual instruments).

LabVIEW has several interesting features. One is that it is a hierarchical language, which means that smaller LabVIEW programs can be used as subunits of larger programs. Used in this manner, the smaller programs resemble subroutines in text-based computer languages. The other feature, which makes it quite different from any other programming language with which you are probably familiar, is that it is a graphical programming language, in contrast to a text-based language such as Fortran or C. This means that programs, or VI’s, are created by selecting graphical elements from a series of menus and connecting them to each other. This connection process, which indicates the path of data flow, is called “wiring”.

Each LabVIEW VI has three main parts: the Display Panel, the Diagram Panel, which contains the actual program in graphical form, and the icon which serves to identify the VI’s. The actual programming is done on the Diagram Screen. However the program is executed from, and the results displayed on, the Display Panel screen.

In the following, you will learn how to construct a simple LabVIEW VI and, from it, how to create a sub-VI. We assume that the computer obtains voltage inputs from a thermocouple. A thermocouple is a type of transducer that we will encounter later in the course, and which produces a voltage that is linearly proportional to temperature. We wish to convert these voltage readings to temperature and to display the results. We begin by starting up the LabVIEW program from the Windows screen. The initial display is a blank Display Panel.


A. Creating a VI for Temperature Measurements
1. Obtain the Controls and Tools palettes:

a. In the Windows menu, chose ShowControlPalette

b. Again, in the Windows menu, chose ShowToolsPalette
2. Now we create a thermometer indicator and place it in the Panel Window.

a. In the Controls palette, click on the Numeric subpalette (top left button). Choose the thermometer icon (3rd row, 5th column).

b. Click on the thermometer icon, and release the button. Move the mouse pointer to the location where you wish to locate the icon, somewhere in the right-half of the panel window. A dotted line with the outline of the icon will appear. Click again to fix the location of the icon.

c. Enter the word “Thermometer” in the gray text box above the numerical box (currently with 0.00 displayed in it), and click the left mouse button in a blank part of the panel.

d. The temperature scale on the thermometer currently reads 0.010.0. Change this by choosing the labeling tool marked A on the Tools panel. Then double-click on the number 10.0 on the scale. Type in 100.0, and click the left mouse button, or click on the Enter button on the toolbar above.
3. Place a switch for choosing the desired temperature (Fahrenheit or Celsius) on the Panel Window.
a. In the Controls panel, you will find a toggle switch. By placing the cursor on this switch, you will see that it is named Boolean. Pop-up this subpalette by clicking on it, and you will see a number of different switches. Choose the Vertical Slide switch located on the 3rd row, 6th column.

b. Click on this switch. Drag it to a location somewhere in the left-half of the panel window. Be sure not to overlap the thermometer icon you have located previously on the panel. Click again to fix the location of the switch.



c. Just above the switch is a highlighted text box. Type in the word TempScale, and then click the mouse button, or click on the Enter button.

d. Place a label “deg F” on the lower right or left side of the switch and another label “deg C” just above the first label. At this point, your front panel display should look approximately like that shown at right.


4. Up to this point, we have been working on the Panel Window. Now we need to actually construct a program to give some functionality to the icons we have placed on the Panel Window. Open the Diagram Window by clicking the mouse button in the window just behind the Panel Window. The Diagram Window has a white background. On it are two objects with the label you have typed in earlier.


5. Gather all the icons shown at right into your Diagram Window, by clicking on them and dragging them to the approximate location shown on the figure on the next page.


  1. The DemoVoltageRead VI is a random number generator that simulates a voltage from Channel 0 of an A/D board. In the Functions palette (popped-up when your Diagram Window was chosen earlier), point your cursor to the mortar board icon located at the 5th row and 2nd column. A pop-up window called Tutorial will appear. Click the icon shown at the left of the pop-up window, called DemoVoltageRead.VI.

The Multiply, Subtract, and Divide functions, located on the Numeric subpalette, behave exactly as their name implies. The Comparison subpalette is located on the 3rd row, 1st column of the Functions palette. The Select function on this subpalatte performs a switch, depending upon the choice made at the TempScale switch. The output for the temperature reading will then be either Fahrenheit (F) or Celsius (T).

Finally, the Numeric Constant function is located on the 5th row, 1st column of the Numeric subpalette. You will need four of these, with the following numeric constants entered: 1, 100.0, 32.0, and 1.8. To change the values in any of these functions, use the Labeling Tool A, and double-click inside the objects before typing in the appropriate numerical values.

The last function we will need is the String Constant function (not shown in the figure) located at the 5th row, 1st column of the String subpalette within the Functions palette. To change the value within this function, use the Labeling Tool A as before. Enter the value 0 here.
7. In the Tools palette, choose the Positioning Tool . Place the objects on the Diagram Window in approximately the desired positions. Then choose the Wiring Tool, which looks like a spool of wire, to wire them as shown in the diagram. To wire, place the wiring tool at the correct location in the icon from which you wish to wire. The icon terminal from which you are wiring will begin to flash, and the function of the terminal will be displayed. Click the mouse to anchor one end of the wire at the icon terminal. Then move the mouse to indicate the wiring path. As you will see, the wire will make only one right angle turn. To make more than one right-angle turn, click the mouse to anchor the end of the wire. Then click again to begin a new wire from the anchor location. The end of the wire will terminate in the appropriate terminal of the icon you select. Again, the terminal will flash and its function will be displayed when the wiring tool is in the correct location. Click to anchor the wire at this location. Bad wires, which can result from a number of causes, will be displayed as dashed lines. You can remove these by selecting RemoveBadWires from the Edit menu, or by clicking on the bad wires with the Positioning Tool and then using the Delete key. When you have finished, your Diagram Window should look approximately like that shown.



Help: At the Help menu, choose ShowHelp. A Help Window will appear. Point to the various objects, to see with what information the Help Window provides you.

You need to understand the program that you have just created. The DemoVoltageRead.vi is essentially a random number generator that simulates a voltage at Channel 0 of the A/D board (Device 1). We assume that the input voltage is such that a simple multiplication by 100 will convert it to a temperature in F. In this application, the DemoVoltageRead.vi multiplies the voltage by 100.0 to convert it to a temperature in F. On the top branch of the Select Function icon, however, the value is first decreased by 32 and then divided by 1.8 to obtain the temperature in C. The Select Function icon takes its cue from the TempScale object, which has the value of True or False, depending on the position of our vertical slide switch (up is True, down is False). Depending upon the True/False state at the Select Function icon, the temperature reading in C or F is then displayed on the thermometer. On the Diagram Window, this is represented by the DBL icon associated with the thermometer on the Panel Window.
8. We are now ready to run this “experiment”. Activate the Panel Window by selecting it with your mouse. The program will run continuously if you click on the Continuous Run button in the Panel Window. When you have finished, you may terminate execution by again clicking on the Continuous Run button or upon the Stop button.

B. Creating your personal icon for this virtual instrument




The icon at the top right-hand corner of the Panel Window is a temporary icon. You can change that icon by following these steps:
1. Double-click on the icon in the top right-hand corner of the Panel Window. The default icon is shown.
2. Erase the default icon by double-clicking on Select Tool (4th row, 1st column) and pressing the delete key on your keyboard.
3. Draw an icon that represents a thermometer, similar to the one shown, using the Drawing Tool, which has a pencil-shaped icon. Tip: Holding down the Shift key while using the Drawing Tool will give either a perfectly vertical or perfectly horizontal line, depending upon the direction in which you are drawing. Also note that the Drawing Tool will function as an eraser, if you click upon an already-drawn pixel.
4. Enter the word Temp on the icon. You may do this by using the Drawing Tool directly, or by using the Text Tool A. Double-click on the Text Tool to reduce the font size to a smaller font.
5. Close the Icon Editor by clicking on “OK” when your are finished with your icon construction. The icon you have just created now appears at the top right-hand corner of both the Panel and the Diagram Windows.
C. Converting your VI to a sub-VI

You have just created your own VI. You may now wish to use this VI as a component of a larger VI. In this context, it becomes a sub-VI, not unlike a subroutine in a Fortran program. To convert your VI to a sub-VI, carry out the following steps.




1. Create a connector by popping-up on the icon at the top right-hand corner. This means that you will point to it with the mouse and click the right mouse button. Choose ShowConnector from the pop-up menu. LabVIEW will automatically select a terminal pattern based upon the number of inputs and outputs in your Panel Window. It will look something like that shown in the figure at right. In this case, we have two terminals, one for the vertical slide switch, and the other for the thermometer indicator.
2. Assign your vertical slide switch to the left terminal. Use the Wiring Tool and click on the left-hand terminal on your icon (top right corner). That terminal will turn black. Likewise, use the Wiring Tool to click on the vertical slide switch in the Panel Window. A dashed line will frame the switch.
3. Assign the Thermometer indicator to the right terminal. The procedure is similar to that described in the previous step. Use the Wiring Tool and click on the right-hand terminal. It will turn black. Then use the Wiring Tool and click on the thermometer indicator. A dashed line will frame the indicator. Now click in an open area and the dashed lines will disappear. The two terminals will turn gray. This means that the terminals have been connected to the correct devices (left terminal to the switch, right terminal to the indicator). The input is now on the left terminal, the output on the right terminal.
4. Now save your Sub-VI, by choosing File and then Save. On a floppy disc, name your VI temp.vi (or anything else that you like, as long as you use a *.vi suffix) and save it. Your VI is now ready to be used as a sub-VI.
5. Close the VI by selecting File and then Close. To find and use your newly created VI as a sub-VI, click on the Diagram Window. In the Functions palette, click the SelectAVI icon located at the bottom right corner of the palette. Form the file dialog box, select the VI that you have created (or any other VI that is already created).


  1. You may now exit LabVIEW by selecting File and then Close.


Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azrefs.org 2016
rəhbərliyinə müraciət

    Ana səhifə