I am trying to run WDOG with a 20ms timeout.
I've configured the WDOG_CS for LPO clock source (128kHz) and PRES = 1, and WDOG_TOVAL = 0x000A.
That should be 10/(128,000/256) = 10/500 = 0.02s.
However, I started noticing some inconsistencies that led me to believe I am overrunning the 20ms in my SW, but the WDOG wasn't resetting me. I then instrumented my code to Set/Clear a GPIO pin to see how much time was elapsing before I refreshed the WDOG, and saw 20.67ms from refresh to refresh.
I was curious to see how long the WDOG timeout is actually set for, so I then added some dummy delays just after refreshing the WDOG that would just wait for the WDOG to reset. The Oscope showed 24ms from refresh to timeout.
I then confirmed using the CLKOUT pin that the LPO clock was indeed running at 128kHz.
Frustrated, I then switched my clock source to the SIRC and adjusted the TOVAL = 625 (625/[8MHz/256] = 625/31250 = 0.02s). Running the same test as before, I saw 20ms on the dot.
I got confused so I then reverted back to the LPO clock, but removed the prescaler. I was concerned that the low frequency was causing some sort of error. When reverting back to the LPO clock without prescaler, and setting TOVAL = 2560 (2560/128000 = 0.02s), I started to see 20ms timeouts from the WDOG.
My question is why did I see such a huge accuracy hit when using the prescaler with the LPO clock? I didn't see the accuracy hit with the SIRC using prescaler. Is there a known error when it comes to this configuration? Frequency too low?
Very confused.