Page 1 of 3
Low power mode pyb.wfi()
Posted: Mon Oct 27, 2014 5:14 pm
by zs6mdh
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?
Re: Low power mode pyb.wfi()
Posted: Mon Oct 27, 2014 5:47 pm
by dhylands
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.
Re: Low power mode pyb.wfi()
Posted: Mon Oct 27, 2014 9:58 pm
by Damien
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.
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 8:57 pm
by inaugurator
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?
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 10:27 pm
by dhylands
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.
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 11:13 pm
by inaugurator
I use Micro Python v1.3.5 on 2014-10-29; PYBv1.0 with STM32F405RG
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 11:18 pm
by Damien
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.
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 11:19 pm
by Damien
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?
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 11:21 pm
by inaugurator
I want give more information, but don't know method: pyboard does not return traceback or something else.
Re: Low power mode pyb.wfi()
Posted: Sat Nov 01, 2014 11:22 pm
by inaugurator
pyb.freq(168000000) - same result.