Show by Label

Sunday, March 24, 2019

Pretty universal battery profiler

Recently, I had a number of Li-Ion and LiPo cells fail on me, and I also suspected a very poor capacity from many of my NiMh cells. Using a method that I concocted earlier with a Raspberry Pi and an ADC was too much trouble and it did not really give me what I want. That method is described in one of my other posts.

The units you can buy give you a mAh number, but don't give you a graph, which is what I really wanted.
I also did not want to buy something that I can build, so I started a Google tour to find a design to my liking. That took a while because most designs that I found were too rudimentary. My philosophy is that when you decide to build something, you might as well do it right.

The design that I eventually found that was even beyond my expectations can be found here :

This is a very complete instrument that comes with a very nice PC program to show the discharging graphs, great for documentation, and you can also drive the testing tool with it. I have never written an application that runs on a Windows PC, so I was delighted with this solution. I normally save data in a CSV format and use Excel to create graphs. This program is so much better!

The only initial downside was the hardware in terms of size. I don't have enough room, and I only build instruments in cases when I use them a lot.

Hardware changes and improvements
Very quickly though, I saw some simple improvements to the hardware that John Lowen, the original designer, used. I decided to use an Arduino Nano board as the processor. The good news is that it already comes with a serial to USB interface, and the power for the whole kit can be supplied from this USB link as well. I also wanted to reduce the foot print of the board I was going to use, so instead of a traditional 20x2 LCD, I opted for an inexpensive Nokia 5110 LCD display, that allowed me to display at least 5 lines with 14 characters each with a very small footprint.

There is also another user that I follow, that found this information and build one too. Greg Christanson makes beautiful PCB layouts, I've used two of them myself for other projects, so if you're interested in his version, have a look here:

I also happened to have two breakout boards with the INA219 from Adafruit already in my stash.
I ordered these a few years ago when I had plans to design my own power supply. (which I did, see an other post) The INA219 is a high-side bi-directional DC current sensor that can also measure the voltage. The chip itself is designed for battery operated devices like PC's, tablets and phones, and helps to figure out how much juice is still available from the cells.

Building a prototype
As is typical for me, I started out with a breadboard version of some of the hardware, and learn from it. After I was satisfied, I started with a protoboard that allowed me to reduce some noise and resistance of the current loop. The INA219 has very jittery readings of especially the current, so I wanted to make the signal path as clean as possible before I did some more drastic work.

Here is a photo of the setup where I did most of the work. In the background is the prototype, beyond that is a simple Li-Ion charger.

One of the reasons for building the prototype was to see how low in voltage the circuit would go. It was designed specifically for Li-Ion cells with a cut-off voltage of about 3.0V and a fully charged voltage of 4.2V. I wanted to go as high as 14V to be able to measure 12V lead batteries, and as low as 0.8V for 1.2V cells like Ni-Mh. That turned out to be no problem at all.

In the partially built version above, I still used a 20x2 LCD screen with an I2C interface, because my Nokia 5110 displays took a long time to arrive from you know where.

The finished hardware
Here is a picture of the finished product running a stress test at a 1Amp discharge current.

Here is a simple circuit diagram that shows what I did in some detail. The Ax and Dx names refer to the Arduino Nano pins.

Note that there is an error in the diagram above: Pin 4 of the Nokia display needs to connect to D4 of the Arduino, not D2.

It was not easy to create the right setting for the back-light of the display to get the picture right. In real life it's much better. The reason why some numbers are difficult to see is that they quickly change and I did not want to speed-up the camera too much due to my room lighting.

The reason I say stress testing is that the maximum current that the heat-sink allows is about 1Amp. With that current, the temperature of the heatsink gets around 60 degrees Celsius. A maximum decharge current of 1Amp is enough for my intended applications, but if you go higher, get a larger heat-sink or use a fan.

Let me explain what you see on the LCD display.
First line is the title and the version number.
Second line is the cell voltage on the left and the dis-charge current on the right.
Third line is the 13-bit PWM number on the left and the "PID" error number on the right.
Fourth line shows the mAh number so far on the left and the running time on the right.
The fifth line is blank and used for error messages and to signal the end of test.

To the right of the display is a beeper, en below it is a trimmer to adjust the back-light level of the LCD.
Furthermore to the right is a fuse and below it the MOSFET on a heat sink.
Next to that are two cell holders, one for normal AA and 14500 types, and next to it a 18650 version.
Below these holders are a LiPo type socket and in blue a 2-wire terminal to connect everything else.
Below the display is the Arduino Nano and to the right the INA219 breakout board.
Below the Nano is a 4-pin connector for the I2C 20x2 LCD and a 100 uF cap for the 5V supply decoupling.
Above the Nano is the 1K2 series resistor to the Gate of the MOSFET, and the 10uF filter to ground.
Below the MOSFET is a 100K resistor that ties the Gate to ground, for safety.

The Nokia LCD display uses a 5-wire SPI and 3V3 power connection to the Nano.
The INA219 is fed by 5V coming from the Nano/USB port, and connects to the Nano with a 2-wire I2C connection.
The MOSFET I use is the same type as John uses, an IRL2203N Logic Level MOSFET, but I tried a few others like the BUK956R1 and they work just as well, as long as they are Logic Level.

