simple high voltage battery gauge - Page 1
Forum section: electronics / projects

author: dutchy
author_rank: Newbie
timestamp: November 12, 2017, 05:05:13 am
content: I am trying to find more information about my plan to use a standard LM3915 as a battery gauge.but the problem is that it's limit is around 20V. i want to measure a voltage of a 16S lipo pack (65.6V charged) witch is way above any limit it has, even of the HV version.i do have a 12v supply in order to power it in a controlled manner but i need to kick down the 60V+ that it needs to measure by a factor of 5 in order to get a decent input signal that it can use without releasing the magic smoke that is needs to operate. the negative is shared by both voltages. i also have a fully isolated 12v supply that i can tap into.the Great Google and its datasheet have no working applications that i can find that can make this work and not even our friends from asia have a meter that you can set to the min-max voltages that i need.if you already did the math then you would be screaming already that 16S is not 65.6V charged, i am keeping the battery between 3.1V and 4.1V per cell in order to maximize lifespan.fun facts about the pack: 400 cells big and clocks in at a solid 18KG and can deliver 12kW without much difficulty. dead short current is something i do not want to find out, i recon in the 75kW range.i build the scooter for me but sadly the wife claimed ownership as it is much better then the petrol one that i can borrow from her now. (aint marriage grand)but for her i want to have a simple 10 led bar for battery capacity instead of the volt meter i originally fitted for me and understandably she cannot understand what the actual charge is. a simple 10 bar from something like a LM3915 that i still have a couple of would be perfect but i need a way to axe the voltages down by a factor of 5.it is probably stupidly simple but i am not seeing it at the moment.

author: ludzinc
author_rank: Unknown
timestamp: November 12, 2017, 06:43:17 am
content: Am I missing something, but why not just use a voltage divider?

author: phil from seattle
author_rank: Super Contributor
timestamp: November 12, 2017, 07:41:46 am
content: Quote from: ludzinc on November 12, 2017, 06:43:17 amThat was my thought as I read looking for a reason the OP was NOT using a divider.One other point - a voltage gauge won't give you a true energy gauge as the Li-whatever discharge curve isn't linear. You'd have to coulomb count for that.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 12, 2017, 07:51:18 am
content: Quote from: phil from seattle on November 12, 2017, 07:41:46 amGood enough for many purposes, especially if you use it personally and kind of know how the battery behaves. Adding a LUT would make it more than good enough, but that would require an MCU.But the OP would need LM3914 instead, which is the linear version. LM3915 is logarithmic, which is useless.Also, some offsetting (level shifting) is needed -- a 0 to 4.2V/cell display is kind of useless with only 10 steps.Now, it's suddenly much cheaper and simpler to just do it on a microcontroller, if you have any experience. If not, it's a great way to learn.Edit: Oh, almost forgot that offsetting is very easy in LM391x since they offer you the resistor divider chain ends. So you just need a single resistor.

author: Ian.M
author_rank: Super Contributor
timestamp: November 12, 2017, 08:01:47 am
content: The LM391x family bargraph display drivers are long discontinued. The modern way to do it is high impedance voltage divider => micropower buffer OPAMP => MCU ADC input, then have the MCU do whatever fancy maths you like to estimate the remaining capacity and display it however you like ranging from simple bar LEDs to animated icon on an OLED screen.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 12, 2017, 08:07:30 am
content: Yes, you don't even need an opamp as you can simply buffer the high-impedance divided input using a capacitor right next to the ADC MCU input pin, providing low impedance the ADC needs for the conversion. Minimum recommended value for this cap would be 10n, but a higher value could offer some extra RC filtering for antialiasing.The first code revision can be extremely simple, in a while(1) loop, just read the ADC and go through ten if-elses to drive the required LED on. The great thing is, you can select the threshold values for each LED by looking at the cell discharge curves posted on the internets instead of doing a linear curve.

