DIY USB 1S LiPo charger; how to get an MCU to set the current ? - Page 1
Forum section: electronics / projects

author: John_Edward
author_rank: Contributor
timestamp: October 23, 2015, 10:24:05 pm
content: Is there a way to control the current on a LiPo charging controller chip like the MCP7813 or TP4056 with an MCU, or would I need to use something else entirely ?I'm looking for a way to charge 1S LiPos with a current I can set with an MCU (~2A max, most likely), so I could build a combined portable version of a regular 4-Button Hobby Charger, and a simpleUSB 5 in 1 charger.With most of the charging chips you set the current by adding a resistor (0 to 10k seems to be quite common) between a programming pin and VCC /GND, so it's either using the current or the voltage at this pin to set the charging current. The best thing I've come up with was an LDR with an LED, but...I did find a few SPI/IIC controllable chips, but they seemed to be really damn expensive...I've done one 3-port switch&resistor type charger before, but I'd like something little more fancier, preferably with an OLED display, a few buttons and a neat UI. Everything else I can do, but the actual charging part is a mystery.The biggest reason for this need is that those USB multichargers are horribly inaccurate and crap, and most of the time the end voltage is randomly between 4.10 to 4.25 volts. Even so, just plugging a cell in to a free port after a flight and letting it do its thing instead of fiddling with a real charger is just too convenient... Also, the fact that the 1S cells I use vary from 100mAh to 750mAh, and the USB charger is locked to 500mA which is really bad for the small lipos, and too slow for the bigger ones.

author: exmadscientist
author_rank: Frequent Contributor
timestamp: October 24, 2015, 06:34:39 pm
content: A digital potentiometer should do the job handily. The AD5175 is one option, but there are lots out there. They may be more expensive than you're looking for, though.

author: KL27x
author_rank: Super Contributor
timestamp: October 24, 2015, 06:47:51 pm
content: You can use a BJT transistor as a variable resistor. Put an RC on the base and PWM from the uC pin. The duty cycle will correlate to base biasing current. You will have to do some testing to see what duty cycle gives you what current. And each device you make may need to be calibrated, unless you are using the same lot of transistors. I suppose you could do same with a FET and a slightly different RC circuitry to vary the voltage on the gate.Another way you can do it is to use a bunch of signal FETS to select the programming resistor. You can either connect them all to the charger IC programming pin in parallel, each FET with a different resistor on it, and use the microcontroller to turn on the FET (or combinations of FETs) to get the different predetermined charging values. You could also put resistors in series, each representing the next step up, so that the resistors are additive. There would be a FET between each resistor in the chain and the rail, and the micro will determine which one (and one, only) FET is switched. The multiple FET method has the advantage of not needing to be calibrated. Just need to make the calculations. But you don't get infinite/arbitrary adjustment and need to use more pins (or an additional serial to whatnot chip of some sort).If your micro input pins can handle same rails as the charger (or at least w/e max voltage is present at the programming pin node*), you can skip the FETs and connect the resistors to the micro pins, directly, by using high impedance state as off, using the IO pins as essentially open drain outputs.*The Vsupply of a 1S Li ion charger might be 5+V, but the voltage of the programming pin might be only 2.5ish V. And in my thinking, the programming pin resistor with usually be grounded on the other end. So switching micro pins between digital low and high impedance would work in this case.

author: jt
author_rank: Regular Contributor
timestamp: October 24, 2015, 10:10:00 pm
content: Depending on the regulator circuit a digital potentiometer may present too much capacitance and screw up the feedback network compensation causing the regulator to go unstable - has happened to me in the past in an attempt for a variable output voltage stepper. Also the digital potentiometers generally have poor tolerances which you may or may not care about in this application.I've used the resistor/FET network that KL27x suggested in a few different applications and found it to be a good solution if you are okay with a few discrete steps. You still should still pay attention to the complex impedances affecting loop stability in your FET selection and PCB layout.

author: John_Edward
author_rank: Contributor
timestamp: October 25, 2015, 04:56:52 am
content: Quite a few good ideas, thanks!As for accuracy etc, most charging chips have a current accuracy of around 10% in the first place so it isn't that important.I could always add a tiny trimmer or try to calibrate it in software....For the resistance range, with LTC1733, Max charge is 1.5A, 1kOhm, and 100mA requires 15kOhm. So while a 100mA step between 1.5A and 1.4A is just a 71ohm difference, between 200mA and 100mA its 7500ohms.I was thinking 100mA steps or so, so while resistor network would be okay for a single channel, it would get really ugly pretty fast with multiples.The BJT transistor solution would be the cheapest, but also require constant interaction and monitoring from the MCU... Not impossible, but a glitch could potentially set the resistance too low which would max the charging current... very dangerous with the smaller LiPos...Digipot seems like the safest bet, and they don't seem to be that expensive either...The basic 10k 8bit 20% would be too inaccurate (~40ohms/step + wiper resistance) on the highest charging rates though...Then again, maybe it could be calibrated somehow ?Well, gotta think about this and research these some more.And the budget right now is rather high, as there really are no commercial options to buy and the gentler charge on the LiPos would pay itself eventually.I've heard of people getting less than 10 charges with the USB craps before they got puffed lipos.If a single charging channel would cost $20, then I'll just make three of them instead of six.

author: jt
author_rank: Regular Contributor
timestamp: October 25, 2015, 07:25:52 am
content: QuoteFrom what I've seen the tolerance is poor, but the stability over time and temp is pretty good. So you should be able to calibrate this out. Its not clear to me if this is for a one-up personal project or if it is something you would be building in volume. If it is a one-off then it shouldn't be hard to build a calibration table by hand; if in volume you might be able to build a test fixture to automate the process. Alternatively, if your MCU is also monitoring charge current, you could forgo any kind of calibration and instead use a closed-loop system.

author: John_Edward
author_rank: Contributor
timestamp: October 25, 2015, 04:27:57 pm
content: @jt, completely one-off personal project.I got this while thinking of how to add the digipot to the circuit while trying to add some safety and functionality:The MCU Enable pin ont the LTC1733 is kinda special, as not only will it shut the chip down, V RProg is a linear voltage proportional to the charge current between 0 to 1.5V.Not exactly sure how I would interface it though so I could use both functions. Would just a series resistor and changing the pin from output high to input and back work ?Would most likely make sense add an external current sense resistor just in case though.With this kind of circuit I think the BJT transistor solution could work as well, as I would have two current measurements, a way to shut the chip down, and a way to limit the charge to around 150mA even if the variable resistor part went short circuit. The LTC1733 also has a few status pins I could connect as well, and an NTC thermistor support too.You can never be too careful when playing with unprotected LiPo cellsI would run out of pins very fast, but I could always get shift registers or multiplex the non-essential stuff.