fine tuning sleep current Atmega328

I have been using the same sleep settings ( originally from Crossroads ) for a long time now, and have pin 2 being called low as the interrupt. :-

void enterSleep()
{
  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(0, pin2Interrupt, FALLING);
  delay(50); // need this?
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  ADCSRA &= ~(1 << ADEN);
  PRR = 0xFF;
  sleep_mode();                         // now goes to Sleep and waits for the interrupt
  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad 
  PRR = 0x00;
  /* First thing to do is disable sleep. */
  sleep_disable(); 

  // set all the keypad columns back high so can read keypad presses again
  digitalWrite(3, HIGH);
  digitalWrite(16, HIGH); 
  digitalWrite(18, HIGH);
  // then go to the void Loop()
}

I have a sleep current of about 20 microamps at the moment, which has been fine for the remote controls with 3 AAA cells.
The batteries last a year.

Unfortunatley I have just made a wonderful remote control unit, with 19 BCD switches, in a compact case.
But when I looked inside, theres no room for the normal battery case !

I can fit an A23 12v keyfob type battery ( with a micropower 5v regulator ) but they are only rated at 55 mAh, which is marginal.

I looked at Nick Gammons sketches, and it looks like I should concentrate on the DAC and the brownout.

Should I just switch the ADC off in setup? I am not using it at all, and I have no idea what ADCSRA &= ~(1 << ADEN); means.

That is exactly what that line does. it resets the ADEN (ADC Enable) bit in the ADCSRA (ADC Control Status Register A) register. Here's what the spec sheet has to say about that bit:

• Bit 7 – ADEN: ADC Enable Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the ADC off while a con- version is in progress, will terminate this conversion.

I can fit an A23 12v keyfob type battery ( with a micropower 5v regulator ) but they are only rated at 55 mAh, which is marginal.

Just out of curiosity, how does that work? The micropower 5v regulator at sub mA loads, I mean. I looked up a couple of micropower 5v regulators, and they didn’t seem to have anything I could understand for loads < 1mA. And the “quiescent current” was 20 uA or so. Does that mean the regulator takes more power than the Arduino when it is sleeping? Because that would be not as useful.

I seemed to recall the micropower regs had 8 microamps quiescent current, but it looks like its 80, which would be a waste of time !

I could use a 2477 3v coin cell, with a large value electrolytic to supply the current on transmit .

The transmitter and 328 only have to come on long enough to scan the switches and send out 19 bytes + checksum.

I use this on a CMOS project, but I would have to run the chip at 8 MHz evidently, I load the bootloader using my second Duemilanove as ISP. Is it possible to change the frequency with this method?

I have just found an available battery ( for $4 ) that is 3.6v 1.2 amphour the ER14250, it looks like it will keep 3.6v terminal voltage for 90% of its life, which at 20 microamps that I have now ( at 4v5 ) would be years - or probably its shelf life would limit it first.

It can supply 40mA continous or 80mA pulsed, but I would use a decent cap anyway.

I think the 328 is OK at 16 MHz at 3v6 ? I have looked at the data sheet for the Atmega328P and apart from a reference to " speed grades on page 321 " which doesnt exist on my datasheet, it lists 20MHz from 1.8 to 5v ??

Postscript - even better and half the price is the ER14335 at 1650 mAh

I think the 328 is OK at 16 MHz at 3v6 ?

Here's what I get from page two of the spec sheet:

• Speed Grade: – 0 - 4MHz@1.8 - 5.5V, 0 - 10MHz@2.7 - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V

I run my shrinkified projects at 8MHz. But they're pretty simple, so far.

Thanks

I will run it at 8 Mhz, there is no timing involved ( apart from the VirtualWire baud rate ) so would there be an advantage in using the internal oscillator - and would this affect the sleep mode?

Will I be able to change the frequency using the 2 Arduinos ISP programming ?

Boffin1: I will run it at 8 Mhz, there is no timing involved ( apart from the VirtualWire baud rate ) so would there be an advantage in using the internal oscillator - and would this affect the sleep mode?

You can save space by using the internal oscillator and I don't think it will make much difference to the sleep mode.

Will I be able to change the frequency using the 2 Arduinos ISP programming ?

Yes, you should be able to set the fuses to change the clock speed. Create a new board definition in boards.txt with the fuses you want to use and then upload your sketch using your ISP or write a bootloader and the fuses should be set.

