EET 159: Week 1

1 / 200
About This Presentation
Title:

EET 159: Week 1

Description:

Create a free label by using the labeling tool on the tools palette or by double ... In LabVIEW's Example Finder, browse according to Task. ... – PowerPoint PPT presentation

Number of Views:98
Avg rating:3.0/5.0
Slides: 201
Provided by: nickr5

less

Transcript and Presenter's Notes

Title: EET 159: Week 1


1
EET 159 Week 1
  • LabVIEW Basics (Chapter 1)
  • Lab 1 and Homework 1 due next week.

2
LabVIEW
  • Stands for Laboratory Virtual Instrument
    Engineering Workbench.
  • Its a software package created by National
    Instruments (www.ni.com).
  • (Bishop, p. 3)

3
National Instruments
  • Company founded about 25 years ago in Austin, TX.
  • In addition to LabVIEW and other software
    packages, they sell data acquisition boards and
    other hardware for using computers in
    engineering, science, and industry.
  • (Bishop, pp. 3-4)

4
Some of LabVIEWs Uses
  • General-purpose programming
  • Instrument control
  • Data acquisition
  • Data analysis
  • Data presentation
  • Automated testing

5
General-purpose Programming
  • Writing programs to perform calculations, process
    information, play games, etc.
  • This is not really what LabVIEW is meant for, but
    you could use it to do these things.

6
Instrument Control
  • Using computer to control multimeters,
    oscilloscopes, function generators, etc.

7
Data Acquisition (DAQ)
  • Connecting the computer directly to circuits or
    sensors to measure voltage, current, temperature,
    pressure, light intensity, chemical composition,
    etc.
  • Need to have a special data-acquisition board
    installed in your computer.

8
Data Analysis
  • Performing statistical analysis, curve fitting,
    signal processing, or other kinds of mathematical
    calculations on the data that youve gathered
    from a DAQ board or from measuring instruments.
  • Similar to what you can do with Microsoft Excel
    or other spreadsheet programs.

9
Data Presentation
  • Using tables, charts, and graphs to present the
    results of your data analysis.
  • Again, similar to what you can do with Microsoft
    Excel or other spreadsheet programs.

10
Automated Testing
  • Using computers to automatically test circuit
    boards or other manufactured parts as they leave
    an assembly line.

11
G
  • LabVIEW is built around a programming language
    called G.
  • Most of this course will be devoted to learning
    how to write programs in G.
  • (Bishop, p. 4)

12
Graphical vs. Text-Based Language
  • Most other programming languages (QBasic,
    VisualBasic, C, C, Java, etc.) are text-based
    languages. You write programs by typing text.
  • G is a graphical language. You write programs by
    dragging and connecting icons.
  • (Bishop, p. 4)

13
Example Program in QBasic
  • CLS
  • INPUT Enter first number , x
  • INPUT Enter second number , y
  • z x y
  • PRINT The product is z

14
Same Program in LabVIEW
15
Virtual Instruments
  • LabVIEW programs are called virtual instruments,
    or VIs for short.
  • When you save a program to a file, be sure that
    the file extension is .vi
  • (Bishop, p. 4)

16
Front Panel Block Diagram
  • Every LabVIEW program has two parts, which appear
    in two different windows on your computer screen
    the front panel and the block diagram.

17
Front Panel
  • The front panel is the user interface for a
    program. It contains controls (inputs) and
    indicators (outputs).
  • Controls let the user feed data into the program.
  • Indicators let the program give data back to the
    user.

18
Sample Front Panel
19
Block Diagram
  • The block diagram shows the programs underlying
    logic. It shows how the users data (entered
    through controls) is manipulated to give the
    results that are fed back to the user (through
    indicators).
  • The block diagram contains components wired
    together.

20
Sample Block Diagram
21
Toolbar
Run Button Continuous Run Button Abort
Execution Pause/Continue Button Text
Settings Align Objects Distribute
Objects Reorder Resize front panel objects
Additional Buttons on the Diagram Toolbar
Execution Highlighting Button Step Into
Button Step Over Button Step Out Button
(Bishop, pp. 9-14)
22
Controls Functions Palettes
Controls Palette (Used to place controls
Indicators on Front Panel)
Functions Palette (Used to place functions on
Block Diagram)
(Bishop, pp. 23-26)
23
Menus
  • LabVIEW has both pull-down menus and short-cut
    menus (pop-up menus) that give you many options.
  • Sections 1.6 and 1.7 in textbook discuss the
    menus.
  • (Bishop, pp. 14-21)

24
Help
  • LabVIEWs context help window is very useful. It
    automatically shows help for functions and other
    objects when you roll your mouse over those
    objects.
  • More detailed help is also available through Help
    menu.
  • (Bishop, pp. 28-29)

25
Context Help Window
  • Ctrl H
  • Detailed help
  • Lock help
  • Simple/Complex Diagram help

26
Example Programs
  • LabVIEW comes with many example VIs, which youll
    find in the examples directory after you install
    LabVIEW.
  • More examples are in the textbooks learning
    files, which you can download from
    http//www.prenhall.com/bishop
  • (Bishop, p. 5)

27
EET 159 Week 2
  • Virtual Instruments (Chapter 2)
  • Lab 2 and Homework 2 due next week.
  • Quiz 1 next week.

28
Virtual Instruments
  • Remember, LabVIEW programs are called virtual
    instruments, or VIs for short.
  • Recall that every VI has a front panel (user
    interface) and a block diagram (program code).
  • (Bishop, p. 46)

29
Items on Front Panel
  • The front panel contains controls and indicators.
  • Controls are inputs that let the user enter data,
    such as switches, knobs.
  • Indicators are outputs that display data to the
    user, such as graphs, numeric displays.
  • (Bishop, p. 55)

30
Controls Palette
  • Use the controls palette to place controls or
    indicators on the front panel. (Open palette
    by View Controls Palette or by right-clicking a
    blank area on front panel.)
  • (Bishop, p. 55)

31
Finding Controls Indicators
  • On the controls palette, under Modern, the most
    commonly used controls and indicators are grouped
    into three categories Numeric, Boolean, and
    String Path.

32
Search Button on Controls Palette
  • Search button lets you find controls or
    indicators by name.
  • (Bishop, p. 57)

