Coulomb counters - battery level gauge with a picaxe 08m2

JPU

Senior Member
Hi All

Has anyone had any experience of using a Picaxe to create a Coulomb counter. I have created a circuit to measure the Voltage of a Li-ion battery with a range 24-29V, however its not very accurate.

I read a thread once and I think is was here about someone who had created a circuit to count the current that had been used from a battery and then produce a battery gauge by subtracting the current counted from the "known" capacity of the battery to give a more accurate battery level compared to just a simple voltage reading.

If someone has experience or remembers that thread (I cant find it now!) or has any ideas which would help, as always I'd be very grateful for any help.

Thanks
 

mikeyBoo

Senior Member
hi JPU,
I am calculating & displaying “amp-hours used” on my kayak control project’s Picaxe Basic program in Misc. Projects. However, if you want a truly accurate “battery gauge”, it’s a little more involved (you have to know a little more about the battery you are using). The kayak program accurately displays amp-hours consumed, so you could combine the code with info. about the battery used.
http://www.picaxeforum.co.uk/showthread.php?28063-Picaxe-Kayak-Control-Project

I didn’t have enough code space to do an “operating time-remaining” on my project (I just poke it in my cellphone’s spreadsheet to find out). Battery voltage alone is fairly meaningless.
If you come up with Picaxe code that does that, please share with us. Could be really useful for solar cell batteries.

The attached .pdf explains everything you need to know. Good luck!
 

Attachments

stan74

Senior Member
I got a bewo 250W addon motor on an old mongoose and the display shows amongst other things the 36V li-po battery voltage. The moving battery level can be calibrated to represent a range of voltages.
The point is the battery voltage is a good indication of battery state. You see the battery voltage not recover after load when the battery voltage bar drops.
So I think an accurate voltage from a compressed range is useful to assess battery state.
 

Jeremy Harris

Senior Member
I got a bewo 250W addon motor on an old mongoose and the display shows amongst other things the 36V li-po battery voltage. The moving battery level can be calibrated to represent a range of voltages.
The point is the battery voltage is a good indication of battery state. You see the battery voltage not recover after load when the battery voltage bar drops.
So I think an accurate voltage from a compressed range is useful to assess battery state.
Not at all true for most good quality lithium chemistry cells, in fact using voltage as an indicator of state-of-charge is near-useless, as the only thing that will flag is "you've almost killed your battery", right at the end of the discharge characteristic. That's the whole point for needing an energy metering system. Years ago, a lot of budget ebikes were being sold with voltage-only charge state indicators, as the idiot manufacturers thought they could re-use the same systems that work OK with Lead Acid cells. It didn't take long to realise that voltage-only monitoring was useless in terms of determining state-of-charge, or remaining range, with the very flat voltage characteristics of good quality lithium chemistry cells during discharge. It's the reason that I first made this simple battery "fuel gauge" way back in 2010, using a Picaxe 08M: https://endless-sphere.com/forums/viewtopic.php?f=2&t=22675
 

John West

Senior Member
One of the (many) problems with battery discharge indicators is that often your gauge is attempting to predict the future, especially in applications like remaining range in an electric vehicle. It has to make assumptions about what rate the battery will be discharged at during the rest of the discharge cycle. But if that's an unknown, then a "gas gauge" type indicator will be off quite a ways, as higher rates of discharge dissipate more power in the form of heat within the battery itself than lower discharge rates do, and no sort of gauge indicates that lost power. So you can really only come close to an accurate measurement of what you have left if you have a fixed discharge rate.
 

mikeyBoo

Senior Member
This is the kind of stuff the Picaxe excels at: (would be a great project!)

Picaxe Battery Profiler: Ok lil’ Picaxe, here’s what I want you to tell me:
Battery claims to be 55 AH, meaning it is supposed to be able to supply 55/20 = 2.75Amps for 20 Hours
Is this true ? What is the real amp-hour capacity of the battery ? (Let me know, I don’t like to paddle)
Does Peukert’s Law really work ?
Can I back-calculate my battery’s real Peukert constant ?
How long will this battery last at a 5AH draw ? 10AH draw ?
Why are we here? What is time made of? (Ok, cut this, too code-intensive)

