# PWM constant current source?

#### imbaine

Joined Mar 23, 2021
13
Hello everyone,

So I need a three stage SLA battery charger, but rather than go out to buy one, I thought I'd challenge myself and build one. It will be an A.C based charger, with a transformer stepping the mains voltage down. After rectification, I want to limit the charge current to 2 amps, which is the maximum the transformer can safely handle.

The biggest challenge I'm facing is how to limit the bulk charge current easily and efficiently. I initially thought of linearly limiting the current (using an LM317 or similar), but that would be wasteful. Buck converters are the other option but I don't want to get into switching current regulators just yet.

I can regulate the battery voltage during the float charge using PWM like it's normally done with solar charge controllers, why can't I do the same with current? I'll be using an Arduino to run the show, and I could scale the PWM like 0 < my_control_signal < 255 to correspond with current 0 < charge_current_of_2_amps < 5 amps (assuming the maximum current to be 5 amps without current limiting). A current sense resistor plus a differential amp with a filtered output (to even out the PWMed current) will provide information on how much current I've got charging the battery. I haven't built or tested it out yet, but the logic here is that the Arduino will read the current and use PWM to raise or lower the battery voltage to the point where 2 amps (average) are flowing into the battery. If this could work, I'd only lose power in the shunt resistor and switching of the power transistor, which would be far more efficient than linear current limiting. Also the battery would have to be fine with switched current.

Isaac.

Last edited by a moderator:

#### crutschow

Joined Mar 14, 2008
32,846
Sorry to burst you bubble but PWM will save power only if there is a series inductor to store energy and limit the current (which is what those solar charge controllers have).
You can limit the average current with PWM but the peak current when the PWM signal is on will be limited only by the resistance in the system (transformer, rectifiers, etc.), and that high peak current dissipates a lot of energy since the dissipation goes up as the square of the current.

Another issue:
If you have a 2Arms rated transformer you need to limit the DC current to less than that.
Due to the high peak current generated by a rectifier output, the DC current should be limited to no more than about 60% of the transformer rating, or 1.2Adc in your case.
Otherwise the transformer can overheat and burn.

#### Papabravo

Joined Feb 24, 2006
20,369
Why do you think you can't regulate current with a PWM?
It does require you to mimic the behavior of an SMPS though, and as @crutschow has pointed out there are some other difficulties, but they are far from insurmountable.

#### imbaine

Joined Mar 23, 2021
13
Sorry to burst you bubble but PWM will save power only if there is a series inductor to store energy and limit the current (which is what those solar charge controllers have).
You can limit the average current with PWM but the peak current when the PWM signal is on will be limited only by the resistance in the system (transformer, rectifiers, etc.), and that high peak current dissipates a lot of energy since the dissipation goes up as the square of the current.
Hello crutschow,
I understand that bit about the series inductor coz in my initial design, I thought of having a differential amplifier that measures the voltage drop across the shunt and feeding that voltage into a comparator with hysteresis. The other input to the comparator would have the voltage reference (illustrated below). Assuming an initial state where there is no current flowing and the comparator has turned the control element on, the current would ramp to 2 amps. I hit a dead stop upon realizing that as soon as the control element is turned off, current would stop instantaneously, requiring the comparator to almost immediately turn it (the control element) back on. This would clearly not work, but what if I added an RC filter at the output of the differential amp so that when the control element is turned off (with the output of the diff amp at zero as well) the capacitor discharges slowly so the comparator doesn't "see" an sudden drop in current. In a way, wouldn't the capacitor act as the energy storage device that would keep the ON-OFF-ON-OFF sequence running? When the voltage on the capacitir drops below a certain threshold (corresponding to about 1.6 amps), the comparator turns on again.

In this case, there would be no fixed frequency for the circuit to run and instead, the load would set the frequency. The faster the current ramps, the higher the frequency.

I have the option of either PWM or the set up above.
Another issue:
If you have a 2Arms rated transformer you need to limit the DC current to less than that.
Due to the high peak current generated by a rectifier output, the DC current should be limited to no more than about 60% of the transformer rating, or 1.2Adc in your case.
Otherwise the transformer can overheat and burn.
I'll keep that in mind, thank you very much.

#### crutschow

Joined Mar 14, 2008
32,846
Your circuit may work, but that won't affect the efficiency, which will still be the same as a linear regulator such as the LM317.
The only way to improve the efficiency is to add a series inductor with a free-wheeling diode to ground after the switch.

#### imbaine

Joined Mar 23, 2021
13
Why do you think you can't regulate current with a PWM?
I'm almost certain I can, but I need a little more guidance or advice from someone that might have already tried.
It does require you to mimic the behavior of an SMPS though, and as @crutschow has pointed out there are some other difficulties, but they are far from insurmountable.
I plan to build an adjustable bench power supply later, but as I was looking over the power supply design, I though I could use a few ideas from it with the battery charger project. I'm following this design, but with a few modifications. The battery charger is essentially a current limited power supply, except that the output current is fixed and the output voltages are preset.
In the bulk charge, the battery charger will operate in current limit mode, but in the float and trickle charge stages, it will operate in voltage limit mode. The voltage limit modes (14.2 volts and 13.5 volts) don't present challenges to me coz I have seen solar charge controllers that use PWM to maintain a constant voltage across a battery (regardless of the current), it's the current limit that gets me.

So, my aim is to use PWM to control output voltage which would in turn control the current of the charger. If this could work, I'd be saved loads of headache!

