• No results found

Lab 2 Analog Signal Input and Output Physics 122 1-16-2018

N/A
N/A
Protected

Academic year: 2020

Share "Lab 2 Analog Signal Input and Output Physics 122 1-16-2018"

Copied!
9
0
0

Loading.... (view fulltext now)

Full text

(1)

Lab #2 - Analog-to-digital conversion and digital-to-analog conversion

Measurements, such as from a light or temperature sensor, are usually converted into voltages that one can record by computer (i.e., convert from analog to digital). The reverse process, digital to analog conversion, is useful for having a computer generate voltage signals to control devices.

We will record and generate signals using a National Instruments USB-6212

Multifunction Data Acquisition ("DAQ") card and the Labview programming language. These are frequently used in science and engineering and will allow us to practice many basic concepts.

Concepts

 Analog voltage input/output  Differential voltage measurement

 Sampling rate, software and hardware timed acquisition, buffered acquisition Background Reading

 Specifications manual for the USB-6212 card (and Glossary of terms)  DAQ M Series User Guide

 Lab exercises on Labview programming basics Additional Resources

You may also have to read the Labview help menus, trial and error, and/or ask for help. Some may find it helpful to first read some of the Labview users guides (PDF files posted on the class website).

WARNING! Follow the instructions carefully regarding electrical wiring. It is

possible to "fry" the DAQ card if you wire up something incorrectly. For example, if you connect a terminal at 5 volts to a ground terminal at 0 volts this can cause a large current to flow that can fry the card!

►► Exercise 1: Testing Analog Input with MAX

The USB-6212 card can record analog input voltages as described in the USB-6212 specifications sheet and the DAQ M Series User Guide). Before starting to write programs, it is useful to test the data acquisition card using the Measurement & Automation Explorer (called "MAX" for short), found in the Start Menu > Programs > National Instruments directory on the computer (or search for "Measurement" in the Start menu search box). This will allow us to investigate many of the card's functions.

 After running MAX you will see a menu listing "Devices and Interfaces", and when you click on this you should see "NI_DAQmx Devices" and "NI USB-6212" card listed, as shown in the screenshot below.

 Click on the "Test Pannels" button at the top of the screen and set the parameters as shown below.

If you are confused, stop and read the document "Using Test Panels in Measurement and Automation Explorer" (a PDF file published by National Instruments posted on the class website).

(2)

individually as multimeter. Differential mode is almost always the best way to measure signals. There is switch labeled as ‘FS/GS’ under AI ports. It stands for ‘Floating Source’ and ‘Ground Source’, respectively.

 Set up a bench top function generator to generate a sine wave voltage with

frequency of about 1 Hz and amplitude of about 3 volts. CAREFULLY connect the function generator and ‘AI0 by plugging coaxial wire on to the ports. ’. Don't make an improper connection to the DAQ card, such as connecting the function generator to the "+5V" terminal, or an "output" terminal that could "fry" the card.

 Click the start button on the test panel and you should see the recorded sine wave, as shown below. Change the frequency and amplitude of the sine wave and see that the changes get recorded.

Show the instructor or TA that your program works ►► Exercise 2: Testing Analog Output with MAX

The USB-6212 card can generate (output) analog signals ranging from -10 to 10 volts on two separate channels. Test this using the Measurement & Automation Explorer (MAX) program.

(3)

CAREFULLY connect the AO_0 terminals to the multimeter on your bench. Don't make an improper connection, such as allowing Positive(Red hook)(which will be set >0 volts) to touch Ground(Black)(zero volts), as this could "fry" the DAQ card

 Set output value to 1 volt and click the "Update". The multimeter should read 1 volt. Try 2 volts, etc.

 Carefully connect the AO_0 terminals to the oscilloscope on your bench. Set the mode to "Sinewave Generation", amplitude to 1 volt, and click "start". You should see the signal on the scope.

 Suppose you didn't have a scope. You could wire the analog output to the analog input (By carefully connecting AO0 to AI0. Check to see if this works.

Show the instructor or TA that your program works

►► Exercise 3: Hardware-Timed Analog Input (using Labview DAQ Assistant)

