Chapter 6 One-Stop Single-Point Acquisition. NI LabVIEW Data Acquisition Basics

Add to My manuals
331 Pages

advertisement

Chapter 6 One-Stop Single-Point Acquisition. NI LabVIEW Data Acquisition Basics | Manualzz

6

One-Stop Single-Point

Acquisition

This chapter shows you how to acquire one data point from a single channel and then one data point from each of several channels using LabVIEW.

Single-Channel, Single-Point Analog Input

A single-channel, single-point analog input is an immediate, nonbuffered operation. In other words, the software reads one value from an input channel and immediately returns the value to you. This operation does not require any buffering or timing. You should use single-channel, single-point analog input when you need one data point from one channel.

An example of this would be if you periodically needed to monitor the fluid level in a tank. You can connect the transducer that produces a voltage representing the fluid level to a single channel on your DAQ device and initiate a single-channel, single-point acquisition whenever you want to know the fluid level.

For most basic operations, use the AI Sample Channel VI, located in the Functions»DAQ»Analog Input palette. The Easy Analog Input VI,

AI Sample Channel, measures the signal attached to the channel you

specify on your DAQ device and returns the scaled value. Figure 6-1 shows

how to wire this VI.

Figure 6-1. AI Sample Channel VI

© National Instruments Corporation 6-1

LabVIEW Data Acquisition Basics Manual

Chapter 6 One-Stop Single-Point Acquisition

Note If you set up your channel in the DAQ Channel Wizard, you do not need to enter the device or input limits. Instead, enter a channel name in the channel input, and the value returned is relative to the physical units you specified for that channel in the DAQ Channel

Wizard. If you specify the input limits, they are treated as being relative to the physical units of the channel. LabVIEW ignores the device input when channel names are used.

This principle applies throughout this manual.

Figure 6-2 shows how you program the Acquire 1 Point from 1 Channel VI,

located in labview\examples\daq\anlogin\anlogin.llb

, using the

AI Sample Channel VI to acquire data.

Figure 6-2. Acquiring Data Using the Acquire 1 Point from 1 Channel VI

The Acquire 1 Point from 1 Channel VI initiates an A/D conversion on the

DAQ device and returns the scaled value as an output. The high limit is the highest expected level of the signals you want to measure. The low limit is the lowest expected level of the signals you want to measure. If you want

to acquire multiple points from a single channel, see Chapter 7, Buffering

Your Way through Waveform Acquisition .

Single-channel acquisition makes acquiring one channel very basic, but what if you need to take more than one channel sample? For example, you might need to monitor the temperature of the fluid as well as the fluid level of the tank. In this case, two transducers must be monitored. You can monitor both transducers using a multiple-channel, single-point acquisition in LabVIEW.

LabVIEW Data Acquisition Basics Manual

6-2 www.natinst.com

Chapter 6 One-Stop Single-Point Acquisition

Multiple-Channel Single-Point Analog Input

With a multiple-channel, single-point read (or scan), LabVIEW returns the value on several channels at once. Use this type of operation when you have multiple transducers to monitor and you want to retrieve data from each transducer at the same time. Your DAQ device executes a scan across each of the specified channels and returns the values when finished. Refer to

Appendix B, Hardware Capabilities, in the LabVIEW Function and VI

Reference Manual, for the number of channels your device can scan at one time. You also can refer to the LabVIEW Online Reference, available by selecting Help»Online Reference.

The Easy I/O VI, AI Sample Channels, acquires single values from multiple channels. The AI Sample Channels VI performs a single A/D conversion on the specified channels and returns the scaled values in a

1-dimensional (1D) array. The expected range for all the signals, specified

by high limit and low limit inputs, applies to all the channels. Figure 6-3

shows how to acquire a signal from multiple channels with this VI.

Note Remember to use commas to delimit individual channels in the channel string. Use a colon to indicate an inclusive list of channels.

Figure 6-3. Acquiring a Voltage from Multiple Channels with the AI Sample Channels VI

You can benefit from using the Easy Analog Input VIs because you only need one icon in your diagram to perform the task, there are only a few basic inputs to the VIs, and the VIs have built-in error checking. However, the lack of programming flexibility with these VIs can be a limitation.

Because Easy VIs have only a few inputs, you cannot implement some of the more detailed features of DAQ devices, such as triggering or interval scanning. In addition, these VIs always reconfigure at start-up. When you need a high-speed or efficiently run program, these configurations can slow down processing time.

© National Instruments Corporation 6-3

LabVIEW Data Acquisition Basics Manual

Chapter 6 One-Stop Single-Point Acquisition

When you need speed and more efficiency, use the Intermediate VIs, which configure an acquisition only once and then continually acquire data without re-configuring. The Intermediate VIs also offer more error handling control, more hardware functionality, and efficiency in developing your application than the Easy VIs. You typically use the Intermediate VIs to perform buffered acquisitions. You can read more about buffered

acquisitions in Chapter 7, Buffering Your Way through Waveform

Acquisition . The Intermediate Analog Input VI, AI Single Scan VI, does

