Atmega328p power consumption

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

I'm trying to minimise power consumption of Atmega328p

My best result is 0.8 mA is active mode and 0.24 mA for sleeping mode. And if consumption for the active mode is acceptable for me, then consumption in sleep should be much less ....

It should be 10-20 uA

 

What has already been done.

I'm experimenting with a pure controller. The only thing that I added an optical interchange with USB2UART convertor

What was done to reduce consumption:

  1. The supply voltage is reduced to 2.7V. (2.7V is minimum for the sensors that will work with controller in future)
  2. The frequency is reduced to 1 MHz. The controller is clocked from an internal 8 MHz oscillator with a divider at 8. Fuse are set as follows: low_fuses=0x62 high_fuses=0xde extended_fuses=0xFF
  3. brown out detector is switch off
  4. The controller periodically falls asleep in SLEEP_MODE_PWR_DOWN mode with awakening by watchdog 
  5. Before sleep mode I disable all internal devices by calling power_all_disable(); and enable onle time1 and UART then wakeup
  6. All analog pint set int OUTPUT mode and LOW state 
      for (byte i = 0; i <= A5; i++)
    {
        pinMode (i, OUTPUT);    // changed as per below
        digitalWrite (i, LOW);  //     ditto
    }

So I've got no other idea how to reduce power consumption in sleep mode.

What can I do more? I need to reduce power consumption in sleep mode from 240 uA to 10-20 uA

 

Here is the full text of the sketch

#include "Test3.h"
#include <avr/io.h>
#include <avr/interrupt.h> // работа с прерываниями
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>

volatile byte watchdogCounter = 0;

void setup_watchdog(byte sleep_time)
{
  cli();

  wdt_enable(sleep_time);

  MCUSR &= ~_BV(WDRF);   
  WDTCSR |= _BV(WDCE) & ~_BV(WDE);
  WDTCSR |= _BV(WDIE);

  sei();
}

void arduino_sleep()
{
  cli();

  power_all_disable();                 
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); 

  sei();

  sleep_mode();
}

void savePower( ) {
         
    power_all_disable();

    for (byte i = 0; i <= A5; i++)
    {
       pinMode (i, OUTPUT);    // changed as per below
       digitalWrite (i, LOW);  //     ditto
    }

    DIDR1 |= _BV(AIN1D) | _BV(AIN0D);
    MCUCR = bit (BODS) | bit (BODSE);
    MCUCR = bit (BODS);

}

void setup()
{

    Serial.begin(9600);
    Serial.println("Wait 5 sec..");
    delay(5000); 

    savePower();
    setup_watchdog(WDTO_8S);
}

ISR (WDT_vect)
{
    WDTCSR |= _BV(WDIE);
    watchdogCounter++;
}

void doSomething() {

    Serial.print("Hello world!!!  Uptime : ");
    Serial.print(millis());
    Serial.print(" _ ");
    for( int i=0; i<100; i++ ) {
        Serial.print(".");
        delay(50);
    }
    Serial.println("");
}

void loop()
{
    power_usart0_enable();
    power_timer0_enable();
    delay(5);

    doSomething();

    Serial.println("Go to sleep....");
    delay(100);
    
    while (watchdogCounter < 2) //wait for watchdog counter reached the limit, WDTO_8S * 4 = 32sec.
    {
        arduino_sleep();
    }

    Serial.println("Wake up....");
    watchdogCounter = 0;        //reset counter
}

 

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

Foxhound32 wrote:
It should be 10-20 uA

Do you mean you want it to be?

 

Or that you've studied the documentation, and think that it should be?

 

 

EDIT

 

Is this running on an Arduino board?

 

Post the complete schematic

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jul 17, 2018 - 11:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I mean I want it to be... smiley
If it's possible

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

Foxhound32 wrote:
If it's possible

Have you checked the datasheet - that will tell you if it's possible as far as the AVR goes.

 

It will also depend on what else is on your board - so please post the full schematic.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Is this running on an Arduino board?

 

No, it works exactly as in the diagram above.

Just controller and optical interchange with USB2UART convertor

I specifically made a simple circuit for experimenting with power consumption

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

