0% found this document useful (0 votes)
8 views61 pages

Module 2 - MVJ22EC643 - Virtual Instrumentation

The document outlines the syllabus for a course on Virtual Instrumentation, focusing on modular programming in LabVIEW. It covers essential topics such as creating VIs, building front panels and block diagrams, and utilizing loops and arrays. Additionally, it provides detailed instructions on creating icons, connector panes, and managing subVIs to enhance code readability and reusability.

Uploaded by

zakiking612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views61 pages

Module 2 - MVJ22EC643 - Virtual Instrumentation

The document outlines the syllabus for a course on Virtual Instrumentation, focusing on modular programming in LabVIEW. It covers essential topics such as creating VIs, building front panels and block diagrams, and utilizing loops and arrays. Additionally, it provides detailed instructions on creating icons, connector panes, and managing subVIs to enhance code readability and reusability.

Uploaded by

zakiking612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

An Autonomous Institute

Affiliated to VTU, Belagavi,


Approved by AICTE, New Delhi,
Recognized by UGC with 2(f) & 12(B)
Accredited by NBA & NAAC

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


SUBJECT CODE : MVJ22EC643
SUBJECT NAME: VIRTUAL INSTRUMENTATION

FACULTY : Dr.M.Thilagaraj, Associate Professor, IIOT.

1
1
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B) s
Syllabus
Module 2:

MODULAR PROGRAMMING: Modular Programming in LabVIEW, Build A VI


Front Panel and Block Diagram, Creating an Icon, Building a Connector Pane,
Creating, Opening And Editing SUBVIs.

REPETITION AND LOOPS: For Loops, While Loops, Structure Tunnels,


Terminals Inside Or Outside Loops, Shift Registers, Feedback Nodes, Control
Timing, Communicating Among Multiple Loops, Local & Global Variables.

ARRAYS: Creating 1-D, 2-D And Multidimensional Arrays, Deleting, Inserting,


Replacing, Elements, Array Functions, Matrix Operations with Arrays,
Polymorphism.
2
2 2 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Modular Programming - Introduction
• Modular programming refers to the idea that programs are easier to read, to write, to
debug, and to maintain if they are divided into smaller subprograms.

• It makes our programs easier to write because individual components can be


independently written and tested.

• It makes the “main’’part of the code easier to read since long code sections are replaced
with simple functions. The individual components can be reused in other programs.

• For example, suppose you write a program that accepts data from the keyboard and
calculates the average, standard deviation and so on. If the part of the program that
calculates the standard deviation is contained inside a separate function, you could reuse
that function in another program that needed to calculate the standard deviation.

3
3 3 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Modular Programming in LabVIEW
• The power of LabVIEW lies in the hierarchical nature of the VI. After you create
a VI, you can use it on the block diagram of another VI. There is no limit on the
number of layers in the hierarchy.

• Modular programming helps manage changes and debug the block diagram
quickly.

• Modularity defines the degree to which your VI is composed of discrete


components such that a change to one component has minimal impact on
other components.

• These components are called modules or subVIs. Modularity increases the


readability and reusability of your VIs.
4
4 4 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Build a VI front panel and block diagram
The first step is to create the front panel and block diagram of a VI as shown
in Figure1. Consider a VI slope (m).vi to find the slope m given the
coordinates y1, y2, x1, x2 of a line. The slope m = (y2 – y1)/(x2 – x1).

Figure 1 VI to find the slope of a line.


5
5 5 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
ICON AND CONNECTOR PANE
• After you build a VI, build the icon and the connector pane so that you can use
the VI as a subVI.

• The icon and connector pane correspond to the function prototype in text-based
programming languages. The icon and connector pane is shown in figure 2.

• 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.

• If you use a VI as a subVI, then the icon identifies the subVI on the block
diagram of the VI.

Figure 2:Icon and connector pane created for the slope VI.