multiple-channel, single-point acquisitions, as shown in Figure 6-4.

Figure 6-4. The AI Single Scan VI Help Diagram

The AI Single Scan VI returns one scan of data. You can also use this VI to read only one point if you specify one channel. Use this VI only in conjunction with the AI Config VI.

Figure 6-5 shows a simplified block diagram for non-buffered applications.

LabVIEW calls the AI Config VI, which configures the channels, selects the input limits (the high limit and low limit inputs in the Easy VIs), and generates a taskID. The program passes the taskID and the error cluster to the AI Single Scan VI, which returns the data in an array (one point for each channel specified).

Figure 6-5. Using the Intermediate VIs for a Basic Non-Buffered Application

LabVIEW Data Acquisition Basics Manual

6-4 www.natinst.com

Chapter 6 One-Stop Single-Point Acquisition

Figure 6-6 shows how you can program the AI Config and AI Single

Scan VIs to perform a series of single scans by using software timing

(a While Loop) and processing each scan. This example shows the

Cont Acquire&Chart (immediate) VI, which you can find in labview\examples\daq\anlogin\anlogin.llb

.

The advantage to using the intermediate-level VIs is that you do not have to configure the channels every time you want to acquire data as you do when using the Easy VIs. To call the AI Config VI only once, put it outside of the While Loop in your program. The AI Config VI configures channels, selects a high/low limit, and generates a taskID. Then, the AI Config VI passes the taskID and error cluster into the While Loop, where LabVIEW calls the AI Single Scan VI to retrieve a scan. The program then passes the returned data to the My Single-Scan Processing VI. With this VI, you can program whatever processing needs your application calls for, such as looking for a limit to be exceeded. The VI then passes the data through the build array function to a waveform chart for display on the front panel.

The Wait Until Next ms Multiple (metronome) function controls the loop timing. You enter a scan rate, the application converts the value into milliseconds and passes the converted value to the Wait Until Next ms

Multiple function. The loop then executes at the rate of scanning. The loop ends when you press the stop button or an when error occurs. Once the loop finishes, the Simple Error Handler VI displays any errors that occurred.

Figure 6-6. The Cont Acq&Chart (Immediate) VI Block Diagram

The previous examples use software-timed acquisition. With this type of acquisition, the CPU system clock controls the rate at which you acquire data. Your system clock can be interrupted by user interaction, so if you do not need a precise acquisition rate, use software-timed analog input.

© National Instruments Corporation 6-5

LabVIEW Data Acquisition Basics Manual

Chapter 6 One-Stop Single-Point Acquisition

Using Analog Input/Output Control Loops

When you want to output analog data after receiving some analog input data, use analog input/output (I/O) control loops. With control loops, this process is repeated over and over again.

The single-point analog input and output VIs support several analog

I/O control loops at once because you can acquire analog inputs from several different channels in one scan, and write all the analog output values with one update. You perform a single analog input call, process the analog output values for each channel and then perform a single analog output call to update all the output channels.

The following sections describe the two different types of analog I/O control loop techniques: software-timed and hardware-timed analog I/O.

Using Software-Timed Analog I/O Control Loops

With software-timed analog control loops the analog acquisition rate and subsequent control loop rate are controlled by a software timer such as the

Wait Until Next ms Multiple timer. The acquisition is performed during each loop iteration when the AI Single Scan VI is called and the control loop is executed once for each time interval. Your loop timing can be interrupted by any user interaction, which means your acquisition rate is not as consistent as that which can be achieved through hardware-timed control loops. Generally, if you do not need a precise acquisition rate for your control loop, software timing is appropriate.

Besides user interaction, a large number or large-sized front panel indicators, like charts and graphs, affect control loop rates. Refreshing the monitor screen interrupts the system clock, which controls loop rates.

Therefore, you should keep the number of charts and graphs to a minimum when you are using software-timed control loops.

An example of software-timed control loops is the Analog IO Control Loop

(immed) VI located in labview\examples\daq\anlog_io\ anlog_io.llb

.

LabVIEW Data Acquisition Basics Manual

6-6 www.natinst.com

Chapter 6 One-Stop Single-Point Acquisition

The following diagram shows how to perform software-timed analog I/O using the AI Read One Scan and AO Write One Update VIs.

Figure 6-7. Software-Timed Analog I/O

The AI Read One Scan VI configures your DAQ device to acquire data from analog input channels 0 and 1. Once your program acquires a data point from channels 0 and 1, it performs calculations on the data and outputs the results through analog output channels 0 and 1. Because the iteration count is connected to the AI Read One Scan and AO Write One

Update VIs, the application configures the DAQ device for analog input and output only on the first iteration of the loop. The loop rate as well as the acquisition rate is specified by loop rate. The reason why the actual

loop period is important is because user interaction affects the loop and acquisition rate. For example, pressing the mouse button interrupts the system clock, which controls the loop rate. If your analog acquisition rate for control loops does not need to be consistent, then use software-timed control loops.

For more control examples, refer to the VIs located in examples\daq\solution\control.llb