I'd recommend setting an IO line to some state as you go to sleep and then resetting it in the ISR() that wakes it from sleep. Monitor this on a scope or analyzer - what percentage of the time is the thing actually asleep? Also how are you actually measuring the consumption. The schematic shows a mysterious "2.6V" but where is this coming from exactly? Also as you are writing this as Arduino code exactly how much of the Arduino circuitry have you duplicated? Are you still using the bootloader and therefor have a USB-UART conversion somewhere in the design? Or are you really ISPing the code into a "bare" AVR? If ISPing is the ISP interface disconnected at the time you make the current measurement? Another consideration, if using Arudino, is the stuff that goes on "in the background". It will have started timers 0 and 1 I believe (for example).

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

 

awneil wrote:
Is this running on an Arduino board?

 

 

Datasheet tell me that it's possable to run at 1 MHz whit consumpition 0.1 uA

So I'm surprised at the consumption of 240 uA. I understand that I have run controller at  2.7 V not 1.8 and consumption should be greater.... 

I tried all the ways I know how to reduce consumption, but the result did not satisfy me...

For experiments on the board, there are no other devices. Only controller and optical isolation

Last Edited: Tue. Jul 17, 2018 - 11:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxhound32 wrote:
Datasheet tell me that it's possable to run (sic) at 1 MHz whit consumpition 0.1 uA 

Not exactly - the datasheet says that the consumption in Power-down Mode is 0.1μA

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In addition to the datasheet, you should always review available Application Notes.

 

Got to the Product Page:

 

https://www.microchip.com/wwwproducts/en/ATmega328P

 

Look on the 'Documents' tab ...

 

This one looks relevant:

 

AN_8349 - AVR4013: picoPower Basics

12/01/2010

92KB

 

Description:

This application note demonstrates how to extend the battery life of our application by multiple factors by modifying only the firmware. 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I'd recommend setting an IO line to some state as you go to sleep and then resetting it in the ISR() that wakes it from sleep.

You mean just set LOW or HIGH state in program or physical pull up/down to Vcc or ground?

clawson wrote:

Monitor this on a scope or analyzer - what percentage of the time is the thing actually asleep? Also how are you actually measuring the consumption. The schematic shows a mysterious "2.6V" but where is this coming from exactly?

 

I get 2.6 V from voltage regulator. But I measure curent after the regulator and before controller and optocouple.

 

clawson wrote:

Also as you are writing this as Arduino code exactly how much of the Arduino circuitry have you duplicated? Are you still using the bootloader and therefor have a USB-UART conversion somewhere in the design? Or are you really ISPing the code into a "bare" AVR?

I'm using USB-UART only for debug messages. Just to know then it sleep and when it's working. And I really ISPing the code into a "bare" AVR

 

clawson wrote:

If ISPing is the ISP interface disconnected at the time you make the current measurement? 

Of course, I turn off ISP then make masument. Just unplug it. 

And more interestingly, when I make measurements with the ISP turned on, the current consumed is less.... About 60 uA

 

clawson wrote:

Another consideration, if using Arudino, is the stuff that goes on "in the background". It will have started timers 0 and 1 I believe (for example).

I know about working in arduino libary in backgorund.... But then controller  falls asleep  I call  power_all_disable(); This is not enough to turn everything off?

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

Foxhound32 wrote:
 I call  power_all_disable(); This is not enough to turn everything off?

What does the documentation for that function tell you?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I sem to recall a nearly-exact thread not too long ago -- power consumption "problems" with an Arduino setup.  See if you can search it out.  The same issues will be rasied:  How are you measuring?  Floating pins. And so on...

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

theusch wrote:

I sem to recall a nearly-exact thread not too long ago -- power consumption "problems" with an Arduino setup.  See if you can search it out.  The same issues will be rasied:  How are you measuring?  Floating pins. And so on...

 

The advices that I found, including in this forum, I already used.
Maybe I just miss something.... So I'm asking questions.

 

It seems for me that the problem really with floating pins. How to deal with them correctly?

 

Last Edited: Tue. Jul 17, 2018 - 01:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Foxhound32 wrote:
How to deal with them correctly?

???  None of the discussions ou found mentioned floating pins?  Hard to believe.

 

https://www.avrfreaks.net/forum/...

Brian Fairchild wrote:
'tis the golden rule of low power design - never let your inputs fl

 

But indeed I cannot seem to fing the thread I was thinking of.

 

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.

Last Edited: Tue. Jul 17, 2018 - 01:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your off to a good start, but writing good low power apps is not easy. You have to think about everything!

 

