Embedded learning window watchdog

Insert picture description here
Insert picture description here

1. From the above figure, we can know that the dog cannot be fed between the initial value of the counter and the upper limit of the window. Only feeding the dog between the upper limit and the lower limit can prevent resetting. Once it reaches 0x3f, it will reset immediately. Here When the counter reaches 0x40, we can enable an interrupt to feed the dog to prevent reset.

2. Why do you need a window watchdog:

Because the window watchdog cannot feed the dog either early or late, the program reset can only be avoided by feeding the dog within the window value set by ourselves. It reduces the possibility that the dog feeding program may be triggered by mistake due to the program running away. In addition, we can use the window watchdog to accurately detect the running of the program. For example, a program running time is 50ms. We can configure the upper limit value and the frequency division coefficient to make the window time slightly larger than 50ms, so if the program is okay, it will go. Feed the dog without resetting, if something goes wrong, it will not feed the dog and reset.

3. Window time calculation:

Upper limit value-0x40 = count the number
of times the time required to count a number: 1/(pclk1/4096/division coefficient)
Therefore, the number of counts * the time required to count a number = window time

4. Specific placement:

Note: wwdg uses the clock of pclk1

	WWDG_CNT =tr&WWDG_CNT;
	NVIC_InitTypeDef NVIC_InitStruct;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
	WWDG_SetPrescaler(fprer);
	WWDG_SetWindowValue(wr);
	WWDG_Enable(WWDG_CNT);
	WWDG_ClearFlag();
	WWDG_EnableIT();
	
	NVIC_InitStruct.NVIC_IRQChannel = WWDG_IRQn;
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStruct);

Guess you like

Origin blog.csdn.net/weixin_44142774/article/details/105983173