Search
33
Items on Block Diagram
  • The block diagram contains items connected by
    wires. These items may be terminals representing
    front-panel controls or indicators, built-in
    functions (such as multiplication), or subVIs.
  • A subVI is a smaller program contained within a
    bigger program.
  • (Bishop, pp. 60-61)

34
Distinguishing Functions from SubVIs (Part 1)
  • On block diagrams, built-in functions have a pale
    yellow background, while subVIs usually have a
    white background (except for Express VIs, which
    have a blue background).
  • (Bishop, p. 61)

35
Distinguishing Functions from SubVIs (Part 2)
  • When you double-click a function, nothing
    happens.
  • When you double-click a standard subVI, the front
    panel for the subVI opens. (Remember, a subVI is
    a complete program with its own front panel and
    block diagram.)
  • When you double-click an Express VI, a dialog box
    opens to let you configure it.
  • (Bishop, p. 61)

36
Functions, SubVIs, and Express VIs
  • Functions Cant be customized.
  • Standard subVIs You can rewire the block diagram
    to customize.
  • Express VIs You use dialog box to customize.

37
Icons vs. Expandable Nodes
  • Standard subVIs and Express VIs can be displayed
    either as icons or as expandable nodes.
  • To change display, right-click and select (or
    deselect) View As Icon.
  • (Bishop, p. 61)

38
Example
  • Same VI, viewed three different ways.

Icon Expandable
Node Expanded Node
39
Terminals
  • A terminal on a block diagram is a connection
    point for a wire. There are several kinds of
    terminals
  • Constants
  • Control terminals for inputs from front panel
  • Indicator terminals for outputs to front panel
  • Node terminals on functions or subVIs
  • (Bishop, p. 62)

40
Control Terminals
  • A control terminal has an arrow pointing out to
    the right.
  • Theres a control terminal on the block diagram
    for each control on the front panel.
  • On front panel, can right-click and choose Find
    Terminal.
  • On block diagram, can right-click and choose
    Find Control.
  • (Bishop, p. 63)

41
Indicator Terminals
  • An indicator terminal has an arrow pointing in
    from the left.
  • Theres an indicator terminal on the block
    diagram for each indicator on the front panel.
  • On front panel, can right-click and choose Find
    Terminal.
  • On block diagram, can right-click and choose
    Find Indicator.
  • (Bishop, p. 63)

42
Icons vs. Data Type Terminals
  • On the block diagram, control terminals and
    indicator terminals can be displayed either as
    icons or as data type terminals.
  • To change display, right-click and select (or
    deselect) View As Icon.
  • (Bishop, p. 63)

Icon Data Type Terminal
43
Terminals on Functions or SubVIs (Part 1)
  • Functions and subVIs also have terminals where
    wires can connect to them.
  • Usually inputs are on the left and outputs are on
    the right.

44
Terminals on Functions or SubVIs (Part 2)
  • To show terminals more clearly, right-click and
    select Visible Items Terminals

45
Colors for Data Types
  • Terminals and wires are color-coded to show what
    type of data they carry
  • Blue integer
  • Orange floating point number
  • Green Boolean (true/false)
  • Pink String (text)
  • Blue White Dashed Dynamic (Express VIs)
  • Usually two terminals can be connected together
    by a wire only if theyre the same data type.
  • (Bishop, p. 63)

46
Dataflow Programming
  • In traditional text-based programming languages,
    the order of the statements determines the order
    in which theyre executed.
  • In LabVIEWs graphical language, the layout on
    the page does not tell you the order of
    execution. A node executes whenever all of its
    inputs are available.
  • (Bishop, pp. 73-74)

47
Highlight Execution Button
  • To watch the order in which nodes are executed in
    the block diagram, click the Highlight Execution
    button on block diagrams toolbar and then run
    the VI.
  • (Bishop, p. 74)

Click on Highlight Execution button data flow is
animated using bubbles. Values are displayed on
wires.
48
EET 159 Week 3
  • Editing and Debugging Virtual Instruments
    (Chapter 4)
  • Lab 3 and Homework 3 due next week.
  • Quiz 2 next week.

49
Editing Techniques
  • Editing techniques include
  • Creating controls indicators on block diagram
  • Selecting objects
  • Moving objects
  • Deleting objects
  • Duplicating objects
  • Resizing objects
  • Labeling objects
  • Changing text font, style, size, color
  • Working with wires
  • Aligning, distributing, and resizing objects
  • Coloring objects
  • (Bishop, pp. 148-168)

50
Creating Controls Indicators on Block Diagram
  • After placing a function or subVI on block
    diagram, right-click on one of its terminals and
    select Create Control or Create Indicator.
  • This adds a control or indicator to the front
    panel and automatically wires it on the block
    diagram.
  • (Bishop, p. 148)

51
Tools Palette
  • Lets you operate and modify objects on front
    panel or block diagram.

Automatic Selection Tool
Scrolling Tool Breakpoint Tool Probe Tool Color
Copy Tool Coloring Tool
Operating Tool Positioning/Resizing Tool Labeling
Tool Wiring Tool Shortcut Menu Tool
(Bishop, p. 22)
52
Selecting Objects
  • To move, delete, or copy an object on the front
    panel or block diagram, you must first select the
    object.
  • The easiest way to select an object or objects is
    to drag a box around them.
  • You can also select an object by clicking it with
    the positioning tool, and you can select multiple
    objects by shift-clicking.
  • (Bishop, p. 149)

53
Moving Objects
  • After selecting an object or objects, move by
    dragging with the mouse or using the arrow keys.
  • (Bishop, p. 152)

54
Deleting Objects
  • After selecting an object or objects, delete by
    pressing Delete or Backspace key, or by Edit
    Clear on pull-down menus.
  • (Bishop, p. 152)

55
Duplicating Objects
  • After selecting an object or objects, duplicate
    by Edit Copy and Edit Paste on pull-down
    menus (or use CtrlC and CtrlV shortcut keys).
  • (Bishop, p. 153)

56
Resizing Objects
  • Resize an object on the front panel by dragging
    the resize handles that appear when you move the
    positioning tool over the object.
  • (Bishop, p. 153)

