Author Topic: Battery Voltage Monitoring  (Read 35049 times)

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Battery Voltage Monitoring
« Reply #45 on: March 01, 2018, 05:59:34 PM »
I suspect it's not just the settling time, you'd need to slow the ADC clock right down so that the sample and hold window is large enough to allow the high impedance source to charge the S&H capacitor. Just allowing a longer settling time on the pin isn't enough.

Mark.
Wanna bet?   ;)

The MUX will charge the SH Cap as soon as the MUX is changed if there is no conversion underway.  The charge in this case is a function of the source impedance and the setup time of the MUX.  Once the conversion is underway, the source is actually disconnected from the S&H cap one clock period after SC.

Another time related factor, however, is the effect of any filter capacitor on AREF if the reference voltage is changed.  If you're reading VCC, however, then this is the default reference and the AREF voltage should be stable.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Battery Voltage Monitoring
« Reply #46 on: March 02, 2018, 07:20:43 AM »
I've been labouring under the misapprehension that there was a 2 clock sample window! It appears I may have got confused with continuous sampling mode in the past. You're completely right, thanks Tom for pointing it out ;)

Mark.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Battery Voltage Monitoring
« Reply #47 on: March 02, 2018, 08:01:55 AM »
You're completely right, thanks Tom for pointing it out ;)
Dang!  I was hoping to make my retirement fortune off this bet!
Good working with you, Mark!
Tom

jf_orders1@outlook.com

  • NewMember
  • *
  • Posts: 6
Re: Battery Voltage Monitoring
« Reply #48 on: November 29, 2021, 10:40:57 PM »
Hi, this thread has not been active for a while but I have an application that relates to it and have some questions.  I'm using a Moteino 328P, LowPowerLab spec says 16 Mhz clock.  The board only has 3.3v pin.  My application is using 2 18650 Li-ion batteries in series that puts ~8v at the Moteino's Vin.  I want to warn user/protect the batteries....plan on warning when one battery is ~ 3v and shutting down @ 2.5v.  I'm assuming that 2 freshly charged batteries will discharge roughly the same so plan on sensing between the two batteries.   I played around with the code to measure Vcc....but that only measures what the processor is seeing after the voltage regulator, and if my 2 18650's in series falls below 3.3v, that means that I'm way past where I want to alert the user/shut down.

My current plan is as follows:
1) set ADC reference to AVcc (which should be pretty stable and close to 3.3v)
2) use 2 resisters as voltage divider to bring the center tap of my series batteries to less than 3.3v when batteries are fully charged.  That  is, read voltage of one battery and scale it to less than 3.3v when fully charged
3) use a digital pin to ground the voltage divider when I want to take a reading.  Set the digital pin to input (high impedance) when not reading so there is no current draw through the voltage divider
4) read the voltage via the ADC, adjust result to account for voltage divider and get the voltage across a single 18650 battery.  Base warnings and shutdown on that.

Question 1: Any issues with the plan?

Question  2: There was discussion above about ATmega digital pin protection circuit that would shunt over voltage to ground if the voltage on the digital pin was over spec......I'm avoiding this by having the voltage divider output at less than 3.3v max.  Does this make sense?

Question 3: Moteino spec says clock is 16 Mhz, so I'm setting the prescaler (ADPS0-2) 20 divide by 128, which makes the ADC clock rate 125 Khz.  I didn't see this addressed in the code (that I've looked at) above.  Is this the thing to do or is there some default that makes it unnecessary?

Last question: Seems like the Moteino processor is being fed by a 3.3v regulator....correct?

Responses much appreciated.  Thanks......jim

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #49 on: November 30, 2021, 12:17:06 PM »
Quote
I'm assuming that 2 freshly charged batteries will discharge roughly the same so plan on sensing between the two batteries.
Not sure that is a great assumption unless you can somehow guarantee they are the exact same capacity and quality and will discharge at the same rate.

1) ADC reference is already VCC.
2) OK
3) OK but use 10k or higher for divider, maybe set the ADC pin to INPUT when not used as well
4) OK

Q1: plan sounds OK
Q2: OK
Q3: Not sure you need to change any defaults, I don't know these values without digging the core files. IMO you should stick with defaults.
LQ: Yes, well known fact I think, I only make 3.3v boards.

jf_orders1@outlook.com

  • NewMember
  • *
  • Posts: 6
Re: Battery Voltage Monitoring
« Reply #50 on: November 30, 2021, 04:08:06 PM »
Thanks Felix!  This morning I woke up to the thought that there is another approach that works and uses no parts.....assuming my assumption about the batteries is correct (and I'll take your point about the validity of that assumption)....anyway, the alternate approach is:
1) power the Moteino from the first battery of the two batteries in series (3.7v).
2) power the motor controller using both batteries in series (8.4v)
3) use the ADC to back calculate AVcc and set warnings accordingly.  The Moteino and motor controller are mostly sleeping, so sleep draw is micro-amps.  The stepper is used infrequently and will draw from both batteries.  When the Moteino driving battery goes below 3.3v, there is still plenty of room to warn user.  I'll shut it all down when AVcc <= 2.5v.

thanks again......jim

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Battery Voltage Monitoring
« Reply #51 on: December 01, 2021, 09:12:50 AM »
That would only work if there is no LDO and the battery V==Moteino VCC. Otherwise you can't use an ADC pin to measure a V that's higher than VCC (setting AVCC higher than VCC is out of spec).

d00m178

  • Jr. Member
  • **
  • Posts: 82
Re: Battery Voltage Monitoring
« Reply #52 on: February 12, 2022, 02:55:29 PM »
Hi

Is it possible to share a good working schema and code for battery voltage monitor for LiPo that not drain the battery?
Currently Im using voltage divider with two resistor 470kΩ and 1M + cap 0.1mF connected to A2.
But I want to improve it if it possible. I've read about divider with the equal two resistors - maybe this variant better?