2018-05-12 06:32 AM
I just used RTC interrupt to measure msec timing. and I got some problem.
when i write naive code in interrupt there is no problem. timing is correct and no delay. the sample code is below
void RTC_IRQHandler(void)
{ val = RTC->CNTL ; dif = val - ex; msec++; if (msec >= 1000) { sec++; msec = 0; }ex = RTC->CNTL ;
}
but when i use a function to replace with the code the timing have delay almost half
void RTC_IRQHandler(void)
{ val = RTC->CNTL ; dif = val - ex; timing(); // just same with previous code.ex = RTC->CNTL ;
}
void timing()
{
msec_++;
if (msec_ >= 1000)
{
sec_++;
msec_ = 0;
}
}
to clarify, i write the two code in same time. but change nothing
void RTC_IRQHandler(void)
{ val = RTC->CNTL ; dif = val - ex; msec++; if (msec >= 1000) { sec++; msec = 0; }
timing(); // the timing is same and also has same delay
ex = RTC->CNTL ;
}
wtf? I didn't change any clock config. why this interrupt is not occur in correct timing when i use any simple function?