0
0
Power-electronicsHow-ToBeginner · 4 min read

How to Reduce Power Consumption in Embedded Systems Efficiently

To reduce power consumption in embedded systems, use sleep modes to pause the CPU when idle, disable unused peripherals, and lower the clock frequency. These techniques help save energy by minimizing active hardware and processing time.
📐

Syntax

Here is the basic syntax to enter a low power sleep mode and disable peripherals in embedded C:

  • __WFI(); - Wait For Interrupt instruction to enter sleep mode.
  • DisablePeripheral(); - Function to turn off unused hardware modules.
  • SetClockFrequency(freq); - Function to reduce CPU clock speed.

Use these calls to control power states and reduce energy use.

embedded_c
void enter_sleep_mode() {
    // Disable unused peripherals
    DisablePeripheral("UART");
    DisablePeripheral("SPI");

    // Reduce clock frequency to save power
    SetClockFrequency(1000000); // 1 MHz

    // Enter sleep mode until an interrupt occurs
    __WFI();
}
💻

Example

This example shows how to reduce power by disabling peripherals, lowering clock speed, and entering sleep mode until an interrupt wakes the system.

embedded_c
#include <stdio.h>

// Mock functions for demonstration
void DisablePeripheral(const char* peripheral) {
    printf("%s disabled\n", peripheral);
}

void SetClockFrequency(unsigned int freq) {
    printf("Clock frequency set to %u Hz\n", freq);
}

void __WFI() {
    printf("Entering sleep mode... Waiting for interrupt.\n");
}

void enter_sleep_mode() {
    DisablePeripheral("UART");
    DisablePeripheral("SPI");
    SetClockFrequency(1000000); // 1 MHz
    __WFI();
}

int main() {
    printf("System running...\n");
    enter_sleep_mode();
    printf("Woke up from sleep mode.\n");
    return 0;
}
Output
System running... UART disabled SPI disabled Clock frequency set to 1000000 Hz Entering sleep mode... Waiting for interrupt. Woke up from sleep mode.
⚠️

Common Pitfalls

Common mistakes when reducing power consumption include:

  • Not disabling all unused peripherals, which wastes power.
  • Failing to reduce clock speed, keeping the CPU running faster than needed.
  • Forgetting to enter sleep mode properly, so the CPU never actually sleeps.
  • Not handling interrupts correctly to wake the system from sleep.

Always verify that peripherals are off and the CPU is in low power mode when idle.

embedded_c
/* Wrong way: CPU never sleeps and peripherals stay on */
void wrong_power_save() {
    // No peripheral disable
    // No clock reduction
    // No sleep instruction
}

/* Right way: Disable peripherals, reduce clock, enter sleep */
void correct_power_save() {
    DisablePeripheral("ADC");
    SetClockFrequency(800000); // 800 kHz
    __WFI();
}
📊

Quick Reference

Summary tips to reduce power consumption in embedded systems:

  • Use sleep modes: Pause CPU when idle with __WFI() or similar.
  • Disable unused peripherals: Turn off hardware modules not in use.
  • Lower clock frequency: Run CPU slower to save energy.
  • Optimize code: Minimize busy-wait loops and unnecessary processing.
  • Use interrupts: Wake CPU only when needed.

Key Takeaways

Enter sleep mode using __WFI() to pause CPU and save power.
Disable all unused peripherals to prevent unnecessary energy use.
Reduce CPU clock frequency to lower power consumption.
Use interrupts to wake the system only when needed.
Avoid busy loops and optimize code for efficiency.