A watchdog timer helps keep your device safe by restarting it if it stops working properly. Feeding or kicking the watchdog means resetting this timer regularly to show the device is still running well.
0
0
Feeding (kicking) the watchdog in Embedded C
Introduction
When you want to make sure your device recovers automatically if it freezes.
In embedded systems like home appliances or robots to keep them running safely.
When running long tasks that might cause the system to hang.
To avoid manual resets by automatically restarting the device if it crashes.
Syntax
Embedded C
void feed_watchdog(void); // or depending on hardware #define WATCHDOG_RESET() feed_watchdog()
The exact function or macro name depends on your hardware and library.
You usually call this function regularly inside your main loop or timer interrupt.
Examples
Simple call to reset the watchdog timer.
Embedded C
feed_watchdog();
Macro to kick the watchdog, common in some embedded libraries.
Embedded C
WATCHDOG_RESET();
Example of feeding the watchdog inside an infinite loop every second.
Embedded C
while(1) { // your code feed_watchdog(); delay_ms(1000); }
Sample Program
This program simulates feeding the watchdog three times in a loop, showing how you reset the timer regularly.
Embedded C
#include <stdio.h> // Simulated watchdog feed function void feed_watchdog(void) { printf("Watchdog fed!\n"); } int main() { for (int i = 0; i < 3; i++) { printf("Loop iteration %d\n", i+1); feed_watchdog(); } return 0; }
OutputSuccess
Important Notes
Always feed the watchdog before its timer expires to avoid unwanted resets.
Do not feed the watchdog inside long blocking code without feeding it periodically.
Check your hardware manual for the exact feeding function or macro.
Summary
Feeding the watchdog resets its timer to prevent system reset.
Call the feed function regularly in your code to show the system is alive.
This helps embedded devices recover automatically from freezes or crashes.