labview programming structures

36

Upload: ahmed4665

Post on 10-Apr-2015

4.823 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: LabVIEW Programming Structures
Page 2: LabVIEW Programming Structures

LabVIEW Programming StructuresStructures located on the Functions» Programming»Structures palette to control how a block diagram executes processes:

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

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

Page 3: LabVIEW Programming Structures

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.

Page 4: LabVIEW Programming Structures

Formula Node• You van select the Formula Node from:Factions Palette >>Programming >>Structures

Page 5: LabVIEW Programming Structures

Formula Node Example 2Solve the equation

AX^2 + BX + C = 0

Page 6: LabVIEW Programming Structures

Formula NodeWhen 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 input.

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

Page 7: LabVIEW Programming Structures

Formula Node

• Evaluates mathematical formulas and expressions similar to C.

Page 8: LabVIEW Programming Structures

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

Page 9: LabVIEW Programming Structures

For Loop StructureYou select the for loop by popping-up in the Block Diagram > Functions > Programming >Structures > For Loop:

Page 10: LabVIEW Programming Structures

For Loop Structure

•For Loop executes its subdiagram count times, where the count equals the value contained in the count terminal (N)

Iteration0 during the first iteration1 during the second iterationetc up to N-1

•If you wire 0 to the count terminal, the loop does not execute.

Page 11: LabVIEW Programming Structures

For Loop Structure

Page 12: LabVIEW Programming Structures

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

Page 13: LabVIEW Programming Structures

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.

Page 14: LabVIEW Programming Structures

Shift Registers Example• sums the first N terms of the series

(1+i^2). Where i is an integer varies from 0 to infinity.

Page 15: LabVIEW Programming Structures

Multiple Shift RegistersOne 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 containsthe value from iteration i-2, and so on with each successive terminal.

Page 16: LabVIEW Programming Structures

Case Structures• The Case Structure is a method of

executing conditional statements. The Case Structure is similar

If (Condition) thenDo ThisElseDo ThatEndif

selector terminal

Page 17: LabVIEW Programming Structures

Case Structures• A Case structure has two or more subdiagrams,

or cases. Only one subdiagram is visible at a time.

• The selector terminal

can be

Boolean, Numeric, or String

Page 18: LabVIEW Programming Structures

Case StructuresA 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 cases.

• 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

Page 19: LabVIEW Programming Structures

Case Structures Example

Page 20: LabVIEW Programming Structures

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

Page 21: LabVIEW Programming Structures

Sequence Structures

Page 22: LabVIEW Programming Structures
Page 23: LabVIEW Programming Structures

Sequence Structures• To pass data from one frame to any subsequent frame,

use a sequence local terminal.

Page 24: LabVIEW Programming Structures

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

Page 25: LabVIEW Programming Structures

Sequence StructuresSequence 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.

Page 26: LabVIEW Programming Structures

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.

Page 27: LabVIEW Programming Structures

Diagram Disable Structure

Has one or more sub diagrams, or cases, of which only the Enabled sub diagram executes.

Diagram Disable Structure:

Page 28: LabVIEW Programming Structures

While Loop StructureYou select the while loop by popping-up in the Block Diagram > Functions > Programming > Structures > While Loop:

Page 29: LabVIEW Programming Structures

While Loop StructureThe While Loop executes the subdiagram until the conditional terminal.

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

Page 30: LabVIEW Programming Structures
Page 31: LabVIEW Programming Structures

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 insidea While Loop and wire the terminal to the loop conditional terminal of the loop, the loop checks the valueof the terminal at the end of every iteration to determine whether it should iterate again.

Page 32: LabVIEW Programming Structures

The Select FunctionThe 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.

Page 33: LabVIEW Programming Structures

TimingWait Until Next ms Multiple function

This function is used to synchronize activities. The function is placed within a loopto control the loop execution rate.

Page 34: LabVIEW Programming Structures

TimingWait (ms) function

Adds the wait time to the code execution time, as illustrated. This can cause a problem if code execution time is variable.

Page 35: LabVIEW Programming Structures

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

Page 36: LabVIEW Programming Structures

Assignments• 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 50

• 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 input=C