Author Topic: Help with battery powered Moteino sketch  (Read 16399 times)

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Help with battery powered Moteino sketch
« on: May 04, 2016, 02:31:49 PM »
Hello Everyone -

I am new to the Moteino, having just received my first 5 units with the RFM69HW radio and flash onboard. I am looking to use it as a sensor node that measures the level of my pool water and transmits this information back to emoncms. I am using a product called eTape manufactured by Milone Tech and sold by Adafruit.

The sketch works great and does exactly what it is supposed to do, but I am monitoring the battery voltage (4 x AA) and just overnight I have seen a drop in voltage from 5.78 volts to 5.625 which means at this rate I will be replacing batteries often! I have read in several plaes to connect my batteries to 3.3V OUT as opposed to VIN.


Here are my connections:


A0 connected to 560 Ohm resistor
One side of eTape connected to same side of resistor and A0
Other side of resistor connected to 3.3V OUT
4 x AA Batteries connected to GND & also to same 3.3V OUT pin as above
Other side of eTape connected to GND


I used some of the code from a previous 'arduino' like unit to make it work and I just do not know
if I have somehow now set up the power reduction stuff correctly.

I have attached the sketch as well...any ideas would be greatly appreciated....



TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #1 on: May 04, 2016, 02:47:34 PM »
Hello Everyone -

I am new to the Moteino, having just received my first 5 units with the RFM69HW radio and flash onboard. I am looking to use it as a sensor node that measures the level of my pool water and transmits this information back to emoncms. I am using a product called eTape manufactured by Milone Tech and sold by Adafruit.

The sketch works great and does exactly what it is supposed to do, but I am monitoring the battery voltage (4 x AA) and just overnight I have seen a drop in voltage from 5.78 volts to 5.625 which means at this rate I will be replacing batteries often! I have read in several plaes to connect my batteries to 3.3V OUT as opposed to VIN.
NO NO NO!  You can ONLY do this if you are using TWO AA batteries!  No more than 3.3V.
Quote


Here are my connections:


A0 connected to 560 Ohm resistor
One side of eTape connected to same side of resistor and A0
Other side of resistor connected to 3.3V OUT
4 x AA Batteries connected to GND & also to same 3.3V OUT pin as above
Other side of eTape connected to GND


I used some of the code from a previous 'arduino' like unit to make it work and I just do not know
if I have somehow now set up the power reduction stuff correctly.

I have attached the sketch as well...any ideas would be greatly appreciated....
Also, I have an alternative circuit for you for the eTape (which works REALLY well as long as you don't get the top connector strip wet).  I'll post the circuit in another post, hopefully later today.

Tom

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6402
  • Country: us
    • LowPowerLab
Re: Help with battery powered Moteino sketch
« Reply #2 on: May 04, 2016, 03:08:29 PM »
4 x AA Batteries connected to GND & also to same 3.3V OUT pin as above
Did the Moteinos survive this?  :-\

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #3 on: May 04, 2016, 03:09:56 PM »
Tom -

Thanks! I looked everywhere for information on connecting batteries to the moteino and didn't find anything except people saying to connect it to the output and not the input.

The eTape that I am using is their newest version with the tape sealed in a plastic enclosure and the leads sealed in the top so hopefully I won't have any issues with them getting wet!

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #4 on: May 04, 2016, 03:12:24 PM »
4 x AA Batteries connected to GND & also to same 3.3V OUT pin as above
Did the Moteinos survive this?  :-\

Well it ran all night and is still running now...hopefully I didn't damage it too bad! If so, I have 4 more that I bought as well and now I know better!

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #5 on: May 04, 2016, 03:14:16 PM »
Interesting...now that I moved my batteries to VIN, my voltage as reported by the sketch is now only 3.31 volts so something is not right for sure (in my code)!
« Last Edit: May 04, 2016, 03:19:05 PM by G550_Pilot »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #6 on: May 04, 2016, 03:25:54 PM »
See https://lowpowerlab.com/forum/index.php/topic,1860.msg13476.html#msg13476 for my implementation.

Re your voltage reading, this sounds right to me, what did you expect?

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #7 on: May 04, 2016, 03:29:05 PM »
See https://lowpowerlab.com/forum/index.php/topic,1860.msg13476.html#msg13476 for my implementation.

Re your voltage reading, this sounds right to me, what did you expect?

Tom

Thanks Tom. Well I have almost 5.8 volts when I measure the batteries with my meter, I guess I was expecting 5.8 volts. I guess I am not sure why it would be in the 3 volt range, is there some limit to measuring voltage above 3.3v? Or is something in my code screwed up? (I reused this code):


Code: [Select]
long readVcc()
{
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
  ADMUX = _BV(MUX3) | _BV(MUX2);
#else
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA, ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
  uint8_t high = ADCH; // unlocks both

  long result = (high << 8) | low;

  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6402
  • Country: us
    • LowPowerLab
Re: Help with battery powered Moteino sketch
« Reply #8 on: May 05, 2016, 08:36:13 AM »
When you use the internal voltage reference you can only measure the VCC of the MCU. That is 3.3v always for the Moteino since it is regulated from VIN (the "3.3v" pin is an OUTPUT from the regulator so never feed input to that pin, unless you desolder the regulator - in which case you should not supply more than 3.5v or you will damage the radio).
What you need is a voltage divider from your original voltage into an analog pin of the Moteino. Something like this.
« Last Edit: May 05, 2016, 09:34:30 AM by Felix »

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #9 on: May 05, 2016, 09:05:05 AM »
If you want to use the 3.3V input, you could take your 4 AA batteries and wire them so that you have two sets of 3V pairs in parallel... ie, 3V at double the AH capacity.

Then you could connect the battery pack to 3.3V, but you'd also need to set fuses to use the 8mhz internal oscillator, and de-solder the regulator IC.

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #10 on: May 05, 2016, 09:33:43 AM »
If you want to use the 3.3V input, you could take your 4 AA batteries and wire them so that you have two sets of 3V pairs in parallel... ie, 3V at double the AH capacity.

Then you could connect the battery pack to 3.3V, but you'd also need to set fuses to use the 8mhz internal oscillator, and de-solder the regulator IC.
An easier alternative is to remove the VR, get rid of 4 AA batteries and switch to 2 Lithium (Eveready Ultimate) AA batteries.  These will give you up to about 3.4V nominally and will last two summers with the right power management code and you won't have to change any fuses in the Mote.

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #11 on: May 05, 2016, 12:31:51 PM »
Thanks Everyone -

I really have no desire to run 4 x AA batteries, that is just what I had in hand for battery holders when I started this project. This is my first run with the Moteinos.

What worried me was that I saw a rapid decline in battery power when first running my code on the Moteino that was was running on another clone making me think that I do not have my power reduction stuff in my sketch correct. Looking at the drop, it looked like I would be replacing my batteries (Energizer Advanced Lithium) every two months.

So far I have learned NOT to connect anything more than 3.3V to the 3.3 pin and some other great information, but I am still lookng for some help in glancing over my sketch to see if I have made any obvious errors in my power saving than others familiar with the best practices with the Moteino may spot right away.

Thanks

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #12 on: May 05, 2016, 03:14:55 PM »
I am still lookng for some help in glancing over my sketch to see if I have made any obvious errors in my power saving than others familiar with the best practices with the Moteino may spot right away.
Sorry, I TOTALLY missed that you had posted the sketch.  I've downloaded and will try to look at it sometime today.

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #13 on: May 05, 2016, 03:18:50 PM »
Tom -

Thank you!! It is much appreciated. I 'think' I have it right, but just don't know for sure.

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #14 on: May 05, 2016, 05:24:15 PM »
I looked at your sketch and, unfortunately, I know nothing about the jeelib library and can not comment on what power savings you should expect from that.

However, assuming that everything else is perfect, you have a relatively large current drain with your sensor wiring.   Because it is always powered the current (in mA) will be

Isensor = 1000 * 3.3 / (560 + Rsensor)

so, if your sensor is 560 ohms, you will have a continuous current drain of approximately 3mA.  This does not explain the large drop you were seeing, but running at 6V I'd say your radio is probably toasted, flash too (if you have it), and they would be a very large current drain.  Did you actually get any radio signal?

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #15 on: May 05, 2016, 05:33:50 PM »
I looked at your sketch and, unfortunately, I know nothing about the jeelib library and can not comment on what power savings you should expect from that.

However, assuming that everything else is perfect, you have a relatively large current drain with your sensor wiring.   Because it is always powered the current (in mA) will be

Isensor = 1000 * 3.3 / (560 + Rsensor)

so, if your sensor is 560 ohms, you will have a continuous current drain of approximately 3mA.  This does not explain the large drop you were seeing, but running at 6V I'd say your radio is probably toasted, flash too (if you have it), and they would be a very large current drain.  Did you actually get any radio signal?

Tom


Tom - Thanks. The radio and unit appear to be working fine. I have it parked all the way across the yard and it is reading the tape and transmitting the information just fine. Is there some way I can check to see if I have damaged the radio/flash? (besides just tossing it in the trash and chalking it up to a learning event)  8)

I am going to apologize in advance for this next question, but I sense in your answer that there might be a way to power down the sensor in between readings? When it is all said and done, I intend on only doing a reading once every 10 minutes since the pool does not change it's level very much over time, even when filling.


So I added this to my reduce_power() subroutine:

Code: [Select]
digitalWrite(ETAPE,LOW);

When I tried:

Code: [Select]
analogWrite(ETAPE,0);

The reading dropped to almost zero. Then I was reading that you could cal a digitalWrite to an analog pin to shut it off and it seems to work, at least in that the readings are correct again.

I am still too new to figure out how to actually 'see' if there is a power drop.
« Last Edit: May 05, 2016, 06:55:59 PM by G550_Pilot »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #16 on: May 05, 2016, 07:35:00 PM »
Tom - Thanks. The radio and unit appear to be working fine. I have it parked all the way across the yard and it is reading the tape and transmitting the information just fine. Is there some way I can check to see if I have damaged the radio/flash? (besides just tossing it in the trash and chalking it up to a learning event)  8)
If it's working, you're a very lucky person...
Quote