6
6 6 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING AN ICON
• The default icon of a VI contains a number that indicates how many new VIs
you have opened since launching LabVIEW. You can create custom icons to
replace the default icon by completing the following steps:

1. Right-clicking the icon in the upper-right corner of the front panel or block
diagram and select Edit Icon from the shortcut menu to display the Icon
Editor dialog box as shown in Figure .

2. Double-click the hatched box which will select the entire icon. Delete the
selected portion.

3. Double-click the rectangular box which will create a border for the icon.

4. Use the line/pencil tool to draw.


7
7 7 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING AN ICON
5. Double-click the Edit Text tool ‘A’ to edit the required text.

6. Choose the Text Tool Font to edit font, font size, color and alignment of the
text.

7. Use the Select Color tool to choose the background color of the icon.

8. Use the Fill With Color tool to change the background color of the icon.

9. Click OK to save the icon.

Figure 3: Default Icon Editor dialog box

8
8 8 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
BUILDING A CONNECTOR PANE
• The connector pane is a set of terminals that correspond to the controls and
indicators of that VI, similar to the parameter list of a function call in text-
based programming languages. The connector pane defines the inputs and
outputs you can wire to the VI so that you can use it as a subVI

• A connector pane receives data at its input terminals and passes the data
to the block diagram code through the front panel controls or receives the
results at its output terminals from the front panel indicators.

• To define a connector pane, right-click the icon in the upper-right corner of


the front panel and select Show Connector from the shortcut menu to
display the connector pane. The connector pane appears in place of the
icon. 9
9 9 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
BUILDING A CONNECTOR PANE
• To add a terminal to the pattern, place the cursor where you want to add
the terminal, right-click, and select Add Terminal from the shortcut menu.
To remove an existing terminal from the pattern, right-click the terminal
and select Remove Terminal from the shortcut menu.

• To change the spatial arrangement of the connector pane patterns, right-


click the connector pane and select Flip Horizontal, Flip Vertical, or Rotate
90 Degrees from the shortcut menu.

• If you placed the VI as a subVI on another block diagram, you must relink
the subVI to the VI whose connector pane you changed by right-clicking the
subVI and selecting Relink To SubVI from the shortcut menu. The figure 4
shows various patterns. 10
1010 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
BUILDING A CONNECTOR PANE

Figure 4 Selecting different connector patterns

11
1111 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Assigning Terminals to Controls and Indicators
After you select a pattern to use for the connector pane, you must assign a front
panel control or indicator to each of the connector pane terminals. To link controls
and indicators to the connector pane, place inputs on the left and outputs on the
right to prevent complicated or confusing wiring patterns.

Complete the following steps to assign terminals to controls and indicators in a


connector pane.

Step 1: Ensure that you have selected a pattern sufficient for the number of controls
and indicators you want to assign to the connector pane.

Step 2: Right-click the icon in the upper-right corner of the front panel and select
Show Connector from the shortcut menu to display the connector pane. The
connector pane appears in place of the icon.
12
. 1212 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Assigning Terminals to Controls and
Indicators
Step 3: Click a terminal of the connector pane. The tool automatically changes to
the wiring tool and the terminal turns black.

Step 4: Click the front panel control or indicator you want to assign to the
terminal. A marquee highlights the object as shown in Figure 3.9.

Step 5: Click an open space 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. If the connector pane terminal turns white, a connection
was not made. Repeat steps 1 through 3 until the connector pane terminal
changes to the proper data type color.

Step 6: Repeat steps 3 through 5 for each control and indicator you want to
assign to a terminal. 13
1313 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Assigning Terminals to Controls and
Indicators
Step 7: If necessary, confirm each terminal connection. You can specify which
terminals are

required, recommended and optional. You can connect only one control or
indicator to a terminal.

Figure 5: Assigning terminals to controls and indicators of the slope VI.

