Electronic – Why does the RTC generate interrupts faster than once per second

interruptsmicrocontrollerrtc

I have configured an RTC module on a uC to generate interrupts every second (~32 kHz module clock with a 0x7FFF prescaler in between the counter and the clock – I hope so, seems like ~32k is the default value, and it would be a shame if the error arises from an incorrect clock being connected to the module). However, it seems like seconds counter register is incremented every time a single assembly instruction is carried out (sometimes every two assembly instructions), thus generating interrupts at an astonishingly fast rate. What could be the cause of this behaviour? And if you were to troubleshoot it without being able to ask this question on forums like I am doing, how would you go about finding the issue?

In response to comments – RTC clock indeed may only be connected to either an internal or an external oscillators, both oscillating at ~32 kHz. The uC is an Infineon XMC series with Cortex M-4 processor. I can hardly think of any section of my code that I can post, as it's simple register configuration that (a) Enables periodic RTC events, (b) Enables SCU (System Control Unit – in charge of clocks, hibernation domain and power/reset domains, etc.) RTC periodic interrupts, (c) Configure NVIC properties. As I've noted in one of the comments; the part that confuses me the most about this problem is that the 'seconds' value seems to be correct when passed to a hyperterminal, yet the refresh rate (putty terminal is refreshed every time an interrupt is handled) is very fast – yet the seconds count seems to increment every second, meaning that the timekeeping is correct.

One more small update on the issue. Seems like the RTC timer is working correctly and even manages to keep up with real life for at least an hour when I leave it running in the background. However, what happens is the interrupt sequence gets stuck in a while loop for no particular reason – if I set up the interrupts to trigger every minute instead of every second, then the program will issue an interrupt one minute after I start running it, and then execute that interrupt over and over again, flickering the terminal very fast.

Best Answer

The interrupt flag is not cleared automatically for this particular interrupt/uC. The RTC counter works fine, however, once an interrupt is issued, if the flag is not cleared at the end of the handler routine, upon returning from exception handling, the processor will see that the flag is raised and enter the same routine again, thus putting itself in one big while loop. One of my other observations is that this is not always the case - some flags are cleared automatically, whereas others you have to clear via software.

Related Topic