Change CPU frequency without PM API

vinimac
Posts: 24
Joined: Sun May 06, 2018 1:04 pm

Change CPU frequency without PM API

Postby vinimac » Mon Aug 09, 2021 11:29 pm

Hello. I would like to change CPU frequency but without power manager API because I am having problems with timer accuracy when PM is enabled.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Change CPU frequency without PM API

Postby ESP_Sprite » Tue Aug 10, 2021 1:08 am

Changing CPU frequency without involving the PM API will only lead to more timer inaccuracies, as a lot of peripherals are dependent on the APB clock (which is partially connected to the CPU frequency); changing that without telling those drivers that something changed will mess things up, and the PM API is supposed to do that.

As an alternative, can you say what your issue is with timing inaccuracies? Perhaps there is a way to fix it or work around it.

vinimac
Posts: 24
Joined: Sun May 06, 2018 1:04 pm

Re: Change CPU frequency without PM API

Postby vinimac » Tue Aug 10, 2021 11:11 pm

We are using the PM api function esp_pm_configure() with 10Mhz and 80Mhz clock speed and the 40Mhz oscillator and we are satisfied with the power consumption when running on 10MHz.
However when we enable the PM our timer is running 1.5 second fast over a minute so that timing accuracy is not acceptable. We would be happy if we could be within a second or two accuracy after a day so our timing goals are not unreasonable and we can easily attain this accuracy without the PM. What is causing the PM to throw off our timer accuracy and how can we fix this?

When running in 80MHz without PM, the timer accuracy is ok. But we need to switch to 10MHz to save power. And when we enable the PM, it happens what I mentioned. We are using the high resolution timer.

Thanks

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Change CPU frequency without PM API

Postby ESP_Sprite » Wed Aug 11, 2021 1:15 am

Gotcha. What timer specifically are you using, and how do you configure it?

vinimac
Posts: 24
Joined: Sun May 06, 2018 1:04 pm

Re: Change CPU frequency without PM API

Postby vinimac » Wed Aug 11, 2021 9:38 pm

Code: Select all

esp_timer_handle_t timer1;
void init_timer(int timer_period_us)
{
    int64_t t_end;
    esp_timer_create_args_t args = {
            .callback = &timer_func,
            .arg = &t_end,
            .name = "timer1"
    };
    //----
    esp_timer_create(&args, &timer1);
    esp_timer_start_periodic(timer1, timer_period_us);
    //esp_timer_delete(timer1);
}
// 1 sec high resolution timer
init_timer(1000000);

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Change CPU frequency without PM API

Postby ESP_Sprite » Thu Aug 12, 2021 1:13 am

I think this is a documented issue with those timers. If your application is OK with some jitter, you could try setting skip_unhandled_events in the config struct, that way your time should stay stable long-term.

vinimac
Posts: 24
Joined: Sun May 06, 2018 1:04 pm

Re: Change CPU frequency without PM API

Postby vinimac » Thu Aug 12, 2021 2:50 am

Alright, thanks for your reply.

But what options do we have for a timer with no jitter and low power?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Change CPU frequency without PM API

Postby ESP_Sprite » Thu Aug 12, 2021 10:07 am

That is complicated, I don't think there is a wakeup source for a timer in the way you need it... an option might be to disable (automatic) light sleep altogether, but I don't know what that does for your power use.

Who is online

Users browsing this forum: No registered users and 82 guests