We now proceed with programming data acquisition in Labview. Run Labview and create a blank VI.

 The simplest way to program data acquisition is using the "DAQ Assistant", found under the Block Diagram menu Express > Input. It is not necessarily the most powerful way, as discussed further below, but is sufficient for many purposes. Drag the DAQ assistant onto an empty Block diagram.

 If you are confused, stop and read the help documents published by National Instruments, particularly "Labview DAQ assistant tutorial.pdf".

 A "configuration window" pops up, as shown below left. Click on "Acquire Signals", then "Analog Input", then "Voltage", then Channel "ai0". (Note options for

measuring "Temperature", "Strain", "Velocity", etc. This sounds deceptively easy because measuring anything other than voltage often requires wiring transducers and additional circuitry or using other types of DAQ cards besides the USB-6212.)  After selecting "Voltage", another configuration window pops up, as shown below.

Set Terminal configuration to "Differential", as we did when testing with MAX. Again note that, as discussed in the DAQ M Series User Manual, this is the most accurate way to measure signals. Note that, channel "ai0" reads the voltage at AI0, just as we did when using MAX.

(4)

 Click OK at the bottom of the DAQ assistant configuration window. Wire the "data" output of the DAQ assistant to a waveform graph that you create on the front panel window, as shown on right. That's it: you now have a very simple program for data acquisition.  Save all your programs (with

sensible names) and test that it

works by attaching the function generator (outputting a sine wave) to the

appropriate terminals on the DAQ connector board (as in the Exercise #1 when testing with MAX).

Show the instructor or TA that your program works

Questions to Investigate

a) How fast can you acquire data? Does it agree with the advertised specifications of the USB-6212 card? (Note that you can access the DAQ assistant configuration window by double clicking on the DAQ Assistant icon).

b) How many data points can you collect at the highest rate? (e.g., can you collect 1 million, 10 million?)

c) Reconfigure the DAQ assistant to record data from two channels "ai0" and "ai1" simultaneously. Wiring for differential input to ai1 was discussed in Exercise #1. Apply “zero volts” to the ai1 channel by simply connecting the red and black hooks together. Run the program and you should see two lines on the plot. Determine whether the maximum possible speed of data acquisition is affected by recording two channels together.

Include answers to questions (a)-(d) in your lab report.

d) Check whether the number of points recorded is really equal to the number of points specified. Hint: You can use the "statistics" function in the express palette. e) Add code to write the data to a text file (recall the function we used in Lab #1).

(5)

Show the instructor or TA that your program works

►► Exercise 4: Repeated Hardware-Timed Analog Input with Triggering (using DAQ Assistant)

Create a simple "oscilloscope" by programming Labview to do repeated analog input as follows:

 Set DAQ assistant to record 100 points at 1000 Hz and plot the data on a waveform graph

 Repeat this in a while loop. Question: how many times per second will the loop repeat? Note: depending on computer speed, Labview may or not be able to plot data at this rate. If an error occurs, you can try increasing the # points and/or decreasing the acquisition rate. Conversely, if no error occurs you can try decreasing the #points and/or increasing the acquisition rate.

 Test the program by recording a ~20 Hz sine wave from the function generator.  Note that the starting point (phase) of the wave tends to drift, causing it to "travel"

right or left on the waveform chart. This can be fixed by using “triggering”, i.e. having the computer start acquisition at the same phase, as one can with an oscilloscope. Although the USB-6212 does not have an analog trigger, it has an option for "digital triggering", meaning that acquisition can be specified to start when a digital (0 to 5 volt) transition is received at a triggering input terminal (a different terminal than the one the sine wave from the function generator will be recorded). This is configured in the "Triggering" tab and “Reference Trigger” settings in the DAQ assistant configuration window. Most function generators have a digital output (often called "TTL" or "Sync output", which is a 0 to 5 volt square wave in sync with the output sine wave) than this can be fed into the DAQ card as a trigger signal. Show that this triggers acquisition at a constant starting point on the waveform. Try changing the frequency and amplitude on the function

generator.

Show the instructor or TA that your program works

►► Exercise 5: Point-by-Point Analog Input (using DAQ Assistant)

A limitation of the N-point data acquisition in Exercise #4 is one has to wait for the whole recording period to be finished before we could see the graph. Often one would like to plot the measurements in "real time" as they are recorded. For example, if you want to record temperature once every second for an hour you wouldn't want to wait an hour before you could

see the results! One way to do it is by repeated 1-point Analog Input:

 Use the DAQ assistant configuration window (accessed by double clicking on the DAQ

(6)

Demand). In this mode, acquisition of one voltage reading will occur as soon as your program issues the command.

 Click OK at the bottom of the DAQ assistant configuration window. Make the simple Labview program shown below right that puts the DAQ assistant inside a while loop and wires its "data" output to a waveform chart (a "chart" that you create on the front panel window, not "graph"), as shown below. This tells the computer to record and plot a single voltage measurement, and repeat this as fast as it can. The chart accumulates points one by one, while keeping a history of past points. The length of the history can be set by right clicking on the chart. The chart can also be "cleared" by right clicking it while a program is running.

 Test that the program works by attaching the function generator (outputting a low frequency signal) to the appropriate terminals on the DAQ connector. Turn on “autoscaling” on the x- and y-axes by right clicking on the axes and selecting this option on the drop down menu.

Show the instructor or TA that your program works

Questions to Investigate

a) About how fast does this program acquire data? Wire up the while loop index "i" to an indicator to see how many points get acquired. Use a clock or stopwatch to figure out roughly how many points get acquired in 10 seconds. Note that the may vary for different computers, depending on the computer's speed.