57
Labeling Objects
  • Create a free label by using the labeling tool on
    the tools palette or by double-clicking on blank
    area of front panel or block diagram.
  • Show or hide an objects owned label by using
    short-cut menus Visible Items Label.
  • Edit any label by double-clicking.
  • (Bishop, p. 154)

58
Changing Text Font, Style, Size, Color
  • Use the Text Settings drop-down box on the
    toolbar to change text appearance. (Similar to
    word processors.)
  • (Bishop, p. 156)

59
Working with Wires
Wiring Hot Spot
Click To Select Wires
Clean Up Wiring
(Bishop, p. 158)
60
Broken Wires
  • Remove a single broken wire by selecting and
    pressing Delete key.
  • Remove all broken wires by using Edit Remove
    Broken Wires pull-down menu (or CtrlB shortcut
    key).
  • (Bishop, p. 161)

61
Aligning, Distributing, and Resizing Objects
  • After selecting two or more objects, use buttons
    on the toolbar to align them with each other,
    space them evenly apart, or make them all the
    same size.
  • (Bishop, p. 164)

Align Distribute Resize
62
Coloring Objects
  • Use the coloring tool on the tools palette to
    change colors of objects.
  • For many front-panel objects, you can also change
    the color by choosing Properties on the objects
    shortcut menu.
  • (Bishop, pp. 166-168)

63
Adding a Description
  • You should document your VI by adding a
    description of what it does.
  • To do this, choose File VI Properties in the
    pull-down menus, then select Documentation from
    the drop-down box, and then type your
    description.

64
Adding More Detailed Info
  • In addition to a description for the entire VI,
    you can also add a description for each control
    and indicator on the VIs front panel.
  • To do this, right-click on the control or
    indicator and choose Description and Tip. Then
    type a description and a brief tip.
  • Now when you roll over the object, its
    description will appear in the Context Help
    window and its tip will appear next to the
    object.

65
Debugging Techniques
  • Debugging techniques include
  • Using Broken Run button to find errors
  • Execution highlighting
  • Single-stepping
  • Breakpoints
  • Probes
  • (Bishop, pp. 173-178)

66
Broken Run Button
  • When the block diagram contains an error that
    prevents the VI from running, the Broken Run
    button appears in place of the normal Run button.
  • (Bishop, p. 173)

Click on Broken Run button to open window
listing errors.
67
Execution Highlighting
  • To monitor the execution of the block diagram,
    click Highlight Execution button on block
    diagrams toolbar and then run the VI.
  • (Bishop, p. 175)

Click on Highlight Execution button data flow is
animated using bubbles. Values are displayed on
wires.
68
Single-Stepping
  • To execute block diagram one node at a time, use
    one of the single-stepping buttons on block
    diagrams toolbar.
  • (Bishop, p. 175)

Step Into button executes current node. If
current node is a subVI, its first step is
executed.
Step Over button executes current node. If
current node is a subVI, entire subVI is executed.
Step Out button executes until current subVI
(or entire program) finishes.
69
Execution Highlighting and Single-Stepping
  • Usually when you single-step, youll also want to
    have execution highlighting turned on so that you
    can see the effect of each step.
  • (Bishop, p. 176)

70
Breakpoints
  • Set a breakpoint in block diagram by using
    Breakpoint tool on tools palette or by
    right-clicking on an object.
  • When you run VI, execution will stop when it
    reaches the breakpoint.
  • (Bishop, p. 177)

71
Probes
  • Place a probe in block diagram by using Probe
    tool on tools palette or by right-clicking on
    wire.
  • When you run VI, window displays value at the
    point where the probe is placed.
  • (Bishop, p. 178)

72
Some Shortcut Keys
  • CtrlB removes broken wires.
  • CtrlE switches between front panel block
    diagram.
  • CtrlT tiles front panel block diagram side by
    side.
  • CtrlH turns help window on or off.
  • Plus standard Windows shortcuts
  • CtrlO to open file.
  • CtrlS to save file.
  • CtrlC to copy.
  • CtrlV to paste.
  • CtrlZ to undo.
  • (Bishop, p. 182)

73
EET 159 Week 4
  • SubVIs (Chapter 5)
  • Lab 4 and Homework 4 due next week.

74
Modular Programming
  • When writing a complex program, good programmers
    divide their programs into separate parts that
    can be written and tested independently, and that
    can be re-used in other programs.
  • In text-based programming languages, these parts
    are called subroutines.
  • In LabVIEW theyre called subVIs.
  • (Bishop, p. 197)

75
Hierarchy of VIs
  • Your main VI can contain one or more subVIs.
  • Each of those subVIs can contain one or more
    smaller subVIs.
  • Each of those smaller subVIs can contain even
    smaller subVIs.
  • And so on

76
Example E-Mail Notification.vi
  • In LabVIEWs Example Finder, browse according to
    Task. Open Networking folder, then open Internet
    Web folder. Then open E-Mail Notification.vi.
  • In its block diagram, double-click on SMTP Email
    Send Message.vi.
  • In its block diagram, double-click on SMTP Email
    Send Message Charset.vi.
  • And so on

77
Hierarchy Window
  • LabVIEWs VI Hierarchy Window shows how all of
    these VIs are related to each other.
  • Open the window by using View VI Hierarchy in
    pull-down menus.
  • (Bishop, p. 217)

78
Example E-Mail Notification.vi
79
A Simpler Example
  • Suppose youre writing a program that lets the
    user enter values for x, y, and z, and then
    calculates x3 y3 z3. Rather than placing all
    of the multiply functions to compute x3, y3, and
    z3 individually, consider building a subVI that
    will cube any number.

80
Steps in Creating a SubVI
  • Create the VI.
  • Create the icon.
  • Create the connector with the correct number of
    input and output terminals.
  • Assign the connectors terminals to the VIs
    controls and indicators.
  • Add a description.
  • Save the VI.

81
Icon
  • A subVI is represented by an icon on the block
    diagram of a VI that uses the subVI.
  • When a VIs front panel or block diagram is open,
    the VIs icon appears in the upper right corner.
  • The default icon is the LabVIEW logo along with a
    number.
  • (Bishop, p. 201)

82
Icon Editor
  • If you plan to use a VI as a subVI, you should
    replace the default icon with a more informative
    icon.
  • Use the icon editor to do this. Right-click on
    the icon in the front panel and select Edit
    Icon.
  • (Bishop, p. 201)

