Author Topic: Sleep Power Consumption - higher in Arduino 1.6.5 (vs 1.0.X) [+solution]  (Read 29955 times)

Tomme

  • NewMember
  • *
  • Posts: 24
This has probably been answered before but I'd like to try and track down a more definitive answer.

What is the power consumption of a Moteino with the radio/flash in sleep mode and the 328p in watchdog sleep supposed to be?

I've seen mentions of 4uA but I'm getting more like 24uA on all of the Moteinos I've tested so far . Am I supposed to be getting closer to 4uA?

  • I have Moteino R4s, they have RFM69HW's and flash chips installed.
  • Using standard LPL Arduino libraries I call radio.sleep and flash.sleep after initialising both, then I enter a watchdog power down with BOC/ADC turned off.
  • I power the Moteino from a decent quality bench power supply at 4.2V and measure with a good multimeter in the microamp range.


Anyone feel like chipping in? Is 24uA what is expected in that scenario? I was expecting closer to the 4uA the 328p uses for the watchdog timer..
« Last Edit: February 16, 2016, 09:25:51 AM by Felix »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Sleep Power Consumption
« Reply #1 on: February 15, 2016, 12:38:31 PM »
then I enter a watchdog power down with BOC/ADC turned off.
Some things to check...

Do you call LowPower.powerDown(SLEEP_FOREVER...) ? or are you using wdt_ timeouts?

Is the flash chip the standard flash that comes with Moteino?

Is the FTDI cable disconnected?

Do you have any IO pins floating?

Tom

Tomme

  • NewMember
  • *
  • Posts: 24
Re: Sleep Power Consumption
« Reply #2 on: February 15, 2016, 03:27:59 PM »
Using "LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);"

Standard flash chip.

Nothing connected to any pins, but haven't explicitly pulled pins high/low. Any recommendations or better yet some example code that achieves 4uA for you?

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Sleep Power Consumption
« Reply #3 on: February 15, 2016, 04:19:20 PM »
Using "LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);"

Standard flash chip.

Nothing connected to any pins, but haven't explicitly pulled pins high/low. Any recommendations or better yet some example code that achieves 4uA for you?
Do SLEEP_FOREVER, not SLEEP_4S, at least during power testing.  Also, configure all the unused, uncoonected pins as INPUT_PULLUP or OUTPUT (polarity doesn't matter).

Tom

KeithR

  • NewMember
  • *
  • Posts: 2
  • Country: us
Re: Sleep Power Consumption
« Reply #4 on: February 15, 2016, 05:37:50 PM »
I ran into this, and observed different behavior using Arduino 1.6.x vs 1.0.5. 

I found that 1.6.x compiler has more aggressive optimization directives, generating binary with an "rjmp" between sleep_bod_disable() and sei(), causing Brown Out Detector to not turn off (too many clock cycles, see datasheet page 45).  BOD uses about 20 uA.

My fix was to add a compiler directive __attribute__((optimize("-O1"))) to the function declarations in LowPower.h to force a lower optimization level.  Sleep power consumption then worked as expected, 4uA.

Code: [Select]
Mods to LowPower.h
void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Sleep Power Consumption
« Reply #5 on: February 15, 2016, 06:14:57 PM »
@KeithR, WOW, good catch!!!

Tom

Tomme

  • NewMember
  • *
  • Posts: 24
Re: Sleep Power Consumption
« Reply #6 on: February 16, 2016, 07:09:02 AM »
Brilliant, thank you. With that compiler directive I'm down to ~6uA without doing anything about the floating pins.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sleep Power Consumption
« Reply #7 on: February 16, 2016, 09:24:02 AM »
+1 @KeithR, really good catch!

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Sleep Power Consumption
« Reply #8 on: February 19, 2016, 11:15:23 AM »
I ran into this, and observed different behavior using Arduino 1.6.x vs 1.0.5. 

I found that 1.6.x compiler has more aggressive optimization directives, generating binary with an "rjmp" between sleep_bod_disable() and sei(), causing Brown Out Detector to not turn off (too many clock cycles, see datasheet page 45).  BOD uses about 20 uA.

My fix was to add a compiler directive __attribute__((optimize("-O1"))) to the function declarations in LowPower.h to force a lower optimization level.  Sleep power consumption then worked as expected, 4uA.

Code: [Select]
Mods to LowPower.h
void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
I can confirm that this is a correct analysis of the problem as well a solution to the problem. 

I was running some low power tests on a 328P and found that the current was much higher than expected.  I confirmed that the BOD instruction sequence was reordered as Keith describes above and, using his suggested optimization attributes, did fix the code sequence, the BOD problem, and I'm happy to say, I have a Mote with an RFM69W and Si7021 spending about 99++% of its time running at about 600nA 1.13uA on a CR2032.   :)

Tom
UPDATE: Corrected the current consumption after calibrating my uCurrent Gold.  Still, I'm happy with this number (even though it means I only get 11.7 years instead of 15 from my CR2032  ;)
« Last Edit: February 19, 2016, 11:48:25 AM by TomWS »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Sleep Power Consumption - higher in Arduino 1.6.5 (vs 1.0.X) [+solution]
« Reply #9 on: February 19, 2016, 02:51:47 PM »
Thanks guys, this is now published to my branch of the LowPower library.

d00m178

  • Jr. Member
  • **
  • Posts: 82
Hello,

I have about 40uA in sleep mode
my code:
Code: [Select]
// Enter power down state for 8s with ADC and BOD module disabled
    //Serial.println(">>> go sleep");
    Serial.flush();
    flash.sleep();
    driver.sleep();
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);


