Vi Srm University

Embed Size (px)

Citation preview

  • 7/28/2019 Vi Srm University

    1/50

    VIRTUAL INSTRUMENTATION USING

    LABVIEW

    BY

    S.ANITHA KUMARI A.P(O.G)DEPT. OF EIE

  • 7/28/2019 Vi Srm University

    2/50

    Virtual Instrument

    LabVIEW works on adata flow modelin which information

    within a LabVIEW program, called a virtual instrument (VI),

    flows from data sources to data sinks connected by wires.

    LabVIEW supports two types of VIs--internal VIs and user

    created VIs.

    Internal VIs are packaged with LabVIEW and perform simple

    functions like adding numbers or opening files.

    User created VIs consist of both a graphical user interface

    called the front panel and a code pipeline called the block

    diagram.

  • 7/28/2019 Vi Srm University

    3/50

    FRONT PANEL

    Every user created VI

    has a front panel that

    contains the graphical

    interface with which a

    user interacts. The front

    panel can house various

    graphical objects ranging

    from simple buttons to

    complex graphs. It alsoincludes nonfunctioning

    items such as free labels

    and decorations.

  • 7/28/2019 Vi Srm University

    4/50

    Block diagram

    TheBlock Diagram is a window

    where the graphical code is

    created.

  • 7/28/2019 Vi Srm University

    5/50

    Accessing the Functions

    Palette in the Block

    Diagram

  • 7/28/2019 Vi Srm University

    6/50

    Popping-Up on Controls

    and Indicators

  • 7/28/2019 Vi Srm University

    7/50

    The Tool Palette

    To manage, modify, and debugVI's .

  • 7/28/2019 Vi Srm University

    8/50

    Automatic

    Tool

    Selection

    Automatically

    selects

    between

    the

    Operate

    Value,Position/Size/Select,EditTextandConnectWireTools.Itisthe

    mostcommonlySelecteditemontheToolsPalette.

    OperateValue ManipulatesthevaluesofFrontPanelControlsand

    Indicators.GenerallyselectedwhilerunningaVI.

    Position/Size/Select SelectsobjectsinaVI,movesthemandresizes

    them.

    EditText CreatesFreeLabelsontheFrontPanelandeditstheirtext.

    Alsoedits

    text

    in

    Owned

    Labels.

    ConnectWire WiresBlockDiagramnodesandobjectstogether.

    ObjectShortcutMenu Displaysanobject'spopupmenuwiththeleft

    mousebutton.

    ScrollWindow PansthecontentonaVIwindowwithoutusingthe

    window'sscrollbars.

  • 7/28/2019 Vi Srm University

    9/50

    Set/ClearBreakpoint CreatebreakpointsinaVIBlock

    Diagramfor

    debugging

    purposes.

    Breakpoints

    cause

    the

    VI

    tosuspendexecutionataparticularpoint.

    ProbeData PlacesProbesonwiresintheBlockDiagramfor

    debuggingpurposes.AProbedisplaysthedataonawire

    whereit

    is

    placed.

    GetColor CopiescolorsfromVIobjectstopastingwiththe

    SetColorTool.

    SetColor ColorsobjectsinaVIanddisplaystheforeground

    andbackground

    colors

    of

    the

    object.

  • 7/28/2019 Vi Srm University

    10/50

    DATA TYPES

    There are three possible data types in a VI

    Number- This data type contains numbers thatcan be either floating point or integer.

    Boolean - This data type contains logical

    combinations of TRUE/FALSE, AND, OR, NOT,Etc.

    String - Contains alpha-numeric characters only

    All of these data types can be in either Scalar, 1DArray or 2D Array form.

  • 7/28/2019 Vi Srm University

    11/50

    Wire Types

    There are different wire colors and types that depict

    what kind of data is flowing through a particular wireand if it is in Scalar, 1D Array or 2D Array form:

  • 7/28/2019 Vi Srm University

    12/50

    Numeric Control

    Representation

    REPRESENTION ABBREVATION TERMINAL SIZE(BYTES)

    Representation Abbreviation Terminal Size (bytes)

    byte I8 1

    unsigned byte U8 1

    word I16 2

    unsigned word U16 2

    long I32 4

    unsigned long U32 4

    single precision SGL 4

    double precision DBL 8

    extend precision EXT 16

  • 7/28/2019 Vi Srm University

    13/50

    complex single CSG 8

    complex double CDB 16

    complex extended CXT 32

  • 7/28/2019 Vi Srm University

    14/50

    CHANGING

    REPRESENTATIONS

  • 7/28/2019 Vi Srm University

    15/50

    WIRING

    Wires are data flow paths between Block Diagram components.

    Block Diagram nodes are wired together for logical functioning of the VI.

    Creatingwires:selecttheConnectWiretoolonthetoolspalette

    Wire Stretching: move a wired node on the Block Diagram, thewires will stretch to follow the node

    Selecting wires:

    Deleting wires:

  • 7/28/2019 Vi Srm University

    16/50

    Align and Distribute

    Objects Rings

    To quickly and easily make the objects on your Front Panel or Block Diagram nice

    and neat.

  • 7/28/2019 Vi Srm University

    17/50

    RUNNING VI

    click on a Broken Run button,to get a list of errors in a

    pop-up window

  • 7/28/2019 Vi Srm University

    18/50

    DEBUGGING VIs

    Debugging Tools on the Block Diagram Debugging Tools on the Tools Palette

  • 7/28/2019 Vi Srm University

    19/50

    ExecutionHighlight when pressed, turns bright and allows you to view

    the data flow through the Block Diagram slowly asit goes from one Block Diagram component to the

    next.

    StepOver activates the single-step mode which steps the

    execution of the VI from node to node. Each nodeblinks then it executes one at a time.

    StepInto activates the single-step mode and is used to step intoa loop or Sub VI so you can single step inside them.

    StepOut used to step out of a loop or Sub VI and to end theexecution of a VI.

    BreakpointTool used to set breakpoints or stopping points in a VI,especially in a Sub VIs, functions, structures and

    wires.

    ProbeTool

    creates probes on wires in the Block Diagram. It

    shows the data at that point in a wire at a particular

    time. It is used for checking intermediate data inside a

    VI.

  • 7/28/2019 Vi Srm University

    20/50

    SUB VIs

    The Sub VI is considered as a lower-level VIinside of an upper-level VI.

    This reduces the number of Block Diagram icons, which simplifies and modularizes the VI. Sub VIsare much like functions or subroutines in conventional text-based programming languages.

    Steps in creating sub vi:

    create sub vi icon

    Assign sub vi connectors

  • 7/28/2019 Vi Srm University

    21/50

    STRUCTURES

    In addition to controls, indicators, and VIs, the block diagram

    can also contain a number of programming structures that

    modify the sequence of data flow on the block diagram.

    LabVIEW currently supports six different structures, -while-

    loops, case structures, event structures, for-loops, sequence

    structures, and formula nodes.

  • 7/28/2019 Vi Srm University

    22/50

    WHILE LOOP

    A While Loop executes all or a portion of

    your Block Diagram code multiple times.

    pseudo-code:

    Do

    Execute diagram Inside the loopWhile the condition is TRUE/FALSE

    Create a While Loop

    Block Diagram > Functions > Structures > While

    Loop

    Drag a rectangle area around the portion of Block

    Diagram code that is to be included in the while

    loop

  • 7/28/2019 Vi Srm University

    23/50

    While loop components

    The Conditional Terminal

    Continue if True condition. thewhile loop will continue to repeat the

    code until a boolean value of FALSE is

    passed to the conditional terminal.

    Stop if True condition. the whileloop will continue to repeat the codeuntil a boolean value of TRUE is

    passed to the conditional terminal.

    The Iteration Terminal

    outputs the number of times the loophas been executed

  • 7/28/2019 Vi Srm University

    24/50

    Controlling a while loop

    The conditional terminal is wired to a Boolean Terminal. This terminal represents a

    Boolean Control (switch) on the Front Panel for the user to control the operation of thewhile loop.

  • 7/28/2019 Vi Srm University

    25/50

    FOR LOOP

    The For Loop repeats Block Diagram code a

    predetermined number of counted times.When the number of iterations equals the

    predetermined count, the loop stops.

    pseudo-code:

    For i = 0 to N-1

    Execute diagram inside the loop

    Create a For Loop

    Block Diagram > Functions > Structures >

    For Loop:

    then drag a rectangle area around the portionof Block Diagram code that is to be included

    in the for loop

  • 7/28/2019 Vi Srm University

    26/50

    For loop components

    The Count TerminalThe Count Terminal is

    where the predetermined

    count is placed. to control

    the number of iterations.

    The Iteration TerminalTheIteration Terminal in a

    for loop It is a terminal that

    outputs the number of times

    the loop has been executed.

    The count starts at zero (thefirst iteration of the loop is

    Iteration Zero)

  • 7/28/2019 Vi Srm University

    27/50

    Case structures

    The Case Structure is a method of

    executing conditional statements. TheCase Structure is similar to if ... then ...

    else statements in conventional

    programming languages.

    pseudo code:

    If (Condition = Something) Then

    Do This

    Else

    Do That

    Endif

    Case Structure is configured like a deck of cards. Labview only executes one at a

    time. case executed is determined by the value wired to the selector terminal

  • 7/28/2019 Vi Srm University

    28/50

    CASE STRUCTURE DATA TYPES

  • 7/28/2019 Vi Srm University

    29/50

    Creating a Case Structure

    Creating a Case Structure is much like creating While Loops and For Loops. To create

    a Case Structure, Pop-up in the Block Diagram > Structures > Case Structure.Drag an area for the Case Structure to encompass.

    Managing case structure

  • 7/28/2019 Vi Srm University

    30/50

    The Select Function

    In simple if-then-else cases, you can use the Selectfunction:

    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 fterminal if the value at the s terminal is

    FALSE.

  • 7/28/2019 Vi Srm University

    31/50

    SEQUENCE STRUCTURES

    used to control the order of execution of nodes that are not data dependent on each other. The

    nodes within each frame are data dependent 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. 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. Data input is available to all frames. CREATING SEQUENCE STRUCTURE:Pop-up in the Block Diagram > Structures >Sequence Structure.

    Toaddmoreframes,popuponthesequenceboundary>AddFrameAfter

    SEQUENCE LOCAL: variablesthatallowyoutopassdatabetweenframesofaSequence

    Structure

  • 7/28/2019 Vi Srm University

    32/50

    Example for sequence local

  • 7/28/2019 Vi Srm University

    33/50

    FORMULAE NODE

    AFormulaNodeisaboxwhereyouenter

    algebraicformulas

    directly

    into

    the

    Block

    Diagram.Itisusefulwhenanequationis

    complicatedorhasmanyvariables.

  • 7/28/2019 Vi Srm University

    34/50

    Below is an example of how you would implement y= x^2 + x + 1 with regular block diagram nodes

    It is much easier to use the Formula Node.

  • 7/28/2019 Vi Srm University

    35/50

    CreatingaFormulaNode

    Pop-up in the Block Diagram > Structures > Formula Node.

    Add an Input and an Output on the left and right vertical sides of the Formula

    Node's boundary. The nodes must also be named to match the variables used in the equation.

    Add them by popping-up on a vertical boundary > Add Input or Add Output.

    Label them correctly and wire them to the appropriate nodes.

    Thentype

    equation

    using

    the

    correct

    operators

    and

    functions.

    A

    semicolon

    always

    followseachformulastatement.

  • 7/28/2019 Vi Srm University

    36/50

    ARRAYS

    Anarrayisacollectionofdataelements. The

    dataelements

    in

    an

    array

    can

    be

    numeric,

    boolean,stringorcluster,butalldataelementsmustbeofthesametypewithinan

    array.Arrays

    can

    be

    one

    or

    two

    dimensional.

  • 7/28/2019 Vi Srm University

    37/50

    ARRAY FUNCTIONS

    Arrays can also be created andcontrolled byArray

    Functions. They are all found by

    popping-up in the Block Diagram

    > Functions > Array:

  • 7/28/2019 Vi Srm University

    38/50

    ARRAY SIZE returns the number of

    elements in an array it

    is wired to.

    INITIALIZE

    ARRAY

    createsanarrayof

    dimensionsize

    elementscontaining

    theelementvalue.

    BUILD ARRAY linksmultiplearrays.It

    appendselements

    to

    anarray.

    itconcatenates

    multiplearrays

    ARRAY SUBSET returnsaportionofan

    arraystarting

    at indexand

    containing length elements

  • 7/28/2019 Vi Srm University

    39/50

    ARRAY

    SEARCHING

    searchesthenamearray

    forthe

    target

    and

    reports

    ifthetargetisfoundas

    wellasitspositioninthe

    array.

  • 7/28/2019 Vi Srm University

    40/50

    Creating One-Dimensional Arrays With a Loop

    Manually creating and

    adding data to arrays

    can be tedious work.

    So loops are often

    used to create one-

    dimensional and two-

    dimensional arrays.

    Both ForLoops and

    While Loops can

    create arrays and their

    boundaries

    automatically with

    auto indexing.

  • 7/28/2019 Vi Srm University

    41/50

    Creating TWO-Dimensional Arrays With nested Loop

    The outer

    loop creates

    the row

    elements andthe inner loop

    creates thecolumn

    elements.

  • 7/28/2019 Vi Srm University

    42/50

    To clear an array of data,

    pop-up on any Index Display >

    Empty Array:

    Clearing Array Data

  • 7/28/2019 Vi Srm University

    43/50

    INDEXING Indexing is a feature that can be enabled for input and output tunnels of both while-

    loops and for-loop

    When an array wire passes into a loop through a tunnel that does not have indexingenabled, the entire array is placed on the wire and can be accessed during each loop

    iteration. When indexing is enabled, only the array element at the index

    corresponding to the current loop iteration is available from that tunnel.s by right

    clicking on a tunnel.

  • 7/28/2019 Vi Srm University

    44/50

    INPUT INDEXING

    OUTPUT INDEXING

  • 7/28/2019 Vi Srm University

    45/50

    Polymorphism

    Labview arithmetic functions like Add, Multiply,

    Divide. Etc. are polymorphic. This means that

    the data structures on their inputs can be either

    scalar or array. If any inputs are of the array data

    structure, the output will be an array data

    structure. If the inputs have array structures ofdifferent sizes, the output will be an array that is

    the same size as the smallest input array.

  • 7/28/2019 Vi Srm University

    46/50

    Controlling Boolean Controls

    BooleanControls

    usually operate likeswitches. Most of them

    are in the off position

    by default (NormallyOpen). You can control

    the mechanical action

    of the Boolean Controlby popping-up on it >

    Mechanical Action

  • 7/28/2019 Vi Srm University

    47/50

    SwitchWhenPressed TheControl'svalueischangedeachtimethecontrolispressed.Thisworksmuchlikeastandardlightswitch.

    SwitchWhenReleased TheControl'svalueischangedwhenthemouse

    buttonis

    released.

    SwitchUntilReleased TheControl'svalueischangedwhenthecontrol

    isclickedandretainsthatvalueuntilthemousebuttonisreleased.

    Latch

    When

    Pressed

    The

    Control's

    value

    changes

    when

    it

    is

    clicked,

    retainsthatvalueuntiltheVIreadsitonceandthenreverts backtoit'soriginalvalue.

  • 7/28/2019 Vi Srm University

    48/50

    LatchWhenReleased TheControl'svaluechangeswhen

    themousebuttonisreleased,retainsthatvalueuntilthe

    VIreads

    it

    once

    and

    then

    reverts

    back

    to

    it's

    original

    value.

    LatchUntilReleased TheControl'svaluechangeswhenit

    isclicked,retainsthatvalueuntiltheVIreadsitonceor

    untilthe

    mouse

    button

    is

    released,

    whicheveroccurslast.

  • 7/28/2019 Vi Srm University

    49/50

    Showing a Boolean

    Controls State

    popping up on the control >

    Visible Items > Boolean Text

  • 7/28/2019 Vi Srm University

    50/50

    THANK YOU