Why is timer object firing at an incorrect frame rate?

조회 수: 4 (최근 30일)
James Potter
James Potter 2013년 1월 16일
I am using a timer object to try to enforce a frame rate of 25 Hz (0.04 seconds per period) for a few minutes. When I use tic/toc to see how long each 25-frame "second" takes, it is not one second. The time-per-second depends on what I have running in the TimerFcn. I have seen a string of 1.1-second "seconds", and other times there are strings of 0.92-second "seconds".
I am confused because when I use the "AveragePeriod" method, the timer always thinks it has perfect timing, and has an average period of 0.04 seconds. Even if the actual periods seem to be 10% off. Does the timer use a completely different system than the tic/toc functions?
I am running it in 'FixedRate' mode, so it should run the TimerFcn every 0.04 seconds. I have tried it with both 'drop' and 'queue' options for the BusyAction.
  댓글 수: 3
James Potter
James Potter 2013년 1월 17일
Here's how I'm defining the timer:
trialTimer = timer('ExecutionMode', 'FixedRate', 'Period', 0.04, 'TimerFcn', @RunOneFrame, 'TasksToExecute', 115*25, 'StartDelay', 0);
As an experiment, I made RunOneFrame contain almost nothing. In the Profile Viewer, timer.wait took up over 95% of the self time, so excessive computation time wasn't an issue. Using get(trialTimer, 'AveragePeriod) gave answers of 0.04 seconds, but the time measured with tic/toc (output every second) showed that 0.94 seconds was passing for each 25-frame set, instead of 1 second.
The computer is running MATLAB 2012a, with Windows XP operating system. It has 1 GB of RAM (it's a little old).
James Potter
James Potter 2013년 1월 18일
Again, the main thing that confuses me is the difference between what the timer thinks its average period is, and what the actual average period is. I don't know what would cause these to be different.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by