Why does MATLAB require half a second of preloaded data for continuous background generation?

I am using Data Acquisition Toolbox with an NI device and want to start continuous background generation with the following workflow:
dq = daq("ni");
start(dq, "Continuous");
write(dq, outputData);
When the initial data is too small, MATLAB returns this error:
Write at least 5000 scans to initiate background generation.
I want a practical way to determine the required initial number of scans across multiple devices, because the threshold is not known in advance for every device. I also want to understand whether this minimum applies only when continuous generation starts, or whether the same error can continue to occur after output has already started.

 Accepted Answer

For continuous generation, MATLAB requires about half a second of data to be queued before background output can begin. In practice, the required initial scan count can be estimated from the rate:
requiredScans = ceil(dq.Rate / 2);
This startup requirement applies only to continuous generation. MATLAB uses the larger initial buffer so that background buffering and callback execution can begin reliably.
For finite output, this limitation does not apply. You can write any finite number of samples, and even a small number of samples can be generated in the background as long as the session is not running in continuous mode.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!