Equipment Needed for this Course

Download Report

Transcript Equipment Needed for this Course

LabVIEW Introduction Course
Semester
National Instruments
11500 N. Mopac Expressway
Austin, Texas 78759
(512) 683-0100
1
National Instruments Confidential
Graphical Programming for Test,
Measurement, and Control
• Rapid application development with
Express VIs and easy-to-use
graphical environment
• Interactive measurement assistants
and powerful redesigned DAQ
interface for connecting to all types
of I/O
• Expanded targeting options from
Real-Time to FPGA to PDA
• Localized in French, German, and
Japanese (Korean documentation)
2
LabVIEW Awards
• Readers of Electronic Design name invention of LabVIEW as one
of the Top 50 Milestones for the Electronics Industry
• LabVIEW 6.1 receives IAN Automation Excellence Award of
2002
• Design News awards LabVIEW 6i Best Computer Productivity
Tool of 2000
• LabVIEW 6i chosen the “Best of the Best” in the software
category by readers of Evaluation Engineering
3
NI LabVIEW: A History of Innovation
4
May 2003
• LabVIEW 7 Express VIs, I/O Assistants, FPGA/PDA targets
January 2002
• LabVIEW 6.1 Enhanced networking capabilities, analysis
August 2000
• LabVIEW 6i Internet-ready measurement intelligence
March 1998
• LabVIEW 5.0 ActiveX, Multithreading
February 1996
• LabVIEW 4.0 Added professional tools, improved debugging
August 1993
• LabVIEW 3.0 Multiplatform version of LabVIEW
September 1992
• LabVIEW for Windows
January 1990
• LabVIEW 2.0 for Macintosh
October 1986
• LabVIEW 1.0 for Macintosh
April 1983
• LabVIEW project begins
Leveraging Commercial Technologies
Third-Party Software
•
•
•
•
•
•
•
•
•
•
5
Wolfram Research Mathematica ®
Microsoft Excel ®
The MathWorks MATLAB® and Simulink®
MathSoft MathCAD ®
Electronic Workbench MultiSim ®
Texas Instruments Code Composer Studio®
Ansoft RF circuit design software
Microsoft Access ®
Microsoft SQL Server ®
Oracle ®
Communication Protocols
•
•
•
•
•
•
•
•
Ethernet
CAN
DeviceNet
USB
IEEE 1394
RS-232
GPIB
RS-485
LabVIEW Everywhere
Sensor
Embedded
(FPGA)
Handheld
Wireless
Networked I/O
PC Boards
Industrial Computer (PXI)
Tektronix Open Windows
Oscilloscopes
PC, Mac, Linux, Sun
Workstation
6
The LabVIEW Family
NI LabVIEW
Graphical Programming Software for Measurement and Automation
LabVIEW Real-Time Module
7
LabVIEW FPGA Module
LabVIEW PDA Module
LabVIEW Datalogging and
Supervisory Control Module
Acquire, Analyze, and Present
Nearly all test, measurement, and control applications can be
divided into 3 main components: the ability to acquire, analyze, and
present data. LabVIEW is the easiest, most powerful tool for
acquiring, analyzing, and presenting real-world data.
8
Acquire with LabVIEW
LabVIEW can acquire data using the
following devices and more:
LabVIEW is tightly
integrated with all NI
hardware, in addition
to connecting to
thousands of I/O
devices from hundreds
of different vendors.
9
• GPIB, Serial, Ethernet, VXI, PXI
Instruments
• Data Acquisition (DAQ)
• PCI eXtensions for Instrumentation (PXI)
• Image Acquisition (IMAQ)
• Motion Control
• Real-Time (RT) PXI
• PLC (through OPC Server)
• PDA
• Modular Instruments
Analyze with LabVIEW
LabVIEW includes the following tools
to help you analyze your data:
Powerful measurement
analysis is built in to the
LabVIEW development
environment.
10
• More than 400 measurement analysis
functions for Differential Equations,
Optimization, Curve Fitting, Calculus, Linear
Algebra, Statistics, etc.
• 12 new Express VIs specifically designed for
measurement analysis, including filtering
and spectral analysis
• Signal Processing VIs for Filtering,
Windowing, Transforms, Peak Detection,
Harmonic Analysis, Spectrum Analysis, etc.
Present with LabVIEW
LabVIEW includes the following
tools to help you present your data:
Presentation with
LabVIEW can be done
on your PC or over a
network, or you can take
advantage of additional
applications such as
DIAdem.
11
• On your machine — Graphs, Charts,
Tables, Gauges, Meters, Tanks, 3D
Controls, Picture Control, 3D Graphs
(Windows Only), Report Generation
(Windows Only)
• Over the Internet — Web Publishing
Tools, Datasocket (Windows Only),
TCP/IP, VI Server, Remote Panels, Email
• Enterprise Connectivity Toolset — SQL
Tools (Databases), Internet Tools (FTP,
Telnet, HTML)
Course Map
Introduction to
LabVIEW
Clusters
Modular
Programming
Plotting Data
Repetition &
Loops
Arrays
12
Decision Making
in a VI
Strings and
File I/O
Data Acquisition
& Waveforms
Instrument
Control
VI
Customization
Course Goals
This course prepares you to:
• Understand front panels, block diagrams, and connectors/icons
• Use the programming structures and data types that exist in
LabVIEW
• Use various editing and debugging techniques
• Create and save your own VIs so you can use them as subVIs
• Display and log your data
• Create applications that use plug-in data acquisition (DAQ)
boards
• Create applications that use GPIB and serial port instruments
13
Course Non-Goals
It is not the purpose of this course to discuss the
following:
•
•
•
•
14
Every built-in LabVIEW object, function, or library VI
Analog-to-digital (A/D) theory
The detailed operation of the serial port or GPIB bus
How to develop an instrument driver
Lesson 1
Introduction to LabVIEW
TOPICS
LabVIEW Environment
Front Panel
Block Diagram
Dataflow Programming
LabVIEW Help and Manuals
Debugging a VI
15
Virtual Instruments (VIs)
Front Panel
• Controls = Inputs
• Indicators = Outputs
Block Diagram
• Accompanying “program”
for front panel
• Components wired
together
16
LabVIEW Dialog Box
17
Creating a new VI
• File»New VI to open a blank VI
• File»New… to open the New dialog box and configure a VI template,
global variable, control, etc…
18
Template Browser
19
Menu
File Edit Operate Tools Browse Window Help
20
Front Panel Window
Front Panel
Toolbar
Boolean
Control
Waveform
Graph
Owned
Label
Icon
Graph
Legend
Waveform
Graph
Plot
Legend
21
Scale
Legend
Block Diagram Window
Block
Diagram
Toolbar
Divide
Function
SubVI
Graph
Terminal
Wire
Data
While Loop
Structure
22
Numeric
Constant
Timing
Function
Boolean Control
Terminal
Front Panel and Block Diagram Toolbars
Run button
Font ring
Continuous Run button
Alignment ring
Abort button
Distribution ring
Pause/Continue button
Resize ring
Warning indicator
Enter button
Broken Run button
23
Reorder ring
Additional Buttons on the
Context Help Button
Block Diagram Toolbar
• Execution Highlighting button
• Step Into button
• Step Over button
• Step Out button
Tools Palette
• LabVIEW automatically selects the tool needed
• Available on the front panel and the block diagram
• A tool is a special operating mode of the mouse cursor
• Use the tools to operate and modify front panel and
block diagram objects
• To show the tools palette, select
Window»Show Tools Palette
24
Front Panel − Controls Palette
Controls Palette
Contains the most commonly used controls
All Controls Palette
Shows all controls
25
Block Diagram − Functions Palette
Functions Palette
Contains the Express VIs (interactive VIs with
configurable dialog page) and the most commonly
used functions
All Functions Palette
Shows all functions
26
Palette Tools
Click pushpin to tack down palette
Up to Owning Search Palette Options
Palette
• Graphical, floating palettes
• Subpalettes can be converted to floating palettes
• Use Palette Options to change palette view from
Express to Advanced
27
Searching for Controls, VIs, and Functions
• Press the search button to
perform text searches of
the palettes
• Click and drag an item
from the search window to
the block diagram or
double-click an item to
open the owning palette
28
Customize Control & Function Palette
Programs» National Instruments»LabVIEW 7.0
• Keep vi.lib in the LabVIEW 7.0 directory
• Place items in user.lib or instr.lib to have them appear in
the Controls and Functions palettes
29
Creating a VI Front Panel
Build the front panel with controls (inputs)
and indicators (outputs)
Owned
Labels
Boolean
Control
30
Boolean
Indicator
Increment
Buttons
Numeric
Indicator
Numeric
Control
Shortcut Menus for Front Panel Objects
Right-click the digital display
to access its shortcut menu
Right-click the label to
access its shortcut menu
31
Property Page
Right-click a control or
indicator on the front
panel and select
Properties from the
shortcut menu to access
the property dialog box
for that object
32
Creating a VI Block Diagram
Front Panel
Block Diagram
Control
Terminals
Indicator
Terminals
Wires
33
Nodes
Express VIs, VIs and Functions
• Express VIs: interactive VIs with configurable dialog page
• Standard VIs: modularized VIs customized by wiring
• Functions: fundamental operating elements of
LabVIEW; no front panel or block diagram
34
Block Diagram Nodes
Icon
•
•
•
•
35
Expandable Node
Function Generator VI
Same VI, viewed three different ways
Yellow field designates a standard VI
Blue field designates an Express VI
Expanded Node
Block Diagram Terminals
• Terminals are entry and exit ports
that exchange information between
the panel and diagram
• Terminals are analogous to
parameters and constants in textbased programming languages
• Right-click and toggle View As Icon
to change the icon view
36
Wiring the Block Diagram
Scalar
Numeric
Boolean
String
Dynamic
37
1D Array
2D Array
Wiring Techniques
•
•
•
•
•
•
Hot Spot
Automatic Wiring
Use Context Help Window when wiring
Right-click wire and select Clean Up Wire
Tip Strips
Automatic wire routing
Right-click terminals
and select Visible
Items»Terminals
View the terminal connections to a function
38
Dataflow Programming
• Block diagram executes
dependent on the flow of data;
block diagram does NOT
execute left to right
• Node executes when data is
available to ALL input terminals
• Nodes supply data to all output
terminals when done
39
Context Help
• To display the Context Help window, select
Help»Show Context Help, press the <Ctrl-H> keys, or press
the Show Context Help Window button in the toolbar
• Move cursor over object
to display help
• Connections:
Required – bold
Recommended – normal
Optional - dimmed
Simple/Detailed Context Help
40
Lock Help
More Help
LabVIEW Help
• Click the More Help button in the Context Help window
• Select Help»VI, Function, & How-To Help
• Click the sentence Click here for more help in the Context
Help window.
Contains detailed descriptions of most palettes, menus,
tools, VIs, and functions, step-by-step instructions for using
LabVIEW features, links to the LabVIEW Tutorial, PDF
versions of all the LabVIEW manuals and Application Notes,
and technical support resources.
41
NI Example Finder
• To find an example, select
Help»Find Examples
• Web-integrated
• Search by keyword,
example type, hardware
type, etc.
42
Debugging Techniques
Finding Errors
Click on broken Run button. A window showing the
error appears
Execution Highlighting
Click on Execution Highlighting button; data flow is
animated using bubbles. Values are displayed on
wires.
43
Debugging Techniques
Probe
Right-click on wire and select probe and it shows
data as it flows through the wire segment
Breakpoints
Right-click on wire and select Set Breakpoint; pause
execution at the breakpoint.
Conditional Probe
Combination of a breakpoint and a probe. Right-click on
wire and select custom probe.
44
Debugging Techniques
Step Into, Over, and Out buttons for Single Stepping
Click on Step Into button to enable single stepping
Once Single Stepping has begun, the button steps
into nodes
Click on Step Over button to enable single stepping
or to step over nodes
Click on Step Out button to step out of nodes
45
Summary
• Virtual instruments (VIs) have three main parts — the front panel, the block
diagram, and the icon and connector pane
• The front panel is the user interface of a LabVIEW program and the block
diagram is the executable code
• The block diagram contains the graphical source code composed of nodes,
terminals, and wires
• Use Express VIs, standard VIs and functions on the block diagram to create
your measurement code. For the most common requirements, use Express
VIs with interactive configuration dialogs to define your application.
• Floating Palettes: Tools Palette, Controls Palette (only when Front Panel
Window is active), and Functions Palette (only when Block Diagram Window is
active)
• There are help utilities including the Context Help Window and LabVIEW Help
46
Summary
• Place controls (inputs) and indicators (outputs) in the front panel window
• Use the Operating tool to manipulate panel objects. Use the Positioning tool to
select, move, and resize panel objects. Use the Wiring tool to connect diagram
objects
• Control terminals have thicker borders than indicator terminals
• All front panel objects have property pages and shortcut menus
• Wiring is the mechanism to control dataflow and produce LabVIEW programs
• Broken Run arrow means a nonexecutable VI
• Various debugging tools and options available such as setting probes and
breakpoints, execution highlighting, and single stepping
47
Tips
• Common keyboard shortcuts
Windows
<Ctrl-R>
<Ctrl-F>
<Ctrl-H>
<Ctrl-B>
<Ctrl-W>
<Ctrl-E>
Sun
<-R>
<-F>
<-H>
<-B>
<-W>
<-E>
Linux
<M-R>
<M-F>
<M-H>
<M-B>
<M-W>
<M-E>
MacOS
<z-R>
<z-F>
<z-H>
<z-B>
<z-W>
<z-E>
Run a VI
Find object
Activate Context Help window
Remove all broken wires
Close the active window
Toggle btwn Diagram/Panel Window
• Access Tools Palette with <shift>-right-click
• Increment/Decrement faster using <shift> key
• Tools»Options selection — set preferences in LabVIEW
• VI Properties (File menu)
48
Lesson 2
Modular Programming
TOPICS
SubVIs
Icon and Connector Pane
Using SubVIs
Creating a SubVI from sections of a VI
49
LabVIEW Hierarchy
SubVI
50
SubVIs
51
Function Pseudo Code
Calling Program Pseudo Code
function average (in1,
in2, out)
{
out = (in1 + in2)/2.0;
}
main
{
average (point1, point2,
pointavg)
}
SubVI Block Diagram
Calling VI Block Diagram
Icon/Connector
terminals
Icon
An icon represents a VI in other block
diagrams
A connector passes data to and receives
data from a subVI through terminals
Connector
terminals
52
SubVI Example – Calculating Slope
• A VI within another VI is called a subVI
• To use a VI as a subVI, create an icon and a connector pane after
building the front panel and block diagram
53
Creating the Icon
• Icon: graphical representation of a VI
• Right-click in the icon pane (Panel or Diagram)
• Always create a black and white icon
Default Icon
54
Create a custom icon
Creating the Connector
Right-click the icon
(Front Panel only)
55
Creating the Connector - continued
56
Click with
wiring tool
The Connector Pane
Terminal colors match the data types to which they are connected
Click the terminal to see its associated front panel object
57
Using a VI as a SubVI
All Functions » Select a VI…
<OR>
Drag icon onto target diagram
58
Help and Classifying Terminals
Classify inputs and outputs:
•
•
•
59
Required — Error if no connection
Recommended — Warning if no connection
Optional — No effect if no connection
Create SubVI Option
• Enclose area to be converted into a subVI
• Select Create SubVI from the Edit Menu
60
Summary
•
•
•
•
VIs can be used as subVIs after you make the icon and connector
Icon created using Icon Editor
Connector defined by choosing number of terminals
Load subVIs using the Select a VI option in the All Functions palette
or dragging the icon onto a new diagram
• Online help for subVIs using the Show Context Help option
• Descriptions document functionality
• Use Create SubVI feature to easily modularize the block diagram
61
Lesson 3
Repetition and Loops
TOPICS
While Loops
For Loops
Accessing Previous Loop Data
62
While Loops
Repeat (code);
Until Condition met;
End;
LabVIEW While Loop
63
Flow Chart
Pseudo Code
While Loops
1. Select While Loop
2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
64
Select the Loop Condition
Click the Conditional Terminal with the Operating tool to define
when the loop stops
Default: Stop if True
Iteration Terminal
65
Conditional Terminal
Structure Tunnels
• Tunnels feed data into and out of structures.
• The tunnel is a block that appears on the border; the color of
the block is related to the data type wired to the tunnel.
• When a tunnel passes data into a loop, the loop executes
only after data arrive at the
tunnel.
• Data pass out of a loop after
the loop terminates.
66
For Loops
N=100;
i=0;
Until i=N:
Repeat (code; i=i+1);
End;
LabVIEW For Loop
67
Flow Chart
Pseudo Code
For Loops
• In Structures subpalette of Functions palette
• Enclose code to be repeated and/or resize and add nodes
inside boundary
• Executes diagram inside of loop a predetermined number
of times
Count terminal
(Numerical input)
Wait Until Next
ms Multiple
function
68
Wait Functions
Wait Until Next
ms Multiple
Functions»Time
& Dialog palette
69
Wait Functions
Wait (ms)
Functions»Time
& Dialog palette
Time Delay
Functions»Time
& Dialog palette
70
Numeric Conversion
• Numerics default to double-precision (8 bytes) or long integer
(4 bytes)
• LabVIEW automatically converts to different representations
• For Loop count terminal always converts to a long integer
• Gray coercion dot on terminal indicates conversion
71
Numeric Conversion
• LabVIEW chooses the representation that uses more bits.
• If the number of bits is the same,
LabVIEW chooses unsigned over signed.
• To choose the representation,
right-click on the terminal and
select Representation.
• When LabVIEW converts floating-point numerics to integers, it
rounds to the nearest integer. LabVIEW rounds x.5 to the
nearest even integer.
For example, LabVIEW rounds 2.5 to 2 and 3.5 to 4.
72
Accessing Previous Loop Data – Shift Register
• Available at left or right border of loop structures
• Right-click the border and select Add Shift Register
• Right terminal stores data on completion of iteration
• Left terminal provides stored data at beginning of next iteration
Initial
Value
Before
Loop
Begins
73
Initial Value
Value 1
Value 2
Value 3
Value 1
First
Iteration
Value 2
Second
Iteration
Value 3
Last
Iteration
Additional Shift Register Elements
Right-click the
left terminal to
add new
elements
Previous values are available at
the left terminals
1 loop ago
2 loops ago
3 loops ago
74
Latest value
is passed to
right terminal
Right-click the
border for a
new shift
register
Feedback Nodes
• Appears automatically in a For Loop or While Loop if
you wire the output of a subVI, function, or group of
subVIs and functions to the input of that same VI,
function, or group.
• Stores data when the loop completes an iteration,
sends that value to the next iteration of the loop, and
transfers any data type
75
Feedback Node
• Wire from output to input to
automatically create a feedback
node
<OR>
• Place a feedback node from the
Functions»Structures palette
76
Initialized Shift Registers & Feedback Nodes
Output = 5
Output = 5
Run Once
VI stops execution
Output = 5
77
Run Again
Output = 5
Uninitialized Shift Registers & Feedback Nodes
Output = 4
Run Once
VI stops execution
Output = 4
78
Output = 8
Run Again
Output = 8
Summary
• Two structures to repeat execution: While Loop and For Loop
• Loop timing controlled using Wait Until Next ms Multiple function,
the Wait (ms) function, or the Time Delay Express VI.
• Coercion dots appear where LabVIEW coerces a numeric
representation of one terminal to match the numeric representation
of another terminal
• Feedback nodes and shift registers transfer data values from one
iteration to the next
• Use shift registers only when more than one past iteration is
needed
79
Lesson 4
Arrays
TOPICS
Introduction to Arrays
Auto Indexing Arrays
Array Functions
Polymorphism
80
Arrays
• Collection of data elements that are of same type
31
• One or more dimensions, up to 2 elements per dimension
• Elements accessed by their index; first element is index 0
index
10-element array
0
1
2
3
4
5
6
7
9
1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7
2D array 0
0
1
2
3
4
5
6
1
2
3
4
Five row by seven column array of 35 elements
81
8
Array Controls and Indicators
1. Select the Array shell from the
Controls palette
2. Place data object inside
shell
Add Dimension
for 2D arrays
82
Creating Array Constants
1. Select Array
Constant shell from
the Array subpalette
2. Place the data object in the array shell
83
Auto-Indexing
• Loops can
accumulate arrays at
their boundaries with
auto-indexing
• For Loops auto-index
by default
• While Loops output the
final value by default
• Right-click on tunnel
and enable/disable
auto-indexing
Auto-Indexing Enabled
Wire becomes thicker
1D Array
0 1
2
3 4
5
Auto-Indexing Disabled
Wire remains the same size
Only one value (last iteration)
is passed out of the loop
84
Creating 2D Arrays
1D Array
0 1
2
3 4
5
• Inner loop creates column elements
• Outer loop stacks them into rows
85
2D Array
Auto-Index Input
• An array input can be
used to set the For
Loop count terminal
• Number of elements
in the array equals
the count terminal
input
• Run arrow not
broken
86
Common Array Functions
Array Size
Initialize Array
87
Common Array Functions
Array Subset
88
The Build Array Function
Appending an element
Concatenate Inputs
Building a higher dimension array
89
default
The Index Array Function
Extracting an Element
Extracting a Row
Extracting an Element of a Row
90
Polymorphism
Function inputs can be of different types
All LabVIEW arithmetic functions are polymorphic
Combination
Result
Scalar + Scalar
Scalar
Array + Scalar
Array
Array + Array
Array
Array + Array
Array
91
Summary
• Arrays group data elements of the same type. You can build arrays of
numeric, Boolean, path, string, waveform, and cluster data types.
• The array index is zero-based, which means it is in the range 0 to n – 1,
where n is the number of elements in the array.
• To create an array control or indicator, select an Array on the
Controls»Array & Cluster palette, place it on the front panel, and drag
a control or indicator into the array shell.
• If you wire an array to a For Loop or While Loop input tunnel, you can
read and process every element in that array by enabling auto-indexing.
• By default, LabVIEW enables auto-indexing in For Loops and disables
auto-indexing in While Loops.
• Polymorphism is the ability of a function to adjust to input data of
different data structures.
92