Вы находитесь на странице: 1из 36

LabVIEW Programming Structures

Structures located on the Functions» Programming»

Structures palette to control how a block diagram executes
• Formula Node: Performs mathematical operations based on
numeric input.
• For Loop: Executes a subdiagram a set number of times.
• Case structure: Contains multiple subdiagrams, only one of
which executes depending on the input value passed to the
• Sequence structure: Contains one or more subdiagrams,
which execute in sequential order.
• Diagram Disable Structure: Has one or more sub diagrams,
or cases, of which only the Enabled sub diagram executes
• While Loop: Executes a subdiagram until a condition is met.
Formula Node
• Formula Node is a box where you enter algebraic
formulas directly into the Block Diagram. It is useful
when an equation is complicated or has many variables.
• y = x^2 + x + 1

Declare an input variable by right-clicking the Formula Node border and selecting
Add Input from the shortcut menu. You cannot declare input variables inside the
Formula Node

Declare an output variable by right-clicking the Formula Node border and selecting
Add Output from the shortcut menu.
Formula Node
• You van select the Formula Node from:
Factions Palette >>Programming >>Structures
Formula Node Example 2
Solve the equation
AX^2 + BX + C = 0
Formula Node
When you work with variables, remember the following points:

• There is no limit to the number of variables or equations

in a Formula Node.

• No two inputs and no two outputs can have the same

name, but an output can have the same name as an

• You can declare and use a variable inside the Formula

Node without relating it to an input or output wire.

• You must wire all input terminals.

Formula Node

• Evaluates mathematical formulas and

expressions similar to C.
Expression Node
• It is a simple model of the formula node, it
has a single input, single output and one
expression can be wrote without ;.
For Loop Structure
You select the for loop by popping-up in the
Block Diagram > Functions > Programming >Structures > For Loop:
For Loop Structure

•For Loop executes its subdiagram

count times, where the count equals
the value contained in the count
terminal (N)

0 during the first iteration
1 during the second iteration
etc up to N-1

•If you wire 0 to the count terminal, the

loop does not execute.
For Loop Structure
Shift Registers in Loops
• Shift registers are local variables that feed back or
transfer values from the completion of one iteration to
the beginning of the next.

• By selecting Add Shift Register from the loop border

pop-up menu, you can create a register anywhere along
the vertical boundary only, as shown in the illustration..
Shift Registers in Loops
• To initialize a shift register, wire a value from outside
the loop to the left terminal.

• If you do not initialize the register, the loop uses as

the initial value the last value inserted in the register
when the loop last executed.
Shift Registers Example
• sums the first N terms of the series
(1+i^2). Where i is an integer varies from 0
to infinity.
Multiple Shift Registers
One can create multiple shift registers on a particular structure.

The left, topmost terminal holds the value from the previous iteration,
i-1. The terminal immediately under the uppermost terminal contains
the value from iteration i-2, and so on with each successive terminal.
Case Structures
• The Case Structure is a method of
executing conditional statements. The
Case Structure is similar
If (Condition) then
Do This
Else selector terminal

Do That
Case Structures
• A Case structure has two or more subdiagrams,
or cases. Only one subdiagram is visible at a
• The selector terminal
can be
or String
Case Structures
A few things to remember about Case Structures and their data types:

• If the data type is Boolean, the structure can only have two cases:
True or False.

• If the data type is numeric or string, the structure can have many

• If the data type is numeric or string, the first case will have default in
the case structure name.

• If the data type is numeric, use positive integer values.

• If the data type is string, the data values must be in quotes.

• Cases are not required to use input data or to supply output data,
but if any case supplies output data, all must do so
Case Structures Example
Sequence Structures
• The Sequence Structure is used to control the data flow
in a VI's Block Diagram. They are used to control the
order of execution of nodes
Sequence Structures
Sequence Structures
• To pass data from one frame to any subsequent frame,
use a sequence local terminal.
Sequence Structures
• An outward-pointing arrow appears in the
sequence local terminal of the frame that
contains the data source.

Can’t be used in previous sequence

Sequence Structures
• The output tunnels of Sequence Structures can
only have one data source which, unlike Case
Structures, has outputs that must have one data
source per case.
Sequence Structures
• The output can come from any frame, but
the data will not leave the structure until
the last frame in the structure has
completed it's execution.
Diagram Disable Structure

Diagram Disable Structure:

Has one or more sub diagrams,

or cases, of which only the
Enabled sub diagram executes.
While Loop Structure
You select the while loop by popping-up in the
Block Diagram > Functions > Programming > Structures > While Loop:
While Loop Structure
The While Loop executes the
subdiagram until the conditional

You can select (Continue if true or

Stop if true )

Both loop structures (FOR and WHILE)

can have terminals called shift
registers that you use for passing data
from the current iteration to the next
Terminals Inside Loops
• Inputs to a loop pass data before loop execution.
Outputs pass data out of a loop only after the loop
completes all iterations.

• When you place the terminal of

a front panel Boolean control inside
a While Loop and wire the terminal
to the loop conditional terminal of
the loop, the loop checks the value
of the terminal at the end of every
iteration to determine whether it should
iterate again.
The Select Function
The Select Function similar to simple
case structure

This function:
• Returns the value wired to the t terminal if the value at
the s terminal is TRUE
• Returns the value wired to the f terminal if the value at
the s terminal is FALSE.
Wait Until Next ms Multiple function
This function is used to synchronize activities. The function is placed within a loop
to control the loop execution rate.
Wait (ms) function
Adds the wait time to the code execution time, as illustrated. This can cause a
problem if code execution time is variable.
Feedback Nodes
• Appears automatically in a For Loop or While Loop if the output of a
subVI or functions are wired to the input of that same VI or function,
Like a shift register

Initial Condition
• Write a VI that sums the first 10 terms of the series (32+i*cos(x)).
Where x in an input value and i=0,1,2,…

• Write a VI that solve any second order equation, you should use
the Formula Node and the case statement. The VI has three
inputs A,B, and C as in assignment 1, and two outputs, the real
part and the imaginary part.

• Write a VI that turn and Led ON if an input temperature is above


• Write a VI that do the sum of two numbers (x1 and x2) if an

input=A, the subtract if the input=B and multiplication if the