Data Acquisition in LabVIEW
Data Acquisition in LabVIEW
Data Acquisition in LabVIEW
to Data
Acquisition
This chapter explains the basic concepts of using DAQ in LabVIEW.
Topics:
LabVIEW is very powerful when it comes to creating DAQ applications. LabVIEW includes a
set of VIs that let you configure, acquire data from, and send data to DAQ devices. Often,
one device can perform a variety of functions, such as analog-to-digital (A/D) conversion,
digital-to-analog (D/A) conversion, digital I/O, and counter/timer operations. Each device
supports different DAQ and signal generation speeds. Also, each DAQ device is designed for
specific hardware, platforms and operating systems.
National Instruments, the inventor of LabVIEW, also make DAQ devices, so the integration
with the DAQ devices from NI and the LabVIEW software is seamless and makes it easy to do
I/O operations from the LabVIEW environment.
4 Introduction to Data Acquisition
The DAQ system has the following parts involved, see Figure:
The parts are:
A voltage signal can typically be a 0-5V signal, while a current signal can typically be a 4-
20mA signal.
• Analog input
• Analog output
5 Introduction to Data Acquisition
• Digital I/O
• Counter/timers
• “Desktop DAQ devices” where you need to plug a PCI DAQ board into your
computer. The software is running on a computer.
• “Portable DAQ devices” for connection to the USB port, Wi-Fi connections, etc. The
software is running on a computer
• “Distributed DAQ devices” where the software is developed on your computer and
then later downloaded to the distributed DAQ device.
[www.ni.com]
• NI-DAQmx
6 Introduction to Data Acquisition
• NI-DAQmx Base
The DAQ Assistant, included with NI-DAQmx, is a graphical, interactive guide for configuring,
testing, and acquiring measurement data. With a single click, you can even generate code
based on your configuration, making it easier and faster to develop complex operations.
Because DAQ Assistant is completely menu-driven, you will make fewer programming errors
and drastically decrease the time from setting up your DAQ system to taking your first
measurement.
NI-DAQmx Base offers a subset of NI-DAQmx functionality on Windows and Linux, Mac OS X,
Windows Mobile and Windows CE.
• Real-time monitoring
• Data analysis
• Data logging
• Control algorithms
• Human machine interface (HMI)
In order to create your DAQ application you need a programming development tool, such as
LabVIEW.
7 Introduction to Data Acquisition
In addition to the standard tools, MAX can expose item-specific tools you can use to
configure, diagnose, or test your system, depending on which NI products you install. As you
navigate through MAX, the contents of the application menu and toolbar change to reflect
these new tools.
2.3 NI-DAQmx
The NI-DAQmx Driver software is the layer of software for easily communicating with the
hardware. It forms the middle layer between the application software and the hardware.
8 Introduction to Data Acquisition
The “DAQ Assistant” is an easy way to start using the DAQ features in LabVIEW. We will
learn more about the “DAQ Assistant” in a later chapter.
2.4 NI USB-6008
NI USB-6008 is a simple and low-cost multifunction I/O device from National Instruments.
9 Introduction to Data Acquisition
The device has the following specifications:
The NI USB-6008 is well suited for education purposes due to its small size and easy USB
connection.
3 Physical input/output
signals
Data acquisition involves gathering signals from measurement sources and digitizing the
signal for storage, analysis, and presentation on a PC. Data acquisition (DAQ) systems come
in many different PC technology forms for great flexibility when choosing your system.
Scientists and engineers can choose from PCI, PXI, PCI Express, PXI Express, PCMCIA, USB,
Wireless and Ethernet data acquisition for test, measurement, and automation applications.
There are five components to be considered when building a basic DAQ system
3.1 Transducers
Data acquisition begins with the physical phenomenon to be measured. This physical
phenomenon could be he temperature of a room, the intensity of a light source, the
pressure inside a chamber, the force applied to an object, or many other things. An effective
DAQ system can measure all of these different phenomena.
A transducer is a device that converts a physical phenomenon into a measurable electrical
signal, such as voltage or current. The ability of a DAQ system to measure different
phenomena depends on the transducers to convert the physical phenomena into signals
measurable by the DAQ hardware. Transducers are synonymous with sensors in DAQ
systems. There are specific transducers for many different applications, such as measuring
temperature, pressure, or fluid flow. Below we see some common phenomena and the
transducers used to measure them.
Phenomenon Transducer
10
11 Physical input/output signals
Sound Microphone
Acceleration Accelerometer
pH pH Electrode
Different transducers have different requirements for converting phenomena into a
measurable signal. Some transducers may require excitation in the form of voltage or
current. Other transducers may require additional components and even resistive networks
to produce a signal.
3.2 Signals
The appropriate transducers convert physical phenomena into measurable signals. However,
different signals need to be measured in different ways. For this reason, it is important to
understand the different types of signals and their corresponding attributes. Signals can be
categorized into two groups:
• Analog
• Digital
12 Physical input/output signals
[ww.ni.com]
An analog signal can be at any value with respect to time. A few examples of analog signals
include voltage, temperature, pressure, sound, and load. The three primary characteristics of
an analog signal is:
• Level
• Shape
• Frequency
Level
Because analog signals can take on any value, the level gives vital information about the
measured analog signal. The intensity of a light source, the temperature in a room, and the
pressure inside a chamber are all examples that demonstrate the importance of the level of
a signal. When measuring the level of a signal, the signal generally does not change quickly
13 Physical input/output signals
with respect to time. The accuracy of the measurement, however, is very important. A DAQ
system that yields maximum accuracy should be chosen to aid in analog level
measurements.
Shape
Some signals are named after their specific shape - sine, square, sawtooth, and triangle. The
shape of an analog signal can be as important as the level, because by measuring the shape
of an analog signal, you can further analyze the signal, including peak values, DC values, and
slope. Signals where shape is of interest generally change rapidly with respect to time, but
system accuracy is still important. The analysis of heartbeats, video signals, sounds,
vibrations, and circuit responses are some applications involving shape measurements.
Frequency
All analog signals can be categorized by their frequency. Unlike the level or shape of the
signal, frequency cannot be directly measured. The signal must be analyzed using software
to determine the frequency information. This analysis is usually done using an algorithm
known as the Fourier transform.
When frequency is the most important piece of information, it is important to consider
including both accuracy and acquisition speed. Although the acquisition speed for acquiring
the frequency of a signal is less than the speed required for obtaining the shape of a signal,
the signal must still be acquired fast enough that the pertinent information is not lost while
the analog signal is being acquired. The condition that stipulates this speed is known as the
Nyquist Sampling Theorem. Speech analysis, telecommunication, and earthquake analysis
are some examples of common applications where the frequency of the signal must be
known.
14 Physical input/output signals
State
Digital signals cannot take on any value with respect to time. The state of a digital signal is
essentially the level of the signal - on or off, high or low. Monitoring the state of a switch -
open or closed - is a common application showing the importance of knowing the state of a
digital signal.
Rate
The rate of a digital signal defines how the digital signal changes state with respect to time.
An example of measuring the rate of a digital signal includes determining how fast a motor
shaft spins. Unlike frequency, the rate of a digital signal measures how often a portion of a
signal occurs. A software algorithm is not required to determine the rate of a signal
4 MAX
Measurement & Automation Explorer (MAX) provides access to your National Instruments
devices and systems.
In addition to the standard tools, MAX can expose item-specific tools you can use to
configure, diagnose, or test your system, depending on which NI products you install. As you
navigate through MAX, the contents of the application menu and toolbar change to reflect
these new tools.
LabVIEW installs MAX to establish all devices and channel configuration parameters. MAX
reads the information the Device Manager records in the Windows Registry and assigns a
logical device number to each DAQ device.
15
16 MAX
You use the device number to refer to the device in LabVIEW. You can access MAX by
selecting Tools»Measurement & Automation Explorer in LabVIEW. This displays the primary
MAX window.
Before using a data acquisition board, you must confirm that the software can communicate
with the board by configuring the devices. For Windows, the Windows Configuration
Manager keeps track of all the hardware installed in the computer, including National
Instruments DAQ devices. The Windows Configuration Manager automatically detects and
configures Plug & Play (PnP) devices.
If you have a PnP device, such as an E Series MIO device, the Windows Configuration
Manager automatically detects and configures the device. If you have a non-PnP device, or
legacy device, you must configure the device manually using the Add New Hardware option
in the Control Panel. You can verify the Windows Configuration by accessing the Device
Manager.
5 NI-DAQmx
Driver software is the layer of software for easily communicating with the hardware. It forms
the middle layer between the application software and the hardware. Driver software also
prevents a programmer from having to do register-level programming or complicated
commands in order to access the hardware functions.
• NI-DAQmx
• NI-DAQmx Base
The DAQ Assistant, included with NI-DAQmx, is a graphical, interactive guide for configuring,
testing, and acquiring measurement data. With a single click, you can even generate code
based on your configuration, making it easier and faster to develop complex operations.
Because DAQ Assistant is completely menu-driven, you will make fewer programming errors
and drastically decrease the time from setting up your DAQ system to taking your first
measurement.
NI-DAQmx Base offers a subset of NI-DAQmx functionality on Windows and Linux, Mac OS X,
Windows Mobile and Windows CE.
National Instruments DAQ boards have a driver engine that communicates between the
board and the application software. There are two driver engines, NI-DAQmx and Traditional
NI-DAQ. You can also use the DAQ Assistant, an Express VI that communicates with NI-
DAQmx, in LabVIEW to communicate with the DAQ board. In addition, National Instruments
provides Measurement & Automation Explorer (MAX) for configuring DAQ boards.
The NI-DAQmx Driver software is the layer of software for easily communicating with the
hardware. It forms the middle layer between the application software and the hardware.
Driver software also prevents a programmer from having to do register-level programming
or complicated commands in order to access the hardware functions.
17
18 NI-DAQmx
Scales
You can configure custom scales for your measurements using MAX. This is very useful when
working with sensors. It allows you to bring a scaled value into your application without
having to work directly with the raw values. For example, you can use a temperature sensor
that represents temperature with a voltage. The conversion equation for the temperature is,
Voltage x 100 = Celsius. After a scale is set, you can use it in your application program,
providing the temperature value, rather than the voltage.
• Acquire 1 Sample
• Acquire n Samples
• Acquire Continuously
19 NI-DAQmx
You can create NI-DAQmx simulated devices in NI-DAQmx 7.4 or later. Using NI-DAQmx
simulated devices:
Later, when you acquire the hardware, you can import the NI-DAQmx simulated device
configuration to the physical device using the MAX Portable Configuration Wizard.
You can work on your applications on a portable system and upon returning to the original
system, you can easily import your application work.
To create an NI-DAQmx simulated device, right-click Devices and Interfaces and select Create
New. The Create New dialog box prompts you to select a device to add. Select NI-DAQmx
Simulated Device and click Finish. In the Choose Device dialog box, select the family of
devices for the device you want to simulate. Select the device and click OK. If you select a PXI
device, you are prompted to select a chassis number and PXI slot number. If you select an
SCXI chassis, the SCXI configuration panels open.
6 DAQ Devices
DAQ hardware acts as the interface between the computer and the outside world. It
primarily functions as a device that digitizes incoming analog signals so that the computer
can interpret them
• Analog input
• Analog output
• Digital I/O
• Counter/timers
• “Desktop DAQ devices” where you need to plug a PCI DAQ board into your
computer. The software is running on a computer.
• “Portable DAQ devices” for connection to the USB port, Wi-Fi connections, etc. The
software is running on a computer
• “Distributed DAQ devices” where the software is developed on your computer and
then later downloaded to the distributed DAQ device.
[www.ni.com]
20
21 DAQ Devices
Most DAQ devices have four standard elements: analog input, analog output, digital I/O, and
counters. The DAQ device transfers the measured signals to a computer through different
bus structures. For example, you can plug a DAQ device into the PCI bus or the USB port of a
computer or the Personal Computer Memory Card International Association (PCMCIA)
socket of a laptop. You also can use PXI/CompactPCI to create a portable, versatile, and
rugged measurement system.
[www.ni.com]
22 DAQ Devices
7 NI USB-6008
NI USB-6008 is a simple and low-cost multifunction I/O device from National Instruments.
The device has the following specifications:
The NI USB-6008 is well suited for education purposes due to its small size and easy USB
connection.
The first time you connect the USB-6008 to the PC, the Windows Hardware Installer Wizard
will open.
23
24 NI USB-6008
The wizard searches the PC for the necessary driver software for the USB-6008. This driver
software was installed along with the installation of the NI-DAQ software. When the wizard
has finished the installation of the driver software, the USB-6008 is ready for use.
In the MAX window, expand the “Devices and Interfaces” node and then “NI DAQmx
Devices”. Right-click on the NI USB-6008 device and select “Self-Test”.
25 NI USB-6008
Hopefully the self-test passes without errors. Then, you should test the individual channels
of the USB-6008 to check that the input signals are detected correctly by the USB-6008, and
that the output signals generated by the USB-6009 have correct values. This I/O can be
tested in several ways, depending on which channels you actually want to test.
Here, let us test analog output channel 0 (AO0) and the analog input channel 0 (AI0) to see if
they work correctly. We will perform a very simple test, which is sufficient if we are to check
that both AO0 and AI0 work correctly. The test procedure, which is denoted loopback, is to
connect the AI0 channel to the AO0 channel. Then we generate some legal voltage at AO0. If
AI0 detects the same voltage, we know that both AO0 and AI0 work. (We may then repeat
this procedure for other channels.) If for some reason AI0 detects some other voltage than
the value we set for AO0, then there is an error in either the AI0 channel or in the the AO0
channel, and further investigations are necessary.
To prepare for the loopback test, we wire together AI0 and AO0. To see the terminals of the
USB-6000, select “Device Pinouts” from the right-click menu.
26 NI USB-6008
To actually perform the loopback test, right-click on the NI USB-6008 device in MAX, and
then select “Test Panels..” in order to open the Test Panels. In the Test Panels window,
select the Analog Output tab.
27 NI USB-6008
In the Analog Output tab, select any voltage between 0V and 5V.
Next, click the Analog Input tab in the Test Panels window.
28 NI USB-6008
The Analog Input tab should indicate the same (or almost the same) voltage as is set out on
AO0. There may be a small difference between the values due to the limited resolution in
the DA-converter (digital-to-analog) and in the AD-converter (analog-to-digital).
29 NI USB-6008
You should also always use a multi-meter to check if the voltage levels on the output and
input channels are correct according to your settings.
30 NI USB-6008
31 NI USB-6008
32 NI USB-6008
In this window you need to select either “Acquire Signals” (i.e., Input Signals) or “Generate
Signals” (i.e., Output Signals).
33 NI USB-6008
In the next window you select which Analog Input you want to use. Select ai0 (Analog Input
channel 0) and click Finish.
34 NI USB-6008
In the Timing Settings Select “1 Sample (On Demand)”.
35 NI USB-6008
The next step is to select the Signal Input Range. A common signal is 0-5V.
You may also rename the name of the channel (right-click on the name):
36 NI USB-6008
You are now finished with the configuration. Click OK in the DAQ Assistant window The DAQ
Assistant icon appears on the Block Diagram:
37 NI USB-6008
Example:
Wire the data output to a numeric indicator like this (and hit the Run button):
Then numeric indicator will show, e.g., the following value:
[End of Example]
Example:
If you want a “continuous” acquisition, put a While loop around the DAQ Assistant like this:
We can also communicate with the DAQ device without using the DAQ Assistant:
38 NI USB-6008
For more advanced applications this approach is recommended.
[End of Example]
39 NI USB-6008
40 NI USB-6008
Example:
Or inside a loop for “continuous” writing to the DAQ device:
41 NI USB-6008
However you should not use the DAQ Assistant inside a loop because of the lack of
performance. The following is therefore better:
In this example we have used some of the other Vis in the DAQmx paletter as well.
42 NI USB-6008
In this example we assume that we connect wires for “Analog Out” and “Analog In” together
like this (a so-called loopback test).
We can also communicate with the DAQ device without using the DAQ Assistant:
For more advanced applications this approach is recommended.
[End of Example]
8 Logging to File
In many cases you want to write your data you get from the DAQ device to a text file for
later use. In this chapter we will learn how to write to a measurement file in LabVIEW. We
will also learn how to read the same file.
You can use the “Write to Measurement File” function on the File I/O palette in LabVIEW for
writing data to text files You can save your data in a tab separated text (LVM data file
format) or as a binary (TDMS file format) file.
If we use the LVM, it is easy to open and view the data in Notepad.
43
44 Logging to File
When you drag in the “Write to Measurement File”, a configuration dialog window will
automatically pop up.
Example:
Front Panel:
45 Logging to File
In this application we log data from a process based on a manual control signal. Both the
input signal u and the output signal (temperature) is saved to a Measurement File.
Block Diagram:
The LVM file may look something like this:
46 Logging to File
The first column is the time, the second column is the input signal, and the third column is
the output signal.
[End of Example]
When you drag in the “Read from Measurement File”, a configuration dialog window will
automatically pop up.
47 Logging to File
Example:
This application reads the data and plots it in 2 different graphs.
48 Logging to File
Block Diagram:
[End of Example]