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

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Find more on Background and Parallel Processing in Help Center and File Exchange

Asked:

Zoe
on 10 Aug 2011

Community Treasure Hunt

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

Start Hunting!