PWM for LM317 - how to increase resolution? - Page 1
Forum section: electronics / beginners

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 25, 2018, 09:17:59 pm
content: I'm using PWM to get variable voltage from an LM317. I take an RC filter, buffer that with an op-amp, and feed that voltage into the adjust pin of the LM317.It works very well!However, for my application (battery charger), I need a narrow range - 3-4.4 volts.Can I offset the LM317 somehow so my PWM resolution affects only that range? ie. 0% would give around 3v, 100% would give 4.4v.

author: ogden
author_rank: Super Contributor
timestamp: August 25, 2018, 09:33:45 pm
content: Quote from: joeyjoejoe on August 25, 2018, 09:17:59 pmImagine two series resistors, let's say 1KOhm. One is connected to 5V, another to variable voltage source, let's say 0...5V. Voltage range of midpoint will be 2.5V to 5V.Got idea?

author: Cerebus
author_rank: Super Contributor
timestamp: August 25, 2018, 09:35:06 pm
content: That's just a classic summing Op Amp circuit. Derive your minimum voltage from somewhere (voltage divider, voltage reference, whatever) and use an op amp to add it to your smoothed PWM voltage, scaling the smoothed PWM signal to get the range you want. You'll find the basic circuit in any of the many compendiums of op amp circuits out there.If you're deriving the PWM from a processor you have the option of pick a inverting variant that subtracts your variable voltage from a fixed maximum and deal with the whole offset and scaling thing in software.

author: Zero999
author_rank: Super Contributor
timestamp: August 25, 2018, 10:49:14 pm
content: Just add a series resistor between the output of the op-amp and the adjust pin of the LM317. The voltage drop across the resistor is constant and proportional to the current flowing through the resistor connected between the output and adjust pins.If you post a schematic it will be easier to show you how.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 26, 2018, 01:31:15 pm
content: Quote from: Cerebus on August 25, 2018, 09:35:06 pmSo if I set my minimum voltage to 3V, I would then have my PWM scale between 0 and 1.5V, giving me an effective range of 3-4.5v, but giving me a resolution of around 5mV (1500mV/255 steps) in that range I care about. I'll take a look

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 26, 2018, 01:34:35 pm
content: Quote from: ogden on August 25, 2018, 09:33:45 pmI had thought a bit about that, but was unsure if that would actually increase the resolution, or just offset the voltage so that PWM from, let's say, 0-40% would be useless and clamped at 3V.

author: Cerebus
author_rank: Super Contributor
timestamp: August 26, 2018, 05:24:44 pm
content: Quote from: joeyjoejoe on August 26, 2018, 01:31:15 pmKeep your life simple, choose whatever is convenient for your PWM maximum (3V3 or 5V according to your logic voltage) and scale it with the gain of the summing op amp (so, a gain of 1.5/5 = 0.3 for a 1.5V range and 5V logic voltage).It's always a good idea to design such a system with a little excess at both ends of your output range - fix it so that say a 5% duty cycle gives you your minimum nominal output and 95% duty cycle your maximum nominal output. That gives you a little bit of wiggle room for calibration and avoids awkwardly short pulses that tend to squeeze past simple filtering/smoothing (i.e. your stopband isn't ever going to be as low or as flat as you hope).

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 28, 2018, 12:04:37 am
content: I've attached my existing schematic.I'm not sure what kind of summing amp I want - non-inverting, or inverting? Can I still scale my PWM output with a non-inverting summing amplifier?

author: Zero999
author_rank: Super Contributor
timestamp: August 28, 2018, 08:19:27 am
content: Quote from: joeyjoejoe on August 28, 2018, 12:04:37 amThere's no need for a summing amplifier.That schematic won't work. The ADJ pin of the LM317 is connected to 0V, so it will just output 0V all the time. I think the GND symbol on the ADJ pin is a mistake and is unintentional.I hope you're aware that the LM317 needs to have a current of at least 5mA through the output, pin 2, to regulate properly. This might not be a problem in this case, if charging the battery with a small current continuously won't do any damage.Scale the PWM to 1.5V with a potential divider. Add another resistor across C1, call it R2, so it forms a potential divider with R1, who's vale may need to be changed. The value of R in the RC circuit will then be equal to the values of R1 and R2 in parallel. Using the potential divider calculator tool, linked below, I get 5k6 for R1 and 2k4 for R2, assuming the voltage from the IO pin is 5V and you want 1.5V.http://sim.okawa-denshi.jp/en/rercal.phpI don't think the LM358 is helping things. If anything it will make life more difficult, since when its output is near 0V and its sinking a decent amount of current, it will have a higher output impedance than the microcontroller. Use an op-amp, such as the MCP6021, which can sink a decent current with a low output voltage.Add a resistor between pins 1 and 2 of the LM317 and another resistor in series with the ADJ pin and the signal source, forming a voltage regulator with an output voltage of 3V. Use 130R for the resistor between pins 1 and 2 and 180R for the one in series with the ADJ pin.

author: Zero999
author_rank: Super Contributor
timestamp: August 28, 2018, 01:18:03 pm
content: How about this circuit?With a standard voltage regulator circuit:VOUT= VREF(1+R2/R1)In this circuit, R2 is composed of R1 & R2 which are in parallel, which makes R = (R1*R2)/(R1+R2) = (5.6*2.4)/(5.6+2.4) = 1k68.When the PWM voltage is low:VOUT= 1.25*(1+1680/1200) = 3V.When the PWM voltage is high, it's little more tricky but still not hard. The voltage on the lower end of the potential divider is equal to:V = VPWM*R2/(R1+R2) = 5*2.4/(5.6+2.4) 1.5V.This will be in series with 1k68.The output voltage will simply be 1.5V + 3V = 4.5V.Note that in real life the output voltage will be slightly higher than that. The LM317 has a small bias current flowing out of the ADJ terminal, which is about 50μA and will add 0.00005*1680 = 84mV on to the output voltage, so you'll get 3.084V to 4.5084V, but it's so tiny, the tolerances the LM317, the 5V rail and resistor will dominate. You might want to change the potential divider to give 1.8V and go for 2.8V to 4.6V out, to account for component tolerances.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 28, 2018, 02:58:38 pm
content: Regarding the LM317, I did put a 400ohm resistor on the output for now for testing purposes so I have a minimum load - gives ~12mA load. The regulator seems to be working well with just the buffered PWM input.I'm going to apply some of your ideas for scaling and see how that works out - I will try it with the LM358 as a buffer for fun, but I am wondering if I could ditch it all-together.Definitely appreciate this feedback, I will give it a shot tonight!

author: Zero999
author_rank: Super Contributor
timestamp: August 28, 2018, 04:09:04 pm
content: Quote from: joeyjoejoe on August 28, 2018, 02:58:38 pmThe previous circuit I posted will not work with the LM358. It is designed to work without any buffering and relies on the impedance of the potential divider to form the lower resistor to set the minimum output voltage for the LM317.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 28, 2018, 04:12:41 pm
content: Noted, thanks!With this scaling, might even get away with 8-bit PWM, as that will give me about 6mV (1.5v/255) per step. Plenty of resolution!

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 28, 2018, 08:35:53 pm
content: Wow, totally works! Thanks so much for all your help, this gives me plenty of resolution to work with.Next, ADC's, reference voltage, current sense shunt...

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 30, 2018, 12:31:48 am
content: So update on this, it's working GREAT! With some smoothing I'm really able to control this thing - it takes about 80% duty cycle to hit 4.20v, although some cells are 4.3 or 4.35v so I might tweak it slightly. For now, good enough!I've cooked up another thread on getting a 5V reference going so I can continue the project! Thanks again for your help on this.. I still need to keep re-reading what you've put down to get it figured out

author: Zero999
author_rank: Super Contributor
timestamp: August 30, 2018, 09:15:11 pm
content: Do you actually understand how this works though?Would you know how to select the resistor values for different voltages?If you're interested I can show you, but it will have to wait until the weekend, unless someone beats me to it.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: August 30, 2018, 11:18:14 pm
content: So I used your math/logic to recalculate the values for a 1.2V range of 3.4-4.6 volts to increase the resolution to something near the resolution of the 10 bit ADC. However, I'm not totally clear on how you came up with the schematic.I am at a wedding all weekend myself, so Sunday I should be able to spend some more time on it. Any keywords I can search for on YouTube to learn would be good, but half is probably understanding the LM317? R1/R2 form a voltage divider which I can try to read up up, but R3 is a mystery to me.I guess I'm not totally sure on what part of the schematic is "compressing" the PWM to 1.5V.

author: Zero999
author_rank: Super Contributor
timestamp: September 02, 2018, 05:59:50 pm
content: The LM317 is really an op-amp, a voltage reference and a large Darlington pair transistor. The 0V of the op-amp is connected to the regulator's output, which is why it needs a certain minimum load current to work properly: without it, the op-amp won't have enough power. The inverting input is connected to the output and the non-inverting input to the adjust pin via a 1.25V band gap voltage reference, which is biased by a 50µA current source connected to the input pin. The tiny 50µA bias current can be ignored for most applications, because it's small, compared to the current flow in the resistors.The op-amp adjusts its output voltage to alter the current flowing through the Dartington pair, to try to keep the voltages at both of its inputs the same. Because, the voltage reference holds the voltage on the non-inverting input at 1.25V above the voltage on the adjust pin, causing the op-amp to set the output to 1.25V above the adjust pin, forcing the adjust pin to different voltages will also change the output, which will sit at 1.25V above the adjust pin. For example, if the adjust pin is tied to 0V, the output will be 1.25V, if it's tied to 1V, it will output 2.25V.In an ordinary LM317 circuit, there are two resistors: R1 and R2. Because R1 is across the output and adjust pins and the LM317 keeps the voltage across it at 1.25V, the current through R1 will also be constant, because it has a fixed voltage across it. One off the applications of the LM317 is a constant current source, which relies on this fact: the circuit can be found using a search engine. R2 is also in series with R1, so any current flowing through R1, also flows through R2. Suppose R1 is 125Ohms, the current through it will be equal to VREF/R = 1.25/125 = 10mA. If R2 = 125R, the voltage across it will also be 1.25V and the output voltage will be 1.25 higher, giving a total output voltage of 2.5V, if R2 = 500R, then the voltage across it = 500*0.01 = 5, so the voltage on the output will be 5+1.25 = 6.25V.The formulae are listed below.VREF= 1.25VIR1= R1/VREF= R1/1.25IR2= IR1VR2= R2*IR2VOUT= VR1+VR2Put the above equations together and the formula for the calculating the ouptut voltage in the standard LM317 circuit can be derived.Now we need to look at how the other circuit converts the PWM signal to 0V to 1.5V, then later we'll examine how the two circuits fit together.A potential divider can be modelled as a voltage source, with a series resistance equal to both of the resistors connected in parallel.VIN= 5VR1 = 5k6R2 = 2k4VOUT= VIN*R2/(R1+R2) = 5*2.4/(5.6+2.4) = 1.5VROUT= (R1*R2)/(R1+R2) = (5.6k*2.4k)/(5.6k+2.4k) = 1.68kPutting this back into the other circuit, assuming the PWM duty cycle is 0% so zero volts.The output voltage, can be calculated using the standard LM317 formula:VOUT= 1.25*(1+1680/1200) = 3VWhen the PWM is at 100% of 5V, the potential divider will appear as 1.5V, again in series with 1.5V, so the output voltage simply increases by 1.5V to 4.5VI hope you can see that the PWM is still filtered by the capacitor, but the R in the circuit is now 1k68, rather than 1k, so now the potential divider works like a 1k68 resistor in series with a variable 0 to 1.5V voltage source, connected to the adjust pin of the LM317.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 03, 2018, 03:15:07 pm
content: Ahhh, that first picture for the voltage divider blew my mind a bit, so now it is more clear what you were referring to!Thanks so much!So the values I've come up with is R3 = 933ohm, and R1 = 7.6k, which should change this to work from 3.5v to 4.7v. Perhaps you can double check the math?Just watched a very cool EEVBlog video this weekend on Capacitance Multiplier, and one of the use-cases was for smoothing PWM values! I'll check the ripple on my PWM to see if that's something I need to look at, although he mentioned in his video a bit about RC causing too big a voltage drop for a large R value, but since all I'm doing is adjusting the LM317, which is 50-100uA, I'm probably ok with a simple but large RC filter...

author: exe
author_rank: Unknown
timestamp: September 03, 2018, 04:09:40 pm
content: Quote from: joeyjoejoe on September 03, 2018, 03:15:07 pmI don't think it is suitable here. Emitter follower (that's what capacitor multiplier really is) without negative feedback is prone to, e.g., temperature drift because of BJT. You wanted to increase accuracy and resolution, but you will loose both. Just breadboard it to see the problem.Capacitor multiplier is more like a pre-filter when you need to remove high freq harmonics (which a normal LDO cannot do) and don't care about DC accuracy.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 03, 2018, 04:55:09 pm
content: Gotcha. I did some measurements, and with my mediocre power supply (Gophert 3205 mk2) I am getting about 60mV peak to peak from the regulator. I think most of that is probably from my PSU itself!Should be acceptable for the charger.

author: exe
author_rank: Unknown
timestamp: September 03, 2018, 05:21:59 pm
content: > I think most of that is probably from my PSU itselfThat's easy to check: just measure noise before and after regulator. I'd also measure ripple after PWM filter just to be sure filter is working.

author: Zero999
author_rank: Super Contributor
timestamp: September 03, 2018, 10:27:00 pm
content: Quote from: joeyjoejoe on September 03, 2018, 03:15:07 pmWhat value did you calculate for R2?Also note that those are non-standard resistor values. It makes it easier to stick with standardE24 or E96 preferred numbers. There are some online tools which make finding optimum combinations for any ratio easy, but they're mostly designed for potential dividers so applying them to this circuit sin't self explanatory. When I get time, I'll show you how.Quoteyess, as mentioned previously, it's not relevant to this circuit because it has an emitter follower.The best way to reduce ripple with this circuit, is to use two RC filter stages. The simplest to calculate is to split R1 into two resistors and connect another capacitor to 0V. For example, using the values in my circuit, the 5k6 resistor could be replaced with 1k3 and 4k3 in series, with another 100μF capacitor to 0V. I don't have time to post a schematic at the moment, but will do later, if this isn't clear.

author: ogden
author_rank: Super Contributor
timestamp: September 04, 2018, 09:05:33 am
content: Quote from: Hero999 on September 03, 2018, 10:27:00 pmCould you please tell what you use to draw neat circuit snippets like this?

author: Seekonk
author_rank: Super Contributor
timestamp: September 04, 2018, 02:34:18 pm
content: If you want to save some heat, the same thing can be done with a buck converter. My whole solar system, several KW, are controlled this way with off the shelf cheap buck converters. You set the converter at the maximum voltage you would like to see and feed additional voltage into the feedback pin. The voltage has to be monitored as there is no direct relation to D/A counts and volts.

author: Zero999
author_rank: Super Contributor
timestamp: September 04, 2018, 10:04:56 pm
content: ogden,I did the original LM317 schematic many years ago, when I was at school, using a child's simulation program called Crocodile Clips, which didn't even have an LM317, so I added it in MS Paint. I did the recent modifications for the PWM, using KolourPaint. The potential divider schematics were either done using the copy and pasted symbols from the other schematics, in KolourPaint or MS Paint, depending on whether I was using a Linux or Windows PC at the time and I can't remember which. Nowadays I do most of my schematics with LTSpice, but I occasionally still use MS/KolourPaintSeekonk,Yes a buck converter is a good idea. The switch could also be directly controlled by the MCU, but I agree, it's better to use a proper SMPS IC.joeyjoejoe,Are you still interested? If so, I'll add the information about using the online calculator to get standard values and more on PWM filtering, although I don't think ripple is a big problem for a battery charger.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 04, 2018, 11:08:01 pm
content: Hey Hero! I'm all good - I think the ripple I have is no issue for a battery charger.So for R2, I kept the same value. So I haveR1 = 7k6R2 = 2k4R3 = 933ohmI was just gonna find something close enough as it doesn't have to be bang on.

author: Zero999
author_rank: Super Contributor
timestamp: September 05, 2018, 08:59:55 am
content: All right, so you want 3.5v to 4.7V from 0V to 5V.The potential divider needs to scale 5V to 4.7V-3.5V = 1.2VVOUT= VIN*R2/(R1+R2) = 5*2400/(7600+2400) = 1.2VGood, you've got that bit right. Now let's look at the LM317. The voltage needs to be set to 3.5V.VOUT= VREF*(1+R2/R1)R1 is the value of R3 in the new circuit, which is 933OhmAnd R2 is equal to the value of R1 and R2 in parallel in the new circuit.R2 = (7600*2400)/(7600+2400) = 1824VOUT= 1.25*(1+1824/933) = 3.69VThat's quite a bit off. Let's look at how to calculate R1 in the original LM317 circuit.VOUT= VREF*(1+R2/R1)Rearrange to make R1 the subject:R1 = R2* VREF/(VOUT- VREF)R1 = 1824*1.25/(3.5-1.25) = 1013.33Back to the new circuit:R1 = 7.6kR2 = 2.4kR3 = 1.01333kNow we have the ratio of the three resistor values, we can now look at choosing standard E24 or E96 values to match them. For that we can use an on-line calculator. Unfortunately the calculators, I could find are designed for three values are aimed at potential dividers, but they can still be used for this circuit, with a little arithmetic.Imagine all the resistors are connected up in series: It would also make a potential divider.The total value would be:RTOTAL= 7.6k+2.4k+1.01333k = 11.01333kNow if we applied 11.01333V to the potential divider.The voltage across each resistor would be equal to its value in kOhms so:V1 = 11.01333VV3 = 1.01333VV2 = 2.4+1.01333 = 3.41333VHere's where the calculator website comes in. If the above voltages are entered into the three resistor potential divider section, it will generate the nearest combination of standard resistor values which will give us as close to the desired resistor ratio as possible.http://sim.okawa-denshi.jp/en/teikokeisan.htmFor E24 values it gives:R1=5.1kΩR2=1.6kΩR3=680ΩWhich is probably near enough.E96 values gives:R1=3.09kΩR2=976ΩR3=412ΩWhich is quite likely more precise than the LM317 so is a bit overkill.Here's another potential divider tool which only works with two resistors, but can be handy for determining the ratio of R1 and R1: see the results in the "ideal values" section.https://www.random-science-tools.com/electronics/divider.htmExercise for the reader: put the above values back into the original formulas and see how they match to the desired values.