14
1414 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Setting Required, Recommended, and Optional
Inputs and Outputs
You can designate which inputs and outputs are required, recommended, and
optional to prevent users from forgetting to wire subVI terminals.

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 you
placed the subVI will be broken if you do not wire the required inputs. Required is
not available for terminal outputs.

For terminal inputs and outputs, Recommended or Optional means that the block
diagram on which you placed the subVI can execute if you do not wire the
recommended or optional terminals. 15
1515 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Setting Required, Recommended, and Optional
Inputs and Outputs
If you do not wire the terminals, the VI does not

generate any warnings.

Complete the following steps to set a terminal to required, recommended, or


optional.

Step 1: Right-click a terminal in the connector pane and select This Connection
Is from the shortcut menu.

Step 2: A checkmark indicates the terminal setting. Select 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 or16
1616 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING SUBVIs FROM SECTIONS OF A
VI
• You can convert a section of a VI into a subVI by using the positioning tool to
select the section of the block diagram you want to reuse as shown in Figure
6.

• Then select Edit»Create SubVI from the menu to convert the selected portion
into a subVI. SubVI created with default icon is shown in Figure 7.

• An icon for the new subVI replaces the selected section of the block diagram.
LabVIEW creates controls and indicators for the new subVI, automatically
configures the connector pane based on the number of control and indicator
terminals you selected, and wires the subVI to the existing wires.

17
1717 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING SUBVIs FROM SECTIONS OF A
VI

Figure 7: SubVI created with default icon.


Figure 6: Select a portion of the available VI to create a
SubVI

18
1818 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
OPENING AND EDITING SUBVIs
When you double-click a subVI, a front panel and a block diagram appear, rather
than a dialog box in which you can configure options.

The subVI controls and indicators receive data from and return data to the block
diagram of the calling VI. Click the Select a VI icon or text on the Functions palette,
navigate to and double-click a VI, and place the VI on a block diagram to call a
created subVI.

Complete the following steps to open a subVI and edit it.

Step 1: Use the operating or positioning tool to double-click the subVI on the block
diagram. LabVIEW displays the front panel of the subVI. You also can press the
<Ctrl> key and use the operating or positioning tool to double-click the subVI on the
block diagram to display the block diagram and front panel of the subVI.
19
1919 s
Step 2: Edit the subVI.
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
PLACING SUBVIs ON BLOCK
DIAGRAMS
Complete the following steps to place a subVI on the block diagram.

Step 1: Display the block diagram of a new or existing VI by selecting


Window»Show Block Diagram.

Step 2: If necessary, display the Functions palette by selecting View»Functions


Palette.

Step 3: Click the Select a VI icon on the Functions palette.

Step 4: Navigate to and double-click the VI you want to use as a subVI, and place
it on the block

diagram.

Step 5: Wire the subVI terminals to other nodes on the block diagram.
20
2020 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
FOR LOOPS
• A For Loop executes a sub diagram, a set number of times. Figure 8 shows a
For Loop in LabVIEW and the flow chart equivalent of the For Loop
functionality. The For Loop is located on the
Functions>>Programming>>Structures Palette.

• Select the For Loop from the palette and use the cursor to drag a selection
rectangle to create a new For Loop or around the section of the block
Figure 8: For Loop .
diagram you want to repeat

21
2121 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
FOR LOOPS
• The value in the count terminal ‘N’ (an input terminal) indicates how many times
to repeat the subdiagram. Set the count explicitly by wiring a value from outside
the loop to the left or top side of the count terminal, or set the count implicitly
with auto-indexing. A VI will not run if it contains a For Loop that does not have a
numeric value wired to the count terminal.

• The iteration terminal ‘i’ (an output terminal) contains the number of completed
iterations. The iteration count always starts at zero. During the first iteration, the
iteration terminal returns 0. Figure 4.2 shows a simple For Loop which generates
10 random numbers and displays in the Random Number Indicator.
Figure 9: Example of a For Loop .

