analog output

25
Lesson 7 will focus on learning how to write analog input programs in LabVIEW. © National Instruments Corporation 1 DAQ & SC Course Instructor Manual We will start by talking about considerations you must make when you are trying to sample an analog input signal. We will then move on to discuss some LabVIEW features that are used specifically with the DAQmx VIs.

Upload: mruet04

Post on 13-Apr-2015

50 views

Category:

Documents


2 download

DESCRIPTION

Analog output

TRANSCRIPT

Page 1: Analog Output

Lesson 7 will focus on learning how to write analog input programs in LabVIEW.

© National Instruments Corporation 1 DAQ & SC Course Instructor Manual

We will start by talking about considerations you must make when you are trying to

sample an analog input signal. We will then move on to discuss some LabVIEW

features that are used specifically with the DAQmx VIs.

Page 2: Analog Output

Before we learn how to write an analog output program in LabVIEW, we need to

© National Instruments Corporation 2 DAQ & SC Course Instructor Manual

examine the analog output architecture of our DAQ device. Most multifunction

DAQ devices have a Digital-to-Analog Converter (DAC) for each analog output

channel. All of the DACs are updated at the same time. Therefore, the output of the

analog output channels is synchronized, similar to the way analog input channels

are synchronized when we perform simultaneous sampling (see Lesson 4).

Page 3: Analog Output

During a DMA Transfer, data collected via the I/O connector is first placed in the

© National Instruments Corporation 3 DAQ & SC Course Instructor Manual

During a DMA Transfer, data collected via the I/O connector is first placed in the

onboard memory (FIFO). The mMITE arranges for the data transfer through the

PCI Bus to the pre-allocated location in the PC RAM. Applications such as

LabVIEW or Measurement Studio can then take data out of this location to

perform analysis or stream to disk.

• Remember that PCI bus is shared among different devices in the system and

it transfers data in bursts. The maximum burst rate is 32 bit x 33 MHz = 132

MB/s.

• We rely on the PCI bus bandwidth when transfer data from the data

acquisition device to the PC RAM. If the rate of data to the onboard memory

is faster than the rate of data transferred out through the PCI bus, then the

onboard memory will report an overflow. The larger the onboard memory,

the less dependency we have on the PCI bus bandwidth since we can hold

more data while waiting for the PCI bus to burst it out.

• To maximize efficiency, the mMITE transfers data through the PCI Bus in

packets of 4 Bytes each. So, at any given time, there could be at most 3 bytes

waiting to be transferred to the PC Memory.

Page 4: Analog Output

There are four selection windows used to determine the instance of the Write VI.

© National Instruments Corporation 4 DAQ & SC Course Instructor Manual

The first selection window allows you to choose the type of output:

• Analog

• Digital

• More (Raw Data)

The second selection window determines the number of channels to write to or if

the data is of the unscaled type. The third selection window allows you to choose to

output either a single sample or multiple samples. For a single sample output, the

fourth selection window will allow you to select the data to be written as either a

waveform or double value. For a multiple sample output, the fourth selection

window will allow you to select the data to be written as a waveform or an array of

double values.

Page 5: Analog Output

For a single sample output, the auto start terminal is by default set to true. This is

© National Instruments Corporation 5 DAQ & SC Course Instructor Manual

because the task state model can be entirely implicitly controlled when outputting a

single output. However, for a multiple sample output, the auto start terminal is by

default set to false. This is because additional timing must be configured when

outputting multiple samples with the DAQmx Timing VI and the DAQmx Start

Task VI and DAQmx Stop Task VI must also be used. For more information about

the DAQmx Task State Model, please refer back to Lesson 2 or ahead to Lesson 10.

Page 6: Analog Output

© National Instruments Corporation 6 DAQ & SC Course Instructor Manual

Page 7: Analog Output

Software Timed AO

© National Instruments Corporation 7 DAQ & SC Course Instructor Manual

Programming AO in LabVIEW is very similar to AI. Some of the main

differences to point out are:

1. DAQ Create Channel.vi is configured as AO instead of AI.

2. Use DAQmx write in place of DAQmx Read.

Software timing is system dependent since there is no Timing VI or Sample

Timing Type property node set.

Page 8: Analog Output

© National Instruments Corporation 8 DAQ & SC Course Instructor Manual

Page 9: Analog Output

© National Instruments Corporation 9 DAQ & SC Course Instructor Manual

Page 10: Analog Output

© National Instruments Corporation 10 DAQ & SC Course Instructor Manual

