Data Acquisition Using NI-DAQmx

advertisement
Data Acquisition Using NI-DAQmx
Wei Lin
Department of Biomedical Engineering
Stony Brook University
Instructor’s Portion
Summary
This experiment requires the student to use NI-DAQmx to acquire voltage
signals. Students should be familiar with the following LabVIEW
programming technique
1.
2.
3.
4.
NI-DAQmx
LabVIEW application for data acquisition
LabVIEW graph and chart
LabVIEW “write LabVIEW measurement file” express VI
Uses
This lecture applies to all courses of virtual instrumentation.
Equipment List

Computers

LabVIEW 8.6

NI-ELVIS benchtop workstation

LabVIEW 8, Student Version

Lecture Slides of Data Acquisition
References
Student’s Portion
Introduction
The students should learn the basic LabVIEW programming techniques
for the data acquisition using NI-DAQmx. They will create two VIs, one
1
for finite samples and the other for continuous samples. Students will use
graph and chart indicator to display acquired signals on the screen and
save the data in files for future analysis.
Objectives



NI-DAQmx Functions
Data acquisition programming using NI-DAQmx
LabVIEW graph and chart
Theory
NI-DAQmx is the next generation drivers for the data acquisition hardware
from National Instruments. It is easy to use and has many new features such
as improved ease of use, faster development time, multithreaded
measurements and increased accuracy of measurements. The data acquisition
application in LabVIEW and NI-DAQmx is quite straightforward. The
following are the steps for creating such an application.
1. Create a virtual channel and task using the NI-DAQmx Create
Virtual Channel VI.
2. Set the sampling frequency and sampling mode, continuous or
finite samples using NI-DAQmx Timing VI.
3. Set the trigger using NI-DAQmx Trigger VI. This step is optional.
4. Start the data acquisition process using NI-DAQmx Start VI.
5. Read the acquired data using NI-DAQmx Read VI.
6. Stop data acquisition task.
7. Clear the data acquisition task using the NI-DAQmx Clear VI.
All the NI-DAQmx VIs are linked through task in and task out terminal and
the error cluster chain. For continuous samples mode, the NI-DAQmx Read
VI should be placed within a while loop.
Lab Procedure
Experiment 1, Create a LabVIEW data acquisition application of
finite samples:
1.
2.
Launch LabVIEW. Create a blank VI.
Add the following to the front panel:
a. Controls: NI-DAQmx physical channel, minimum value,
maximum value, sample frequency, number of samples.
Change the representation of number of samples control to
I32.
2
b. Indicator: Waveform graph
3.
Drop the following functions to the block diagram.
a. NI-DAQmx Create Virtual Channel VI and choose “AI
voltage”.
b. NI-DAQmx timing VI and choose “Sample clock”.
c. NI-DAQmx Start Task VI
d. NI-DAQmx read VI and select “analog 1D Wfm NCha
NSamp”
e. NI-DAQmx Stop Task VI
f. NI-DAQmx Clear VI
g. Simple Error Handler VI
h. Align the VIs using alignment tool.
4.
For “NI-DAQmx Create Virtual Channel VI”, Connect the controls
of minimum value, maximum value and physical channel to the
respective terminals. Right click the “input terminal configuration”
terminal and choose “create constant”. Select “RSE” to configure the
input as referenced single ended terminal.
5.
For “NI-DAQmx timing VI” Connect controls of sampling
frequency and the number of samples to the respective terminals.
Right click the “sample mode” terminal and choose “create
constant”. Select the constant as “finite samples”. This configures
the finite sample mood. .
6.
For “NI-DAQmx read VI”, connect the control of the number of
samples to the terminal “number of samples per channel”. Connect
the output from the terminal “data” of “NI-DAQmx read VI” to the
waveform indicator.
7.
Connect the NI-DAQmx VIs through “task in” and “task out”
terminals and error cluster input and output terminals. connect the
error output of NI-DAQmx Clear VI” to the input of “Simple Error
Handler VI”
8.
Drop a “Write LabVIEW Measurement File” express VI to the block
diagram and choose “Ask user to choose file”, “Ask each iteration”,
“Overwrite file” and “one column only in X value column”. Connect
the acquired data to its input.
9.
Save the VI on your H drive.
10. Keep the ELVIS unit off. Connect the output of function generator
“FUNC OUT” to ACH0 using connection wire on the prototype
board.
11. Turn ELVIS unit on including the prototype board.
12. Launch ELVIS application and choose function generator. Select the
frequency, waveform type and amplitude of the function generator
and turn it on.
13. Enter the parameters for the controls of the LabVIEW data
acquisition controls, run the VI and save acquired signal for lab
report.
3
Experiment 2, Create a LabVIEW data acquisition application of
continuous samples:
1.
2.
3.
4.
5.
Modify the LabVIEW code of previous experiment by changing the
sample mode constant for “NI-DAQmx timing VI” to “continuous”
for continuous sampling. Remove the wire connecting the “number
of samples” control to this VI. Remove the “Write LabVIEW
Measurement File” express VI.
Replace the waveform indicator to chart indicator and add a STOP
button on the front panel.
Change the X axis scale of the chart by right clicking the chart and
choosing properties, scales. Disable auto scale of X axis. Set the
minimum as 0 and maximum as 5
Using WHILE loop to enclose the “NI-DAQmx read VI” in the
block diagram. Move the STOP button terminal into the WHILE
loop and connect it to the WHILE loop conditional terminal. Save
the VI to your H drive.
Set the frequency of ELVIS function generator to 5Hz. Run the
application as described in the previous experiment.
Lab Report
The lab report should contain the following:
1. The experiment objective
2. Explain how to write a data acquisition application using LabVIEW.
Please also describe the physical channel, virtual channel, task and
their relationship.
3. Data (collected signal)
4. LabVIEW VIs with documentation
Lab report due on 10/17/2009
Appendix
1. VI for finite data acquisition
4
2. VI for continuous data acquisition
5
Download