A watchdog timer helps reset a device if it stops working properly. Setting the timeout decides how long the device waits before resetting.
0
0
Configuring watchdog timeout in Embedded C
Introduction
When you want to make sure your device recovers from freezes automatically.
When your device runs critical tasks and must not stay stuck.
When testing how long your system can run without problems.
When you want to save power by resetting after a certain time.
When debugging to check if your program hangs.
Syntax
Embedded C
void Watchdog_SetTimeout(uint32_t timeout_ms);
The timeout is usually given in milliseconds.
Check your device datasheet for allowed timeout values.
Examples
Sets the watchdog timeout to 1000 milliseconds (1 second).
Embedded C
Watchdog_SetTimeout(1000);Sets the watchdog timeout to 5000 milliseconds (5 seconds).
Embedded C
Watchdog_SetTimeout(5000);Sample Program
This program sets the watchdog timeout to 2000 milliseconds and then runs a simple loop printing messages.
Embedded C
#include <stdio.h> #include <stdint.h> // Simulated watchdog setup function void Watchdog_SetTimeout(uint32_t timeout_ms) { printf("Watchdog timeout set to %u milliseconds.\n", timeout_ms); } int main() { // Set watchdog timeout to 2000 ms (2 seconds) Watchdog_SetTimeout(2000); // Simulate main program loop for (int i = 0; i < 3; i++) { printf("Running main loop iteration %d\n", i + 1); } return 0; }
OutputSuccess
Important Notes
Always set the watchdog timeout long enough for your tasks to complete.
Remember to reset or 'kick' the watchdog regularly to avoid unwanted resets.
Consult your hardware manual for exact watchdog configuration details.
Summary
The watchdog timer helps recover from system hangs by resetting the device.
Configuring the timeout sets how long the system waits before resetting.
Use the timeout setting carefully to balance safety and normal operation.