PWM help

Thread Starter

JosXD

Joined Mar 16, 2022
69
Hi,

I'm wondering if I can control a buck converter with a pwm signal and a low pass filter rc attached to the feedback pin of the converter,

can someone tell me is this info about PWM is trustable? https://www.parallax.com/go/PBASICHelp/Content/LanguageTopics/Commands/PWM.htm

The info it kinda confuse me in first instance talks about a high output equals to 5V I imagine it is a micro controller with a power supply of 5V, then it says if you could switch on and off rapidly, half time on and half time off should give 2.5V and last it calculates the average voltage at 100% duty cycle = 1.953V, but 100% is not equals to high ouput pin(5V)?

And for example let's say I have a micro controller with an 8-bit for PWM porpuses, that means we can adjust the brightness of a led in 256 steps from 0 to 255, does each of that step provides a different voltage level?
 

k1ng 1337

Joined Sep 11, 2020
1,038
You are confusing "Duty Cycle" with what they are calling "Duty" which is just a name they gave a variable. It is the 8 bit value assigned to the PWM output.

if Duty is 0, (0 ÷ 256) x 5 V = 0 V
if Duty is 100, (100 ÷ 256) x 5 V = 1.953 V
if Duty is 256, (256 ÷ 256) x 5 V = 5 V

Divide the current voltage by the total voltage to find the Duty Cycle.

1.953V / 5V * 100 = 39% Duty Cycle

100 / 256 * 100 = 39% Duty Cycle
 
Last edited:

k1ng 1337

Joined Sep 11, 2020
1,038
Hi,

I'm wondering if I can control a buck converter with a pwm signal and a low pass filter rc attached to the feedback pin of the converter,

can someone tell me is this info about PWM is trustable? https://www.parallax.com/go/PBASICHelp/Content/LanguageTopics/Commands/PWM.htm

The info it kinda confuse me in first instance talks about a high output equals to 5V I imagine it is a micro controller with a power supply of 5V, then it says if you could switch on and off rapidly, half time on and half time off should give 2.5V and last it calculates the average voltage at 100% duty cycle = 1.953V, but 100% is not equals to high ouput pin(5V)?

And for example let's say I have a micro controller with an 8-bit for PWM porpuses, that means we can adjust the brightness of a led in 256 steps from 0 to 255, does each of that step provides a different voltage level?
Correct, this is called quantization. 8 bits represent 256 possible values (0 to 255). You take your reference voltage and divide by however many quantization units are available. If your reference voltage is 5V, the smallest increment you can make (or measure) is 5V / 256 = 0.02V.

If your reference voltage is 1V, the smallest increment is 1V / 256 = 0.004V

The smaller the reference voltage, the more precise the measurement becomes but the maximum voltage that can be measured is reduced in the same proportion (unless you use a voltage divider). If you try to measure 2V with a 1V reference voltage, the output will be 256 (not 512) because no more quantization units are available. The microcontroller can't tell the difference between 1V and 2V because the scale was set to 1V max via the voltage reference.
 
Last edited:

Irving

Joined Jan 30, 2016
5,122
And for example let's say I have a micro controller with an 8-bit for PWM porpuses, that means we can adjust the brightness of a led in 256 steps from 0 to 255, does each of that step provides a different voltage level?
Well yes & no...

When you output a PWM signal into a low pass filter (LPF) you get a voltage proportional to the duty cycle. But driving an LED from a PWM output is different. The LED always sees 5v during the ON time but the perceived brightness is the ratio of ON to OFF. Assuming the PWM frequency is faster than your persistence of vision (typically > 70Hz) your eye becomes the LPF and you see a smooth transition from off to full brightness as the duty cycle goes from 0% -> 100%.
 

Thread Starter

JosXD

Joined Mar 16, 2022
69
K1ing 1337: Oh I had not idea that duty and duty cycle were different, so the duty is like the amount of steps, and with Voltage Reference you mean the Voltage of the power supply feeding the micro controller?

Irving: Why the voltage is proportional to the duty cycle and not 5V? it is because the time the signal is on just charges the capacitor to a certain voltage?

Crutschow: I want to drive high power leds like a XHP50.2 which can take 6amps from factory specs, but yes you could overdrive to 10 amps.

buck.png
Guys in the squematic the formula to setup the ouput voltage for this buck converter is 0.6*(1+R1/R2), with those resistors values the output voltage is about 3.6V, If I output an almost steady voltage from the pwm pin and a rc filter, the voltage at FB prin will increase and the converter will try to down the output voltage to meet the 0.6v fb reference right?

When using RC filters I have seen some examples where use a graphic that shows a curve from off to the desired voltage but with spikes, I think they call it ripple voltage, as I don't speak english natively is kinda tricky to understand, with ripple it means something like an offset or variation from the desired target voltage? like sometimes in a given time it will be the desired voltage and sometimes it will be a little more or less?
 

crutschow

