Sleep and Current Consumption

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

I'm having trouble with basic sleeping - my aim is to minimize current consumption - currently with this board (below image) I get ~5mA drained when asleep and 15mA drained when active (after the button is pressed): 5mA seems way too high still, I'm after much lower if possible - I don't feel as though I'm switching everything off.
Any help or direction is much appreciated

PP

P.s. My Code so far is:

#include 
#include 
#include 
using namespace std;


int main()
{
cli();  
GIMSK  |= (1 << PCIE1);	// 'pin change interrupt' 
PCMSK0 |= (1 << PCINT0);// change on PCINT0 
set_sleep_mode(SLEEP_MODE_PWR_DOWN);	
sei();
sleep_mode(); 	
sleep_enable();
		
while(1)
 { 
  DDRA  = 0x02;	
  PORTA = 0x02;
 }			
return 0;
}


//Pin Change Interrupt
ISR(PCINT_vect)
{
GIMSK  &= ~(1<<PCIE1); //Disable the interrupt 
PCMSK0 &= ~(1<<PCINT0);
sleep_disable();
cli();  
}

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should make sure that no input pin is floating.

What controller are you using?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, in response:

You should make sure that no input pin is floating.
OK, many thanks - this mostly worked, though I'm not sure -- I introduced this code:

DDRA  = 0x00;   // Configure I/O pins of portA
DDRB  = 0x00;	// Configure I/O pins of portB
PORTA = 0xff;	// Enable pullup resistors on portA
PORTB = 0xff;	// Enable pullup resistors on portB

And I do go down to 0.76mA when asleep and 14mA when awake - however, two questions:
Q1/ Can I take any minimize this further?

and

Q2/ I see the LED is very faintly glowed, why would this be, does it matter?

What controller are you using?
attiny461

Thanks again

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

P.s. yes it does matter(!)
I'd set

PORTA = 0xff

and I wanted pin19 (PA1) active as an output, so

PORTA = 0xff - 0x02 = 0xfd

Now I get 0.47mA asleep and 14mA active - anything else I can do to drop this further?

Best, PP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What controller are you using?
attiny461


You have read chapter 7 I take it. Are you using BOD - if so did you read about BOD disable in 7.2? Did you read about PRR in 7.3? All the advice in 7.4 is worth looking at.

7.4.6 even had the advice you just used about port pins:

datasheet wrote:
When entering a sleep mode, all port pins should be configured to use minimum power. The
most important thing is then to ensure that no pins drive resistive loads. In sleep modes where
both the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device
will be disabled. This ensures that no power is consumed by the input logic when not needed. In
some cases, the input logic is needed for detecting wake-up conditions, and it will then be
enabled. Refer to the section “Digital Input Enable and Sleep Modes” on page 58 for details on
which pins are enabled. If the input buffer is enabled and the input signal is left floating or has an
analog signal level close to VCC/2, the input buffer will use excessive power.
For analog input pins, the digital input buffer should be disabled at all times. An analog signal
level close to VCC/2 on an input pin can cause significant current even in active mode. Digital
input buffers can be disabled by writing to the Digital Input Disable Registers (DIDR0, DIDR1).
Refer to “DIDR0 – Digital Input Disable Register 0” on page 160 or “DIDR1 – Digital Input Dis-
able Register 1” on page 160 for details.

Bottom line: read chapter 7.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which micro?

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim,
attiny461

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Quote:

What controller are you using?
attiny461


You have read chapter 7 I take it. Are you using BOD - if so did you read about BOD disable in 7.2? Did you read about PRR in 7.3? All the advice in 7.4 is worth looking at.

7.4.6 even had the advice you just used about port pins:

datasheet wrote:
When entering a sleep mode, all port pins should be configured to use minimum power. The
most important thing is then to ensure that no pins drive resistive loads. In sleep modes where
both the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device
will be disabled. This ensures that no power is consumed by the input logic when not needed. In
some cases, the input logic is needed for detecting wake-up conditions, and it will then be
enabled. Refer to the section “Digital Input Enable and Sleep Modes” on page 58 for details on
which pins are enabled. If the input buffer is enabled and the input signal is left floating or has an
analog signal level close to VCC/2, the input buffer will use excessive power.
For analog input pins, the digital input buffer should be disabled at all times. An analog signal
level close to VCC/2 on an input pin can cause significant current even in active mode. Digital
input buffers can be disabled by writing to the Digital Input Disable Registers (DIDR0, DIDR1).
Refer to “DIDR0 – Digital Input Disable Register 0” on page 160 or “DIDR1 – Digital Input Dis-
able Register 1” on page 160 for details.

Bottom line: read chapter 7.

Thanks - yes I did read this, but given I'm new to attiny's I found it awkward to follow, so I found this macro, http://www.nongnu.org/avr-libc/u...

Assuming the macro is correct the saving was 10uA by disabling BOD, i.e.
previous: 0.47mA
now: 0.46mA

Bottom line: A very small saving but of use yes.
Cheers, PP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

so I found this macro

Yes but that does nothing more than setting the sleep mode. It doesn't do all the stuff documented in chapter 7. If you are serious about power consumption you have to read EVERYTHING it says about it and consider for each point raised whether it's something you could benefit from adding code to use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have an external pullup on PA0, so you should not enable the internal pullup for it.

PA1 sources the current for the LED, so it should be set to 0.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ensure that you are actually measuring Vcc current of the AVR and not e.g. input to a regulator.

Also ensure that your measuring device is correct at microamp levels.

IME an AVR will match the draws given in the datasheet.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What controller are you using?
attiny461

Quote:

my aim is to minimize current consumption

Are you using a '461A? After all, your main aim is to ...
http://www.atmel.com/Images/doc8...

Let's see the full test program that you are now using. Tell how you are testing and measuring, and the results.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, the LED output pin MUST be set low before entering sleep mode.It follows therefore that this pin must not have its pullup enabled.You should be able to achieve 1-2 uA easily.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Thanks for the reponse all - I will tyry this as soon as time permits.

Directly now, Chartman, in response:
I want PA1 active as an output, and all else as input (resistor pull ups), so I think this is correct -

PORTA = 0xfd // = 0b11111101

Best, PP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear all, sorry to return to this late but I now have:

#include
#include
#include
using namespace std;

int main()
{

cli();
DDRA = 0xfe; // I/O pins of portA(11111110) - all output, except for PA0 which is an input
DDRB = 0xff; // I/O pins of portB(11111111) - all output
PORTA = 0xfd; // pullup on portA(11111101) - all pull up,except for PA1 which is an output
PORTB = 0xff; // pullup on portB(11111111) - all pull up

GIMSK |= (1 << PCIE1); // interrupt mask register - 'pin change interrupt' selected
PCMSK0 |= (1 << PCINT0); // change on PCINT0 (pin20) causes interrupt
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_bod_disable();
sei();
sleep_mode();
sleep_enable();

while(1)
{
DDRA = 0x02;
PORTA = 0x02;
}
return 0;
}

//Pin Change Interrupt
ISR(PCINT_vect)
{
GIMSK &= ~(1<<PCIE1); //Disable the interrupt so it doesn't keep flagging
PCMSK0 &= ~(1<<PCINT0);
sleep_disable();
cli();
}

I get 0.48mA asleep and 20mA once the button is pressed.
Q1/ Can I lower the sleep current further?
Q2/ is this section correct? I'm unsure:

set_sleep_mode(SLEEP_MODE_PWR_DOWN);    
sei(); 
sleep_mode();     
sleep_enable(); 

My practice circuit for this is (as below).
Assistance appreciated,

PP

Attachment(s):