Bird
Raised Fist0
Embedded Cprogramming~20 mins

Feeding (kicking) the watchdog in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Watchdog Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Watchdog Timer Feeding Frequency
Consider a watchdog timer that resets the system if not fed within 1000 milliseconds. What will be the output of the following code snippet if the feeding interval is set to 1200 milliseconds?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool watchdog_fed = false;

void feed_watchdog() {
    watchdog_fed = true;
}

void watchdog_check(int interval_ms) {
    if (interval_ms > 1000 && !watchdog_fed) {
        printf("System Reset Triggered\n");
    } else {
        printf("System Running Normally\n");
    }
    watchdog_fed = false;
}

int main() {
    watchdog_check(1200);
    feed_watchdog();
    return 0;
}
ANo Output
BSystem Running Normally
CCompilation Error
DSystem Reset Triggered
Attempts:
2 left
💡 Hint
Think about whether the watchdog is fed within the allowed time interval.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Feeding the Watchdog
Why is it important to feed (kick) the watchdog timer regularly in embedded systems?
ATo enable debugging mode in the system
BTo prevent the system from resetting due to software hang or fault
CTo save power by shutting down peripherals
DTo increase the CPU clock speed automatically
Attempts:
2 left
💡 Hint
Think about what happens if the watchdog is not fed.
🔧 Debug
advanced
2:30remaining
Identify the Bug in Watchdog Feeding Code
What is the bug in the following code that causes the watchdog to reset unexpectedly?
Embedded C
void feed_watchdog() {
    // Missing actual feeding command
}

int main() {
    while(1) {
        // supposed to feed watchdog here
        feed_watchdog();
        // other tasks
    }
    return 0;
}
AThe return statement is unreachable
BThe main loop is infinite, causing a system hang
CThe feed_watchdog function does not actually feed the watchdog hardware
DThe watchdog is fed too frequently causing overflow
Attempts:
2 left
💡 Hint
Check what the feed_watchdog function does internally.
📝 Syntax
advanced
1:30remaining
Correct Feeding Syntax for Watchdog Timer
Which of the following code snippets correctly feeds the watchdog timer assuming the hardware register is WDT_RESET = 1?
AWDT_RESET = 1;
BWDT_RESET == 1;
Cif (WDT_RESET = 1) {}
DWDT_RESET := 1;
Attempts:
2 left
💡 Hint
Remember the difference between assignment and comparison operators in C.
🚀 Application
expert
3:00remaining
Calculate Watchdog Feeding Interval
An embedded system's watchdog timer resets if not fed within 5000 clock cycles. The system clock runs at 1 MHz. What is the maximum time in milliseconds allowed between feeding the watchdog?
A5 milliseconds
B0.5 milliseconds
C5000 milliseconds
D50 milliseconds
Attempts:
2 left
💡 Hint
Calculate time = cycles / clock frequency.

Practice

(1/5)
1. What is the main purpose of feeding (kicking) the watchdog in embedded C systems?
easy
A. To start a new program execution
B. To increase the system clock speed
C. To save power by turning off peripherals
D. To reset the watchdog timer and prevent system reset

Solution

  1. Step 1: Understand watchdog function

    The watchdog timer resets the system if it is not fed in time, preventing hangs.
  2. Step 2: Purpose of feeding watchdog

    Feeding the watchdog resets its timer, showing the system is running fine.
  3. Final Answer:

    To reset the watchdog timer and prevent system reset -> Option D
  4. Quick Check:

    Feeding watchdog = reset timer [OK]
Hint: Feeding watchdog means resetting its timer regularly [OK]
Common Mistakes:
  • Thinking feeding increases clock speed
  • Confusing feeding with power saving
  • Assuming feeding starts program execution
2. Which of the following is the correct syntax to feed (kick) the watchdog in embedded C if the function is named FeedWatchdog()?
easy
A. FeedWatchdog();
B. feed_watchdog();
C. FeedWatchdog;
D. FeedWatchdog[];

Solution

  1. Step 1: Identify correct function call syntax

    In C, calling a function requires parentheses and a semicolon.
  2. Step 2: Check each option

    FeedWatchdog(); uses correct capitalization and parentheses; others are incorrect syntax.
  3. Final Answer:

    FeedWatchdog(); -> Option A
  4. Quick Check:

    Function call syntax = functionName(); [OK]
Hint: Function calls need parentheses and semicolon [OK]
Common Mistakes:
  • Omitting parentheses when calling function
  • Using wrong capitalization
  • Using brackets instead of parentheses
3. What will be the output of the following code snippet if the watchdog is not fed within 5 seconds?
void main() {
  init_watchdog(5); // 5 seconds timeout
  while(1) {
    // no FeedWatchdog() call here
  }
}
medium
A. System runs normally without reset
B. System resets after 5 seconds
C. Compilation error due to missing FeedWatchdog()
D. Watchdog timer disables automatically

Solution

  1. Step 1: Understand watchdog timeout behavior

    If the watchdog is not fed within the timeout, it triggers a system reset.
  2. Step 2: Analyze code behavior

    No FeedWatchdog() call means timer is not reset, so system resets after 5 seconds.
  3. Final Answer:

    System resets after 5 seconds -> Option B
  4. Quick Check:

    Not feeding watchdog = system reset [OK]
Hint: No feeding within timeout causes reset [OK]
Common Mistakes:
  • Assuming system runs normally without feeding
  • Expecting compilation error for missing feed
  • Thinking watchdog disables automatically
4. Identify the error in this code snippet that feeds the watchdog incorrectly:
void main() {
  init_watchdog(10);
  while(1) {
    FeedWatchdog;
    delay(1000);
  }
}
medium
A. Missing parentheses in FeedWatchdog call
B. Incorrect delay function usage
C. Watchdog timeout too short
D. No error, code is correct

Solution

  1. Step 1: Check FeedWatchdog usage

    FeedWatchdog is a function and must be called with parentheses.
  2. Step 2: Analyze code snippet

    FeedWatchdog; is missing parentheses, so it does not call the function.
  3. Final Answer:

    Missing parentheses in FeedWatchdog call -> Option A
  4. Quick Check:

    Function call needs () [OK]
Hint: Always use () to call functions [OK]
Common Mistakes:
  • Forgetting parentheses on function calls
  • Assuming delay is incorrect without context
  • Thinking timeout value causes error
5. You have a system with a watchdog timeout of 3 seconds. Your main loop takes 5 seconds to complete one iteration. How should you modify your code to prevent the watchdog from resetting the system?
hard
A. Remove the FeedWatchdog() calls entirely
B. Increase the watchdog timeout to 10 seconds
C. Call FeedWatchdog() multiple times inside the loop before 3 seconds pass
D. Call FeedWatchdog() only once after the loop finishes

Solution

  1. Step 1: Understand watchdog timeout vs loop time

    The loop takes longer than the watchdog timeout, so feeding once per loop is too late.
  2. Step 2: Feeding watchdog multiple times inside loop

    Calling FeedWatchdog() multiple times before 3 seconds resets timer and prevents reset.
  3. Final Answer:

    Call FeedWatchdog() multiple times inside the loop before 3 seconds pass -> Option C
  4. Quick Check:

    Feed watchdog before timeout expires [OK]
Hint: Feed watchdog often enough within timeout [OK]
Common Mistakes:
  • Assuming increasing timeout is always possible
  • Feeding watchdog only once after long loop
  • Removing feeding calls thinking it helps
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