Author Topic: PWM for LM317 - how to increase resolution?  (Read 10527 times)

0 Members and 1 Guest are viewing this topic.

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
PWM for LM317 - how to increase resolution?
« on: August 25, 2018, 09:17:59 pm »
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.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: PWM for LM317 - how to increase resolution?
« Reply #1 on: August 25, 2018, 09:33:45 pm »
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.

Imagine 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?
 

Offline Cerebus

  • Super Contributor
  • ***
  • Posts: 10576
  • Country: gb
Re: PWM for LM317 - how to increase resolution?
« Reply #2 on: August 25, 2018, 09:35:06 pm »
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.
Anybody got a syringe I can use to squeeze the magic smoke back into this?
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #3 on: August 25, 2018, 10:49:14 pm »
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.
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #4 on: August 26, 2018, 01:31:15 pm »
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.

So 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 :)
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #5 on: August 26, 2018, 01:34:35 pm »
Imagine 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?

I 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.
 

Offline Cerebus

  • Super Contributor
  • ***
  • Posts: 10576
  • Country: gb
Re: PWM for LM317 - how to increase resolution?
« Reply #6 on: August 26, 2018, 05:24:44 pm »
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.

So 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 :)

Keep 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).
Anybody got a syringe I can use to squeeze the magic smoke back into this?
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #7 on: August 28, 2018, 12:04:37 am »
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?



 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #8 on: August 28, 2018, 08:19:27 am »
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?


There'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.php

I 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.
« Last Edit: August 28, 2018, 08:35:30 am by Hero999 »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #9 on: August 28, 2018, 01:18:03 pm »
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.
« Last Edit: August 28, 2018, 01:45:55 pm by Hero999 »
 
The following users thanked this post: joeyjoejoe

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #10 on: August 28, 2018, 02:58:38 pm »
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!  :)
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #11 on: August 28, 2018, 04:09:04 pm »
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!  :)
The 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.
 
The following users thanked this post: joeyjoejoe

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #12 on: August 28, 2018, 04:12:41 pm »
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!
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #13 on: August 28, 2018, 08:35:53 pm »
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...
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #14 on: August 30, 2018, 12:31:48 am »
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 :)
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #15 on: August 30, 2018, 09:15:11 pm »
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.
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #16 on: August 30, 2018, 11:18:14 pm »
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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #17 on: September 02, 2018, 05:59:50 pm »
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.25V
IR1 = R1/VREF = R1/1.25

IR2 = IR1
VR2 = R2*IR2

VOUT = VR1+VR2

Put 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 = 5V
R1 = 5k6
R2 = 2k4
VOUT = VIN*R2/(R1+R2) =  5*2.4/(5.6+2.4) = 1.5V
ROUT = (R1*R2)/(R1+R2) = (5.6k*2.4k)/(5.6k+2.4k) = 1.68k

Putting 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) = 3V

When 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.5V



I 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.
« Last Edit: September 02, 2018, 06:29:18 pm by Hero999 »
 
The following users thanked this post: fossil

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #18 on: September 03, 2018, 03:15:07 pm »
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...
 

Offline exe

  • Supporter
  • ****
  • Posts: 2647
  • Country: nl
  • self-educated hobbyist
Re: PWM for LM317 - how to increase resolution?
« Reply #19 on: September 03, 2018, 04:09:40 pm »
Just watched a very cool EEVBlog video this weekend on Capacitance Multiplier, and one of the use-cases was for smoothing PWM values!

I 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.
 

Offline joeyjoejoeTopic starter

  • Frequent Contributor
  • **
  • Posts: 285
  • Country: ca
Re: PWM for LM317 - how to increase resolution?
« Reply #20 on: September 03, 2018, 04:55:09 pm »
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.
 

Offline exe

  • Supporter
  • ****
  • Posts: 2647
  • Country: nl
  • self-educated hobbyist
Re: PWM for LM317 - how to increase resolution?
« Reply #21 on: September 03, 2018, 05:21:59 pm »
> I think most of that is probably from my PSU itself

That'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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 20357
  • Country: gb
  • 0999
Re: PWM for LM317 - how to increase resolution?
« Reply #22 on: September 03, 2018, 10:27:00 pm »
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?
What value did you calculate for R2?

Also note that those are non-standard resistor values. It makes it easier to stick with standard E24 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.

Quote
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...
yess, 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.

 
The following users thanked this post: exe, joeyjoejoe

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: PWM for LM317 - how to increase resolution?
« Reply #23 on: September 04, 2018, 09:05:33 am »
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.



Could you please tell what you use to draw neat circuit snippets like this?
 

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1966
  • Country: us
Re: PWM for LM317 - how to increase resolution?
« Reply #24 on: September 04, 2018, 02:34:18 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf