Challenge - 5 Problems
Watchdog Timeout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Watchdog Timer Timeout Value Calculation
Given a watchdog timer with a clock frequency of 1 MHz and a prescaler of 64, what is the timeout period in milliseconds if the watchdog counter is set to 250?
Embedded C
/* Timeout (ms) = (Counter * Prescaler) / (Clock Frequency in kHz) */ // Clock Frequency = 1 MHz = 1000 kHz // Prescaler = 64 // Counter = 250 unsigned int timeout_ms = (250 * 64) / 1000;
Attempts:
2 left
💡 Hint
Calculate the timeout by multiplying the counter by the prescaler, then divide by the clock frequency in kHz.
✗ Incorrect
Timeout in milliseconds = (Counter * Prescaler) / (Clock frequency in kHz). Here, (250 * 64) / 1000 = 16 ms.
❓ Predict Output
intermediate2:00remaining
Watchdog Configuration Register Value
If a watchdog timer register uses bits 0-3 to set the prescaler value as a power of two (e.g., 0 means divide by 1, 1 means divide by 2, 2 means divide by 4, etc.), what value should be written to set a prescaler of 128?
Embedded C
/* Prescaler = 2^n, find n for prescaler 128 */ // 2^7 = 128 unsigned char prescaler_setting = 7;
Attempts:
2 left
💡 Hint
Find the power n such that 2^n equals the prescaler value.
✗ Incorrect
Since 2^7 = 128, the register bits should be set to 7 to get a prescaler of 128.
🔧 Debug
advanced2:00remaining
Identify the Bug in Watchdog Timeout Setup
What error does the following code produce when configuring the watchdog timeout?
unsigned int timeout = 5000;
void setup_watchdog() {
WDT_CTRL = timeout << 2;
}
Assume WDT_CTRL is an 8-bit register and timeout is in milliseconds.
Embedded C
unsigned int timeout = 5000; void setup_watchdog() { WDT_CTRL = timeout << 2; }
Attempts:
2 left
💡 Hint
Consider the size of WDT_CTRL and the value assigned to it.
✗ Incorrect
Shifting 5000 (which is 0x1388) left by 2 bits results in a value too large for an 8-bit register, causing overflow and incorrect timeout setting.
📝 Syntax
advanced2:00remaining
Correct Syntax for Watchdog Timeout Macro
Which option correctly defines a macro to calculate watchdog timeout in milliseconds given clock frequency (in Hz), prescaler, and counter value?
Embedded C
#define WDT_TIMEOUT_MS(clock, prescaler, counter) ???Attempts:
2 left
💡 Hint
Use parentheses to ensure correct order of operations and multiply by 1000 to convert seconds to milliseconds.
✗ Incorrect
Option A correctly multiplies counter and prescaler, then multiplies by 1000, and divides by clock frequency, all with proper parentheses.
🚀 Application
expert3:00remaining
Calculate Maximum Watchdog Timeout
An embedded system uses an 8-bit watchdog timer counter and a prescaler selectable as powers of two from 1 to 256. The clock frequency is 2 MHz. What is the maximum watchdog timeout in milliseconds achievable?
Embedded C
/* Max counter = 255 (8-bit)
Max prescaler = 256
Clock frequency = 2 MHz = 2,000,000 Hz
Timeout (s) = (counter * prescaler) / clock
Timeout (ms) = Timeout (s) * 1000
*/Attempts:
2 left
💡 Hint
Calculate timeout in seconds first, then convert to milliseconds.
✗ Incorrect
Timeout = (255 * 256) / 2,000,000 = 0.03264 seconds = 32.64 ms. But careful: 255 * 256 = 65280, so 65280 / 2,000,000 = 0.03264 s = 32.64 ms. The correct option is 32.64 ms (A).