2022-11-08 11:03 PM
I struggled with the CMPM interrupt and made a small test programm to reproduce the bug.
To see whats going on I use an oscilloscope with 2 GPIO pins called A and B.
Pseudo Code:
LPTIM_IRQHandler()
{
setGpioA;
clearFlag_CMPM;
resetGpioA;
}
main()
{
uint16 cmpVal = 0;
Init LPTIM with 32kHz clock, update mode immediate ;
EnableLPTIM;
setAutoReload(0xffff);
enableIT_CMPM;
startCounter(Continouse mode);
while(1)
{
setGpioB;
cmpVal += 1000;
setCompare(cmpVal);
// to show the bug, we do it again ....
cmpVal += 1000;
setCompare(cmpVal);
resetGpioB;
wfi();
}
}
I would expect to get an CMPM interrupt every 2000 ticks and most the time this happens. But if an overflow of the CMP register happens at the second writting, a CMP interrupt is raised just after calling wfi();
GpioA ____/\____/\_________
GpioB _____/°°°\__/°°°\_____
If I write CMP only once, I get a interrupt every 1000 ticks even if the new CMP values is overflowed and set to a smaller value than CNT.
GpioA ____/\______ 1000 ticks _/\______ 1000 ticks _/\__
GpioB _____/°°°\____ ___/°°°\__ ___/°°°\__
I made an check in the interrupt routine as a bugfix, but I think this is ugly and I wonder why this is not mention in the errata and if someone else experienced the same.
Best regards
Armin
2022-11-09 02:17 PM
I've never used LPTIM except for "set once and let it run" periodic interrupts. But... maybe this is related to issues here
and specifically as documented in @Jeff Tenney github page (linked in that post)
2022-11-09 11:39 PM
Thanks Bob, the very last comment in your link explains the same behavior.