Electronic – How to use a gas gauge

battery-charginglithium ionlithium-poly

I must have missed an article, lesson at uni, or something obvious because I'm struggling to work out how to write some firmware to use a gas gauge to get out a rough percentage of battery remaining, e.g. "56%".

I'm primarily hardware-focused by trade and so whenever I've integrated them into professional products, the firmware has been handled by either a colleague or a contracted company. Now I'm just doing a design at home by myself and because of reasons, I've gone straight to using this STM part (instead of using a Sparkfun Module or something with pre-written and easy firmware) – because I actually want to learn, not just get something working.

So basically I was just after some advice on how they generally work. Obviously each part is probably unique in their own way, but in general I know:

  1. They monitor the through-current with the shunt resistor
  2. They monitor the battery voltage by tapping off the + and – terminals
  3. They monitor charge/energy/power flowing in and out of the battery, by combining these two measurements and some math

My question is: how do I get a percentage read-out from this? Especially since batteries all have different capacities and there is surely no way the GG knows what size battery I have plugged in?

I'm guessing I have to plug in a fully-charged battery when the system first "fires up" (for example, 400mAh), and then work out the percentage myself in the firmware by constantly subtracting/adding the charge that has flown in/out from the total 400mAh. The bit that confuses me a little is that this then assumes a fully charged battery was first inserted into the system but this definitely isn't always the case – Li-Po/Li-Ion batteries are usually shipped at ~50% charge (if I'm not mistaken) and would be installed into products straight away before being fully charged, thus making all these calculations wrong and pointless.

Is there something I'm missing? I can't find any detailed information on how to actually "use" these chips. Any help is much appreciated 🙂

Best Answer

Gauging the level of battery charge is not trivial at all. Accurate gas gauges, for example from Texas Instruments, use a built-in powerful MCU to calculate the charge level based on particular (selectable) chemistry model, accurate charge-in and charge-out measurements, and also track impedance of cell to track battery aging and get more accurate results. Gauge architecture also varies depending on whether it is built into battery, or residing at system level. Start here, Accurate gauging products for any battery system overview.