Skip to main content
JJohn.3
Associate III
Mar 7, 2021 6:40 PM UTC
Solved

Independent watchdog timer is not accurate

Here is my source code:

 void CLOCK(void){
 
 RCC_DeInit(); 
 
 RCC_LSICmd(ENABLE);
 
 RCC_HSEConfig(RCC_HSE_ON);
 while(RCC_WaitForHSEStartUp()==ERROR);
 
 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); 
 FLASH_SetLatency(FLASH_Latency_2); 
 
 RCC_PLL2Cmd(DISABLE);
 
 RCC_PLLCmd(DISABLE);
 RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE,RCC_PREDIV1_Div1); 
 RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_8);
 RCC_PLLCmd(ENABLE);
 
 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)!=SET);
 
 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
 
 RCC_HCLKConfig(RCC_SYSCLK_Div1);
 RCC_PCLK1Config(RCC_HCLK_Div2);
 RCC_PCLK2Config(RCC_HCLK_Div1);
 
 while (RCC_GetSYSCLKSource() != 0x08){} 
 
 
}
 
int main(){ 
 unsigned long int counter; 
 CLOCK();
 GPIOS();
 
 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
 IWDG_SetPrescaler(IWDG_Prescaler_32);
 IWDG_SetReload(500);
 IWDG_Enable();
 
 while(1)
 { 
 counter=counter+1; 
 Print(counter);
 if(counter>6553500){counter=0;}
 IWDG_ReloadCounter(); 
 }
 
}

I have set my watchdog counter to 500( .

second)(Stm32f107, LSI=40Khz,Prescale=32 ). By ignoring the "IWDG_ReloadCounter(); " (I commented //IWDG_ReloadCounter();) , this watchdog resets my MCU after about 3 seconds instead of .4 seconds. I need what my problem is.

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Mar 7, 2021 8:19 PM UTC

Is this SPL? What do those function do? Do they wait until the status register indicates the writes are finished?

Try one call of IWDG_ReloadCounter() just after IWDG_Enable(), before while(1). Does it make any difference?

JW

4 replies

Uwe Bonnes
Chief
Mar 7, 2021 7:13 PM UTC

Look in the datasheet for the tolerance of LSI. For F072 it is 30 min, 40 typ, 50 max kHz. But your error 0.4 vs 3 points to errors in your code. For me it does not make sense...

JJohn.3
JJohn.3Author
Associate III
Mar 8, 2021 2:55 AM UTC

Thank you very much for your comment.

waclawek.jan
waclawek.janBest answer
Super User
Mar 7, 2021 8:19 PM UTC

Is this SPL? What do those function do? Do they wait until the status register indicates the writes are finished?

Try one call of IWDG_ReloadCounter() just after IWDG_Enable(), before while(1). Does it make any difference?

JW

JJohn.3
JJohn.3Author
Associate III
Mar 8, 2021 2:55 AM UTC

Thank you very much, it works fine. I really appreciate your help.