Getting Started Generating Data with Digilent Analog Discovery
This example shows you how to generate voltage data at a rate of 300 kHz.
Discovery Devices
Discover Digilent devices connected to your system using daqlist
daqlist("digilent")
ans = 1×4 table DeviceID Description Model DeviceInfo ________ _____________________________________________ ____________________ _______________________ "AD1" "Digilent Inc. Analog Discovery 2 Kit Rev. C" "Analog Discovery 2" [1×1 daq.di.DeviceInfo]
Create a DataAcquisition for a Digilent Device
dq = daq("digilent")
dq = DataAcquisition using Digilent Inc. hardware: Running: 0 Rate: 10000 NumScansAvailable: 0 NumScansAcquired: 0 NumScansQueued: 0 NumScansOutputByHardware: 0 RateLimit: [] Show channels Show properties and methods
Add an Analog Output Channel
Add an analog output channel with device ID AD1
and channel ID 1
. Set the measurement type to Voltage
. By default, the voltage range of the output signal is -5.0 to +5.0 volts.
ch_out = addoutput(dq, "AD1", "1", "Voltage"); ch_out.Name = "AD1_1_out"
ch_out = Index Type Device Channel Measurement Type Range Name _____ ____ ______ _______ _____________________ ____________________ ___________ 1 "ao" "AD1" "1" "Voltage (SingleEnd)" "-5.0 to +5.0 Volts" "AD1_1_out"
Generate a Single Sample
Generate a single scan on-demand.
outVal = 2; write(dq, outVal);
Set DataAcquisition Properties and Define the Output Waveform
Set the output scan rate to 300 kHz.
rate = 300e3; dq.Rate = rate; % Generate a 10 Hz sine-wave for half a second. The length of the % output waveform and the specified output rate define the duration of % the waveform (totalduration = numscans / rate). f = 10; totalduration = 1; n = totalduration * rate; t = (1:n)/rate; output = sin(2*pi*f*t)';
Generate Data
write(dq, output);