Introduction To LabVIEW
Introduction To LabVIEW
Introduction To LabVIEW
1 Introduction
1.1 Aims
The following material is a short introduction to LabVIEW and it aims for you to:
• familiarise with the LabVIEW programming environment including front panel and block
diagram;
• familiarise with the programming structures and data types that exist in LabVIEW;
It is estimated that this introduction session takes between 1.5 and 2 hours.
Have Fun,
Mohammed El-Hajjar
Rob Maunder
Michael Ng
1
ELEC6021 Research Methods NI USRP Lab 2
The block diagram is formed of the graphical representation of the code for the functions
in the front panel. Figure 2 shows an example block diagram window.
Figure 4 shows a different example with two code segments. In Figure 4, it is not possible
to determine which of the “add”, “random number” and “divide” functions execute first. The
input to the “add” and “divide” functions are available at the same time and the “random
number” function has no input.
2 Exercise 1
In this exercise you will create a VI that simulates an analogue signal and plots it on a waveform
graph. The VI will test the input values against a user-specified limit and light an LED if the
input value exceeds that limit.
ELEC6021 Research Methods NI USRP Lab 4
Launch LabVIEW; you will get a splash screen like the one shown in Figure 5.
Two windows appear: the grey window is the Front Panel and the white one is the Block
Diagram. The Front Panel contains the parts of your VI used for the User Interface and present-
ing information, whereas the Block Diagram contains the code that controls the functionality
of the VI. You can toggle between the two windows by selecting Window>>Show Block
Diagram or Window>>Show Front Panel. You can also switch between the windows by
pressing <Ctrl+E> on your keyboard.
Examine the Front Panel and Block Diagram of this Template VI. The Front Panel contains
a Waveform Chart and a STOP button as shown in the Figure 7.
The Block Diagram in Figure 8 contains a Simulate Signal VI, which is currently configured
to simulate a sine wave and plot it to the chart.
ELEC6021 Research Methods NI USRP Lab 6
Switch back to the Front Panel by pressing <Ctrl+E>. Since the Run button (the white
arrow at the top left corner) is solid, you can run this VI as it is. Click the Run button and
examine the operation of the VI. When you are finished, click the STOP button on the Front
Panel to stop running the VI.
Note: As you will see later in the exercise, when the Run button in the upper left corner
of both the Front Panel and the Block Diagram changes from a solid white arrow to a broken
grey arrow, this new icon indicates that the VI is currently not executable. Pressing it will
reveal the programmatic errors that are keeping it from executing.
Now we can add some functionality to this basic VI. We will modify the VI to flash an
alarm whenever the signal value is above a certain level. Open the Controls palette (if it is not
open already) by right-clicking the Front Panel window. A snapshot of the controls palette
is shown in Figure 9.
ELEC6021 Research Methods NI USRP Lab 7
Navigate to the Express palette and click on the Numeric Controls sub-palette. Select
a Vertical Pointer Slide to be placed on the Front Panel. To do this, click the Vertical
Pointer Slide and drag it onto the Front Panel. A snapshot of the Numeric Controls sub-
palette is shown in Figure 10.
Click the Express menu item on the Controls palette to return to the Express Controls
palette.Then click the LEDs sub-palette shown in Figure 11, and place a Round LED on the
Front Panel.
Right-click the Vertical Pointer Slide and select Properties. A property page will
appear. Make the following changes on the Appearance tab and click OK to apply the
changes. A snapshot of the properties window is shown in Figure 12.
Label: Limit
Slider 1: Check Show digital display(s)
Right-click the Round LED labelled Boolean and select Properties. Examine the different
ELEC6021 Research Methods NI USRP Lab 9
properties that can be modified. On the Appearance tab, change the label from Boolean to
Alarm. Click OK to apply your change. Move the objects on the Front Panel so it resembles
Figure 13.
Switch to the Block Diagram by pressing <Ctrl+E>. Double-click the Simulate Signal
Express VI to bring up its properties window. Examine the different properties you can modify.
Change the Amplitude of the signal to 10. Click OK to apply this change and to close the
properties window.
Bring up the Functions palette by right-clicking on the Block Diagram. Select Ex-
press>>Signal Analysis as shown in Figure 14 and place the Amp&Level Express VI on
the Block Diagram by dragging and dropping as before.
When you place an Express VI on the Block Diagram a dialog box appears so that you can
configure the function as per your needs. For this function select RMS as shown in Figure 15.
You can connect Controls, Functions, and Indicators on the Block Diagram by pointing to
an object and clicking on its terminal when the cursor changes to a spool of wire. You can
then move the cursor to the terminal of the object you want to connect it to and click again.
Following this, connect the Limit control to the Alarm indicator as shown in Figure 16.
Figure 16
Note: The Run button in the upper left corner of both the Front Panel and the Block
Diagram has changed from a solid white arrow, to a broken grey arrow. This new icon indicates
that the VI is currently not executable. If you click the Run button when it is solid and white,
it runs the VI. Clicking it when it is broken and grey brings up a dialog box that will help you
debug the VI.
Click the Run button now. The resulting dialog box shows that, in this case, the error
results from connecting terminals of two different types. Since the Limit control is a Numeric
type and the Alarm indicator is a Boolean type, we cannot wire these two terminals together.
Highlight the error by clicking it, and then click Show Error. LabVIEW will highlight the
location of the error.
Notice that the wire between Limit and Alarm is dashed and a red ”X” is displayed on it
as shown in Figure 17.
To delete this broken wire, press <Ctrl+B>. This keyboard shortcut removes all broken
wires from the Block Diagram.
ELEC6021 Research Methods NI USRP Lab 11
Figure 17
Wire the output of the Simulate Signal VI to the Signals input on the Amplitude and
Level Measurements VI. Right-click on the RMS output and select Create>>Numeric
Indicator from the list as shown in Figure 18.
Bring up the functions palette by right-clicking the Block Diagram. Select Arithmetic &
Comparison >> Comparison and place the Comparison Express VI shown in Figure 19
on the diagram.
ELEC6021 Research Methods NI USRP Lab 12
When you place the Comparison Express VI on the Block Diagram, a dialog box appears
that lets you configure what type of comparison you will be doing. Make the following selections
as shown in Figure 20, then click OK to apply these changes and to close the dialog box.
Compare Condition: Greater
Comparison Inputs: Second signal input
1. Wire the Limit control to the Operand 2 input of the Comparison function.
ELEC6021 Research Methods NI USRP Lab 13
2. Connect the RMS output of the Amplitude and Lever Measurements block to the Operand
1 input of the Comparison block.
3. Wire the Result output of the Comparison block to the Alarm indicator.
While the VI is running you can change the Limit value. Also notice that when a data point
received from the Simulate Signal VI is greater than the Limit value, the Alarm indicator
lights up.
While the VI is still running, switch to the Block Diagram by pressing <Ctrl+E>. Enable
Highlight Execution by clicking on the light bulb on the tool bar shown in Figure 22. This
will allow you to see the flow of data through your program.
Figure 22
When you are finished, stop the VI by clicking the STOP button on the Front Panel.
ELEC6021 Research Methods NI USRP Lab 14
Take a few minutes to explore other topics in the help system. Click on the Search tab and
try searching for analysis functions with features you might need in your work applications.
Figure 24