22
2222 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
WHILE LOOPS
A While Loop executes a subdiagram until a condition is met.
The While Loop is similar to a Do Loop or a Repeat-Until Loop in text-based
programming languages.
A While Loop in LabVIEW and the flow chart equivalent of the While Loop is
shown in figure 10. The While Loop always executes at least once.
In LabVIEW, the WHILE Loop is located on the
Functions>>Programming>>Structures palette.
The While Loop contains two terminals, namely Conditional Terminal and
Iteration Terminal.

23
2323 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
WHILE LOOPS
.
The While Loop executes the subdiagram until the conditional terminal,
and receives a specific Boolean value. The default behavior and
appearance of the conditional terminal is Stop if True as shown in Figure
10. Figure 10: While Loop .

24
2424 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
WHILE LOOPS
When a conditional terminal is Stop if True, the While Loop executes its
subdiagram until the conditional terminal receives a TRUE value. You
can change the behavior and appearance of the conditional terminal by
right-clicking the terminal or the border of the While Loop and selecting
Continue if True from the shortcut menu as shown in Figure 11. When a
conditional terminal is Continue if True, the While Loop executes its
subdiagram until the conditional terminal receives a FALSE value.

Figure 11: While Loop .

25
2525 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
STRUCTURE TUNNELS
• Data can be passed out of or into a loop through a tunnel. Tunnels feed data
into and out of structures. The tunnel appears as a solid block on the border of
the loop. The block is the color of the data type wired to the tunnel. Data
passes out of a loop after the loop terminates. When a tunnel passes data into a
loop, the loop executes only after data arrives at the tunnel. The value in the
tunnel does not pass to the Iteration Number indicator until the While Loop has
finished execution.

Figure 12: Passing data outside the loop through a


tunnel

26
2626 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
TERMINALS INSIDE OR OUTSIDE LOOPS
• Inputs pass data into a loop at the start of loop execution.

• Outputs pass data out of a loop only after the loop completes all iterations.

• If you want the loop to check the value of a terminal for each iteration,
place the terminal inside the loop.

• When you place the terminal of a front panel Boolean control inside a While
Loop and wire the terminal to the conditional terminal of the loop, the loop
checks the value of the terminal for every iteration to determine if it must
iterate.

• You can stop the While Loop as shown in Figure 4.10(a) by changing the
value of the front panel control to FALSE. 27
2727 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
TERMINALS INSIDE OR OUTSIDE LOOPS
• If you place the terminal of the Boolean control outside the While Loop as
shown in Figure 13 and the control is set to FALSE if the conditional terminal
is Stop if True when the loop starts, you cause an infinite loop.

• You also cause an infinite loop if the control outside the loop is set to TRUE
and the conditional terminal is Continue if True.

Figure 13 While Loop with Boolean control


placed inside the loop and While Loop with
Boolean control placed outside the loop.

28
2828 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
SHIFT REGISTERS
• When programming with loops, you often need to access data from previous
iterations of the loop. For example, you may have a VI that reads the
temperature and displays it on a graph. If you want to display a running average
of the temperature as well, you need to use data generated in previous
iterations. Two ways of accessing this data include the shift register and the
feedback node.

• While Loops produce default data when the shift register is not initialized. For
Loops produce default data if you wire 0 to the count terminal of the For Loop or
if you wire an empty array to the For Loop as an input with auto-indexing
enabled. The loop does not execute, and any output tunnel with auto-indexing
disabled contains the default value for the tunnel data type. Use shift registers
to transfer values through
An Autonomous aAffiliated
Institution, loop to regardless of whether
VTU, Belagavi, Approved the
By AICTE, New loop
Delhi, executes.
Recognized
29
2929 s
by UGC with 2(f) & 12(B)
SHIFT REGISTERS
• Shift registers are used with For Loops and While Loops to transfer values from
one loop iteration to the next.

• LabVIEW transfers the data connected to the right side of the register to the
next iteration. After the loop executes, the terminal on the right side of the loop
returns the last value stored in the shift register. Create a shift register by right-
clicking the left or right border of a loop and selecting the Add shift register
from the shortcut menu.

