Bird
Raised Fist0
Embedded Cprogramming~20 mins

Window watchdog concept in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Window Watchdog Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this watchdog timer reset code?
Consider this embedded C code snippet that simulates a window watchdog reset. What will be printed when the program runs?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 5;
    const unsigned int window_end = 10;
    if (counter < window_start || counter > window_end) {
        return false; // Reset triggered
    }
    return true; // No reset
}

int main() {
    unsigned int counter = 7;
    if (window_watchdog_reset(counter)) {
        printf("No reset\n");
    } else {
        printf("Reset triggered\n");
    }
    return 0;
}
AReset triggered
BNo reset
CCompilation error
DNo output
Attempts:
2 left
💡 Hint
Check if the counter value is inside the allowed window range.
🧠 Conceptual
intermediate
1:30remaining
What does the window watchdog timer prevent in embedded systems?
Choose the best description of what a window watchdog timer helps to prevent in embedded systems.
AIt prevents the system from resetting too early or too late by enforcing a time window for resets.
BIt increases the clock speed of the microcontroller to improve performance.
CIt stores data permanently in non-volatile memory.
DIt manages power consumption by shutting down unused peripherals.
Attempts:
2 left
💡 Hint
Think about why a reset outside a certain time frame might be harmful.
🔧 Debug
advanced
2:30remaining
Identify the bug causing the watchdog reset to always trigger
This code is supposed to reset the watchdog only if the counter is within the window 3 to 8. However, it always triggers a reset. What is the bug?
Embedded C
bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 3;
    const unsigned int window_end = 8;
    if (counter > window_start && counter < window_end) {
        return false; // No reset
    }
    return true; // Reset triggered
}
AThe function is missing a counter increment causing infinite reset.
BThe window boundaries are incorrect; they should be inclusive using >= and <=.
CThe function returns wrong boolean values; it should return true for reset and false for no reset.
DThe condition logic is inverted; it should return true inside the window and false outside.
Attempts:
2 left
💡 Hint
Check what the function returns inside and outside the window.
📝 Syntax
advanced
2:00remaining
Which option fixes the syntax error in this watchdog timer code?
This code snippet has a syntax error. Which option fixes it correctly?
Embedded C
bool check_watchdog(unsigned int count) {
    if count >= 2 && count <= 6 {
        return true;
    } else {
        return false;
    }
}
Aif (count >= 2 && count <= 6) { return true; } else { return false; }
Bif count >= 2 && count <= 6: return true else return false
Cif (count >= 2 && count <= 6) return true; else return false;
Dif [count >= 2 && count <= 6] { return true; } else { return false; }
Attempts:
2 left
💡 Hint
Remember the syntax for if statements in C requires parentheses around the condition.
🚀 Application
expert
3:00remaining
How many times will the watchdog reset be triggered in this loop?
Given this code simulating a watchdog reset check in a loop, how many times will "Reset triggered" be printed?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 4;
    const unsigned int window_end = 7;
    return (counter >= window_start && counter <= window_end);
}

int main() {
    unsigned int resets = 0;
    for (unsigned int i = 1; i <= 10; i++) {
        if (!window_watchdog_reset(i)) {
            printf("Reset triggered at %u\n", i);
            resets++;
        }
    }
    printf("Total resets: %u\n", resets);
    return 0;
}
A4
B5
C6
D3
Attempts:
2 left
💡 Hint
Count how many values of i are outside the window 4 to 7 inclusive.

Practice

(1/5)
1. What is the main purpose of a window watchdog timer in embedded systems?
easy
A. To increase the processing speed of the microcontroller
B. To reset the system if the software fails to refresh the timer within a specific time window
C. To store data temporarily during program execution
D. To provide power backup during system failure

Solution

  1. Step 1: Understand the watchdog timer function

    A watchdog timer monitors if the software is running correctly by expecting periodic refreshes.
  2. Step 2: Identify the role of the window watchdog

    The window watchdog resets the system if the refresh happens too early or too late, ensuring software reliability.
  3. Final Answer:

    To reset the system if the software fails to refresh the timer within a specific time window -> Option B
  4. Quick Check:

    Window watchdog resets system on missed or mistimed refresh [OK]
