Getting Started Acquiring Data with Digilent Analog Discovery
This example shows you how to acquire voltage data at a rate of 300 kHz. The input waveform is a sine wave (10 Hz, 2 Vpp) provided by an external function generator.
Create a DataAcquisition for a Digilent Device
Discover Digilent devices connected to your system using daqlist
.
daqlist("digilent") dq = daq("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] 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 Input Channel
Add an analog input channel with device ID AD1
and channel ID 1
. Set the measurement type to Voltage
.
ch_in = addinput(dq, "AD1", "1", "Voltage");
Set DataAcquisition and Channel Properties
Set the acquisition rate to 300 kHz. The default range is -25 to 25 volts.
ch_in.Name = "AD1_1_in"
rate = 300e3;
dq.Rate = rate;
ch_in
ch_in = Index Type Device Channel Measurement Type Range Name _____ ____ ______ _______ ________________ __________________ __________ 1 "ai" "AD1" "1" "Voltage (Diff)" "-25 to +25 Volts" "AD1_1_in"
Acquire a Single Sample
Acquire a single scan on-demand, displaying the data and trigger time.
[singleReading, startTime] = read(dq)
singleReading = timetable Time AD1_1_in _____ ________ 0 sec -0.37211 startTime = datetime 21-Nov-2019 16:56:50.631
Acquire Timestamped Data
Acquire a set of clocked data for one second.
[data, startTime] = read(dq, seconds(1));
Plot Acquired Data
plot(data.Time, data.AD1_1_in); xlabel('Time (s)'); ylabel('Voltage (V)'); title(['Clocked Data Triggered on: ' datestr(startTime)]);