+ 巩固系统稳定性---看门狗
时间:10-02
整理:3721RD
点击:
为了增加系统的运行稳定性,看门狗是必不可少的。在系统运行以后也就启动了看门狗的计数器,看门狗就开始自动计数,如果到了一定的时间还不去清看门狗,那么看门狗计数器就会溢出从而引起看门狗中断,造成系统复位,所以在使用有看门狗的芯片时要注意清看门狗。
以官方例程为例
初始化看门狗的程序如下
这个地址的确定在数据手册中。

TimerConfigure函数的原型为:
其中主要设置了TMR_TGCR寄存器,设为看门狗模式

TimerPeriodSet函数的原型为:
主要设置定时器的周期为
定时时间为5秒.
包括看门狗定时器(定时器 / 计数器 1)的时钟来源于 PLL 旁路时钟,即 晶体振荡器的时钟 24MHz。
TimerWatchdogActivate函数的原型为:
对TMR_WDTCR寄存器的配置:

而这些寄存器的偏移量在手册中

以上就是看门狗的配置流程。
以官方例程为例
初始化看门狗的程序如下
- void TimerWatchDogInit(void)
- {
- // 配置 定时器 / 计数器 1 为 看门狗模式
- TimerConfigure(SOC_TMR_1_REGS, TMR_CFG_64BIT_WATCHDOG);
-
- // 设置周期 64位
- TimerPeriodSet(SOC_TMR_1_REGS, TMR_TIMER12, TMR_PERIOD_LSB32);
- TimerPeriodSet(SOC_TMR_1_REGS, TMR_TIMER34, TMR_PERIOD_MSB32);
- // 使能看门狗定时器
- TimerWatchdogActivate(SOC_TMR_1_REGS);
- }
- #define SOC_TMR_1_REGS (0x01C21000)
这个地址的确定在数据手册中。

TimerConfigure函数的原型为:
- void TimerConfigure(unsigned int baseAddr, unsigned int config)
- {
- /*
- ** Set the timer control register. This will only affect the clock
- ** selection bits. All other fields will be reset and the timer counting
- ** will be disabled.
- */
- HWREG(baseAddr + TMR_TCR) = (config & (TMR_TCR_CLKSRC12 | TMR_TCR_CLKSRC34));
- /* Clear the Timer Counters */
- HWREG(baseAddr + TMR_TIM12) = 0x0;
- HWREG(baseAddr + TMR_TIM34) = 0x0;
- /* Clear the TIMMODE bits and Reset bits */
- HWREG(baseAddr + TMR_TGCR) &= ~( TMR_TGCR_TIMMODE | TMR_TGCR_TIM34RS |
- TMR_TGCR_TIM12RS);
- /*
- ** Select the timer mode and disable the timer module from Reset
- ** Timer Plus features are enabled.
- */
- HWREG(baseAddr + TMR_TGCR) |= (config &
- (TMR_TGCR_TIMMODE | TMR_TGCR_TIM34RS |
- TMR_TGCR_TIM12RS | TMR_TGCR_PLUSEN));
- }
其中主要设置了TMR_TGCR寄存器,设为看门狗模式

TimerPeriodSet函数的原型为:
- void TimerPeriodSet(unsigned int baseAddr, unsigned int timer,
- unsigned int period)
- {
- if(TMR_TIMER12 & timer)
- {
- /* Write the period for Timer12 */
- HWREG(baseAddr + TMR_PRD12) = period;
- }
- if(TMR_TIMER34 & timer)
- {
- /* Write the period for Timer34 */
- HWREG(baseAddr + TMR_PRD34) = period;
- }
- }
主要设置定时器的周期为
- #define TMR_PERIOD_LSB32 (0x07270E00)
定时时间为5秒.
包括看门狗定时器(定时器 / 计数器 1)的时钟来源于 PLL 旁路时钟,即 晶体振荡器的时钟 24MHz。
TimerWatchdogActivate函数的原型为:
- void TimerWatchdogActivate(unsigned int baseAddr)
- {
- /* Enable the watchdog timer. Write the keys in the order */
- HWREG(baseAddr + TMR_WDTCR) = ((TMR_WDTCR_WDEN | TMR_WDTCR_WDFLAG) |
- (WDT_KEY_PRE_ACTIVE << TMR_WDTCR_WDKEY_SHIFT));
- HWREG(baseAddr + TMR_WDTCR) = ((HWREG(baseAddr + TMR_WDTCR) &
- (~TMR_WDTCR_WDKEY)) |
- (WDT_KEY_ACTIVE << TMR_WDTCR_WDKEY_SHIFT));
-
- }
对TMR_WDTCR寄存器的配置:

而这些寄存器的偏移量在手册中

以上就是看门狗的配置流程。
广告吧 还是 看着不错
不是广告,小编是6748试用者里的大神
在线调试的时候看门狗是不是要影响复位?
调试时肯定要关看门狗的。要不总是复件,没法调试
,我当时就是开了看门狗,在线调试,想想真傻!
好
