Page 1 of 1
ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 9:00 am
by stefan.erni
In the menueconfig I can set the clock to 80Mhz,160Mhz,240Mhz with the result that power consumption is reduced.
However, this applies to all boards with the same ESP32
It is also possible to make the individual clock with a C-code.
I have tried, there is no error but the clock is not changed either
Menu working:

- 2025-05-06_09-52-28.PNG (36.17 KiB) Viewed 3187 times
C-Code in main:

- 2025-05-06_09-06-27.PNG (134.56 KiB) Viewed 3187 times
Supplementary Code:

- 2025-05-06_09-06-00.PNG (36.65 KiB) Viewed 3187 times
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 10:04 am
by mnfisher
esp_pm_configure(&pm_config); 'should' do this. I've tested - and you need to have power management enabled in menuconfig (component config/power management).
Note that delays should still work correctly (this is handled by RTOS)
I use 5.3.2 - and esp_clk.h is now 'private' - and may disappear. Location may be different (see supplementary code)
Allowing light sleep (set to true in Set80MHz) - seems to stop the clock changing.
The output - shows clock before and after change:
Clock test
Clock Set = 240000000
fÚšâ–’j%â–’(453) pm: Frequency switching config: CPU_MAX: 80, APB_MAX: 80, APB_MIN: 80, Light sleep: DISABLED
Clock Set = 80000000
Martin
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 11:02 am
by stefan.erni
Hi Martin
Ok I have tried but a small error...
idf/main/CMakeFiles/__idf_main.dir/esp-project.c.obj -c C:/Users/stefan.erni/Desktop/esp-idf-2/mtxesp32s_sdkconfig/main/esp-project.c
C:/Users/stefan.erni/Desktop/esp-idf-2/mtxesp32s_sdkconfig/main/esp-project.c: In function 'FCM_Set80MHz':
C:/Users/stefan.erni/Desktop/esp-idf-2/mtxesp32s_sdkconfig/main/esp-project.c

3: error: unknown type name 'esp_pm_config_t'; did you mean 'esp_netif_config_t'?
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 11:07 am
by mnfisher
That's odd - which version of the tools are you using?
Have you enabled the power management option?
Martin
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 11:23 am
by stefan.erni
IDF Version: v5.0.6 ...
I have tested both settings:

- 2025-05-06_12-18-59.PNG (23.2 KiB) Viewed 3161 times

- 2025-05-06_12-18-59.PNG (23.2 KiB) Viewed 3161 times
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 11:41 am
by mnfisher
There was deprecated struct - this must be only available on later versions
I'm out at present and can't remember my first attempt - which used the old version...
Martin
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Tue May 06, 2025 11:01 pm
by mnfisher
I don't have anything less than 5.1.4 (and BT are running in treacle tonight) - but try changing the struct from esp_pm_config_t to esp_pm_config_esp32_t
Otherwise hopefully everything else would be the same?
I tested using 5.1.4 (the earliest I have installed) and it does work - using the older struct name. However - the 'change' in clock speed doesn't take place until the MCU has an idle section - this is easily achieved by adding a delay....
Martin
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Wed May 07, 2025 7:45 am
by stefan.erni
Hi Martin
Perfect! It's working nice.
It is very comfortable to use. Just import the macro and place it at the begin.
If you need to test with 240Hz just toggle disable the macro.
With this setting my recorder runs twice as long on one battery charge

The whole board needs:
40mA-50mA at 80Mhz
80mA-100mA at 240Mhz
2mA at lightsleepmode for both clock
Main:

- 2025-05-07_08-24-00.PNG (25.5 KiB) Viewed 2891 times
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Wed May 07, 2025 9:28 pm
by mnfisher
The idea of dynamic frequency scaling is quite appealing - what happens on setting max speed to 240MHz and min to 80MHz.
Also - are other speeds allowed (40MHz?) - underclocking further, might give further power savings.
Have you tested the power requirement in deep sleep too? It can wake on a timer - and depending on the sample interval might give further savings?
Martin
Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz
Posted: Mon May 12, 2025 8:07 am
by stefan.erni
Hi Martin
Yes deep sleep save power.
On my complet board:
deep sleep =0.7mA
light sleep = 2.0mA