Last week we looked at the ability of Labview to measure and display external signals. These included voltages and other physical variables which we could represent as voltages. This week we will start by looking at the other direction: using Labview to generate signals. These will also be voltages, which we can then use in their own right or transform into other physical variables.
In this Experiment we will practice signal generation techniques on a new, blank VI. When we are confident of our skills, we will use them to make improvements to the VI we built last week in Experiment 3.2.
![]() | ||
Step 1: |
Recall that the DAQ card has two analog voltage outputs:
dac0
and
dac1.
Unlike the analog inputs which have different sensitivities,
there's no real difference between these, so we'll
arbitrarily choose
dac0
for our output.
Use a BNC patch cable to connect
J1-1
to
CH 1
of the oscilloscope.
On the interface module connector strip,
connect
J1-1
(socket strip pin 1)
to
dac0
(pin 51).
| |
Step 2: |
Start Labview and open a new, blank VI.
Since we want this VI to run continuously,
go to the block diagram window and create a large while loop.
![]() | |
Step 3: |
We create D/A output blocks in nearly the same way we did
A/D input blocks, using the DAQ Assistant.
From the Functions palette, select
Output,
then
Place the resulting block inside the while loop, somewhere in the
right-hand half.
![]() | |
Step 4: |
Once it is placed, you will get a
Create New ...
wizard, just as you did with the input block in
Experiment 3.2.
This time, select
Analog Output,
then
Voltage.
From the list of Supported Physical Channels, select
ao0,
then click the
Finish
button at the bottom of the frame.
![]() | |
Step 5: |
When the DAQ Assistand dialog appears,
set the
Output Range
to have a
Max
of 10 Volts and a
Min
of -10 Volts.
Set the
Generation Mode
to
1 Sample (On Demand).
When finished, click the
OK
button.
![]() | |
Step 6: |
There will be a brief flurry of activity, the
DAQ Assistant
block will expand, and a white band containing the word
data
will appear.
![]() | |
Step 7: |
On the left-hand side of the while loop, place a numeric constant.
Set its value to 1.
![]() | |
Step 8: |
Wire the constant to the
data
input
of the D/A output block.
Our first signal generating VI is finished.
![]() | |
Step 9: |
Press Run and verify on the oscilloscope that the output is set to 1 volt. |
![]() | ||
Step 1: |
Go to the front panel and press the
Stop
button.
VIs can't be edited while they are running.
![]() | |
Step 2: |
Right click to bring up the
Controls
palette.
Move the cursor to the
Num Ctrls
button to bring up the
Numeric Controls
palette.
![]() ![]() ![]() | |
Step 3: |
Return to the block diagram and notice the orange icon labeled
Vout.
![]() ![]() | |
Step 4: |
Delete the numeric constant and the wire from the diagram.
Place the icon for the numeric control
in the left-hand half of the diagram and wire its output to
the input of the DAQ Assistant block.
![]() | |
Step 5: |
Return to the front panel and press the
Run
button.
If the numeric control still contains the default value
(zero), the signal displayed on the scope should fall to zero.
![]() | |
Step 6: |
With the VI still running, double click over the
Vout
control and type in a new value (between -10 and 10).
Press
Enter
or click the check box.
The signal on the scope should jump to the value that you
entered.
![]() | |
Step 7: |
Try typing in a few more values.
When the excitement has faded, stop the VI.
![]() | |
Step 8: |
Typing in a number is a convenient way to
precisely set a value, but for quick
changes, something like a knob
is more suitable.
Right click over the
Vout
control and select
Replace.
This will bring up a palette of objects with which this
control may be replaced.
From this palette, select
Num Ctrls,
then a
Vertical Pointer Slide.
![]() ![]() | |
Step 9: |
Start the VI.
Place the cursor over the white triangular portion of the slider,
left click, and drag the pointer up and down.
The signal on the scope should rise in fall in response.
![]() | |
Step 10: |
Change the lower limit on the slider from the default value (0)
to -10.
To do this,
double click over the number you wish to change.
This will select it and allow you to enter the new value.
You should now be able to vary the output over the full range of
-10 volts to +10 volts.
![]() | |
Step 11: |
Try replacing the slider with some of the other controls and examine their behavior. |
This should be fairly easy.
We have Labview compute the value of
at regularly
spaced values of
, then set the D/A output to that value during
the corresponding interval.
The tricky part is keeping the values of
at which we update the
output regularly spaced.
In
Part 4 of Experiment 3.2
we took samples of the A/D input value at 1 second intervals
by placing a 1 second delay block inside the while loop.
This is satisfactory for long intervals (like 1 second), but
as we try to generate more closely spaced samples
(think of that 1 kHz sine wave)
the scheduling uncertainty of Windows
will make the sample spacing very irregular.
The solution is to do the sampling in hardware, on the DAQ card, directly at the A/D or D/A converter. If we buffer a sufficient number of samples, irregularities in processing them can be smoothed out and the actual input and output values will change at consistently correct times. In order for this to work, we need to generate and process samples in blocks or buffers containing a fixed number of samples. Labview provides for this with the array data type.
![]() | ||
Step 1: |
Stop the VI.
Go to the block diagram and disconnect the slider output
from the D/A converter input.
Move the slider icon out of the way, but don't delete it;
we'll use it again a bit later.
![]() | |
Step 2: |
From the
Functions
palette,
select
Input,
then
Simulate Sig.
Place the
Simulate Signal
block to the left of the
DAQ Assistant
block and left click to place it.
In the
Configure Simulate Signal
accept the default values and click
OK
A white band labeled
Sine
will appear at the bottom of the block.
Wire the
Sine
output of this block to the
data
input of the D/A block.
Double click on the D/A block
or right click and select
Properties
from the menu.
Change the
Generation Mode
from
1 Sample (On Demand)
to
Continuous.
Click
OK
and wait for everything to settle down.
![]() | |
Step 3: |
Click
Run.
You should see a 10.1 Hz
sine wave on the oscilloscope.
![]() | |
Step 4: |
Again, it would be convenient if we could change the
parameters of the waveform (e.g. frequency or amplitude)
without having to stop the VI, edit the
Simulate Signal block, and restart.
Fortunately that's easy to do.
Stop the VI. Move the cursor over the small double arrow in the middle of the bottom edge of the Simulate Signal block. It will turn into a small black square and the cursor will become a resize arrow. ![]() ![]() | |
Step 5: |
Wire the slider output to this new input.
Edit the slider to set its range to be 0 to 100.
![]() | |
Step 6: |
Go to the front panel and start the VI.
Adjust the slider and observe that the frequency of the sine wave
changes corresponding to the position of the slider.
![]() | |
Step 7: |
You may notice that the output sine wave is initially
discontinuous and that the response to changes in the slider
position is very sluggish.
The former is caused by a lag in synchronizing the
generation and output processes and the latter
is due to the amount of buffering that Labview
provides.
We can speed things up by increasing the sample rate.
Double click on the
Simulate Signal
block.
In the
Timing
sub-panel,
set
Samples per second (Hz)
to 10000.
Restart the VI.
Things should now be a bit more responsive.
| |
Step 8: |
If you feel so inclined, place another slider (or knob) on the
front panel and use it to control the amplitude of the sine wave.
![]() | |
Step 9: |
Stop the VI and save it in a persistent location. |