# Practicality of this LM317T PWM Voltage and Current control circuit

Ive been trying to design a LM317T power supply with a PWM (Arduino MCU etc) adjustable voltage and current limit. After various circuits, videos and tutorials i have designed the following circuit in LTspice.

I am a complete beginner in electronics, so can someone point out any practical considerations or something even more obvious that i've missed; before i commit this circuit in hardware.

I've run a few basic simulations and both the current and voltage limit seem to work without considerable oscillations.

Ive attached the LTSpice schematic below:

V3 sets the voltage

V2 sets the maximum current

Please note PWM filtering has not yet been implemented

• If you're using Arduino, keep in mind that a lot of people call servo signals "PWM". Technically, they are, but they have some special rules that limit their usefulness for anything that doesn't understand those rules. A "PWM library" could be straight PWM or it could be for servos. Make sure you know what you have. – AaronD Apr 8 '15 at 19:09
• I have merely simulated a clean DC source and am aware that PWM would need a lot of filtering before it can come near to the inputs here. I am actually thinking of using 12 bit DAC ICs. – Adil Malik Apr 8 '15 at 19:13
• It looks OK. What are the supply voltages for the opamps? Don't forget bypass caps. How much current and voltage. Q1 and the LM317 may need heatsinks. – George Herold Apr 8 '15 at 19:24
• Vin will be a 20V DC source. I am thinking about powering the Op amps with Vin (20V) – Adil Malik Apr 8 '15 at 19:26

Some practical concerns...

1. Q1 should have some base resistance to limit the current feeding it (when U3 is behaves as a comparator, in constant-voltage regulation).
2. The "gain" of the constant-current loop formed by R1, U2, U3, and Q1 will vary depending on load current (because Q1's transconductance is proportional to current). In particular, evaluate the stability of this loop at maximum programmed load, because the loop gain will be highest then. The dominant pole is in U3's compensation, although U2 adds a pole, as does U3's $Z_O$ feeding Q1's base capacitance. You might consider making U3 an integrator to reduce the crossover frequency to a certain programmed value (e.g., 1kHz).
3. Power supplies are usually built with voltage regulation and current limiting in the "high side" -- that is to say, one terminal of the load is connected to ground. Since you've already given up your ground connection (with Q1), it's more practical to place R1 below Q1 (between Q1's emitter and ground). Thus, U3 could regulate the Iset current without needing the U2 difference amplifier.
4. The output voltage regulation isn't going to be especially accurate. This is because of the voltage drop across R1, as well as Q1's $V_{SAT}$, which is typically ~0.2V. You can improve this somewhat by making Q1 a MOSFET. Generally, though, it's better for the voltage regulator to measure (and regulate) the voltage directly across the load, bypassing the sense resistor. The LM317 doesn't give you the option to do this, but other regulators do. This will usually require a high-side sense resistor (like the way your R1 is now), meaning you'd need a difference amplifier again.
5. You can find high-side current sense amplifiers that will be quite a bit more accurate than an op-amp difference amplifier is. Just look on Digikey for current sense amplifiers.
6. Since the voltage regulator already provides a power device, having a second power device (i.e., the current regulation transistor) is somewhat redundant. If you do it right, you can measure the current through a sense resistor, and if the current exceeds the setpoint then you can throttle back on the voltage setpoint.
7. You should always have capacitors bypassing the input and output pins of voltage regulators.
8. When evaluating stability, you should run a transient simulation with some sort of impulsive perterbation to give the circuit a "kick." A popular choice is a current step. If it oscillates after the kick, then it's unstable. You should re-run the simulation under various load conditions.
9. Before committing to the PCB, you should perform a simulation with reasonably accurate models of all the devices you're using. In particular, U2, U3, and Q1 are going to behave very differently from the [almost] ideal model you're using right now. Also, be aware of input common-mode range; if you powered U2 from the regulator's output, without a rail-to-rail input common-mode range then it wouldn't work at all.

In summary, if it were me I would redesign the whole thing. That said, making a PCB is cheap enough that you can just try it and see for yourself. After all, seeing how things work in real life is more educational than any gibberish I can generate.

All that said, you might consider just buying a pre-made solution. Try the LT3081 on for size. It includes built-in current regulation. The application on Page 24 of the datasheet shows a sophisticated programmable CV/CC regulator. I'm sure the ILIM pin can be readily hacked to make it controllable from a MCU.

• Thank you so much! Just what i needed! Point 3 is what i was particularity confused about, i did not see which configuration is better (or different). Will definitely breadboard this soon! Is there something inherently wrong in "giving up your ground"? – Adil Malik Apr 8 '15 at 19:23
• Switching the ground-side of circuits also generally makes them harder to interface with other circuits: most circuits are made to be ground-referenced, and this philosophy permeates the entire design. Also, since most PCBs have a large ground plane, you can power circuits simply by running a power wire out to them. If a circuit is disconnected from ground, then you must run two wires to power it. – Zulu Apr 8 '15 at 19:32
• Ok, i think i have to change this then. How can regulate the current in a similar fashion but with the Load being connected to ground? Use a PNP transistor and high side sensing? No so sure – Adil Malik Apr 8 '15 at 19:35
• @AdilMalik, you've already got a high side current sense. For a grounded load switch the position of the load and Q1. (That was easy :^) – George Herold Apr 8 '15 at 20:07
• @AdilMalik, see Point 6. When you sense too much current, you can throttle back the voltage setpoint. – Zulu Apr 8 '15 at 20:18

A lot of analog stuff can be PWM'ed like that, but I would not do it here. At least not directly. The idea behind PWM controlling analog stuff is that the system being controlled cannot react nearly as fast as the PWM is running and so it follows the average.

In your case, I would expect the regulator chip to track the PWM waveform better than spec'ed (thanks, Murphy), and so I would definitely add an explicit lowpass filter between the PWM and the regulator chip to guarantee that it cannot react that fast to the PWM. The filter should cutoff as low as practical and certainly no higher than a tenth of the PWM frequency. (raise the PWM freq. if this becomes a problem) Then you should be okay. Still check for noise across the load though.

Another idea, if you have some spare I/O, is to have an entirely DC control scheme where different combinations of multiple binary outputs produce different analog voltages. There are many different ways to do this, ranging from one-hot open-drain with different resistances to an R/2R-based DAC.

Speaking of DAC's, some uC's have them built-in. This might be even easier than PWM. (Arduino doesn't, as far as I know)

• This circuit was mainly to test its current limiting capabilities in LTSpice. I will definitely implement a buffered low pass filter between the MCU and the inputs here. How about a few SPI 12 Bit DACs?. – Adil Malik Apr 8 '15 at 19:11
• External DAC should work. I'm not sure you need that much resolution, but the free market says that an external unit has to be better than the internal stuff on most uC's. Oh well. – AaronD Apr 8 '15 at 19:33