Figure 3. DAQmx Create Virtual Channel

advertisement
```APLICAȚIA NR. 8
Utilizarea plăcii de achiziție NI USB-6008 pentru măsurarea frecvenței
semnalelor
The aim of this application is to describes how to measure analog frequency using the
NI USB-6008 DAQ device.
Some data acquisition cards have limited counter input capabilities. Due to limited FIFO
buffers, absence of DMA channels, and other miscellaneous reasons, some cards may
not be able to perform higher frequency measurements. A simple work around in these
cases would be to acquire the signal as an analog input, then perform some spectral
analysis. One can take the data signal from the DAQmx Read and wire it to the Tone
Measurements express VI for a numeric output of the frequency. Also, one can use the
Spectral Measurements express VI to display an FFT graph of the signal.
I. PARTEA TEORETICĂ
Some devices can measure analog frequency directly using frequency-to-voltage
circuitry. Many devices, however, only measure voltage, and you must use software
algorithms to convert those measurements to frequency.
The Nyquist Theorem states that the highest frequency you can accurately represent is
half the sampling rate. For instance, to measure the frequency of a 50 Hz signal, you
need a sampling rate of at least 100 S/s. In practice, you should use sampling rates of 5
to 10 times the expected frequencies to improve accuracy of measurements.
The Nyquist frequency is the bandwidth of the sampled signal and is equal to half the
sampling frequency. Frequency components below the Nyquist frequency appear
normally. Frequency components above the Nyquist frequency appear aliased between
0 and the Nyquist frequency. The aliased component is the absolute value of the
difference between the actual component and the closest integer multiple of the
sampling rate. For example, if you have a signal with a component at 800 Hz and you
sample at 500 S/s, that component appears aliased at 200 Hz because |800–(2 x 500)|
= 200(Hz).
One way to eliminate aliased components is to use an analog hardware filter before you
digitize and analyze the frequency information. If you want to perform all the filtering in
software, you must first sample at a rate fast enough to correctly represent the highest
frequency component the signal contains. For example, with the highest component at
800 Hz, the minimum sampling rate is 1,600 Hz, but you should sample 5 to 10 times
faster than 800 Hz. If the frequency you want to measure is around 100 Hz, you can use
a lowpass Butterworth filter with a cutoff frequency (fc) of 250 Hz to filter out frequencies
above 250 Hz and pass frequencies below 250 Hz.
For devices that cannot measure frequency directly, you need to use software
algorithms, such as the Fast Fourier Transform (FFT), to convert voltage to frequency.
LabVIEW Full and Professional Development Systems contains advanced analysis VIs
that handle these transformations.
Last years LabVIEW software made a great expansion in industrial measurement
applying and virtual instrumentation in data acquisition. LabVIEW is a graphical
programming language which combines data acquisition, analysis, and presentation
tools into one software program. We can use traditional NI-DAQ and NI-DAQmx to
measure analog frequency, each with its own application programming interface (API),
hardware configuration, and software configuration. NI-DAQmx is the latest NI-DAQ
driver with new VIs, functions, and development tools for controlling measurement
devices.
1
NI-DAQmx VIs are organized in LabVIEW under the NI Measurements palette. Here,
you can access all of the polymorphic VIs for analog, digital, and counter reads and
writes. You also can retrieve the DAQ Assistant from this location. There are also
controls and indicators for the physical channel, virtual channel and task on the front
panel.
Figure 1. NI-DAQmx Data Acquisition
Physical channel, virtual channel and task are three important definitions in the NIDAQmx. A physical channel is a terminal or pin at which an analog or digital signal can
be measured or generated. Every physical channel on a device that supports NIDAQmx has a unique name. A virtual channel is a collection of property settings that
can include a name, a physical channel, input terminal connections, the type of
measurement or generation, and scaling information. A task in NI-DAQmx is a
collection of one or more virtual channels with timing, triggering, and other properties. A
task represents a measurement or a generation of analog or digital signals. Virtual
channel and task can be created using DAQ assistant or NI-DAQmx VI.
The data acquisition hardware used in this paper is NI USB-6008 multifunction I/O
device, which interfaces to the PC through a USB connector. It has 8 differential analog
voltage inputs, 2 outputs, 12 channels which can be used as either DI or DO (configured
individually), and 12-bit resolution. The National Instruments USB-6008 provides basic
data acquisition functionality for applications such as simple data logging, portable
measurements, and academic lab experiments. The NI USB-6008 are ideal for
students. We are create our measurement application by programming the NI USB6008 using LabVIEW and NI-DAQmx driver software for Windows.
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: analog-to-digital
(A/D) conversion, digital-to-analog (D/A) conversion, digital I/O, and counter/timer
operation.
LabVIEW interacts with many kinds of real world hardware. To see what devices are
recognized by the computer, go to Start &raquo; Programs &raquo; National Instruments &raquo;
Measurement &amp; Automation and then select My System &raquo; Devices and Interfaces.
Under NI-DAQmx Devices section we see all of the devices listed, including NI USB6008.
2
Figure 2. My System Configuration
II. PARTEA PRACTICĂ
Virtual instrument for frequency measurement and spectral analysis is able to acquire a
continuous amount of data using the DAQ device's internal clock. This VI must acquire
the signal as an analog input, then perform some spectral analysis. One can take the
data signal from the DAQmx Read and wire it to the Tone Measurements express VI for
a numeric output of the frequency. Also, one can use the Spectral Measurements
express VI to display an FFT graph of the signal.
Require these steps to create block diagram:
1.Create an analog input voltage channel.
Figure 3. DAQmx Create Virtual Channel
The NI-DAQmx Create Virtual Channel function creates a virtual channel and adds it to
a task. It can also be used to create multiple virtual channels and add all of them to a
task. If a task is not specified, the function creates a task. The NI-DAQmx Create Virtual
Channel function has numerous instances. These instances correspond to the specific
type of measurement or generation the virtual channel(s) perform. The inputs to the NIDAQmx Create Virtual Channel function differ for each instance of the function.
However, certain inputs are common to most, if not all, of the function’s instances. For
example, an input is required to specify the physical channels. Additionally, analog
input, analog output, and counter operations use minimum value and maximum value
inputs to configure and optimize the measurements and generations based on the
minimum and maximum expected values of the signals. Furthermore, a custom scale
can be applied to many types of virtual channels.
- Physical Channels specifies the names of the physical channels to use to create
virtual channels. The DAQmx physical channel constant lists all physical channels on
devices and modules installed in the system. You also can wire a string that contains a
list or range of physical channels to this input.
3
- Maximum value specifies the maximum value you expect to measure.
- Minimum value specifies the minimum value you expect to measure.
2.Set the rate for the sample clock and define the sample mode to be continuous.
Figure 4. DAQmx Timing
The NI-DAQmx Timing function configures the timing for hardware-timed data
acquisition operations. This includes specifying whether the operation will be continuous
or finite, selecting the number of samples to acquire or generate for finite operations,
and creating a buffer when needed. For operations that require sample timing (analog
input, analog output, and counter), the Sample Clock instance of the NI-DAQmx Timing
function sets both the source of the sample clock, which could be an internal or external
source, and its rate. The sample clock controls the rate at which samples are acquired
or generated. Each clock pulse initiates the acquisition or generation of one sample for
each virtual channel included in the task.
- Sample rate specifies the sampling rate in samples per channel per second. If you
use an external source for the Sample Clock, set this input to the maximum expected
rate of that clock.
- Sample mode specifies if the task acquires or generates samples continuously or if it
acquires or generates a finite number of samples. Continuous Samples acquire or
generate samples until the DAQmx Stop Task VI runs.
3.Call the Start VI to start the acquisition.
Figure 5. DAQmx Start Task
This VI transitions the task to the running state to begin the measurement or generation.
- task/channels in is the name of the task or a list of virtual channels to which the
operation applies. If you provide a list of virtual channels, NI-DAQmx creates a task
automatically.
- error in describes error conditions that occur before this VI or function runs. The
default is no error. If an error occurred before this VI or function runs, the VI or function
passes the error in value to error out. If an error occurs while this VI or function runs,
the VI or function runs normally and sets its own error status in error out.
- task out is a reference to the task after this VI or function runs. If you wired a channel
or list of channels to task/channels in, NI-DAQmx creates this task automatically.
- error out contains error information. If error in indicates that an error occurred before
this VI or function ran, error out contains the same error information. Otherwise, error
out describes the error status that this VI or function produces.
4.Read the waveform data in a loop until the user hits the stop button or an error occurs.
Figure 6. DAQmx Read
4
This VI reads data from one or more channels and returns an array of data. Use the
Index Array function to access an individual channel of data.
- Samples to Read specifies the number of samples to read.
- timeout specifies the amount of time in seconds to wait for samples to become
available.
5. Use the Tone Measurement express VI to find the frequency of the signal.
Figure 7. Tone Measurement express VI
6. Use the Spectral Measurement express VI to display the FFT graph of the signal.
Figure 8. Spectral Measurement express VI
7.Call the Clear Task VI to clear the Task.
8.Use the popup dialog box to display an error if any.
Figure 9. Virtual instrument Front Panel
5
Figure 10. Virtual instrument Block Diagram
6
```