0
0
Embedded Cprogramming~10 mins

Feeding (kicking) the watchdog in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Feeding (kicking) the watchdog
Start Program
Initialize Watchdog
Enter Main Loop
Perform Tasks
Feed (Kick) Watchdog
Check Watchdog Timer
Timer OK
Continue
The program initializes the watchdog, then repeatedly performs tasks and feeds the watchdog to prevent system reset.
Execution Sample
Embedded C
void main() {
  WDT_Init();
  while(1) {
    DoTasks();
    WDT_Feed();
  }
}
This code initializes the watchdog timer and then continuously performs tasks and feeds the watchdog to avoid reset.
Execution Table
StepActionWatchdog Timer (ticks)ConditionResult
1Initialize watchdog0N/AWatchdog timer started
2Enter main loop0N/ALoop begins
3Perform tasks5Timer < timeoutTasks done, timer running
4Feed watchdog0Timer resetWatchdog timer reset to 0
5Perform tasks5Timer < timeoutTasks done, timer running
6Feed watchdog0Timer resetWatchdog timer reset to 0
7Perform tasks5Timer < timeoutTasks done, timer running
8Feed watchdog0Timer resetWatchdog timer reset to 0
9Perform tasks5Timer < timeoutTasks done, timer running
10Feed watchdog0Timer resetWatchdog timer reset to 0
11Watchdog timer expires10Timer >= timeoutSystem reset triggered
💡 System resets if watchdog timer reaches timeout without feeding.
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6After Step 7After Step 8After Step 9After Step 10After Step 11
Watchdog Timer (ticks)05050505010
Key Moments - 3 Insights
Why does the watchdog timer reset to 0 after feeding?
Feeding the watchdog resets the timer to 0 to prevent system reset, as shown in steps 4, 6, 8, and 10 in the execution_table.
What happens if the watchdog is not fed before the timer reaches the timeout?
If the timer reaches the timeout value without feeding, the system triggers a reset, as shown in step 11 in the execution_table.
Why does the watchdog timer increase during task execution?
The timer counts up during task execution to measure elapsed time since last feeding, shown by the increase from 0 to 5 ticks in steps 3, 5, 7, and 9.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the watchdog timer value immediately after step 6?
A10
B5
C0
DUndefined
💡 Hint
Check the 'Watchdog Timer (ticks)' column for step 6 in the execution_table.
At which step does the system reset occur according to the execution_table?
AStep 11
BStep 9
CStep 4
DStep 2
💡 Hint
Look for the row where 'Result' mentions 'System reset triggered' in the execution_table.
If the feeding step is skipped after step 3, what will happen to the watchdog timer at step 5?
AIt resets to 0
BIt increases beyond 5
CIt remains at 5
DIt decreases
💡 Hint
Refer to the variable_tracker to see how the timer increments when feeding is skipped.
Concept Snapshot
Feeding (kicking) the watchdog means resetting its timer regularly.
Syntax: call WDT_Feed() inside main loop.
If not fed before timeout, system resets.
Prevents system hang by ensuring code runs.
Feed watchdog after tasks to avoid reset.
Full Transcript
This example shows how an embedded program uses a watchdog timer to keep the system running safely. The watchdog timer counts up while the program runs tasks. The program must regularly feed or kick the watchdog to reset the timer to zero. If the watchdog timer reaches its timeout without being fed, it triggers a system reset to recover from possible errors. The execution table traces each step: initializing the watchdog, performing tasks, feeding the watchdog, and the timer values. Feeding the watchdog resets the timer to zero, preventing reset. If feeding is skipped, the timer continues to count up and eventually causes a reset. This mechanism helps embedded systems recover from software faults by restarting automatically.