Está en la página 1de 20

Data Acquisition Fundamentals

(NI-DAQmx)
Jeffery Radigan
Ohio State University

Instructor’s Portion
Summary
Students will learn about the basics of data acquisition (DAQ). First, they will become
familiar with the components in the computer and their settings by using Measurement
and Automation Explorer. Then the students will write data acquisition programs using
both software and hardware timing. The automatic code generation and DAQ Assistant
features of LabVIEW 7 will enable the students to write these programs faster and with a
better understanding of the timing concepts, allowing them to draw conclusions about the
results of their programs.

Uses
This lab is used as an introduction to the different ways of acquiring data using a DAQ
board and LabVIEW. In addition, it also shows the difference between software and
hardware timing.

Equipment List
• Computer with LabVIEW Full Development System version 7 or
later

• Any E-Series Data Acquisition Board (i.e. NI 6052E)

• Terminal Block and Function Generator, for example the BNC-


2120, NI ELVIS, or any other connector block

• SH68-68-EP Shielded Cable or r6868 Ribbon Cable

• BNC to BNC cables

References
• Robert H. Bishop (2003), LabVIEW Student Edition, Prentic-Hall,
Upper Saddle River, NJ.

• LabVIEW Introduction Course - Six Hours.

• LabVIEW Introduction Course - Three Hours.

1
• Introduction to LabVIEW 7 and Data Acquisition (NI-DAQmx)

Student’s Portion
Introduction
In this lab, you will learn about the basics of data acquisition. Initially you explore how
the DAQ board in your computer is configured. Then, you will write three different data
acquisition programs with help from the DAQ Assistant and the automatic code
generating features found in LabVIEW 7. These programs will also help to illustrate the
difference between software and hardware timing. Finally, you will compare and
contrast the results of these programs.

Objective
• Become familiar with the data acquisition hardware in your computer.
• Learn how LabVIEW acquires data from the DAQ hardware.
• Differentiate between hardware timed, finite acquisition; hardware timed,
continuous acquisition; and software timed, on demand acquisition.

Measurement & Automation Explorer

Measurement & Automation Explorer, or MAX, is a software interface that gives you
access to all National Instruments devices connected to your system. The shortcut to
MAX is placed on the desktop during installation of NI-DAQ. MAX is used primarily to
configure and test National Instruments hardware. The functionality of MAX is divided
into five categories:

• Data Neighborhood
• Devices and Interfaces
• Scales
• Software
• IVI Drivers

2
Figure 1. Measurement and Automation Explorer

1) Data Neighborhood

Data Neighborhood contains all of the DAQmx tasks that are currently
configured. DAQmx tasks are the objects that communicate with the DAQ
hardware in LabVIEW. They can be configured in LabVIEW as well as MAX.
Data Neighborhood also provides tools for testing and reconfiguring these tasks,
as well as a utility for creating a new task.

a) DAQmx Tasks

LabVIEW 7 and NI-DAQmx center around the formation of tasks. A task can
be created in either LabVIEW or MAX and contains the relevant information
to a data acquisition such as channel, scale, and timing. By using a task the
same type of data can be collected in many different programs without
configuring the acquisition every time. In addition, a Task Control allows the
user to use many different tasks in the same LabVIEW VI enabling them to
quickly acquire different sets of data using the same program. Tasks will be
used through parts 2, 3 and 4 of this lab.

3
b) Creating a new DAQmx Task

When creating a new DAQmx task, the user is given the options of analog
input, analog output, counter input, counter output, and digital I/O. After
choosing the measurement category, the user is prompted to select the specific
type of measurement from a list. The user then selects the measurement
device and physical channel. After that the user gives the task a name to
remember. Task names are consistent between MAX and LabVIEW and their
descriptive names are easier to remember than arbitrary numbers.

When the task is given a name the creation of that task is complete. The task
configuration window then appears so that the user can specify the parameters
of the task. Options such as scale, timing and input range are all displayed
and can be edited. The task configuration window will be dealt with more
extensively later in this lab.

2) Devices and Interfaces

Devices and Interfaces displays the currently installed and detected National
Instruments hardware. Devices and Interfaces also includes utilities for both user
testing and device self tests. The three utilities that are specific to DAQ devices
are Properties, Self Test, and Test Panels.

a) Properties

Properties is a utility for configuring DAQ devices. When you launch the
Properties utility, a dialog box appears with the following tabs that you can
use to configure the DAQ devices.

• RTSI Configuration
• Accessory – In this menu the user can configure the accessories
that are attached to the DAQ device.

b) Self Test

The Self Test utility in MAX will inform the user if the computer is able to
communicate with the device. This is the lowest level of testing and trouble
shooting.

4
c) Test Panels

The Test Panel is a utility for testing the analog input, analog output, digital
I/O, and counter functionality of the DAQ device. The Test Panel is useful for
troubleshooting because it allows you to test the functionality of the device
directly from NI-DAQ. If the device does not work in the Test Panel, it will
not work in LabVIEW.

3) Scales

Scales shows you all the currently configured custom scales and provides utilities
for testing and reconfiguring those custom scales. Scales also provides access to
the DAQ Custom Scales Wizard, which allows you to create new custom scales.

a) DAQ Custom Scales Wizard

The DAQ Custom Scales Wizard is a utility that creates custom scales you
can use to determine scaling information for existing virtual channels. Each
custom scale can have its own name and description to help you identify it.

A custom scale can be one of four types: linear, map ranges, polynomial, or
table.
• Linear - A scale that uses the formula y = mx + b.
• Map Ranges – Scales values proportionally from a range of
pre-scaled values to a range of scaled values.
• Polynomial – A scale that uses the formula y = a0 + (a1 * x) +
(a2 * x2) + … + (an* xn).
• Table – A scale in which you enter the raw value and the
corresponding scaled value in a table format.

4) Software

Software shows all the currently installed National Instruments software.


The icon for each software package is also a shortcut that you can use to launch
the software. The Software category also includes a Software Update Wizard. The
purpose of the Software Update Wizard is to check if the National Instruments
software is the latest version. If the software is not the latest version, the Software
Update Agent opens the Web page on ni.com to download the latest version of the
software.

5) IVI Drivers

The IVI Drivers are used to allow software written for one instrument to be used
with other instruments using the same set of drivers. This section is beyond the
scope of this lab.

5
DAQ in LabVIEW 7

DAQ Assistant

The DAQ Assistant Express VI in LabVIEW 7 makes configuring a data


acquisition task a step by step process. It combines all the options on to a
sequence of visual panels, making it easy for the novice user or advance
programmer to configure a task quickly and efficiently. The DAQ Assistant also
allows the user to test the current configuration before inserting it into the
program to ensure that it is configured correctly. The DAQ Assistant will be used
in part 2 of this lab.

DAQmx VIs

Although the DAQ Assistant is easy to use, it does require more overhead than
using the standard DAQmx VIs. In situations where execution speed is critical,
the DAQmx VIs are the correct choice for data acquisition. In previous versions
of DAQ there were different levels of VIs with a range of difficulty for different
levels of users. Now with DAQmx, these VIs have been combined into
“Polymorphic VIs” to integrate functionality and ease of use. The idea behind
Polymorphic VIs is to use one VI for each high level function, such as reading,
writing, beginning the acquisition and ending the acquisition, and then to
configure that VI for the specific data type. This way the user always uses the
same function and does not get confused about which VI to use. An example of a
Polymorphic VI can be found in Figure 2.

Figure 2. Polymorphic VI

In Figure 2, the Task Read VI is placed on the block diagram and being
configured. The menus allow the user to pick the type of read desired. In

6
addition to being straight forward, these VIs are easy to change if the type of data
being collected is changed. The DAQmx VIs are used in parts 3 and 4 of this lab.

Automatic Code Generation

You can generate three types of code in LabVIEW from a task or channel—
Example, Configuration, or Configuration and Example.
• Example – Generates all the code necessary to run the task or channel,
such as functions/VIs needed to read or write samples.
• Configuration – Generates the code associated with the configuration. For
example, in LabVIEW, the I/O constant is replaced with a subVI that contains
Create Channel VIs, Timing VIs, Triggering VIs, and any other VIs used in
the task or channel configuration.
• Configuration and Example – Generates both Configuration Code and
Example Code for the task or channel in one step.

Generate code when you want the convenience of the Express features of
LabVIEW but want to make some modifications to the configuration or the
example code. One example of this is if you want to create a VI that could take
user input to adjust certain configuration parameters before running. By
generating the configuration code, you could easily turn some of the constants on
the Block Diagram to controls on the Front Panel. This would be especially useful
if you wanted to build an executable using Application Builder since Express VI
properties cannot be modified in an executable.

