WDT看门狗---》嵌入式简单说
WDT看门狗
今天写写看门狗,谈谈我对看门狗的理解
首先啥是看门狗?其实就是个定时器
应用场景:有的时候一个应用会会因为外部干扰或者噪音导致设备死机,这时候我们就需要重启一下,但是人为重启不现实,因此就有了看门狗。让他看着程序,如果程序不正常运行,这个狗子就会负责重启一下。
狗子不会给我们白干活,所以就有了喂狗的概念,所谓喂狗就是给定时器赋值,狗子是个向下计数的计数器,当他到0时就需要我们喂狗,然后它继续向下计数。但是如果程序“跑飞”,死机,这时候就不会再喂狗了,狗子当然高兴,狗子不高兴就会重启设备。
数据手册是这样说的,还是和之前写的PWM那节一样,**建议你对照图片去理解下面的一段死长死长的英文文档,希望你耐心点看完。**图片在下面…
Watchdog timer is used to resume the controller operation whenever it is disturbed by malfunction such as noise and system error. It can be used as normal 16-bit interval timer to request interrupt service. The watchdog timer generates the reset signal.
Difference in usage WDT compared with PWM timer is that WDT generates the reset signal.
看门狗定时器是用来恢复控制器的运作,每当它受到故障,如噪音和系统错误干扰。它可以作为普通的16位间隔定时器来请求中断服务。看门狗定时器产生复位信号。
WDT与PWM定时器的不同之处在于WDT产生复位信号。
In the Figure below shows the functional block diagram of the watchdog timer. The watchdog timer uses only PCLK as its source clock. The PCLK frequency is prescaled to generate the corresponding watchdog timer clock, and the resulting frequency is divided again.
下图是看门狗定时器的功能框图。看门狗定时器只使用PCLK作为它的源时钟。对PCLK频率进行预处理,生成相应的看门狗定时器时钟,并将所得频率再除以。
The prescaler value and the frequency division factor are specified in the watchdog timer control (WDTCON) register. Valid prescaler values range from 0 to 28-1. The frequency division factor can be selected as 16, 32, 64 or 128.Use the following equation to calculate the watchdog timer clock frequency and the duration of each timer clock
在看门狗定时器控制(WDTCON)寄存器中指定了预调数值和频率分割因子。有效的预估值范围从0到28-1。频率分割因子可以选择为16、32、64或128。利用下列公式计算看门狗定时时钟的频率和每个定时时钟的持续时间
cycle:
周期:定时时间怎么计算,看下面图片,有例子
看门狗的寄存器相对较少,使用也比较简单,我在下面依次备注了,伪代码也在下面
1、控制寄存器
2、计数寄存器
伪代码示例:
好啦,看门狗相对简单些,如果文中有错误请各位在评论区多多指正!
喜欢的可以扫码关注松鼠哥的公众号----嵌入式简单说,我会陆续把ARM的一些外设学习心得写出来和大家分享