Joined Mar 14, 2008
38,508
Here's a way to calculate the resistor values without having to solve any simultaneous equations:
Start at the output half-voltage point, where the average PWM voltage equals the FB voltage of 600mV (12% duty-cycle for a 5V PWM).
Since, at that point, there's no current going through R3, you can ignore it and calculate the values of R1 and R2 to give the desired (arbitrary) 1/2 full-scale output voltage.
Then you set the average PWM voltage to 0V (0% duty-cycle) which effectively puts R3 in parallel with R2 to ground, and calculate the value of R3 to give the desired full-scale output voltage.
These resistor values also then mean that an average PWM voltage of double the FB voltage (1.2V or 24% 5V duty-cycle) will generate 0V at the converter output.

Note that the output voltage changes inversely to the PWM control voltage.
 
Last edited:

Thread Starter

JosXD

Joined Mar 16, 2022
69
Crutschow: you mean something like half the desired voltage output, the desired output is 3.6v so half is 1.8v, R1 as 200k and R2 as 100k gives 1.8V output voltage.

When you said average PWM voltage equals FB voltage you mean that doesn't add or substract right like off 0v?

Here is where I start to being slow, 'cuz I don't know much about electronics, in my mind average PWM voltage should be 1.65v half the voltage of the micro controller suply 3.3v.

Okay that part of the double FB voltage from the average PWM I get what you say, if I raise PWM voltage, output voltage will decrease.

If I use R3 as 67K in parallel with R2 100k it gives ~40k equivalent resistor, so with 1.8V now we have 0.3v in feedback pin now converter will start to raise output voltage to match the 0.6v, so let's calculate this resistors with the desired voltage 3.6v/240k = 15uA, let's take R2 and R3 as one resistor of 40k*15uA = 0.6V.
 
Last edited:

crutschow

Joined Mar 14, 2008
38,508
you mean something like half the desired voltage output, the desired output is 3.6v so half is 1.8v, R1 as 200k and R2 as 100k gives 1.8V output voltage.
Yes.
When you said average PWM voltage equals FB voltage you mean that doesn't add or substract right like off 0v?
No, as 0V would subtract current from the FB node through R3.
I mean the average PWM voltage is 0.6V (18.1% duty-cycle for a 3.3V PWM signal).
At that PWM voltage there's no voltage across R3 and thus no current, so R3 can be ignored.
If I use R3 as 67K in parallel with R2 100k it gives ~40k equivalent resistor, so with 1.8V now we have 0.3v in feedback pin now converter will start to raise output voltage to match the 0.6v, so let's calculate this resistors with the desired voltage 3.6v/240k = 15uA, let's take R2 and R3 as one resistor of 40k*15uA = 0.6V.
Yes, so a 66.5k, 1% resistor would be good for R3.
 

Thread Starter

JosXD

Joined Mar 16, 2022
69
Yes.
No, as 0V would subtract current from the FB node through R3.
I mean the average PWM voltage is 0.6V (18.1% duty-cycle for a 3.3V PWM signal).
At that PWM voltage there's no voltage across R3 and thus no current, so R3 can be ignored.
Yes, so a 66.5k, 1% resistor would be good for R3.
Okay now it's time for the capacitor value I used this website to calculate the RC low padd filter desing for PWM http://sim.okawa-denshi.jp/en/PWMtool.php,

First If I use a 12 bit resolution it means there is 4096 steps in the range from 0v to 3.3v, but we only need max 1.2v so 3.3v/4096 = 0.0008v each step, 1.2v/0.0008v = 1500 steps but more like ~1489 steps if we use all the number of the division.

In the RC filter for PWM calculator I put the 66.5k ohms resistor and a 0.5uF capacitor and a PWM of 10Khz, there was a field that asked for PWM voltage low and voltage high, in voltage high it was 3.3v right and not 1.2v?
capacitor.png

With those values of RC, it gives a voltage ripple peak to peak of 0.00248v which is bigger than the 0.0008v steps and it takes about 0.2 seconds to reach the desired voltage.

If I change the capacitor to 0.3uF voltage ripple peak to peak is 0.00413v and it takes about 0.1 seconds to reach the desired voltage.

For example the first step will be 0.0008v so duty cycle will be about 0.024%, calculator says final voltage without ripple will be 0.000792v,

------- No Ripple --- Ripple min - max
step 1: 0.000792v --- -0.003338v - 0.000492v
step 2: 0.001610v --- -0.002520v - 0.005740v
step 3: 0.002416v --- -0.001714v - 0.006546v

In the mins voltage I get negative voltage but there it can't be negative voltage right it must be 0v at min right?

Which capacitor configuration is better? because If I increase capacitance the time to reach desired voltage also increases or should I jump the first steps to one that starts to give a significative min voltage?
 
Last edited:

crutschow

Joined Mar 14, 2008
38,508
If you want to use the full 12-bit resolution, you can attenuate the PWM signal so that full scale is 1.2V.

