External 32 KHz timer2 in order to shutdown

I would also suggest a bare bones chip + RTC. I have very strong doubts that it would be even remotely easy to beat a dedicated RTC with regard to both power consumption and accuracy.

Why not put it into sleep mode but leave counter/timer 1 counting clock cycles (and waking the processor up every 5 minutes), and counter/timer 2 counting input pulses from the phototransistor?

You can run the whole chip from a 32768Hz crystal, unless you need a faster clock speed when sending the data via RF.

Running @32kHz implies flashing @8kHz. This is a major pain. For low power I would run @1Mhz internal clock + use an RTC. Deep sleep till the RTC triggers the wakeup. Then perform whatever is necessary and go to sleep again. Unlike a crystal the RC oscillator will be ready much earlier. It also consumes less power.

Also keep in mind to shut down all parts that are not really needed (e.g. unneeded timers, brown out, I2C, ADC). The datasheet holds the details :wink:

Stuff about power saving:

This makes me think about the vast number of projects where AVR is a bit overkill.

Thanks a lot all of you guys ... it's wonderfool to see a lot of help.

I just ordered yesterday some 32,768 MHz crystals in order
to begin to test it.

So after i read (but not understand all) the wonderfool article post by Nick (http://www.gammon.com.au/power)
i understand this steps:

  • i must run it using the Timer2 trained by an 32MHz external quartz in order to have an accurate time after wake up
  • i must program the atmel in order to use 8MHz (i anyway need at last 4Mhz in order to use the RFM12B for rf transmitter)
  • for the LED pulse i will use the LOW interrupt wake-up on pin 5 of atmel
    (i hope will fill the LOW status, cause now in my program i use the RISING status)

Is everything right until now ?
The Timer2 is work in "Power Down" mode ? ..or it's work only in "Power Save" mode ?

I just must understand about how to program the atmel in this case.
If I understand I can not use the normal flash using the bootloader
cause of use of internal 8MHz RC clock... it is there a bootloader that can use 8MHz internal clock ?

Thanks a lot again
Denis

cause of use of internal 8MHz RC clock... it is there a bootloader that can use 8MHz internal clock ?

Yes there are 8 MHz bootloaders. The Lilypad is one I think.

There's Arduino as ISP to minimal config breadboard 8 Mz.

AFAICT this warning applies to UNO's with 168 chips, not 328's, see the chip-specific part in parenthesis. I can tell as far as my 328-chip UNO bootloading and programming 328P-PU's
using material and wiring from that link.

Note that these techniques only work with the Arduino Duemilanove w/ an ATmega328, not the Arduino Uno (or older Arduino boards w/ an ATmega168).

Hard to predict change, that comment must be ooooooooooooooold!

This project got me interested in what sort of low power consumption might be achievable. I made up a test case with a LLS05-A linear light sensor.

The wiring for that is pretty simple:

// Count light pulses on a light sensor.
// Author: Nick Gammon
// Date: 18 November 2012

#include <avr/sleep.h>

const byte LED = 13;
const byte photoTransistor = 8;

// count of pulses
volatile unsigned long count;

/*

Pin change interrupts.

Pin                  Mask / Flag / Enable

D0	  PCINT16 (PCMSK2 / PCIF2 / PCIE2)
D1	  PCINT17 (PCMSK2 / PCIF2 / PCIE2)
D2	  PCINT18 (PCMSK2 / PCIF2 / PCIE2)
D3	  PCINT19 (PCMSK2 / PCIF2 / PCIE2)
D4	  PCINT20 (PCMSK2 / PCIF2 / PCIE2)
D5	  PCINT21 (PCMSK2 / PCIF2 / PCIE2)
D6	  PCINT22 (PCMSK2 / PCIF2 / PCIE2)
D7	  PCINT23 (PCMSK2 / PCIF2 / PCIE2)
D8	  PCINT0 (PCMSK0 / PCIF0 / PCIE0)
D9	  PCINT1 (PCMSK0 / PCIF0 / PCIE0)
D10	  PCINT2 (PCMSK0 / PCIF0 / PCIE0)
D11	  PCINT3 (PCMSK0 / PCIF0 / PCIE0)
D12	  PCINT4 (PCMSK0 / PCIF0 / PCIE0)
D13	  PCINT5 (PCMSK0 / PCIF0 / PCIE0)
A0	  PCINT8 (PCMSK1 / PCIF1 / PCIE1)
A1	  PCINT9 (PCMSK1 / PCIF1 / PCIE1)
A2	  PCINT10 (PCMSK1 / PCIF1 / PCIE1)
A3	  PCINT11 (PCMSK1 / PCIF1 / PCIE1)
A4	  PCINT12 (PCMSK1 / PCIF1 / PCIE1)
A5	  PCINT13 (PCMSK1 / PCIF1 / PCIE1)

*/

ISR (PCINT0_vect)
  {
  byte sensor = digitalRead (photoTransistor);
  digitalWrite (LED, sensor);  
  if (sensor == HIGH)
    count++;
  PCICR  &= ~_BV (PCIE0);   // disable pin change interrupts
  }  // end of lightOn


void setup ()
{
  pinMode (LED, OUTPUT);
  
  // pin change interrupt masks (see above list)
  PCMSK0 |= _BV (PCINT0);   // pin 8

}  // end of setup

void goToSleep ()
  {
  PCIFR  |= _BV (PCIF0);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE0);   // enable pin change interrupts
  
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
  sleep_enable();

  byte old_ADCSRA = ADCSRA;
  // disable ADC to save power
  ADCSRA = 0;  
  // turn off various modules
  PRR = 0xFF;  
   
  // turn off brown-out enable in software
  MCUCR = _BV (BODS) | _BV (BODSE);
  MCUCR = _BV (BODS); 
  sleep_cpu ();  
 
  // cancel sleep as a precaution
  sleep_disable();
  PCICR = 0;  // cancel pin change interrupts
  PRR = 0;    // enable modules again
  ADCSRA = old_ADCSRA; // re-enable ADC conversion
    
  }  // end of goToSleep
  
