Watchdog is a very necessary module for embedded system. Someone said that embedded system operates without watchdog enabled just like the car without air bag. You should always enabled watchdog as possible as you can.
The PIC32MZ Watchdog Timer (WDT), when enabled, operates from the internal Low-Power RC (LPRC) Oscillator clock source which is 32.768 KHz. The WDT can be used to detect system software malfunctions by resetting the device if the WST is not cleared periodically in software. The WDT can be configured in Windowed mode or non-Windowed mode. Various WDT time-out periods can be selected using the WDT postscaler. The WDT can also be used to wake the device from Sleep or Idle mode.
At the moment, I implement the primary function of the WDT is to reset the processor in the event of a software malfunction. I enable WDT with Non-Windowed mode, and the WDT will increment until it overflows or "times out". A WDT time-out will force a device Reset, except during Sleep or Idle modes. To prevent a WDT time-out Reset, my application always periodically clear the WDT by writing a key word 0x5743 to the WDTCLEKEY (WDTCON<31:16>) through a single 16-bit write (for some other devices, or by setting the WDTCLR (WDTCON<0>).
The WDT is enabled or disabled by the device configuration bits or controlled through software by writing to the WDTCON register. In my application I just set the device configuration bits like below.
#pragma config WDTPS = PS32 // Watchdog Timer Postscaler (1:32)
#pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
#pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)
The setting as above, the postscaler of Watchdog Timer is 32. It determines the period of Watchdog Timer overflow is 32ms. The FWDTEN Configuration bit is clear, so I need enable Watchdog Timer by software, and I also need a function to clear Watchdog and call this function periodically in the main loop. Below is my implementation of them.
void Wdt_Init(void)
{
WDTCONSET = 0x8000;
}
void Wdt_Refresh(void)
{
unsigned short *pWdtClear = (unsigned short *)0xBF800800 + 1;
*pWdtClear = 0x5743;
}
上一篇:PIC32MZ tutorial -- External Interrupt
下一篇:PIC32MZ tutorial -- Output Compare
推荐阅读最新更新时间:2024-03-16 15:31
设计资源 培训 开发板 精华推荐
- 你有原创,我有豪礼!(原创精选评选第7期)
- 有奖直播|安森美先进的封装和驱动技术助力碳化硅能源应用
- 【新年乐分享】EEWORLD优秀主题/回复第18期来啦~~
- 开学季!解锁奇楼去充电,玩转幸运大抽奖~抽不中再抽
- Microchip直播|如何在ADAS系统中解决精密授时挑战
- 预约有礼:预约理想配电网络的电源完整性设计等直播,涨知识赢好礼
- Follow me第2期来袭,与得捷电子一起解锁开源硬件 Adafruit ESP32-S3 TFT Feather!
- 下载赢礼 | 雅特生 PMBus 接口非隔离数字 DC-DC 转换器
- 红外战高温,下载预测性维护手册,预约热像仪、测温仪有好礼!
- 【边分享,边成长,11月有奖】EEWORLD优秀主题/回复第16期活动开始拉