Page 1 of 1

Change CPU frequency without PM API

Posted: Mon Aug 09, 2021 11:29 pm
by vinimac
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.

Re: Change CPU frequency without PM API

Posted: Tue Aug 10, 2021 1:08 am
by ESP_Sprite
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.

Re: Change CPU frequency without PM API

Posted: Tue Aug 10, 2021 11:11 pm
by vinimac
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

Re: Change CPU frequency without PM API

Posted: Wed Aug 11, 2021 1:15 am
by ESP_Sprite
Gotcha. What timer specifically are you using, and how do you configure it?

Re: Change CPU frequency without PM API

Posted: Wed Aug 11, 2021 9:38 pm
by vinimac

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);

Re: Change CPU frequency without PM API

Posted: Thu Aug 12, 2021 1:13 am
by ESP_Sprite
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.

Re: Change CPU frequency without PM API

Posted: Thu Aug 12, 2021 2:50 am
by vinimac
Alright, thanks for your reply.

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

Re: Change CPU frequency without PM API

Posted: Thu Aug 12, 2021 10:07 am
by ESP_Sprite
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.