How to synchronize daq data logging and daq timer events?

3 views (last 30 days)
Hello everybody,
I have a problem with synchronizing data logging and timer events. I'm working with Matlab2012a_32bit and try the following. Do daq data-logging for 0.3 seconds with a startdelay of 0.1 seconds. At the same time a timer event is scheduled each 0.5 seconds. For me it seems to be obvious that corresponding to this setup the number of timer events should be zero. But that is not the case (of course I created this example just to show that there is something wrong with the timer events). The following code produces two timer events.
if true
timerEventsPerSecond = 2;
SamplesPerSecond = 10;
recordDuration = 0.3;
delay = 0.1;
global k;
k = 0;
ai = analoginput('nidaq','Dev1');
addchannel(ai, 0);
ai.SampleRate = SamplesPerSecond;
ai.SamplesPerTrigger = recordDuration*SamplesPerSecond+1;
ai.TriggerDelay = delay;
ai.TimerPeriod = 1/timerEventsPerSecond;
set(ai,'TimerFcn',{@TimerFcn});
tic
start(ai);
wait(ai,2);
toc
[data,time,~,~] = getdata(ai);
function TimerFcn( obj,event )
global k;
k=k+1;
disp(k);
end
end
Variable time is alright and number of timer events correspond to the time measured by tic toc. Aren't timer and daq-logging using the same clock? Has anybody an idea how to solve this?
Thanks in advance for your help

Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!