資料擷取研討會之一
A Highly Productive Graphical Development Environment for Engineers and Scientists
3
Section I – LabVIEW Environment
A. Set up Your Hardware
B. Take Your First Measurement
• Open and Explore Final Project: Audio Equalizer
C. Demonstration: Creating our First VI
D. LabVIEW Environment
E. Hands-On Exercise: Acquiring Data
• Write a program that reads in a signal from a microphone
4
A. Setting Up Your Hardware
• Data Acquisition Device (DAQ)
– NI myDAQ
– Configured in Measurement and Automation Explorer
(MAX)
5
NI myDAQ USB controlled,
bus powered
Power Supply:
Analog Input: +5 V
2 channels, 200kS/s/ch, 16-bit 8 DIO lines,
Analog Output: 1 counter
2 channels, 200kS/s/ch, 16-bit
2 AI lines
DIO: 8 lines
2 AO lines
CTR: 1 counter
Power Supply:
Integrated DMM: V, A, Ohm +/– 15 V
Power Supply: +5 V, +/–15 V
3.5 mm stereo audio jacks Audio IN/OUT
ELVISmx Software Instruments
Integrated DMM
6
Demonstration: What is MAX?
• Stands for Measurement & Automation Explorer
• Organizes all your National Instruments hardware and software
• Configure your hardware in MAX
• Tests your device in MAX
8
Exercise 1 – Setting Up Your Hardware Device
• Use Measurement and Automation Explorer (MAX) to:
– Configure and test your myDAQ
9
What is an Audio Equalizer?
• It’s a car stereo!
• Audio Equalizers adjust the
volume of a certain frequency
within a signal.
• We are going to build a 3-band
Audio Equalizer using filters that
affects these frequency ranges
– Bass
– Midtones
– Treble
12
Let’s Explore the Final Project
Open up the myDAQ Audio Demo.vi and play around with it. Be sure you
have your microphone (or MP3 player) plugged in along with the
speakers!
13
Time to Break it Down
Acquire Analyze Present
Gather data from your Extract useful information from Visualize results in graphs and
myDAQ or another data your data with interactive charts. Create custom user
acquisition device. wizards and more than 600 built- interfaces and reports in text
in LabVIEW measurement files, HTML, Microsoft Word,
analysis and signal processing Microsoft Excel, and more.
functions.
14
Types of Signals to Acquire
Analog Digital
15
Demonstration: Creating our First VI
Front Panel Window
Graph
Indicator
Output
Terminal
Input
Terminals
Boolean
Control
17
美商國家儀器 LabVIEW 與
資料擷取研討會之二
LabVIEW Environment
19
Palettes
Where can you find the following Palettes?
20
Data Types
What are the following data types?
22
Toolbar
What do the following buttons do?
23
Using the Search Functions
Feel free to reference LabVIEW to find the answers
Can you name three ways you can search for a function in
LabVIEW?
25
Dataflow
Which VI(s) will execute first? Which VI will execute last?
26
Debugging Techniques
How do you use the following debugging tools?
• Broken Run Arrow • Execution Highlighting
27
Context Help Window
28
Commenting Your Code
Double-click anywhere on your front panel or block diagram
to insert a comment
29
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)
– <Ctrl-T> -- Tile Front Panel and Block Diagram
• Tools»Options… – Set Preferences in LabVIEW
• File»VI Properties – Configure VI Appearance, Documentation, etc.
• Create»Control/Constant/Indicator – Right-click on terminal to create
30
Peak Detection
• Convert Time-domain
signals to Frequency-
domain signals
• Analyze all frequency
components to find the
dominant frequency
Time
• In this exercise
– We acquire a sound signal
– Perform spectral analysis to
detect peak frequency
Frequency
– Display on graph
31
Exercise 2 – Acquiring a Signal with DAQ
Do Not Delete
Exercise 2 Instructions
32
Video: myDAQ Piano Staircase
41
美商國家儀器 LabVIEW 與
資料擷取研討會之三
Section II – Elements of Typical Programs
A. Demonstration: While Loops and SubVI
B. Loops
• While Loop
• For Loop
B. Functions and SubVIs
• Types of Functions
• Creating Custom Functions (subVI)
C. Hands-On Exercise: Filtering and Outputting Sound
43
Demonstration: While Loop and SubVIs
44
While Loop
• What do the following
terminals do?
45
For Loop
• What does the iteration terminal
start counting from?
46
Drawing a Loop
1. Select the structure 2. Enclose code to be repeated
(Programming»Structures)
47
3 Types of Functions
Express VIs: interactive VIs with configurable dialog page (blue border)
48
LabVIEW Functions and SubVIs Operate Like
Functions in Other Languages
Function Pseudo Code Calling Program Pseudo Code
function average (in1, in2, out) main
{ {
out = (in1 + in2)/2.0; average (in1, in2, pointavg)
} }
49
Create SubVI
What are some ways that you can create subVIs?
50
Icon Editor and Connector Pane
Icon Editor Connector Pane
• Why is having a good icon • Where do you find the
important? connector pane?
• How can you edit the icon of • How do you add inputs or
your subVI? outputs to the connector pane?
51
Analysis: Filters
• Allows some frequencies of a
signal to pass more easily than
others
• We will be using three types of
filters in our project
– Lowpass (Bass Filter)
– Bandpass (Midtone Filter)
– Highpass (Treble Filter)
52
Outputting signal to DAQ
• Send a signal from the
computer to your data
acquisition device or
sound card
• In our case we are
modifying the audio
input and sending the
signal to our speakers.
53
Exercise 3 – Outputting Sound with myDAQ
• Use LabVIEW Express VIs to:
– Acquire a signal
– Apply a Filter
– Output sound to your
speakers
54
2013 New Products: NI myRIO
Feature & Benefits
- Xilinx Zynq Dual-Core ARM Cortex A9
- Build in WiFi & 3-axis accelerometer
- 40 lines DIO
- 10 Channels analog in, 6 Channels out
- Stereo audio I/O
- Programmable in LabVIEW & C/C++
- User defined LEDs and button
-Compatible with NI miniSystems
-Fully programmable FPGA through LabVIEW
FPGA
-Has many accessory for projects use
-Ready to use projects and courseware for
reference
-Deploy code to real-time processor and
FPGA via USB or WiFi
-Minutes to first measurement
61
NI myRIO Software
LabVIEW
Requires:
- LabVIEW 2013
- LabVIEW Real-Time
- NI myRIO Module
-Optional :
-LabVIEW FPGA Module
-LabVIEW Control Design & Simulation Module
-LabVIEW MathScript
-LabVIEW Vision Development Module
--Robotics algorithms from LabVIEW Robotics
Module
62
美商國家儀器 LabVIEW 與
資料擷取研討會之四
Section III – Analyzing and Presenting Your Results
64
Demonstration: Arrays
65
Arrays
• An array consists of elements and
dimension. What do those terms mean?
• When would you use an array?
• In LabVIEW, what is the index of the
first element in an array?
66
Creating an Array
From the Controls»Modern»Array, Matrix, and Cluster
subpalette, select the Array icon
1. Place an array shell on the front panel
2. Drag a data object or element into the array shell
67
Building Arrays with Loops (Auto-Indexing)
Auto-Indexing Enabled
• Loops can accumulate
Wire becomes thicker
arrays at their boundaries
with auto-indexing
• For loops auto-index by
1D Array
default
• While Loops output only 0 1 2 3 4 5
the final value by default Auto-Indexing Disabled
• How can you Wire remains the same size
enable/disable
auto-indexing?
68
Waveform Charts
Waveform chart – special numeric indicator that can display a
history of values. Charts add 1 data point at a time with history.
• Chart updates with each individual point it receives
• Controls»Express»Graph Indicators»Chart
69
Waveform Graphs
Waveform graph – special numeric indicator that displays an
array of data. A graph displays many data points at once
• Graph updates after all points have been collected
• May be used in a loop if VI collects buffers of data
• Controls»Express»Graph Indicators»Graph
70
Control and Indicator Properties
• Properties are characteristics or qualities about an object
• Properties can be found by right-clicking on a control or
indicator
• Properties include:
– Size
– Color
– Plot style
– Plot color
• Features include:
– Cursors
– Scaling
71
Demonstration: Case Structures
72
How Do I Make Decisions in LabVIEW?
1. Case Structures
(a) (b)
2. Select
(c)
73
Tab Control
• Keep your front panel
organized
• Add a new Tabs for new
operations
• Use the Tab control to
select operations and
perform different
analyses
74
Exercise 4 – Building an Audio Equalizer
• Complete your 3-band
equalizer
• Become familiar with
Case Structures
75
美商國家儀器 LabVIEW 與
資料擷取研討會之五
Section IV – Timing and File I/O
A. Demonstration: Timing a While Loop
B. Timing Loops
C. File I/O
D. Hands-On Exercise: Adding a Karaoke Machine
84
Demonstration: Timing a Loop
Vs.
85
How Do I Time a Loop?
1. Configure the Time Delay Express VI for seconds to wait each
iteration of the loop (works on For and While Loops).
2. Configure the Wait and Wait Next ms Multiple for milliseconds to
wait for each iteration of the loop
86
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)
87
Karaoke!
• Stereo sound has two
channels: left and right
• Sound is recorded using
two strategically placed
microphones
• Voice is present in both
channels
• Subtract left channel from
right channel to eliminate
voice
88
Exercise 5 – Adding Karaoke Functionality
• Expand Audio Equalizer
program to include Karaoke
functionality
89
其他學習資源介紹
學生適用的自學課程影片
• http://www.ni.com/f/academic/12/8168/zht/
– 學習 LabVIEW
– 學習 DAQ
– 學習 RIO
• NI KnowledgeBase
– ni.com/kb
• NI Developer Zone
– ni.com/devzone
99
LabVIEW Pro 網站 labviewpro.net
100
華語區最佳的 LabVIEW 專業論壇
一個讓你快速上手、晉身高手的練功秘境!
Online Test
■ 加入會員,收到任務地圖
■ 開啟地圖,逐一過關斬將
■ 連闖五關,就等同官方認證 CLAD 等級
■ 測驗自己的高手等級,進一步評量自己的功力
現在就加入
LabVIEW Pro !
http://www.labviewpro.net/
Certification 認證考試
考過線上測驗第五關可享 5 折: 1000 元
102
Optional Data Flow Topics
Section V – Advanced Data Flow Topics (Optional)
104
Introduction to Clusters
• Data structure that groups data together
• Data may be of different types
• Analogous to struct in ANSI C
• Elements must be either all controls or all indicators
• Thought of as wires bundled into a cable
• Order is important
105
Creating a Cluster
1. Select a Cluster shell.
2. Place objects inside the shell.
Controls»Modern»Array, Matrix & Cluster
106
Cluster Functions
• In the Cluster & Variant subpalette of the Programming
palette
• Can also be accessed by right-clicking the cluster terminal
(Terminal labels
reflect data type)
Bundle
Bundle By Name
107
Using Arrays and Clusters with Graphs
The waveform data type contains 3 pieces of data:
• t0 = Start time
• dt = Time between samples
• Y = Array of Y magnitudes
108
Shift Register – Access Previous Loop Data
• 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 15
Value
Before
Loop First Second Last
Begins Iteration Iteration Iteration
109
Local Variables
• Local variables allow data to be passed between parallel loops
• You can read or write a single control or indicator from more than one
location in the program
– Local variables break the dataflow paradigm and should be used sparingly
110
LabVIEW Navigation Window
111
LabVIEW Project
• Group and organize VIs
• Manage hardware and I/O
• Manage VIs for multiple targets
• Build libraries and executables
• Manage large LabVIEW applications
• Enable version tracking and management
112