# An Energy-Efficient Strategy for Microcontrollers
## 5 Analysis and Suggestions  
Based on our analytical models and test results, in this section, we will discuss how to achieve higher energy efficiency on embedded SoCs. The electric current consumed while working shows a linear increase with an increase in the processor frequency, and the execution time shows an inverse proportional decrease with an increase in the processor frequency. According to the results shown in Figure 6, under ideal circumstances, when the processor is executing computationally intensive tasks, the energy consumption of the processor is not related to the clock frequency of the processor. In other words, regardless of whether the processor clock frequency increases or decreases, the processor will complete the ideal computationally intensive task with the same energy consumption, which means that E\({}_{\text{af}}\) should be equal to E\({}_{\text{of}}\) in Equation (2). In the meantime, the power consumption of peripheral components remains basically constant despite different processor clock frequencies. Moreover, when the whole system enters power-saving modes, the power consumption of peripheral components is also decreased. Thus, as long as the existence of peripheral components and their power consumption is inevitable, the energy consumed by the whole system can be saved by increasing the processor clock frequency. Although increasing the processor clock frequency cannot reduce the energy consumed by the microcontroller itself in executing applications, it can shorten the power-on period of both the processor and peripheral components, thereby reducing the energy consumed by the peripheral components. In other words, for computationally intensive tasks, running at low frequency cannot save energy due to the increment of the energy consumed by the peripheral components. Since the working current in each status is relatively constant, the energy consumption in Equation (1) can be converted into Equation (18), the sum of the energy consumption of several statuses. The energy consumption of each status is the product of the voltage, the working current, and the duration. \[\text{E}(\mu\text{J})=\Sigma[\text{U}(\text{V})\times\text{I}(\text{mA})\times \text{t}(\text{ms})] \tag{18}\]  
Take a periodic task whose task period is 100 ms as an example. The task runs on a device that is powered by a DC 5 V power supply. When the processor clock frequency is set at 16 MHz, it takes 50 ms to complete, and the system enters sleep mode in the remaining 50 ms. The energy consumption per task period is  
\[\text{E}_{\text{16 MHz}}=5\times 12.05\times 50+5\times 6.23\times 50=4570 \text{ \mu J} \tag{19}\]  
If the processor clock frequency is configured to 128 MHz, the task will complete in 6.25 ms, and the sleep stage will last 93.75 ms. In this case, the energy consumption per task cycle is  
\[\text{E}_{\text{128 MHz}}=5\times 39.49\times 6.25+5\times 6.23\times 93.75=4154.375\text{ \mu J} \tag{20}\] \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Mode** & **Working Current (mA)** & **Power Consumption (mW)** & **Wake-Up Time (ms)** \\ \hline Active & 50.23 & 251.15 & N/A \\ Light sleep & 12.21 & 61.05 & 0.44 \\ Deep sleep & 11.07 & 55.35 & 115 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Working current, power consumption, and wake-up time of the ESP32 module in different power modes. Our results show that the transition of the processor clock frequency requires a considerable amount of time and significant energy overhead, approximately 70 ms, and 4.218 mJ each time. Thus, the DVFS technology must be carefully considered before being used. It will not only introduce additional overhead on energy consumption but also affect the real-time performance of the entire embedded system. If the energy saved by adjusting processor clock frequency is less than 4.218 mJ, or the system cannot tolerate an unresponsive period of 70 ms, utilizing DVFS technology is neither worthwhile nor suitable. This also applies to power-saving modes.