void loop ()
  {
  goToSleep ();  
  
  // do something with results here
  }

I put an LED on pin 13 to see if it was working. The code counts when the light comes on (ie. the LED on the power meter flashes). You could add code to check the time (from a RTC chip) and periodically upload the results to somewhere else (after powering up the transmitter).

I measured it taking about 2 uA when asleep, which isn't too bad. Note that the darker it is, the less current drawn by the phototransistor, and thus the less power consumption. So the ideal thing would be for the sensor to be in a meter box with the door shut (or a black cloth over it or something), to keep the light out.

This was tested on a "bare bones" board. No voltage regulator, USB interface or anything like that.

See my page here for tips about turning on external things like clocks, transmitters: http://www.gammon.com.au/power

The simple thing, I think, would be to check the time when it wakes (where I have the comment "do something with results here"). Or maybe even every 5 flashes to keep it even lower consumption. After all, if the meter isn't flashing, you hardly need to upload new results.

Of course, the LED in my test uses power also. I would disconnect that when you are comfortable it is working. When testing, the LED should flash in time with the meter flash.

I tested it at 3V, it worked OK, except I needed to set the "divide clock by 8" fuse bit. The processor isn't rated to run at 16 MHz at 3V. An alternative would be to run from the internal oscillator at 8 MHz (that's OK at 3V) thus saving the need for a crystal or resonator.

2 uA is pretty good, because a AA battery will self-discharge at a somewhat faster rate than that anyway, so the battery is the limiting factor, not the power consumption of the chip.

Dear Nick,
thanks a lot for your big help
I was out of home all weekend, and i can't replay.

My simply opinion is that 2 uA it's very good.
So for the timer... you think that is better if i put there an external RTC chip ?
...or is better using external 32Mhz crystal for timer2, and internal oscillator at 8MHz ? in this case i must flash it different right ?