I would also turn off the brown-out detection by setting the fuses for that. You can get the power consumption down to as little as 0.1uA in power down sleep mode if you run at 8MHz and turn the BOD off.

TanHadron:

I can fit an A23 12v keyfob type battery ( with a micropower 5v regulator ) but they are only rated at 55 mAh, which is marginal.

Just out of curiosity, how does that work? The micropower 5v regulator at sub mA loads, I mean. I looked up a couple of micropower 5v regulators, and they didn’t seem to have anything I could understand for loads < 1mA. And the “quiescent current” was 20 uA or so. Does that mean the regulator takes more power than the Arduino when it is sleeping? Because that would be not as useful.

I use the MCP1702 micropower regulator, which has quiescent current of 5uA max, 2uA typical at very low loads. Still more than a atmeg328p in power down mode with the watchdog disabled, but low enough to be usable. See http://ww1.microchip.com/downloads/en/DeviceDoc/22008E.pdf.

MCP1702

Thats the one I was thinking of DC42 ! , I knew it was less than 10 micoramps.

Perhaps I am not so senile after all, but I think I will try and get the 328 going at 8 Mhz as I have another project that runs off a coin cell.

I dont like the sound of blowing fuses though :-)

..328p runs fine @16MHz and 3.6V, as well as 3.3V..

Well spotted Pito, we were all looking at the 328 range of speeds / voltage, where the 328P says 20 Mhz down to 1.8v.

I must confess I made a remote control that has been working fine for over a year with 2 AAA batteries at 16 Mhz, but I was too embarrassed to mention it :-)

[/img]

Do you have to blow the fuses? I thought that was only if you wanted it to come up at that speed. The way I understood it, by default the chip comes up using the 8 MHz internal clock and prescaler of 8, but one of the first things you do is to tell the chip which clock to use, change the prescaler.

Also, programming the fuses is not permanent, is it? You can reset them if you want, right?

Blowing the fuses is not permanent. You may reprogram them when required. For more info: http://www.engbedded.com/fusecalc

As it seems the chip is fine at 16 Mhz and 3.6v I will leave well alone.

The battery I have chosen will last several years anyway at 40 microamps ( which is the sleep current with the 3 CD4017 expander chips supplied by the battery ) plus the 160ms pulse of 15mA when the score is updated, which might be 200 times in a cricket match = about 0.14 mAh per match. ( 7000 matches at 1650 maH )

I think the shelf life of the battery will be the limiting factor.

( I put a smiley about blowing fuses )

Boffin, I know whatcha mean about the blowing fuses, but the other point was that I think you can kick into 8MHz mode without touching the fuses. Regardless of which mode is the default when the chip initializes, you can tell it to override that in your program.

On another note, thanks for the information the MCP1702. I needed one of those for a project I did a short time ago, but didn't know they existed. I got around it another way, but next time...

TanHadron: Regardless of which mode is the default when the chip initializes, you can tell it to override that in your program.

That is if you can manage to get the chip started at all if you run it at lower voltages. Otherwise it won't run that code. It may or may not work.

Good point.

Which is why the default is 8MHz internal clock with /8 prescaler?

That is if you can manage to get the chip started at all if you run it at lower voltages. Otherwise it won't run that code. It may or may not work.

But the speed rate in the specs ( for the P suffix ) say 1.8 to 5.5v, why would they say that if it was doubtful if it would start ?

Boffin1: But the speed rate in the specs ( for the P suffix ) say 1.8 to 5.5v, why would they say that if it was doubtful if it would start ?

It says 0 -20 MHz @ 1.8 -5.5 V but they don't say which speed you can use at which supply voltage. The supply voltage requirement varies with the clock speed as TanHadron already pointed out.

TanHadron: • Speed Grade: – 0 - 4MHz@1.8 - 5.5V, 0 - 10MHz@2.7 - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V

This means you can run the chip on 1.8 V at up to 4MHz It also means you need to get up to 2.7V to run it at 10MHz It doesn't mention what voltage you need at 8MHz but if you read the Speed Grades section it says that the frequency vs. Vcc voltage curve is linear between 1.8V and 2.7V meaning that you would need 2.5V to safely run at 8MHz.

I saw that speed grade for the 328, but the 328*P* says 20 Mhz for 1.8 to 5.5 v..