Hint: Watchdog resets system if refresh is outside allowed time [OK]
Common Mistakes:
  • Confusing watchdog with memory storage
  • Thinking watchdog speeds up the processor
  • Assuming watchdog provides power backup
2. Which of the following is the correct way to refresh a window watchdog timer in embedded C?
easy
A. Call WWDG_Refresh() function within the allowed time window
B. Call WWDG_Refresh() only once at system startup
C. Disable the watchdog timer before refreshing
D. Refresh the watchdog timer continuously without delay

Solution

  1. Step 1: Understand watchdog refresh requirements

    The watchdog must be refreshed periodically within a specific time window to avoid reset.
  2. Step 2: Identify correct refresh method

    Calling WWDG_Refresh() within the allowed time window is the correct way to refresh.
  3. Final Answer:

    Call WWDG_Refresh() function within the allowed time window -> Option A
  4. Quick Check:

    Refresh watchdog periodically inside time window [OK]
Hint: Refresh watchdog periodically, not just once or too fast [OK]
Common Mistakes:
  • Refreshing only once at startup
  • Disabling watchdog before refresh
  • Refreshing too frequently causing reset
3. Consider this code snippet using a window watchdog timer:
void main() {
  WWDG_Init();
  while(1) {
    delay(50);  // delay in ms
    WWDG_Refresh();
  }
}
If the allowed refresh window is between 40ms and 60ms, what will happen?
medium
A. The system will reset because refresh is too early
B. The system will reset because refresh is too late
C. The system will run normally without reset
D. The system will freeze due to watchdog error

Solution

  1. Step 1: Analyze the refresh timing

    The code delays 50ms before refreshing the watchdog, which is within the 40-60ms window.
  2. Step 2: Determine system behavior

    Since refresh happens inside the allowed window, the system will not reset and runs normally.
  3. Final Answer:

    The system will run normally without reset -> Option C
  4. Quick Check:

    Refresh at 50ms inside 40-60ms window = no reset [OK]
Hint: Check if refresh delay fits inside allowed window [OK]
Common Mistakes:
  • Assuming 50ms is too early or too late
  • Confusing delay units
  • Ignoring the watchdog window limits
4. The following code causes the system to reset unexpectedly. What is the likely error?
void main() {
  WWDG_Init();
  while(1) {
    WWDG_Refresh();
    delay(30);  // delay in ms
  }
}
Assuming the allowed refresh window is 40ms to 60ms.
medium
A. Not calling WWDG_Refresh() frequently enough
B. Delay is too long causing late refresh
C. Missing WWDG_Init() call
D. Refreshing the watchdog too early before the window opens

Solution

  1. Step 1: Check refresh timing relative to window

    The code refreshes the watchdog immediately, then delays 30ms, so refresh happens every ~30ms.
  2. Step 2: Compare with allowed window

    Since the window starts at 40ms, refreshing at 30ms is too early and causes reset.
  3. Final Answer:

    Refreshing the watchdog too early before the window opens -> Option D
  4. Quick Check:

    Refresh before 40ms window causes reset [OK]
Hint: Refresh only after window opens, not before [OK]
Common Mistakes:
  • Thinking delay is too long
  • Ignoring refresh order
  • Assuming missing init causes reset here
5. You want to design a system using a window watchdog timer that resets if the refresh happens outside 100ms to 200ms window. Which approach correctly implements this behavior in embedded C?
hard
A. Refresh the watchdog every 150ms
B. Refresh the watchdog every 50ms
C. Refresh the watchdog every 250ms
D. Refresh the watchdog only once at startup

Solution

  1. Step 1: Understand the allowed refresh window

    The watchdog must be refreshed between 100ms and 200ms to avoid reset.
  2. Step 2: Evaluate each refresh timing option

    Refreshing at 50ms is too early, 150ms is inside window, 250ms is too late, and once at startup is insufficient.
  3. Final Answer:

    Refresh the watchdog every 150ms -> Option A
  4. Quick Check:

    Refresh inside 100-200ms window avoids reset [OK]
Hint: Refresh watchdog only inside allowed time window [OK]
Common Mistakes:
  • Refreshing too early or too late
  • Refreshing only once
  • Ignoring window timing constraints
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard