Professional Documents
Culture Documents
Signals, Spectra and Signal Processing GETTING FAMILIAR WITH LABVIEW (PART I) Activity No. 1 I. INTENDED LEARNING OUTCOMES 1. Familiarize oneself with the programming environment of LabVIEW. 2. Build a simple virtual instrument (VI) that uses commonly-used functions, controls and indicators of LabVIEW. 3. Create sub-VIs and use them in the development of more complex VIs. 4. Use the While-Loop structure in the development of a continuously running VIs. 5. Create a VI using an array and For-Loop. 6. Use the Help function of LabVIEW. II. BACKGROUND INFORMATION LabVIEW (Laboratory Virtual Instrumentation Engineering Workbench) is a graphical programming environment developed by National Instruments (NI), which allows high-level or system-level designs. It uses a graphical programming language to create so-called Virtual Instruments (VI) blocks in an intuitive flowchart-like manner. A design is achieved by integrating different components or subsystems within a graphical framework. LabVIEW provides data acquisition, analysis and visualization features well suited for various applications. It is also an open environment accommodating C and MATLAB codes, as well as ActiveX and DLLs (Dynamic Link Libraries).
LabVIEW constitutes a graphical programming environment that allows one to design and analyze a system in a shorter time as compared to text-based programming environments. LabVIEW graphical programs are called virtual instruments (VIs). VIs run based on the concept of data flow programming. This means that execution of a block or a graphical component is dependent on the flow of data, or more specifically a block executes when a data is made available at all of its inputs. Output data of the block are
Page 1
In this activity as well as in the next activity, the LabVIEW environment will be explored and basic VIs will be created.
III. LEARNING ACTIVITIES Activity 1.1 Building a Simple VI. 1. Open LabVIEW by double clicking the LabVIEW icon in the desktop or access it through the Start button of the Windows. The Getting Started window appears. Click on the Blank VI option to start from scratch.
2. Two new windows should appear: the Block Diagram (BD) window and the Front Panel (FP) window, as shown below.
Page 2
Note: It is encouraged that a folder be created where VIs can be organized by activity. It is possible that future activities will use VIs that were created in earlier activities. Also, ensure that a regular back-up of files be done as the computers in the laboratory are shared by everyone.
An FP contains the user interfaces of a VI shown in BD. Inputs to a VI are represented by so-called controls. Knobs, pushbuttons and dials are a few examples of controls. Outputs from a VI are represented by so-called indicators. Graphs, LEDs (light indicators), and meters are a few examples of indicators.
Page 3
LEDs palette
All of these can be accessed via the controls palette by right-clicking on an empty space on the front panel or via View > Controls Palette. A BD contains terminal icons, nodes, wires and structures. Terminal icons are interfaces through which data are exchanged between an FP and a BD. Terminal icons correspond to controls or indicators that appear on an FP. Whenever a control or indicator is placed on an FP, a terminal icon gets added to the corresponding BD. Place a numeric control on the front panel (right-click on an empty space on FP or View > Controls Palette, Express, Numeric Control). Click on Num Ctrl and then drop onto the FP.
Page 4
Notice that when a numeric control is placed onto the FP, a terminal icon of the same name appeared on the BD, as shown. The FP and BD windows can be switched by pressing Ctrl+E. Note: When opening saved VIs, only the FP appears (try this by closing act01-01.vi and then opening the file again). Use Ctrl+E to make BD appear in this case.
Rename this Numeric Control as x by typing x when the Numeric label is selected (at the instance that a control or indicator is placed, its label is automatically selected). Note that the numeric control FP and its corresponding terminal icon in the BD are renamed. Put another Numeric Control and two Numeric Indicators and name them as y, Sum, and Average respectively.
Page 5
3. A node represents an object which has input and/or output connectors and performs a certain function. A subVI (a VI that is used in another VI) and functions are examples of nodes. Functions and subVIs can only be placed in the BD. The Functions palette be accessed by clicking View > Functions Palette or by right-clicking empty space in the BD.
Page 6
Place an Add function in the block diagram. This can be accessed in the Functions > Express > Arith & Comparison > Numeric. Click and drop the Add node in the BD.
Note: Use the Search button in the Functions palette to search for BD functions. Type the name of the function (or some parts of it) and look for it in the list that the query generates. Then either double-click the selection to open the location of the function, or drag and drop the name from the list onto the BD.
Page 7
Place a Divide function in the BD. The Add function will get the sum of the two inputs x and y, while the Divide function will divide the sum by 2 to get their average.
Note: Make the label of the nodes visible by right-clicking the node, select Visible Items and checking the Label option. 4. Wires establish the flow of data in the BD. To connect the x control icon with the Add function, click on the x terminal icon, and then click on the one of the inputs of the Add function.
Activity No. 1 Getting Familiar with LabVIEW (Part I) Page 8
When it is fully connected, it becomes a solid line, whose color depends on the data type that it carries. There are basically three data types that LabVIEW supports: numeric, Boolean, and string. Numeric data represent numbers, which can be floating-point numbers (numbers with fractional parts) or integers (whole numbers). Boolean data represent those that have only two states: 1 or 0. String data represent alphanumeric characters. The table below summarizes the wire color representation of data types and their dimensions.
Note: These color representations are also applicable to the borders of terminal icons.
Activity No. 1 Getting Familiar with LabVIEW (Part I) Page 9
Note: Broken wires occur for a variety of reasons, such as when two objects with incompatible data types are wired. Broken wires can be removed by pressing Ctrl+B.
Note: Terminal icons, by default, are viewed as icon. For more compact BDs, right-click on a terminal icon, then uncheck the View As Icon option.
Page 10
Since the average of x and y must be taken and displayed in the Average indicator, the sum of the two inputs should be divided by two. The first input to the Divide function is the sum of the two inputs; the second input should be a constant. To insert a constant, right-click on the other input of the Divide function and choose Create > Constant. Type the number 2 when the constant node appears.
Note: Observe all the screenshots before the above screenshot. The Run arrow in the previous screenshots are broken, which means that the program contains error and it cannot be executed. Once the program is error-free, the icon appears like the one shown above. 5. Save the program. Test the functionality of the program by putting values in the controls of the FP and clicking the Run button.
Page 11
Note: After building the block diagram, it can be made more compact and professional looking by clicking the Clean Up Diagram icon in the BD window.
Activity 1.2 Creating SubVI 1. A subVI is a VI that is used in a higher-level VI. If a VI is to be used as a subVI, its connector pane needs to be configured. A connector pane assigns inputs and outputs of a subVI to its terminals through which data are exchanged. The icon at the top-right corner of the FP or BD is the icon that represents the VI once it is used as a subVI.
Page 12
2. To assign controls and indicators to the connector pane, click on one of the slots of the pane and click a control or indicator to be assigned on that slot. Remember, controls are assigned to the left of the connector pane while indicators are assigned to the right.
Page 13
Note: A subVI can also be created from a section of a VI. Use the Help function of LabVIEW to find out how to do this. Click Help > LabVIEW Help, or press Ctrl+? or F1 to bring out the Help window of LabVIEW. On the left pane, select the Search tab, then type Creating SubVIs from Sections of a VI to list topics related to this. This should generate an article about creating subVIs from a section of a VI. Activity 1.3 Using Structures and SubVIs 1. Create a new VI named as act01-03. This VI will show the sum and average of two input values in a continuous fashion. The two inputs can be altered by the user. If the average of the two inputs becomes greater than a preset threshold value, a LED warning light is lit.
Page 14
Input 1 and Input 2 are Knobs. The size of the knobs can be adjusted by selecting it and dragging the edges of the selection to the desired size. Right-click the Input 1 knob and choose Properties; the Knob Properties window appears. Click the Data Type tab. The default data type of this control is Double Precision (DBL). Change this to Byte (I8) type. Click OK. Note: This step can also be accomplished by right-clicking the knob then choosing Representation > Byte (I8). For the Input 2 knob, leave the data type as double precision. For both of the knobs, set both to zero, right-click the knob, then choose Data Operations > Make Current Value Default to make the default value of the knobs 0. The Warning LED is a Rounded LED indicator. The Average is a Gauge. The Sum is a Numeric Indicator. Place all of these in the FP and resize them accordingly.
3. At this point, there should be five terminal icons in the BD, corresponding to the controls and indicators in the FP. Build the BD as shown.
Page 15
4. For the VI to run continuously, the program must be enclosed in a While structure. The While structure makes the function inside it run continuously (or stop indefinitely) until a condition is met. In this case, it is required that the program runs until a Stop button is pressed. The While structure is accessed by rightclicking an empty space in the BD, choose Express > Exec Control > While Loop. Drag the mouse until the entire program in the BD is enclosed within the While structure. The final FP and BD should look like the one below.
Note: Notice that when the While structure is placed, a Stop button is automatically inserted. This is the necessary condition that the loop will terminate. In general, a While loop must have a terminating condition or it will run indefinitely. A structure in LabVIEW is represented by a graphical enclosure. The graphical code enclosed by a structure is repeated or executed conditionally. A loop structure is equivalent to a for-loop or a while-loop statement encountered in text-based programming languages, while a case structure is equivalent to an if-
Page 16
Page 18
Question: Compare the wires connecting the indicators to the tunnels. Why is this so? _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________
Page 19
Expand the boxes for the Current Output and Output without Indexing. Drag the Output with Indexing downwards until ten indicators appear. Note: The Output with Indexing is an array indicator; it holds values in an array. The number of elements that is held by this array depends on how many iterations the For-Loop has, which in this case, ten. The index of an array always starts from zero; thus the first element of the Output with Indexing array has an index of zero, and the last element has an index of nine. 3. Save the VI and run the program. Question: Describe the functionality of the program. Compare the output of the Output with Indexing and Output without Indexing indicators. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________
Page 20
Page 21