LM317 Based Digitally Controlled Power Supply - Page 1
Forum section: electronics / beginners

author: EthannCraftt
author_rank: Newbie
timestamp: April 20, 2024, 02:57:43 am
content: Hello. I'm looking to construct a digitally controlled power supply. I have a circuit drawn up with a PWM voltage control circuit of my own design, and the current control design that Dave drew on his PSU series hooked up to the input of the second LM317.After being plugged into a circuit simulator, it seems to have really weird behavior even though both circuits work great on their own. Any help??? Schematic below.(The +5v inputs are where the PWM will be inputted. An RC filter will be added in the final design. The 1ohm resistor to the far right will also be removed.)

author: TerrySt
author_rank: Regular Contributor
timestamp: April 21, 2024, 12:57:30 am
content: The voltage regulator using the pwm to the lm317 won’t work as drawn. You have eliminated the feedback for the lm317 by connecting the opamp output directly to the reference pin of the lm317. You can sum in a voltage to the ref pin or use the pwm voltage to raise the ground but you still need the output of the lm317 to affect the ref voltage. But the way you have it, the connection from the output of the lm317 to ref is basically eliminated.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 21, 2024, 01:06:34 am
content: Sorry. I spoke too soon. I was going by memory and it obviously isn’t too sharp. That should work, although the resistor from the output to the ref pin isn’t doing anything other than raising the dissipation of the opamp.

author: Zero999
author_rank: Super Contributor
timestamp: April 21, 2024, 10:37:33 am
content: Quote from: TerrySt on April 21, 2024, 01:06:34 amThe 220R resistor provides a minimum load for the LM317. It won't work without it. A lower value resistor might even be required, because the minimum load current for the LM317 is 10mA.Quote from: EthannCraftt on April 20, 2024, 02:57:43 amWhat a strange circuit.What does the Darlington pair and all of the op-amps do before the LM317? It appears to be a current limiter, but the LM317 already has built-in current limiting.All this circuit will do is output 30V.Why not skip the LM317 and just use a Darlington pair? All it does in that circuit is increase the drop-out voltage.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 21, 2024, 01:40:50 pm
content: Yes, I see that the 220R is a good way to ensure a minimum load current for the 317.The first stage is a programmable current limit using a pwm controlled voltage in place of the +5V input to the opamp. Either circuit (the voltage control or the current control) should work on its own, but combining them might be tricky. The current control won't take effect until the voltage control goes into drop out, which might make for some erratic behavior. Whenever I've tried something similar, I've run into issues making it work predictably under all conditions.I would try to sum the current control into the the opamp for the voltage control by eliminating the darlingtons and integrating the current error. That might make things behave a little more predictably.

author: themadhippy
author_rank: Super Contributor
timestamp: April 21, 2024, 02:27:44 pm
content: I tinkered with similar ideas and gave up and used a high side current sensor (ina168),adjust its output range to match your pwm signal range and compare the 2 .

author: TerrySt
author_rank: Regular Contributor
timestamp: April 21, 2024, 05:08:05 pm
content: Something like this is what I would do. It compares the current sense (high side sense) to a reference voltage that could come from a PWM and integrates the difference to over-ride the voltage set when the current goes above the set point.Of course the devil is in the details. One downside of this architecture is a small delay as the integrator slews from zero. This will let the current overshoot for a short time.The biggest issue is the choice of opamps. As drawn, it assumes a 'perfect' opamp that doesn't exist. You need rail to rail inputs for the high side current sense. And single supply, 30V tolerant. I don't know that you can find that.There are ways to deal with the rail to rail input issue, but it requires a bit more design work.

author: Zero999
author_rank: Super Contributor
timestamp: April 21, 2024, 09:52:29 pm
content: Quote from: TerrySt on April 21, 2024, 05:08:05 pmAnother strange circuit.How does it work?Have to simulated it under different loads, currents and voltages?

