0
0
Embedded Cprogramming~20 mins

Watchdog timer operation 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 Reset Behavior
What will be the output of the following embedded C code snippet simulating a watchdog timer reset?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool watchdog_reset = false;

void watchdog_feed() {
    watchdog_reset = true;
}

void watchdog_check() {
    if (!watchdog_reset) {
        printf("System Reset by Watchdog\n");
    } else {
        printf("System Running Normally\n");
    }
}

int main() {
    watchdog_reset = true;
    watchdog_feed();
    watchdog_check();
    watchdog_reset = false;
    watchdog_check();
    return 0;
}
A
System Running Normally
System Reset by Watchdog
B
System Reset by Watchdog
System Reset by Watchdog
C
System Running Normally
System Running Normally
D
System Reset by Watchdog
System Running Normally
Attempts:
2 left
💡 Hint
Watchdog resets the system if it is not fed (reset) in time.
🧠 Conceptual
intermediate
1:30remaining
Purpose of a Watchdog Timer
What is the main purpose of a watchdog timer in embedded systems?
ATo manage power consumption by shutting down peripherals
BTo increase the processing speed of the CPU
CTo store data persistently during power loss
DTo monitor system health and reset the system if it becomes unresponsive
Attempts:
2 left
💡 Hint
Think about what happens when a system freezes or crashes.
🔧 Debug
advanced
2:30remaining
Identify the Bug in Watchdog Feeding Code
What is the bug in the following watchdog feeding code snippet?
Embedded C
void feed_watchdog() {
    // Missing watchdog reset sequence
    // supposed to reset the watchdog timer here
}

int main() {
    while(1) {
        feed_watchdog();
        // Other tasks
    }
    return 0;
}
AThe while loop will never execute
BThe watchdog timer is never reset, causing system reset
CThe function feed_watchdog() causes a memory leak
DThe program will compile but never start
Attempts:
2 left
💡 Hint
Feeding the watchdog means resetting its timer to prevent reset.
📝 Syntax
advanced
1:30remaining
Correct Watchdog Timer Initialization Syntax
Which option correctly initializes a watchdog timer with a timeout of 2 seconds in embedded C?
AWDT_Init(2000);
BWDT_Init(2000ms);
CWDT_Init(2);
DWDT_Init("2s");
Attempts:
2 left
💡 Hint
Timeouts are usually given in milliseconds as integers.
🚀 Application
expert
3:00remaining
Watchdog Timer Use Case Scenario
In an embedded system controlling a robotic arm, the watchdog timer is set to 1 second. The main control loop takes 1.5 seconds to complete one cycle. What will happen and why?
AThe watchdog will extend its timeout automatically to 2 seconds
BThe system will run normally because the watchdog timer is disabled during the control loop
CThe watchdog will reset the system because the control loop exceeds the watchdog timeout
DThe system will ignore the watchdog timer because the control loop is critical
Attempts:
2 left
💡 Hint
Watchdog timers reset the system if not fed before timeout.