I am going to apologize in advance for this next question, but I sense in your answer that there might be a way to power down the sensor in between readings? When it is all said and done, I intend on only doing a reading once every 10 minutes since the pool does not change it's level very much over time, even when filling.
No apologies necessary.  You're trying to learn.

The way to reduce power is to cut off power to the sensor.  In your case, since the worst case current is less than 6mA, you can drive the 560 ohm resistor from a spare GPIO pin. So, disconnect  the 560 ohm resistor from 3.3V and connect it to the GPIO pin and then use digitalWrite() to that pin to turn it on and off (digitalWrite(pin, HIGH) to turn on, digitalWrite(pin, LOW)). 

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #17 on: May 05, 2016, 10:44:52 PM »
Tom -

Great, I will give this a try and let you know how it works out!

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #18 on: May 05, 2016, 11:15:16 PM »
Tom -

Thanks for the great tip. Here is what I did:

Code: [Select]
// Where is the ETAPE connected
#define ETAPE A0
const int ETAPE_POWER = 7;

Code: [Select]
void setup(void)
{
  pinMode(LED_RED, OUTPUT);
  pinMode(ETAPE_POWER, OUTPUT);

etc...

Code: [Select]
void loop(void)
{
  digitalWrite(ETAPE_POWER, HIGH);
  pool.resistance = analogRead(ETAPE);                      // read etape resistance
  digitalWrite(ETAPE_POWER, LOW);

etc


It looks like it works great. Readings are what they should be at with the etape at various levels. The resistance did go down a bit (600 to 580) but that is no problem.

Thanks again for the great idea!!
« Last Edit: May 05, 2016, 11:30:01 PM by G550_Pilot »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #19 on: May 06, 2016, 01:10:55 AM »
The resistance did go down a bit (600 to 580) but that is no problem.
Yes, that's due to the extra voltage drop at the GPIO pin.  This should be relatively consistent so you can probably reliably 'fudge' it.  The alternative would be to drive with an external transistor, but it sounds like you're ok with this implementation.

Enjoy the fully filled pool!

Tom

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #20 on: May 06, 2016, 01:33:41 AM »
Yes, I really do not need a specific value, just need to know the value when full, and when empty!

Code: [Select]
moteino_Pool_Water_Level_Sensor_ETAPE V1.0
RFM69HW Init>
Node: 25 Freq: 433Mhz Network: 210

You are currently configured to transmit data every 1 minute(s).

Here is the data that we are transmitting:
ETape Level: 571 Ohms, Battery voltage: 3.37V, Pool Level is OK
ETape Level: 728 Ohms, Battery voltage: 3.37V, Pool Level is LOW
ETape Level: 570 Ohms, Battery voltage: 3.37V, Pool Level is OK

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #21 on: May 10, 2016, 03:07:40 PM »
The resistance did go down a bit (600 to 580) but that is no problem.
Yes, that's due to the extra voltage drop at the GPIO pin.  This should be relatively consistent so you can probably reliably 'fudge' it.  The alternative would be to drive with an external transistor, but it sounds like you're ok with this implementation.

Enjoy the fully filled pool!

Tom

Hi Tom -

Well, I am totally stumped and completely stumped. I left for the weekend and came back to find my moteino totally unresponsive. I could not figure out what was wrong. I connected it back to the computer and had problems reading or writing anything to it.

On a whim, I unplugged it form the 4 x AA Energizer Advanced Lithium batteries that I had it connected to over the weekend and the moteino came back to life. Weird I thought, so I grabbed a meter and checked the voltage on the batteries. 1.94 volts. They were dead. Grabbing four new batteries, they measured 6.67 volts. I plugged those in and the moteino came back to life.

These were all brand new batteries that I got on Friday.

So obviously my low power mote is anything but a low power mote having drained 4 x AA Lithium batteries in the space of three days.  :( :o


I disconnected the lithium battery pack and threw my meter in the mix. With a new (non-lithium) battery pack reading 5.6v, I was drawing .007a (7mA) at "idle" and .013a (13mA) at read & transmit.

I took those reading and figured it based on Duracell's 2100mAh spec and figured I should have gotten somewhere close to 12 days (still horrible, but much better than 4 days).

I then put 4 new Lithium batteries on the mote (reading 6.8V) and the reading stayed the same (7mA and 13mA).

So then out of curiosity I went to two Lithium AA batteries (3.4v) and saw that my current draw dropped to 5mA (at "idle") from the 7mA above. Still it seems a bit high.

Then I threw on two Duracell AA batteries (2.95v) and something very strange happened. When I first connect the power, I see a jump in power from 0.000 to 0.006, but then it immediately drops to 0.000 again. I thought I lost the moteino, battery connection or something, so I tried again and saw the exact same result. This time I just waited, and sure enough, 1 minute later, the power jumps to 5 or 6mA for a second, then back to 0.000 on the meter. The radio transmitted as I see the updates in my database.

I have done this now three times, with 4 x AA Lithium, 2 x AA Lithium, and 2 X AA Duracell and only with the duracell (at a lower voltage) does the power go to zero (or as low as my meter will read) between transmits. If I use a higher voltage or lithium batteries, the power stays constant at 5mA until transmit, jumps to 13mA for a second then back to 5mA.

I thought the higher the voltage, the lower the amperage, and I m at a total loss as to why lithium batteries (or I assume more correctly a higher voltage) would result in a constant current draw on the moteino (exact same sketch on all tests) and tested on three moteinos.

Can you help me with what Im missing?


perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #22 on: May 10, 2016, 06:16:10 PM »
So an extra 5mA is drawn when the voltage is 3.4V, for both when the Moteino is supposed to be asleep and when it's transmitting? That could happen if an IO pin is driving a device powered by a lower voltage, the substrate diodes of the device could start to conduct. It could also be a blown regulator, it'll start to regulate over 3.3V but when that happens it might take more current if it's damaged.
Mark.
Edit: If you've ever applied power outside the spec of the unit  (e.g. 6V to 3.3V rail with devices that have absolute max ratings below that applied voltage) your best is to throw the unit away and start again, you could be chasing all kinds of problems as a result of subtle damage.
« Last Edit: May 10, 2016, 06:55:12 PM by perky »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #23 on: May 10, 2016, 06:45:20 PM »
The resistance did go down a bit (600 to 580) but that is no problem.
Yes, that's due to the extra voltage drop at the GPIO pin.  This should be relatively consistent so you can probably reliably 'fudge' it.  The alternative would be to drive with an external transistor, but it sounds like you're ok with this implementation.

Enjoy the fully filled pool!

Tom

Hi Tom -

Well, I am totally stumped and completely stumped. I left for the weekend and came back to find my moteino totally unresponsive. I could not figure out what was wrong. I connected it back to the computer and had problems reading or writing anything to it.

On a whim, I unplugged it form the 4 x AA Energizer Advanced Lithium batteries that I had it connected to over the weekend and the moteino came back to life. Weird I thought, so I grabbed a meter and checked the voltage on the batteries. 1.94 volts. They were dead. Grabbing four new batteries, they measured 6.67 volts. I plugged those in and the moteino came back to life.

These were all brand new batteries that I got on Friday.

So obviously my low power mote is anything but a low power mote having drained 4 x AA Lithium batteries in the space of three days.  :( :o


I disconnected the lithium battery pack and threw my meter in the mix. With a new (non-lithium) battery pack reading 5.6v, I was drawing .007a (7mA) at "idle" and .013a (13mA) at read & transmit.

I took those reading and figured it based on Duracell's 2100mAh spec and figured I should have gotten somewhere close to 12 days (still horrible, but much better than 4 days).

I then put 4 new Lithium batteries on the mote (reading 6.8V) and the reading stayed the same (7mA and 13mA).

So then out of curiosity I went to two Lithium AA batteries (3.4v) and saw that my current draw dropped to 5mA (at "idle") from the 7mA above. Still it seems a bit high.

Then I threw on two Duracell AA batteries (2.95v) and something very strange happened. When I first connect the power, I see a jump in power from 0.000 to 0.006, but then it immediately drops to 0.000 again. I thought I lost the moteino, battery connection or something, so I tried again and saw the exact same result. This time I just waited, and sure enough, 1 minute later, the power jumps to 5 or 6mA for a second, then back to 0.000 on the meter. The radio transmitted as I see the updates in my database.

I have done this now three times, with 4 x AA Lithium, 2 x AA Lithium, and 2 X AA Duracell and only with the duracell (at a lower voltage) does the power go to zero (or as low as my meter will read) between transmits. If I use a higher voltage or lithium batteries, the power stays constant at 5mA until transmit, jumps to 13mA for a second then back to 5mA.

I thought the higher the voltage, the lower the amperage, and I m at a total loss as to why lithium batteries (or I assume more correctly a higher voltage) would result in a constant current draw on the moteino (exact same sketch on all tests) and tested on three moteinos.

Can you help me with what Im missing?
clearly there is something wrong.  Can you please post your schematic?  The only difference SHOULD be that you lose voltage due to the voltage regulator, the current demand should be constant (since it's based on the 3.3V output of the regulator) so the lost power would only be   (Vin-3.3V) * Iavg

That your current is not the same with different voltages going to Vin, tells me there is some voltage dependent load in your system.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #24 on: May 10, 2016, 08:06:53 PM »
You mention that this problem has been seen on 3 Moteinos. Have all of these Moteinos had 6V applied to the 3.3V rail? If they have there might be common damage, and my guess it's the regulator.
Mark.

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #25 on: May 10, 2016, 10:05:51 PM »
The resistance did go down a bit (600 to 580) but that is no problem.
Yes, that's due to the extra voltage drop at the GPIO pin.  This should be relatively consistent so you can probably reliably 'fudge' it.  The alternative would be to drive with an external transistor, but it sounds like you're ok with this implementation.

Enjoy the fully filled pool!

Tom

Hi Tom -

Well, I am totally stumped and completely stumped. I left for the weekend and came back to find my moteino totally unresponsive. I could not figure out what was wrong. I connected it back to the computer and had problems reading or writing anything to it.

On a whim, I unplugged it form the 4 x AA Energizer Advanced Lithium batteries that I had it connected to over the weekend and the moteino came back to life. Weird I thought, so I grabbed a meter and checked the voltage on the batteries. 1.94 volts. They were dead. Grabbing four new batteries, they measured 6.67 volts. I plugged those in and the moteino came back to life.

These were all brand new batteries that I got on Friday.

So obviously my low power mote is anything but a low power mote having drained 4 x AA Lithium batteries in the space of three days.  :( :o


I disconnected the lithium battery pack and threw my meter in the mix. With a new (non-lithium) battery pack reading 5.6v, I was drawing .007a (7mA) at "idle" and .013a (13mA) at read & transmit.

I took those reading and figured it based on Duracell's 2100mAh spec and figured I should have gotten somewhere close to 12 days (still horrible, but much better than 4 days).

I then put 4 new Lithium batteries on the mote (reading 6.8V) and the reading stayed the same (7mA and 13mA).

So then out of curiosity I went to two Lithium AA batteries (3.4v) and saw that my current draw dropped to 5mA (at "idle") from the 7mA above. Still it seems a bit high.

Then I threw on two Duracell AA batteries (2.95v) and something very strange happened. When I first connect the power, I see a jump in power from 0.000 to 0.006, but then it immediately drops to 0.000 again. I thought I lost the moteino, battery connection or something, so I tried again and saw the exact same result. This time I just waited, and sure enough, 1 minute later, the power jumps to 5 or 6mA for a second, then back to 0.000 on the meter. The radio transmitted as I see the updates in my database.

I have done this now three times, with 4 x AA Lithium, 2 x AA Lithium, and 2 X AA Duracell and only with the duracell (at a lower voltage) does the power go to zero (or as low as my meter will read) between transmits. If I use a higher voltage or lithium batteries, the power stays constant at 5mA until transmit, jumps to 13mA for a second then back to 5mA.

I thought the higher the voltage, the lower the amperage, and I m at a total loss as to why lithium batteries (or I assume more correctly a higher voltage) would result in a constant current draw on the moteino (exact same sketch on all tests) and tested on three moteinos.

Can you help me with what Im missing?
clearly there is something wrong.  Can you please post your schematic?  The only difference SHOULD be that you lose voltage due to the voltage regulator, the current demand should be constant (since it's based on the 3.3V output of the regulator) so the lost power would only be   (Vin-3.3V) * Iavg

That your current is not the same with different voltages going to Vin, tells me there is some voltage dependent load in your system.

Tom

I'm probably missing something because Perky and Tom seem WAY more experienced than me... BUT... it seems obvious to me that, assuming you're running at the default 16Mhz clock rate, 2.95V supplied to VIN won't be enough (especially after the regulator dropout) to power the Atmega328p. 

To run at <3V I think you would need to program the fuses to use the internal 8Mhz oscillator... but even then I found weird behaviour when trying to use lower voltages on VIN. Things started working at <3V consistently for me when I de-soldered the regulator AND ran at 8Mhz.

EDIT: Weird thing is that when underpowering the 328p I generally found a much HIGHER current draw... as if the unit was stuck in a boot loop or something. This doesn't match your observations...
« Last Edit: May 10, 2016, 10:12:49 PM by davegravy »

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #26 on: May 11, 2016, 02:27:50 AM »
You mention that this problem has been seen on 3 Moteinos. Have all of these Moteinos had 6V applied to the 3.3V rail? If they have there might be common damage, and my guess it's the regulator.
Mark.

Hi Mark -

I have 5 moteinos and only one of them had 6v applied to the 3.3v rail, and that unit is working! None of the rest of them were even put together.

Tonight I took a brand new unit, soldered the pins on it and I see the exact same thing with this unit. 

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #27 on: May 11, 2016, 02:30:30 AM »

I'm probably missing something because Perky and Tom seem WAY more experienced than me... BUT... it seems obvious to me that, assuming you're running at the default 16Mhz clock rate, 2.95V supplied to VIN won't be enough (especially after the regulator dropout) to power the Atmega328p. 

To run at <3V I think you would need to program the fuses to use the internal 8Mhz oscillator... but even then I found weird behaviour when trying to use lower voltages on VIN. Things started working at <3V consistently for me when I de-soldered the regulator AND ran at 8Mhz.

EDIT: Weird thing is that when underpowering the 328p I generally found a much HIGHER current draw... as if the unit was stuck in a boot loop or something. This doesn't match your observations...

The mote seems to run fine on the 2 Duracell batteries, or at least has been the entire day!

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #28 on: May 11, 2016, 02:42:59 AM »

clearly there is something wrong.  Can you please post your schematic?  The only difference SHOULD be that you lose voltage due to the voltage regulator, the current demand should be constant (since it's based on the 3.3V output of the regulator) so the lost power would only be   (Vin-3.3V) * Iavg

That your current is not the same with different voltages going to Vin, tells me there is some voltage dependent load in your system.

Tom

Here is the diagram Tom, hopefully you can read it!

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #29 on: May 11, 2016, 03:57:20 AM »
I can't see anything wrong there.

One possibility, while I was bringing up a different system I temporarily forgot to add pull-ups for all unused pins in my initialization code which meant all inputs were floating, this caused about the same amount of extra current as yours that I couldn't account for (~6mA). It probably was due to significant amounts of internal oscillation as the inputs float around their threshold. I had a 3.3V regulator in mine, so I don't know the effects of varying voltage but there's a possibility that below a certain threshold most of the oscillation stops, and so that makes it voltage dependent.

Have a look through your sketch and make sure every single pin that has an input buffer is pulled either very close to Vcc or very close to GND (e.g. enable pull-ups, ot tie high or low, or drive high or low). In my system adding pull-ups on all unused pins removed the excess current completely, and it was several mA's worth.

Mark.

Edit: This sounds plausible. In fact the regulator stops regulating below 3.3V and acts like a small resistor (around a few ohms) which will act like a natural RC filter with the decoupling caps, it effectively changes the impedance characteristics of the power supply which is all part of the oscillation system.
« Last Edit: May 11, 2016, 04:28:01 AM by perky »

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #30 on: May 11, 2016, 08:27:53 AM »
The mote seems to run fine on the 2 Duracell batteries, or at least has been the entire day!

I am missing something then... Didn't you say the Duracell's were the problem?


Then I threw on two Duracell AA batteries (2.95v) and something very strange happened. When I first connect the power, I see a jump in power from 0.000 to 0.006, but then it immediately drops to 0.000 again. I thought I lost the moteino, battery connection or something, so I tried again and saw the exact same result. This time I just waited, and sure enough, 1 minute later, the power jumps to 5 or 6mA for a second, then back to 0.000 on the meter. The radio transmitted as I see the updates in my database.

I have done this now three times, with 4 x AA Lithium, 2 x AA Lithium, and 2 X AA Duracell and only with the duracell (at a lower voltage) does the power go to zero (or as low as my meter will read) between transmits. If I use a higher voltage or lithium batteries, the power stays constant at 5mA until transmit, jumps to 13mA for a second then back to 5mA.


I'm assuming you don't have access to a variable voltage power supply? If you do, it might be useful to sweep the input voltage (CAREFULLY) to see what's going on and at what boundaries within the rated supply voltage things work/don't work.
« Last Edit: May 11, 2016, 08:29:50 AM by davegravy »

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #31 on: May 11, 2016, 12:21:11 PM »
The mote seems to run fine on the 2 Duracell batteries, or at least has been the entire day!

I am missing something then... Didn't you say the Duracell's were the problem?

No, the Duracells actually had the least current draw of any of the batteries!

I'm assuming you don't have access to a variable voltage power supply? If you do, it might be useful to sweep the input voltage (CAREFULLY) to see what's going on and at what boundaries within the rated supply voltage things work/don't work.

I do,  but not in these voltage ranges. I think mine starts at 4.8v and goes to 14volts. I see that Fry's has them pretty cheap, I may run down and pick one up. The added benefit (as I see it) is that is shows current draw in real time!
« Last Edit: May 11, 2016, 12:31:57 PM by G550_Pilot »

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #32 on: May 11, 2016, 12:27:56 PM »
As a side note, here is my battery graph since last night.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #33 on: May 11, 2016, 01:33:32 PM »
Did you check that all the unused pins that have input buffers have pull-ups?
Mark.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: Help with battery powered Moteino sketch
« Reply #34 on: May 11, 2016, 01:45:58 PM »
Quote
I temporarily forgot to add pull-ups for all unused pins in my initialization code which meant all inputs were floating, this caused about the same amount of extra current as yours that I couldn't account for (~6mA)

If you sleep in powerDown the 328p disconnects all I input buffers that don't have interrupts on them. So you'd only see increased power consumption while awake.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #35 on: May 11, 2016, 07:07:14 PM »
Quote
I temporarily forgot to add pull-ups for all unused pins in my initialization code which meant all inputs were floating, this caused about the same amount of extra current as yours that I couldn't account for (~6mA)

If you sleep in powerDown the 328p disconnects all I input buffers that don't have interrupts on them. So you'd only see increased power consumption while awake.

Interesting feature. Pity, this had a good ring about it.
Mark

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #36 on: May 11, 2016, 09:12:08 PM »
Well, two brand new Duracell batteries died about an hour ago. Less than 24 hours from start.

 :(

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #37 on: May 11, 2016, 09:28:21 PM »
This is very odd. Are you absolutely certain you're applying power to the correct pins? It is possible to power the board through an IO pin because of the substrate diodes. Pin numbers on the schematic please, and physical position of the pins on the Moteino so we can be sure the pin numbers have been counted properly.

Also, I assume there are no pin interrupts enabled that would cause it to wake up immediately it has been put to sleep, I know the atmega328p disables input buffers when asleep but it's possible noise might wake it up (or at least trigger the wakeup condition) just before it sleeps, then pull-ups might still be the problem.

Mark.

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #38 on: May 11, 2016, 10:38:51 PM »
Mark -

I have triple checked the connections. I ONLY have power connected to VIN, ground to GND, D7 for the sensor and A0 for the other side. Please see attached pics (don't laugh too loud my my poor soldering skills.

I have attached the sketch as well. I don't know what else to look for or what else to do to lower the power consumption.

I will read up more on settings the unused pins to make sure they are not sucking up any power they should not be using.

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #39 on: May 11, 2016, 10:39:18 PM »
Front

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #40 on: May 12, 2016, 12:27:39 AM »
OK, so I went out and purchased an Korad KD3005P Programmable DC power supply from Frys.

I also purchased a couple of good sets of test leads (as opposed to holding the multimeter leads against the power post with my thumbs) and set out to recreate my weird battery/current draw tests from the other day.

I used four different power sources:

1) Programmable DC Power Supply (Voltage to match batteries)
2) 2 x AA Energizer Ultimate Lithium Batteries (3.622 volts)
3) 2 x AA Energizer Advanced Lithium (3.420 volts)
4) 2 x Duracell Alkaline Batteries (3.26 volts)

Using the test leads and a Fluke 117 meter, I tested all of the batteries on the mote I am having battery-sucking issues with right now.

All of the results (this time) were the same. 5mA idle and 13mA during transmit (once per minute). I can only assume that using actual test leads instead of my fingers made the measurements much more accurate.


Using the DC power supply, I started with a voltage of 3.3 volts and went up and down from there to determine if lower or higher voltages make a difference.

3.3v = 5mA/13mA
6.0v = 5mA/13mA
12v = 5mA/13mA

Which means all of those tests I did the other night were wrong and a waste of time (me doing them and you guys reading about them).




perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #41 on: May 12, 2016, 06:11:18 AM »
Looks OK, I can't see any miswiring.

One thing though, the flash is fitted and the MISO is common to both the flash and the radio. If the flash chip select is not high it could be trying to overdrive the radio MISO. If this is happening it would be dependent on what the state of the chip selects and MISOs are, both awake and asleep.

Could you check that pin D8 (PB0) is driven high permanently, even when asleep. That will eliminate the flash from overdriving anything.

Mark.

Edit: I'm not sure how the software is configured, but it might have a #define for whether the flash chip is fitted or not. If it's set to not fitted it might assume it's OK to either leave D8 floating (which is actually bad anyway as the flash chip might see it as low if it's fitted and could cause excessive current consumption if it's not), or drive it low. A simple fix might be to set that #define to flash fitted, that may well enable the D8 output and drive it high for you.
« Last Edit: May 12, 2016, 08:27:38 AM by perky »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #42 on: May 12, 2016, 08:49:14 AM »
Good catch on the Flash chip, Mark.

@G550_Pilot, add to your code:

Code: [Select]
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash

...
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)

...

void setup(void) {
... your other stuff

  flash.initialize();
  flash.sleep();     // put this in your loop code too, just to be safe

... the rest of your setup stuff
}


Your flash chip should be put to sleep to get the lowest power.  Also, I'll repeat my original statement, most of us have no experience with the jeelabs rfm12 library being used with an RFM69 and can not comment on whether that sleep code is appropriate.

Tom

UPDATE: This still doesn't explain the pathetic battery life you're getting.  Even if there was a constant drain of 10mA a pair of Ultimate Lithium AAs should last 300 hours.
« Last Edit: May 12, 2016, 09:06:20 AM by TomWS »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #43 on: May 12, 2016, 09:04:00 AM »
Well spotted Tom, I forgot about sleeping the flash. I'm going to give this a 95% chance of fixing it ;-)
Mark.

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #44 on: May 12, 2016, 01:47:52 PM »
OK, I added:

Code: [Select]
void setup(void)
{
 ...
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);

...
  flash.initialize();
  flash.sleep();


And I went from 5mA to less than what my Fluke 117 would register (0.000) at idle and 6mA at transmit. I verified this with both batteries as well as the bench power supply.

On battery, my sketch is reporting 3.359volts but my meter is showing 3.450volts (at the batteries). I assume that the Mote is showing less due to a voltage drop as a result of the circuit? Is that correct?


I have put a fresh set of batteries (Energizer Ultimate Lithium) on this and will watch and see what happens to the battery voltage over the next few days. It is pretty easy to spot when its sucking the batteries down.

Thanks Everyone for all of the help on this!
 

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #45 on: May 12, 2016, 02:12:34 PM »
Excellent news, glad it now seems to be working. It was always going to be something simple, just a case of tracking it down  ;)

There'll be a little IR voltage drop, and some tolerances with reference voltage for the ADC. It sounds pretty accurate considering.

Mark.

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #46 on: May 12, 2016, 02:25:14 PM »
Excellent news, glad it now seems to be working. It was always going to be something simple, just a case of tracking it down  ;)

There'll be a little IR voltage drop, and some tolerances with reference voltage for the ADC. It sounds pretty accurate considering.

Mark.
Assuming the Lithium AAs are feeding the Vin pin then you're reading the output of the VR, not the actual battery voltage.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #47 on: May 12, 2016, 02:35:23 PM »
UPDATE: This still doesn't explain the pathetic battery life you're getting.  Even if there was a constant drain of 10mA a pair of Ultimate Lithium AAs should last 300 hours.

That's true. I'm wondering whether if the flash CS was low and it was seeing a clock and MOSI data it might get itself into some weird current hogging mode at some point. It is odd that they failed that quickly.
Mark.

@TomWS: I completely misread the original post about the difference in voltages! Doh.

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #48 on: May 12, 2016, 04:39:42 PM »

Assuming the Lithium AAs are feeding the Vin pin then you're reading the output of the VR, not the actual battery voltage.

Tom

Tom -

Yes I am feeding power to the Moteino at VIN.

That does raise a question. I have read several times to NOT use VIN but a 3.3v pin instead (assuming that your input voltage is around 3.3 volts).

Why exactly is that?

Also, if I wanted to read the actual battery voltage as opposed to the output of the VR, what would I be looking at...?

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #49 on: May 12, 2016, 06:20:24 PM »


That does raise a question. I have read several times to NOT use VIN but a 3.3v pin instead (assuming that your input voltage is around 3.3 volts).

Why exactly is that?


The regulator uses some power,  so to operate from a tiny battery like a coin cell you need to shave off this excess.


Also, if I wanted to read the actual battery voltage as opposed to the output of the VR, what would I be looking at...?

You need to measure the battery using an analog pin.  A resistor divider will divide the battery voltage to a level you can read,  and then in software you need to scale the measured level to compensate for the divider. There's a bunch of pastaposts on here dealing with this topic.

EDIT: Fixed silly autocorrect
« Last Edit: May 12, 2016, 08:36:19 PM by davegravy »

G550_Pilot

  • Full Member
  • ***
  • Posts: 151
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #50 on: May 12, 2016, 06:26:53 PM »

The regulator uses some power,  so to operate from a tiny battery like a coin cell you need to shave off this excess.

So at what point (voltage wise) is it OK to input on a 3.3 pin as opposed to VIN? Would this be acceptable under say 4volts (2 x Lithium AA batteries)?

You need to measure the battery using an analog pin.  A resistor divider will divide the battery voltage to a level you can read,  and then in software you need to scale the measured level to compensate for the divider. There's a bunch of pasta on here dealing with this topic.

Got it. So I run a resistor from the positive side of my battery to an analog pin, then deal with the conversion in my sketch? Is that correct?

Also, if I did not want to go that route, would the voltage measurement that I am getting now stay constant until the voltage dropped below the max voltage the VR supplies? Basically, the battery will read a fixed voltage until it drops below the VR limit, then read the correct voltage still allowing me time to change my batteries before they go dead?


Thanks!

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #51 on: May 12, 2016, 08:41:21 PM »
Ok, trying to answer the questions and suggestions in sequence:

A. the Processor, with it's normal 'read VCC' function, will read the supply voltage to the Processor.  Not the supply voltage to the voltage regulator.
B. Yes, the voltage regulator consumes some quiescent current, but it is very small compared to your overall budget and supply (AA batteries).  Mentioning coin cells in this context is probably more distraction than helpful.
C. Yes, you can measure other voltages, including the battery's, if you use an analog input, a voltage divider and scale the reading by the measured VCC but there are two factors you need to consider before doing this:
1. The resistor divider will draw cpointontinuous current from the voltage source - generally not a good thing in a battery operated device.
2. The measurement usually uses VDD as the reference (to get good scaling), but if VDD is variable (and it ALWAYS is - to some extent) then you might need to measure VDD using the bandgap reference and then scale all other measurements accordingly.  Now one could ask that if you can use the bandgap to get the basis for VDD, why not use it for all other measurements?  Mainly 'cause its easier to use the standard reference (VDD), but since it's your processor, you can do anything you want  :)  Also, if all you care about is whether the battery is doing well or is getting weak, measuring against the 3.3V VDD is probably accurate enough.
3. (extra bonus factor): You need to learn about the input resistance vs capacitance of analog inputs in order to get a reliable reading from a high resistance source.  Plenty of discussion of this here and on the web.

Net: If you absolutely NEED to know the EXACT battery voltage and it is greater than VDD, you must use a voltage divider and I recommend using a load switch to switch the divider off when not reading.  If you just need to know whether your battery is dying, then reading the VR output MAY be sufficient.  However, this is only generally true if the battery still has some 'headroom' at <3.3V (this rules out most batteries except alkaline and possibly  SLA). 

Tom

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #52 on: May 12, 2016, 08:43:05 PM »
There's a bunch of pastaposts on here dealing with this topic.

EDIT: Fixed silly autocorrect
Gosh!  I thought the original WAS correct!

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #53 on: May 12, 2016, 08:48:47 PM »


So at what point (voltage wise) is it OK to input on a 3.3 pin as opposed to VIN? Would this be acceptable under say 4volts (2 x Lithium AA batteries)?

The RFM69 is the limiting factor here. I believe it can safely accept up to 3.8V but you'd be wise to check the datasheet as my memory's not amazing.

Got it. So I run a resistor from the positive side of my battery to an analog pin, then deal with the conversion in my sketch? Is that correct?

Also you'll need a resistor of approximately equal value going to the negative side of your battery to complete the voltage division. Possibly a capacitor too depending on how large your resistors are. Read up on past threads here.

Also, if I did not want to go that route, would the voltage measurement that I am getting now stay constant until the voltage dropped below the max voltage the VR supplies? Basically, the battery will read a fixed voltage until it drops below the VR limit, then read the correct voltage still allowing me time to change my batteries before they go dead?

Almost... once the battery drops below about 3.3V, the voltage you read will slightly lower than the battery voltage due to dropout from the regulator. The problem you might find is that lithium batteries drop very little voltage until they are almost completely dead, at which point voltage nosedives. If you wait for the voltage to pass 3.3V before sending a notice, depending on the battery you use you might not get much of a head's up before your battery kicks the bucket. The extra power draw from sending the low battery notice itself could be the final nail in the battery's coffin!

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #54 on: May 13, 2016, 04:58:30 AM »
The problem with depleting lithium cell's apparent output voltage nosediving is primarily due to a rapid increase in internal resistance, not its internal voltage. The curves you see are usually shown with a specific current load, and the effective resistance of that load forms a voltage divider with the battery's internal resistance. That means if you are taking bursts of high current like when TXing the voltage dip due to that can be very large, so it's important to try to measure the voltage while under high load conditions to detect that condition.

Applying power form a lithium cell to the 3.3V output side of the regulator could be beneficial for quiescent current, but only if you remove the regulator. There is a P channel MOSFET in the regulator with the intrinsic diode pointing from Vout to Vin, so if you connect the voltage to Vout it will actually drive through the diode onto Vin, powering up the regulator and you'll still be sinking the regulator's quiescent current. You would need to physically remove the regulator or disconnect it from its Vout to stop that. 

When the lithium cell is close to depletion its internal resistance will dominate the resistance of the regulator, so it's dubious as to whether there is any benefit from the removal of the small resistance of the regulator in that condition (and of course while the battery is not depleted you have plenty of headroom anyway).

Mark.

Edit: It is sometimes difficult to measure the voltage at the highest peak current, the radio for example will do that for a very short time while transmitting. It could be useful to actually put a dummy load on the board that you can switch on or off and only turn it on when measuring the voltage. You could do that regularly, say every hour, and not eat too much into your capacity budget (you could, for example, choose low value resistors for your voltage divider for the ADC and use a high side switch).
« Last Edit: May 13, 2016, 05:20:35 AM by perky »

TomWS

  • Hero Member
  • *****
  • Posts: 1925
Re: Help with battery powered Moteino sketch
« Reply #55 on: May 13, 2016, 07:45:34 AM »
Very good summary, Mark.  I agree about measuring under a loaded condition so I've taken to using a low resistance (typically going for 50-100mA) on the gate/drain resistor of the P Channel on the battery divider load switch (lower resistance on the divider would also work).  This way the battery is loaded only when measuring, but it is loaded with a meaningful value and doesn't require any additional parts.  Alternative is to simply accept that the few milliamps of the processor while measuring is sufficient load to know that your battery is about to fall off the cliff - the problem with this approach is that you may not have the current to report it unless you've got enough capacitance to sustain the brief TX load (of course, this will also affect the processor reading unless you isolate the capacitance).

Your discussion also demonstrates why measuring a Lithium battery by measuring the output of the VR is pretty pointless.  By the time you'll see a difference in the VR output, you wouldn't have enough energy to measure it, let alone report it.

Net: accurately measuring your battery voltage should not be considered a simple matter of adding a couple of resistors to your A0 pin (or A7 as some shields are wired).

Tom


WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #56 on: May 13, 2016, 10:15:18 AM »

Edit: It is sometimes difficult to measure the voltage at the highest peak current, the radio for example will do that for a very short time while transmitting. It could be useful to actually put a dummy load on the board that you can switch on or off and only turn it on when measuring the voltage. You could do that regularly, say every hour, and not eat too much into your capacity budget (you could, for example, choose low value resistors for your voltage divider for the ADC and use a high side switch).

Would that be better than, say, transmitting a longer message from the radio if your voltage measurement needs extra time?

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #57 on: May 13, 2016, 01:57:58 PM »

Edit: It is sometimes difficult to measure the voltage at the highest peak current, the radio for example will do that for a very short time while transmitting. It could be useful to actually put a dummy load on the board that you can switch on or off and only turn it on when measuring the voltage. You could do that regularly, say every hour, and not eat too much into your capacity budget (you could, for example, choose low value resistors for your voltage divider for the ADC and use a high side switch).

Would that be better than, say, transmitting a longer message from the radio if your voltage measurement needs extra time?

Speaking of using radio transmission as an aid to measuring battery voltage, does Felix's RFM69 library provide a convenient means to do this, or would one need to modify the library or write their own to achieve this? I'm guessing the latter...

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #58 on: May 14, 2016, 09:49:35 AM »
Speaking of using radio transmission as an aid to measuring battery voltage, does Felix's RFM69 library provide a convenient means to do this, or would one need to modify the library or write their own to achieve this? I'm guessing the latter...

That's not actually a bad idea, it would allow a very high resistance voltage divider with a smoothing cap to lower its impedance during ADC measurement externally without a high side switch (but note there's a large RC constant for that so the transmitter might have to be on for several hundred ms to allow it to settle).
Mark.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #59 on: May 14, 2016, 11:54:34 AM »
Speaking of using radio transmission as an aid to measuring battery voltage, does Felix's RFM69 library provide a convenient means to do this, or would one need to modify the library or write their own to achieve this? I'm guessing the latter...

That's not actually a bad idea, it would allow a very high resistance voltage divider with a smoothing cap to lower its impedance during ADC measurement externally without a high side switch (but note there's a large RC constant for that so the transmitter might have to be on for several hundred ms to allow it to settle).
Mark.