Page 11: Analog Output

Now that we know how to output a waveform, it is often important to know the

© National Instruments Corporation 11 DAQ & SC Course Instructor Manual

frequency of the waveform we are outputting. The frequency of our output

waveform will depend on two factors: the update rate, and the number of cycles of

our waveform present in the buffer. The formula we can use to calculate the

frequency of our output signal is as follows:

signal frequency = [(cycles) x (update rate)]/(points in the buffer)

We will walk through an example to illustrate how the update rate and the number

of cycles of our waveform in the buffer affect our signal frequency. Assume we

have a 1000 point buffer that holds one cycle of our waveform. If we were to

generate our signal with an update rate of 1kHz our signal frequency would be:

[(1 cycle) x (1000 points per second)]/(1000 points) = 1Hz

What would happen if we doubled the update rate and left everything else the same?

[(1 cycle) x (2000 points per second)]/(1000 points) = 2Hz

What would happen if we doubled the number of cycles in the buffer and left

everything else the same?

[(2 cycles) x (1000 points per second)]/(1000 point) = 2Hz

As you can see if we double either our update rate or our number of cycles we will

double the frequency of our output waveform.

Page 12: Analog Output

Wait Until Done.VI will return an error if the timeout value passes without all data

© National Instruments Corporation 12 DAQ & SC Course Instructor Manual

Wait Until Done.VI will return an error if the timeout value passes without all data

acquired.

Page 13: Analog Output

© National Instruments Corporation 13 DAQ & SC Course Instructor Manual

Page 14: Analog Output

© National Instruments Corporation 14 DAQ & SC Course Instructor Manual

Page 15: Analog Output

© National Instruments Corporation 15 DAQ & SC Course Instructor Manual

Page 16: Analog Output

Now that we have mastered a finite buffered acquisition, we will move on to a

© National Instruments Corporation 16 DAQ & SC Course Instructor Manual

continuous buffered acquisition. The main difference between a finite buffered

acquisition and continuous buffered acquisition is the number of points that are

acquired. With a finite buffered acquisition we acquire a set number of points.

With a continuous buffered acquisition we can acquire data continuously. The

flowchart for a continuous buffered acquisition is shown above. The flowchart is

the same as a buffered flowchart for the first three steps. We set the buffer size,

configure timing, start the task, and begin reading. At this point the continuous

buffered acquisition flowchart strays from the buffered acquisition flowchart. Since

we are acquiring data continuously we also need to be reading data continuously.

Therefore we have DAQmx Read VI in a loop. The loop is done when either an

error occurs, or the user stops the loop from the front panel. If we are not done, we

will continue to read data. If we are done we will go to DAQmx Stop Task to

unassign our resources and display any errors with either the Simple or General

Error Handler.

Page 17: Analog Output

The DAQmx Timing.vi is used to configure the Sample Clock for waveform

© National Instruments Corporation 17 DAQ & SC Course Instructor Manual

The DAQmx Timing.vi is used to configure the Sample Clock for waveform

generation. The DAQmx Is Task Done.vi is used within the while loop for

error checking.

Page 18: Analog Output

Another option for waveform generation is to use the “Use Waveform” instance of

© National Instruments Corporation 18 DAQ & SC Course Instructor Manual

the DAQmx Timing.vi. This VI uses the dt component of the waveform to

determine how often to produce samples. Dt will be the time in between samples (in

seconds). Notice the waveform is an input to the DAQmx Timing.vi to get the dt

component. Waveform generation also uses the DAQmx Is Task Done.vi inside of

the while loop to continue the generation until the stop button is pushed.

To regenerate the waveform from the board use the ‘Use Only on Board Memory’

Property Node. FIFO’s are included in the onboard memory.

Note Make sure the total number of samples contained in the Analog Output

Waveform does not exceed the size of the on-board memory of the device.

Page 19: Analog Output

The Regeneration Mode Property allows you to tell DAQmx to allow for

© National Instruments Corporation 19 DAQ & SC Course Instructor Manual

regeneration. If you allow regeneration, the samples that the device previously

generated will continue to be regenerated for as long as the task occurs. The write

marker returns to the beginning of the buffer after the device generates all samples

currently in the buffer.

If regeneration is not enables, DAQmx waits for you to write more samples to the

buffer or until a timeout occurs. If you disable regeneration, you must pay careful

attention to the timing of your generation to ensure that new data is written to the

buffer in a correct time manner.

