SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
In normal watchdog operation, the watchdog is set up to reset the CPU if it makes it to a full count. The firmware is designed to write a 1 to the CNT_RESET bit frequently, so that the watchdog should never reach a full count unless some fault causes the firmware to stop executing properly.
Initialization of the watchdog is very simple:
TimerRegs.WDCTRL.bit.CNT_RESET = 1; //make sure counter is cleared
TimerRegs.WDCTRL.bit.WDRST_EN = 1; //Enable watchdog
TimerRegs.WDCTRL.bit.CPU_RESET_EN = 1; //Enable resetting of CPU is watchdog overflows
TimerRegs.WDCTRL.bit.PROTECT = 0; //enable protected watchdog
Then just repeat the two statements below frequently enough in the code to prevent the watchdog counter from overflowing:
TimerRegs.WDCTRL.bit.CNT_RESET = 1; //make sure counter is cleared
If a faster watchdog timeout is desired, simply write to the WD_PERIOD bitfield:
TimerRegs.WDCTRL.bit.WD_PERIOD = 2; // fast watchdog
The default value for WD_PERIOD is 0x7f, which will give an approximate 2.2second watchdog.