Figure 14: Shift register operation

30
3030 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
FEEDBACK NODES
When the output of a node is connected directly to the input, the feedback
node is generated automatically. The feedback node shown in Figure 4.17
appears automatically in a For Loop or While Loop if we wire the output of a
node or group of nodes to the input of that node or group of nodes. Like a
shift register, the feedback node stores data when the loop completes an
iteration, sends that value to the next iteration of the loop, and transfers any
data type. Use the feedback node to avoid unnecessarily long wires in loops.
The feedback node arrow indicates the direction in which the data flows
along the wire. The arrow automatically changes direction if the direction of
data flow changes.
31
3131 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
FEEDBACK NODES

Figure 15: Feedback node.

You also can select the Feedback Node on the Structures palette and
place it inside a For Loop or While Loop. If you place the feedback node
on the wire before you branch the wire that connects the data to the
tunnel as in Figure 4.18, the feedback node passes each value to
32
the tunnel. 3232 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CONTROL TIMING
• When a loop finishes executing an iteration, it immediately begins executing
the next iteration unless it reaches a stop condition.

• Most applications need precise control of the frequency or timing of the


iteration to be maintained between successive operations of the loop.

• You might want to control the speed at which a process executes, such as the
speed at which data values are plotted to a chart.

• You can use a wait function in the loop to wait an amount of time in
milliseconds before the loop re-executes. LabVIEW consists of two wait
functions.

• A wait function is placed inside a loop to allow a VI to sleep for a set amount of
time. This allows your
An Autonomous processor
Institution, toVTU,
Affiliated to address otherBytasks
Belagavi, Approved during
AICTE, New the wait
Delhi, Recognized by UGCtime.
33
3333 s
with 2(f) & 12(B)
CONTROL TIMING
Wait functions use the operating system millisecond clock.

• The Wait Until Next ms Multiple function monitors a millisecond counter and
waits until the millisecond counter reaches a multiple of the time you specify.

• The Wait (ms) function adds the wait time to the code execution time. This
can cause a problem if code execution time is variable. The Wait (ms) function
waits until the millisecond counter counts to an amount equal to the input you
specify.
Figure 16: (a) Wait Until Next ms Multiple function
and (b) Wait (ms) function

34
3434 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
COMMUNICATING AMONG MULTIPLE
LOOPS
In LabVIEW, the flow of data determines the execution order of block diagram
elements.

Variables are block diagram elements that allow you to access or store data in
another location.

The actual location of the data varies depending upon the type of the variable.

Local variables store data in front panel controls and indicators.

Global variables and single process-shared variables store data in special


repositories that you can access from multiple VIs.

Functional global variables store data in While Loop shift registers.

35
3535 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
LOCAL VARIABLES
• Local variables transfer data within a single VI and allow data to be passed
between parallel loops as shown in Figure 4.22.

• They also break the dataflow programming paradigm. Two ways to create a
local variable are right-click on an object’s terminal and select Create»Local
Variable.

Figure 17: Local variable.

36
3636 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
LOCAL VARIABLES
• Another way is to select the Local Variable from the Structures palette. Create
the front panel and select a local variable from the Functions palette and place
it on the block diagram.

• To associate a local variable with a control or indicator, right-click the local


variable node and select Select Item from the shortcut menu.

• After you create a local or global variable, you can read data from a variable
or write data to it. By default, a new variable receives data.

• This kind of variable works as an indicator and is a write local or global. When
you write new data to the local or global variable, the associated front panel
control or indicator updates to the new data.
37
3737 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
GLOBAL VARIABLES
• Global variables are built-in LabVIEW objects. You can use variables to access
and pass data among several VIs that run simultaneously.

• A local variable shares data within a VI; a global variable also shares data,
but it shares data with multiple VIs. For example, suppose you have two VIs
running simultaneously.

