0
0
Embedded Cprogramming~20 mins

Low-power design patterns in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Low-Power Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A
Woke up from low power mode!
Entering low power mode...
BNo output (infinite loop)
C
Entering low power mode...
Woke up from low power mode!
DEntering low power mode...
Attempts:
2 left
💡 Hint
Think about when wakeup_flag is set and how the while loop behaves.
🧠 Conceptual
intermediate
1: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?
AUse a timer interrupt to wake device every 10 seconds and sleep in between
BBusy-wait loop checking sensor every millisecond
CKeep CPU running at full speed and poll sensor continuously
DDisable all interrupts and run sensor reading in main loop
Attempts:
2 left
💡 Hint
Think about how to save power by sleeping and waking only when needed.
🔧 Debug
advanced
2: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;
}
AThe __WFI() instruction is missing a semicolon
BInterrupts are disabled before sleep and enabled after, so wakeup interrupts never happen
CThe while loop should be a for loop
DThe function low_power_sleep() is never called
Attempts:
2 left
💡 Hint
Think about how interrupts and sleep instructions interact.
📝 Syntax
advanced
1: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()
}
A
#define ENTER_LOW_POWER() __asm__("WFI")

void sleep_mode() {
    ENTER_LOW_POWER();
}
B
#define ENTER_LOW_POWER() __asm__("WFI")

void sleep_mode() {
    ENTER_LOW_POWER()
}
C
#define ENTER_LOW_POWER() __asm__("WFI")

void sleep_mode() {
    ENTER_LOW_POWER
}
D
#define ENTER_LOW_POWER() __asm__("WFI");

void sleep_mode() {
    ENTER_LOW_POWER();
}
Attempts:
2 left
💡 Hint
Check macro usage and semicolon placement.
🚀 Application
expert
2: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?
A10 seconds
B55 seconds
C50 seconds
D60 seconds
Attempts:
2 left
💡 Hint
Multiply sleep time per cycle by number of cycles.