author: Zero999
author_rank: Super Contributor
timestamp: September 05, 2018, 01:12:20 pm
content: Here's a spreadsheet which calculates the values of R1, R2 and R3.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 05, 2018, 08:46:37 pm
content: I might need some guidance on filtering.I'm not sure what I was doing before, but now I'm getting 200mV ripple. The issue is this is throwing off the ADC in reading the voltage output of the regulator. I'm going to take a look at your earlier post and split up R1 and see if that gets things under control.

author: iMo
author_rank: Super Contributor
timestamp: September 05, 2018, 09:35:05 pm
content: I think you will get large ripple as the resistors and capacitors are rather small values. You would need high PWM freq to get ripple small.I would go with an opamp ie the LM358 as the buffer (or put the LM317 inside the opamp loop). The PWM filter could be then with large R and C --> small ripple even with low freq PWM..

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 05, 2018, 09:38:17 pm
content: Quote from: imo on September 05, 2018, 09:35:05 pmSo I briefly looked at higher PWM freq. I'm using a 32u4, so it has a 16 bit timer which might help. In doing so temporarily bricked it, so I'm working on getting it back nowEDIT : Back in business. I got PWM going as well. 10-bit gives me great resolution at 2kHz. 9-bit a bit less at 4kHz.If I'm doing this right, at 2kHz, I can get a decent filter with 2k and 47u.I think the time constant would be good enough for a battery charger.In any case, I think I have some work to do with filter both the output as well as potentially my bench supply. Time for more reading!

author: Zero999
author_rank: Super Contributor
timestamp: September 06, 2018, 07:59:54 pm
content: Quote from: joeyjoejoe on September 05, 2018, 09:38:17 pmWhere are you thinking of putting the 2k resistor?Any resistance in series with the PWM input will change the potential divider scaling factor.Don't forget that the output impedance of a potential divider is equal to the value of the two resistors in parallel, so R in your RC circuit should be the values of R1 and R2 in parallel. For example, if R1 = 5k6 and R2 = 2k4, then R for the purpose of your RC circuit is:R = (R1*R2)/(R1+R2) = (5.6k*2.4k)/(5.6k+2.4k) = 1.68k.If the capacitor value is 100μF, then the RC constant is:τ = RC = 1680*100×10-6= 168×10-3= 168ms

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 06, 2018, 08:26:23 pm
content: I was thinking of doing an RC filter on the final output stage of the regulator. I'm now second guessing this...

author: Zero999
author_rank: Super Contributor
timestamp: September 07, 2018, 07:38:18 am
content: Quote from: joeyjoejoe on September 06, 2018, 08:26:23 pmOn the output? No that's a bad idea. It will increase the output impedance of the regulator, which will severely restrict the output current.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 07, 2018, 04:43:32 pm
content: Okay. I should have done this sooner, a picture is worth a thousand wordsHere's what I'm trying to smooth out. Note PWM freq is 2kHz.Yellow is the pure PWM output.Blue is between R1 and R2.Purple is the output of the LM317.