• Each VI contains a While Loop and writes data points to a waveform chart.
The first VI contains a Boolean control to terminate both VIs.

• You can use a global variable to terminate both loops with a single Boolean
control. If both loops were on a single block diagram within the same VI, you
could use a local variable to terminate the loops.
38
3838 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
GLOBAL VARIABLES

Figure 18: Global variable

When you create a global variable, LabVIEW automatically creates a special


global VI, which has a front panel but no block diagram. Add controls and
indicators to the front panel of the global VI to define the data types of the
global variables. Select a global variable as shown in Figure 18 from the
Functions palette and place it on the block diagram.
39
3939 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
ARRAYS
A group of homogeneous elements of a specific data type is known as an
array, one of the simplest data structures.

Arrays hold a sequence of data elements, usually of the same size and same
data type placed in contiguous memory locations that can be individually
referenced.

Hence arrays are essentially a way to store many values under the same
name. Individual elements are accessed by their position in the array.

The position is given by an index, which is also called a subscript.

The index usually uses a consecutive range of integers.

Some arrays are multi-dimensional, but generally, one- and two-dimensional


arrays are An
the most Institution,
Autonomous common. 40
4040 s
Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING ONE-DIMENSIONAL ARRAY
• Create an array control or indicator on the front panel by placing an array
shell on the front panel and dragging a data object or element, which can
be a numeric, Boolean, string, path, refnum, or cluster control or indicator,
into the array shell.

• The array shell automatically resizes to accommodate the new object. The
array shell can be selected from Controls>>Modern>>Arrays, Matrix &
Clusters palette. The array elements must be controls or indicators.

• After placing an element in the array shell, you can expand the array either
horizontally or vertically to see more number of elements. Once a data type
is assigned to the array shell, the block diagram takes the color and
lettering (in [ ] brackets) of the data type 41
4141 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING TWO-DIMENSIONAL ARRAY
• A two-dimensional array is analogous to a spreadsheet or table. A two-
dimensional array stores elements in a grid. It requires a column index and
a row index to locate an element, both of which are zero-based. Two-
dimensional arrays are very commonly used in data acquisition
applications.

• For example, when waveforms from several channels are read from a data
acquisition (DAQ) board, the data is stored in a two-dimensional array
where each column in the array corresponds to data from one channel. To
create a two-dimensional array on the front panel, right-click the index
display of the array and select Add Dimension from the shortcut menu. You
also can use the Positioning tool to resize the index display to have one
42
4242 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING MULTIDIMENSIONAL ARRAY
• To create a multidimensional array on the front panel, right-click the index
display of the array and select Add Dimension from the shortcut menu.

• You also can use the Positioning tool to resize the index display until you
have as many dimensions as you want.

• To delete dimensions one at a time, right-click the index display and select
Remove Dimension from the shortcut menu. You can also resize the index
display to delete dimensions.

• Use the Positioning tool to resize the array to show more than one row or
column at a time.

43
4343 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
CREATING 1D, 2D and MULTIDIMENSONAO
ARRAY

Figure 19: 1D Array

Figure 20: Two-dimensional array.

Figure 21: Array with horizontal and vertical scroll


bars.
44
4444 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
INSERTING ELEMENTS, ROWS, COLUMNS AND
PAGES INTO ARRAYS
• You can insert an element into a one-dimensional array and a row or column
into a two-dimensional array. To add an element to a one-dimensional array,
right-click the array on the front panel and select Data Operations»Insert
Element Before.

• To add a row or column to a two-dimensional array, right-click the array on


the front panel and select Data Operations»Insert Row Before or Insert
Column Before.

• You can insert an element, row, column or page into an array


programmatically. What you can insert depends on how many dimensions
the array has.
45
• For example, you can
An Autonomous insert
Institution, a torow
Affiliated or a column
VTU, Belagavi, Approved By into anDelhi,
AICTE, New array of two
Recognized orwithmore
by UGC 4545 s
2(f) & 12(B)
INSERTING ELEMENTS, ROWS, COLUMNS AND
PAGES INTO ARRAYS
• Complete the following steps to insert elements, rows, columns or pages in an
array.