@perky
It would be great to get your input on the specific details (i.e. specific component values) of what you would consider to be an ideal hardware setup.  Regarding the "settle" time, the evidence collected so far (see link below) is that much of the required wait time is consumed by the very first conversion, regardless of whether settling has occurred or not.  So, it's best to launch the first conversion immediately upon waking up, so you can get other useful things done while the ADC initializes and comes up to speed.  For more detail in that regard, see:  https://lowpowerlab.com/forum/index.php/topic,1305.msg13013.html#msg13013
« Last Edit: May 14, 2016, 11:56:19 AM by WhiteHare »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #60 on: May 15, 2016, 07:42:37 AM »
It seems to me you would need to know exactly when the transmitter is transmitting as to when to sample the ADC, or alternately continually sample at the highest rate possible from intitiating transmission until the end and use the lowest recorded value. You'd also need a low source impedance on the voltage divider (<10k) for the ADC to sample correctly, if you use high value resistors you'll need a cap but that has a long RC constant, your radio would need to tx for a long time and the ADC conversion rate won't even come into it. Maybe 1Mohm total divider with 10nF cap. At 3.3V. The Thevenin equivalent would produce an RC constant of around 5ms, so you may have to wait up to 50ms to get a stable voltage to read. It would sink 3.3uA constantly though. Higher value resistors would decrease the quescent current at the expense of increasing the settle time at the ADC.