I don’t want to do this test manually, it could take days!!
Alright lil’ Picaxe, you need to run the following sequence:
Charge battery to capacity. (switch charger on/off & loads via relays)
Let battery sit (to cool)
Run test for 30 Hours into 2.75A resistive load, stop time at 10.5v cutoff (save results to RAM)
Let battery sit (to cool)
Charge battery to capacity.
Let battery sit (to cool)
Run test for 20 Hours into 5.0A resistive load, stop time at 10.5v cutoff (save results to RAM)
Let battery sit (to cool)
Charge battery to capacity.
Let battery sit (to cool)
etc. for 10A, 15A, 20A (Amps depends on battery being tested)

Come back after a week, save battery’s profile to my yak’s Picaxe controller. Ok battery vendor, you’re a damn liar!
Now I know what the battery will really do. A REAL BATTERY CAPACITY METER via my lil’ Picaxe buddy.

Repeat test every few months for each yak battery & put profile in yak’s Picaxe controller.
 

mikeyBoo

Senior Member
One of the (many) problems with battery discharge indicators is that often your gauge is attempting to predict the future, especially in applications like remaining range in an electric vehicle. It has to make assumptions about what rate the battery will be discharged at during the rest of the discharge cycle. But if that's an unknown, then a "gas gauge" type indicator will be off quite a ways, as higher rates of discharge dissipate more power in the form of heat within the battery itself than lower discharge rates do, and no sort of gauge indicates that lost power. So you can really only come close to an accurate measurement of what you have left if you have a fixed discharge rate.
Yep, you're right. If you look at the .pdf I posted, it illustrates the huge difference in run time versus rate of discharge. The only way to get close is to plug in values to the formula. The ambient temp. will also have an effect on the calculation. The formula works for me because I troll at a constant speed. An analog meter is useless. Looks like a a good Picaxe project.
 

AllyCat

Senior Member
Hi,

IMHO it also depends on how "easy" it is to measure the current, its dynamic range and the timescale. With a ~30 volt battery, it might be necessary to connect a (current sensing) resistor in the "earth" side of the supply. But for an electric bike (or similar) the load current range won't be too large and should swamp the quiescent (PICaxe) current / battery leakage, and the battery will probably be recharged within a few days anyway. It might be a very different situation with, for example, a PICaxe + HC12 (RF transceiver) data logger, trying to maintain power over an annual cycle from a small solar panel.

I have created a circuit to measure the Voltage of a Li-ion battery with a range 24-29V, however its not very accurate.
Lithium cells do have a very low temperature coefficient and low internal resistance so (at least for the latter example above) a voltage measurement may not be totally out of the question. But you need to be able to resolve to literally a few millivolts per cell (and not measure when a significant current is flowing in the battery); I've posted several code snippetts which can do this for the PICaxe supply rail at "zero cost".

It might be possible to adapt the method for higher voltages (probably using the DAC/ADC "Reference" input pin), but then would need to devise a precision (analogue) switch to disconnect the voltage divider (to avoid draining the battery) except whan actually making a voltage measurement.

Cheers, Alan.
 

JPU

Senior Member
Hi Guys

Thanks for taking an interest and again helping in this thread. It appears that my original voltage meter using a voltage divider, ADC input and software wasn't that bad after all then? At present it splits the capacity into 4 parts and I have "low", "medium", "high" and "full". Which is OK but could be better.

After reading some of the posts above I ordered my very own ACS712 CHIP and received it today! I arrived home from work to find it waiting and such was my excitement, I have already hooked it up to my circuit and I have only just now come back in to the house from my "shed". The wife has gone to bed and so I might have to tread carefully tomorrow!

Anyway, When connected to a multi-meter I can see that the output signal increases from 2.5V (which I believe is zero current flow) to 2.8V. I only had a light bulb on the circuit drawing about 1.4Amps at 24V. So tomorrow I am going to go back to it and Ill be adding a 08M2, utilising the ADC input pin and Ill be getting stuck into the maths (or I might be lazy and pinch some code from above!). Lets see if I can build my own coulomb gauge.

The "load" connected to my circuit is a brushless motor and so I am not sure how accurate this might end up being, but it should be interesting and beats watching TV this weekend.

Thanks for your help.
 

Jeremy Harris

Senior Member
I've been riding electric bikes with either the old 2010 Picaxe 08M based gauge I linked to above (still working and fitted to a folding electric bike) or the later version (also linked to above) that uses a Hall current sensor, rather than the current measurement shunt built-in to all ebike motor controllers. Both have worked fine. The gauge or bargraph tells me the remaining battery capacity in Ah, so it doesn't matter what the load is, or how the bike is used, the gauge always indicates how much is left in the battery, just like a car fuel gauge. In practice you get to be pretty good at knowing how far, and over what terrain, a given remaining battery capacity is, in terms of range, exactly as you do with a car fuel gauge.

