I want to change the CPU frequency dynamically
code :
static const char *TAG = "power_save";
#if CONFIG_PM_ENABLE
static esp_pm_lock_handle_t lock_handle;
rtc_cpu_freq_t max_freq;
rtc_clk_cpu_freq_from_mhz(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ, &max_freq);
esp_pm_config_esp32_t pm_config = {
.max_cpu_freq = max_freq,
.min_cpu_freq = RTC_CPU_FREQ_XTAL
};
ESP_ERROR_CHECK( esp_pm_configure(&pm_config) );
ESP_ERROR_CHECK(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX,0,NULL,&lock_handle));
ESP_ERROR_CHECK(esp_pm_lock_acquire(lock_handle));
//I think CPU works at the maximum power at this time.
ESP_ERROR_CHECK(esp_pm_lock_release(lock_handle));
//I think CPU works at low power at this time
#endif // CONFIG_PM_ENABLE
I add delay between frequency switching
However, the working current of the development board has not changed.
Can you tell me where the problem is?
Questions about the dynamic frequency setting of CPU
-
- Posts: 11
- Joined: Tue Mar 20, 2018 7:36 am
Re: Questions about the dynamic frequency setting of CPU
This is not so — the system will be able to go the a lower power mode only when not RTOS tasks are running.//I think CPU works at low power at this time
This is because on each core, FreeRTOS will take ESP_PM_CPU_FREQ_MAX lock whenever there is any code to be run.
So your task needs to block on some synchronization primitive (mutex, queue,...) and no other tasks should run — then the system will go into lower power mode.
-
- Posts: 11
- Joined: Tue Mar 20, 2018 7:36 am
Re: Questions about the dynamic frequency setting of CPU
How to dynamically switch CPU frequency
For example, switch from 240M to 80M. from 80M to 240M.
thanks very much
For example, switch from 240M to 80M. from 80M to 240M.
thanks very much
Re: Questions about the dynamic frequency setting of CPU
In the simplest way, switching working frequency can look like this:
https://gist.github.com/igrr/a0c3b05f16 ... 8d943036e6
However, take note that:
1) There is currently a bug in IDF which makes this kind of switching between 80/160 and 240MHz impossible. I.e. you can switch between 80 and 160, but can't switch 80<->240 and 160<->240. The fix is in review and should be on Github soon.
2) Frequency switching is not possible while any power management lock is being held. This is why there is a vTaskDelay in the code — to wait until the only task in this example is idle, then frequency can be switched.
https://gist.github.com/igrr/a0c3b05f16 ... 8d943036e6
However, take note that:
1) There is currently a bug in IDF which makes this kind of switching between 80/160 and 240MHz impossible. I.e. you can switch between 80 and 160, but can't switch 80<->240 and 160<->240. The fix is in review and should be on Github soon.
2) Frequency switching is not possible while any power management lock is being held. This is why there is a vTaskDelay in the code — to wait until the only task in this example is idle, then frequency can be switched.
-
- Posts: 11
- Joined: Tue Mar 20, 2018 7:36 am
Re: Questions about the dynamic frequency setting of CPU
Excuse me,Can you give an example of wifi as an AP and udp-multicast?
-
- Posts: 11
- Joined: Tue Mar 20, 2018 7:36 am
Re: Questions about the dynamic frequency setting of CPU
Hee, I've done it
Re: Questions about the dynamic frequency setting of CPU
Hi I'm also trying to change the cpu frequency. I tried your code and they are really useful, I enabled the PM DFS setting in the menuconfig and I used your code to set the cpu frequency to 40MHz but the current is still higher than expected, I noticed there is an 8Mhz crystal in the esp32. I wonder if there is any way to chose 8MHz as my cpu frequency when I don't need a very high processing speed? Thanks!ESP_igrr wrote:In the simplest way, switching working frequency can look like this:
https://gist.github.com/igrr/a0c3b05f16 ... 8d943036e6
However, take note that:
1) There is currently a bug in IDF which makes this kind of switching between 80/160 and 240MHz impossible. I.e. you can switch between 80 and 160, but can't switch 80<->240 and 160<->240. The fix is in review and should be on Github soon.
2) Frequency switching is not possible while any power management lock is being held. This is why there is a vTaskDelay in the code — to wait until the only task in this example is idle, then frequency can be switched.
Re: Questions about the dynamic frequency setting of CPU
ESP32 does not allow us to set CPU frequency below APB frequency, and APB frequency needs to be set to 80MHz to use WiFi, BT, and some other peripherals. For this reason pm_configure does not allow setting maximum CPU frequency to a value lower than 80MHz. It is a restriction we are planning to relax eventually, along with adding support other frequencies between XTAL and 2MHz.I enabled the PM DFS setting in the menuconfig and I used your code to set the cpu frequency to 40MHz but the current is still higher than expected, I noticed there is an 8Mhz crystal in the esp32. I wonder if there is any way to chose 8MHz as my cpu frequency when I don't need a very high processing speed? Thanks!
Re: Questions about the dynamic frequency setting of CPU
But I think I already set the frequency to 40 MHz because the current is about 17 mA and the function returned success when I use it.By the way I'm not using WIFI nor BT.I will keep my config I'm current using. If there's any other alternatives to lower the frequency please keep me posted.Thanks for your help!ESP_igrr wrote:ESP32 does not allow us to set CPU frequency below APB frequency, and APB frequency needs to be set to 80MHz to use WiFi, BT, and some other peripherals. For this reason pm_configure does not allow setting maximum CPU frequency to a value lower than 80MHz. It is a restriction we are planning to relax eventually, along with adding support other frequencies between XTAL and 2MHz.I enabled the PM DFS setting in the menuconfig and I used your code to set the cpu frequency to 40MHz but the current is still higher than expected, I noticed there is an 8Mhz crystal in the esp32. I wonder if there is any way to chose 8MHz as my cpu frequency when I don't need a very high processing speed? Thanks!
Who is online
Users browsing this forum: Bing [Bot] and 101 guests