0
0
Embedded Cprogramming~20 mins

Sleep modes overview in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sleep Mode Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of MCU entering sleep mode

What will be the output of this embedded C code snippet when the microcontroller enters sleep mode?

Embedded C
#include <stdio.h>
#include <avr/sleep.h>

int main() {
    printf("Before sleep\n");
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_cpu();
    printf("After sleep\n");
    return 0;
}
ABefore sleep\nAfter sleep
BBefore sleep
CAfter sleep
DNo output
Attempts:
2 left
💡 Hint

Consider what happens after sleep_cpu() in this code.

🧠 Conceptual
intermediate
1:30remaining
Purpose of different sleep modes

Which sleep mode is best suited for the lowest power consumption while keeping the RAM contents intact?

APower-down mode
BStandby mode
CIdle mode
DExtended standby mode
Attempts:
2 left
💡 Hint

Think about which mode stops most clocks but preserves RAM.

🔧 Debug
advanced
2:00remaining
Identify the error in sleep mode usage

What is the error in this code that prevents the microcontroller from entering sleep mode?

Embedded C
#include <avr/sleep.h>

void enter_sleep() {
    set_sleep_mode(SLEEP_MODE_IDLE);
    sleep_enable();
    sleep_cpu();
    sleep_disable();
}
Asleep_disable() should be called before sleep_cpu()
Bsleep_enable() is not needed
CMissing semicolon after set_sleep_mode line
DSLEEP_MODE_IDLE is not a valid mode
Attempts:
2 left
💡 Hint

Check syntax carefully line by line.

Predict Output
advanced
2:00remaining
Effect of sleep_disable() after sleep_cpu()

What is the output of this code snippet?

Embedded C
#include <stdio.h>
#include <avr/sleep.h>

int main() {
    printf("Start\n");
    set_sleep_mode(SLEEP_MODE_STANDBY);
    sleep_enable();
    sleep_cpu();
    sleep_disable();
    printf("End\n");
    return 0;
}
ANo output
BStart\nEnd
CStart
DEnd
Attempts:
2 left
💡 Hint

Consider the order of sleep_disable() and sleep_cpu() calls.

🧠 Conceptual
expert
2:30remaining
Wake-up sources in different sleep modes

Which wake-up source can bring the microcontroller out of Power-down mode?

AExternal interrupt
BWatchdog timer interrupt
CTimer/Counter interrupt
DAll of the above
Attempts:
2 left
💡 Hint

Think about which interrupts are active in Power-down mode.