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

3 ビュー (過去 30 日間)
Adriana
Adriana 2022 年 7 月 7 日
回答済み: Anurag Ojha 2024 年 1 月 31 日
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

回答 (1 件)

Anurag Ojha
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.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by