For instance, any floating input port pin will consume power as the pin floats across the switching threshold, so either enable the pull up on EVERY unused port pin or make it an output.

You may find "running fast"(8MHz) and sleeping long will work better then running slow (1MHz)....

 

How are you measuring your cpu current? in line VOM or voltage drop across known series resistor?

You should always add bypass caps on VCC/GND and AVCC/GND pin pairs!!!

 

 

Good luck with your project!

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

Foxhound32 wrote:
My best result is ... 0.24 mA for sleeping mode.

ATmega328_P datasheet wrote:
• Power Consumption at 1 MHz, 1.8V, 25°C

– Active mode: 0.2 mA

– Power-Down mode: 0.1 μA

– Power-Save mode: 0.75 μA (Including 32 kHz RTC)

So looks rather like you are still in Active mode ... ?

 

Did you study that Application Note?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
You should always add bypass caps on VCC/GND and AVCC/GND pin pairs!!!

But beware of leakage ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
But beware of leakage ...

Yes... Choose wisely!

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

ki0bk wrote:
Choose wisely!

https://www.youtube.com/watch?v=...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
Your off to a good start, but writing good low power apps is not easy. You have to think about everything!   For instance, any floating input port pin will consume power as the pin floats across the switching threshold, so either enable the pull up on EVERY unused port pin or make it an output. 

 

 

You mean that I should set all unusep pins to OUTPUT and lavel to LOW?

Something like this:

pinMode (i, OUTPUT);    
digitalWrite (i, LOW);  

Is it enough?

 

Or I should physically connect pin to the GND?

 

ki0bk wrote:

How are you measuring your cpu current? in line VOM or voltage drop across known series resistor? You should always add bypass caps on VCC/GND and AVCC/GND pin pairs!!!

 

Just turn on the ammeter in the gap between the plus voltage regulator and contacts + 2.6V in the diagram above

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

awneil wrote:
ki0bk wrote: You should always add bypass caps on VCC/GND and AVCC/GND pin pairs!!! But beware of leakage ...

 

I know. The beginning schematic was like this

 

But consumption in sleep is the same ....
Therefore, in order to understand why I threw all the extra ...

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

Foxhound32 wrote:
Just turn on the ammeter in the gap between the plus voltage regulator and contacts + 2.6V in the diagram above

There is no regulator in that diagram!

 

Again, this is why it helps to show the full schematic - so that we can see exactly what you're doing.

 

Trying to describe connections in words is a doomed exercise. That's why we have schematics!

 

EDIT: Are you sure that your "ammeter" is able to read such low currents?

 

But consumption in sleep is the same ....

Again: it looks like you're not actually getting into "sleep"

 

And: have you studied that App Note?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
ATmega328_P datasheet wrote: • Power Consumption at 1 MHz, 1.8V, 25°C – Active mode: 0.2 mA – Power-Down mode: 0.1 μA – Power-Save mode: 0.75 μA (Including 32 kHz RTC) So looks rather like you are still in Active mode ... ?

 

I don't think so ...
Since in the active mode it consumes about 0.8 mA
And then I do in a sketch

 cli();

power_all_disable();                 
set_sleep_mode(SLEEP_MODE_PWR_DOWN); 

sei();

sleep_mode();

Consumption drops to 240 uA

I think because it falls asleep

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

Foxhound32 wrote:
You mean that I should set all unusep pins to OUTPUT and lavel to LOW?

 

Output level does not matter, either make them outputs (default is low), no physical connection to gnd is needed or enable pull ups if left as inputs so they don't float.

As it is now your floating inputs can cause additional power consumption as the inputs switch back and forth from 0 to 1 or 1 to 0 and back again.  Pull ups will hold at 1 state or make them outputs, either will work.

 

Jim

 

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

Foxhound32 wrote:
I think because it falls asleep

So you need to check whether your thinking is actually correct or not ... 

 

http://www.8052mcu.com/faqs/120313

 

​I think the Arduino Framework is likely to get in the way of this.

So, as you've pared-down your hardware to the bare minimum, you also need to pare down the software.

 

Did I mention that Application Note ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

I'd rule out the Arduino nonsense if I were you. Don't even bother about waking up initially. Just a plain main() that does little more than:

int main(void) {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); 

  sleep_mode();

  while(1);
}