83
Connector
  • To use a VI as a subVI, you must assign it a
    connector so that youll be able to attach wires
    to it on the block diagram of a VI that uses it
    as a subVI.
  • The connector contains one terminal for each of
    the subVIs inputs and outputs.
  • (Bishop, p. 203)

Input terminals
Output terminal
Connector
84
Creating the Connector
  • To create the connector, right-click on the icon
    in the front panel and select Show Connector.
  • By default, the connector has one input for each
    control and one output for each indicator.
  • To change this, right-click the connector and
    select Patterns.
  • (Bishop, p. 204)

85
Assigning Terminals to Controls and Indicators
  • Next, you must assign each terminal on the
    connector to a control or indicator.
  • To do this, click on a terminal with the Wiring
    tool and then click on the control or indicator
    that you want to assign to that terminal.
  • For clarity, assign inputs (controls) to
    terminals on the left, and outputs (indicators)
    to terminals on the right.
  • (Bishop, p. 206)

86
Required, Recommended, Optional Terminals
  • You can identify each terminal as being required,
    recommended, or optional.
  • If required terminals are left unwired, then the
    VI will not run as a subVI. But it will run when
    recommended or optional terminals are left
    unwired.
  • By default, all terminals are recommended.
  • To change a terminals status, right-click the
    terminal and select This Connection Is.
  • (Bishop, p. 207)

87
Context Help Window
  • Information about a subVI appears automatically
    in the Context Help window when you roll the
    mouse over the subVIs icon on a block diagram.
  • This information includes
  • the subVIs name and icon
  • the name of each terminal (in bold text if its
    required, in plain text if its recommended, in
    gray text if its optional)
  • The subVIs description, if you added one
  • (Bishop, p. 207)

88
Adding a Description
  • Remember from last week that to add a
    description, you choose File VI Properties from
    the pull-down menus and then choose Documentation.

89
Summary Creating a SubVI
  • Create the VI.
  • Create the icon.
  • Create the connector with the correct number of
    input and output terminals.
  • Assign the connectors terminals to the VIs
    controls and indicators.
  • Add a description.
  • Save the VI.

90
Using a VI as a SubVI
  • After youve created and saved a VI, how do you
    use it as a subVI?
  • To place it as a subVI on another VIs block
    diagram, choose All Functions on the Functions
    palette, then choose Select a VI and then locate
    your VI.
  • (Bishop, p. 211)

91
Creating a SubVI from a Selection
  • Heres another way to create a subVI from an
    existing VI
  • On the block diagram, select the objects to
    become part of your subVI.
  • Select Edit Create SubVI from the pull-down
    menus.
  • (Bishop, p. 214)

92
EET 159 Week 5
  • Loops (Sections 6.1, 6.2, and 6.9)
  • Lab 5 and Homework 5 due next week.
  • Quiz 3 next week.

93
Structures
  • Structures control the flow of a programs
    execution.
  • This week we look at two kinds
  • For Loops
  • While Loops
  • Later well look at other kinds
  • Sequence Structures
  • Case Structures
  • (Bishop, p. 232)

94
For Loop
  • A For Loop executes the code inside its borders a
    specified number of times.
  • The code inside the For Loops borders is called
    a subdiagram.
  • A For Loop has two terminals the count terminal
    and the iteration terminal.
  • (Bishop, p. 233)

95
For Loop Example
96
Placing a For Loop
  • For Loops are found on the Functions
    Programming Structures palette.
  • Click it, and then drag to create a loop on the
    block diagram.
  • Then place items inside the loop to build your
    subdiagram.
  • (Bishop, p. 234)

97
Count Terminal
  • A For Loops Count Terminal, labeled N, lets you
    set how many times the loop will execute.
  • You can set the count to a constant, or to a
    value set by the user through a control, or to
    the output of a function, etc.
  • The count is available to be used inside the
    loop.
  • (Bishop, p. 233)

98
Iteration Terminal
  • A For Loops Iteration Terminal, labeled i,
    contains the number of loop iterations that have
    been completed.
  • The iteration number is available to be used
    inside the loop.
  • It starts at 0 and increases to N-1.
  • (Bishop, p. 233)

99
Inserting a Time Delay
  • For Loops usually run so quickly that the user
    cant see whats happening.
  • To add a time delay, use either the old-fashioned
    Wait (ms) function or the newer Time Delay
    Express VI.
  • Both are found on the Functions Programming
    Timing palette.
  • Simply place either one anywhere inside the loop.

100
Tunnels
  • If a wire crosses the border of a loop (or other
    structure), a tunnel automatically appears on the
    border.
  • Doing this can be useful, but can also be very
    tricky and lead to errors unless you keep in mind
    that data will pass out of a structure through a
    tunnel only after the entire structure finishes
    executing.

101
Example For Loop in QBasic
  • The type of loop weve been discussing is called
    a For Loop because in traditional programming
    languages (such as QBasic) it is coded using the
    word FOR.
  • Example
  • CLS
  • FOR i 1 TO 15
  • PRINT i, 2 i
  • NEXT i

102
Integer Representations
  • Recall that blue terminals and blue wires
    represent integer numbers.
  • Integer terminals can be further categorized into
    byte integer (I8), word integer (I16), long
    integer (I32), and quad integer (I64).
  • This is called the representation of the
    number, and you can change it by right-clicking
    on a terminal and choosing Representation.

103
Integer Representations (Continued)
  • These representations differ in the range of
    values that they can handle and the amount of
    memory that they use.
  • Byte integer (I8) max. 127
  • Word integer (I16) max. 32,767
  • Long integer (I32) max. 2,147,483,647
  • Quad integer (I64) max. 1?1019

104
Floating-Point Representations
  • Recall that orange terminals and orange wires
    represent floatingpoint numbers.
  • Floating-point terminals can be further
    categorized into single precision, double
    precision, and extended precision.

105
Floating-Point Representations (Continued)
  • These representations differ in the range of
    values that they can handle and the amount of
    memory that they use.
  • Single-precision max. 3.40 x 1038
  • Double-precision max. 1.79 x 10308
  • Extended-precision max. 1.19 x 104932

