Why I have a delay when using an external clock with a NI-DAQ (USB 6211) data acquisition board?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Anurag Ojha
el 31 de En. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!