1. Place an Insert Into Array function on the block diagram.

2. Wire an array of any dimension to the n-dim array input of the Insert into Array
function. The function automatically resizes based on the dimensions of the array.

3. Determine which operation you want to perform from Table 5.2 and complete the
associated steps.

4. The index input specifies the element, row, column or page where you want to
insert the element or array, with 0 being the first. Elements and arrays are added
before the value you wire to index.

5. Run the VI. An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
46
4646 s
DELETING ELEMENTS, ROWS, COLUMNS AND
PAGES WITHIN ARRAYS
• You can delete an element within a one-dimensional array and a row or column
within a two-dimensional array.

• To delete an element in a one-dimensional array, right-click the array element on


the front panel and select Data Operations» Delete Element.

• To delete a row or column in a two-dimensional array, right-click the array row or


column on the front panel and select Data Operations» Delete Row or Delete
Column.

• You can also programmatically delete elements, rows, columns and pages within
arrays using the Delete From Array function.

• You can delete an element, row, column or page within an array programmatically.
What you can delete depends on how many dimensions the array has. 47
4747 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
DELETING ELEMENTS, ROWS, COLUMNS AND
PAGES WITHIN ARRAYS
• Complete the following steps to delete elements, rows, columns or pages in an
array.

• Step 1: Place the Delete From Array function on the block diagram.

• Step 2: Wire an array of any dimension to the n-dim array input of the Delete
From Array

• function. The function automatically resizes based on the dimensions of the


array.

• Step 3: Determine which operation you want to perform from Table 5.1 and
complete the

• associated steps.
48
4848 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
REPLACING ELEMENTS, ROWS, COLUMNS, AND
PAGES WITHIN ARRAYS
• You can replace an element, row, column or page in an array.

• What you can replace depends on how many dimensions the array has. For
example, in an array of two or more dimensions, you can replace a row or a
column with a one-dimensional array.

• In an array of three or more dimensions, you can replace a page with a two-
dimensional array. Replacing is done using the Replace Array Subset function.

• Complete the following steps to replace elements, rows, columns or pages in an


array.

• Step 1: Place the Replace Array Subset function on the block diagram.

49
4949 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
REPLACING ELEMENTS, ROWS, COLUMNS, AND
PAGES WITHIN ARRAYS
• Step 2: Wire an array of any dimension to the n-dimension array input
of the Replace Array Subset function. The function automatically resizes
based on the dimensions of the array.

• Step 3: Determine which operation you want to perform from Table 5.3
and complete the associated steps. The index input specifies which element,
row, column or page to replace, with 0 being the first. The new
element/subarray input specifies the value you want to replace an element, or
the array you want to replace a row, column or page.

• Step 4: Resize the Replace Array Subset function to replace another


element, row, column or page within an array and repeat steps 2 and 3.
50
• Step 5: RunAnthe VI. 5050 s
Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
ARRAY FUNCTIONS
• Array functions are used to create and manipulate arrays. You can perform
common array operations such as extracting individual data elements from an
array, inserting, deleting, or replacing data elements in an array or splitting
arrays using array functions.

• Array functions including Index Array, Replace Array Subset, Insert Into Array,
Delete From Array, and Array Subset automatically resize to match the
dimensions of the input array you wire.

• For example, if you wire a one-dimensional array to one of these functions, the
function shows a single index input. If you wire a two-dimensional array to the
same function, it shows two index inputs—one for the row index and one for the
column index. 51
5151 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
ARRAY FUNCTIONS (EXAMPLES)

Figure 22: Index array function


with one-dimensional array as
input,
Figure 23: Index array
function with two-
dimensional array as input
and with one index (row
index)

Figure 24: Index array function with two-


