0
0
Embedded Cprogramming~20 mins

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

Choose your learning style9 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.