Why using an external clock with a NI-DAQ (USB 6211) data acquisition board is too slow?

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 it takes longer per measure I do not understand why if I am putting adquisition time of 0.01 seconds. Here I leave the code I have for now:
dataFocus = [];
acq_time=0.01;
N = 1
while true
tic
dataIn= read(dq,seconds(acq_time));
timing=toc()
n0 = max(dataIn.Dev1_ctr0);
dataFocus(N) = n0/acq_time;
if N<= 150
figure(1);
plot(dataFocus, 'Linewidth',1.5);
else
plot(dataFocus(end-150:end), 'Linewidth',1.5);
end
drawnow
N=N+1;
end
I appreciate your help,
Kind regards

5 Comments

Side note: it is not recommended to plot like that within the loop. Instead, use animatedline() with maximum points set to 150, and inside the loop use addpoints()
Is data acquisition running on dq? Have you issued a start() on it?
Thank you for your suggestion, I added start(dq) to my code before while true, but it is still showing very slow. The tic toc measures the time between the read() function and is the section of the code that it is making it slower but I do not figure it out what it is making it so slow, it shows it is 0.3 seconds per measure when it should be 0.01 seconds.
Thank you very much for your help, I changed the code with the start and it's working now with the proper time. However now it has a delay. It can be observed when starting and making changes.
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

Sign in to comment.

Answers (1)

Hi Adriana,
From the modified code you shared, the delay in real-time plotting may arise due to factors such as inefficient timing calculations and plotting operations. This problem may be address with:
  • Increased Acquisition Time: You may modify the acquisition time to consider additional time for completion like:
% Additional time for completion
delay_time = 0.005; % Modify as per your setup
dataIn = read(dq, seconds(acq_time + delay_time));
The code now reads data with a slightly longer time to ensure completion of the acquisition operation, accounting for potential variations in the device's response time.
  • Callbacks in drawnow: Real-time plotting operations can be affected by the timing of data acquisition, particularly when dealing with rapidly changing data streams. Consider optimizing the plotting process to improve performance. You may also want to refer to the documentation for `drawnow` to explore options for processing callbacks efficiently.By implementing these suggestions, you should be able to mitigate the delay issue during data acquisition and achieve more accurate counts from the APD detector. Remember to adjust the additional delay time based on your system's characteristics to optimize performance.

Products

Asked:

on 27 Jun 2022

Answered:

on 9 Feb 2024

Community Treasure Hunt

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

Start Hunting!