#### imbaine

Joined Mar 23, 2021
13
Your circuit may work, but that won't affect the efficiency, which will still be the same as a linear regulator such as the LM317.
The only way to improve the efficiency is to add a series inductor with a free-wheeling diode to ground after the switch.
I don't see how........the transistor wouldn't operate in its linear mode. It'd only either be ON or OFF as opposed to the LM317 type circuit which would regulate linearly (so to speak), am I right?

I'm trying to avoid getting into switching regulators. I don't have a scope at the moment, so I wouldn't know in case of instabilities in my circuit. I wouldn't be able to measure the output noise, ripple or any of that nasty stuff either, so I'm trying to keep it simple.

#### Papabravo

Joined Feb 24, 2006
20,369
So what output voltage would you start with for a current of 1.2 amperes. Would you have to try a bunch of voltages before you found the correct one?

#### crutschow

Joined Mar 14, 2008
32,846
I don't see how........the transistor wouldn't operate in its linear mode.
Yes, the transistor won't be dissipating much power but your are just transferring the loss to the other resistances in the circuit (transformer, wiring, etc.) so there's no change in efficiency.
You can look at it any way you want, but you won't improve the efficiency until you add an inductor.

#### BobTPH

Joined Jun 5, 2013
7,509
PWM does not control voltage. PWM does not control current. PWM controls duty cycle. The average power is controlled because it is 0 during the off phase and 100% during the on phase.

Learn how a buck converter works. When you understand that you will understand how what I am saying. And why @crutschow says you need an inductor.

Bob

#### imbaine

Joined Mar 23, 2021
13
So what output voltage would you start with for a current of 1.2 amperes. Would you have to try a bunch of voltages before you found the correct one?
Actually, it will be the job of the charger to do that. First, it will apply the full output of the transformer across the battery, measure the current and if for instance to current is 3 amps (I know that's more than double the current I can safely pull from the transformer but is just momentary), it will ramp the PWM down until the current drops to 1.2 amps and maintain it there until the battery hits 14.5v. At that point, the charger will measure the current again and this time maintain the voltage until the current drops to 10% of the value it was when the voltage had just hit 14.5. Then the third stage will begin (maintaining 13.8 volts).

#### imbaine

Joined Mar 23, 2021
13
Yes, the transistor won't be dissipating much power but your are just transferring the loss to the other resistances in the circuit (transformer, wiring, etc.) so there's no change in efficiency.
You can look at it any way you want, but you won't improve the efficiency until you add an inductor.
I know there will be transformer losses, but those are out of my control and there isn't that much I can do about it. The losses would still be present if I took the path of linear current regulation. Besides, transformers can be very efficient, reaching regions of 95 - 99%. I'll take that any day vs using linear regulation. Switching losses wouldn't be that significant either since the PWM frequency is low. If I don't have to mount a heat sink on the switching transistor, I'm golden!

I'm quite sure the premise would work (nothing beats ohm's law), I just want to bench test it but I can't seem to fine the time just yet. All I have to do is provide a filtered current reading to the MCU.

#### crutschow

Joined Mar 14, 2008
32,846
If I don't have to mount a heat sink on the switching transistor, I'm golden!
So you are not really worried about efficiency, just the dissipation in the transistor.
That's different from increasing the overall efficiency by using PWM, which your circuit won't do.

#### Papabravo

Joined Feb 24, 2006
20,369
Actually, it will be the job of the charger to do that. First, it will apply the full output of the transformer across the battery, measure the current and if for instance to current is 3 amps (I know that's more than double the current I can safely pull from the transformer but is just momentary), it will ramp the PWM down until the current drops to 1.2 amps and maintain it there until the battery hits 14.5v. At that point, the charger will measure the current again and this time maintain the voltage until the current drops to 10% of the value it was when the voltage had just hit 14.5. Then the third stage will begin (maintaining 13.8 volts).
I do not think this scheme has any chance of working the way you think it will. By all means give it a try, if that is what it takes to convince you.

#### BobTPH

Joined Jun 5, 2013
7,509
Do you also think it would work to charge it at 1200A for 1ms out of each second? Like your scheme, that also gives you an average charging current of 1.2A.

Bob

#### Bordodynov

Joined May 20, 2015
3,084
See

#### crutschow

Joined Mar 14, 2008
32,846
In this case, there would be no fixed frequency for the circuit to run and instead, the load would set the frequency. The faster the current ramps, the higher the frequency.
Switching losses wouldn't be that significant either since the PWM frequency is low.
Since you are not controlling the switching frequency, why do you think it will be low?
As you stated, the current ramp-up will be determined by the load (mainly the circuit stray inductance of perhaps a few microhenries) and, since that is low, the ramp-up will be fast and the PMW frequency thus also high.

Last edited:

#### BobTPH

Joined Jun 5, 2013
7,509
In all the time you have wasted here arguing with experts like @crutschow and @Papabravo , you could have instead learned how a buck converter works. Then you might understand what we are saying.

Bob

#### Papabravo

Joined Feb 24, 2006
20,369
In all the time you have wasted here arguing with experts like @crutschow and @Papabravo , you could have instead learned how a buck converter works. Then you might understand what we are saying.

Bob
I don't think that matters to the TS. Just let this one go.

#### crutschow

Joined Mar 14, 2008
32,846
Yes, it's annoying when a TS asks for advice and then argues that he's right and the advice from several posters is wrong.