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

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: 1930
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: 1930
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: 1930
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: 1930
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 »