7
Lab Procedure

Part 1 DAQ Hardware configuration and testing.

In Part 1, you will become familiar with the data acquisition device inside of your
computer. This exercise also gives a detailed tour of MAX.

1. Connect the sine wave from the function generator


to analog input 0.

2. Connect analog out 0 to analog input 1.

3. Launch MAX by double-clicking the icon on the


Windows desktop.

4. Double-click the Devices and Interfaces category.


MAX searches for installed hardware and lists the National
Instruments devices found. Click on NI-DAQmx Devices. A
device number in parentheses is assigned to each device in the
system. The LabVIEW DAQ VIs use this number to specify which
device the VIs address. If the device is not listed, go to
View»Refresh.

5. Click on the DAQmx device and then click the Test


Panels button at the top of the window. The following window
appears.

8
Figure 3. Test Panel in MAX

The Analog Input tab allows you to read the analog input
channels. Make sure that the sine wave from the function
generator is connected to analog in 0. Click the Start button
with channel 0 selected. You should see the sine wave that you
are acquiring. The sine wave probably looks distorted.

6. On the Analog Input test panel, change the channel


to 1. Click the start button. You should see a steady constant
voltage near zero volts.

9
In the upper left corner of the test panel, you can see the
following three options for the Acquisition Mode:

• Continuous: continuously displays data, scrolling


as new data is acquired.
• On Demand: displays only one screen of data.
• Finite: continuously displays a screen of data at a
time

Finite and Continuous Data Modes allow you to adjust the


sample rate. The higher the sample rate, the more accurately
the graph displays the waveform.

7. Complete the following steps to make the graph look


better.
• Lower the frequency and amplitude of your
generated signal.
• On the test panel, change the Acquisition Mode
to Finite or Continuous and try different values such as
5,000, 10,000, or 15,000 for the sample rate until the graph
displays a smooth sine wave.

8. Click the Analog Output tab. In this dialog box, you


can set up a DC voltage or sine wave on one of the analog output
channels of the DAQ device. Complete the following steps to
output a DC voltage on channel 0.
• Verify that analog out 1 is connected to
analog in 2. DC Voltage should already be selected for the
Output Mode.
• Enter 5V for the DC Voltage and click Update
Channel.

9. Click the Analog Input tab. Change the channel to


2. You should now see 5 V displayed on the graph. You can make
the signal more readable by selecting Continuous for the
Acquisition Mode. If you don’t see the change, click Start.

10. Click the Counter I/O tab. Complete the following


steps to verify counter/timer operation:
• Change the Counter Mode to Edge Counting.
The counter is now set up to count the pulses of a 20MHz
onboard signal.
• Click Start. The Counter Value should increment
very rapidly.
• Click Stop to stop the counter.

10
• Change the source of the counting rate to 100 kHz
by clicking in the Edge Source box and changing the number
manually from 20 MHz to 100 kHz.
• Click Start. The Counter Value should increment
at a much lower rate.
• Click Stop to stop the counter.

12 Click the Digital I/O tab. This tab gives you access
to the eight digital lines on the device and allows you to set each
line as an input or output line.

13 Close the test panel and exit MAX.

11
Part 2 Voltmeter VI
Complete the following steps to build a VI that acquires a sine wave from a function
generator and scales it. Verify your function generator is connected to channel 0 and
set it to sine input of 500 Hz.

1. Open a new VI and build the following front panel (Figure 4).

Figure 4. Exercise 2 Front Panel

2. Place the DAQ Assistant on the Block Diagram. The DAQ Assistant
can be found under Functions >> Input >> DAQ Assistant. A window will
come up asking for the type of measurement you are taking. Choose Analog
Input >> Voltage >> Dev1/ai0 from the menus. This will allow you to take
measurements on channel 0 of Device 1 (from MAX). Name your measurement,
after which the screen shown in Figure 5 will appear.

12
Figure 5. DAQ Assistant

3. The three important parts of the DAQ Assistant configuration page are
the 1) Settings, 2) the Task Timing, and 3) Task Triggering. Set the Task
Timing to Acquire 1 Sample.
4. Under Settings >> Custom Scaling the value should be “<No
Scale>”. Click the drop down box and select Create New. The screen shown in
Figure 6 will appear.

13
Figure 6. DAQ Assistant Custom Scaling