If you go for speed (i.e. low tx time) you'll end up using lower value resistors with little or no capacitance for the divider. That means you'll need a high side switch, and if you've got that there's no real point in using the radio as you could easily make the resistor values draw a known current. You'll need to size those resistors so they draw the required current at the lowest voltage that the radio is to work at.

Mark.



Mark.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: Help with battery powered Moteino sketch
« Reply #61 on: May 15, 2016, 09:49:58 AM »
Quote
It seems to me you would need to know exactly when the transmitter is transmitting

Once you set the radio to TX it will send preamble until you switch it back to standby. So you could just setMode( TX ); delay( 1 ); measureVcc(); setMode( standby). The delay because it does take some time for PLL to lock etc.

The different powerLevels give you a nice way to control the load on the battery during measurement. I think you could monitor Vcc even if you're using a voltage regulator without voltage divider, provided you don't use full tx power in the normal course of business: just set the radio to TX and increase powerLevel until you either drop below 3.3V or hit 31.

If you can expend 130mA and still stay >3.3V you're safe for a while longer. And given the fairly fixed internal resistance of the battery you can extrapolate what your "normal load" voltage currently is.

Joe

davegravy

  • Jr. Member
  • **
  • Posts: 56
  • Country: ca
Re: Help with battery powered Moteino sketch
« Reply #62 on: May 15, 2016, 01:51:34 PM »
Rather than setting the radio for TX then back to standby specifically for the purpose of measuring the battery, I was thinking of taking said measurement as part of a regular transmission.

