tomjorquera / pico-micropython-lowpower-workaround

Workaround for low power support in micropython for the Raspberry pico
GNU Lesser General Public License v3.0
58 stars 12 forks source link

Unstable power consumption in Dormant mode #6

Closed anairo11 closed 1 year ago

anairo11 commented 2 years ago

I have an rp2040 programmed to stay in dormant mode using the library you created, it wakes up every time a certain interrupt occurs.

When the rp is in the Dormant state, it consumes more mA than expected and in an unstable way, for example, it is in dormant consuming 1.1mA , then it is woken up by a clock interrupt and on its next entry into dormant mode, its consumption is 2.4mA and so on, where its minimum consumption in dormant has been 1.1mA and its maximum 5.1mA.

I have read the rp2040 datasheet and in the "Dormant state" section (page 189 https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) and as I understand it, to avoid additional energy consumption in this mode, You must turn off the PLLs before entering the DORMANT state and then start and configure the PLLs again after exiting the DORMANT mode.

Now, regarding how to enable or disable the PLLs, I find examples like these: pll_deinit(pll_sys); pll_init(pll_sys, 1, 1596 * MHz, 6, 2); however, I am still not clear on how to implement everything together (Dormant + DLL management) but I'm creating this post to see if we can move forward along this line!

I really appreciate your great contribution with this library to handle the DORMANT mode and really lower the consumption of the rp2040 to amazing levels!!!

tomjorquera commented 2 years ago

Hey @anairo11, sorry for the late reply and thanks for the info!

I don't have much time to work on the lib currently, but I will try to dig in regarding what you describe.

Do you have some example code that allows to reproduce the inconsistent power consumption by any chance?

ABelliqueux commented 1 year ago

Also, in the datasheet, in section 2.15.2.5, p.185 :

The PLLs are not affected by SLEEP mode. If the user wants to save power in SLEEP mode then all clock generators must be switched away from the PLLs and they must be stopped in software before entering SLEEP mode. The PLLs are not stopped and restarted automatically when entering and exiting DORMANT mode. If they are left running on entry to DORMANT mode they will be corrupted and will generate out of control clocks that will consume power unnecessarily. This happens because their reference clock from XOSC will be stopped. It is therefore essential to switch all clock generators away from the PLLs and stop the PLLs in software before entering DORMANT mode.

Informations regarding these PLLs are in section 2.18, p.228.

Would it be possible to dump the PLL registers before going dormant, and filling them on wake ?

tomjorquera commented 1 year ago

Hey folks,

With the merge of #11, we now try to handle the clocks a little better. It should handle the USB PLL, and improve on the situation somewhat.

Nothing is done regarding the SYS PLL at this stage. I need to find some time to read further into the doc and do some testing.

If somebody wants to make a stab at it, it should be somewhat easier now by taking inspiration on how things are done for the USB PLL.

Yoda-Soda commented 1 year ago

Hey folks,

With the merge of #11, we now try to handle the clocks a little better. It should handle the USB PLL, and improve on the situation somewhat.

Nothing is done regarding the SYS PLL at this stage. I need to find some time to read further into the doc and do some testing.

If somebody wants to make a stab at it, it should be somewhat easier now by taking inspiration on how things are done for the USB PLL.

This is way more stable! Thanks