b) Add code to write the data to a text file (recall the function we used in Lab #1). Does this affect the rate of data acquisition?

c) The above method of acquisition is "software timed" and is usually not very

accurate except possibly at low sampling rates. More accurately timed acquisition can be done by configuring the DAQ assistant for acquisition mode "1 sample (HW timed)", meaning "hardware timed", where the timing is controlled by circuits on the DAQ card. However, there are two caveats. Hardware timing here means that when Labview commands the card to acquire one sample with a rate of 10 Hz, the card will acquire a point and then wait 0.1 seconds. If the command is in a loop it only be allowed to repeat after 0.1 s has passed, however this does not mean Labview will be able to continue the loop instantly, especially if it is doing

something else like drawing a plot, so there will likely be a small extra delay before the next sample is acquired. Thus, the acquisition rate is not guaranteed to have a certain precision, as in N-point hardware timed acquisition, which does not involve Labview. Second, if you try to acquire single points in a loop repeatedly at a rate faster than Labview can respond, the program will crash. Note: Our DAQ card does not accept HW timed 1 sample acquisition mode

Include answers to these questions in your lab report.

►► Exercise 6: Faster Point-by-Point Analog Input (using DAQmx Functions) The DAQ assistant isn't always the best way to program the DAQ card. It is the

(7)

 To program hardware timed acquisition with DAQmx, you need three functions: "DAQmx Create Channel", "DAQmx Timing", and "DAQmx Read", as shown below. These function names are almost self-explanatory.

 If you are confused, stop and read the document "Learn 10 Functions in NI-DAQmx"(PDF file published by

National Instruments).

 The DAQmx functions are partly configured by clicking on the text box below each icon. Here, we set the Create Channel to "AI Voltage > Voltage", we set

DAQmx Timing to "Sample Clock", and set DAQmx Read to "Analog > Single Channel > Single Sample > DBL. Here DBL

refers to a "double precision floating point number".

 We have wired the program on the right to first Create Channel, then set Timing, then repeatedly Read voltages in a while loop. The "Task Out" terminal of each DAQmx function is wired to the "Task In" terminal of the next DAQmx function. Importantly, only DAQmx Read is done inside the loop. All configurations are done only once, before the reading loop starts. This makes acquisition much faster.

In fact, the program above won't run because we haven't connected all the wires

needed to configure the DAQ parameters. To see what parameters can be

configured, hover the cursor over each function icon and hit Ctrl-h to see the help window, which shows the terminals that can be wired up. Right-click each terminal for and select "create control" for each, which puts a control for each on the front panel. Use Ctrl-b to remove broken wires and "Ctrl-u" to clean up the wiring diagram:

(8)

 If you are confused, read the Labview help documents, such as "Learn 10 Functions in NI-DAQmx.pdf" (published by National Instruments).

Show the instructor or TA that your program works Questions to investigate

a) How fast can you set the acquisition rate? Is it faster than DAQ assistant? Does Labview really record data at the highest settable rate? (check using a stopwatch) b) If you add a "Write to measurement file" function (set to write a text file with only one header) how much does this slow down the acquisition rate (by the stopwatch test)?

Include answers to these questions in your lab report.

►► Exercise 7: Continuous (Buffered) Analog Input

From the last exercise, “Continuous acquisition" is a mode where the DAQ card

records continuously at a desired rate and save the data temporarily into its own memory (called "buffer memory"). The card can then be commanded by the DAQmx Read