In my applicaiton, when the moteino exists listenmode because an update is requested from Gateway, the response is given using sendWithRetry(). If battery measurement could be taken as part of  sendWithRetry, stored, and returned to gateway with the NEXT requested update... the gateway would always be behind one update on battery level, but it would still show the trend, and it would reduce overhead.

Also even though the gateway is one update delayed, the node locally is not, and can use it's knowledge of the battery level to make intelligent decisions about power management... whatever that may mean.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Help with battery powered Moteino sketch
« Reply #63 on: May 15, 2016, 01:58:45 PM »
Once you set the radio to TX it will send preamble until you switch it back to standby. So you could just setMode( TX ); delay( 1 ); measureVcc(); setMode( standby).
Joe

Yes, good point. You still would have a problem with the ADC voltage settling on the voltage divider though, you'd need a lower impedance resistor network for that which would require a high side switch to be turned on and off during that period.
Mark.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: Help with battery powered Moteino sketch
« Reply #64 on: May 16, 2016, 01:48:19 AM »
Quote
You still would have a problem with the ADC voltage settling on the voltage divider though, you'd need a lower impedance resistor network for that which would require a high side switch to be turned on and off during that period.

Yeah - these days I mostly run without regulator so I don't do much of this anymore. I do remember my lake thermometer though which does have a very high impedance voltage divider. If I remember correctly a 200us delay handled the issue in that case. I did not add a cap.

