DAQ: how to synchronize timing of background acquisition (startBackground) and other Matlab operations

4 vues (au cours des 30 derniers jours)
I acquire digital data in background using a National Instruments device.
After initiating background data acquisition, I perform other operations for which I also get the timing by using tic toc (or GetSecs from Psychtoolbox).
Is there a way to precisely align (down to milliseconds or less) the timing of the data acquired in background with the timing of the other operations?
In other words, in the example below, time_operation1 and event.TimeStamps are measured with different clocks. How can I align them?
daq.reset;
device = 'Dev1';
s = daq.createSession('ni');
addDigitalChannel(s, device,'port0/line0','InputOnly');
addAnalogInputChannel(s, device,0,'Voltage');
s.IsContinuous = true;
lh = addlistener(s,'DataAvailable',@(src,event) manageData);
startTime = tic;
startBackground(s);
% other operations here ...
a = 1; % operation1
time_operation1 = toc(startTime);
% etc ...
s.stop()
delete(lh)
function manageData(event)
global data
data = [ data;...
[event.TimeStamps, event.Data(:,1)] ];
end
Additional comments:
  • the variable event.TimeStamps(1) is always zero.
  • event.TriggerTime is a time stamp representing the absolute time the acquisition trigger occurs.
  • The function clock or now might be used to get a time stamp of the other operations and then measure time differences relative to event.TriggerTime. However, this is probably not a good approach because (from clock Matlab documentation) "The clock function is based on the system time, which can be adjusted periodically by the operating system, and thus might not be reliable in time comparison operations".
  • Even assuming that event.TriggerTime is reliable, using a single time point for aligning the timings is not enough for longer data acquisitions. The two clocks (the one of the NI device and the tic toc) are different, meaning that 1 sec will not be exactly the same for the two clocks, such that an offset of one clock over the other will build up over time.

Réponses (0)

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by