author: TerrySt
author_rank: Regular Contributor
timestamp: April 21, 2024, 10:34:52 pm
content: Not really unusual. I've seen it, or variations of it many times. Just summing in the voltage and current control loops. You could also ground the bottom of the 2k resistor (R9) and use a diode to sum in the current control.I just did a quick simulation of it with a constant load as I ramped the voltage up enough to switch from voltage mode to current mode and then back down. It works as expected, with a short period of overcurrent before the current loop kicks in. That will always be there, but can be minimized with tuning. If you shorten the integration time, it will respond faster, but eventually loop stability will be an issue. Unless your requirements are ultra-strict, it will probably work.It wouldn't make much sense to do a lot of simulations until you cleaned up the design (scaling the voltage and current loop gains) and used 'real' op amps instead of 'perfect' op amps. I just wanted to show the general architecture.Also, as drawn, the current set point is 'backwards'. Low voltage sets the highest current and vice-versa. You could handle that in the software that controls the PWM or add an inversion.Here is a sim with a constant load of 100 Ohms as the voltage is ramped up using the voltage control from zero (but of course 1.25V is as low as the 317 goes) to 30V. The current limit kicks in at about 19.2V (192mA). I used the ADA4097-2 op amp for the high side current sense which is just the first one I came across that works rail to rail with a single supply at 30V. The other two op amps are still 'ideal'. You would probably need to add some caps in the feedback of the op amps to get everything stable once you pick the real op amps.

author: Zero999
author_rank: Super Contributor
timestamp: April 22, 2024, 07:38:05 am
content: How does the LM317's output go down to 0V, without the adjust pin being pulled down to -1.25V?Are you sure the op-amp models you've used model the power supply rails properly?Please post the .asc file. You can use LT's version of the LM317, the RH117 which is similar enough.

author: MrAl
author_rank: Super Contributor
timestamp: April 22, 2024, 09:37:38 am
content: Quote from: EthannCraftt on April 20, 2024, 02:57:43 amHello,A couple points to be made here.That 220 Ohm resistor is not considered to be low enough anymore, 120 Ohms is the preferred value now. That's to load the LM317 with at least 10ma.When you drive the ADJ terminal directly with a voltage source, you essentially give up the voltage regulation offered from the LM317. The external voltage source appears in series with the 1.25 volt reference source internal to the LM317. That means that your external voltage source is now a large part of the reference source, which means it must be well regulated if the output is to be well regulated. Another side issue is that the LM317 now becomes just a driver, similar to an amplifier with a gain of 1 with an added reference of around 1.25v, and with the external voltage source Vs the reference becomes Vs+1.25v, and that is 'amplified' by the gain of 1 amplifier and then the output of that amplifier drives the output load.That's probably not a problem, but the external source has to be regulated itself, which for your circuit could be a problem. More about that later.The input circuit, ideally, should really be a buck switching regulator that automatically adjusts to the minimum requirements of the input of the LM317. If the so-called drop out voltage was 2.5 volts for example, then the output of the buck should be 2.5 volts plus whatever the output voltage has to be. This isn't too hard to do, but the buck circuit front end is more important because that lowers power dissipation by a very large amount. It means the circuit can go from instead of 30 watts of dissipation for a given load, down to 3 watts of dissipation for that same load. That's a lot and that is why switching regulators make good front ends for linear regulators.So this means drop the linear front end and go with a buck front end. If you can't do that, then you're going to be stuck with pure linear operation which sometimes will dissipate a large amount of power and require a very large heat sink.Now a little more about the external voltage source.Because you will be using PWM, you might have to incorporate some feedback so that you can get the PWM to output the right source voltage so you can get decent accuracy on the output voltage setting. This means sensing the output or the filtered PWM signal and adjusting the pulse width accordingly. This is because the LM317 can no longer regulate the output voltage like it does when only resistors connect to the ADJ terminal. That means you have to do all the regulation with a separate feedback system. This brings in the question of if an LM317 is really needed at all if you have to incorporate your own feedback system anyway and why put up with the unusually large voltage drop of the LM317 that comes with it. With a power transistor and some feedback you can get the voltage drop down to at least 1v or even less.

author: Terry Bites
author_rank: Super Contributor
timestamp: April 22, 2024, 01:15:57 pm
content: https://www.edn.com/control-an-lm317t-with-a-pwm-signal/