So how fast is the PWM duty-cycle changing, and how fast do you need to respond to the change?
I would think in this application you don't need to respond that fast, so you can use a RC filter with a lower frequency response than the minimum.
If can also use two RC low-pass filters in series to form a 2nd-order filter, you will a get much lower ripple voltage for a given response time.

Incidentally you shouldn't use R3 as part of the filter, as a capacitor at the FB input may cause the buck regulator to become unstable.
You should thus do the filtering before R3.
 

Thread Starter

JosXD

Joined Mar 16, 2022
69
If you want to use the full 12-bit resolution, you can attenuate the PWM signal so that full scale is 1.2V.
Yes I would like to use the full, I noticed if I equally average PWM voltage of 0.6v to 2.4v output in the converter about 750 steps will be usable, and if average 0.6v PWM to 3v output converter about 1500 steps, but in this last configuration I won't be able to turn down the converter, with 2.4v and 0.6v at PWM yes, How could I attenuate 3.3v to 1.2v and get the full 12-bit resolution, please? could be a resistor divider or it is something more avanced?

So how fast is the PWM duty-cycle changing, and how fast do you need to respond to the change?
Well I would like to make a ramping mode, let's say from 0.1% to 100% duty cycle in 4 seconds or 0.025% to 100% in the same 4 seconds, the case it's to create a smooth ramping, if we take the 0.1% to 100% in 4 seconds, that means duty cycle will change every 0.004 seconds?

If can also use two RC low-pass filters in series to form a 2nd-order filter, you will a get much lower ripple voltage for a given response time.

Incidentally you shouldn't use R3 as part of the filter, as a capacitor at the FB input may cause the buck regulator to become unstable.
You should thus do the filtering before R3.
pwm.png
Something like this?

If a resistor of 66.5K was needed to get to the full desired voltage in the converter, I just divide the 66.5k equally for the 3 resistors or I do have to do a new math?

Also how do I calculate the second filter, do I need to use min-max ripple voltage from the first filter?

Hope your answer, please.
 

crutschow

Joined Mar 14, 2008
38,508
How could I attenuate 3.3v to 1.2v and get the full 12-bit resolution, please? could be a resistor divider or it is something more avanced?
A resistive divider will work.
Below is the LTspice sim of such a divider with a 2nd-order filter.

The R4 and R5 divider equivalent resistance is 22.6kΩ, so there is 66.8kΩ total series resistance.

I took the lazy way and just tweaked the capacitor values until I got about a 4s settling time (yellow trace) for PWM signal going from 0% to 100% duty-cycle in 4s (green trace)

R1 is grounded since its voltage is at zero for the maximum PWM voltage which gives 0V output.

1703488901942.png
 

Thread Starter

JosXD

Joined Mar 16, 2022
69
A resistive divider will work.
Below is the LTspice sim of such a divider with a 2nd-order filter.

The R4 and R5 divider equivalent resistance is 22.6kΩ, so there is 66.8kΩ total series resistance.

I took the lazy way and just tweaked the capacitor values until I got about a 4s settling time (yellow trace) for PWM signal going from 0% to 100% duty-cycle in 4s (green trace)

R1 is grounded since its voltage is at zero for the maximum PWM voltage which gives 0V output.
Thank you so much crutschow! you simulated the PWM signal with an OpAmp?

I did another example using again 1 RC filter but with a resistor in series, however your example is way better 'cuz it gives the full 12-bit resolution!

For curiosity can you check this example:

rc filter.png
I did the calculation for this RC filter R4 60.4k and C1 47uF, the peak to peak ripple voltage is 29uV and 36uV is the worst case,
R4 and R3 in series sums up 66.44k almost 66.5k both 0.1% tolerance.

Wondering if you could tell me if R3 is okay or will cause problems, 29-36uV ripple voltage if every step is 800uV doesn't sounds bad right?

And ofcourse I will use your example, just wanted to know how bad I did it.
 
Last edited:

Thread Starter

JosXD

Joined Mar 16, 2022
69
A resistive divider will work.
Below is the LTspice sim of such a divider with a 2nd-order filter.

The R4 and R5 divider equivalent resistance is 22.6kΩ, so there is 66.8kΩ total series resistance.

I took the lazy way and just tweaked the capacitor values until I got about a 4s settling time (yellow trace) for PWM signal going from 0% to 100% duty-cycle in 4s (green trace)

R1 is grounded since its voltage is at zero for the maximum PWM voltage which gives 0V output.

View attachment 310831
Hi crutschow, thanks for the example,

I installed LTSpice and reacreated your example and it's great pretty smooth, I was playing with the simulator for learning porpuses and noticed that if I set V1 everything to 0 to keep it off and V3 from 0.1v to 1v, it means V3 is always greater than V1, so output pin in OpAmp is always pulled down to negative rail, however the FB jumps to 30mV in about 900ms, is there voltage leakage in the OpAmp's output pin?
 
Top