ESP32 Poweroption 80Mhz,160Mhz,240Mhz

For general Flowcode discussion that does not belong in the other sections.
Post Reply
stefan.erni
Valued Contributor
Posts: 1009
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 192 times
Been thanked: 217 times

ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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
2025-05-06_09-52-28.PNG (36.17 KiB) Viewed 3162 times


C-Code in main:
2025-05-06_09-06-27.PNG
2025-05-06_09-06-27.PNG (134.56 KiB) Viewed 3162 times
Supplementary Code:
2025-05-06_09-06-00.PNG
2025-05-06_09-06-00.PNG (36.65 KiB) Viewed 3162 times

mnfisher
Valued Contributor
Posts: 1487
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 137 times
Been thanked: 715 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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
Attachments
esp32_clock.fcfx
(13.76 KiB) Downloaded 16 times

stefan.erni
Valued Contributor
Posts: 1009
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 192 times
Been thanked: 217 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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:2268:3: error: unknown type name 'esp_pm_config_t'; did you mean 'esp_netif_config_t'?

mnfisher
Valued Contributor
Posts: 1487
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 137 times
Been thanked: 715 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post by mnfisher »

That's odd - which version of the tools are you using?

Have you enabled the power management option?

Martin

stefan.erni
Valued Contributor
Posts: 1009
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 192 times
Been thanked: 217 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post by stefan.erni »

IDF Version: v5.0.6 ...

I have tested both settings:
2025-05-06_12-18-59.PNG
2025-05-06_12-18-59.PNG (23.2 KiB) Viewed 3136 times
2025-05-06_12-18-59.PNG
2025-05-06_12-18-59.PNG (23.2 KiB) Viewed 3136 times

mnfisher
Valued Contributor
Posts: 1487
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 137 times
Been thanked: 715 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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

mnfisher
Valued Contributor
Posts: 1487
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 137 times
Been thanked: 715 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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
Attachments
esp32_clock.fcfx
(13.79 KiB) Downloaded 21 times

stefan.erni
Valued Contributor
Posts: 1009
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 192 times
Been thanked: 217 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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
2025-05-07_08-24-00.PNG (25.5 KiB) Viewed 2866 times

mnfisher
Valued Contributor
Posts: 1487
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 137 times
Been thanked: 715 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post 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

stefan.erni
Valued Contributor
Posts: 1009
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 192 times
Been thanked: 217 times

Re: ESP32 Poweroption 80Mhz,160Mhz,240Mhz

Post by stefan.erni »

Hi Martin

Yes deep sleep save power.
On my complet board:
deep sleep =0.7mA
light sleep = 2.0mA

Post Reply