106
Numeric Conversion
  • If you wire together two terminals of different
    numeric representations, LabVIEW must convert the
    number from one representation to the other.
  • In these cases a red dot called a coercion dot
    will appear on the terminal where the conversion
    takes place.
  • In general, you should try to avoid doing this.
    It can lead to rounding errors that are difficult
    to find.
  • (Bishop, p. 235)

107
While Loop
  • A While Loop executes the code inside its borders
    repeatedly until a certain condition is met.
  • A While Loop has two terminals the iteration
    terminal and the conditional terminal.
  • (Bishop, p. 238)

108
While Loop Example
109
Placing a While Loop
  • While Loops are found on the Functions
    Programming Structures palette.
  • Click it, and then drag to create a loop on the
    block diagram.
  • Then place items inside the loop to build your
    subdiagram.

110
Iteration Terminal
  • A While Loops Iteration Terminal, labeled i,
    contains the number of loop iterations that have
    been completed.
  • It behaves just like a For Loops iteration
    terminal.
  • The iteration number is available to be used
    inside the loop.
  • (Bishop, p. 238)

111
Conditional Terminal
  • A While Loops Conditional Terminal determines at
    the end of each loop execution whether the loop
    will be executed again.
  • You set the Conditional Terminal to either Stop
    if True or Continue if True.
  • Usually youll wire a Boolean control or the
    output of a Boolean function to this terminal.
  • (Bishop, p. 238)

112
Conditional TerminalStop if True
  • When the Conditional Terminal is set to Stop if
    True, it looks like a red stop sign on the block
    diagram.
  • A true condition will cause the loop to stop
    executing, but a false condition will cause it to
    execute again.
  • (Bishop, p. 240)

113
Conditional TerminalContinue if True
  • When the Conditional Terminal is set to Continue
    if True, it looks like a green looping arrow on
    the block diagram.
  • A true condition will cause the loop to execute
    again, but a false condition will cause it to
    stop executing.
  • (Bishop, p. 240)

114
Example While Loop in QBasic
  • This type of loop is called a While Loop
    because in traditional programming languages it
    is coded using the word WHILE.
  • Example
  • CLS
  • INPUT Guess my age. , guess
  • WHILE guess 46
  • INPUT No. Try again. , guess
  • WEND
  • PRINT You got it!

115
EET 159 Week 6
  • Shift Registers and Feedback Nodes (Section 6.3)
  • Sequence Structures (Section 6.5)
  • Lab 6 and Homework 6 due next week.
  • Quiz 4 next week.

116
Shift Registers and Feedback Nodes
  • When programming with loops, you may need to
    access data from previous iterations of the loop.
  • LabVIEW provides two ways to do this
  • Shift registers
  • Feedback nodes
  • (Bishop, p. 244)

117
Shift Registers
  • Shift registers transfer values from one
    iteration of a For Loop or While Loop to the next
    iteration.
  • To create a shift register, right-click on the
    left or right border of a loop and select Add
    Shift Register.
  • (Bishop, p. 244)

118
Shift Registers (Continued)
  • A shift register appears as a set of arrows on
    the borders of the loop an up arrow on the right
    border, and one or more down arrows on the left
    border.
  • These arrows are terminals that can be wired to
    other items inside or outside the loop.
  • (Bishop, p. 244)

119
Using a Shift Register
  • The terminal on the right border receives and
    stores a data value as each iteration of the loop
    finishes.
  • This value then becomes available from the
    terminal on the left-hand border during the next
    iteration.
  • (Bishop, p. 244)

120
Using a Shift Register (Continued)
  • The shift registers initial value is set by
    wiring the left terminal to a constant or a
    control or another element outside of the loop.
    For consistent results, always initialize your
    shift registers.
  • The shift registers final value can be used by
    wiring the right terminal to an element outside
    of the loop.
  • (Bishop, pp. 247-248)

121
Feedback Nodes
  • Feedback Nodes offer another way to transfer
    values from one iteration of a loop to the next
    iteration.
  • Shift registers are more powerful because they
    can remember as many of the previous values as
    you want, while feedback nodes can only remember
    one previous value.
  • (Bishop, p. 250)

122
Feedback Nodes (Continued)
  • A Feedback Node appears as an arrow inside a
    rectangle, along with an associated Initializer
    Terminal on the loops left border.
  • (Bishop, p. 250)

123
Converting Between Shift Registers Feedback
Nodes
  • A Feedback Node can be converted to a shift
    register (or vice versa) by right-clicking and
    selecting Replace with Shift Register (or
    Replace with Feedback Node).
  • A Feedback Node will appear automatically if you
    wire the output of an element or group or
    elements to the input of that same element or
    group.
  • (Bishop, p. 250)

124
Sequence Structures
  • In traditional, text-based programming languages,
    the order of the statements determines the order
    of execution. But in LabVIEW, you cant always
    predict the order of execution.
  • Sequence structures are used to force code to
    execute in a specific sequence.
  • (Bishop, p. 263)

125
Frames in Sequence Structures
  • The code to be executed sequentially is entered
    on subdiagrams called frames. The analogy is to
    frames of movie film, which are projected one
    after another.
  • (Bishop, p. 263)

126
Flat or Stacked?
  • LabVIEW has two kinds of Sequence structures
  • Flat Sequence structures, in which the frames are
    laid out side by side, as in the image on the
    previous slide.
  • Stacked Sequence structures, in which the frames
    are stacked like a deck of cards, with only one
    visible at a time.
  • (Bishop, p. 263)

127
Flat or Stacked? (Continued)
  • The two kinds of Sequence structure are similar.
    The main difference is how much space they take
    up on the block diagram. But there are other
    differences, such as
  • If data is wired out through a tunnel from a
    frame in a Flat Sequence structure, the data
    passes out as soon as that frame finishes
    executing.
  • If data is wired out through a tunnel from a
    frame in a Stacked Sequence structure, the data
    does not pass out until the entire structure
    finishes executing.

128
Use Sequence Structures Only When Necessary
  • Sequence structures serve a valid purpose, but
    they also tend to hide parts of the program and
    interfere with the natural flow of data in
    LabVIEW.
  • Avoid using them unless you have a situation
    where you need to guarantee the order of
    execution, and LabVIEWs natural data flow does
    not provide such a guarantee.
  • (Bishop, p. 266)

