1. A s h r a f A l M a d h o u n
Mechatronic Engineer
Ashraf Said AlMadhoun
Mechatronics System Engineer AlAzhar University
Embedded Systems Researcher & Developer, EngPal Co.
2. LabVIEW Step By Step Guide
By Ashraf AlMadhoun | Mechatronics Engineer
3. Course Goals
Understand the components of a Virtual
Instrument
Introduce LabVIEW and common LabVIEW
functions
Build a simple data acquisition application
Create a subroutine in LabVIEW
Work with Arrays.
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
3
5. A s h r a f A l M a d h o u n
Mechatronic Engineer
5
Laboratory Virtual Instrumentation Engineering Workbench
Compiled graphical development environment..
Development time reduction of 4~10 times..
Tools to: acquire, analyze, and present data..
6. A s h r a f A l M a d h o u n
Mechatronic Engineer
6
110+ Countries
40+ Int. Branches
5000+ Employees
7500+ University
1000+ University in USA
150+ Textbooks
30000+ Companies
1000+ Products
600 Alliance Partners
7. A s h r a f A l M a d h o u n
Mechatronic Engineer
7
Diversity of Applications
Electronics
Semiconductors Computers
Advanced
Research
Petrochemical
Food
Processing
Textiles
Automotive
Telecom
ATE Military/Aerospace
8. A s h r a f A l M a d h o u n
Mechatronic Engineer
8
9. Acquiring data and displaying it using an oscilloscope
Two parallel loops for acquiring data and displaying it using an oscilloscope
A s h r a f A l M a d h o u n
Mechatronic Engineer
9
10. Two parallel loops with different rates for acquiring data and displaying it using
an oscilloscope
13Pages ~700Lines
A s h r a f A l M a d h o u n
Mechatronic Engineer
10
11. Acquiring analog data from FPGA pin and
storing it
66Pages ~4000Lines
A s h r a f A l M a d h o u n
Mechatronic Engineer
12
13. A s h r a f A l M a d h o u n
Mechatronic Engineer
14
14. A s h r a f A l M a d h o u n
Mechatronic Engineer
15
Data Flow
Block diagram execution is
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
If the computer running this
code had multiple processors,
these two pieces of code could
run independently without
additional coding
15. A s h r a f A l M a d h o u n
Mechatronic Engineer
16
16. A s h r a f A l M a d h o u n
Mechatronic Engineer
17
Answer: a LabVIEW program
1. Front Panel
User interface (UI)
– Controls = inputs
– Indicators = outputs
2. Block Diagram
Graphical source code
– Data travels on wires from control
terminals through functions to indicator
terminals
– Blocks execute by data flow
3. Icon/Connector Pane
• Graphical representation of a VI
• Means of connecting VIs (subVIs)
What is a Virtual Instrument (VI)?
* Conn. pane
available from
FP only
17. A s h r a f A l M a d h o u n
Mechatronic Engineer
18
18. A s h r a f A l M a d h o u n
Mechatronic Engineer
19
Spring Workshop 2011
6th Feb - 10th Feb.
19. A s h r a f A l M a d h o u n
Mechatronic Engineer
20
20. A s h r a f A l M a d h o u n
Mechatronic Engineer
21
21. A s h r a f A l M a d h o u n
Mechatronic Engineer
22
Common Data Types Found in LabVIEW
22. A s h r a f A l M a d h o u n
Mechatronic Engineer
23
23. Faster Programming
– Graphical Programming
Program with drag-and-drop,
graphical function blocks
instead of writing lines of text
– Dataflow Representation
Easily develop, maintain, and understand code with an intuitive
flowchart representation
LabVIEW Key Features
A s h r a f A l M a d h o u n
Mechatronic Engineer
24
24. Hardware Integration
– I/O and Communication
Connect to any instrument or sensor with built-in libraries and
thousands of instrument drivers
– Plug-and-Play Hardware
Seamlessly integrate NI plug-and-play devices for
USB, PCI, PXI, Wi-Fi, Ethernet, GPIB, and more
LabVIEW Key Features
A s h r a f A l M a d h o u n
Mechatronic Engineer
25
26. Embedded Design
Real-Time Module
FPGA Module
Microprocessor SDK
Statechart Module
Mobile Module
DSP Module
Embedded Module for ARM
C-Code Generator
Robotics Module
A s h r a f A l M a d h o u n
Mechatronic Engineer
27
27. Image & Signal Processing
Vision Development Module
MathScript RT Module
Advanced Signal Processing Toolkit
Digital Filter Design Toolkit
Adaptive Filter Toolkit
Sound & Vibration Measurement Toolkit
Spectral Measurements Toolkit
Modulation Toolkit
Vision Builder for Automated Inspection
Math Interface Toolkit
Real-Time Vision Development Bundle
A s h r a f A l M a d h o u n
Mechatronic Engineer
28
28. Industrial Monitoring & Control
Data Logging & Supervisory Control
Wireless Sensor Network Module
Touch Panel Module
Motion Assistant
SoftMotion Module
OPC Servers
Instrument Control
Test Automation & Validation
A s h r a f A l M a d h o u n
Mechatronic Engineer
29
29. Multicore Programming
– Automatic Multithreading
Handle large data sets and complex algorithms faster because
LabVIEW inherently runs on multiple threads
– Execution Highlighting
Easily optimize code for parallel execution
using built-in debugging and
Visualization tools
LabVIEW Key Features
A s h r a f A l M a d h o u n
Mechatronic Engineer
30
30. A s h r a f A l M a d h o u n
Mechatronic Engineer
31
31. A s h r a f A l M a d h o u n
Mechatronic Engineer
32
33. Automating a Washing Machine Line Using
LabVIEW and Compact RIO
A s h r a f A l M a d h o u n
Mechatronic Engineer
34
34. A s h r a f A l M a d h o u n
Mechatronic Engineer
35
35. A s h r a f A l M a d h o u n
Mechatronic Engineer
36
36. A s h r a f A l M a d h o u n
Mechatronic Engineer
37
37. A s h r a f A l M a d h o u n
Mechatronic Engineer
38
Start from a blank VI:
New»Blank VI
Start from an example:
Examples»Find
Examples…
Run LabVIEW
38. Front Panel
•
Controls = Inputs
•
Indicators = Outputs
Block Diagram
•
Accompanying “program” for front
panel
•
Components “wired” together
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
39
LabVIEW Programs Are Called Virtual Instruments
(VIs)
39. VI Front Panel
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
40
Front Panel
Toolbar
Graph
Legend
Boolean
Control
Waveform
Graph
Icon
Plot
Legend
Scale
Legend
40. Ashraf AlMadhoun | LabVIEW Step By
Step Guide
41
VI Block Diagram
Wire
Data
Graph
Terminal
SubVI
While Loop
Structure
Block
Diagram
Toolbar Divide
Function
Numeric
Constant
Timing
Function
Boolean Control
Terminal
41. 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
Express VI Standard
VI
Function
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
42
43. Operating Tool
Positioning/Resizing Tool
Labeling Tool
Wiring Tool
Shortcut Menu Tool
• Floating Palette
• Used to operate and modify
front panel and block diagram
objects.
Scrolling Tool
Breakpoint Tool
Probe Tool
Color Copy Tool
Coloring Tool
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
44
Tools Palette
Automatic Selection Tool
44. Run Button
Continuous Run Button
Abort Execution
Pause/Continue Button
Text Settings
Align Objects
Distribute Objects
Reorder
Resize front panel
objects
Execution Highlighting
Button
Step Into Button
Step Over Button
Step Out Button
Additional Buttons on
the Diagram Toolbar
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
45
Status Toolbar
45. Open and Run a Virtual Instrument
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
46
Example finder
47. Ashraf AlMadhoun | LabVIEW Step By
Step Guide
48
Creating a VI – Block Diagram
48. Wiring Tips – Block Diagram
Ashraf AlMadhoun | LabVIEW Step By
49
Wiring “Hot Spot”
Clean Up Wiring
Use Automatic
Wire Routing
Click To Select Wires
49. Help Options
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
50
Context Help
• Online help
• Lock help
• Simple/Complex Diagram help
• Ctrl + H
Online reference
• All menus online
• Pop up on functions in diagram to access online info directly
50. End of Introduction To LabVIEW
- Now you let’s learn more by doing a simple Led
Example
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
51
51. Exercise 1 - Convert °C to °F
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
52
1 degree Celsius = 33.8
52. Debugging Techniques
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
53
• Finding Errors
• Execution Highlighting
• Probe
Click on broken Run button
Window showing error appears
Click on Execution Highlighting button; data
flow is animated using bubbles. Values are
displayed on wires.
Right-click on wire to display probe and it
shows data as it flows through wire segment
You can also select Probe tool from Tools
palette and click on wire
53. Section II – SubVIs
What is a subVI?
Making an icon and
connector for a subVI
Using a VI as a subVI
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
54
54. Ashraf AlMadhoun | LabVIEW Step By
Step Guide
55
Block Diagram Nodes
Icon Expandable Node Expanded Node
• Function Generator VI
• Same VI, viewed three different ways
• Yellow field designates a standard VI
• Blue field designates an Express VI
55. SubVIs
A SubVI is a VI that can be used within another VI
Similar to a subroutine
Advantages
• Modular
• Easier to debug
• Don’t have to recreate code
• Require less memory
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
56
56. Icon and Connector
An icon represents a VI in other
block diagrams
A connector shows available
terminals for data transfer
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
57
Icon
Connector
Terminals
58. Steps to Create a SubVI
1. Create the Icon
2. Create the Connector
3. Assign Terminals
4. Save the VI
5. Insert the VI into a Top Level VI
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
59
59. Create the Icon
Right-click on the icon in the
block diagram or front panel
Ashraf AlMadhoun | LabVIEW Step By
60
60. Create the Connector
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
61
Right click on the icon pane (front panel only)
62. Save The VI
Choose an Easy to Remember Location
Organize by Functionality
Save Similar VIs into one directory (e.g. Math Utilities)
Organize by Application
Save all VIs Used for a Specific Application into one
directory or library file (e.g. Lab 1 – Frequency
Response)
Library Files (.llbs) combine many VI’s into a single file, ideal for
transferring entire applications across computers
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
63
63. Insert the SubVI into a Top Level
VI
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
64
Accessing user-made subVIs
Functions >>All Functions >> Select a VI
Or
Drag icon onto target diagram
64. Tips for Working in LabVIEW
Keystroke Shortcuts
<Ctrl-H> – Activate/Deactivate Context Help Window
<Ctrl-B> – Remove Broken Wires From Block Diagram
<Ctrl-E> – Toggle Between Front Panel and Block Diagram
<Ctrl-Z> – Undo (Also in Edit Menu)
Tools » Options… – Set Preferences in LabVIEW
VI Properties – Configure VI Appearance,
Documentation, etc.
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
65
65. Section III – Data Acquisition
Data acquisition (DAQ) basics
Connecting Signals
Simple DAQ application
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
66
Computer
DAQ Device
Terminal Block
Cable
Sensors
66. Data Acquisition in LabVIEW
Traditional NI-DAQ
Specific VIs for
performing:
• Analog Input
• Analog Output
• Digital I/O
• Counter operations
NI-DAQmx
Next generation driver:
• VIs for performing a
task
• One set of VIs for all
measurement types
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
67
67. DAQ – Data Acquisition
Temperature Acquisition using the DAQ Assistant
Ashraf AlMadhoun | LabVIEW Step By
68
68. Data Acquisition Terminology
Resolution - Determines How Many Different
Voltage Changes Can Be Measured
Larger Resolution More Precise Representation of
Signal
Range - Minimum and Maximum Voltages
Smaller range More Precise Representation of
Signal
Gain - Amplifies or Attenuates Signal for Best Fit
in Range
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
69
70. Exercise 2 – Simple Data Acquisition
Complete Convert C to F.vi, then create Thermometer.vi.
Ashraf AlMadhoun | LabVIEW Step By
71
71. Section IV – Loops and Charts
For Loop
While Loop
Charts
Multiplots
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
72
72. Loops
While Loops
• Have Iteration Terminal
• Always Run at least Once
• Run According to Conditional
Terminal
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
73
•For Loops
• Have Iteration Terminal
• Run According to input N of
Count Terminal
73. Loops (cont.)
1. Select the loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
74
74. Charts
Waveform chart – special numeric
indicator that can display a
history of values
Controls >> Graph Indicators
>> Waveform Chart
Ashraf AlMadhoun | LabVIEW Step By
75
75. Wiring Data into Charts
Single Plot Charts Multiplot Charts
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
76
76. Exercise 3 – Using loops
Students build Use a loop.vi.
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
77
77. Section V – Arrays & File I/O
Build arrays manually
Have LabVIEW build arrays automatically
Write to a spreadsheet file
Read from a spreadsheet file
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
78
78. Adding an Array to the Front Panel
From the Controls >> All Controls >> Array and
Cluster subpalette, select the Array Shell
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
79
Drop it on the screen.
79. Adding an Array (cont.)
Place data object into shell (i.e. Numeric Control)
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
80
80. Creating an Array with a Loop
Loops accumulate arrays at their boundaries
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
81
82. File I/O
File I/O – passing data to and from files
- Files can be binary, text, or spreadsheet
- Write/Read LabVIEW Measurements file (*.lvm)
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
83
Writing to LVM file Reading from LVM file
83. Write LabVIEW Measurement File
Includes the open, write, close and error handling
functions
Handles formatting the string with either a tab or
comma delimiter
Merge Signals function is used to combine data into
the dynamic data type
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
84
84. Section VI – Array Functions &
Graphs
Basic Array Functions
Use graphs
Create multiplots with graphs
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
85
85. Array Functions – Basics
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
86
Functions >> All functions>> Array
87. Graphs
Selected from the Graph palette of Controls menu
Controls>>All Controls>>Graphs
Ashraf AlMadhoun | LabVIEW Step By
88
Waveform Graph – Plot an array of
numbers against their indices
Express XY Graph – Plot one array against
another
Digital Waveform Graph – Plot bits from
binary data
88. Graphs
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
89
Right-Click on the Graph and choose Properties
to Interactively Customize
89. Exercise 5 – Using Waveform
Graphs
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
90
91. Strings
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
92
• A string is a sequence of displayable or nondisplayable
characters (ASCII)
• Many uses – displaying messages, instrument control, file
I/O
• String control/indicator is in the Controls »Text Control or
Text Indicator
92. Clusters
Data structure that groups data together
Data may be of different types
Analogous to struct in C
Elements must be either all controls or all
indicators
Thought of as wires bundled into a cable
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
93
93. Creating a Cluster
1. Select a Cluster shell
Controls >> All Controls >> Array & Cluster
Ashraf AlMadhoun | LabVIEW Step By
94
2. Place objects inside the shell
94. Cluster Functions
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
95
• In the Cluster subpalette of the Functions>>All
functions palette
• Can also be accessed by right-clicking on the cluster
terminal
Bundle
(Terminal labels
reflect data type)
Bundle By Name
96. Error Clusters
Error cluster contains the following information:
Boolean to report whether error occurred
Integer to report a specific error code
String to give information about the error
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
97
97. Error Handling Techniques
Error information is passed from one subVI to the next
If an error occurs in one subVI, all subsequent subVIs are not
executed in the usual manner
Error Clusters contain all error conditions
Automatic Error Handling
Ashraf AlMadhoun | LabVIEW Step By
98
error clusters
98. Section VIII - Case & Sequence
Structures, Formula Nodes
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
99
99. Case Structures
In the Structures subpalette of Functions palette
Enclose nodes or drag them inside the structure
Stacked like a deck of cards, only one case visible
Functions >> Execution control
Ashraf AlMadhoun | LabVIEW Step By
100
100. Sequence Structures
In the Execution Control subpalette of Functions palette
Executes diagrams sequentially
Right-click to add new frame
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
101
101. Formula Nodes
In the Structures subpalette
Implement complicated equations
Variables created at border
Variable names are case sensitive
Each statement must terminate with a semicolon (;)
Context Help Window shows available functions
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
102
Note semicolon
102. Section IX – Printing &
Documentation
Print From File Menu to Printer, HTML, Rich
Text File
Programmatically Print Graphs or Front Panel
Images
Document VIs in VI Properties »
Documentation Dialog
Add Comments Using Free Labels on Front
Panel & Block Diagram
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
103
103. Printing
File » Print… Gives Many Printing Options
Choose to Print Icon, Front Panel, Block Diagram, VI Hierarchy,
Included SubVIs, VI History
Print Panel.vi (Programmatically Prints a Front Panel)
Functions » All Functions » Application Control
Generate & Print Reports (Functions » Output »
Report)
Ashraf AlMadhoun | LabVIEW Step By
104
104. Documenting VIs
VI Properties » Documentation
Provide a Description and Help Information for a VI
VI Properties » Revision History
Track Changes Between Versions of a VI
Individual Controls » Description and Tip…
Right Click to Provide Description and Tip Strip
Use Labeling Tool to Document Front Panels &
Block Diagrams
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
105
105. Section X – Basic Programming
Architecture
• Simple VI Architecture
• General VI Architecture
• State Machine Architecture
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
106
106. Simple VI Architecture
Functional VI that produces results when run
No “start” or “stop” options
Suitable for lab tests, calculations
Example: Convert C to F.vi
Ashraf AlMadhoun | LabVIEW Step By
107
108. State Machine Architecture
Advantages
Can go from any state to any other
Easy to modify and debug
Disadvantages
Can lose events if two occur at the
same time
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
109
States:
0: Startup
1: Idle
2: Event 1
3: Event 2
4: Shutdown
109. Section XI – Remote Front Panels
• View & Control LabVIEW Front Panels from a
Web Browser
• Requires no programming
• Remote clients see “live” front panel updates
• Multiple clients can view the same panel
simultaneously
• Only one client can control the front panel at a
time
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
110
110. Remote Panel Web Publishing Tool
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
111
•
Tools » Web Publishing Tool…
•Click Save to Disk
and VI is embedded
into an HTML file
•After file is saved, it
can be reopened and
customized in any
HTML editor
111. Remote Front Panels - Resources
• NI Developer Zone
(zone.ni.com)
• Search for Remote
Front Panel
• Tutorials &
Instructions Are
Available for
Download
• Information on
Incorporating Web
Cameras into Remote
Panel Applications
Ashraf AlMadhoun | LabVIEW Step By
112
112. Section XII – Additional Topics
Property Nodes
Local Variables
Global Variables
DataSocket
Binary File I/O
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
113
113. Where Do I Go From Here?
Example programs (Help» Find Examples…)
LabVIEW Student Edition (www.ni.com/labviewse)
Web resources (ni.com)
NI Developer Zone (zone.ni.com)
Application Notes
Info-labview newsgroup (www.info-labview.org/)
Instrument Driver Library (www.ni.com/idnet)
Ashraf AlMadhoun | LabVIEW Step By
Step Guide
114