dimensional array as input and with two indices.
52
5252 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
MATRIX OPERATIONS WITH ARRAYS
• Use the matrix data type to make modeling of math problems easier. Matrices
group rows or columns of real or complex scalar data for some math
operations, such as linear algebra operations.

• A two-dimensional array is similar to a matrix.

• Converting an Array to a Matrix

• You can convert a one-dimensional or two-dimensional array of double-


precision or complex numbers to a matrix and continue to use array functions
to manipulate the matrix values. Complete the following steps to convert an
array to a matrix.

Step 1: Place a one-dimensional or two-dimensional array of floating-point


values on the front panel.
An Autonomous
53
53 s
Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
MATRIX OPERATIONS WITH ARRAYS
Step 2: Place the Array To Matrix function on the block diagram.

Step 3: Wire the array to the Array To Matrix function.

Step 4: Right-click the Array To Matrix function and select Create»Indicator


from the shortcut menu to create a matrix indicator.

Step 5: Run the VI. The matrix indicator displays the contents of the original
array

Figure 25: Front panel and block diagram of the VI to convert an array to a
matrix.
54
54 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
MATRIX OPERATIONS WITH ARRAYS
Converting a Matrix to an Array:

Complete the following steps to convert a matrix to a two-dimensional array.

Step 1: Place a Real Matrix or Complex Matrix control on the front panel.

Step 2: Place the Matrix To Array function on the block diagram.

Step 3: Wire a matrix to the Matrix To Array function

Step 4: Right-click the Matrix To Array function and select Create» Indicator
from the shortcut menu to create a two-dimensional array indicator.

Step 5: Run the VI from the front panel. The array indicator displays the
contents of the array.
55
55 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
MATRIX OPERATIONS WITH ARRAYS

Figure 26: Front panel and block diagram of the VI to convert a matrix into
an array.

56
56 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
POLYMORPHISM
• All LabVIEW arithmetic functions are polymorphic. This means that the
inputs to these functions can be different data structures such as scalar
values and arrays.

• By definition polymorphism is said to be the ability of a numeric function to


adjust to input data of different data structures.

For example, the Add function can be used in the following ways.

1. Scalar + Scalar = Scalar addition.

2. Scalar + Array = The scalar is added to each element of array.

3. Array + Array = Each element of one array is added to the corresponding


element of other array.
57
5757 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
POLYMORPHISM

Figure 27: Various examples of Polymorphism

58
5858 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
POLYMORPHISM

Figure 28: Polymorphism with array size of different dimension

•Polymorphism does not perform matrix arithmetic when inputs are two-
dimensional arrays (for example, two two-dimensional array inputs to a
multiply function do element by element multiplication, not matrix
multiplication).

59
5959 s
An Autonomous Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
Assignment Questions
1. Bulid a VI to create seven segment display.

2. Build a VI to create seven segment display for two digit numbers. (EX:10 TO
99)

3. Build a VI to find the roots of a quadratic equation. Input the coefficients of


X^2, X and constant as A,B and C respectively. Display the roots and the
message if the roots are Real or imaginary or equal.

4. Build a VI to display only the odd numbers using conditional tunnel modes.

5. Build a VI to demonstrate the difference of tunnelling modes(Concatenating,


conditional, last value)

6. Create a VI to find the sum of first n natural numbers using A WHILE LOOP
with a feedback node.Institution, Affiliated to VTU, Belagavi, Approved By AICTE, New Delhi, Recognized by UGC with 2(f) & 12(B)
An Autonomous
60
60 s
MVJ College of Engineering
Near ITPB, Whitefield
Thank You
Bangalore

An Autonomous Institution, AffiliatedtotoVTU,


VTU,Belagavi,
Belagavi, Approved 61 s
61
An Autonomous Institution, Affiliated ApprovedBy
ByAICTE,
AICTE,New
NewDelhi, Recognized
Delhi, by UGC
Recognized with with
by UGC 2(f) & 12(B)

You might also like