author: TerrySt
author_rank: Regular Contributor
timestamp: April 22, 2024, 01:28:06 pm
content: Quote from: Zero999 on April 22, 2024, 07:38:05 amAs I mentioned, the LM317 won't go below 1.25V without a negative reference.The model for the ADA4097-2 is the one that is in the LTSpice op amp directory by default. It is a 50V single supply capable with over the top input capability, so should work here. The data sheet even shows it sensing 50V inputs with a 5V supply.But if I use it in all three locations in my asc file it never completes (I even let it run overnight and it didn't finish). That is usually a sign of some non-monotonic behavior in the model, So the asc I'm attaching only uses it in the current sense location, and just uses 'ideal' op amps in the other two locations.You will probably need to change the LM317 model since I build a custom part from a model I grabbed on the internet. Make sure the model you use works though. I The first one I grabbed didn't. It only had a 0.625 V reference and didn't give close to the correct output.

author: Zero999
author_rank: Super Contributor
timestamp: April 22, 2024, 06:24:30 pm
content: My simulation results differ from yours and the only thing I change was the LM317 to the RH117, which shouldn't make any difference.EDIT:I notice the schematic is different to theother one. I'm glad you realised a diode is necessary to implement CC as well as CV control.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 22, 2024, 06:59:27 pm
content: The diode isn’t required. I put it in there to make it easier to understand. When not in current regulation, the op amp output is at zero volts, so eliminating the diode and connecting the 2k resistor to the op amp output works just as well. I mentioned that above.The results are different because I changed some resistors to make the current scaling different. It is now about 1 amp full scale.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 22, 2024, 07:19:03 pm
content: Quote from: MrAl on April 22, 2024, 09:37:38 amPresumably, the PWM will come from a micro processor or similar running off a 5V supply. So the stability of the PWM control and the reference voltage to the 317 should be pretty much as stable as whatever supply is feeding the micro.And you still get the benefit of the line and load regulation of the 317. Not lab quality, but not bad. You will definitely want to calibrate the relationship between PWM and output volts, or like you suggest, measure the output and trim the pwm. That will be slow though, so probably only good for a fine trim.

author: Zero999
author_rank: Super Contributor
timestamp: April 22, 2024, 08:57:12 pm
content: Quote from: TerrySt on April 22, 2024, 06:59:27 pmOh, I see now. The op-amp's negative rail is 0V, so it just connects the 2k to 0V. That will work fine.Another thing to note about these ideas is in addition to the 1.25V minimum LM317 voltage, there's also the saturation voltage of the op-amp.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 22, 2024, 09:24:24 pm
content: Quote from: Zero999 on April 22, 2024, 08:57:12 pmYep. These are rail to rail op amps, but that is a term that is loosely defined. In this case, it looks like it should get you within 20mV or so of the rails.adding the diode, does get you that 20mV closer to zero if that's important.

author: Zero999
author_rank: Super Contributor
timestamp: April 23, 2024, 06:47:34 pm
content: I'd just ditch the LM317 and replace it with an emitter follower. I chose the BD437 because it has a high enough hFEto be driven by the LM358, even with a collector current of 1A.It's designed so neither op-amp gets driven into saturation, which can take awhile to recover from. D2, R8 & R9 form another feedback loop when it's in current mode. This limits the voltage over-shoot, during recovery.The peak current due to the speed limitation of the current op-amp is limited by D3 and D4 which clamp the base voltage to around 1.4V above the output.

author: MrAl
author_rank: Super Contributor
timestamp: April 24, 2024, 01:23:38 pm
content: Quote from: TerrySt on April 22, 2024, 07:19:03 pmHi there,Actually I was referring to the accuracy of the set point of the voltage that would be controlling the LM317. If the user wanted to output say 5 volts then they would have to apply about 3.75 volts to the ADJ pin. If it was just 3.70 volts then the output would be 4.95 volts. If the design could get that right though (3.75v) I don't think there would be any worry, but that could easily require feedback which brings in the issue of control stability into the picture. If the designer wants to use feedback then it's going to be their responsibility to get it stable. That means the uC will have to sample the output and make adjustments, and that means there will be a delay.As far as regulating once the right voltage is actually applied, that may be ok but I have not looked into that in detail.

