Hands-on Introduction to Data Acquisition with LabVIEW
ni.com/ukni.com/irelandni.com/uk/handson
ni.com/events
Hands-on Introduction to Data Acquisition with LabVIEW 1
1
Introduction to LabVIEW and Computer-Based
Measurements Hands-On Seminar
2
Company Profile• Leaders in Computer-Based
Measurement and Automation
• Long-term Track Record of Growth and Profitability
• $660M Revenue in 2006
• $184.4M in Q3 2007 (12% YOY)
• More than 4,300+ employees; operations in 40+ countries
• Fortune’s 100 Best Companies to Work For 8th Consecutive Year
• FT 50 Best Workplaces UK 2006 & 2007
3
National Instruments Vision
“To do for test and measurement what the
spreadsheet did for financial analysis.”
Virtual InstrumentationThe software is the instrument
Hands-on Introduction to Data Acquisition with LabVIEW 2
4
The NI Approach – An Integrated Platform
High-SpeedDigitizers
DynamicSignal AcquisitionDigital I/O
InstrumentControl
Counter/Timers
MachineVision
Motion Control
Distributed I/O andEmbedded Control
Laptop PC PDADesktop PCPXI Modular Instrumentation
Keypad
LCD
Sound
Acoustics
RFSignal
Battery
Body & Chassis AudioEngine
Durability
Tire & Brake SafetyEmissions Electronics
Temperature
Monitoring
Waste Monitoring
Process Control Motor and
Valve Control
High-ResolutionDigitizers and DMMs
Multifunction Data Acquisition
5
Agenda
• Introduction to LabVIEW
Exercise 1: Create a simple LabVIEW VI
• Data Acquisition with LabVIEW
Exercise 2a – 2c: Introduction to Data Acquisition with LabVIEW
• Decision making in LabVIEW
Exercise 3: Controlling program execution
• Analogue Output and Digital Control
Multiple operations with Analogue IO
6
Introduction to LabVIEW
Hands-on Introduction to Data Acquisition with LabVIEW 3
7
LabVIEW Graphical Programming
• Compiled graphical development environment
• Development time reduction of four to ten times
• Tools to acquire, analyze, and present your data
8
The LabVIEW Environment
Front Panel – User Interface Block Diagram – Compiled Code
10
Graphical Programming – Dataflow
1 Start of Data Flow
2VIs execute once all
inputs are available
Hands-on Introduction to Data Acquisition with LabVIEW 4
11
• LabVIEW automatically divides each application
into multiple execution threads
• LabVIEW introduced multithreading in 1998
Automatic Multithreading in LabVIEW
12
• LabVIEW automatically divides each application
into multiple execution threads
• LabVIEW introduced multithreading in 1998
Automatic Multithreading in LabVIEW
thread
thread
thread
13
Exercise 1: Create a Simple LabVIEW VI
What you will learn:
– Working in the LabVIEW environment
Create an application that:
– Simulates data collection
– Performs RMS Calculation
– Turns on an a front panel indicator when
threshold is reached
Hands-on Introduction to Data Acquisition with LabVIEW 5
14
PC-Based Data Acquisition with
LabVIEW
15
PC-Based Data Acquisition (DAQ)
16
Measuring Analogue Input Signals
• Architecture
Multiplexed
Simultaneous sampling
• Sampling rate
• Resolution
• Signal conditioning
Analogue Input
To PC
…
Important Factors to Consider:
Hands-on Introduction to Data Acquisition with LabVIEW 6
17
Analogue Input – Architectures
Channel 0
Channel 1ADC
Channel 0
Channel 1
Simultaneous sampling
MUX
Multiplexed
AMP
ADC
Channel 0
Channel 1
ADC Channel 0
Channel 1
AMP
AMP
Interchannel delay
No interchannel delay
18
Analogue Input – Sampling Rates
• Undersampling may result in the misrepresentation of the measured signal (aliasing).
• After a signal is aliased, it is impossible to reconstruct the original signal.
• For accurate frequency representation: Sample at least 2x the highest frequency signal being measured.
• For accurate shape representation Sample 5–10x the highest frequency signal being measured.
19
Time (ms)100 200150500
0
1.25
5.00
2.50
3.75
6.25
7.50
8.75
10.00
Amplitude
(Volts)
16-Bit versus 3-Bit Resolution
(5 kHz Sine Wave)
16-bit
3-bit
000
001
010
011
100
101
110
111
| ||||
Analogue Input – Resolution• Number of bits analogue-to-digital converter (ADC) uses to
represent a signal
• Higher resolution – detect smaller voltage changes
Hands-on Introduction to Data Acquisition with LabVIEW 7
20
Sensors/Signals
Amplification, Linearisation, and
Cold-Junction Compensation, Filtering
Isolation
Thermocouples
RTDs
Strain Gauges
Common Mode or High Voltages
Signal Conditioning
DAQ Device
Analogue Input – Signal ConditioningHigh voltage signals and most sensors require signal
conditioning to properly read the signal
Current Excitation,
Linearisation, Filtering
Voltage Excitation, Bridge
Configuration, Linearisation, Filtering
21
NI CompactDAQ
Hi-Speed USB 2.0
Mix and match over 30
hot-swappable modulesBuilt-in signal
conditioning
Synchronized I/O
22
C Series Modules
Thermocouples
4 to 20mA
High Voltage (60V)
RTD
Accelerometer
Strain Gauge
Load Cells
Digital I/O
Hands-on Introduction to Data Acquisition with LabVIEW 8
23
Data Acquisition with LabVIEW
• Triggering
• Sample rates
• Clocking
NI-DAQmx driver software provides connectivity between LabVIEW
and your hardware
Programmatic Interface
NI-DAQmx driver configures
• Buffering
• Signal routing
• etc…
Configuration Based
24
Exercises 2a –2c:
Introduction to Data Acquisition with LabVIEW
What you will learn:
• Taking measurements from scratch
using NI CompactDAQ and
NI LabVIEW
• Create an application that
Measures from a thermocouple
Logs data to a file
25
DAQ Solution for Your Application
Rugged and Modular Test
Hands-on Introduction to Data Acquisition with LabVIEW 9
26
Analysis in LabVIEW
27
Choose Your Analysis Approach
Configuration
Oriented
Textual Math
Standard VIsExpress VIs LabVIEW MathScript
LabVIEW has over 600 built-in analysis functions
28
LabVIEW Analysis
Built-in functions available for
signal processing, analysis and math
• Signal synthesis
• Curve fitting and interpolation
• FFT-based frequency analysis
• Mathematics
• Probability and statistics
• Time- and frequency-domain analysis
• Digital signal processing
• Waveform alignment and resampling
• Much more…
Hands-on Introduction to Data Acquisition with LabVIEW 10
29
LabVIEW Toolkits
• Sound & Vibration
• RF and Communications
• Digital Filter Design
• Database Connectivity
• Reporting Interface to MS Office
• And many more…
Productivity enhancing functionality found in several toolkits,
including…
30
Presenting Data in LabVIEW
31
Presenting Data
• Graphs and strip charts
• Buttons and checkboxes
• Knobs and sliders
• Text and combo boxes
• Tree controls
• Tables
• ActiveX objects
• etc...
Types of controls and indicators available:
Hands-on Introduction to Data Acquisition with LabVIEW 11
32
Options for Professional UIs
LabVIEW is optimised for creating technical user interfaces
Displaying data, visualising processes and controlling machines
33
LabVIEW File I/O
• ASCII
• Binary
Functions for saving your data to files and databases
NI TDM file format provides
an easy way to make test
data searchable
• Excel
• Databases
ni.com/tdm
34
LabVIEW Report GenerationFunctions for creating reports and documenting test results
• HTML
• XML
• MS Office
• DIAdem
The Report Generation toolkit
provides connectivity to
MS Office
NI DIAdem provides a
WYSIWYG report editorni.com/diadem
Hands-on Introduction to Data Acquisition with LabVIEW 12
35
Controlling Program Execution
• Looping (For and While)
• Case structure
• Sequence structure
• State machines
• Event structure
• State diagram editor
• Timed loop
Is Limit
Met?
Turn On
Output
Yes
Reset
Output
No
Start
36
LabVIEW Looping Basics
While Loop For Loop
Run until stop
condition metRun N times
37
LabVIEW Case Structure
Primary decision making block
Hands-on Introduction to Data Acquisition with LabVIEW 13
38
Exercise 3: Controlling Program Execution
What you will learn:
– How to incorporate logic into your
LabVIEW application
Create an application that:
– Charts a sine or triangle wave
depending on toggle switch position
– Turns on/off digital outputs based on
user selections
39
Analogue Output – Considerations
• Accuracy: digital-to-analog converter (DAC) resolution
• Update Rate: settling time and waveform frequency
• Range: fixed or adjustable output voltage/current
DAC
Channel 0
Channel 1
DAC Channel 0
Channel 1
• 16-bit
• 100 kS/sec
• ±10 VDC, 0–20 mA
40
Exercise 4:
Multiple Operations with Analogue I/O
What You Will Learn
• Creating parallel operation in LabVIEW
• Create an application that
Outputs an analogue signal
Uses analogue input channel to acquire
and display on front panel
Time: 20 minutes
Hands-on Introduction to Data Acquisition with LabVIEW 14
41
Analogue Output Functions – PID Control
1Read Sensor 2
CalculatePID value 3
Output to Actuator
Analogue IO can be used in combination for control applications
42
Additional Measurement Platforms
43
NI LabVIEW™ Everywhere
PC
Networked I/O
PC Boards
Handheld
Micro-
processors
PXI
Wireless
Tektronix open Windows
oscilloscopes
FPGA
Platforms:• Desktop
• Mobile
• Industrial
• Embedded
Hands-on Introduction to Data Acquisition with LabVIEW 15
44
Modular Instrumentation
Data Acquisition Sensors, voltage and current
I/O
Measurements: DC to 10 MHz
Resolution: ~18 to 24 bits
Modular Instruments– DMMs, Switches, Oscilloscopes,
High-speed digital, Power
supplies, RF
– Measurements: DC to 6 GHz
– Resolution: Up to 26 bits
45
Interfacing with Benchtop Instruments
Processor
RAM
ROM
Display
PowerSupply
Hard Disk
LabVIEW uses drivers for PC connectivity
• Benchtop instruments involve:
– Fixed functionality
– Vendor defined interface
46
Instrument Control with LabVIEW
GPIB - USB - Ethernet
RS 232 - RS 485 - LXI
Over 5,000 Instrument drivers online, from over 250 vendors
ni.com/idnet
Hands-on Introduction to Data Acquisition with LabVIEW 16
47
Using NI CompactDAQ to Crash Test Safety
Helmets
Application: Designing a highly accurate and portable
high-level impact test application for the certification of
safety helmets.
NI Products Used: NI CompactDAQ
Solution: CompactDAQ is used to control the height from which the helmet under test is
dropped, as well as acquiring data related to what a person's head would be subjected to
upon impact. The system was chosen as it had sufficient throughput to ensure that each
helmet test is thoroughly and accurately documented.
“A system upgrade such as the one we required is a major budget
consideration, and for this reason we were very deliberate in our
search for a new hardware package”
48NI Customer Solutions
Microsoft Uses NI LabVIEW and PXI Modular
Instruments to Develop Production Test System for
Xbox 360 Controllers
Application: Creating an updated versatile test system
to test and validate new Xbox 360 controllers.
NI Products Used: LabVIEW, Modular Instruments and PXI/CompactPCI
Reasons for Choosing NI Products: “Using the LabVIEW graphical development
environment, we created more than 100 tests, implemented Ethernet communication, and
incorporated a data storage interface to our Microsoft SQL Server database…we
implemented a test strategy that resulted in a 50 percent increase in our test throughput per
test station.”
Microsoft Uses NI LabVIEW and PXI Modular Instruments to Develop Production Test System for Xbox 360 Controllers
49
Your Next Steps
• Visit ni.com/labview
Try LabVIEW Online for FREE
Read technical white papers
View webcasts on-demand
Find other seminars in your area
• Schedule a visit with your local field engineer to discuss your
application
Hands-on Introduction to Data Acquisition with LabVIEW 17
50
Useful ResourcesMeasurement Fundamentals
www.ni.com/measurementfundamentals
51
LabVIEW Skill Development Plan
ni.com/training
Certifications
LabVIEW
Basics I
LabVIEW
Basics II
LabVIEW
Intermediate I
Certified LabVIEW
Developer Exam
LabVIEW Advanced I
Certified LabVIEW
Architect Exam
LabVIEW
Intermediate II
Courses
New User Experienced User Advanced User
Core CoursesBegin
Here
Certified LabVIEW
Associate Developer Exam
• Save development time and cost
• Differentiate skills with professional credentials
• Multiple training formats – Classroom, Onsite, Online, Self-Paced
52
Questions or Comments?
ni.com/labview
Hands-on Introduction to Data Acquisition with LabVIEW 18
Exercise 1: Create a Simple LabVIEW VI In this exercise, you will create a simple LabVIEW VI that simulates an analog signal and plots it on a waveform graph. The VI will test the input values against a user-specified limit and light an LED if the input value exceeds that limit.
Below are pictures identifying each of the palettes found in LabVIEW to assist you as you complete these exercises.
Note: LabVIEW has a built-in Automatic Tool Selection feature that changes the behavior of the cursor depending on what type of object you are currently pointing to.
Controls Palette
Functions Palette
1. If you have not already done so, click the LabVIEW icon on your quick launch toolbar.
Hands-on Introduction to Data Acquisition with LabVIEW 19
Once you launch LabVIEW, a splash screen like the following appears.
2. Click More…
3. Expand From Template. Notice the different categories on the left of the window that correspond to the types of tasks from which you can choose. You can select Blank VI to start from scratch. There are also Template VIs to use as a starting point for building your application. Projects and Other Files are more advanced components and will not be described in detail. To get more information on any of the listings in the New Dialog Box, click the Help button in the lower right corner of the window.
Hands-on Introduction to Data Acquisition with LabVIEW 20
4. Select VI»From Template»Tutorial (Getting Started) »Generate and Display and click OK.
Two windows appear. The gray window is the front panel, and the white one is the block diagram. The front panel contains the parts of your VI used for presenting information, whereas the block diagram contains the code that controls the functionality of the VI. You can toggle between the two windows by selecting Window»Show Block Diagram or Window»Show Front Panel. You can also switch between the windows by pressing <Ctrl-E> on the keyboard.
5. Examine the front panel and block diagram of this template VI. The front panel contains a Waveform Chart and a STOP button as shown in the following figure.
Hands-on Introduction to Data Acquisition with LabVIEW 21
The block diagram contains a Simulate Signal VI, which is currently configured to simulate a sine wave and plot it to the chart.
6. Switch back to the front panel by pressing <Ctrl-E>. Since the Run button (the white arrow in the top left corner) is solid, you can run this VI as it is. Click the Run button and examine the operation of the VI. When you are finished, click the STOP button on the front panel to stop running the VI.
Note: As you will see later in the exercise, when the Run button in the upper left corner of both the front panel and the block diagram changes from a solid white arrow, to a broken gray arrow, this new icon indicates that the VI is currently not executable.
7. Now we can add some functionality to this basic VI. We will modify the VI to flash an alarm whenever the signal value is above a certain level. Open the Controls palette (if it is not open already) by right-clicking the front panel window. A small pushpin icon in the upper left corner of this palette appears. Click this pushpin to force the palette to remain on your screen.
Hands-on Introduction to Data Acquisition with LabVIEW 22
8. Click the Numeric Controls palette, and select a Vertical Pointer Slide to be placed on the front panel. To do this, click the Vertical Pointer Slide and drag it to the front panel. Click once to place it.
9. Click the Express menu item on the Controls palette to return to the Express Controls palette.
10. Click the LEDs subpalette, and place a Round LED on the front panel.
Hands-on Introduction to Data Acquisition with LabVIEW 23
11. Right-click the Vertical Pointer Slide and select Properties. A property page will appear. Examine the different properties that you can modify. Make the following changes on the Appearance tab and click OK to apply the changes.
Label: Limit
Slider 1: Check Show digital display(s)
Hands-on Introduction to Data Acquisition with LabVIEW 24
12. Right-click the Round LED labeled Boolean, and select Properties. Examine the different properties that can be modified. On the Appearance tab, change the label from Boolean to Alarm. Click OK to apply your change. Move the objects on the front panel so it resembles the following.
13. Switch to the block diagram by pressing <Ctrl-E>. Double-click the Simulate Signal Express VI to bring up its properties window. Examine the different properties you can modify. Change the Amplitude of the signal to 10. Click OK to apply this change and to close the properties window.
Hands-on Introduction to Data Acquisition with LabVIEW 25
14. Bring up the Functions palette by right-clicking the block diagram. Select Express & Signal Analysis and place the Amp & Level Express VI on the diagram.
15. When you place the Comparison Express VI on the block diagram, a dialog box appears. Select RMS as shown below.
16. As shown below, wire the output of the Simulate Signal VI to Signals input on the Amplitude and Level Measurements VI. Then right-click on RMS output and select Create»Numeric Indicator from the context menu.
Hands-on Introduction to Data Acquisition with LabVIEW 26
17. Bring up the functions palette by right-clicking the block diagram. Select Arithmetic & Comparison»Comparison and place the Comparison Express VI on the diagram
Hands-on Introduction to Data Acquisition with LabVIEW 27
When you place the Comparison Express VI on the block diagram, a dialog box appears that lets you configure what type of comparison you will be doing. Make the following selections, then click OK to apply these changes and to close the dialog box.
Compare Condition: Greater
Comparison Inputs: Compare to second input
18. You can connect Controls, Functions, and Indicators on the block diagram by pointing to an object and clicking it when the cursor changes to a spool of wire. You can then move the cursor to the object you want to connect it to and click again. Connect the Limit control to the Alarm indicator.
Note: The Run button in the upper left corner of both the front panel and the block diagram has changed from a solid white arrow, to a broken gray arrow. This new icon indicates that
Hands-on Introduction to Data Acquisition with LabVIEW 28
the VI is currently not executable. If you click the Run button when it is solid and white, it runs the VI. Clicking it when it is broken and gray brings up a dialog box that will help you debug the VI.
19. Click the Run button now. The resulting dialog box shows that, in this case, the error results from connecting terminals of two different types. Since the Limit control is a Numeric type and the Alarm indicator is a Boolean type, we cannot wire these two terminals together. Highlight the error by clicking it, and then click Show Error. LabVIEW will highlight the location of the error.
20. Notice that the wire between Limit and Alarm is dashed and a red is displayed on it.
To delete this broken wire, press <Ctrl-B>. This keyboard shortcut removes all broken wires from the block diagram.
21. Make your block diagram resemble the following image by completing the following steps.
a. Wire the Limit control to the Operand 2 input of the Comparison function.
b. Connect the wire between the Simulate Signals block and the Waveform Graph to the Operand 1 input of the Comparison block.
c. Wire the Result output of the Comparison block to the Alarm indicator.
Your block diagram should now resemble the following:
Hands-on Introduction to Data Acquisition with LabVIEW 29
22. Switch to the front panel by pressing <Ctrl-E>.
23. Save the VI in the Desktop\CustomerWork folder by using the File menu and name it Exercise1.vi.
Note: Be sure to save this VI, as you will be using it later in the seminar.
24. Run the VI. While running the VI, you can change the Limit value. Also notice that when a data point received from the Simulate Signal VI is greater than the Limit value, the Alarm indicator lights up.
While the VI is still running, switch to the block diagram by pressing <Ctrl-E>. Enable highlight execution by clicking the light bulb on the tool bar. This will allow you to see the flow of data through your program.
25. When you are finished, stop the VI by clicking the STOP button on the front panel.
Hands-on Introduction to Data Acquisition with LabVIEW 30
Optional Exercise 1: The LabVIEW Help System The LabVIEW help system is a great place to learn about LabVIEW and to go when you have questions. This exercise will introduce you to the rich source of information that is available for you to take advantage of.
1. Go back to the VI you just created, and press <F1> on the keyboard to start the help system
2. Expand Fundamentals»LabVIEW Environment and explore the information available here, click around and get a feel for how it is organized.
3. Take a few minutes to explore other topics in the help system.
4. Click on the Search tab try searching on analysis functions for features you might need in your work applications.
Hands-on Introduction to Data Acquisition with LabVIEW 31
Optional Exercise 2: LabVIEW Example Finder As you learned in Optional Exercise 1, LabVIEW has a comprehensive help system. LabVIEW also includes an extensive set of examples that in many cases are the building blocks for your applications. This exercise will introduce you to what examples are available.
1. Go back to the VI you created, and from the Help menu select Find Examples.
2. Expand New Examples for LabVIEW 8.5»Express and double-click on Select Signals.vi.
3. Run the VI and explore the block diagram.
4. Take a few minutes to look around at the other example programs available, search on terms that you are familiar with, i.e., “analysis”, and try out as many as there is time for.
End of Exercise 1
Hands-on Introduction to Data Acquisition with LabVIEW 32
Exercise 2a: Data Acquisition with NI LabVIEW
Exercise Overview
Objective Learn about data acquisition in LabVIEW
Goals When you have completed this exercise, you will:
Know how to configure a data acquisition device
Know how to use the DAQ Assistant and take measurements with NI LabVIEW
Exercise Instructions
Set up hardware
1. Make sure that the NI CompactDAQ chassis (cDAQ-9172) is powered on.
2. Connect the chassis to the PC using the USB cable.
3. NI-DAQmx driver installed on the PC automatically detects the chassis and brings up the following window.
Hands-on Introduction to Data Acquisition with LabVIEW 33
4. Click on Configure and Test This Device to open Measurement & Automation Explorer (MAX).
Note: NI Measurement & Automation Explorer is a configuration utility for all National Instruments
hardware.
Configure Hardware
5. Devices and Interfaces section under My System shows all the National Instruments devices installed and configured on your PC. The NI-DAQmx Devices folder shows all the NI-DAQmx compatible devices. By default, the NI CompactDAQ chassis NI cDAQ-9172 shows up with the name “cDAQ1”.
6. This section of MAX also shows the installed modules as well as empty slots in the CompactDAQ chassis.
7. Right-click on NI cDAQ-9172 and click on Self-Test.
8. The device passes the self test, which means it is configured properly and ready to be used in your LabVIEW application.
LabVIEW
9. Open NI LabVIEW 8.5 and press <Ctrl-N> to open a blank VI.
10. Press <Ctrl-T> to tile front panel and block diagram windows.
11. Pull up the Functions Palette by right-clicking on the white space on the LabVIEW block diagram window.
12. Move your mouse over the Express»Input palette, and click the DAQ Assist Express VI. Click again on the white space of the LabVIEW block diagram to place the DAQ Assistant VI.
Hands-on Introduction to Data Acquisition with LabVIEW 34
13. The Create New Express Task… window appears:
14. To configure a temperature measurement application with a thermocouple, click on Analog Input»Temperature»Thermocouple. Click the + sign next to the cDAQ1Mod1 (NI 9211), highlight channel ai0, and click Finish. This adds a physical channel to your measurement task.
15. Change the CJC source to Built In and Acquisition Mode to Continuous. Click the Run button. You will see the temperature readings from the thermocouple in test panel window.
Hands-on Introduction to Data Acquisition with LabVIEW 35
16. Click OK to close the Express block configuration window to return to the LabVIEW block diagram.
17. Notice that LabVIEW automatically creates the code for you for this measurement task. Click Yes to automatically create a While Loop.
18. Right-click the data terminal output of the DAQ Assistant Express VI (the blue output arrow on the right side) and select Create»Graph Indicator.
19. Notice that a graph indicator is placed on the front panel.
20. Your block diagram should now look like the figure below. The while loop automatically adds a stop button to your front panel that allows you to stop the execution of the loop.
Hands-on Introduction to Data Acquisition with LabVIEW 36
21. Rather than displaying our data in a graph indicator, we want to display our temperature readings in a thermometer indicator. To do this, go to the front panel by pressing <Ctrl-E>. Right-click the graph indicator and select Replace. The Controls palette will appear. Select Modern»Numeric»Thermometer. The thermometer indicator should now appear instead of the graph indicator.
22. Also, right-click on the stop (F) button and select Replace. The Controls palette will appear. Select Boolean»Stop Button.
Hands-on Introduction to Data Acquisition with LabVIEW 37
23. Modify the thermometer indicator by right-clicking it and selecting Properties. On the Appearance Tab, change the Label to Temperature.
On the Scale tab, change the Minimum to 20 and the Maximum to 30.
Click OK when you are finished.
Hands-on Introduction to Data Acquisition with LabVIEW 38
24. Switch to the block diagram. Expand the While Loop. Your block diagram should now resemble the following illustration.
25. To perform analysis on your data, select the Express»Signal Analysis»Statistics Express VI and place it on your block diagram.
26. A properties window will appear. Make the following selections and click OK.
Statistical Calculations: Arithmetic Mean
Hands-on Introduction to Data Acquisition with LabVIEW 39
Extreme Values: Maximum, Minimum
27. Connect the data output of the DAQ Assistant VI to the Signals input of the Statistics VI.
Hands-on Introduction to Data Acquisition with LabVIEW 40
28. Right-click the Arithmetic Mean output of the Statistics VI and select Create»Numeric Indicator. This will create a numeric indicator on the front panel that will display the mean. Repeat this step for both the Maximum and Minimum outputs of the Statistics VI. Your block diagram should resemble the following.
29. Switch to the front panel and rearrange your controls and indicators to resemble the following.
30. Save the VI in the Desktop\CustomerWork folder by using the File menu and name it Exercise2.vi.
Hands-on Introduction to Data Acquisition with LabVIEW 41
31. Run the VI. Hold the thermocouple between your fingers to raise the temperature. Notice the change in temperature on the thermometer. If you are not seeing enough of a temperature fluctuation, stop the VI and decrease the range on your thermometer indicator.
32. Click the STOP button on the front panel when you are finished.
33. Close the VI.
End of Exercise 2a
Hands-on Introduction to Data Acquisition with LabVIEW 42
Exercise 2b: File I/O in LabVIEW
Exercise Overview
Objective
How to log data to a file using LabVIEW.
Goals
When you have completed this exercise, you will:
Know how to use Write to Measurement File express VI and how to log data to a file using LabVIEW.
Exercise Instructions
1. Open the VI from exercise 2a.
2. Right-click on the block diagram and select Express» Output» Write to Measurement File and place it inside the While Loop on the block diagram.
Hands-on Introduction to Data Acquisition with LabVIEW 43
3. A configuration window will appear. Enter the following parameters and click OK.
4. Wire the output of the DAQ Assistant Express VI to the input of the Write to Measurement File Express VI.
5. Your block diagram should now resemble the following figure.
Hands-on Introduction to Data Acquisition with LabVIEW 44
6. Save the VI in the Desktop\CustomerWork folder by using the File menu and name it Exercise2b.vi.
7. Run the VI momentarily and press STOP to stop the VI.
8. Your file will be created in the folder specified.
9. Open the file using Microsoft Office Excel or Notepad. Review the header and temperature data saved in the file.
10. Close the data file and the LabVIEW VI.
End of Exercise 2b
Hands-on Introduction to Data Acquisition with LabVIEW 45
Exercise 2c (Optional): Automatic Code Generation in LabVIEW
Exercise Overview
Objective
Create DAQmx code from the DAQ Assistant.
Goals
When you have completed this exercise, you will:
Know how to generate code automatically from the DAQ Assistant.
Have experience using some of the NI-DAQmx VIs.
Exercise Instructions
1. Open the VI from Exercise 2a.
2. Delete all the functions and terminals from the block diagram except the DAQ Assistant. Delete all the wires as well.
3. Right-click on the DAQ Assistant and select Generate NI-DAQmx Code.
Hands-on Introduction to Data Acquisition with LabVIEW 46
4. NI-DAQmx will now generate LabVIEW code using the NI-DAQmx API. Your block diagram should now resemble this:
5. Double-click on the configuration VI (shown below) that NI-DAQmx generated for you on your block diagram
6. The block diagram of the configuration VI should appear as shown below. This is an example of how you can use the DAQmx VIs if you need to create customized DAQ code that includes features beyond those offered by the DAQ Assistant.
Hands-on Introduction to Data Acquisition with LabVIEW 47
In this block diagram, you will see 3 SubVIs:
DAQmx Create Task.vi
DAQmx Create Channel.vi
DAQmx Timing.vi
To learn about each VI, hover your mouse over each one and press <Ctrl-H>. This will bring up the Context Help which explains the parameters and functionalities of each VI.
7. Close the VI and do not save any changes.
End of Exercise 2c
Hands-on Introduction to Data Acquisition with LabVIEW 48
Exercise 3: Controlling Program Execution
If you are up for challenge, try to build the following LabVIEW application without using the instructions; if you feel you need more guidance skip down to the section step-by-step for a complete set of instructions.
Challenge Application
Using a While Loop, case structure, toggle switch and the Simulate Signal VI, create a simple application that charts a sine or triangle wave depending on toggle switch position.
When you are done, save your VI as Exercise3-Decisions.vi. You will use it in the next exercise.
If you are really up for a challenge add logic to the VI so it will stop either when you press the stop button or when the loop iterations have exceeded 10,000.
Step By Step Instructions
In this exercise, you will create a LabVIEW VI that will output a triangle or sine wave to a front panel graph depending on the state of a toggle switch. You will use a case structure to handle the logic of which signal is output and a While Loop to keep the application running until a Stop button is pressed.
1. Let’s start by placing a While Loop on the block diagram. Draw it large enough to accommodate the other code you will be placing inside it. You can locate the While Loop on the Express» Execution Control palette as shown below.
Hands-on Introduction to Data Acquisition with LabVIEW 49
2. Next select the Case Structure from the Execution Control palette and place it inside the While Loop as shown below.
3. Next we will add the simulate signal VIs two the case statement. Remember one will output a triangle wave, the other a sine wave. From the Express»Input palette, select Simulate Sig as shown below, and place it inside the case statement.
Hands-on Introduction to Data Acquisition with LabVIEW 50
4. Configure the first Simulate Sig to produce a triangle wave by selecting the Signal type as shown below.
5. Your block diagram should now look like the following.
Hands-on Introduction to Data Acquisition with LabVIEW 51
6. Next, switch the case statement from True to False, as shown below.
7. Repeat steps 3 and 4, except this time leave the default settings for the Simulate Sig VI so it will generate a sine wave.
8. Switch to your front panel and place a Waveform Graph as shown below.
Hands-on Introduction to Data Acquisition with LabVIEW 52
9. Also add a vertical toggle switch from the Boolean palette to the front panel as shown below.
10. Your front panel should look like the following.
Hands-on Introduction to Data Acquisition with LabVIEW 53
11. Switch back to the block diagram and wire the toggle switch to the input of the case statement as shown below.
12. Next, wire the outputs from both of the Simulate Signals to the waveform graph. Note that you will have to wire through the wall of case statement. Don’t forget wire both the cases, True and False.
13. You are ready to test your VI by switching the toggle switch back and forth. You should see the graph switch between a sine and triangle wave.
Hands-on Introduction to Data Acquisition with LabVIEW 54
Adding Digital Output to Your Project
Often when you are creating control applications, controlling digital lines is necessary to interface with pumps, valves, lamps, etc. In the next part of this exercise we will extend our application to include control of the digital output lines.
8. Right-click on your front panel and select an empty array container as shown below.
9. Place the array container at the bottom of the VI, as shown below.
Hands-on Introduction to Data Acquisition with LabVIEW 55
14. You can create an array of controls by simply inserting them into the array. Right-click on the front panel and select a push button from the Boolean palette and drop it into the empty array.
15. It should look like the following.
16. Next we will increase the size of the array of Booleans so it contains eight elements. To do this, click on the right side of the array container and drag it to the right until eight push-buttons are visible.
Hands-on Introduction to Data Acquisition with LabVIEW 56
17. VERY IMPORTANT STEP- Click on the eighth switch to initialize the array size:
18. Next configure the hardware to recognize these switches and control one digital output per switch. Start by switching to the block diagram using <Ctrl-E>.
19. Next select the DAQ Assistant from the Express»Output palette
20. In the DAQ Assistant select Digital I/O»Line Output as shown below. Click Next.
Hands-on Introduction to Data Acquisition with LabVIEW 57
21. Select all the digital output lines by clicking on the first then holding the shift key down before clicking on the last out, then click Finish.
22. Click OK at the following dialog.
Hands-on Introduction to Data Acquisition with LabVIEW 58
23. Finally wire the output of the array to the data input on the DAQ Assistant, as shown below.
24. Switch to the front panel and Run the VI. Use the push buttons to activate the digital outputs on the NI 9472 module and watch the LEDs change as you select different push buttons.
Hands-on Introduction to Data Acquisition with LabVIEW 59
Optional Steps
1. Add logic to the VI so it will stop either when you press the STOP button or when the loop iterations have exceeded 10,000.
2. Do this by inserting an Or gate from the Boolean palette before the STOP button, as shown below.
Hands-on Introduction to Data Acquisition with LabVIEW 60
3. Next select the greater than function from the Comparisons palette.
4. Wire as follows.
Hands-on Introduction to Data Acquisition with LabVIEW 61
5. Right-click on the open terminal of the greater than block and select Create»Contant.
6. Change the constant to 10000 as shown below and Run the VI.
Hands-on Introduction to Data Acquisition with LabVIEW 62
7. Finally, open and examine the State Diagram template that ships with LabVIEW. Select File»New and select Standard State Machine from the list box as shown below. Examine the comments included on the template. There are several templates such as this one to help you get started with your LabVIEW applications. Take a few minutes to familiarize yourself with what is available.
End of Exercise 3
Hands-on Introduction to Data Acquisition with LabVIEW 63
Exercise 4: Multiple Operations with Analogue I/O
Exercise Overview
Objective In this exercise, you will use the DAQ Assistant to build a LabVIEW VI that generates and outputs an analogue waveform. You will then add a second loop that measures the waveform using an analogue input channel.
Goals When you have completed this exercise, you will:
Know how to generate signals in LabVIEW with NI CompactDAQ
Run loops in parallel for multiple analogue operations
Exercise Instructions
1. If you closed LabVIEW after the last exercise, launch it. Open a new VI.
2. Press <Ctrl-E> to switch to the LabVIEW block diagram.
3. Browse to the Input subpalette on the Functions»Express palette and click the Simulate
Sig Express VI as shown below. Place the VI on the block diagram.
4. In the Signal section of the window, set Amplitude to 5.
5. In the Timing section of the window, set Samples per second (Hz) to 10,000. Click OK.
Hands-on Introduction to Data Acquisition with LabVIEW 64
6. Bring up the Functions»Express palette again, and browse to the DAQmx Assist VI on
the Output subpalette of the Functions palette. Place the VI on the block diagram.
7. In the Create New window, select Analogue Output as the Measurement Type and then
select Voltage.
Hands-on Introduction to Data Acquisition with LabVIEW 65
8. In the next window, click the + sign next to cDAQ1Mod3 (NI 9263), select ao0, and click the Finish button.
9. In the DAQ Assistant configuration window, select Generate Continuously from the Task Timing tab in the lower part of the window. Uncheck Use timing from waveform data, and set the Rate (Hz) to 10,000. Click the OK button.
Hands-on Introduction to Data Acquisition with LabVIEW 66
10. On the block diagram, move the DAQ Assistant Express VI to the right side of the Simulate Signal Express VI. Wire the Sine output of the Simulate Signal VI to the data input of the DAQ Assistant VI. To create a wire, move your cursor over the blue arrow on the Sine output terminal of the Simulate Signal VI and left-click to start the wire. Move your cursor to the data input terminal of the DAQ Assistant VI and left-click again to attach the wire. Your block diagram should resemble the following figure.
11. To make the VI run continuously, create a While Loop. A While Loop causes all parts of the program inside the loop to run continuously until a Stop button is clicked. To create the While Loop, browse to the Exec Ctrl subpalette of the Functions palette and select a While Loop.
12. Draw the While Loop around your entire block diagram. Your block diagram should resemble the following figure.
Hands-on Introduction to Data Acquisition with LabVIEW 67
13. To create a slide control for varying the frequency of the sine wave, press <Ctrl-E> to switch to the LabVIEW front panel. Right-click on the empty gray space to pull up the Controls palette. Select Vertical Pointer Slide from the Numeric Controls subpalette of the Controls palette. Place the vertical pointer slide on the front panel.
14. Right-click the slide control and select Properties. On the Appearance tab, change the label to Frequency. On the Scale tab, change the Scale Range so Minimum equals 0.00 and Maximum equals 1000.00. Click OK to close the Properties window.
15. Press <Ctrl-E> to switch to the block diagram. Notice the orange Frequency slide control
terminal. Move the control inside the While Loop to the left side of the Simulate Signal Express VI. Wire the knob control to the Frequency input terminal of the Simulate Signal Express VI (the second orange arrow on the left side of the Simulate Signal Express VI).
Hands-on Introduction to Data Acquisition with LabVIEW 68
Note: Make sure that you wire the knob control to the correct input terminal of the Simulate Signal Express VI. If you make a bad wire connection, double-click the wire to select it and press <Delete>. Your block diagram should resemble the following figure.
16. This VI will now use the frequency knob on the LabVIEW front panel to generate a sine wave at the specified frequency. This sine wave is then generated on analogue output channel 0 of the NI 9263 C Series module by the DAQ Assistant Express VI.
17. Save the VI as Analogue output.vi in the Desktop\CustomerWork folder.
18. Increase the size of the block diagram window to make space for another While Loop to
go below the existing Analogue Output code.
Hands-on Introduction to Data Acquisition with LabVIEW 69
19. Place a DAQ Assistant Express VI from the Input subpalette of the Functions»Express palette. Select Analogue Input as the Measurement Type and select Voltage. In the next window, expand channels of the cDAQ1Mod2 (NI 9215) by selecting the + sign, and select ai0. Click the Finish button.
Hands-on Introduction to Data Acquisition with LabVIEW 70
20. In the DAQ Assistant window, select Acquire Continuously from the Task Timing tab in the lower part of the window. Set the Rate (Hz) to 10,000 and click OK.
21. Once you click OK, a dialog window will appear asking if you would like to create a While Loop around the DAQ Assistant. Select Yes to automatically create a While Loop for this continuous acquisition.
Hands-on Introduction to Data Acquisition with LabVIEW 71
22. The block diagram should resemble the figure above. Next, create a graph indicator to display the analogue input data. To create a graph indicator, right-click the data output terminal of the DAQ Assistant Express VI, and select Create Graph Indicator.
Hands-on Introduction to Data Acquisition with LabVIEW 72
23. Below is a picture of the completed block diagram.
24. Press <Ctrl-E> to switch to the LabVIEW front panel.
25. Locate the stop (F) Push Button control and right-click to replace it with a Stop Button
control, as shown on the diagram below. (Replace»Boolean»Stop Button)
Hands-on Introduction to Data Acquisition with LabVIEW 73
26. Rearrange the front panel controls and indicators to resemble the figure below.
27. Save the VI as Analogue Input and Output.vi in the Desktop\CustomerWork
folder.
28. Run the VI
29. The analogue output loop is generating a sine wave on analogue output channel 0,
which is wired directly to channel 0 of the analogue input module. Use the slider control on the front panel to control the sine wave frequency, and look at the graph on the front panel to monitor the sine wave.
30. Press both stop buttons to stop the execution of both loops.
Hands-on Introduction to Data Acquisition with LabVIEW 74
Beyond the Exercise For Loops can be used to generate arrays using a feature called automatic indexing, as shown in the following figure.
Try building the following block diagram to further manipulate the waveform being generated.
End of Exercise 4