How do you control the time TimerFcn takes to perform its function?

I made the following timer to trigger a NI USB-60008 ADC device so that it pulses from zero volts to 5 volts:
t_stim = timer('TimerFcn','putsample(ao, [0 0]); putsample(ao, [5 5]); disp(''.'')', 'Period', 1/10, 'TasksToExecute', N_stimulus,'ExecutionMode', 'fixedRate');
I then start and stop t_stim within a for loop. What I want to know is whether or not there is a way to control the time TimerFcn allots to all the functions that define it? For instance, my TimerFcn here has three tasks: send a zero volts signal, send a 5 volts signal, and show a "." on the screen for each task executed.
My ideal is to have is to have it split 50% between 0 and 5 volts... and have the "." done in little to no time ;)
Thank you,
Zoe

 采纳的回答

You could do something like define a slowputsample function which appears to take T duration to complete.
function slowputsample(ao, val, T)
tic
putsample(ao, val);
while toc < T
end
end
then change your callback to be something like:
'slowputsample(ao, [0 0], 0.05); slowputsample(ao, [5 5], 0.05); disp(''.'')'
Where 0.05 seconds is so much longer than the time it takes disp('.') to complete that you should not notice it. You could of course make 0.05 be anything you want.

1 个评论

Thank you! It works great, and now I know how to make use of a home made function within the timer function.
Cheers,
Zoe

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Background and Parallel Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by