I'm looking for some LLS05-A linear light sensor... but i already have some photo-resistance maybe i'll test using that.
Again thanks to all
Denis

denisj:
So for the timer... you think that is better if i put there an external RTC chip ?

Yes, I don't see how the other options will work. If the processor is asleep, it won't be counting time. If it isn't asleep it isn't saving power. The $10 RTC chip with its battery backup will know the time, even if the processor spends most of its time sleeping.

Could the IR pulse or data from the meter serve in a time-keeping capacity? Does the meter data include time? Even if it doesn't, the Elster meters I'm somewhat familiar with emit data every 1.0 seconds to some degree of accuracy so count the packets and you have time.

Nik,
thanks again for your answer.
Like you can understand, I'm trying to keep the hardware as simple as possible.

I will not need a like a calendar time ... but just to have the millis between last 2 pulses.
So i search some RTC that have a millis also... but i don't find for now.
For example i found DS3232 from Maxim and on the key fastures i read:
Real-Time Clock Counts Seconds, Minutes, Hours, Day, Date, Month, and Year with Leap Year Compensation Valid Up to 2099

It is there something that give me the mills ? i don't need other ... as little is possible :slight_smile:

Can i use the RTC with the current from the principal batteries ? so with out the battery backup.
After the reset I'll set to 0000 the time and then will count only the mills between last 2 pulses.
Then every 5 minutes wakeup, send the watt/hour via RF and i'll turn the RTC to 0000, then back to shutdown.
I think in this mode will consume less power.

GoForSmoke@ ... the current meters in Italy have only the LED that emit a pulse every watt, there is not the time :frowning:

Thanks again all
Denis

Is there nowhere near an electric meter that you can plug a USB charger in?

denisj:
I will not need a like a calendar time ... but just to have the millis between last 2 pulses.

Why? Don't you just want to count the number of pulses over 5 minutes? If you want to know the number of watts, who cares when the pulse occurred, to the nearest millisecond?

but just to have the millis between last 2 pulses.

Generally, if your duration between tasks is that short, you don't put your mcu into sleep: the restart of a crystal oscillator can be several ms on most mcus.

If that's what you truly want to do, look into msp430: their crystal oscillator is "instant on". Energy micro is a distant 2nd and other mcu oems are not even in the same universe with TI on that.

GoForSmoke:
Is there nowhere near an electric meter that you can plug a USB charger in?

The problem is not the power, i just want to make it run from 2 X 1.5 Batts cause i'm sure it can run some mounts if i make it right :wink:

Nick, i will need to send 2 types of data on the net ...

  1. the actual power that the PV system generate, for this i'll need the time between last 2 pulses every 5 minutes
  2. the total generated power, and here i'll count all pulses of that day.

dhenry:
If that's what you truly want to do, look into msp430: their crystal oscillator is "instant on". on that.

Dhenry ... I allready have difficult to understand this world cause I'm newbe, thansk a lot but i don't want to go versus new mcu's

I want to ask something also.
In the link of Nick page Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors i so the difference from
SLEEP_MODE_PWR_SAVE: 1.62 mA - this I can use if I'll use the external Timer2 using the 32KHz cristal
SLEEP_MODE_PWR_DOWN : 0.36 mA - for this mode I'll use the external RTC chip.
...so the diff is 1.26 mA
My question is... how much ampere an external RTC can use ? ...less than 1.26 I hope right ?

Thanks again all
Denis

how much ampere an external RTC can use ?

Look into the device datasheet for that. Can be less than 1ua, depending on the rtc and mode you are running it in.

dhenry:
Look into the device datasheet for that. Can be less than 1ua, depending on the rtc and mode you are running it in.

Whoau ... great thinks
So now I only most fount an RTC that give me the millis
can anybody target me to some of this RTC please ?
Thanks again
Denis

So now I only most fount an RTC that give me the millis

You never will, because a beast like that does not make sense, as has been explained to you earlier.