and then measure the current. Does that get you to uA levels?
 

I'd even be tempted to take the opto isolator off the board too. Just start from the very basics and work up from there. At some stage, as you add more complexity back you may find the culprit that explains why you are not achieving datasheet power levels.

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

It seems that Atmel Studio has some examples which might help:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote:
Did I mention that Application Note

which has accompanying example code ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Again, this is why it helps to show the full schematic - so that we can see exactly what you're doing.   Trying to describe connections in words is a doomed exercise. That's why we have schematics!   EDIT: Are you sure that your "ammeter" is able to read such low currents?

 

The full schematics looks like this

 

and the schematics from the first post connected to the pins +2.6 adn GND

To measure current I use  digital multimeter ANENG AN8001

In principle, he gives it can measure tens of miroamperes.

Last Edited: Tue. Jul 17, 2018 - 02:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

clawson wrote:
and then measure the current.

Indeed, I've said many times to test going to sleep, with no wakeup sources enabled.  Sleep with the fishes forever.

 

But I'll add something else:  Before going to sleep, stay awake for some seconds.  That gives an Active level, and when the draw drops it indicates going to sleep.

 

OP seems to be in the trap of "my car doesn't work; what is wrong?"  Many things could be wrong.  So people list possible causes.  Then OP essentially says "that isn't it".

 

A similar prior thread that demonstrates the analysis: https://www.avrfreaks.net/forum/...

 

 

 

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.

Last Edited: Tue. Jul 17, 2018 - 02:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is BOD enabled ? try to disable 

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

Don't know if already mentioned (long thread) but you must initiliase all port pins preferably as outputs or with pull up enabled if inputs to avoid oscillation and additional current drain.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

There is another very important reason to initialize all unused port pins as outputs or defined level inputs. An undefined input can float. If it should float into the region around Vcc/2, the internal transistor structure will "burn" a lot of current that just flows from Vcc to ground, internally. 

 

It is a really bad idea to tie inputs to external ground because if you ever change you mind and want to use one of those, then you are stuck. But, if you define the pin as an output or input with internal (soft) pullup, then you can change it any way you want to. Also, if you tie a port pin to ground, there is always the risk of it being set to high output. THEN, you will see more than 20ma, not 0.2ma.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. Jul 17, 2018 - 10:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, here are the results of the experiment

I've change the program as clawson recommend

#include <avr/sleep.h>
#include <util/delay.h>

int main(void){

        for(int i=0; i<10000; i++) {
                _delay_us(500);
        }

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_mode();
    while(1);
}

At the beginning consumption is 800 uA, after 0 uA. It means that my multimeter can measure this current. It less then 10 uA

A bit more complicated. Then I try to wake up on whatsdog.

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/wdt.h> 
#include <avr/sleep.h> 
#include <avr/interrupt.h>

ISR (WDT_vect) {

        WDTCSR |= _BV(WDIE); 
}

int main(void) {

        for(int i=0; i<10000; i++) {
                        _delay_us(500);
        }


    wdt_reset(); 
    wdt_enable(WDTO_1S);
    WDTCSR |= _BV(WDIE);
    sei(); 

    set_sleep_mode(SLEEP_MODE_PWR_DOWN); 
    while(1) {
            sleep_enable(); 
            sleep_cpu();
    }

}

In this case it falls asleep but does not wake up. Why?

 

And one more question. I usually use Eclipse+Sloeber plugin to develop arduino style sketch.

That IDE better for AVR develop on Linux. I've look on Eclipse + AVR plugin but it seems that it has not been updated since 2012

What alternatives under Linux?

 

 

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

Foxhound32 wrote:
In this case it falls asleep but does not wake up. Why?
How do you KNOW it doesn't wake up? As far as I can see your while(1) will ensure that as soon as the WDT_vect wakes it from one sleep it will go immediately back to sleep. After the sleep_cpu() I would put in something to flash an LED perhaps:

    while(1) {
            sleep_enable(); 
            sleep_cpu();
            PORTB = 0xFF;
            _delay_ms(200);
            PORTB = 0x00;
    }

It should sleep. Then 1 second later the WDT should fire so it wakes up, flashes all the B output pins (to which you have connected one or more LEDs+resistors) on for 200ms, then off again then it will go back to sleep and await the next 1S interrupt from the WDT.

 

