The watchdog timer is an important device in the embedded system , which is used to develop reliable products. Most of the embedded systems need to be self-reliant in order to restart and restore the system if any software bug disturbs the system. It is not always possible for human operators to wait for rebooting the system for every software problem. The watchdog timer is a piece of hardware that provides ultimate solutions for the real-time industries, which used to detect system abnormalities automatically and to reset the processor.
The watchdog timer is a simple electronic device that is responsible to resetting the microcontroller or microprocessor for invalid software status. Generally a microcontroller is programmed with software that contains several loops and number of subroutines that direct variety of activities. If any reason, if the loop is fail to execute, then it finds and resets the device at starting or top of the loop.
Watchdog Timer Circuit
The watchdog timer is a simple counter that gives pulses to restart the MCU. This timer in an embedded system consists of separate clock frequency based on the MCU to generate the clock pulses by setting the time through the WDTCSR register.
The output of the watchdog timer is given directly to the microcontroller reset signal. Whenever the watchdog counter register is not get cleared, then it immediately forces to restart the microprocessor or controller. For example the AVR microcontroller watchdog timer frequency is 128KHz.
The watchdog timer is closely interfaced to the microcontroller unit. In this, counter cycles are set by the WDP bit. If WDP0= WDP1=WDP2=0, then it is selected for the 16k clock cycles which means, 17ms time delay. If the WDP bit is changed, then the time will also change consequently. This timer is enabled and disabled by this WDE bit. If WDE =0, then the watchdog timer will be enabled, or else, disabled.
Watchdog Timer Functionality:
The heart of every watchdog timer is a counter register and is set by the ‘control status register’ of the watchdog timer. While executing the program loop, for every executed instruction, this counter register’s count is cleared. If any instruction of the loop fails to execute, then the watchdog timer counter will not be cleared and thus, provides pulses to restart the MCU. This repeats until the program is executed successfully.
Watchdog Timer Program
uint_16 volatile * pwatchdog =
(uint16 volatile *) 0xFF0000;
for (;;) //continuous loop//
*pwatchdog = 10000; // set the watchdog timer 5ms//
The above program is suitable for sensors and motors functionality. In the above program, the loop must be executed at least once in every five milliseconds. Consider that the motor must be fed with new control parameters frequently. If the counter is initialized to a value that corresponds to five milliseconds time, and if the timer reaches to 10,000 count, which means that there are no bugs in the software and program executes in a proper manner. If the timer will stops counting, then the software will restart the counter.
Watchdog Program with AVR Microcontroller
static unsigned int LED; // variable to time blink//
DDRC=0x01; // set the portc as output//
While(PINA.0= = 1)
; //wait for PB to be pressed//
WDTCR=0x0b; // enable watchdog timer with 130ms//
(WDR); //reset WT continuously//
++LDR; //increment LDR variable//
PORTC.0=PORTC.0^1// complement port bit//
LDR=0; //reset LDR for next delay//
while(1) //loop up to allow WDT to time out
Watchdog Timer Functionality in Microcontroller:
The watchdog timer is a hardware timing device that triggers to reset a system. Many of the microcontrollers or processors have inbuilt watchdog timer circuit for detecting the system malfunctions. There are of two types such as;
- Internal Watchdog Timer
- External Watchdog Timer
Internal Watchdog Timer:
While manufacturing the microcontrollers or processors, they are designed with inbuilt watchdog timer which is enabled by the software program to detect the system abnormality functions and rectify it by system rebooting. This type of timer automatically restarts the microcontroller and reboots the program at the starting address untill successful execution of the programs. The internal watchdog timers save money, but can be affected by the runway code.
External Watchdog Timer:
If the microcontrollers or processors lack inbuilt watchdog timer, then these are necessarily interfaced with watchdog timers, externally. These external watchdog timers are enabled manually by hardware after detecting the system abnormality functions. The external watchdog has a separate clock source given for better reliability. It cannot bypass or disable runway code. High cost is a disadvantage of external watchdog timer.
Watchdog Timer in 8051
The 8051 microcontroller has no inbuilt watchdog timer and, therefore, this must be connected and operated externally. The external one is connected to a complete RC oscillator to the microcontroller. The microcontroller is programmed with many instructions with clock cycles. Sometimes the microcontroller miss or jumps the instructions; at that time, we don’t get the appropriate signal from the microcontroller.
If the watchdog timer is enabled, then every time it counts up to the program end, if the microcontroller resets, then the program execution starts from the first instruction. The operation of this timer will not affect the execution of the program.
Watchdog Timer in PIC Microcontroller:
Many PIC microcontrollers have inbuilt watchdog timers that are enabled by the software using appropriate registers. The microcontroller is programmed with many functions. If any function fails to execute, then it forces to restart the microcontroller automatically until the execution occurs properly.
If the watchdog timer is enabled, then every time it counts up to the program end, then microcontroller resets, and then the program executes from the first instruction. The operation of the watchdog timers will affect the execution of the program.
Advantages of Watchdog Timers:
- Resets automatically without human intervention.
- Detects the errors in the program and reboot the system
- Cost sensitive
- Saves the time and money
- No need to place the employers to monitor the software debugs.
- Increases the system performance.
This is about the watchdog timer and its functionality in different microcontrollers with programming. If you want any further technical information and programming concepts about this timer, you can contact us by commenting below.