0
0
Embedded Cprogramming~20 mins

Why power management matters in Embedded C - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Power Management Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this power state check?

Consider a microcontroller with different power states. What will this code print?

Embedded C
#include <stdio.h>

#define POWER_STATE_ACTIVE 1
#define POWER_STATE_SLEEP  2

int main() {
    int power_state = POWER_STATE_SLEEP;
    if (power_state == POWER_STATE_ACTIVE) {
        printf("Active Mode\n");
    } else if (power_state == POWER_STATE_SLEEP) {
        printf("Sleep Mode\n");
    } else {
        printf("Unknown Mode\n");
    }
    return 0;
}
AActive Mode
BSleep Mode
CUnknown Mode
DCompilation error
Attempts:
2 left
💡 Hint

Check the value assigned to power_state and compare it with the defined constants.

🧠 Conceptual
intermediate
1:30remaining
Why reduce power consumption in embedded devices?

Which of the following is the main reason to manage power carefully in embedded systems?

ATo make the device heavier
BTo increase memory capacity
CTo extend battery life and reduce heat
DTo increase the device's processing speed
Attempts:
2 left
💡 Hint

Think about what happens when a device uses less power.

🔧 Debug
advanced
2:00remaining
Identify the error in this power mode switch code

What error will this code cause when compiled?

Embedded C
#include <stdio.h>

void set_power_mode(int mode) {
    switch(mode) {
        case 1:
            printf("Active mode set\n");
            break;
        case 2
            printf("Sleep mode set\n");
            break;
        default:
            printf("Invalid mode\n");
    }
}

int main() {
    set_power_mode(2);
    return 0;
}
ANo error, prints 'Sleep mode set'
BCompilation error: missing semicolon in printf
CRuntime error: segmentation fault
DSyntax error due to missing colon after case 2
Attempts:
2 left
💡 Hint

Look carefully at the switch cases and their syntax.

📝 Syntax
advanced
1:30remaining
Which option correctly defines a low power mode constant?

Choose the correct way to define a constant for low power mode in embedded C.

A#define LOW_POWER_MODE 0x01
Bconst int LOW_POWER_MODE = 0x01;
Cint LOW_POWER_MODE = 0x01;
D#define LOW_POWER_MODE = 0x01
Attempts:
2 left
💡 Hint

Remember how #define works in C for constants.

🚀 Application
expert
3:00remaining
Calculate total power consumption from modes

An embedded device runs 3 hours in active mode consuming 50mA, 5 hours in sleep mode consuming 5mA, and 16 hours in deep sleep consuming 1mA. What is the total average current consumption in mA?

A8.5 mA
B6.5 mA
C12.5 mA
D4.5 mA
Attempts:
2 left
💡 Hint

Calculate weighted average: (current * hours) / total hours.