# Can I use a current control buck converter to charge a battery?

As shown below, could I use a microcontroller to charge the Li-ion battery? I'm unsure if I'll run into issues with the voltages on the ADC. I've done this exact setup before with a generic load, I'm unfamiliar with batteries though.

simulate this circuit – Schematic created using CircuitLab

• You should first dig into the requirements of Li-ion charging: required accuracy, charge modes (current controlled, voltage controlled), protection. Then see if your PWM driver and ADC can handle that. Aside from that, if not embedded in the cell pack, I would highly recommend a hardware protection circuit. – gommer Jul 13 at 20:37
• I think you forgot to connect the cathode of the freewheel diode = negative battery terminal to the negative terminal of the 12 V source... and to relocate the (current sense?) resistor. This way no battery will be charged. – Huisman Jul 13 at 20:41
• @Huisman, you're right about the circuit, even in my notes I drew it correctly, I fixed the post. – Connor Redding Jul 13 at 21:28
• can't see that fix, sadly! – Marcus Müller Jul 13 at 21:28
• @Marcus Müller This should? be it !schematic The cell's negative terminal now has a link to ground and is at the ADC – Connor Redding Jul 13 at 21:31

Generally, yes, you can build a switch-mode power supply using a microcontroller.

It'll certainly be more work than just buying a dedicated controller IC, though, and your digital control scheme must take software reliability risks into account.

Here, these risks are increased: if your MCU software fails for some reason, or the MCU doesn't properly power on, there's a realistic chance the MOSFET will stay "on", and that'll quickly render the inductor effectively a short, delivering as much current as your 12V can source into the battery. Lithium batteries, under these circumstances, will heat up, produce gas, bulge and tend to explode. No fun. Considering that, I'd very much recommend using dedicated third-party LiIon charge controllers that integrate all the switch driving (often even the switching mosfet), sensing and overtemperature and -current protection you need.

That being said:

No, this is not an appropriate LiIon charger circuit; Lithium batteries want to be charged by a controlled current, not using a controlled voltage (the voltage is usually used to check the charging state). Your ADC just checks the voltage across the battery, not the current flowing into it. Thus, this can't be a safe charger.

Again, a dedicated LiIon charger IC has an "understanding" of the state the Lithium cell is in. It will charge at a limitable rate, and it will slow down and stop when the cell has reached a certain state. Such chips are typically not very expensive.

• I realized that I misplaced the cell, the ADC should be reading between it and the resistor to get the voltage drop across the resistor ergo getting the current through both the resistor and battery. I can use a purpose built ic for the bucking, however LiPo charging ics are a bit out of my budget. The battery I'm using already has overcharge/overdischarge protection on board with the S8261 chip, so I'm more focused on the constant current for battery charging. – Connor Redding Jul 13 at 21:25

For Li-ion batteries you need to guarantee three things:

• don’t discharge below 2.8 ~ 3.0V
• don’t charge above 4.2V
• don’t exceed the battery 1C charge rate

Your proposed solution really doesn’t address these items. It could damage the battery, or worse, cause the cell to catch fire.

Please consider a purpose-made controller IC that’s designed for managing Li-ion safely.

A pretty good write-up here: https://www.digikey.com/en/articles/techzone/2016/sep/a-designer-guide-fast-lithium-ion-battery-charging

A good resource here: https://batteryuniversity.com/learn/article/charging_lithium_ion_batteries

• So the battery I'm using has an S8261 chip on board, preventing the overcharge/overdischarge problem, what I'm focusing on here more is the constant current for battery charging, where I need to limit it to ~200 mA. – Connor Redding Jul 13 at 21:27
• Ok. That said, have a look at the references. It’s not just about limiting current - this will vary depending on the battery’s state of charge. – hacktastical Jul 13 at 21:38

Assuming this is a single cell Li-Ion due to the buck converter circuit topology so you'd stop charging at a voltage within the ADC range (higher voltage would need accurate resistor divider).

Charging Li-Ion batteries is a two stage process and you can find lots of info on the charging particulars online. Generally the first stage is Constant Current (CC) until the measured battery cell voltage hits the desired "fully charged voltage" (depends on your exact battery chemistry) and then it switches over to Constant Voltage (CV) mode. Therefore the current vs time profile is a flat line at your desired charging current (manufacture should specify safe charge rate as a fraction of the battery capacity) and then the charging current will drop off and asymptotically approach zero once you switch over to CV charging.

From Battery University charging lithium battery post:

So to answer your question, your circuit will work for the CV portion but you don't have a way to check what the charging current is into your battery. Unfortunately there's no accurate way to calculate this from the circuit you already have because even if we know the source voltage (Vs) and the voltage drop over the FET (Vfet) we could calculate the voltage over the inductor using your ADC input, but the integral to calculate current would quickly diverge and you'd lose control of your CC charging.

$$$$I = \frac{1}{L} \int_0^T V \it{dt} + I_0$$$$

I'd recommend using a shunt resistor directly after your inductor with current sensor amplifier (should be details elsewhere in this forum) to increase the measured voltage to something you can more accurately detect with a separate ADC pin. It'll be a variation of this sort of setup.

simulate this circuit – Schematic created using CircuitLab

Be aware that you may want an external entity to verify the battery never goes above it's max voltage in case the FET fails in conduction mode or the microcontroller freezes.