Li-ion battery capacity measurer - Page 1
Forum section: electronics / beginners

author: metrologist
author_rank: Super Contributor
timestamp: August 28, 2022, 04:55:50 pm
content: Hey All,I made an 18650 capacity measuring system with an Arduino, IRFP460, and a 1 ohm power resistor. I do not get accurate measurements due to Arduino and I suspect because the mosfet is not fully turning on, so I had to fudge some of the parameters for a "best" fit. I mostly just want to match capacity of cells so I can build a pack for my e-bike.Does this seem safe to use?Code:// Very simple Arduino Lithium-ion battery capacity tester// from electronicsblog.net#define LED 13#define resistor 1.9float capacity = 0, value, voltage, current, time = 0.0;boolean x = true;ISR(TIMER1_OVF_vect) {TCNT1 = 0x0BDC;if (x == true) measure();}void setup() {pinMode(LED, OUTPUT);TIMSK1 = 0x01; // enabled global and timer overflow interrupt;TCCR1A = 0x00; // normal operation page 148 (mode0);TCNT1 = 0x0BDC; // set initial value to remove time error (16bit counter register)TCCR1B = 0x04; // start timer/ set clockSerial.begin(9600);Serial.println("battery-monitor.01");Serial.println("simple li-ion capacity test");Serial.println("A0 voltage sense");Serial.println("D13 mosfet gate");}void loop () {digitalWrite(LED, x);}void measure (void) {value = analogRead(0);voltage = 4.98 * value / 1024;current = voltage / resistor;capacity = capacity + current / 3600;if (voltage < 3.0) x = false;if (voltage >= 3.5) x = true;time++;Serial.print("Voltage= ");Serial.print(voltage);Serial.print("V Current= ");Serial.print(current);Serial.print("A Capacity= ");Serial.print(capacity);Serial.print("Ah ");Serial.print("Discharging time= ");Serial.print(time);Serial.print("s ");Serial.print("\n");}

author: ledtester
author_rank: Super Contributor
timestamp: August 28, 2022, 05:36:59 pm
content: As long as your cutoff mechanism works it should be fine.I would probably write the code so that you have to start a discharge with a button press and then when the voltage drops below the cutoff threshold the MOSFET is turned off and stays off until you start another discharge with another button press.For a similar cheap commercial product, look up the the "ZB2L3" battery capacity tester available on aliexpress/ebay -- it basically does the same thing -- discharge a battery through a fixed resistor.

author: Benta
author_rank: Super Contributor
timestamp: August 28, 2022, 07:33:23 pm
content: Looking at your photo, I'd say that the problem lies in your electronics. But without a schematic it's impossible to say.

author: metrologist
author_rank: Super Contributor
timestamp: August 29, 2022, 06:17:17 am
content: I think this is it, the schematic. Cutoff happens at 3V and I think will not start a new discharge until arduino is rebooted.

author: ledtester
author_rank: Super Contributor
timestamp: August 29, 2022, 10:47:32 am
content: Quote from: metrologist on August 29, 2022, 06:17:17 amAh, I see -- this line in the measure routine will not have any effect:Code:if (voltage >= 3.5) x = true;because measure() only gets called when x is true.Standard practice is to add a pull-down resistor on the gate of a MOSFET to prevent it from accidentally turning on when the MCU GPIO pin is not asserting a logic 0 or 1 -- such as when it is not powered or the firmware hasn't yet set the pin to a digital output. It's also standard to add a resistor (like 100R) between the GPIO pin and the MOSFET get to prevent excess current draw from the pin when it turns the gate on. See, for example, this page:https://www.build-electronic-circuits.com/mosfet-gate-resistor/or this video:MOSFET Why use a Gate and a Pull-Down Resistor? -- Dustin Wattshttps://youtu.be/Wd6NzCY3NgIWhat MOSFET are you using?

author: metrologist
author_rank: Super Contributor
timestamp: August 29, 2022, 02:23:47 pm
content: When I measure voltage across the 1 ohm resistor, I get ~2.4V at most, so I think that is 6W.IRFP460 is the mosfet.Thanks for the tips on resistors. I was originally using the if loops in the function without a test in the ISR but the voltage would always come up to high and it would just toggle on/off at the bottom of the discharge. Even if I set the voltage high enough, it would keep counting and adding capacity as it's just looking at voltage of the cell. I can clean up that erroneous line.

author: not1xor1
author_rank: Frequent Contributor
timestamp: August 29, 2022, 05:59:40 pm
content: Quote from: metrologist on August 29, 2022, 02:23:47 pmWrong choice of mosfet. The threshold voltage is too high so it is not fully ON. Besides that even if it were fully on still its conduction resistance would be too high. A logic level mosfet would work much better.For instance an IP*060N03L at 3V of Vgs would be less than 20mΩ.

author: metrologist
author_rank: Super Contributor
timestamp: August 29, 2022, 06:43:41 pm
content: Yes it is. I wasn't sure it would turn on enough. I'll see what the resistors do to the behavior. It's just something I had laying there on the bench. A couple amps is the right current for what I'm doing. I'd have to change the resistor with the right mosfetWell, I did buy a 5 pack of them.

author: strawberry
author_rank: Super Contributor
timestamp: August 29, 2022, 08:14:07 pm
content: 4,2A...3,0A will give optimistic capacityat high temperature that resistor might be 1% off

