LM317 control by PWM  - Page 1
Forum section: electronics / projects

author: tzc
author_rank: Newbie
timestamp: February 01, 2019, 10:09:23 am
content: I am trying to adjust the output of the LM317 by using PWM of microcontroller but I cant get the aspected result that I want ,even the output of the non inverting operation amplifier is wrong.It is my schematic diagram is wrong?please give some recommendation and suggestion.Thanks.

author: iMo
author_rank: Super Contributor
timestamp: February 01, 2019, 11:32:17 am
content: What is the value of RV1?What is your PWM frequency?Here is something which may work:https://www.eevblog.com/forum/beginners/pwm-for-lm317-how-to-increase-resolution/msg1809224/#msg1809224The R6/R7 in my schematics is the feedback from the output of the LM317.What results you get?

author: Yansi
author_rank: Super Contributor
timestamp: February 01, 2019, 12:12:44 pm
content: Why would one want to use a LM317 for this task? It is one of the worst choices, if there is an opamp available already.Beef the opamp outputs with a suitable NPN transisotr and let the opamp deal with the regulation. Then just one NPN more to add current limiting.

author: Zero999
author_rank: Super Contributor
timestamp: February 01, 2019, 01:52:14 pm
content: What's the PWM voltage?What's the desired output voltage range?

author: tzc
author_rank: Newbie
timestamp: February 01, 2019, 03:42:08 pm
content: Quote from: imo on February 01, 2019, 11:32:17 am

author: tzc
author_rank: Newbie
timestamp: February 01, 2019, 03:45:47 pm
content: Quote from: Zero999 on February 01, 2019, 01:52:14 pm

author: iMo
author_rank: Super Contributor
timestamp: February 01, 2019, 04:44:04 pm
content: With the feedback resistors ratio RV1=5k/R3=1k and LM317's Input voltage >=32.5V you should get the output range.Not sure -15V rail is necessary, I would use an LM358 (or similar) with single 32.5V source.Mind the feedback divider is wired at the LM317 output - such the LM317 is inside the control loop.You may leave your R4=240ohm there, hopefully the TL081 can handle 5mA output current (sink).

author: David Hess
author_rank: Super Contributor
timestamp: February 01, 2019, 05:32:30 pm
content: Tzc, the circuit is not ideal but it should work.Quote from: Yansi on February 01, 2019, 12:12:44 pmThe advantage of using an LM317 instead of discrete transistors are:1. The LM317 includes built in current limiting.2. The LM317 includes built in thermal protection.3. The LM317 includes built in safe operating area protection.4. The LM317 only requires a constant drive current invariant of load which in this example is about 5 milliamps.

