Q1. I tried to capture the signal with Analog discovery2 (input) generated by Analog discovery2 (output) with the help of matlab data acquisition (DAQ) toolbox. The data capture is not reliable (sometimes captured, but not always). Please let me know the reason.
-------------------------
clear all, close all, clc
daqlist("digilent")
dq = daq("digilent")
%% Output Setting
% Add a function generator channel with device ID AD1 and channel ID 1. Set the waveform type to Sine.
ch_fgen = addoutput(dq, "AD1", "1", "Square");
% Set channel gain to 5 (sets the amplitude of the sinusoid to 5 V). Assign the gain to a variable.
gain = 4;
ch_fgen.Name = "AD1_1_fgen"
ch_fgen.Gain = gain;
% Set the signal frequency to 1 kHz
ch_fgen.Frequency = 1000;
%% Input Setting
% 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");
ch_in.Name = "AD1_1_in"
%% Sampling Frequency Setting
% Acquire data at a higher scan rate than the highest frequency in the generated waveform.
dq.Rate = 100 * ch_fgen.Frequency;
%% Generate a Periodic Waveform and Record Input
for ii=1:10
[ii 10]
[data, startTime] = read(dq, seconds(1));
%% Plot Data
period = 1/ch_fgen.Frequency;
plot(data.Time, data.AD1_1_in);
xlabel('Time in seconds');
ylabel('Voltage in volts');
title(['Period = ', num2str(period), ' seconds'])
xlim([seconds(0) seconds(5*period)]);
ylim([-gain-1 gain+1]);
disp([num2str(ii) '-th measurement is completed'])
pause
end
--------------
Q2. I also tried to use my Analog discovery2 and Analog discovery Studio simultaneously in Matlab DAQ Toolbox.
Studio for signal generation, discovery2 for DAQ. However, there is a problem in setting two devices initial stage as follows:
>>daqlist('digilent')
ans =
0×0 empty table
>> dq = daq("digilent")
Error detected using 'digilent' hardware:
Digilent devices with the following serial numbers are reserved by another program:
SN:210384AC957B. To unreserve these devices, close the application and call daqreset.
Please let me know how to do.