Why I have a delay when using an external clock with a NI-DAQ (USB 6211) data acquisition board?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Anurag Ojha
2024-1-31
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!