Too much power consumption in STOP mode using STM32sleep library

acobo
Fri May 12, 2017 10:01 am
Hello to all,
I have tried this simple program:

#include <STM32Sleep.h>
#include <RTClock.h>

RTClock rt(RTCSEL_LSE);
long int alarmDelay = 5;

void setup() {
// Disable ADC to save power
adc_disable_all();

// Set all GPIO pins to Analog input to save power (this disables pretty
// much all I/O incl. Serial)
setGPIOModeToAllPins(GPIO_INPUT_ANALOG);

// first a period in STOP mode, then STANDBY
sleepAndWakeUp(STOP, &rt, alarmDelay); // sleeping in stop mode for 5 seconds, then ...
sleepAndWakeUp(STANDBY, &rt, alarmDelay); // sleeping in standby mode for 5 seconds, then RESET
}

void loop() {
// We have woken up from sleep! System clock is set to 8MHz HSI.
// but never reach here
}


edogaldo
Fri May 12, 2017 10:12 am
Is there a voltage regulator that could consume some current?
In the blue pill maybe you have also to consider the current drawn by the USB circuitry (pullup resistor) if powering via USB.

ahull
Fri May 12, 2017 11:34 am
I’m impressed that you can accurately measure 20uA :o

800uA by my back of the envelope calculation suggests a load of around 4kOhms at 3.3V

Maybe if we had a few pictures of your setup and how you are measuring, and perhaps the full schematic of the bare STM32 only board that might shed some light on the problem. I must confess that in my low power experiments when I got to sub 1mA I figured I was doing pretty well.


ag123
Fri May 12, 2017 11:51 am
maybe put an LM741 opamp with pretty much its open loop gain & feed that to adc pin, or add an elaborate whetstone bridge, but i’d guess accuracy would still be a problem :lol:
http://www.ti.com/lit/ds/symlink/lm741.pdf
https://en.wikipedia.org/wiki/Wheatstone_bridge

the other thing that may be tried is perhaps replace that high dropout ams1117 regulator with a ‘real’ LDO http://www.stm32duino.com/viewtopic.php … 061#p27657 & use 5000 mAH LiPo batteries, 24×365 ~ 8760 hours so i’d guess that may last say 1/2 year before needing recharge

and these days there are monster usb power banks like this 100000mAH LiPo power bank with solar cells thrown in :lol:
http://www.ebay.com/itm/New-100000mAh-D … 2162353948


acobo
Fri May 12, 2017 12:28 pm
Thank you all for your replies,
I forgot to mention that I am not using any voltage regulator. The blue pill board is powered through the 3.3V pin, so only the output of the inactive regulator is seen by the power supply. The other board (custom PCB) has no regulator at all (3V non-rechargable lithium battery) and the current is exactly the same.
The schematics I am using is this:

circuit.PNG
circuit.PNG (30.89 KiB) Viewed 1188 times

ahull
Fri May 12, 2017 12:31 pm
ag123 wrote:
..the other thing that may be tried is perhaps replace that high dropout ams1117 regulator with a ‘real’ LDO http://www.stm32duino.com/viewtopic.php … 061#p27657 & use 5000 mAH LiPo batteries, 24×365 ~ 8760 hours so i’d guess that may last say 1/2 year before needing recharge

and these days there are monster usb power banks like this 100000mAH LiPo power bank with solar cells thrown in :lol:
http://www.ebay.com/itm/New-100000mAh-D … 2162353948


ag123
Fri May 12, 2017 12:32 pm
@acobo
the other thing would be about the clocks, i’m not too sure if simply doing stop would turn off the peripheral clocks, i’d guess one way is to stop all the APB1 and APB2 clocks as well and check power consumption

as for precise measurements, i’m thinking the inactive AMS1117 may literally be taking some power. hence for a ‘real’ test u may need to unsolder that ams1117 and put that back later :lol:
http://www.advanced-monolithic.com/pdf/ds1117.pdf

@ahull
agreed, lipo size is a trouble, that’s why all that fuss looking for a ‘real’ LDO that drop less than < 0.5v :lol:


victor_pv
Fri May 12, 2017 1:12 pm
ag123 wrote:@acobo
the other thing would be about the clocks, i’m not too sure if simply doing stop would turn off the peripheral clocks, i’d guess one way is to stop all the APB1 and APB2 clocks as well and check power consumption

as for precise measurements, i’m thinking the inactive AMS1117 may literally be taking some power. hence for a ‘real’ test u may need to unsolder that ams1117 and put that back later :lol:
http://www.advanced-monolithic.com/pdf/ds1117.pdf

@ahull
agreed, lipo size is a trouble, that’s why all that fuss looking for a ‘real’ LDO that drop less than < 0.5v :lol:


zoomx
Fri May 12, 2017 1:20 pm
He measured the same power consumption using a custom board without any regulator.
This is strange since I expect some consumption on bluepill due to the regulator like in the Arduino Pro Mini where I have to cut the regulator trace to obtain a real low power.

acobo
Fri May 12, 2017 1:45 pm
victor_pv wrote:ag123 wrote:@acobo
the other thing would be about the clocks, i’m not too sure if simply doing stop would turn off the peripheral clocks, i’d guess one way is to stop all the APB1 and APB2 clocks as well and check power consumption

as for precise measurements, i’m thinking the inactive AMS1117 may literally be taking some power. hence for a ‘real’ test u may need to unsolder that ams1117 and put that back later :lol:
http://www.advanced-monolithic.com/pdf/ds1117.pdf

@ahull
agreed, lipo size is a trouble, that’s why all that fuss looking for a ‘real’ LDO that drop less than < 0.5v :lol:


ag123
Fri May 12, 2017 2:17 pm
i did a little bit of reading in rm0008,
p73 5.3.4 Stop mode
The Stop mode is based on the Cortex®-M3 deepsleep mode combined with peripheral
clock gating. The voltage regulator can be configured either in normal or low-power mode.
In Stop mode, all clocks in the 1.8 V domain are stopped, the PLL, the HSI and the HSE RC
oscillators are disabled. SRAM and register contents are preserved.
In the Stop mode, all I/O pins keep the same state as in the Run mode.

it didn’t seem to suggest that the peripheral clocks would be stopped automatically, hence you may like to try stopping the clocks

then there is also the standby mode
p75 5.3.5 Standby mode
The Standby mode allows to achieve the lowest power consumption. It is based on the
Cortex®-M3 deepsleep mode, with the voltage regulator disabled. The 1.8 V domain is
consequently powered off. The PLL, the HSI oscillator and the HSE oscillator are also
switched off. SRAM and register contents are lost except for registers in the Backup domain
and Standby circuitry (see Figure 4).
I/O states in Standby mode
In Standby mode, all I/O pins are high impedance except:
• Reset pad (still available)
• TAMPER pin if configured for tamper or calibration out
• WKUP pin, if enabled

hence you may like to try standby mode as well

oh and use a *real* LiPo LDO that drop out less than < 0.5v if you need that (e.g. running on 4.2v), that 1 Amp ams1117 is apparently not to reduce power more than its cost effectiveness regulating 5v to 3.3v and gives 1 A output reducing complaints about insufficient power. who knows someone may use blue pill to drive their 3d printer hot end :lol:

just 2 cents, hope it helps


victor_pv
Fri May 12, 2017 3:19 pm
acobo wrote:victor_pv wrote:ag123 wrote:@acobo
the other thing would be about the clocks, i’m not too sure if simply doing stop would turn off the peripheral clocks, i’d guess one way is to stop all the APB1 and APB2 clocks as well and check power consumption

as for precise measurements, i’m thinking the inactive AMS1117 may literally be taking some power. hence for a ‘real’ test u may need to unsolder that ams1117 and put that back later :lol:
http://www.advanced-monolithic.com/pdf/ds1117.pdf

@ahull
agreed, lipo size is a trouble, that’s why all that fuss looking for a ‘real’ LDO that drop less than < 0.5v :lol:


acobo
Fri May 12, 2017 7:02 pm
victor_pv wrote:acobo wrote:victor_pv wrote:
The library has a function for disabling the clocks, I did not see it called when entering any mode. I think you are supposed to call it in your code if you want to stop the clock to all peripherals.
I may have missed the call to that function, if so, please let me know.

victor_pv
Fri May 12, 2017 7:09 pm
acobo wrote:victor_pv wrote:acobo wrote:

ag123
Fri May 12, 2017 7:53 pm
i think rm0008 p80 6 backup registers discussed backup registers (16 registers making up 84 bytes)

another way though in the STOP mode, you may try to put all the pins that you don’t use (e.g. the led pin) into tristate mode or even all of them into tristate mode (depending on the context)
pinMode(pin, INPUT_FLOATING);


ahull
Fri May 12, 2017 10:46 pm
If you use name brand LiPo or LiIon cells then the self discharge rate will be in the datasheet. Typical values can be inferred from the information here. http://batteryuniversity.com/learn/arti … _discharge

If you use cheap off brand “Chinesium” cells, your on your own.


victor_pv
Sat May 13, 2017 2:25 am
Just checked with the STM Cube MX tool, in stop mode is supposed to take about 46uA with voltage regulator in ON mode, and 38uA with regulator in LP mode.

Are you sure there is nothing else that may be draining some of that current, and also that whatever you use to measure the current is completely accurate?

EDIT:
And out of curiosity I checked a couple other power modes. Sleep mode with HSI at 8Mhz is 800uA. I suspect the library may be getting you in SLEEP mode rather than STOP mode.


stylon
Tue May 16, 2017 12:30 pm
Some time ago I came across this useful thread on the ChibiOS forum: http://www.chibios.com/forum/viewtopic. … 9&start=10. User barthess seems to be very experienced in low-power modes and he hints at the fact that the STM32 DEBUG mode prevents FCLK or HCLK to be turned off at all. You must disable DEBUG mode to be able to do so. Explanations how to do that are also there (in reply by user saraben).

ag123
Thu May 25, 2017 9:32 am
on a side note, i noted that the systick interrupt
https://github.com/rogerclarkmelbourne/ … /systick.c
http://docs.leaflabs.com/static.leaflab … le-systick

runs every millisecond, it does something ‘important’, it updates the systick_uptime_millis system uptime counter;
this is where millis() and micros() provides values from.

hence the processor may be actually awake as “wfi” (wait for interrupt) and “wfe” (wait for event) would wakeup with the systick interrupt.
hence to conserve power it may be necessary to
1) configure the systick interrupt to a lower priority so that “wfi” or “wfe” won’t wake it up
or
2) systick_disable();

there’s also something from usb side which i’m not too familar if usb fires interrupts. i think usb do have a ‘start of frame’ interrupt that fires every millisecond. but i’m not sure if it sof interrupt is enabled or say disconnecting usb would stop that


ag123
Sat Jun 03, 2017 5:43 pm
the main trouble with systick is *it keeps the mcu awake*
the systick interrupt mainly updates systick_uptime_millis
https://github.com/rogerclarkmelbourne/ … tick.c#L84
i think this is used by the functions millis(), micros(), and you may be caught off guard but delay() uses millis()
so if you have codes that dodelay(100) //delay 100ms

Leave a Reply

Your email address will not be published. Required fields are marked *