Actually the WDT will presumably continue to "tick" even when the 200ms delay is happening so I think I'd actually make it:

    while(1) {
            sleep_enable(); 
            sleep_cpu();
            PORTB = 0xFF;
            _delay_ms(200);
            PORTB = 0x00;
            wdt_reset();
    }

to restart the watchdog clock just before you sleep again. So it should be a 1.2s cycle with the LED on for just 0.2s

 

Of course lighting an LED is going to mess with your power consumption readings but there should be current draw from both the AVR while awake for those 200ms and also the LED. If you own a scope/analyzer maybe drop the LED idea and simply moniotr one of the B pins to see it high/low.

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

Foxhound32 wrote:
after 0 uA. It means that my multimeter can measure this current.

;)  So the AVR really draws >>no<< power?  But indeed, once you get down that low it usually doesn't matter.

 

What changes did you make to go from the original power-draw numbers to the 800 active, ~0 sleeping?

 

Foxhound32 wrote:
In this case it falls asleep but does not wake up. Why?
Foxhound32 wrote:
wdt_enable(WDTO_1S); WDTCSR |= _BV(WDIE);

And what does the datasheet say?

• Bit 6 – WDIE: Watchdog Interrupt Enable
When this bit is written to one and the I-bit in the Status Register is set, the Watchdog Interrupt is enabled. If
WDE is cleared in combination with this setting, the Watchdog Timer is in Interrupt Mode, and the
corresponding interrupt is executed if time-out in the Watchdog Timer occurs. If WDE is set, the Watchdog
Timer is in Interrupt and System Reset Mode. ...
 

 

There have been extensive threads on watchdog-interrupt on this family of processors.  As you notice, your chosen toolchain doesn't know about watchdog-interrupt mode.  It appears to me you are in interrupt+reset mode.  What is the purpose of setting WDIE in the ISR?

 

2008 thread, with links to prior:  https://www.avrfreaks.net/forum/...

https://www.avrfreaks.net/forum/...

2014 pertinent thread, but with Tiny85 target: https://www.avrfreaks.net/forum/...

 

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.

Last Edited: Wed. Jul 18, 2018 - 03:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems the problem is solved. I just change the program. Now microcontroller consump about 800 uAH in active mode and less than 10 uA the sleeping on 1Mhz frequence.
At 8Mhz frequance it consump 2.3 mA in active and less then 10uA in slepping mode.

#include <avr/delay.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>

volatile int interruptCount=0;

ISR (WDT_vect) {
   WDTCSR |= _BV(WDIE);
    interruptCount++;
}

void doSomething() {
   for(int i=0; i<10000; i++)    _delay_us(500);
}

void sleep() {
   interruptCount=0;
   while(interruptCount<5) {
      sleep_cpu();
      wdt_reset();
   }
}

void setup() {
   wdt_reset(); 
   wdt_enable(WDTO_1S); 
   WDTCSR |= _BV(WDIE);
   sei(); 
   set_sleep_mode(SLEEP_MODE_PWR_DOWN); 
   sleep_enable(); 
}




int main(void) {

   setup();

    while(1) {
       doSomething();
       sleep();
    }
}

 

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

Foxhound32 wrote:
It seems the problem is solved.

So, for the benefit of future readers, what was the key?

 

Please mark the solution - see Tip #5.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
 for(int i=0; i<10000; i++)    _delay_us(500);

Is there some reason to split the delay like that rather than?:

_delay_ms(5000);

 

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

Foxhound32 wrote:

void doSomething() {
   for(int i=0; i<10000; i++)    _delay_us(500);
}

Surely, that function should be called doNothing() ?!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Is there some reason to split the delay like that rather than?:

Does it really matter, for the purposes of creating a sleep-mode current-draw test program?

 

After a number of responses, I've lost track whether the problem was the circuit (floating), or peripheral setup.  From my experience, I still think the latest "working" code is interrupt+reset mode for the watchdog.  I wonder if the reset occurring isn't showing any symptoms?

 

 

 

 

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

theusch wrote:
From my experience, I still think the latest "working" code is interrupt+reset mode for the watchdog.  I wonder if the reset occurring isn't showing any symptoms?

The reset isn't occurring, since the ISR re-enables interrupt-and-reset mode. Yes it's unnecessary, but neither should it skew the results.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]