author: Yansi
author_rank: Super Contributor
timestamp: February 01, 2019, 06:03:36 pm
content: One can protect for over-current and SOA with a single transistor. Even implement a fold-back current limit. I see zero reason for LM317. Current drive argument is irrelevant, the opamp does not care if 10uA or 10mA needs to be supplied.Soft current limiting will be pain in the arse to add to the LM317. Can't do that with a single transistor in this single supply configuration.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 01, 2019, 06:21:25 pm
content: First off - having to resort to a dual +/-15V supply to only generate a positive supply in the end is quite wasteful. Just chose a different opamp that can work on a single supply (with an output which can get close to ground).Due to R4, the opamp will also have to sink significant current. Not sure the TL081 can.Additionally, obviously you will never get a 30V output with a 15V input...(As a side note, when you say "I can't get the result I want", it's a bit vague, to be polite. Please be more specific as to what you notice about the behavior of your circuit.)I would get rid of the -15V supply and select an appropriate opamp. An LM358 would kinda work, but it doesn't have nulling offset pins (if that matters, since you'd probably get only a few mV offset), and whereas its output can get down to almost ground, it won't get high enough - due to the current it will have to sink - to get your full output voltage range here IMO.Your circuit should get you an output voltage close to: 1.25V + Vop (where Vop is the output voltage of the opamp) and with a maximum voltage of approx. between (Vin-2.5V) and (Vin-1.5V) (dropout voltage of the LM317) depending on the conditions (output current, temperature...) So take that into account. Your input supply voltage should thus be at least 32.5V if you want a 30V max output. Don't forget to use a good heatsink on the LM317. The opamp should also be able to take a 32.5V supply and sink enough current. With all that combined, a possible opamp would be the AD820 for instance. Many others will have a much reduced output voltage span due to the relatively high current they will have to sink here (~5 mA).

author: iMo
author_rank: Super Contributor
timestamp: February 01, 2019, 06:45:53 pm
content: This is an LTspice rewrite of my LM317 PWM (see my link above).How the output looks like when an R_LOAD is switched on/off, I=15mA/500mA, Vout=15V.Still you may see some PWM feed-through at the output.Simulation only.Use at your own risk..

author: Zero999
author_rank: Super Contributor
timestamp: February 01, 2019, 09:39:08 pm
content: Quote from: imo on February 01, 2019, 04:44:04 pmQuote from: SiliconWizard on February 01, 2019, 06:21:25 pmYou've got that backwards. The LM358 won't do without a negative supply because it can't sink enough current with a low enough saturation voltage for 1.25V out. The higher end of the voltage range is no problem.I've done a quick search and there are no common, cheap op-amps, which can sink the minimum load current required by the LM317, with a low saturation voltage.If a single supply is a requirement, then I'd add a current sink to the LM317's output and remove the resistor.Here's how I'd do it. Q1 is a constant current sink which takes the LM317's minimum load.U2 is configured as a Sallen-Key filter with a cut-off of 10Hz, a damping factor of 1.4 and a gain of 5.75. If a dual op-amp is being used, it might be better to separate the filter and gain stage, but I just wanted to demonstrate it can be done.I cheated by using a calculator tool to select the component values, see the link below:http://sim.okawa-denshi.jp/en/OPstool.php

author: Yansi
author_rank: Super Contributor
timestamp: February 01, 2019, 09:49:24 pm
content: So yet another reasons why NOT to use a damn 317!//also you sure it will be stable at gain of almost 6? I have had bad trouble making sallen-key filters to not oscillate above gain of 3.

author: Zero999
author_rank: Super Contributor
timestamp: February 01, 2019, 11:09:06 pm
content: Well I wouldn't agree with you about the LM317: the current limiting, thermal, safe operating area protection are very good reasons tio use it, in spite of the other minor inconveniences it causes.Regarding the Salen-Key, you're probably right. I've not tried to design one with this much gain before. It would be a good idea to move the gain stage to after the filter.

author: David Hess
author_rank: Super Contributor
timestamp: February 02, 2019, 12:22:12 am
content: Quote from: Zero999 on February 01, 2019, 09:39:08 pmIf the saturation voltage matters, then a different circuit topology should be used. The LM317 is not suitable for outputs below 1.25 volts unless a negative control voltage and a minimum load current with a negative compliance is available but often this restriction is acceptable.For performance and precision reasons, the minimum load or quiescent current of the integrated regulation should be buffered from the output of the operational amplifier with a transistor and old designs which use the LM317 or other integrated regulator do this.Both of these problems are solved if the minimum load current is provided without the resistor between the output and adjustment pin of the LM317 despite how convenient it was. Now no buffering is required and the load current on the operational amplifier is stable and low allowing for low saturation voltages. But to operate below 1.25 volts, this still requires a negative supply which might as well be used to remove the saturation requirements on the operational amplifier also.Quote from: Yansi on February 01, 2019, 06:03:36 pmAnd thermal protection? I really try to avoid adding discrete temperature sensors if I can avoid it.It does not apply to this circuit but current boosted designs using the LM317 to drive a power transistor make the LM317 even more useful that just a current buffer because with a little attention to thermal resistance, the thermal protection of the LM317 can be extended to cover the power transistors.QuotePrecision applications (which this is not yet) require the operational amplifier's output current to be controlled and even better, low. This makes the LM317 with the minimum load current returned to another point especially useful for simplified precision power applications.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 12:37:29 am
content: This is not a precision circuit in any way shape or form, and if there was a requirement for the output to go from0to 30V. Adding a negative supply, or other hacks (the pre-load current sink) for it to work at least close to zero, is just to much fucking around for nothing, in my opinion.A simple NPN darlington cascade would be more than adequate, with some form of fold-back current limiting circuit (still nothing more, than a TO220 power darlington and a small signal NPN to handle the current limiting).Thermal protection being the most difficult difficult of these to implement (you've got me on that one), but a thermal cutoff switch (that mechanical one) would probably do more than enough in that case.However PWM indicates a presence of an MCU, so simple temperature sensing is a matter of just an NTC and a couple of resistors. Not ideal, but simple and effective also.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 02, 2019, 03:27:45 am
content: Quote from: Zero999 on February 01, 2019, 09:39:08 pmWell, yeah. The sink current (as opposed to source) is going to have the opposite effect. My bad.That said, I think an LM358 can sink 5mA without much problem. Its output should be able to get as low as a few tens of mV, and I think it will still get further away than this from the positive rail on the other end. From its datasheet, it's given for a typical 8mA of max current sink. Would have to be tested, but simulation shows that the output can go as low as ~30mV for 5mA of current sink, and can't get higher than the positive rail minus ~1.2V, so there's still this asymetry (of course for higher currents, the output range would get shifted up). Looking at an LM317 datasheet, its reference voltage is specified between 1.2V and 1.3V, so a minimum of 50mV output for the opamp is not really going to make much of a difference actually. If the OP really wants 1.25V min voltage output to a few mV of accuracy, then clearly this topology is not for them. Given the proposed schematic and their questions, I doubt 50mV or 100mV from 1.25V will make any difference! But if it did, I guess an LM317 could go lower than its reference voltage by setting a negative voltage on its ADJ pin, but not 100% sure it would not cause issues. In this case, a slightly negative supply voltage (-15V would certainly not be needed) should allow to do this.(As to the higher end, there is a lot of headroom here actually, if the opamp is powered by the input voltage of the circuit, given that the LM317 has around 2.5V of dropout voltage and there is an extra 1.25V, so that's 3.75V of headroom. So yes the higher end shouldn't be a concern here anyway.)The OP's schematic's idea was actually given here:https://www.edn.com/design/analog/4363990/Control-an-LM317T-with-a-PWM-signalThere are of course a lot of ways to do better, but as far as I've gotten it, the OP simply wanted something that "works" before going any further and chasing after a few mV...And in that case, it seems to just be a matter of using a more appropriate opamp than the TL081.

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 09:22:33 am
content: Quote from: SiliconWizard on February 02, 2019, 03:27:45 amThe simulator you've used doesn't model the output stage correctly. Never rely on the manufacturer's SPICE models to accurately show things such as output voltage saturation, supply current and input common mode range. They're more often than not wrong. The only way to test this is to build it!The LM358 doesn't have a proper single supply output stage. It has 50µA current sink, consisting of a current mirror, connected to an ordinary push-pull stage, with a PNP low side. As long as the output isn't sinking any more than 5µA, the saturation voltage will be fairly low and there's a huge ramp up, as the current exceeds 10µA.This is all on the datasheet.http://www.ti.com/lit/ds/symlink/lm158.pdfIn short, the LM358 is not designed to sink any current, with its output at the negative rail

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 09:58:43 am
content: Once more - using a NPN darlington output stage instead of 317 solves all of these hassles. Only current supplied, not needed to be sunk!

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 12:38:50 pm
content: Quote from: Yansi on February 02, 2019, 09:58:43 amThat's all well, until it overheats, resulting in magic smoke. It also will have a higher drop out voltage than the LM317, as the saturation voltage of the op-amp's output stage will add to Darlington pair.Just use the LM317 and current sink, to provide the minimum load. It's not complicated.

author: soldar
author_rank: Super Contributor
timestamp: February 02, 2019, 01:16:34 pm
content: If I understand how this IC works then a bias voltage like in the attached diagram should control the LM317 output voltage. Then it is just a matter of filtering the PWM so that it results in a stable voltage. The two diodes help bring the output closer to zero but they can be omitted if not needed.With R1 = R2 roughly Vout = - Vcontrol.Increasing the value of R1 would make roughly Vout = -(R1 / R2) * VcontrolMaybe somebody can go over it and check.

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 02:10:32 pm
content: Quote from: soldar on February 02, 2019, 01:16:34 pmYes, that's the general idea. The trouble with that configuration is the op-amp has to sink all of the current.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 02:23:43 pm
content: Quote from: Zero999 on February 02, 2019, 12:38:50 pmWho cares about the Vdrop? Was not in the requirement list.Why should it overheat? Your LM317 will anyway, if you will not use enough heatsinking.That is like saying your car is going to crash, because it is an older model without airbags. It is the same kind of logic.//EDIT: Using a compound darlington the Vdrop becomes even smaller//EDIT2: Wanted to compare the voltage drops, and ... wtf is this?

author: soldar
author_rank: Super Contributor
timestamp: February 02, 2019, 03:42:25 pm
content: Quote from: Zero999 on February 02, 2019, 02:10:32 pmI am sorry but I don't understand. What op-amp? Are you referring to the LM317? In which case... yeah. Isn't that what it is supposed to do?If you are referring to the voltage source I have included, then, no, it does not sink all the current. The main current returns via the common ground. The PWM signal is very small and can be generated using a 555 timer or anything else, completely independent of the rest of the system.Maybe I am missing something.I am not good enough with LTSpice yet but maybe someone can do it. I would start by just connecting R2 to a variable negative voltage. Then add the diodes. Then add LC filter and put a PWM signal there.

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 05:50:07 pm
content: Quote from: Yansi on February 02, 2019, 02:23:43 pm1) Voltage drop is important because you won't be able to get 30V out, without exceeding the maximum voltage rating of the LM358.2) Reading between the lines, it's probably for a bench power supply, so it will be abused and thermal protection is important.3) Yes a compound transistor helps, but still no thermal protection.4) An error.Quote from: soldar on February 02, 2019, 03:42:25 pmI don't see how that circuit is supposed to convert 5V PWM into 1.25V to 30V.