I've never felt the need to do anything more complex in terms of adding a "range remaining" feature, as it's not needed for an application like this. My electric car is a good example of how poor range estimation is, as it always gives a very pessimistic remaining range, so much so that I have got used to just ignoring that display and using the battery charge indicator as a far more reliable way of estimating how much range the car has left, as for local journeys I have knowledge the car doesn't have, like the terrain and average speeds along the route ahead.
 

stan74

Senior Member
So a 10AH battery, measure current over time seems ok for an ideal battery but I don't see it being so predictable in reality hence erring on the pessimistic side to be safe.
My batteries are 4 years old and "seem" the same as new. I've never fully depleted them, I just watch how much the voltage gauge drops under load and how long it takes to recover. I can do 6 miles from fully charged and the battery charger doesn't start. 6 miles next day and the gauge has dropped but plenty of power. 6 miles next day and noticing gauge bottoms and recovery time worsens so I charge it. Not very scientific. The voltage of each bar can be selected and I set mine higher than the defaults.
 

Jeremy Harris

Senior Member
There's virtually no voltage drop under load on my batteries, they are rated for a 50C discharge, which would be 500A, and the maximum I have set in the controller is 40A. The Peurkert factor for decent lithium cells is very close to unity, unlike lead acid or nickel chemistries. The same goes for the 300+ V battery pack in my car, even under a discharge of a couple of hundred amps the voltage barely dips.
 

stan74

Senior Member
I can't adjust the current on the controller on the bewo but I put a thin film of solder on the current limiter shunt wire on a tonaro controller as the motor is said to be 350W but sold as 250. There's a 35A in line fuse in the battery lead.
 

PhilHornby

Senior Member
There's virtually no voltage drop under load on my batteries, they are rated for a 50C discharge, which would be 500A, and the maximum I have set in the controller is 40A.
I recently bought a Wisper 905 Torque. I love everything about the bike, apart from its 'Dashboard'. It has a bar graph 'capacity' meter - but it looks for all the world, like it's measuring voltage: it drops when you climb hills and recovers somewhat afterwards. I'd trust it as far as I could throw it...

My other half's Gepida Reptila 900 uses the Bosch Active Line/Intuvia which does have a 'range remaining' feature. Unfortunately, there's only one way to find out how accurate it is...
 

premelec

Senior Member
"My other half's Gepida Reptila 900 uses the Bosch Active Line/Intuvia which does have a
'range remaining' feature. Unfortunately, there's only one way to find out how accurate it is."

Just take a smaller extra battery pack... ;-0
 

Jeremy Harris

Senior Member
One of the issues with commercially available ebikes is that it seems that the batteries are often where corners are cut. My ebikes are both home made, and both use packs made up from these lithium batteries: https://hobbyking.com/en_us/batteries/turnigy-nano-tech.html . They are massively over-rated, in terms of max discharge, so the voltage drop under load on something like an ebike is negligible. The down side to building a pack using these cells is that you have to fit a decent battery management system, to prevent over-charge or over discharge. Not hard now, as there are affordable solutions readily available for most common pack configurations.
 

PhilHornby

Senior Member
Just take a smaller extra battery pack... ;-0
That got me thinking...

Something that my (many) motorcycles had, was a "Reserve" setting on the fuel tap - so when the engine spluttered, you flicked the switch and had a known amount of juice left. I don't know how the battery packs are organised (an anti-tamper screw stands in my way!) ... but I wonder if a convenient portion of the cells could switched out of the circuit, until needed? - they then become the smaller extra battery pack :) I assume you'd have to switch between the two banks, rather than connecting them back in parallel with the now dead cells. That sort of implies they would have to be charged separately as well?

I suppose you could do this 'virtually', but that means somehow knowing the capacity of the battery when fully charged - something which is going to change as time goes by.

One of the issues with commercially available ebikes is that it seems that the batteries are often where corners are cut.
I'm sure I'll end up building my own replacement battery pack, when the time comes. Wispa/Amp bike make a big deal about using "Samsung" cells, if you buy their higher-rated battery pack. To my mind, that just casts aspersions on their standard pack, which I have :(
 

stan74

Senior Member
I tried 2 36V packs in parallel each through a 45A shottky diode but the extra weight meant you used more power. The power meters on drills are pretty...useless.
 
Top