I'm using Code Block instead Arduino IDE and these changes in header file leads only to "warning: 'optimize' attribute directive ignored"

more details:

Code: [Select]
Arduino Compiler & Uploader Version 0.8.9
(C)2013 Developed by Stanley Huang <stanleyhuangyc@gmail.com>, distributed under GPL license
Build Target: Arduino Duemilanove (328) (MCU: atmega328p)
Referenced libraries: [SPI]
Compiling library [SPI]...
avr-g++ -c -Os -s -pipe -fno-exceptions -ffunction-sections -fdata-sections -MMD -DARDUINO=105 -DF_CPU=16000000L -mmcu=atmega328p -Iarduino/hardware/arduino/cores/arduino -Iarduino/hardware/arduino/variants/standard -Iarduino/libraries/SPI "arduino/libraries/SPI/SPI.cpp" -o "C:\Users\ramz\AppData\Local\Temp/SPI.cpp.o"

-------------- Build: Arduino Duemilanove (328) in lora_server (compiler: GNU AVR GCC Compiler)---------------

Compiling: lora_server.ino
Compiling: LowPower.cpp
In file included from lora_server.ino:86:
LowPower.h:136: warning: 'optimize' attribute directive ignored
LowPower.h:137: warning: 'optimize' attribute directive ignored
LowPower.h:138: warning: 'optimize' attribute directive ignored
LowPower.h:139: warning: 'optimize' attribute directive ignored
In file included from LowPower.cpp:31:
LowPower.h:136: warning: 'optimize' attribute directive ignored
LowPower.h:137: warning: 'optimize' attribute directive ignored
LowPower.h:138: warning: 'optimize' attribute directive ignored
LowPower.h:139: warning: 'optimize' attribute directive ignored
Linking console executable: build\lora_server_duemilanove328.elf
Output file is build\lora_server_duemilanove328.elf with size 13.26 KB
Running target post-build steps
avr-objcopy -O ihex -R .eeprom -R .eesafe "build\lora_server_duemilanove328.elf" "build\lora_server_duemilanove328.elf.hex"
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex "build\lora_server_duemilanove328.elf" "build\lora_server_duemilanove328.elf.eep.hex"
avr-size --mcu=atmega328p --format=avr "build\lora_server_duemilanove328.elf"
AVR Memory Usage
----------------
Device: atmega328p
Program:   13200 bytes (40.3% Full)
(.text + .data + .bootloader)
Data:       1493 bytes (72.9% Full)
(.data + .bss + .noinit)
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 8 warning(s) (0 minute(s), 0 second(s))
 

TomWS

  • Hero Member
  • *****
  • Posts: 1930
I'm using Code Block instead Arduino IDE and these changes in header file leads only to "warning: 'optimize' attribute directive ignored"
I just noticed this posting and see that it hasn't been answered.  Sorry for the delay, I've been traveling.   I don't use Code Block, but there are two ways to get around this problem. 

The first is to research how to enable the optimize attribute with your build tool.  This should be an easy search to find.

The second is to modify your version of the LowPower library to replace the sleep with BOD C code with inline assembler so that the compiler doesn't optimize away the critical sequence needed to shut off BOD prior to sleeping (it must be done within 4 machine instruction sequence).  This requires a more detailed search, but I suspect you'll find some code you can cut and paste.

Tom

snorp

  • Jr. Member
  • **
  • Posts: 62
  • Country: us
I had this problem too, but the LowPower library was updated in github fairly recently to work around this. See the commit here: https://github.com/LowPowerLab/LowPower/commit/2b5225174cac52eb94577c6bff802898a61b1336

I now get the expected ~3uA power consumption when sleeping.

d00m178

  • Jr. Member
  • **
  • Posts: 82
Re: Sleep Power Consumption
« Reply #13 on: May 19, 2016, 05:41:45 AM »

..........

  Also, configure all the unused, uncoonected pins as INPUT_PULLUP or OUTPUT (polarity doesn't matter).

Tom

Is it standard practice to configure unconnected pins to OUTPUT in code?
Is it helps for better power consumption?

I still looking how to enable this hint with optimize attribute in CodeBlock because my power consumption is about 43 uA in sleep mode..
 
Thanks.
 

RobertBil

  • NewMember
  • *
  • Posts: 1
  • Country: us
Re: Sleep Power Consumption - higher in Arduino 1.6.5 (vs 1.0.X) [+solution]
« Reply #14 on: August 16, 2016, 12:05:30 PM »
Hi..i am a new user here. In my case i found that 1.6.x compiler has more aggressive optimization directives, generating binary with an "rjmp" between sleep_bod_disable() and sei(), causing Brown Out Detector to not turn off (too many clock cycles, see datasheet page 45).  BOD uses about 20 uA.