Pages: [1]   Go Down
Author Topic: What to turn off, and how?  (Read 1287 times)
0 Members and 1 Guest are viewing this topic.
Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to figure out what all I can turn off on a 328P to save on battery consumption.  The majority of what it's doing is driving two LED strings (2-wire communication) using A0 - A3 (don't ask), then it has 2 separate LEDs (pins 3 and 4) that act as indicators, one's a heartbeat and the other flashes when the unit receives an RF signal.  The RF module uses pins 13, 12, 11, 8, and 7 (SPI communications).  The SPI pins are broken out but they're shared with the RF module pins.  The FTDI pins are also broken out (RX/TX/RST), and there's an external oscillator attached as well.

So what can be turned off?  Do I need the watchdog?  Do I need the ADC?  What about the timers?  And how does one turn them off?  Is it all done in programming?
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6805
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is it all done in programming?
yes, of course.
Practically, your best bet is to make sure your unused pins are set to outputs or have pullups enabled.  The other things you're talking about probably only make a small difference compared to the other things you have in your system (the whole AVR should consume less than 25mA when active.  (table 29-16 "Additional current consumption" in the datasheet says that the peripherals add 1 to 4% additional for each of the 7 possible.  ADC is most power hungry.)
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, so basically just do something like 'pinMode(UNUSED_PIN, OUTPUT);' would suffice?  What about killing the ADC?
Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could also use low current LED (around 3mA instead of 20mA)
Logged

Patgadget
Montreal

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your best bet is to look in the datasheet. It's really not that bad if you know what you're looking for, and I hadn't even thought of it as a good place to find information.

Here's a similar project.

Also, please don't cross-post.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After declaring pinMode, digitalWrite the unused pins HIGH.
Also helps to run from 3 1.5V batteries & bypass the regulator.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

WizenedEE: I specifically didn't cross post, I merely added a pointer from one thread to the other.  I didn't know whether my question pertained to either of them, partly because I thought it could have to do with fuses, in which case, in my mind, it has to do with the microcontroller itself, and not programming.  But then it dawned on me, maybe what I wanted to achieve can only be done (or also done) through programming, in which case my post should've been there.  If you're going to nitpick about a pointer from one to the other, I say find something better to do.  There are far worse posters than me.

CrossRoads: Possible.  I could also put a zener in place and drop the incoming 6V down and do away with a regulator.  As I've discovered I ordered the wrong regulator to begin with, the zener route is looking promising at the moment.  Doubt I have enough time to build up another order in time (I'm not paying high shipping for $12 worth of stuff.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

0.7V series Diode drop would do it, get you down to 5.3V.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The following code works well for me, the ATmega328P draws < 0.5µA current while in power-down mode (running on 2 AA cells). Before calling goToSleep(), I ensure that all pins are either (a) defined as inputs with pullups enabled, or (b) set to a low level if they're output pins driving loads like LEDs or whatever. Be sure to provide a way to wake up, in this case I'm using pin change interrupts on any of several pins.

Of course this will not reduce current consumption of other circuit components like voltage regulators, etc., as CrossRoads correctly states.

Code:
#include <avr/sleep.h>
...
void goToSleep()
{
    byte adcsra, mcucr1, mcucr2;

    sleep_enable();
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    PCICR = _BV(PCIE1);            //enable pin change interrupts 8-14
    PCMSK1 = _BV(PCINT8) | _BV(PCINT11) | _BV(PCINT12) | _BV(PCINT13);    //enable PCINT8,11,12,13 (PC0,3,4,5)
    adcsra = ADCSRA;               //save the ADC Control and Status Register A
    ADCSRA = 0;                    //disable ADC
    cli();
    mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
    mcucr2 = mcucr1 & ~_BV(BODSE);
    MCUCR = mcucr1;                //timed sequence
    MCUCR = mcucr2;                //BODS stays active for 3 cycles, sleep instruction must be executed while it's active
    sei();                         //ensure interrupts enabled so we can wake up again
    sleep_cpu();                   //go to sleep
    sleep_disable();               //wake up here
    ADCSRA = adcsra;               //restore ADCSRA
}

« Last Edit: November 25, 2011, 08:59:01 am by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pages: [1]   Go Up
Jump to: