• 0

Setting Multiple devices in Matlab Data Acquisition Toolbox


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

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'])



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:


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.

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @phillcau,

I have moved your question to a more appropriate section of the Forum.

Could you explain a bit more what you mean by "data capture is not reliable"? Are you saying that during an acquisition that some of the data samples are dropped or missed in the middle of the acquisition, or just at the end? I believe the sample rate within Matlab is also somewhat limited to my understanding, so that might be an issue here depending on the sample rate you are using (looks like 100 kHz based on your Matlab code)?


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now