/*看门狗函数*/
void IWDG_test(void)
{
/* IWDG timeout equal to 280 ms (the timeout may varies due to LSI frequency
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz */
IWDG_SetPrescaler(IWDG_Prescaler_32); //预分频寄存器(IWDG_PR)
/* Set counter reload value to 349 */ //4*2^3=32
IWDG_SetReload(349); //重装载寄存器(IWDG_RLR) 重此值递减 喂狗时间T=40Khz/((4*2^prer )* rlr)=3.6ms
/* Reload IWDG counter */
IWDG_ReloadCounter(); //键寄存器(IWDG_KR)写入0xAAAA
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable(); //键寄存器(IWDG_KR)写入0xCCCC,启动看门狗工作
}
我看网上是这么算的:T=40Khz/((4*2^prer )* rlr)~那我写的349就应该等于3.6ms~
想请问一下这样算对么~~如果对的话请再对比一下这个void Wdt_Init(void)
{
// Enable write access to IWDG_PR and IWDG_RLR registers
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //IWDG->KR = 0x5555
// IWDG counter clock: 40KHz(LSI) / 64 = 0.625 KHz
IWDG_SetPrescaler(IWDG_Prescaler_256); //IWDG->PR = 0x06;
// Set counter reload value to 1250
IWDG_SetReload(0xfff); //IWDG->RLR =0xFFF
Red IWDG counter
IWDG_ReloadCounter(); //IWDG->KR = 0xAAAA
/ Enable IWDG (the LSI oscillator will be enabled by hardware)
IWDG_Enable(); //IWDG->KR = 0xCCCC
}
//喂狗
void Kick_Dog(void)
{
//Reload IWDG counter
IWDG_ReloadCounter(); //IWDG->KR = 0xAAAA
}
/*上面这个看门狗有 /256 26214.4 ms。即2s多一点时间没有喂狗就复位。*/
同样的算法上边不对呢~~新人求释疑!!先行谢过~~ |