Changing the MOSFET mode of operation
Apart from using another display and the Nano, the only major deviation I made to John's circuit is to increase the size of the filter capacitor to the Gate of the MOSFET, and add a 100K safety clamp to ground. John used a 100nF filter, and used PWM to drive the Gate, in an attempt to switch the MOSFET on and off. This is the preferred method to regulate power (and save energy and heat), but I found that the INA219 does not really like that. By increasing the capacitor value to 10uF, you create a crude ADC and the resulting DC voltage will drive the MOSFET into it's linear mode, and is than really acting as a variable resistor.

Improving the PC side of things
Together with John Lowen, we worked on some of the changes I suggested for the original PC program, to make it accept other cell technologies as well and turn it into a universal cell tester. He was very helpful and responsive and I think the program is now a lot better and supports all my particular wishes. One of the nice touches he added was a minimum cut-off voltage based on the various cell technologies. While te test is running the graph also shows the Min and Max values for that particular technology.

This post is based on John's Batterytester software. He and I worked together to create the 1.2 version. In the mean-time, he has made some changes to the code and is now at version 2.2c. My published code on the Github is compatible, but I may miss an update that John does. Send me a PM if that is the case again.

Testing some cells
Below is an example of a test report. This is a poor cell that I rejected. Although it still performs pretty well, it has less than a third of the specified capacity left. If it ever had that. I now do incoming inspections on all arriving cells.

Because I needed extra 18650 cells, I ordered two UltraFire 4.200mAh 3.7V cells from a distributor. When they arrived, there was a nice note in the package saying that the UltraFire cells were not performing to their expectations, so they send me two German made M2 TEC 8.800mAh cells, specified to deliver 11.8Wh. This translates to a discharge current of over 3Amps. I charged and tested them 5x to obtain their maximum capacity. I used the maximum 1Amp with the tester, and lo and behold, even these German manufactured cells did not get above 1.200mAh. They weighted 35 grams, seems a little low to me. This is the reason I wanted this tester in the first place! And yes, I did send the distributor the test reports. I have never heard back from him...

Note the jittery lines for the current and voltage after about 5 minutes into the test. I suspect this is due to the chemical reaction of the cell during the discharge. Some cells display a very nice line, and some very jittery. I don't think that this effect is a good sign for the quality of the cell. When the voltage is jittery, the current will be jittery too, because the program tries to keep the current constant.

Here is another test,this time of a 14500 Lithium cell, where I suspected the capacity very much.

The cell weight is a good give away for the vastly overrated capacities that are advertised, so this is a nice touch from John to add it into the documentation. His intention for this feature is to slap an unscrupulous or oblivious vendor with this proof to get replacements or his money back.

Are more expensive cells better than considerably less expensive cells?
There is only one way to find out.
Below is a test made with the latest version of the tester software using an inexpensive IKEA LADDA AAA HR03 1.2V NI-MH cell with a capacity of 900 mAh :

Inexpensive does not have to mean poor performance is what you can see here.

Is a much more expensive Panasonic BK-4HCCA 1.2V Eneloop AAA Ni-Mh 900mAh is any better?

Trying to improve on the original Arduino code
While testing, playing and learning about the Arduino code, I decided to try a real PID routine to see if I could improve the current loop. It was very jittery and I saw some room for improvement. I experimented for a few days with different methods while learning the subject, because I'm pretty much a noob with PID methods. In the end, I got one working pretty good, after making considerable changes to the original code, but it did not improve much. John's method seems to be good enough.  The root cause I think is the INA219 measured current "noise" in combination with the fluctuating voltage level of the cell. It almost looks like the chemicals inside the cell are "boiling", creating tiny effects on the output voltage. That combined with the jittery current readings from the INA219 is in my opinion the reason.

I also experimented with a version of my software low frequency filter program (IIR) that I used in my milli-Volt DMM code (see my post about that) to filter and tame the 24-bit ADC output. It worked in this application as well, but had some side-effects without improving much so it went in the bit-bucket as well. I think we need to leave "good enough" alone, and be satisfied with it.

Changing the PWM counter resolution
The most significant improvement I got however was when I realized that the 10-bit PWM counter that John used was too course for the current loop regulation. A single digit change caused too much of an effect. If you realize that the Gate voltage to turn on the MOSFET and regulate it as a resistor is all done within a very small Voltage range (VGS).  Typically within 100-200mV. A 10-bit counter with a 5V maximum output has a bit level resolution of 5V/1024 bits=4.8mV. My observations were that this is not fine enough. John maybe wasn't aware of the trick you can use to get higher resolution counters. I experimented with 12, 13 and 14-bits and settled on 13, giving me a bit resolution of 5V/8192 = 620 microVolt.

Most of the other software changes I made were to create a nice way to display the results on the Nokia display by making numbers right justified.

Finally, I added some code changes to better terminate the loop when an error occurs, or when the test finishes normally.

I also have no use for running the tester all by itself, so there is no method to try to input the test parameters other than by using the PC. All that code is gone. I also don't see a need to have an LED signalling the end of test, that's what the display and beeper are for, so that went out as well.

There are a number of added comments and additional documentation in the code, so my changes should be self-explanatory.

The code can be found on my Github site here :


23-Oct-22: I found that John updated the PC software now to V2.2c. It still worked with my earlier version V3.03 but to stay compatible, I have updated my code to V3.04 which is on the Github.

This tester is very easy to build, and the project was already very well documented. If you consider building a very good battery tester or profiler, you now have two options to choose from. I can highly recommend either one.


If you like what you see, please support me by buying me a coffee: