| Data Acquisition Toolbox | ![]() |
Example: Performing a Linear Conversion
This example illustrates how to configure the engineering units properties for an analog output object connected to a National Instruments PCI-6024E board.
The queued data consists of a 4 volt peak-to-peak sine wave. The UnitsRange property is configured so that queued data is scaled to the OutputRange property value, which is fixed at ±10 volts. This scaling utilizes the maximum dynamic range of the analog output hardware.
You can run this example by typing daqdoc6_6 at the MATLAB command line.
1. Create a device object - Create the analog output object AO for a National Instruments board. The installed adaptors and hardware IDs are found with daqhwinfo.
AO = analogoutput('nidaq',1);
2. Add channels - Add one hardware channel to AO.
chan = addchannel(AO,0);
3. Configure property values - Create the data to be queued.
freq = 2; w = 2*pi*freq; t = linspace(0,10,10000); data = 2*sin(w*t)';
Configure the sampling rate to 2 kHz, configure the trigger to repeat two times, and scale the data to cover the full output range of the D/A converter. Since the peak-to-peak amplitude of the queued data is 4, UnitsRange is set to [-2 2], which scales the output data to 20 volts peak-to-peak.
set(AO,'SampleRate',2000) set(AO,'RepeatOutput',2) set(chan,'UnitsRange',[-2 2])
Queue the data with one call to putdata.
putdata(AO,data)
4. Output data - Start AO and wait until all the data is output.
start(AO) while strcmp(AO.Running,'On') end
5. Clean up - When you no longer need AO, you should remove it from memory and from the MATLAB workspace.
delete(AO) clear AO
| Linearly Scaling the Data: Engineering Units | Starting Multiple Device Objects | ![]() |