Filter löschen
Filter löschen

Why I have a delay when using an external clock with a NI-DAQ (USB 6211) data acquisition board?

3 Ansichten (letzte 30 Tage)
Hi, I have this code of MATLAB for obtaining the number of counts from an Avalanche Photodiode detector with the NI-DAQ model USB 6211. I am adding an external clock to obtain the counts but when running the code it is showing but it starts with a delay and when changing the signal it has a delay also to show the changes. I would appreciate your help.
dataFocus = [];
h = animatedline();
acq_time=0.01;
N = 1;
start(dq,"Continuous")
while true
tic
dataIn= read(dq,seconds(acq_time));
timing=toc()
n0 = max(dataIn.Dev1_ctr0)-min(dataIn.Dev1_ctr0);
dataFocus = n0/acq_time;
addpoints(h,N,dataFocus);
drawnow
N=N+1;
end

Antworten (1)

Anurag Ojha
Anurag Ojha am 31 Jan. 2024
Hello Adriana,
The delay you are experiencing in your code is due to the use of the “tic” and “toc” functions. These functions measure the elapsed time between their calls, but they are not accurate for measuring small time intervals like “acq_time”. Instead, you can use the “datetime” function to get the current time and calculate the elapsed time between iterations.
Here's an updated version of your code that uses “datetime” for timing:
dataFocus = [];
h = animatedline();
acq_time = 0.01;
N = 1;
start(dq, "Continuous")
prevTime = datetime('now');
while true
dataIn = read(dq, seconds(acq_time));
currTime = datetime('now');
timing = seconds(currTime - prevTime);
prevTime = currTime;
n0 = max(dataIn.Dev1_ctr0) - min(dataIn.Dev1_ctr0);
dataFocus = n0 / timing;
addpoints(h, N, dataFocus);
drawnow
N = N + 1;
end
Refer to the following MATLAB documentation for more information:
I hope this resolves your issue.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by