author: mikerj
author_rank: Super Contributor
timestamp: September 07, 2018, 05:32:52 pm
content: This is one of those cases where you'd be far better off filtering the PWM and then buffering it, since you need to drive into a low impedance. This also means you can use a multi-pole filter to provide low ripple without making the response very sluggish.Another point here is that the LM317T has a minimum load current to meet the datasheet regulation performance. Normally this is achieved by making R3 a low value, 120 or 240 ohms is common (120 ohms is needed to meet worst case 10mA spec.). With 1k2 as shown in the diagrams here, the minimum load will not be met if nothing else is connected to the regulator output.That said the scope shows some very sharp edges on the output ripple. If you were seeing residual ripple on the adjust pin then you would expect to see a sawtooth waveform here, so it's quite likely you are seeing some of the PWM signal being superimposed on the output. This will happen if you don't have a really good, low impedance ground connection to connect the regulator circuit back to the PWM source.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 07, 2018, 05:53:47 pm
content: I do have a 410ohm resistor as a dummy load going to ground.I originally had a buffer, but I believe Hero thought it would work better without, or that maybe I would need a different op-amp then the 358.

author: Zero999
author_rank: Super Contributor
timestamp: September 07, 2018, 09:03:24 pm
content: I don't see who this ripple is a problem for a battery charger. If you connect a battery to the output, you'll find it will be attenuated hugely.Yes, a buffer is unnecessary, if the circuit can be designed with the impedance of the potential divider in mind. The problem with adding a buffer is it needs to be able to pull the LM317 all the way down to 0V, which the LM358 can't do. An alternative is to use an op-amp which can sink a reasonable amount of current, such as the MCP6021.What values are you using for R1, R2 and R3 now?It's possible to put another RC circuit before the potential divider, but its impedance needs to be taken into account. For example, in first circuit I posted R1 = 5k6, R2 = 2k4 and R3 = 1k2, R1 can be split into two resistors, of 2k and 3k6, which total 5k6 and a capacitor added to 0V. The scaling factor of the potential divider is not altered, but the output will be smoother, since it has another stage of filtering.

author: joeyjoejoe
author_rank: Frequent Contributor
timestamp: September 08, 2018, 01:35:48 am
content: Okay, things are looking aweeeesome!Blue is ADJUST. Magenta is the output voltage.I wanted to make sure I cleaned up what I could without any major load, as I spent a few hours tinkering with code to realize it was likely the ADC picking up noise. Now I can rule that out.At 0% PWM, I'm seeing ~3.55v, and 100%, ~4.7VI think the noise floor of my desk is 200mV though. So I won't get too hung up on that for nowPlus a bread board won't help. I can run V1 of a PCB with some test points to see how much tighter I can get things.

author: Zero999
author_rank: Super Contributor
timestamp: September 08, 2018, 01:56:32 pm
content: Good, I'm glad you got the two stage RC filtering working.An alternative is to put the additional RC circuit after the potential divider and adjust the other resistor in the LM317 circuit to compensate. It does make the calculations more difficult and isn't any better, but I thought I'd show it for completeness.

author: StillTrying
author_rank: Super Contributor
timestamp: September 08, 2018, 02:07:11 pm
content: You could switch CH2 and CH3 to AC coupling and increase the sensitivity to get a better look at the ripple.I get the p-p ripple to be under 5mVpp with just the one 100uF filter.

author: iMo
author_rank: Super Contributor
timestamp: September 08, 2018, 04:52:57 pm
content: May be a bit off topic, but I could not resist to try with an LM358 + LM317:With 500us PWM period:Code:Duty Vout---------------------------50us 1.5023V100us 3.0001V150us 4.5002V250us 7.497V400us 11.996V499us 14.964V

author: Zero999
author_rank: Super Contributor
timestamp: September 08, 2018, 11:13:12 pm
content: Quote from: imo on September 08, 2018, 04:52:57 pmThat's a perfectly good circuit, but yes it is a little off topic. It has gain, whilst the original poster wanted some loss, i.e. a narrower range of output, than input voltages. A transfer function of VOUT= VIN/4.166+3.5.It is doable with an op-amp and even a transistor, rather than the LM317, if the short circuit and thermal protection aren't needed.Here's an alternative solution.I used the formulae on this site to help to design the circuit.http://earmark.net/gesr/opamp/gain_offset.htmHere's the section applicable:http://earmark.net/gesr/opamp/case7.htmUnfortunately the calculator isn't very good at picking out the optimum values or just giving the ratio, as the value for R1 has to be selected manually, so I copied the formula into a spreadsheet and used the solve function to generate the exact ratio of R1, R2 and R3, yes I could have spent ages revising how to do this the old way, but I'm lazy. I then put the ratio into the potential divider calculator, linked to earlier, which gave the optimum E24 values.The plain old LM358 can be used for the op-amp. If more than a couple of hundred mA is required, then both channels of the op-amp can be connected inparallelto give more base drive to Q1. For even higher currents, Q1 will need to be a Darlington or Sziklai pair.