129
EET 159 Week 7
  • Case Structures (Section 6.4)
  • Formula Nodes (Section 6.6)
  • Lab 7 and Homework 7 due next week.
  • Quiz 5 next week.

130
Structures
  • Structures control the flow of a programs
    execution.
  • Weve looked at several kinds
  • For Loops
  • While Loops
  • Sequence Structures
  • This week we look at two more
  • Case Structures
  • Formula Nodes
  • (Bishop, p. 232)

131
Case Structure
  • Case structures provide a way to execute
    different code depending on which one of several
    possible conditions is true.
  • Traditional programming languages accomplish the
    same thing using IF statements or CASE
    statements.
  • (Bishop, p. 252)

132
Placing a Case Structure
  • Case structures are found on the
    ProgrammingStructures palette.
  • As with loops, click it, and then drag to create
    a Case structure on the block diagram.
  • (Bishop, p. 253)

133
Subdiagrams
  • A Case structure has multiple subdiagrams, one of
    which is executed when the structure runs.
  • These subdiagrams are stacked on top of each
    other like a deck of cards, so that only one is
    visible at a time.
  • The selector label on the top border tells which
    case is visible, and has arrow buttons to let you
    step through the cases.
  • (Bishop, pp. 253-254)

134
Selector Terminal
  • A Case structure has one terminal, called the
    selector terminal.
  • This terminal, labeled ?, determines which one of
    the structures subdiagrams will be executed.
  • Youll usually wire this terminal to a control or
    to the output of a function.
  • (Bishop, p. 254)

135
Selecting Which Case to Execute Boolean Example
  • A Case structure with a Boolean selector terminal
    will have two subdiagrams one that executes if
    the condition wired to the terminal is true, and
    one that executes if the condition is false.

136
Selecting Which Case to Execute Numeric Example
  • A Case structure with a numeric selector terminal
    can have any number of subdiagrams the one
    thats executed depends on the value wired to the
    terminal.

137
Numeric Selector Labels
  • A numeric selector label can be
  • a single integer, such as 24
  • a list of integers, such as 1, 5, 11
  • a range of integers, such as
  • 10..20 meaning all integers from 10 to 20
  • ..10 meaning all integers less than or 10
  • 10.. meaning all integers greater than or 10
  • Selector labels cannot be floating point numbers.
  • (Bishop, p. 255)

138
Adding and Deleting Cases
  • Right-click a Case structures border and then
  • choose Add Case Before or Add Case After to add a
    case.
  • choose Duplicate Case to copy a subdiagram to a
    new case.
  • choose Delete This Case to remove a case.
  • (Bishop, p. 255)

139
Default Case
  • Numeric case structures and string case
    structures must have a default case, which will
    execute whenever none of the other cases apply.
  • To make a case the default case, right-click its
    border and choose Make This The Default Case.
  • (Bishop, p. 256)

140
Tunnels
  • Recall that a tunnel automatically appears on a
    structures border when you run a wire across the
    border.
  • If data flows from outside the structure to
    inside, the tunnel is an input tunnel.
  • If data flows from inside the structure to
    outside, its an output tunnel.
  • If an output tunnel is wired on one of a Case
    structures subdiagrams, then it must be wired on
    all of the subdiagrams.
  • (Bishop, pp. 256-257)

141
Example IF Statement in QBasic
  • CLS
  • INPUT How many CDs are you buying? , CDs
  • IF CDs 5 THEN
  • Cost 9 CDs
  • PRINT You get a discount!
  • ELSE
  • Cost 10 CDs
  • END IF
  • PRINT Total cost is Cost

142
Example CASE Statement in QBasic
  • CLS
  • INPUT How many CDs are you buying? , CDs
  • SELECT CASE CDs
  • CASE IS 10
  • Cost 8 CDs
  • CASE IS 5
  • Cost 9 CDs
  • CASE ELSE
  • Cost 10 CDs
  • END SELECT
  • PRINT Total cost is Cost

143
Entering Formulas
  • You can perform just about any mathematical
    calculation using LabVIEWs built-in arithmetic
    functions on the Functions Mathematics
    palette.
  • But for long, complicated formulas, there are two
    easier ways
  • Formula Nodes
  • the Formula Express VI

144
Formula Nodes
  • The Formula Node, which Bishop describes on pages
    266-269, lets you type in formulas using the
    keyboard.
  • Formulas must end with a semicolon.
  • To raise a number to a power, type .
  • Example to set y equal to x squared, type
  • y x2
  • (Bishop, pp. 266-269)

145
Formula Express VI
  • The Formula Express VI, which Bishop does not
    describe in the book, provides an even easier way
    to enter formulas.
  • It uses a calculator keyboard interface, so you
    dont have to remember the syntax for
    constructing formulas.

146
EET 159 Week 8
  • Arrays (Sections 7-1 to 7-3)
  • Homework 8 and Lab 8 due next week.

147
Arrays and Clusters
  • An array is a variable-sized collection of data
    elements that are all of the same data type (such
    as floating point, integer, string, or Boolean).
  • A cluster is a fixed-sized collection of data
    elements of mixed data types.
  • (Bishop, p. 290)

148
Usefulness of Arrays
  • Arrays are useful when you have a collection of
    data points that you wish to plot or a collection
    of similar items that you wish to manipulate as a
    group.
  • (Bishop, p. 290)

149
Dimension of an Array
  • Every array has a dimension.
  • Well deal primarily with one-dimensional arrays,
    which you can think of as a list of items.
  • Example a list of student grades on a single
    assignment in a class 90, 77, 82, 95, 60,
  • (Bishop, p. 290)

150
Creating an Array of Controls or Indicators
  • To create an array of controls or indicators
  • Place an array shell on the front panel from the
    Controls Modern Array, Matrix Cluster
    palette.
  • Place a control or indicator inside that array
    shell.
  • (Bishop, p. 291)

151
Displaying Multiple Elements
  • To display more than one element of an array on
    the front panel, drag the arrays resizing
    handles until the desired number of elements are
    visible.
  • The box to the left shows the index of the first
    visible element.
  • (Bishop, p. 291)