(9)

 The Create channel function is set to "AI Voltage", Timer set to "Sample Clock", and Read to "Analog 1D DBL 1Chan NSamp", meaning it will read the specified number of samples from the memory buffer each loop.

 Note that a waveform GRAPH (not chart) is better to use as there is no need for chart history.

 Although the program below works, it is good practice to also use the DAQmx "Start" function after the "Timer", the "Stop" function after the loop ends (wire the "Read"

task terminal to the "Stop" one outside the loop) to stop the acquisition, and the DAQmx "Clear" function to reset the card (e.g. for use in a different configuration later).

 Test that the program works by reading a signal from the function generator

Show the instructor or TA that your program works Questions to Investigate

a) How many measurements per second are recorded if the program is set up as shown above?

(10)

 Modify the program to calculate the mean value of all the samples read each iteration (use the "mean.vi" function – but not other functions also containing the word

“mean”). Add code to make a green light on the front panel light up when the mean value is >1. Test that the program works by reading a signal from the function

generator and try adjusting the “offset” knob on the function generator to change the magnitude of the mean value.

Show the instructor or TA that your program works

►► Exercise 8: Analog Output (with Labview DAQ Assistant)

One often wants to generate analog voltage outputs to control devices. This can be done with the DAQ assistant in similar manner as you did for Analog Input above and we leave it as exercises for you to figure out. If you are confused, stop and read the help documents published by National Instruments, particularly "Labview DAQ assistant tutorial.pdf". Try the following:

 Program Labview to output a 1 Hz sine wave for 10 seconds consisting of 100 samples/sec using "Simulate Signal" and DAQ assistant. Test it by looking at the signal on the oscilloscope.

 Make a new program that outputs a voltage point-by-point as fast as possible that is controlled by a "pointer slide" number control on the front panel that can vary between 0 and 10 volts.

 Make a new program that outputs 10 volts and then, after a button is pressed, steps down in increments of 1 volt every second until it reaches zero volts. Show the instructor or TA that your programs work

►► Exercise 9: Analog Output Based On Analog Input

One often wants to acquire a signal and then output a different signal that depends on the acquired signal. As an exercise, write a Labview program to acquire a sine wave from the function generator and output a modified signal, as follows:

 Acquire "on demand, point-by-point" in a loop from two differential input channels with DAQ assistant. Hook up the function generator into the first one inputting a ~1 Hz sine wave. Plot the results on a waveform chart.

 Use the "split signals" function in Labview to separate off this first acquired signal. Check if the value is greater than 0.5 volt, and if so then set the value to 1 volt (i.e., limit the voltage to 1 volt).

 Use Analog Output to output this limited signal point-by-point. Test that this works by looking at the outputted signal on the oscilloscope.

Show the instructor or TA that your programs work

 Now physically wire up the DAQ output voltage signal to the 2nd analog input on the DAQ card (which Labview is plotting on the same graph as the acquired signal from the function generator). Test that this works.

 Further modify the program to put a button on the front panel labeled "invert", which inverts the output signal whenever the button is depressed (e.g., changes 0.37 volts to -0.37 volts or vice-versa)

Show the instructor or TA that your programs work Questions to Investigate

(11)

References

Related documents

Está solamente por la presencia de la tierra que el fuego puede quemar (fuego en la tierra), agua puede ser aspirada de (agua en la tierra), los cuerpos puede

28 However, on an ad hoc basis, the Comptroller has adopted some fairly narrow views of what constitutes a “direct cost”: STAR 201108182L (Aug. 2011) (“Direct labor costs for cost

One (1) analog audio ouput.. 2) Pass through to HDMI output. The input card shall be a Crestron DMC-CAT or equivalent. The UTP/STP-DSP input Card shall accept UTP/STP signal

The horizons were interpolated through series of procedures to create isomap layers and were subsequently gridded and converted to generate both time and depth structure

Lyons, et al., Sequence analysis of clonal immunoglobulin and T-cell receptor gene rearrangements in children with acute lymphoblastic leukemia at diagnosis and at relapse:

When there is a true vacancy, a School Advisory Council representative will participate actively in the interview and selection process in the same manner as any other member of

I want to congratulate all our newly certified Treasurers, Collectors and Assistants Treasurers and Collectors on passing the Certification Examination. We hope you

protruding legs of the rail (where the profile will go) and the floor. Attach the plastic rail to the base, with the long lip in the direction of the floor. This can be done in