0
0
Embedded Cprogramming~10 mins

Window watchdog concept in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Window watchdog concept
Start Program
Initialize Window Watchdog
Enter Main Loop
Check if Refresh Window Open?
NoSystem Reset
Yes
Refresh Watchdog Counter
Continue Normal Operation
Back to Main Loop
The program initializes the watchdog, then repeatedly checks if the refresh happens within the allowed time window. If refreshed too early or too late, the system resets.
Execution Sample
Embedded C
WWDG_Init();
while(1) {
  if (within_refresh_window()) {
    WWDG_Refresh();
  } else {
    // do not refresh
  }
}
This code initializes the window watchdog and refreshes it only when inside the allowed time window to prevent system reset.
Execution Table
StepWatchdog CounterTimeCondition: Inside Window?ActionSystem State
1Start at max (e.g. 127)0 msN/AInitialize watchdogRunning
212610 msNo (too early)No refreshRunning
312520 msYes (inside window)Refresh watchdogRunning
412721 msNo (too early after refresh)No refreshRunning
512530 msYes (inside window)Refresh watchdogRunning
612731 msNo (too early)No refreshRunning
712640 msNo (too late, missed window)No refreshSystem Reset
Exit----System reset triggered due to missed refresh window
💡 System resets because the watchdog was not refreshed within the allowed time window.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6After Step 7Final
Watchdog Counter127126127126127126126-
System StateRunningRunningRunningRunningRunningRunningSystem ResetSystem Reset
Key Moments - 2 Insights
Why can't we refresh the watchdog counter too early?
Refreshing too early means outside the allowed window, so the watchdog treats it as a fault and will reset the system, as shown in steps 2 and 4 where no refresh happens because it's too early.
What happens if we miss the refresh window completely?
If the refresh window is missed, the watchdog counter reaches a critical value and triggers a system reset, as seen in step 7 where the system resets due to no refresh.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the watchdog counter value at step 3 after refresh?
A126
B125
C127
D124
💡 Hint
Step 3 shows 125 before refresh, but after refresh reloads to max 127 (as step 4 starts at 127).
At which step does the system reset occur according to the execution table?
AStep 6
BStep 7
CStep 5
DStep 4
💡 Hint
Look at the 'System State' column for the first occurrence of 'System Reset'.
If the watchdog is refreshed too early at step 2, what would happen?
ASystem reset triggered immediately
BWatchdog counter increases
CSystem continues running normally
DWatchdog counter freezes
💡 Hint
Refer to the explanation in key_moments about refreshing too early causing reset.
Concept Snapshot
Window Watchdog Concept:
- Initializes with a counter that counts down.
- Must refresh only within a specific time window.
- Refreshing too early or too late causes system reset.
- Helps detect software faults by enforcing timing constraints.
- Used in embedded systems for safety and reliability.
Full Transcript
This visual execution trace shows how a window watchdog timer works in embedded C. The watchdog counter starts at a maximum value and counts down over time. The program must refresh the watchdog only when inside a specific time window. Refreshing too early or too late causes the watchdog to reset the system. The execution table shows each step with the watchdog counter value, time, condition check, action taken, and system state. Variable tracking shows how the watchdog counter and system state change over time. Key moments clarify why refreshing too early or missing the window causes reset. The quiz questions test understanding of the watchdog counter values and reset timing. This concept helps embedded programmers ensure their system recovers from software faults by enforcing timely refreshes.