If one is to make a battery charger, lets say a Li-Ion battery charger (using a micro-controller with buck converter), is it necessary to do some kind of control implementation inside the micro-controller for e.g P , PI , PID ?

Like generally we would be measuring the voltage and current being fed to the battery, and try to keep the current constant (by adjusting PWM duty cycle being fed to the buck converter) for the first phase of charging. After that when a certain Voltage is reached, we would try to maintain that voltage by reducing the current, until a current value is reached where charging has to be terminated.

But my MAIN QUESTION is that, is it necessary always to implement some kind of control technique (P,PI or PID) in our micro-controller to adjust this value of voltage and current being fed to the battery (by adjusting the PWM cycle off course) ? If yes why ? and if not then why not ?

P.S i searched online and came to find out mostly people have implemented PID control in micro-controllers for running motors. I couldn't find much regarding this with respect to battery charging. I was thinking that may be its because the response time of the system (time to implement the current/voltage change needed) is very small in case of motors operation as that compared to battery charging. Am i right ?

Thankyou !

  • \$\begingroup\$ PID is not particularly easy to tune at the best of times and, in the case of battery charging, the plant you are trying to control is time variant (e.g. the resistance of the battery varies with the level of charge). So applying PID to battery charging sounds like using a sledge hammer to crack a nut. \$\endgroup\$
    – Chu
    Commented Apr 21, 2015 at 16:24

2 Answers 2


You said yourself that depending on what part of the charging process you are in, you keep the current constant or try to maintain that voltage. That's going to require some kind of controller, though not necessarily PID or some subset thereof.

The characteristics of a charging battery change very slowly relative to what even a slow microcontroller can measure and react to. Batteries also don't exhibit second order effects like inertia, like motor speed as a function of current does. Both these together allow very simple control schemes to work well.

Probably about the simplest control scheme for a switching power supply is pulse on demand. It is always stable and robust, although results in more ripple than a more finely tuned control scheme can accomplish.

When the output is below the regulation threshold, you do a pulse, else you don't. To avoid inductor saturation, you may always not do a pulse at the next slot immediately after a previos one, but that's a detail.

I've done pulse on demand switching power supplies with the PIC 10F204 a bunch of times. The code spins in a loop checking the comparator output as long as it is indicating the output is above the regulation threshold. When the output falls below the threshold, the code following the loop is executed, which produces a pulse. The instruction cycles to jump back to the top of the loop and do the next comparator check usually take enough time so that it's OK to do the next pulse righ away if the comparator indicates the output is still below the threshold.

Sometimes this can go meta-stable by producing two pulses in a row before the feedback catches up to the output having gone higher, but in all cases it remains stable as long as the maximum load isn't exceeded.

This sort of system is fine for battery charging, except that you have two thresholds, one for voltage and one for current. You only do a pulse if the output is below both. The higher level logic can adjust the limits as the battery progresses thru the charging procedure.

  • \$\begingroup\$ I heard about the "pulse on demand" for the first time. I think i should try to search about it more over the internet. As most of the articles (almost all that ive gone through) says that buck converter is being operated with PWM for the battery charging purpose. Yet i dont know what would be the output current ripple be like if using "pulse on demand" technique, as i really desire a small current ripple at the output (a constant current value). As in PWM case ive read that current ripple can be reduced by increasing the switching frequency. \$\endgroup\$
    – yiipmann
    Commented Apr 21, 2015 at 13:35
  • 1
    \$\begingroup\$ @yiipmann, the "pulse on demand" scheme is more commonly referred to as a "constant on-time" control scheme. It is quite common in power supplies. \$\endgroup\$
    – Zulu
    Commented Apr 21, 2015 at 19:07
  • \$\begingroup\$ While searching about it, i am getting articles related to PFM i.e Pulse Frequency Modulation, where you adjust the frequency of constant duty cycle pulses to achieve your desire output. I think its the same as "pulse on demand" thing. Am i right ? \$\endgroup\$
    – yiipmann
    Commented Apr 22, 2015 at 13:55

Since you will be controlling a parameter (duty cycle) as a function of battery current and voltage, you will necessarily express some kind of control law in your code. P, PI, and PID are just the most common types with well-known properties, so you should aim to implement one of these instead of just writing some code which "kind of works" but may have unexpected properties like instability problems or bad precision.

That "pulse on demand" Olin is talking about is a special case of P controller with P=infinity and a saturation which naturally comes from the fact that your duty cycle cannot be less than 0% or more than 100%. It is very simple, stable and imprecise in dynamic systems. It will perfectly work for charging though, because battery parameters variation is so slow it can hardly be called "dynamic" from microcontroller's perspective.

PI and PID control laws allow you to minimize dynamic error in your regulation, but they are really not worth the trouble implementing in your case.

  • \$\begingroup\$ After searching online, i found out that i would be having an increased current ripple if ill be using the "pulse on demand" technique. Since i dont want that, i really wish to have a smooth dc current value at my buck converter o/p to be fed to the battery, is there any suggestion how should i design my controller ? I searched alot online on "how to design controller for battery charging" but all i get are the readily available ICs from different companies which are used for battery charging control. \$\endgroup\$
    – yiipmann
    Commented Jul 18, 2015 at 15:21
  • \$\begingroup\$ However i really wish to know, what method would be the best (in terms of good result, and easy implementation) and how to implement it. For eg some design document which could guide me on how to design your control loop for the battery charging purpose, as i dont have any vast knowledge in control field, neither have i designed and implemented any control loop ever in my life, so im a bit afraid here \$\endgroup\$
    – yiipmann
    Commented Jul 18, 2015 at 15:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.