author: Ian.M
author_rank: Super Contributor
timestamp: November 12, 2017, 09:16:56 am
content: For less than 1/2 LSB error due to charge sharing during sampling, the external capacitor at the ADC pin should be greater than 2(N+1)times the internal sampling capacitor of the ADC, where N is the number of bits of ADC resolution. For older PICs with 10 bit ADCs with 120pF sampling caps, that works out to 246nF and a 330nF cap is suitable. However there is a limit on input source resistance even with a capacitor - the input leakage current. e.g. a PIC's input leakage can reach +/-1uA, which is 1V developed across a 1Meg resistor. As a LiPo cell's terminal voltage range is from 4.2V to 3.0V, a swing of only 1.2V, its obvious that the input resistance *MUST* be much much lower than 1Meg.. This limits the maximum resistor values that can be used in the divider, which if its permanently connected to the battery pack may be problematic as a standing current higher than a fraction of the equivalent self-discharge current will kill any battery stored with insufficient charge. Adding a low input leakage micropower OPAMP buffer allows the divider chain resistors to be increased by at least two orders of magnitude without compromising accuracy, and also lets the input be offset to better use the ADC input range for greater accuracy.Its easier to code by putting the thresholds in order in a const array and loop through it incrementing the index while the reading is below the threshold, then use the index to determine which LED (dot) or LEDs (bar) to drive.Something like:Code:#define SCALE(x) ((int)(1024*(x)/5.0)const int lookup[]={SCALE(3.0), SCALE(3.7), SCALE(3.75), SCALE(3.8), SCALE(3.95), SCALE(4.15), INT_MAX};//...do{bv=readADC();idx=0;while(lookup<bv) {idx++;}showBar(idx);}while(1);

