Low power mode pyb.wfi()

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
zs6mdh
Posts: 9
Joined: Fri Mar 07, 2014 4:58 am

Low power mode pyb.wfi()

Post by zs6mdh » Mon Oct 27, 2014 5:14 pm

Is there any documentation on pyb.wfi() ?

Ive searched plenty, and even tried to look at the source. Im a little lost there.

According to the datasheet for the processor there are various levels of sleep/power down modes. Can we choose the different modes with pyb.wfi().

Im sure I read somewhere a while ago on what the current consumption is in low power mode but cannot find it now. Does anyone have details on this?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Low power mode pyb.wfi()

Post by dhylands » Mon Oct 27, 2014 5:47 pm

WFI is a CPU instruction that basically means "Wait For Interrupt".

Basically, the CPU stops executing instructions and waits for an interrupt to occur.

I don't believe that WFI has any choice about types of modes. That's really outside the scope of wfi.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Low power mode pyb.wfi()

Post by Damien » Mon Oct 27, 2014 9:58 pm

Using pyb.wfi() allows you to reduce power consumption by about 1/2 if you are waiting in a loop.

Consider:

Code: Select all

sw = pyb.Switch()
while True:
    if sw():
        print("switch pressed")
versus:

Code: Select all

sw = pyb.Switch()
while True:
    if sw():
        print("switch pressed")
    pyb.wfi()
The second code will run the same, but use about 1/2 the power. This is because the wfi instruction pauses the CPU, waiting for an internal or external interrupt. Since the systick timer interrupts at 1kHz, wfi() waits at most for 1ms (unless irqs are disabled). It's always a good idea to put wfi() in a "busy" loop like the one above.

The other power saving modes are pyb.stop() and pyb.standby(). pyb.stop() works well, and the CPU is woken on an external interrupt (see ExtInt class).

pyb.standby() is woken only by RTC alarm (not currently implemented) and special external interrupts.

You can also adjust the CPU frequency to reduce power consumption: pyb.freq(30000000) will clock down to 30MHz and save you a lot of power.

inaugurator
Posts: 23
Joined: Tue Sep 30, 2014 4:02 pm

Re: Low power mode pyb.wfi()

Post by inaugurator » Sat Nov 01, 2014 8:57 pm

Hi all.
I try to reduce frequency with pyb.freq(30000000), but after this command pyboard hungs without any reacts. I was trying other values, but it behaves the same.
What I am doing wrong?

In the docs is written not all. For example, about pyb.SD class I did not find any information. Where I can find some info about available frequencies?
Evgeny

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Low power mode pyb.wfi()

Post by dhylands » Sat Nov 01, 2014 10:27 pm

Do you have recent firmware?

You can check the firmware version when you start the REPL. You should see a line something like this:

Code: Select all

Micro Python v1.3.3-92-gfb765bc-dirty on 2014-10-22; PYBv1.0 with STM32F405RG
Anything earlier than Oct 5 doesn't have the proper frequency changing code.

inaugurator
Posts: 23
Joined: Tue Sep 30, 2014 4:02 pm

Re: Low power mode pyb.wfi()

Post by inaugurator » Sat Nov 01, 2014 11:13 pm

I use Micro Python v1.3.5 on 2014-10-29; PYBv1.0 with STM32F405RG
Evgeny

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Low power mode pyb.wfi()

Post by Damien » Sat Nov 01, 2014 11:18 pm

The pyb.freq() command supports frequencies (in MHz) between 24MHz and 168MHz, and it rounds them to a compatible value. Sometimes when you change the frequency while connected over USB you will lose the USB connection, but this doesn't happen very often. And I think pyb.freq(24000000) doesn't allow USB to work at all. But otherwise it should be working.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Low power mode pyb.wfi()

Post by Damien » Sat Nov 01, 2014 11:19 pm

Are you typing pyb.freq(30000000) at the REPL prompt when connected over the USB serial? Can you try pyb.freq(168000000) and also pyb.freq() to see what the output of that says?

inaugurator
Posts: 23
Joined: Tue Sep 30, 2014 4:02 pm

Re: Low power mode pyb.wfi()

Post by inaugurator » Sat Nov 01, 2014 11:21 pm

I want give more information, but don't know method: pyboard does not return traceback or something else.
Evgeny

inaugurator
Posts: 23
Joined: Tue Sep 30, 2014 4:02 pm

Re: Low power mode pyb.wfi()

Post by inaugurator » Sat Nov 01, 2014 11:22 pm

pyb.freq(168000000) - same result.
Evgeny

Post Reply