author: soldar
author_rank: Super Contributor
timestamp: February 02, 2019, 07:14:06 pm
content: Quote from: Zero999 on February 02, 2019, 05:50:07 pmYeah, sorry, just ignore it. It was a sketch of a half baked idea which I cannot complete. At least I have been playing around and learning a bit of LTSpice so something good came of it.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 08:20:57 pm
content: QuoteYou won't likely be able to do that anyway, with a mains-transformer based supply. If you add into account mains voltage variation, which is likely +-10% at most places, you have extremely small margin there, if any at all.So back to the drawing board anyway.

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 09:33:06 pm
content: Quote from: Yansi on February 02, 2019, 08:20:57 pmWith the LM317 on the output, the op-amp only has to swing from 0V to 27.5V to cover a 1.25V to 30V output range, so it could easily be powered from a regulated 31V power supply.A far bigger problem is the LM317's safe operating area protection kicking in when the output voltage is set low. A centre tapped transformer with a switch should be used minimise power dissipation.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 09:39:32 pm
content: Regulated dedicated 31V supply for opamp. Then add negative bias voltage so you can lower the current limit of the 317 realiably even to short circuit operation. Then regulated this or that or that there... you end up with something pretty hilarious, as most 317 or 723 based power supplies are. Overly complex (junk)!

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 09:49:37 pm
content: Quote from: Yansi on February 02, 2019, 09:39:32 pmYou get that anyway when designing a 0V to 30V PSU, whichever route you take.If you opt for the traditional Darlington pair method you're proposing, the op-amp's power supply voltage needs to be even higher, ruling out most common op-amps or you can add a buffer circuit, but that leads to extra complexity.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 09:59:37 pm
content: So why are you constantly arguing my solution is too complicated, if yours is becoming exactly the same?The discrete solutions would give quite more ways to implement things differently (or even better, if you want).