152
Index of an Arrays Elements
  • Each element in an array can be referred to by
    its index, which is a integer showing the
    elements position in the array.
  • In LabVIEW, indexes are zero-based. So the first
    element in a one-dimensional array has an index
    of 0, the second element has an index of 1, and
    so on.
  • If a one-dimensional array contains n elements,
    the last element has an index of n?1.
  • (Bishop, p. 290)

153
Array Terminal on Block Diagram
  • When an array shell is first created, its
    terminal on the block diagram is outlined in
    black and shows no data type.
  • After the arrays data type has been defined by
    placing an item in the shell, the terminal
    changes color to show the data type.
  • (Bishop, p. 291)

154
Array Wires on Block Diagram
  • On the block diagram, a wire carrying an array of
    data values appears thicker than a wire carrying
    a single data value.
  • (Bishop, p. 291)

155
Creating Arrays with Loops
  • A feature called auto-indexing on For Loops and
    While Loops lets you tell LabVIEW to create
    arrays automatically when the loops run.
  • To enable or disable auto-indexing, right-click a
    tunnel on a loops border and select Enable
    Indexing or Disable Indexing.
  • (Bishop, pp. 294-295)

156
Array Functions
  • LabVIEW provides many functions for working with
    arrays, including
  • Array Size
  • Index Array
  • Initialize Array
  • Build Array
  • Array Subset
  • These and many others are on the Functions
    Programming Array palette.
  • (Bishop, pp. 297-305)

157
Array Size
  • The Array Size function takes an array as its
    input. For its output, it returns the number of
    elements in that array.
  • The input array can be of any data type (numeric,
    Boolean, string). The output returned by the
    function is an integer.
  • (Bishop, p. 299)

158
Index Array
  • The Index Array function takes an array and a
    number (called index) as its inputs. For its
    output, it returns the element at the index
    position in that array.
  • (Bishop, p. 303)

159
Initialize Array
  • The Initialize Array function takes an integer n
    and a data value as its inputs. For its output,
    it returns a newly created array containing n
    elements, each of which is equal to the specified
    data value.
  • The input data value can be of any data type
    (numeric, Boolean, string). The output returned
    by the function is an array of that same type.
  • (Bishop, pp. 299-300)

160
Build Array
  • The Build Array function takes arrays and/or
    individual data values as its inputs. For its
    output, it returns an array containing the input
    arrays and values concatenated together.
  • The input arrays and data values must be of the
    same type as each other (numeric, Boolean,
    string). The output returned by the function is
    an array of that same type.
  • (Bishop, pp. 300-301)

161
Array Subset
  • The Array Subset function takes an array and two
    numbers (one called index and one called length)
    as its inputs. For its output, it returns a new
    array containing the portion of the original
    array starting at index and containing length
    elements.
  • (Bishop, p. 302)

162
Arrays the DAQ Assistant
  • When you use the DAQ Assistant to perform a
    digital input task, the DAQ Assistant produces an
    array of Boolean values.
  • When you use the DAQ Assistant to perform a
    digital output task, you must provide the DAQ
    Assistant with an array of Boolean values.

163
Two-Dimensional Array
  • Think of a two-dimensional array as a set of
    items arranged in a table.
  • Example a table of student grades on all of the
    assignments in a class 90, 86, 93, 77, 92,
    68, 82, 84, 82, 95, 89, 94, 60, 80, 75,

164
Higher-Dimensional Arrays
  • Three-dimensional and higher-dimensional arrays
    are also possible, but well concentrate on
    one-dimensional arrays.

165
EET 159 Week 9
  • Clusters (Sections 7-4 to 7-10)
  • Lab 9 and Homework 9 due in two weeks.

166
Polymorphism
  • Polymorphism is a feature of functions in modern
    programming languages such as LabVIEW.
  • It lets a single function work on inputs of
    different dimensions and data types.
  • This allows one function to do the work that
    youd need several different functions to do in
    older languages that dont have polymorphism.
  • (Bishop, p. 311)

167
Polymorphism Example Add
  • LabVIEWs Add function is an example of a
    polymorphic function.
  • It can add a scalar plus a scalar, or an array
    plus an array, or a scalar plus an array.
  • In non-polymorphic languages, this would require
    several different functions.

168
Clusters
  • Recall that an array is a variable-sized
    collection of elements that are all of the same
    data type (such as numeric, string, or Boolean).
  • In contrast, a cluster is a fixed-sized
    collection of elements of mixed data types.
  • While clusters can group different types of
    controls or different types of indicators, it
    cannot group controls together with indicators.
  • (Bishop, p. 314)

169
Usefulness of Clusters
  • Clusters are useful when you have a related group
    of elements of different data types that you want
    to associate with each other.
  • Example you might group a string containing a
    persons name together with a number containing
    his/her age and a Boolean indicating his/her
    citizenship status.
  • Using clusters may result in cleaner block
    diagrams by reducing the number of wires on the
    diagram.
  • (Bishop, p. 314)

170
Creating a Cluster of Controls or Indicators
  • To create a cluster of controls or indicators
  • Place a cluster shell on the front panel from the
    Controls Modern Array, Matrix Cluster
    palette.
  • Place controls or indicators inside that cluster
    shell.
  • (Bishop, pp. 315-316)

171
Order within a Cluster
  • Individual items within a cluster are referred to
    by the order in which they were placed in the
    cluster.
  • The first item placed in a cluster becomes
    element 0, the next item placed in the cluster
    becomes element 1, and so on.
  • To change the order, right-click a clusters
    border on the front panel and select Reorder
    Controls in Cluster.
  • (Bishop, pp. 316-317)

172
Connecting Control Cluster to Indicator Cluster
  • You can wire a control cluster to an indicator
    cluster if they contain the same number of
    elements and if the data types of the
    corresponding elements match.
  • Example if a control clusters element 0 is a
    string control and its element 1 is a numeric
    control, you could not wire it to an indicator
    cluster whose element 0 is a numeric indicator
    and whose element 1 is a string indicator.
  • (Bishop, p. 318)

173
Cluster Functions
  • LabVIEW provides several functions for working
    with clusters, including
  • Bundle
  • Unbundle
  • These and others are on the Functions
    Programming Cluster Variant palette.
  • (Bishop, p. 318)

174
Bundle
  • The Bundle function is used to assemble objects
    into a new cluster, or to replace objects in an
    existing cluster.
  • (Bishop, p. 318)

