您的位置 首页 基础

STM8L探究套件学习笔记-窗口看门狗WWDG(十七)

窗口看门狗(WWDG)通常被用来监测由外部干扰或不可预见的逻辑条件造成的应用程序背离正常的运行序列而产生的软件故障。除非递减计数器的值

窗口看门狗WWDG)通常被用来监测由外部搅扰或不行预见的逻辑条件形成的应用程序违背正常的运转序列而发生的软件毛病。除非递减计数器的值在T6位变成0前被改写,看门狗电路在到达预置的时刻周期时,会发生一个MCU复位。在递减计数器到达窗口寄存器数值之前,假如7位的递减计数器数值(在操控寄存器中)被改写,那么也将发生一个MCU复位。这表明递减计数器需要在一个有限的时刻窗口中被改写。上面说到的T6便是窗口看门狗的自减计数器的第六位(最高位)。在该计数器的T6位变为0后(小于0X40),就会引起一复位。这是窗口的下限。而当计数器的值在大雨窗口装备寄存器的窗口值之前就被修正的话,也会引起一次复位,这儿窗口值是上限。窗口值是由用户自己设定的,依据实践要求来规划窗口值,可是一定要保证窗口值大于0X40,不然窗口就不存在了
void main(void)
{
uint8_t Index;
GPIO_Init(LED3_PORT,LED3_PIN,GPIO_Mode_Out_PP_Low_Fast);
//输出低电平-高速10M
GPIO_Init(LED4_PORT,LED4_PIN,GPIO_Mode_Out_PP_Low_Fast);
//输出低电平-高速10M
GPIO_Init(KEY_PORT,KEY_PIN,GPIO_Mode_In_FL_IT);
//输入浮空-中止
/* Set PC1 sensitivity to falling edge and low level 下降沿低电平触发*/
EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling_Low);
/* Check if the MCU has resumed from WWDG reset */
if (RST_GetFlagStatus(RST_FLAG_WWDGF) != RESET)
{
/* IWDGF flag set */
/* Toggle LED3 */
for (Index = 7; Index != 0; Index–)
{
GPIO_ToggleBits(LED3_PORT,LED3_PIN);
Delay(0x7FFF);
}
/* Clear WWDGF Flag */
RST_ClearFlag(RST_FLAG_WWDGF);
}
/* WWDG configuration: WWDG is clocked by SYSCLK = 2MHz */
/* WWDG timeout is equal to 251,9 ms */
/* Watchdog Window = (COUNTER_INIT – 63) * 1 step
= 41 * (12288 / 2Mhz)
= 251,9 ms
*/
/* Non Allowed Window = (COUNTER_INIT – WINDOW_VALUE) * 1 step
= (104 – 97) * 1 step
= 7 * 1 step
= 7 * (12288 / 2Mhz)
= 43.008 ms
*/
/* So the non allowed window starts from 0.0 ms to 43.008 ms
and the alowed window starts from 43.008 ms to 251,9 ms
If refresh is done during non allowed window, a reset will occur.
If refresh is done during allowed window, no reset will occur.
If the WWDG down counter reaches 63, a reset will occur. */
WWDG_Init(COUNTER_INIT, WINDOW_VALUE);
/* enable interrupts by switching to level 0 */
enableInterrupts();
while (1)
{
/* Check if WWDG counter refresh is allowed in Allowed window */
if (AllowedRefresh != 0)
{
/* get WWDG counter value */
/* wait until WWDG counter becomes lower than window value */
while ((WWDG_GetCounter() & 0x7F) > WINDOW_VALUE);
/* Refresh WWDG counter during allowed window so no MCU reset will occur */
WWDG_SetCounter(COUNTER_INIT);
}
/* Check if WWDG counter refresh is allowed in non Allowed window */
if (NonAlowedRefresh != 0)
{
/* wait until WWDG counter becomes higher than window value */
while ((WWDG_GetCounter() & 0x7F) < WINDOW_VALUE);
/* Refresh WWDG counter during non allowed window so MCU reset will occur */
WWDG_SetCounter(COUNTER_INIT);
}
/* Toggle LED4 */
GPIO_ToggleBits(LED4_PORT,LED4_PIN);
Delay(0x6FFF);
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/jichu/260274.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部