CSE-471 Lab 01
CSE-471 Lab 01
CSE-471 Lab 01
MAX MARKS
Q. No. CLOs
MARK OBTAINED
1
2
3
4
5
6
7
TOTAL MARKS
PERFORMANCE OBJECTIVES:
Upon completion of this laboratory exercise, the student technicians/engineers will be able to:
1. Work with LABVIEW programming environment, the front panel and block diagram.
2. Write a simple Virtual Instrument (VI) to incorporate basic operations in LABVIEW.
3. Convert their programs into subVIs by creating an icon and connector pane.
EQUIPMENT:
1 LABVIEW equipped PC
DISCUSSION:
LABVIEW ENVIRONMENT BASICS
LABVIEW is a graphical programming language that uses icons instead of lines of text to
create applications. In contrast to text-based programming languages, where instructions
determine program execution, LABVIEW uses dataflow programming, where the flow of data
determines execution. In LABVIEW, user interface is built by using a set of tools and objects.
The user interface is known as the front panel. The code is then added using graphical
representations of functions to control the front panel objects. The block diagram contains this
code. In some ways, the block diagram resembles a flowchart. LABVIEW programs are called
virtual instruments, or VIs, because their appearance and operation imitate physical
instruments, such as oscilloscopes and multimeters. Every VI uses functions that manipulate
input from the user interface or other sources and display that information or move it to other
files or other computers. A VI contains the following three components:
FRONT PANEL
The front panel is the user interface of the VI. A front panel is built with controls and
indicators, which are the interactive input and output terminals of the VI, respectively. Controls
are knobs, pushbuttons, dials, and other input devices. Indicators are graphs, LEDs, and other
displays. Controls simulate instrument input devices and supply data to the block diagram of
the VI. Indicators simulate instrument output devices and display data the block diagram
acquired or generated.
BLOCK DIAGRAM
After building the front panel, the code is then using graphical representations of functions to
control the front panel objects. The block diagram contains this graphical source code. Front
panel objects appear as terminals on the block diagram. Additionally, the block diagram
contains functions and structures from built-in LABVIEW VI libraries. Wires connect each of
the nodes on the block diagram, including control and indicator terminals, functions, and
structures.
LABVIEW PALETTES
LABVIEW palettes give user options that are needed to create and edit the front panel and
block diagram.
The Tools palette is available on the front panel and the block diagram. A tool is a special
operating mode of the mouse cursor. When a tool is selected, the cursor icon changes to the tool
icon that is used to modify front panel and block diagram objects. The tool palette is displayed
by selecting Tools palette in the View option of the main menu. If automatic tool selection is
enabled LABVIEW automatically selects the corresponding tool from the palette when the
cursor is moved over objects on the front panel or block diagram.
The Controls palette is available only on the front panel. The Controls palette contains
controls and indicators which are used to create the front panel. The Controls palette is
displayed by selecting Controls Palette in the View option of the main menu or by clicking the
right button of the mouse on the front panel.
The Functions palette is available only on the block diagram. The Functions palette contains
the VIs and functions which are used to build the block diagram. The Functions palette is
displayed by selecting Funtions Palette in the View option of the main menu or by clicking the
right button of the mouse on the block diagram.
DATAFLOW PROGRAMMING
LABVIEW follows a dataflow model for running VIs. A block diagram node is executed when
all its inputs are available. When a node completes execution, it supplies data to its output
terminals and passes the output data to the next node in the dataflow path.
CREATING SUBVIs
After building a VI, it can be used in another VI by creating its icon and connector pane. A VI
called from the block diagram of another VI is called a subVI. A subVI corresponds to a
subroutine in text-based programming languages. A subVI node corresponds to a subroutine
call in text-based programming languages. The node is not the subVI itself, just as a subroutine
call statement in a program is not the subroutine itself.
To define a connector pane, right-click the icon in the upper right corner of the front panel
window and select Show Connector from the shortcut menu. The connector pane replaces the
icon. Each rectangle on the connector pane represents a terminal as shown in figure 1.4. These
rectangles are used to assign inputs and outputs. The number of terminals LABVIEW displays
on the connector pane depends on the number of controls and indicators on the front panel. The
connector pane has, at most, 28 terminals. If front panel contains more than 28 controls and
indicators then some of them are grouped into a cluster which is assigned to a terminal on the
connector pane. A different terminal pattern may be selected for a VI by right-clicking the
connector pane and selecting Patterns from the shortcut menu. A pattern with some
unconnected terminals may be used in the future use. This flexibility enables developers to
make changes with minimal effect on the hierarchy of the VIs. If a group of subVIs is created
that they can be used together often by giving the subVIs a consistent connector pane with
common inputs in the same location which help users remember where to locate each input. For
a subVI that produces an output that another subVI uses as the input, it is better to align the
input and output connections to simplify the wiring patterns. A good practice is to place the
error in clusters on the lower left corner of the front panel and the error out clusters on the
lower right corner.
SETTING REQUIRED, RECOMMENDED, AND OPTIONAL INPUTS
AND OUTPUTS
The programmer can designate which inputs and outputs are required, recommended, and
optional to prevent users from forgetting to wire subVI connections. To do that Right-click a
terminal in the connector pane and select This Connection Is from the shortcut menu. A
checkmark indicates the terminal setting, select Required, Recommended, or Optional.
For terminal inputs, Required means that the block diagram on which the subVI is dropped
will be broken if the required inputs are not wired. Required is not available for terminal
outputs.
For terminal inputs and outputs, Recommended means that the block diagram on which the
subVI is dropped can be run if the input is not wired but the Warnings dialog box will generate
a warning that the input has not been wired.
Optional means that the block diagram on which the subVI is dropped can be run and will not
generate any warnings if the terminal input or output is not wired. Inputs and outputs of VIs in
vi.lib are already marked as Required, Recommended, or Optional. LABVIEW sets inputs
and outputs of VIs you create to Recommended by default. Set a terminal setting to required
only if the VI must have the input or output to run properly.
In the Context Help window, Required connections are bold, Recommended connections are
plain text, and Optional connections are dimmed if the Detailed view is selected or do not
appear if the Simple view is selected.
CREATING AN ICON
Every VI displays an icon in the upper right corner of the front panel and block diagram
windows. An icon is a graphical representation of a VI. It can contain text, images, or a
combination of both. If a VI is used as a subVI, the icon identifies the subVI on the block
diagram of the VI. The default icon contains a number that indicates how many new VIs the
user has opened since launching LABVIEW. Custom icons are created to replace the default
icon by right-clicking the icon in the upper right corner of the front panel or block diagram and
selecting Edit Icon from the shortcut menu or by double-clicking the icon in the upper right
corner of the front panel. A graphic from anywhere in your file system can be dragged and
dropped in the upper right corner of the front panel or block diagram. LABVIEW converts the
graphic to a 32 X 32 pixel icon. Depending on the type of screen used, a separate icon may be
used for monochrome, 16-color, and 256-color mode. LABVIEW uses the monochrome icon
for printing.
CREATING SUBVIS FROM SECTIONS OF A VI
To convert a section of a VI into a subVI the section of the block diagram is selected first. From
Edit menu Create SubVI is selected then, an icon for the new subVI replaces the selected
section of the block diagram. LABVIEW creates controls and indicators for the new subVI and
wires the subVI to the existing wires. Creating a subVI from a selection is convenient but still
requires careful planning to create a logical hierarchy of VIs.
TASK-1A
ENTERING FORMULA IN LABVIEW VIRTUAL INSTRUMENT (VI)
The formula for converting degrees Celsius to degrees Fahrenheit is as follows:
℉ = (1.8 × ℃) + 32
For example, to convert a temperature of 100 degrees Celsius into degrees Fahrenheit, first the
Celsius temperature reading is multiplied by 1.8 to get 180 and then 32 is added to get 212
degrees Fahrenheit.
PROCEDURE:
1. Launch LABVIEW from Start » Programs » National Instruments LABVIEW Click New
VI to open a new front panel.
2. (Optional) Select Window » Tile Left and Right to display the front panel and block
diagram side by side.
3. Create a numeric digital control. You will use this control to enter the value for degrees
Centigrade.
a. Select the digital control on the Controls » Numeric palette. If the Controls palette is not
visible, right-click an open area on the front panel to display it.
b. Move the control to the front panel and click to place the control.
c. Type deg C inside the label and click outside the label or click the Enter button on the
toolbar, shown at left. If you do not type the name immediately, LABVIEW uses a
default label. You can edit a label at any time by using the Labeling tool, shown at left.
4. Create a numeric digital indicator. You will use this indicator to display the values of
degree Fahrenheit.
a. Select the digital indicator on the Controls » Numeric palette.
b. Move the indicator to the front panel and click to place the indicator.
c. Type deg F inside the label and click outside the label or click the Enter button.
LABVIEW creates corresponding control and indicator terminals on the block diagram. The
terminals represent the data type of the control or indicator. For example, a DBL terminal,
shown at left, represents a double-precision, floating-point numeric control or indicator.
d. Use the Pencil tool to create the arrow. To draw horizontal or vertical straight lines,
press the <Shift> key while you use the Pencil tool to drag the cursor.
e. Use the Select tool and the arrow keys to move the text and arrow you created.
f. Select the B&W icon and select 256 Colors in the Copy from field to create a black and
white icon, which LABVIEW uses for printing unless you have a color printer.
g. When the icon is complete, click the OK button to close the Icon Editor dialog box. The
icon appears in the upper right corner of the front panel and block diagram.
18. Right-click the icon on the front panel and select Show Connector from the shortcut menu
to define the connector pane terminal pattern. LABVIEW selects a connector pane pattern
based on the number of controls and indicators on the front panel. For example, this front
panel has two terminals, deg C and deg F, so LABVIEW selects a connector pane pattern
with two terminals.
19. Assign the terminals to the digital control and digital indicator.
a. Select Help » Show Context Help to display the Context Help window. View each
connection in the Context Help window as you make it.
b. Click the left terminal in the connector pane. The tool automatically changes to the
Wiring tool, and the terminal turns black.
c. Click the deg C control. The left terminal turns orange, and a marquee highlights the
control.
d. Click an open area of the front panel. The marquee disappears, and the terminal changes
to the data type color of the control to indicate that you connected the terminal.
e. Click the right terminal in the connector pane and click the deg F indicator. The right
terminal turns orange.
f. Click an open area on the front panel. Both terminals are orange.
g. Move the cursor over the connector pane. The Context Help window shows that both
terminals are connected to floating-point values.
20. Select File » Save to save the VI.
21. Select File » Close to close the VI.
TASK-1B
ENTERING FORMULA IN LABVIEW VIRTUAL INSTRUMENT (VI)
Repeat TASK1A to convert temperature from degree Fahrenheit to degree
Celsius and answer the following:
1) Conversion formula:
3) For the following values of temperature given in degree Fahrenheit write down the output in
Table 1.1.
Table 1.1
Temperature
S. No. Degree Fahrenheit Degree Celsius
1 -40
2 32
3 100
4 200
5 212
TASK-2
CREATING A SubVI IN A GIVEN VI
The formula for the slope of a line is as follows:
(𝑦2 − 𝑦1)
𝑆𝑙𝑜𝑝𝑒 =
(𝑥2 − 𝑥1)
where (X1, Y1) and (X2, Y2) are points on the line. Using following front panel as reference
design a VI in LABVIEW to calculate the slop of the line.
PROCEDURE:
1) Using the techniques learned in TASK 1; create a VI to calculate the slope of a line.
2) Transform the code into a subVI using the Edit » Create SubVI method.
3) Save the VI as Slope.vi.
4) Save the subVI as SlopeSub.vi.
5) The front panel, block diagram and SubVI should resemble the followings diagrams.
TASK-3
FIRST ORDER RESPONSE
The voltage across capacitor 𝑣𝑐 (𝑡) in the following circuit can be expressed using first order
response equation.
𝑡
𝑣𝑐 (𝑡) = �𝑣𝑓 − 𝑣𝑖 � �1 − 𝑒 −𝑅 �
Where
Final voltage at t = a
Initial voltage at t = 0
Resistor
Capacitor
Create a VI that will calculate 𝑣𝑐 (𝑡) for the values of time t specified in table 1.2.
Assume capacitor was initially uncharged.
Table 1.2
REVIEW QUESTIONS
Write a VI to convert given seconds into hours, minutes and seconds and shows the
results on the front panel. Write down the corresponding results in the space by using
1. the given data in the following table. Save VI as secondsconverter.vi.
[Hint: In Functions palette of block diagram use Quotient and Remainder function in
the numeric sub palette]
Input Output
S. No.
Seconds Hours Minutes Seconds
1 00180
2 03000
3 03661
4 43110
5 86463
Design a VI that adds, subtracts, multiplies, divides, and averages two numbers as
2.
inputs and displays the results on the front panel. Save your VI as Calculator.vi
3. What is a VI? What are the three main parts of a VI? Describe each.
FINAL CHECKLIST
All the students must make sure, before they leave the Lab:
1. Clean your equipment, materials, and work benches before you leave.
2. Return all equipment and materials to their proper storage area.
3. Submit your lab report and answers to the questions, together with your data, calculations (if any) and
results before the next laboratory sessions.