175
Unbundle
  • The Unbundle function is used to split a cluster
    into its individual objects.
  • (Bishop, p. 323)

176
Displaying Multiple Plots on a Chart
  • To display more than one plot on a waveform
    chart, bundle the data together using the Bundle
    function. (Well discuss charts in more detail
    next week.)
  • (Bishop, p. 345)

177
EET 159 Week 10
  • Charts and Graphs (Chapter 8)
  • Homework 9 and Lab 9 due next week.
  • Final exam next week.

178
Charts and Graphs
  • Charts and graphs are used to display data in
    graphical form.
  • LabVIEW has many types of charts and graphs,
    found on the the Controls Modern Graph
    palette.
  • The two most common types are the Waveform Chart
    and the Waveform Graph.
  • (Bishop, pp. 342-343)

179
Charts versus Graphs
  • Charts and graphs in LabVIEW are similar to each
    other, but theres an important difference
  • Charts display data on the fly as it becomes
    available.
  • Graphs display a set of data that has been
    previously generated and stored in an array.
  • (Bishop, p. 342)

180
Waveforms Charts
  • A waveform chart takes numeric data values, one
    at a time, and plots them on a chart.
  • By default, the vertical axis automatically
    scales itself to have the best minimum and
    maximum for the data youre plotting.
  • You can easily change the vertical or horizontal
    scale by double-clicking the minimum or maximum
    values.
  • (Bishop, p. 343)

181
Clearing a Chart
  • To clear all plotted data, right-click on the
    chart and select Data Operations Clear Chart.

182
Displaying Multiple Plots on a Chart
  • To display more than one plot on a waveform
    chart, bundle the data together using the Bundle
    function.
  • (Bishop, p. 345)

183
Graphs
  • As weve seen, charts display data on the fly
    as it becomes available.
  • Graphs, on the other hand, display a set of data
    that has been previously generated and stored in
    an array.
  • Well look at two kinds of graphs waveform
    graphs and XY graphs.
  • (Bishop, p. 351)

184
Waveform Graphs
  • Use a waveforms graph to plot data points that
    are evenly distributed on the x-axis.
  • Example Suppose youve got a set of voltage
    measurements that were made at one-second
    intervals. Since the time interval is constant,
    you can plot these values using a waveform graph.
  • (Bishop, p. 351)

185
XY Graphs
  • When you use a waveform graph, the data in your
    data array just contains the y-coordinates of the
    data points, and LabVIEW assigns the
    x-coordinates.
  • On the other hand, when you use an XY graph, you
    must provide the x-coordinate and y-coordinate
    for each data point.
  • (Bishop, p. 358)

186
When to Use XY Graphs
  • Use an XY graph to plot data points that are not
    evenly distributed on the x-axis.
  • Example Suppose youve got a set of measurements
    that were made at irregular intervals. If you
    want your plot to accurately show the time
    relationship among the values, you cannot plot
    these values using a waveform graph use an XY
    graph instead.
  • (Bishop, p. 358)

187
When to Use XY Graphs (Cont.)
  • Also use an XY graph if the plot contains more
    than one data point for the same x-coordinate.
  • Example Suppose you want to plot a circle. For
    each x-coordinate in the plot, a circle contains
    two points (with different y-coordinates). You
    cannot plot these points using a waveform graph
    use an XY graph instead.
  • (Bishop, p. 358)

188
Customizing Charts Graphs
  • LabVIEW has many features that let you customize
    charts and graphs.
  • Most of these features can be accessed through
    the Properties dialog box. To open this dialog
    box, right-click on the chart or graph and select
    Properties.
  • (Bishop, pp. 361-372)

189
Chart/Graph Properties
  • The Properties dialog box has the following tabs
  • Appearance
  • Format and Precision
  • Plots
  • Scales
  • Cursors (for Graphs only)
  • Documentation

190
Plots Tab
  • The Plots tab lets you control many aspects of
    the line used to plot data
  • Solid, dashed, or dotted
  • Thickness
  • Show or hide data-point markers
  • Smooth or jagged
  • Color
  • Fill

191
Scales Tab
  • The Scales tab lets you control many aspects of
    the scales on the x-axis and y-axis, including
  • Scales shown or hidden
  • Minimum and maximum values
  • Colors of scale markers and text
  • Colors of grid lines
  • Autoscaling enabled or disabled

192
Format and Precision Tab
  • The Format and Precision tab lets you control
    aspects of the values shown on the scales
  • Floating point notation, scientific notation, or
    engineering (SI) notation
  • Number of digits displayed

193
Cursors Tab
  • The Cursors tab (for graphs only) lets you add
    one or more cursors to your graph and lets you
    control many aspects of the cursor
  • Line style and thickness
  • Color
  • Whether cursors can be moved freely or are locked
    to a particular plot

194
Appearance Tab
  • The Appearance tab lets you reveal or hide items
    such as
  • Label
  • Caption
  • Graph Palette
  • Plot legend
  • Scrollbar
  • Scale legend
  • Digital display (for Charts only)
  • Cursor legend (for Graphs only)

195
Plot Legend
  • The plot legend shows the name and appearance of
    each plot.
  • Right-clicking on the plot legend gives you easy
    access to many of the same features that you can
    access from the Plots tab in the Properties
    dialog box.
  • (Bishop, p. 365)

196
Graph Palette
  • The graph palette (which is available on both
    graphs and charts) lets you zoom in on part of
    the displayed data and lets you scroll forward or
    backward through the displayed data.
  • (Bishop, p. 366)

197
Scale Legend
  • The scale legend gives you easy access to many of
    the same features that you can access from the
    Scales tab and the Format and Precision tab in
    the Properties dialog box.
  • (Bishop, p. 366)

198
Cursor Legend
  • The cursor legend (for graphs only) shows you the
    x and y coordinates of the cursor. It also gives
    you easy access to many of the same features that
    you can access from the Cursors tab in the
    Properties dialog box.
  • (Bishop, p. 370)

199
Chart History Length
  • By default, a chart remembers the last 1024
    data points that it has plotted, and you cant
    scroll back to view earlier data points.
  • To increase this number of data points,
    right-click on the chart and select Chart History
    Length.

200
EET 159 Week 11
  • Final Exam
Write a Comment
User Comments (0)