If regeneration is enables and you write new data to the buffer, a phenomenon

known as glitching can occur – a combination of old and new data being held in the

buffer at one time.

Page 20: Analog Output

The last streaming challenge we are going to discuss deals with analog output waveform generations. Often when performing waveform generations, you will want to make an immediate update to some parameter of the waveform only to discover that your update takes much longer to appear on the output than expected. The time it takes for an update to your waveform to

© National Instruments Corporation 20 DAQ & SC Course Instructor Manual

waveform generations, you will want to make an immediate update to some parameter of the waveform only to discover that your update takes much longer to appear on the output than expected. The time it takes for an update to your waveform to actually appear on the output is known as the latency of your waveform generation and can best be understood by taking a closer look at how a typical waveform generation works.

In the example shown, the task is performing a continuous generation where the generation starts by outputting a sine wave. The task continues to output the sine wave until the user clicks the Update Waveform button. Once this button is pushed, thebuffer is updated with new data, and the waveform will change from a sine wave to a square wave. This square wave will then continue until the user stops the program.

Now let’s take a step by step look at this generation in progress. <Next Slide> In the first Write VI, the sine waveform is written to the buffer. <Next Slide> Once the Start VI is executed, the driver will first transfer enough data from the buffer to completely fill the FIFO. This step is usually called the “priming” step and is done so the generation has the best chance possible of withstanding periods of time where the PCI bus is unavailable. <Next Slide> Once the FIFO has been filled, the timing engine is started and the waveform generation begins. In this case, the user updates the buffer right away by changing from a sine wave to a square wave. Notice that upon writing the square wave, the driver waits to update the data until the current pass through the buffer has completed. Also, notice that even after the buffer has been updated with new data, it takessome time for that data to actually make its way to the output. This is because the driver must first transfer the remaining data in the buffer to the FIFO before it gets to the new data, and that data must then travel the length of the FIFO before any new data appears on the output. This makes the worst case latency of new updates (Buffer Size + FIFO Size) samples. <Next

Slide>

Since many times you want to minimize the latency from when you make a change to when it shows up on the output, there are a number of properties in the API that you can use to achieve the desired latency for your application. First, let’s talk about what each property does, and then we’ll discuss how you can combine these properties to control the overall latency of your waveform generation.

The DAQmx Write RegenMode controls whether data written to the buffer is allowed to be regenerated or not. If you want to ensure you’re always writing new data, setting the RegenMode to Do Not Allow Regeneration will cause the driver to error if your data generation out paces the ability of your application to write new data to the buffer. If you want to generate a periodic waveform, setting the RegenMode to Allow Regeneration works great because you only have to write data once, and the driver will continuously regenerate the data. This eliminates the need for your application to keep up with writes to the buffer, and you only need to scale the data once and then regenerate it.

The DAQmx Channel AO.UseOnlyOnBrdMem controls whether data for the generation is regenerated from the FIFO or whether data is continually streamed across the PCI bus. When set to true, data from the buffer is transferred exactly once to the FIFO upon starting the task and then it is regenerated from the FIFO there after. With this attribute set to true, it is not possible to update your waveform data once the generation has been started. Setting this attribute to false means data will always be transferred across the PCI bus from the buffer to the FIFO.

The DAQmx Channel AO.DataXferReqCond controls how much data is left in the FIFO before the device requests that the DMA controller writes more data. This in essence controls the effective FIFO size for your device. When set to Onboard Memory Empty, you are effectively eliminating your FIFO. This yields great latency but poor throughput performance since you can only tolerate a jitter of one sample across the PCI bus. Conversely, a setting of Onboard Memory Less Than Full yields great throughput but incurs the highest latency to updates.

Page 21: Analog Output

In the block diagram, the task is configured to prohibit the automatic regeneration

© National Instruments Corporation 21 DAQ & SC Course Instructor Manual

of data. The automatic regeneration of data has been disabled, so new data has to be

provided throughout the duration of the continuous Analog Output operation.

Page 22: Analog Output

© National Instruments Corporation 22 DAQ & SC Course Instructor Manual

Page 23: Analog Output

© National Instruments Corporation 23 DAQ & SC Course Instructor Manual

Page 24: Analog Output

1. A

© National Instruments Corporation 24 DAQ & SC Course Instructor Manual

2. Inverts the dt of the waveform to find the sampling rate

Page 25: Analog Output

3. C

© National Instruments Corporation 25 DAQ & SC Course Instructor Manual

4. B & D