Introduction to Watchdog timer and Significance of watchdog timer in embedded

Introduction to Watchdog timer in embedded c

Watchdog timers are hardware count down timers, which when enabled in microcontrollers will generate a microcontroller reset (or) interrupt if the program running on the microcontroller fails to reload the watchdog timer within the predetermined time interval. Therefore, it is the responsibility of the running program to reload the watchdog timer before it reaches zero, or else the watchdog timer circuitry will reset the system. 

Significance of watchdog timer in embedded
Significance of watchdog timer in embedded

The reloading of the watchdog timer value by the software is called kicking the watchdog. The watchdog timers can be clocked from the internal RC oscillators, RTC oscillators. When the watchdog timer underflows, the program counter will start from 0x0000 0000 as in the case of external reset. Some systems refer the watchdog timers as Computer Operating Properly Timer (COP Timer). Most microcontrollers have the watchdog timers in their hardware.

Embedded systems need to self-reliant since it is not possible for someone to reboot the whole system when a problem occurs. If there are any problems in the systems that are used in space probes, satellites etc., no one is there to reset the system.  Here is where the watchdog timer comes into play. If the system fails to reload the watchdog timer before it hits zero, the watchdog timer circuitry will reset the whole system presuming there is a malfunction. 

There are a several ways an embedded system can hang. For instance, the memory might get corrupted and the program can get stuck in an infinite loop; a hardware component might not work properly and not respond to requests; a high priority task might take a lot of CPU cycles that the low priority task might not run at all resulting in cases like data loss. 

Now for example consider a watchdog timer working on 4kHz clock. Let us assume the time for finishing a task is 100ms. 

Given 4kHz, one tick equals = ¼ = 0.25 ms

For 100ms the watchdog timer ticks 400 times. So, if the system does not reload the watchdog timer before it ticks 400 times, the system will reset fully. This is how the watchdog timers are implemented in embedded systems. The watchdog timers can be internal watchdog timers, or external watchdog timers. 

Significance of watchdog timer in embedded c

In real-time operating systems, the watchdog timers ensure that each task is completed within the given time limit. This way it is helps in better functioning of the system. The watchdog timers can also be used in computers, where it can be used to limit the CPU time available for any untrusted piece of code and thus preventing attacks like the denial-of-service attack.

The output of the watchdog timer is directly given to the microcontroller’s reset signal. This way, if the watchdog timer is not reloaded, the microcontroller resets. Every watchdog timer has a counter register whose value is set by the control status register of the watchdog timer. When executing the program loop, the counter register count will be cleared. If the program has an error in any instruction, the counter register will not be cleared which then provides signal to reset the microcontroller. As told earlier there are two types of watchdog timers: Internal watchdog timers and External watchdog timers. Internal watchdog timers are those that are built-in the microcontroller while manufacturing. These use software instructions to enable the timer and reboot the microcontroller. If the watchdog timer is not in-built in a microcontroller, externally these are connected to the microcontroller. These are enabled through hardware connections between the microcontroller and the timer. The external watchdog timers have separate clock for themselves. This means there will be better reliability since a separate clock is used.

Watchdog timers have many advantages. They are used in fault detection in the system, so no human intervention is needed to reboot the system. Since humans cannot go to all the places, where the embedded systems are used, watchdog timers make the whole system self-reliant. The use of watchdog timers results in better performance of the whole system. This saves the time and cost. The Arduino uses Atmega328p microcontroller. Watchdog timer can be implemented in Arduino using Arduino IDE and the watchdog timer library. Careful measures must be taken when implementing watchdog timers in an embedded system. The timeout of the watchdog timer must be calculated carefully since wrong timeout can result in improper working of the system. The watchdog timers can not only be used for resetting the system. Due to environmental noises, electrical noises, the software running might get corrupt and stop immediately. At this time, the watchdog timer when connected to the reset line can reset the system. It can also be used to switch on alarms to notify the fault, stop the working of the component that caused the fault in the system. This way the watchdog timers are used in embedded systems.

Summary :

In this section we saw Introduction to Watchdog timer and Significance of watchdog timer in embedded so about this section you have any query then free to ask me

I am Mr. Sachin pagar the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *