timer period resolution issue

조회 수: 1 (최근 30일)
Rakesh
Rakesh 2023년 2월 7일
댓글: Rakesh 2023년 2월 11일
Hi all,
I am using MATLAB 2022b version.
I am developing a script which sends the packet at every 10 msec.
I configured the timer in free running mode with the period of 10 msec and then started storing the time stamp value in an array at each interrupt in my timer ISR.
Then plotted the difference between the time stamp values ,we are observing that the timer interrupt is varying from 7msec to 15msec.
But when the same calculations are carried out for 1sec period, we have observed that max error was 2msec .
Can you please provide me a wayout to configure the timer at 10 msec period.

답변 (2개)

Dr. JANAK TRIVEDI
Dr. JANAK TRIVEDI 2023년 2월 7일
% Start timer
t = timer('TimerFcn',@timerISR, 'Period', 10/1000, 'ExecutionMode', 'fixedRate');
start(t);
% Timer ISR function
function timerISR(~,~)
tic; % Start measuring processing time
% Code to store time stamp value in an array
processingTime = toc; % End measuring processing time
set(t,'Period',(10 - processingTime)/1000); % Adjust timer period
end
  댓글 수: 1
Rakesh
Rakesh 2023년 2월 11일
Hi Janak,
Thanks for the reply,
I have checked with the same configuration,
When the period is given in seconds , the above code works fine,
But when the same is checked for less resolution i.e. msec , I am observing this issue.
Regards,
Rakesh

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


Amal Raj
Amal Raj 2023년 2월 7일
편집: Amal Raj 2023년 2월 7일
Hi Rakesh,
You can check out timer.
ExecutionMode can be set to 'fixedRate', so that the timer generates events at a fixed rate.
  댓글 수: 1
Rakesh
Rakesh 2023년 2월 11일
Hi Amal,
Thanks for the reply,
I had set the executionmode to fixedrate only,
The above observations is with executionMode Fixedrate .

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

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by