author: Zero999
author_rank: Super Contributor
timestamp: February 02, 2019, 10:21:48 pm
content: Quote from: Yansi on February 02, 2019, 09:59:37 pmThe LM317 does things such as safe operating area and thermal protection which are virtually impossible with a discrete design and is no more complex to implement. The only extra complexity associated with the LM317 is the requirement for a current sink to provide a minimum load, which is just a resistor, two diodes and a low power transistor. This is already less complex than the Darlington pair you're proposing, before any current limiting is added.Getting an op-amp with a sufficiently high voltage rating is a challenge whichever route you take, but the Darlington pair one is more difficult. The LM317 solution only needs the op-amp's output voltage to reach 1.25V less than the output voltage, whist the Darlington solution requires the op-amp's output to exceed the output voltage by at least 1.6V and most op-amps require a couple of volts headroom.

author: Yansi
author_rank: Super Contributor
timestamp: February 02, 2019, 10:26:43 pm
content: SOA protection using discrete components is just as easy to implement. What other thing than a current limit following a voltage drop across the pass element would you need? Discrete transistor audio amps solve this SOA protection on common basis.Thermal protection may become more tricky, depending on the circuit, but again, what more then just a thermal cutoff is needed? Havin a thermal cutoff fuse in the mains input is all what is needed to protect the supply. If it can't cool enough, then it is probably badly designed or would not work anyway (as some dumbass may have covered the heatsinks, etc).

author: Kalvin
author_rank: Super Contributor
timestamp: February 02, 2019, 10:41:02 pm
content: TI's LM395 "ultra reliable transistor" comes with current limiting, power limiting, and thermal overload protection.http://www.ti.com/product/LM395/descriptionIt is a complete IC turned into an NPN transistor with extra protection features.

author: soldar
author_rank: Super Contributor
timestamp: February 02, 2019, 11:09:36 pm
content: Couple of thoughts.The LM317 uses a resistor to set the output voltage. Could it be replaced by a FET which could be controlled by voltage?The LM317 uses a resistor to set the output voltage. It would be easier to use a different circuit which uses a voltage reference, like a zener, and then vary that reference voltage.

author: David Hess
author_rank: Super Contributor
timestamp: February 03, 2019, 05:23:49 am
content: Quote from: Kalvin on February 02, 2019, 10:41:02 pmThe LM395 is a great solution to add integrated protection but they cost almost 10 times more than LM317s.The LM317 is not ideal for reasons not discussed here yet, but it is a simple way to add current limiting, safe operating area protection, thermal protection, and buffering at a very low cost.

author: iMo
author_rank: Super Contributor
timestamp: February 03, 2019, 08:28:27 am
content: I think the OP has got enough hints on the topic he is interested in, he can elaborate and report the results. Let him work.

author: Zero999
author_rank: Super Contributor
timestamp: February 03, 2019, 07:29:53 pm
content: Quote from: Yansi on February 02, 2019, 10:26:43 pmAll right not impossible, but more complex than just using the LM317 in the first place!Quote from: David Hess on February 03, 2019, 05:23:49 amYes the LM395 is expensive!https://uk.farnell.com/texas-instruments/lm395t/power-transistor-to-220-3-395/dp/9488278?st=LM395Why do you think the LM317 is not ideal? The main problem I can think of is stability and the increased risk of oscillation.

author: David Hess
author_rank: Super Contributor
timestamp: February 04, 2019, 02:47:31 am
content: Quote from: Zero999 on February 03, 2019, 07:29:53 pmMeanwhile the TI LM317 from uk.farnell.com is about 1/7th the price. The ST LM317 is less.QuoteThe LM317 complicates the frequency compensation and the -1.25 volt bias requirement for a zero volt output is inconvenient.

author: Zero999
author_rank: Super Contributor
timestamp: February 04, 2019, 08:56:54 am
content: The LM395 also doesn't appear to be that straightforward to use. It still passes a quiescent current of up to 10mA, when VBE= 0! To get a true 0V out, a negative rail is required, but I suppose a current mirror circuit will get within 100mV or so.http://www.ti.com/lit/ds/symlink/lm395.pdf

author: tzc
author_rank: Newbie
timestamp: February 19, 2019, 01:09:28 am
content: Hi,If I connected this two ground together will it cause any problems to my circuit?kindly give some adviseThanks

author: Yansi
author_rank: Super Contributor
timestamp: February 19, 2019, 11:17:57 am
content: And how would it supposed to work, without both circuits having a common reference point?