author: TerrySt
author_rank: Regular Contributor
timestamp: April 25, 2024, 01:19:58 am
content: Quote from: Zero999 on April 23, 2024, 06:47:34 pmThat looks like a good approach. Many ways to go about this for sure. I like the way the voltage control sums with the current control.I added models for 'real' op amps to my version and tweaked the component values to make it work with a range of output (load) capacitance (up to at least 10,000uF).I'm posting the latest. It could still use some fine tuning, but since the OP hasn't been back, probably no reason to carry this further.Terry

author: TerrySt
author_rank: Regular Contributor
timestamp: April 25, 2024, 01:26:33 am
content: Quote from: MrAl on April 24, 2024, 01:23:38 pmYep. I hope the OP realizes the issue and has a plan to deal with it.Terry

author: aliarifat794
author_rank: Regular Contributor
timestamp: April 25, 2024, 04:22:09 pm
content: Here is also an adjustable power supply design featuring LM317 and LM337. You can see it for further improvement. It uses two voltage regulators, an LM317 for positive voltage and an LM337 for negative voltage.https://www.pcbway.com/project/shareproject/LM317_AND_LM337_ADJUSTABLE_POWER_SUPPLY_CIRCUIT_BOARD_904eaf4a.html

author: EthannCraftt
author_rank: Newbie
timestamp: April 26, 2024, 02:25:23 am
content: Thanks all for replying!! I got caught up in my high voltage work and was a little busy with that.I'm not necessarily opposed to replacing the lm317 with discrete components, I just thought it would be a fun design challenge and a nice way to use the ones I had on handI did plan on adding a feedback on the output to the microcontroller (and one across the 1ohm resistor from the current limiter circuit), I just didn't know how to integrate that into a digital schematic.The main problem that I've noticed based on the replies was the fact that inputing a voltage puts the internal voltage refrence in series, and to be frank I doubt the accuracy of my own voltage input. How would I go about voltage regulation with PWM another way that doesn't have this issue? I couldn't figure it out with my tinkering in simulation software. Can it even be done while maintaining use of the LM317?Again, I would be perfectly okay with changing out the voltage regulator with discrete circuitry, so long as it's accurate(ish). Thanks!

author: MrAl
author_rank: Super Contributor
timestamp: April 26, 2024, 01:41:03 pm
content: Quote from: EthannCraftt on April 26, 2024, 02:25:23 amWell it does make an interesting linear series pass power element as compared to a regular power transistor.

author: Kleinstein
author_rank: Super Contributor
timestamp: April 26, 2024, 07:56:01 pm
content: The LM317 when used as the regulator is not very accurate. This starts with the output pins / contacts and the heating of the reference and amplifier part. So a serate build regulator is often the more accurate way. Adding current limiting / regulator to a LM317 regualtor circuit is challanging, arguably more tricky than starting from scratch with OPs and power transistors.Usually the regulation is done analog - a digital solution is rather demanding on the ADC / DAC side and still often slow.When starting with PWM as a set signal one goes PWM -> fitler to get an analog set voltage and than goes with an analog regulator (e.g. classic PID style) from there.

author: MrAl
author_rank: Super Contributor
timestamp: April 28, 2024, 04:09:03 pm
content: Quote from: Kleinstein on April 26, 2024, 07:56:01 pmHi,Yes, they do not mention that directly in the data sheet so it's easy to miss. If you look at the spec's carefully and surmise yourself that the temperature is going to rise with significant load in most cases, then you might realize that the on-chip voltage reference temperature is also going to rise and thus the output voltage will change more significanly than the voltage reference.

author: Zero999
author_rank: Super Contributor
timestamp: April 28, 2024, 08:48:28 pm
content: The good thing about the LM317 is it has over-temperature and safe operating area protection, which you don't get with a plain transistor.The circuit I posted above will should work with the LM317. Note R11 is only there to keep the simulator happy.EDIT: Added -5V supply.

author: Kleinstein
author_rank: Super Contributor
timestamp: April 29, 2024, 07:50:02 am
content: The circuit with the LM317 as a power transistor replacement would need a negative supply for the OP-amp. Otherwise it would not work below some 1.2 V and could not limit the current with these low voltages (e.g. with a short).

author: Zero999
author_rank: Super Contributor
timestamp: April 29, 2024, 08:28:08 am
content: Quote from: Kleinstein on April 29, 2024, 07:50:02 amYes, you're right. I somehow messed up by copying the wrong schematic. I evensaid that myself.I'll edit it.