author: Siwastaja
author_rank: Super Contributor
timestamp: November 12, 2017, 09:42:45 am
content: For 8 bits of actual resolution (1LSB error), and a sampling capacitor of 20 pF, this works out to 5.16nF. Besides, this formula assumes the worst case of the sampling capacitor being at a totally wrong state of charge. When a single input is measured repeatably (no mux changing, no long wait times), people who have completely forgotten the impecance issue, or use a capacitor orders of magnitude too small, still usually getsurprisinglyusable results. In a case where I couldn't use a cap or an opamp (due to the measured thing being an unbuffered internal temperature sensor - extremely stupid design from ST), I actually made a compensation algorithm that looks at the previous converted value (from the previous input channel) to estimate how much of that charge is remaining in the sampling cap. Not accurate, but made the completely unusable internal temperature sensor to be usable enough for protection functionality.Precision solutions are designed differently, anyway. In situations like this, I typically just put the 100nF 0402 cap there, the same type I use for power bypassing, and call it a day.I think the most important point is the quiescent current through the resistor divider; indeed, the divider needs to be disconnected for long-term storage; if not, the measurement system kills the battery. I have seen this countless of times when people design battery "protection" devices that become self-destruction devices instead.In one case (single cell), I solved the issue by directly powering the MCU from the cell, then used an IO pin as the bottom of the resistor divider to "turn it off", then utilized sleep modes. This worked well given some software calibration (including offset, gain and temperature coefficient, all individually calibrated using an calibration oven/PSU jig), since the IO pin added a temperature dependent offset. But unit-by-unit calibration was necessary anyway due to the not-so-great internal voltage reference.But, if the OP wants simplicity and is thinking about just driving ten LEDs for some kind of status indication, and is disconnecting the measurement device from the battery for storage, then all of this doesn't matter. Doing it with an MCU and the code you posted is the easiest bet, and the BOM is cheapest that way. (It's nice to see well crafted C code where the details are right, by the way.)

author: dutchy
author_rank: Newbie
timestamp: November 12, 2017, 12:44:35 pm
content: Quote from: Siwastaja on November 12, 2017, 07:51:18 ami also have a bunch of those, i never really realised what the difference was. thanks.going for a coulomb meter based system is not needed. this is just as a indication. and the voltage drop is not so bad while driving so it remains fairly accurate. my BMS does have a proper current sensing and logging enabled. i use that information once a moth or so to check up on the battery and see if everything is still within spec. the LM3914 is just a easy way for the wife to see if she did not forget to charge it or see how far see can still go if she wants to make a detour. it has a total range of 190km so she will not get stranded fast but there needs to be some ease of mind.Quote from: Siwastajathis is kind of my issue, i need 2 trim pots on both the lower and high end and can handle a 60ish volt input and that i can tweak for myself. you can do this with these chips but i have no idea how the resistor values should work to handle such a out of spec voltage. the datasheets and examples online only talk about a input of 24v peak. useless for my application.Quote from: Siwastajai have a couple of arduino mega's in a drawer, but i find that a tad overkill for a simple 10 led meter.Quote from: Siwastajathere is the issue for me. i always had difficulty in setting up proper resitor values in divider networks and i do not know how these chips will behave whith such high voltages. id really hate to blow stuff up if i can prevent it.i can run the pin 5 on 12v no problem, but getting a voltage divider from the 1.2v reference on pin 4 6 and 7 right up to the range of 50~65V is another thing. that is quite the difference. with this i need help to get my head around.great reading material you have all supplied, really awesome for taking the time and coming up with ideas. but please do not worry about power saving. the battery has a total capacity of 4.2kWh at 57.6V nominal. it would take decades to run it flat with a simple low power led.i also have a fully isolated 70>12v converter (decent one from mean well) that runs the GPS based odometer wich i keep powerd all the time (about 50mA at 12v) so it does not have to reaquire the gps signals every time you turn the scooter on. it is also meant as a daily driver so it gets charged every day. the discharge resistors mounted in the motor controller use more then what a led uses. so no worries there.i am a fan of microcontrollers like the arduino (my aquarium lighting and maintenance is done fully automated by it) but in this case it is way overkill and i just need something that i can make on a piece of perfboard and tuck away under the dash.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 12, 2017, 01:19:10 pm
content: This is super hyper basics, really.For example, take your 70V input and put it through a resistor divider of 100k and 10k, and you'll have a 10/(100+10) * 70V = 6.36V range to work with now. So now you are not blowing anything up.https://en.wikipedia.org/wiki/Voltage_divider

author: Ian.M
author_rank: Super Contributor
timestamp: November 12, 2017, 01:43:42 pm
content: If you actually have NOS LM3914 chips, their SIG input bias current is under 100nA, so as long as the divider Thévenin impedance is under 300K it should be fine. A 11:1 ratio divider with a 1Meg upper resistor and a 100K lower resistor + 0.1uF cap across the lower resistor should do nicely to feed SIG. That gives you 5.96V fully charged dropping to 4.36V fully discharged, so you need the LM3914, powered from 12V, configured for an extended scale centered on 5.15V with a range of about 1.5V. Start from Figure 17. Expanded Scale Meter, Dot or Bar in theT.I. LM3914 datasheet, but feed V+ and the LEDs from a 12V supply and tweak the resistor values R1-R4 for the slightly modified input range required.N.B. If you add a circuit to lift the voltage at the lower end of the divider circuit slightly depending on the load current from the battery, you can compensate for the voltage droop on load and avoid it giving a low battery indication at full throttle.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 12, 2017, 02:02:13 pm
content: LM3914N-1/NOPB (DIP), LM3914VX/NOPB and LM3914V/NOPB are all listed with active status and standard manufacturer lead time of 6 weeks on Digikey, so they don't look too obsolete to me.

author: Ian.M
author_rank: Super Contributor
timestamp: November 12, 2017, 02:18:02 pm
content: I must be misremembering, I was sure some of the LM391x series parts have gone out of production. In that case, yes a LM3914 based solution is still a viable alternative to a MCU for a one-off. However, even for a one-off the ease of trimming the range and linearity in software makes a ATmega328P (so a novice can use the Arduino toolchain), directly driving a 10 LED bar graph quite attractive even though it will need a 7805 regulator to power it and a current limiting resistor for each LED.

author: drussell
author_rank: Super Contributor
timestamp: November 12, 2017, 02:33:48 pm
content: The 3914 is still produced, it is just the '15 and '16 that were recently discontinued.