AnsweredAssumed Answered

Problem setting reload value for independent watchdog

Question asked by dan on Jul 29, 2015
Latest reply on Jul 29, 2015 by dan

Hi all,

I am using a STM32F103 MCU and I want to set the reload value for independent watchdog (IWDG) so watchdog will reset the device (a timeout will occur) after "t" seconds. I am using the following code to initialize watchdog (for the moment I do not use LSI measurement and assume that the frequency of LSI clock is 40Khz, according to the reference manual):

void wd_init(uint32_t timeout) {
  IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);    // Enable write access to IWDG registers.
  IWDG_SetPrescaler(IWDG_Prescaler_32);            // IWDG timer clock will be (LSI / 32).
  IWDG_SetReload(timeout * LSIFreq / 32);
  IWDG_ReloadCounter();                            // Reload the IWDG counter (kick the dog for once!).
  IWDG_Enable();                                   // Enable IWDG (LSI will be enabled by hardware).
The unit of "timeout" is "seconds". The above code works fine only up to 4 seconds. I am turning on a LED whenever a reset due to the timeout happens, and up to 4 seconds, all resets are correctly happens each t seconds (t < 4s), but for values more that 4 seconds, the timeoout happens earlier and device keeps reseting however the timeout should not have happened. I have tested with LSI measurement using TIM5 CH4 (as stated in the example for IWDG) and the result is same. Is there anything that I am doing wrong?