For this lab we will amplify the sine wave by a factor of 5. Choose Linear and
enter “Amplifier” for the name of the scale.

5. In the box entitle Slope enter a value of “5”. In Scaled Units box enter
“Scaled Waveform”. Click OK to complete the scale setup.

6. Now that the input is scaled by a factor of 5, you will need to adjust the
range of the data. In the section of the DAQ Assistant configuration page labeled
Input Range, specify a range that will encompass the scaled input data. For
example, if you function generator is outputting a signal from +/- 1 V, and you
are scaling it by 5, the input range should be set to be +/- 5 V or greater. Click
OK to close the DAQ Assistant.

7. Build the Block Diagram to look similar to that shown in Figure 7. The
Time Delay VI can be found under Functions >> Execution Control >> Time
Delay.

14
Figure 7. Exercise 2 Block Diagram

1. Display the Front Panel and run the VI.

The graph displays the scaled sine wave to the screen. Vary the frequency and
notice how the signal on the screen changes.

2. Save and close the VI.

15
Part 3 Finite Acquisition VI
In this exercise, you will acquire data from one channel of your DAQ card and
display the data on the graph using the DAQmx VIs.

With a finite acquisition, LabVIEW tells the DAQ device how many points to acquire
and at what rate to acquire them. Timing then becomes the responsibility of the DAQ
device. In a finite acquisition, the DAQ device controls all aspects of the acquisition.
In contrast, with a software-timed acquisition, the computer is solely responsible for
managing the acquisition, which can be problematic if the computer suddenly cannot
give priority to the data acquisition process.

1. Open a new VI and build the following front panel (Figure 8).

Figure 8. Exercise 3 Front Panel

The DAQmx Task Name control can be found under Controls >> All Controls
>> I/O >> DAQmx Name Controls >> DAQmx Task Name.

2. Build the following block diagram (Figure 9).

16
Figure 9. Block Diagram for Exercise 3

The DAQmx VIs can be found under Functions >> All Functions >> NI
Measurements >> DAQmx Data Acquisition. The four VIs that are used in this
lab, in order, are DAQmx Timing, DAQmx Start Task, DAQmx Read, and
DAQmx Stop Task.

3. Set the DAQmx Timing VI to “Sample Clock”.

4. Set the DAQmx Read VI to “Analog, 1 Channel, 1 Sample,


Double.”

5. Save the VI as ”Finite Acquisition.vi”.

6. Switch to the Front Panel. Select the task name on the DAQmx
Task Name control that you used in Exercise 2.

7. Press the Run button. The program will acquire data at a rate of
10,000 samples per second and display the data to the screen. Because it the
number of samples is set at 10,000 this program will acquire data for one second
and return the results.

17
8. Save and close the VI.

18
Part 4 Continuous Acquire with Automatic Code Generation
Complete the following steps to build a VI that performs a
continuous acquisition operation. Instead of creating all the code
from scratch, you will use the automatic code generation features in
LabVIEW 7.
1. Open a new VI and place a DAQmx Task Name
control on the front panel.
2. Right click on the Task Name control and select New
Task (DAQ Assistant) from the drop down menu. The DAQ
Assistant will load allowing you to configure a new task. Set the
DAQ Assistant to read an analog voltage off of channel 0.
3. Set the DAQ Assistant to continuously acquire
signals. If you have closed the DAQ Assistant you can edit the
settings by right clicking on the Task Name control and selecting
Edit Task (DAQ Assistant). When you have changed the task
timing return to the front panel.
4. Now we will go through the automatic code
generation feature of LabVIEW 7. Right click on the Task Name
control and select Generate Code >> Configuration and
Example.
5. The computer will take a few moments to generate
the code. After which your Block Diagram should look similar to
the diagram shown in Figure 10.

19
Figure 10. Exercise 4 Block Diagram

6. Save the VI as ”Continuous Acquire.vi.” Save the


SubVI as “Automatically Generated.vi.”

7. Display the front panel. Run the VI and monitor the


data plotted on the graph as you change the frequency of the
input signal.

8. Save and close the VI.

Lab Report
For your lab report, email the VIs and the answers to the questions below to the
instructor no later than <date>.

Questions
1. How can the test panels in MAX be used for
debugging a program.

2. In your own words, explain the benefit of a


polymorphic style of VI.

3. What are the differences and similarities


between on-demand, finite, and continuous acquisition?

20

También podría gustarte