Challenge - 5 Problems
Low-Power Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of low-power mode entry code
What is the output of this embedded C code snippet that simulates entering a low-power mode and waking up?
Embedded C
#include <stdio.h> #include <stdbool.h> volatile bool wakeup_flag = false; void enter_low_power_mode() { printf("Entering low power mode...\n"); // Simulate low power mode by waiting for wakeup_flag while (!wakeup_flag) { // CPU sleeps here } printf("Woke up from low power mode!\n"); } int main() { enter_low_power_mode(); wakeup_flag = true; return 0; }
Attempts:
2 left
💡 Hint
Think about when wakeup_flag is set and how the while loop behaves.
✗ Incorrect
The code enters a while loop waiting for wakeup_flag to become true. However, wakeup_flag is set to true only after enter_low_power_mode() returns, which never happens because of the infinite loop. So the program never prints the second message and never exits the loop.
🧠 Conceptual
intermediate1:30remaining
Best low-power design pattern for periodic sensor reading
Which low-power design pattern is best suited for a device that needs to read a sensor every 10 seconds and sleep otherwise?
Attempts:
2 left
💡 Hint
Think about how to save power by sleeping and waking only when needed.
✗ Incorrect
Using a timer interrupt to wake the device every 10 seconds allows the CPU to sleep most of the time, saving power. Busy-waiting or continuous polling wastes power.
🔧 Debug
advanced2:30remaining
Identify the bug causing high power consumption
This embedded C code is intended to put the device into low-power mode but the device never wakes up. What is the bug?
Embedded C
void low_power_sleep() {
// Disable interrupts
__disable_irq();
// Enter sleep mode
__WFI();
// Enable interrupts
__enable_irq();
}
int main() {
while (1) {
low_power_sleep();
// Do some work after waking
}
return 0;
}Attempts:
2 left
💡 Hint
Think about how interrupts and sleep instructions interact.
✗ Incorrect
Disabling interrupts before entering sleep prevents any interrupt from waking the CPU. The CPU stays asleep indefinitely.
📝 Syntax
advanced1:30remaining
Identify the syntax error in low-power mode code
Which option contains the correct syntax for entering low-power mode using a macro?
Embedded C
#define ENTER_LOW_POWER() __asm__("WFI")
void sleep_mode() {
ENTER_LOW_POWER()
}Attempts:
2 left
💡 Hint
Check macro usage and semicolon placement.
✗ Incorrect
Option A correctly defines the macro without a trailing semicolon and calls it with parentheses and a semicolon. Option A adds an extra semicolon in the macro causing double semicolons. Option A misses semicolon in call. Option A misses parentheses in call.
🚀 Application
expert2:00remaining
Calculate total sleep time in a low-power cycle
An embedded device sleeps for 5 seconds, wakes for 1 second to perform tasks, then repeats. After 10 cycles, what is the total time spent sleeping?
Attempts:
2 left
💡 Hint
Multiply sleep time per cycle by number of cycles.
✗ Incorrect
Each cycle has 5 seconds sleep and 1 second awake. Total sleep time after 10 cycles is 5 * 10 = 50 seconds.