# An Energy-Efficient Strategy for Microcontrollers
## 5 Analysis and Suggestions
Different power-saving modes have different effects on saving energy and have different overheads on returning to normal mode. It should be noted that, when waking up from stop and standby mode, the system clock and peripheral IO clocks should be reinitialized, or it could stay at a default clock frequency. According to Table 3, the overhead of sleep mode is only 0.6745 us, and it can be ignored, so sleep mode can be applied anywhere needed. Although stop mode and standby mode have a much better energy-saving effect than sleep mode does, if clock reconfiguration is required after waking up, sleep mode is more applicable for \"short sleep\". From Table 2, the power consumption of sleep mode and stop mode is about 31.1 mW and 22.8 mW. To calculate the minimum time for stop mode, Equation (13) is referenced:  
\[\text{t}_{\text{stopmin}}=\frac{E_{oh}}{P_{sleep}-P_{stop}}=\frac{4.218\;\text{ mJ}}{31.1\;\text{mW}-22.8\;\text{mW}}=508\;\text{ms} \tag{21}\]  
This means only when the \"sleep time\" is longer than 508 ms can stop mode save more energy than sleep mode. Although standby mode has an extremely low power consumption of about 4.65 mW, all the data stored in registers and RAM will be lost. The application scenarios of standby mode are more restrictive. Even if the side effects of standby mode are ignored, compared with sleep mode,  
\[\text{t}_{\text{standbymin}}=\frac{E_{oh}}{P_{sleep}-P_{standy}}=\frac{4.218\; \text{mJ}}{31.1\;\text{mW}-4.65\;\text{mW}}=159\;\text{ms} \tag{22}\]  
The sleep time has to be longer than 159 ms to show the advantage of standby mode. Since sleep mode does not require system clock reconfiguration, it can be applied almost anywhere needed, and stop mode and standby mode can also be applied wherever HSI or HSE is used as the system clock source. However, when PLL is used as the system clock source, due to the energy consumed by clock reconfiguration, stop mode and standby mode require a minimum sleep period of about 508 ms and 159 ms, respectively. Otherwise, the energy saved will not cover the overhead of clock reconfiguration. Table 5 indicates which power-saving mode will have the best energy-saving effect under different conditions. For the ESP32 module, the time required to wake up from light-sleep mode is significantly less than the time to wake up from deep-sleep mode. Although the light-sleep mode contributes less to power saving, the connection to the AP is maintained in this mode. Thus, if it is required to maintain the connection to the AP, the deep-sleep mode cannot be used. Our results show that waking up from deep-sleep mode requires a considerable amount of time and significant energy overhead, approximately 115 ms, and 27.393 mJ \begin{table}
\begin{tabular}{c c c c} \hline
**Clock Source and** & **Memory Loss** & **Sleep Time (ms)** & **Best Choice** \\
**Frequency** & **Acceptable?** & & \\ \hline HSI/HSE & Yes & Any & Standby mode \\  & No & Any & Stop mode \\  & Yes & \textless{}159 & Sleep mode \\ PLL & & \textless{}508 & Sleep mode \\  & No & \textgreater{}508 & Stop mode \\ \hline \end{tabular}
\end{table} 
Table 5: Best choice of STM32F407 power-saving modes under different conditions. each time. Thus, the application of deep-sleep mode should be strictly limited. Referring to Equation (13), the minimum sleep time for deep-sleep mode can be calculated as  
\[\text{t}_{\text{deep-sleepmin}}=\frac{E_{oh-down}-E_{oh-light}}{P_{deep-sleep}- P_{light-sleep}}=\frac{27.393\text{ mJ}-0.078\text{ mJ}}{61.05\text{ mW}-55.35\text{ mW}}\approx\text{ 4.792\ s} \tag{23}\]  
The application of deep-sleep mode should be carefully considered, as it will not only introduce additional overhead on energy consumption but also affect the real-time performance of the entire system. This means that, if the sleep time in deep-sleep mode is shorter than 4.792 s, the energy consumption cannot be saved. Table 6 lists out which low-power mode of the ESP32 module will achieve the best energy-saving effect under different conditions.