author: radiolistener
author_rank: Super Contributor
timestamp: August 29, 2022, 10:30:17 pm
content: I think 1 Ω load is a bad choice for 18650 element.The issue here is that capacity of the battery depends on discharge current. For low discharge current the capacity will be higher, for high discharge current the capacity will be lower.As I know, the standard of capacity for the battery is specified for 1C current. And if you use different discharge current, you will get different capacity which cannot be compared with specification, because it is measured not for 1C current.Usual 18650 capacity is C=2600 mAh.So, the required discharge current for measurement isI = 1 * 2600 = 2600 mASince 18650 has 4.2 V, the required load resistance isR = 4.2 / 2.600 = 1.62 ΩWhen you use 1 Ω resistor, it leads to discharge current I = 4.2 / 1 = 4.2 Amps. So the battery capacity needs to be C = 1 * 4200 = 4200 mAh.4200 mA is too high current for 2600 mAh battery capacity measurment, so your measurement will show you lower capacity than real.In your arduino code there is hardcoded 1.9 Ω it leads to the current 4.2 / 1.9 = 2210 mA, which is too smal for battery with 2600 mAh capacity, so your measurement will show you higher capacity than real.Another issue with resistor load is that voltage will drop down while discharge, so it leads to slightly current change over discharge time and as result - a little different measured capacity.in order to get proper capacity measurement at constant 1C current, it's better to use constant current load circuit instead of simple resistor. It will give you proper capacity measurement.For example, you can try this DIY kit of electronic load constant current from aliexpress for proper battery capacity measurement:https://www.aliexpress.com/item/32870007246.htmlIt allows to setup constant current and stablilize it for entire discharge process.So, you can setup 1C current and get proper capacity measurement with it.Update:sorry, just googled, I was wrong. The specified capacity is rated for 1C discharge current, not 0.1C. So I fixed calculations above.

author: cellularmitosis
author_rank: Unknown
timestamp: August 30, 2022, 06:00:07 am
content: OP, I don’t understand how your setup achieves constant current draw? How are you calculating capacity?Here was my take on this projecthttps://www.eevblog.com/forum/projects/jellybean-li-ion-capacity-tester/msg4312528/#msg4312528

author: ledtester
author_rank: Super Contributor
timestamp: August 30, 2022, 01:31:34 pm
content: Quote from: cellularmitosis on August 30, 2022, 06:00:07 amPermit me to answer this...This type of electronic load does not create a constant current draw. Since the load is a simple resistor (or resistor plus not fully turned on MOSFET) the draw depends on the battery voltage. But you're measuring the current at each timestep so the capacity is simply the sum of these measurements times the length of the timestep.The "ZB2L3" capacity tester also uses this approach. In this case the OP has determined experimentally that the resistance of the power resistor and the not fully turned on MOSFET is about 1.9 ohms. The ZB2L3 has a calibration mode where you apply a constant current source and that would be another way to determine the effective resistance of the power resistor + MOSFET combo -- for instance by using a 5V or less constant current source.High-end electronic loads have a "constant resistance" mode which does the same thing but the resistor is implemented electronically. Here's a good white paper which goes over all of the different modes and how they are implemented:https://www.keysight.com/us/en/assets/7018-06481/white-papers/5992-3625.pdf

author: cellularmitosis
author_rank: Unknown
timestamp: August 30, 2022, 02:55:06 pm
content: Ah thanks!

author: metrologist
author_rank: Super Contributor
timestamp: August 30, 2022, 03:35:36 pm
content: I am not really interested in an absolute accurate accounting of capacity, but just to match the cells to make 4P10S packs. This is for a 500W e-bike application, which would draw ~3.5A from each parallel cell (13.9A from the pack). The commercial packs I am sourcing are 3Px3S and are rated 3.0V min and 10A max operating conditions. I think the e-bike runs an equivalent of a resistive load so I wanted to match the use case, hence the 1Ω resistor. Since the resistors are 10W I was planning on a 2P2S configuration.Using the salvaged stuff I had laying around, the original plan did not work but I figured the way I show it would be good enough. Most cells are resulting in 2.41Ah capacity, which seems reasonable to consider re-pourposing.The resistor value is entered based on periodic current measurements during the discharge cycle. Measured current runs from ~ 2.2A to 1.5A, measured between a battery terminal using a trusty $12 Chinese DMM. That matches the 1.9Ω constant as noted, also the Arduino is not properly measuring the voltage, which starts high at ~4.5V and ends at 3.0V. The termination voltage is more important to me and that is where I set the voltage calculation, and the e-bike does not discharge below 3V/cell either, it actually stops providing useful power closer to 32V - power drop-off is a steady decline.I had also considered making this measurer constant current using PWM and half the resistance, but that wasn't what I was going for. This code would even allow me to match current curves.Thanks for the tips and the white paper seems to suggest a constant power load for capacity measurement.

author: strawberry
author_rank: Super Contributor
timestamp: August 30, 2022, 04:15:49 pm
content: it is sorta discharge speed tester not capacityconstant resistance load (voltage go down - current down) = motor, resistor, incandescent light bulbconstant power load (voltage go down - current up) = cell phone, laptop, DC-DC powersupplycells are sold by constant current capacity I guess