But these were the days when I considered 4uA an acceptable sleep current - and the mote is potted in epoxy so I can't even fix it :-)

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Help with battery powered Moteino sketch
« Reply #65 on: May 16, 2016, 11:51:53 AM »
Rather than setting the radio for TX then back to standby specifically for the purpose of measuring the battery, I was thinking of taking said measurement as part of a regular transmission.

In my applicaiton, when the moteino exists listenmode because an update is requested from Gateway, the response is given using sendWithRetry(). If battery measurement could be taken as part of  sendWithRetry, stored, and returned to gateway with the NEXT requested update... the gateway would always be behind one update on battery level, but it would still show the trend, and it would reduce overhead.

Also even though the gateway is one update delayed, the node locally is not, and can use it's knowledge of the battery level to make intelligent decisions about power management... whatever that may mean.
Exactly.  The notion is that you're leveraging current that's going to be spent anyway, not expending extra current for the sole purpose of taking a measurement of voltage under load.
« Last Edit: May 16, 2016, 11:54:47 AM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: Help with battery powered Moteino sketch
« Reply #66 on: May 16, 2016, 03:53:42 PM »
Quote
Rather than setting the radio for TX then back to standby specifically for the purpose of measuring the battery, I was thinking of taking said measurement as part of a regular transmission.

Sure why not. I actually do something similar in my bootloader: I need to detect whether I'm running on a coin cell since then I can't run the radio at max tx. So I just tx at 0dBm and if that doesn't succeed and voltage during tx didn't significantly decline I switch to full power.