.

Using Hardware-Timed Analog I/O Control Loops

For more precise timing of your control loops, and more precise analog input scan rate, use hardware-timed control loops.

An example of hardware-timed, non-buffered control loops is the Analog

IO Control Loop (hw timed) VI located in labview\examples\daq\ anlog_io\anlog_io.llb

.

© National Instruments Corporation 6-7

LabVIEW Data Acquisition Basics Manual

Chapter 6 One-Stop Single-Point Acquisition

With hardware-timed control loops, your acquisition is not interrupted by user interaction. Hardware-timed analog input automatically places the data in your DAQ device FIFO buffer at an interval determined by the analog input scan rate. You can synchronize your control loop diagram to this precise analog input scan rate by repeatedly calling the AI Single

Scan VI to read the oldest data in the FIFO buffer.

The AI Single Scan VI returns as soon as the next scan has been acquired by the DAQ device. If more than one scan is stored in the DAQ device FIFO buffer when the AI Single Scan VI is called, then the LabVIEW diagram was not able to keep up with the acquisition rate. You can detect this by monitoring the data remaining output of the AI Single Scan VI. In other words, you have missed at least one control loop interval. This indicates that your software overhead is preventing you from keeping up with your

hardware-timed loop rate. In Figure 6-8, the loop too slow Boolean

indicator is set to TRUE whenever this occurs.

Figure 6-8. Analog IO Control Loop (HW-Timed) VI Block Diagram

In this diagram, the AI Config VI configures the device to acquire data on channels 0 and 1. The application does not use a buffer created in CPU memory, but instead uses the DAQ device FIFO buffer. input limits (also known as limit settings) affects the expected range of the input signals. For

more information on input limits (limit settings), refer to Chapter 3, Basic

LabVIEW Data Acquisition Concepts . The AI Start VI begins the analog

LabVIEW Data Acquisition Basics Manual

6-8 www.natinst.com

Chapter 6 One-Stop Single-Point Acquisition acquisition at the loop rate (scan rate) parameter. On the first iteration of the loop, the AI Single Scan VI reads the newest data in the FIFO buffer.

Some data may have been acquired between the execution of the AI Start and the AI Single Scan VIs. On the first iteration of the loop, the application reads the latest data acquired between the AI Start and the AI Single Scan

VIs. On every subsequent iteration of the loop, the application reads the oldest data in the FIFO buffer, which is the next acquired point in the FIFO buffer.

If more than one value was stored in the DAQ device FIFO buffer when you read it, your application was not able to keep up with the control loop acquisition and you have not responded with one control loop interval. This eventually leads to an error condition, which makes the loops complete.

After the application completes analog acquisition and generation, then the

AI Clear VI clears the analog input task.

Figure 6-8 also includes a waveform chart in the control loop. This reduces

your maximum loop rate. You can speed up the maximum rate of the control loop by removing this graph indicator.

You easily can add other processing to your analog I/O control loop by putting the analog input, control loop calculations and analog output in the first frame of a sequence inside the loop, and additional processing in subsequent frames of the sequence. Keep in mind that this additional processing must be less than your control loop interval. Otherwise, you will not be able to keep up with your control loop rate.

Improving Control Loop Performance

There are some performance issues you should take into account if you plan to have other VIs or loops execute in parallel with your hardware-timed control loop. When you call the AI Single Scan VI in a hardware-timed control loop, the VI waits until the next scan is acquired before returning, which means that the CPU is waiting inside the NI-DAQ driver until the scan is acquired. Consequently, if you try to run other LabVIEW VIs or while loops in the same diagram in parallel with your hardware-timed control loop, they may run more slowly or intermittently. You can reduce this problem by putting a software delay, with the Wait (ms) VI, at the end of your loop after you write your analog output values. Your other

LabVIEW VIs and loops can then execute during this time.

Another good technique is to poll for your analog input without waiting in the driver. You can set the AI Single Scan VI time limit in sec to 0 . Then, the VI reads the DAQ Device FIFO buffer and returns immediately, regardless of whether the next scan was acquired. The AI Single Scan VI

© National Instruments Corporation 6-9

LabVIEW Data Acquisition Basics Manual

Chapter 6 One-Stop Single-Point Acquisition

scaled data output array is empty if the scan was not yet acquired. Poll for your analog input by using a Wait (ms) or Wait Until Next ms Multiple function together with the AI Single Scan VI in a While Loop within your control loop diagram. Set the wait time smaller than your control loop interval (at least half as small). If the scaled data output array is not empty, exit the polling loop passing out the scaled data array and execute the rest of your control loop diagram. This method does not return data as soon as the scan has been acquired, as in the example described previously, but provides ample time for other VIs and loops to execute. This method is a good technique for balancing the CPU load between several loops and VIs running in parallel.

For more control examples, refer to the VIs located in examples\daq\ solution\control.llb

.

LabVIEW Data Acquisition Basics Manual

6-10 www.natinst.com

advertisement

Related manuals

Download PDF

advertisement

Table of contents