Setup we used:
- Using NI DAQ object callback ScansAvailableFcn with a call to read(d, ‘all’) within the callback
- Using NI DAQ object callback ScansRequiredFcn with a call to write(d, d.UserData.u) within the callback where matrix u has a fixed number of rows, n
- Before starting the DAQ we preloaded a fixed number of rows, p, to the DAQ
- We used start(d, ‘Continuous’)
- In our control loop, no faster than f Hz, we would update d.UserData.u (I do not think “no faster than f” is a hard requirement)
Parameters of concern:
- a = NI DAQ object ScansAvailableFcnCount
- r = NI DAQ object ScansRequiredFcnCount
- n = size(d.UserData.u, 1)
- p = size(preload_matrix, 1)
- f = DAQ frequency
Restrictions (that have worked for us)
- a == r && r == n (4 has worked for us. Other values may also work)
- n > f (f = 1; n = 4*f has worked for us)
- p > a
- p ~= r && ((p + r) cannot be a multiple of a)
Our theory is that these restrictions prevent the initiation of a write and the completion of a read in which either the read or the write can be disregarded by the DAQ leaving in a few possible situations.
- The DAQ misses a write cycle (to pull an additional r scans from d.UserData.u and write them to the DAQ) and before getting to the next write cycle, DAQ’s buffer runs out of scans to write and errors with “underflow” and “trigger timestamp was not received”, or
- The DAQ misses a read cycle resulting in an error “DAC (digital to analog conversion)… DAQ did not have enough time to convert all the…”