The 4th installment in the lab power supply design series. This time Dave shows you how to control the supply with a Pulse Width Modulation (PWM) signal, and chose the correct filter values.

Hi. Now, after the last three videos on the power supply design I've had a few people ask how do you do the Pwm or the Pulsewidth modulation voltage control instead of the 10 Turn Pipe Well, it's a good question, so let's take a look at it. Now, when it comes to controlling a power supply like this, you've got three main options. The first one is the 10 turn pot which I've been talking about, but they're quite expensive.

They're about 5 to 10 bucks or even more each depending on where you buy them from. The second one is to use a digital to analog converter. It puts out you put a digital signal in from your microcontroller. It gives you a voltage output exactly like the pot, but I don't know you're going to pay two bucks plus for a digital analog converter.

Not many microcontrollers have a deck actually built in, so what you do is you use the third option which is pulsewidth modulation and it's effectively free. Most, uh, decent microcontrollers these days have a couple of Pwm modules in them, pulsewidth modulator modules, and all you need. It's not quite free, you got to pay for a resistor and a capacitor. but gee, you know they don't cost much at all.

So let's take a look at these and there's a 10 turn pot and they're very, very nice. And if you're just building a just a a linear uh power supply or even a switch mode one and it's not intelligent microcontroller control in there at all, then I Highly recommend. Just use a 10-term pot. You can use regular uh pots, but then you got a you've probably seen those power supplies that have coarse and fine adjustment you.

That's probably a dead giveaway that they're not using a high quality, expensive 10 turn pot and they're Dicky Trust me, just the fine and cost controls. They're hopeless. Get a decent 10 turn pop. They're 510 plus dollar each and you need one for voltage and current.

Wow, Wow. There's like 10 to 20 bucks just for your Supply right? There doesn't include the knobs. and if you're going for digital control, then, well, you're going to use instead of a pot because you still got to have a knob on the front panel unless you use switches. Uh, then you're going to use one of these rotary encoders and they're pretty cheap.

They're only about 50 cents each or something like that. under a dollar and you just put a little cheap knob on the top and then you've got complete control that is more than 10 turns. That's infinite number of returns. So these rotary encoders are great.

They're easy to encode in software, and you can use this to drive via your microcontroller, either a digital to analog converter, or a pulsewidth modulator. And the goal for all three of these things is exactly the same: You want a voltage output. If you got a 0 to 10 volt, Supply, then you want 0 volts to 10 volts output to drive? Uh, whatever you're to actually control your voltage regulator and these do exactly the same thing. You turn a knob or these two.

Here, you turn a knob, but a microcontroller generates the voltage. Now in terms of the deck, uh, here you know about digital to analog converters or if you don't look them up I Won't go into them here. But basically they're a dedicated device you feed a digital signal in Via Usually you know, like a Serial input these days, an SPI or an I Squ C interface. Or if they're built into the micro, they could do that and they give you a direct voltage out.
You don't have to do anything else with it. they're magic, But a pulsewidth modulator is exactly the same as a deck. It works it well. It works differently, but it gives you the same result.

It gives you a voltage output just like a Dack And the resolutions are exactly the same as well Because if you're working with a 10 or a 12bit deck, it's going to be give you exactly the same voltage resolution as a 10 to 12bit Pwm. So let's take a look at how the Pwm actually works now. Uh, you can get Pwm Hardware modules dedicated Hardware block inside your microcontroller. That does all this for you independent of the software.

The the microcontroller software can be off doing whatever it else it likes and the Pwm module in the micro will take care of generating the Pwm waveform. and I highly recommend you use those if you have them available. but you can do it using just a any generic IO pin and you can do it in software because all it is is a digital waveform with a varing duty cycle. Now what we have here what a Pwm signal is in this case is just.

it's uh, a fixed frequency, say 10 khz or something like that might be a typical Pwm frequency. So this waveform just repeats at at a a frequency of uh 10 khz. Now what changes though is the duty cycle or What's called the on time from 0 to 100% Or what amount of time in that period that that waveform is high and it can be anywhere from zero zero of course 0% would be. It doesn't go high at all, it just stays low.

Your output pin just stays forever low. and of course you're going to get zero volts output. It's just low. It's a DC signal, but let's say it goes high for x amount of time.

Let's say it goes high for 10% of the time. then uh, 10% of the time it stays low for 90% of the time. What do you get out? Well, you don't get out anything. It's a digital signal, but if you pass it through a low pass filter, an RC filter.

first order filter like this, you will actually magically as long as you got the filter, values right, magically convert this Pwm signal into a DC voltage from 0 to 5 Vols. Because let's say we got a 5V microcontroller and that's what its output. Uh voltage is going to be either Z or 5 Vols. Well, when you pass it through the RC filter like this, it averages out that duty cycle or on time value to a direct linear proportion linearly proportional voltage from 0 to 100% or 0 to 5.

Vols. So if it's on 10% of the the time and off 90% of the time, you will get out 1/10th of 5 Vols or half a volt out of your RC filter down here. Magic! So you can see why it is actually a Dack. It's a digital to analog converter.
It works just like a deck. You feed in a value. In this case, instead of Uh outputting it into a digital analog converter, you put it you uh. the value that you put in from 0 to 100 % gets converted into a duty cycle or on time from 0 to 100% And It generates an output voltage proportional to the digital signal or the digital number that you put in.

Now, Uh Resolution plays a big part in these digital analog converters and pulsewidth modulator circuits. And I said before, they're exactly the same. They're resolution of a Dack is the same as the resolution of a pulsewidth uh modulator. Now, Uh based.

Dack that's sometimes what it's called. It's a Pwm based Dack Basically, because it is a digital to analog converter. except it uses the Pwm technique. Now the resolution.

Let's take a pretty meager, pretty low-end 8bit resolution, and most really cheap budget low-end microcontrollers. You know the 50 Cent ones might have these Uh 8bit uh Pwm uh outputs like this Now, of course 8 Bits represents this 256 different levels. Now that means that we can set this resolution in here in steps. There can be 256 different steps in there from 0 to 100% So what does that mean? It means that 100% / 256 at Um each step, we can get a resolution of 0.39% of our maximum voltage.

which is 5 Vols. So in this case, 5 Vols ID 256 19. 5 mol steps. And if you're designing a 5V uh power supply for example, then you would with an 8bit resolution Pwm module you'd be able to get.

You'd be able to adjust that in almost 20 Molt steps. That's not too bad for a generic Uh Lab supply, but let's say you doubled that to 10 volts, you multiplied it by two and you want to zero to 10vt Output Uh DC Supply Then you've got. Then your steps would be 40 molts. Uh, you know it's getting a bit crusty.

You might want to up that to 10bit resolution if you have a look at 10bit and 12-bit resolution. Uh, Pwm modules. In the same case of Uh, 5 Vols um. output, then divided by 1024 because it's 10 bits, 4.8 molt, almost 5 molt steps.

Not bad. 12bit Oney We're getting serious now. 4,096 steps in 12 bits. So we're talking a resolution of 1.22 molt steps.

Fantastic. Now here comes that tricky thing to do with the difference between resolution and accuracy. just like you get on multimeters and a whole bunch of other stuff. Yes, a 12bit uh, digital to analog converter be it Pwm based or other type of Uh Dack based uh system, then you will get almost 1 molt, just over 1 molt resolution, or steps from 0 to 5 vs.

and uh, it's and you do actually get that you can control that output. You can jump it up by 1.22 molts bang bang bang, or drop it down like that. You've got that fine control. But the absolute value or the absolute accuracy? Well, if you feed in completely 100% are you going to get exactly 5 Vols out? Well, that depends on how you power or how you power your uh, microcontroller here.
Because the good thing about modern microcontrollers is that they're all Seos. They're Seos output. so they use Fet switching on the output. so that means that they can get Incredibly Close ridiculously close to their input voltage rail up here on their output switching.

So if you're powering your pick from precisely 5 volts 5.00 volts, then you can pretty much expect close to that absolute accuracy on the output of your Pwm Here, As a you know there might be a Molt drop or something like that, it's going to be very, very close. Okay with these fat outputs. Now, if you just power your pick or AVR from like a 7805, they're only 5% accurate. So the output of your pulsewidth modulator here is going to be 5% accurate absolute as well.

And that's really not much good if you got a uh bench, uh, Precision bench power supply. Now you can compensate for that in software or pots. with further gain stages or something like that, you can actually calibrate it and tweak it. But yeah, that's a bit nasty.

But uh. so sometimes you might want to actually power your microcontroller instead of from a regular voltage regulator. You can actually power them from a voltage reference one of those Precision uh, you know, 2 and 1/2 volt voltage references if your micro goes down that low or a 3.3 volt voltage reference or a 5vt voltage reference and you can get those in like 0.1% Well, something like that. 2% for a dollar or so.

So um, you can actually power your microcontroller from that, provided that your microcontroller and the other circuitry you're powering from. It doesn't take more than its maximum allowable current, but you can actually do that. So when you're designing power supplies like this, don't be afraid to actually power your microcontroller from a Precision voltage reference. It can work and it can be very handy.

And in the previous videos, I actually used an Lt19 voltage reference in the bill. But you can use LM 336 and there's hundreds or thousands of other voltage references and some of them might have you know, 40 50 milliamps output capability. And that's a decent amount of current for powering a, uh, a microcontroller. But just be careful if you're driving loads like LEDs and stuff directly from the microcontroller, then that current's got to come from the micro power rail which comes from the voltage reference.

But as long as you don't exceed that, you, you can get excellent absolute output accuracy as well as resolution on a Pwm. So as you saw, if we have 10% on 90% off during our period here, then we're going to get this: RC filter is going to average that value out to 0.5 Vols But it's not just going to be completely DC There's going to be some noise on that. Okay, there's going to be noise superimposed on there depending upon the values you pick down here and how effective this filter is. So really need to take a look at it in depth at the filter and what values you need to get rid of.
say a 10 khz uh might be a, you know, a very typical Uh frequency. Let's take a look at what RC filter you need to get a decent uh uh low noise output from this which then usually you want it lower than your resolution. So if your resolution is 12 bits, you don't want the noise to be any more than one bit resolution of 1.22 Ms Now what we're going to take a look at is a filter simulation program here. I'm using Filter Lab.

it's from Microchip. Um, it's an old uh program it. It does an okay job. There's one another one from TI and from various other uh people, uh, linear technology do one as well.

and um, and they're all pretty old. but uh, they give you a good feel for how Uh filters work. In this case, we just our simple RC filter here with the buffer and that's called a single pole filter and we can change the filter up here. That's this number one up here.

That's so if we go to a sec, what's called a second pole filter? You've added some extra components and third, a three Poole filter and a four pole filter. This is called a Salin key configuration. There's there's different configurations you can do, but basically the order of the filter the higher the order, the greater the attenuation. um of those higher frequencies.

Now let's take a look, let's go to the first order filter now. I've set the filter to have a rollof, a nominal rolloff, or a Uh filter cut frequency of 1,000 Hertz So you can see that here it's 1 khz and what that means? You've seen that. probably seen that formula before. It's 1 over 2 Pi r C and that gives you the cut off frequency of your filter now that it's not a brick wall cut off.

Okay, what we've got on the X axis here is our frequency. Okay, now this is a logarithmic scale so it's in decades so it doesn't go linearly from say 100 HZ to 1,000 HZ. Here it goes: that's 100 HZ that's 200, then 300, 4, 5, 6, 7, 8, 9 and then 1,000 Hertz Like that. Now the reason um, we use a log scale like this is because it actually gives us a linear slope.

Like like this, it converts our logarithmic Um response into a linear slope which will become um. It's just easier to do when it's easier to fit. uh, wide frequency spans into the one graph like this. So that's why we're using a decade log rythmic response on the X-axis Now the Y- axis here is the magnitude in DB.

So right down here at 100 Htz, it's got Z DB attenuation. That's the attenuation of the filter. So you feeding your signal and what you get out you at at at 100 HZ you feeding exactly what you get out, there's zero DB attenuation. Now the uh, the filter cut frequency that Formula 1 over 2 Pi RC That gives you your what's called minus 3db Uh, cut off frequency of that filter.
So as you can see in uh that that filter there I've got it on the Uh Y axis. There, it's about - 3db and it's spot on. 1,000 Hertz on the x-axis cuz CU that's where that's what we've designed it for and then it rolls off after that. Now you remember we've been talking about filtering out a 10 khz frequency.

Well, let's go down to 10 khz Here It is. How much is our that filter attenuating our 10 khz signal by? Well, if you take that over to the X Um, sorry to the Y- axis over there, it's minus 20 DB And if you know your DBS a minus 20 DB drop in amplitude is 1 10th or uh, an order of magnitude. So if we're feeding in 1 volt we're going to get out 0.1 Vols. Now the thing about DBS is that once you step down to uh, if you go down to so in multiples of 20, that's an an order of magnitude drop.

So - 20 DB is 1/10th - 40 DB is 1/ 100th, - 60 DB is 1,000 and - 80 DB is 1 10,000th of your input voltage. Now, if we increase our pole, our number of poles, or the sharpness of our filter, you'll see that it gets steeper and steeper as we go off. Now the rolloff which is is specified in Uh DBS per Uh decade can be specified in other things too, but in this case it would be DB per decade. And uh, it, it gets just sharper and sharper.

And as you can see, if we used a five Pole filter, our 10 khz signal would be attenuated by minus 100 DB. That is absolutely phenomenal. Okay, but if we use our first order filter which we've got our RC filter, it's only attenuated by 1110th. So we're not going to filter out if if we set our cut off at 1,000 Hertz.

So if you're trying to filter out a 10 khz frequency Pwm signal with a 1 khz filter, it's going to do a pretty darn poor job of it. It's only going to attenuate that 10 khz signal by one, or the 10 khz Ripple by 1110th. It's hopeless. It's like, you know, 10% unbelievably hopeless.

Now, what I've done here is to set the filter to Uh 10 Hertz. So there's the Minus 3db cut off Uh frequency at 10 Hertz and you'll notice that at 100 HZ, it's 20 DB down. And at 1 khz there, it's 40 DB down. So if you measure the difference actually between uh, the Uh 100, once it gets on this linear part of the curve.

Here, if you measure the difference between the 100 HZ frequency at minus 20 DB and the 1,00 Hertz frequency at- 40 DB, that's what's called 20 DB per decade. So that filter rolls off at 20 it. Uh, you get 20 DB attenuation per decade in frequency. So so e, um, if we extended that graph out even further there to 10 khz, we'd find that it' be down to -60 DB.

So if we set our filter at 10 Hertz at 10 khz, we will be. we'll have minus 60 DB attenuation of that 10 khz fundamental frequency. And remember when I said uh, it drops an order of magnitude or 10 times per 20. Uh DB Then at 10 khz, we be at- 60 DB Sorry, it's off the Uh graph I Haven't got enough decades to show it here, but it's - 60 DB at 10 khz.
So that's 1 1,000th. That's the attenuation. So you feed in one volt. then you're only going to get one molt out Now just to be clear, that 1 molt I'm talking about there.

And these levels I'm talking about are they only apply to a sine wave at 10 khz. So um, basically all this filter talk we've been talking talking about doesn't actually apply directly those amplitudes to the Pwm. It gets more complicated when you start talking to Pwm signal and in practice it's actually going to be lower than that. But let's uh, use a ballpark.

Let's say you did actually get 1 Molt of Ripple out assuming it transferred to your output through the regulator then and there wasn't any extra further uh filtering. Then you know that that might be okay. but generally you'd want to shoot for better than that. But with a filter cut off of 10 HZ you don't That means you're not going to be able to um, change your output voltage really quickly and on a DC power supply.

If you're manually turning a knob, it's not a problem. You know, you can't turn that knob very quickly at all. You're going to turn it only you know effectively. You know 5 or 10 Hertz at most or something like that.

Okay, you're not going to get huge big step changes on your power supply because it's filtered out all right now. We're actually going to do some real circuit simulation here with with a Pwm Uh signal and with our LC uh one pole LC filter and see what we actually get out now. I've set up this uh voltage. Um, it looks like a voltage source, but it's actually a pulse Source I'm using LT spice um here which is a free Uh circuit simulation tool I Highly recommend.

You get it. It's pretty darn good. And basically what I've set here is I set the pulse width modulation um uh, voltage level from Uh to 1 Vol So it's going to uh switch between zero and 1 volt. Now you know I it.

It won't do that if you're using a microcontroller. that's say a 3.3 volt voltage rail. You will get 3.3 but we'll set it to one here just to make our uh math nice and easy today. Now the period down here I've set to 100 microsc and that's equivalent to 10 khz.

So we're going to get a 10 khz repetition rate on our Pwm signal and then I can set my on time. I've set it to one10 of that. So I'm setting it to 10% uh, on time or 10% duty cycle. It's 10 microc out of that 100 microc total.

Okay, so what I'm doing is I'm uh, going to go into the simulation command here. we're doing transient analysis um, and I've set my stop time to 1 millisecond and I've set my time step. So it, um, effectively, um, samples or simulates A at every 0.1 microc. And if we hit that then and we run it up here bang There we go and I told it so we're only going to get it stops when it once it got to that 1 millisecond period.
and what we're doing is we're measuring this point here. You can see the little red probe down there on the circuit and we're probing that point right there which is the Pwm input and as you can see, it is 10% and you can go in there and actually measure that precisely. But but trust me, it's going to be 10% So our on time is 10% so we expect if we're feeding in 1 Vol here 1 VT Peak to Peak There it is over on the y axis here from 0 to 1 volt Pwm signal, we expect 10% on time. We expect 1110th voltage on here.

Do we get it? Well, not quite and we'll see why. Now the reason is is that is actually slowly ramping up because there's an RC time constant. We started the simulation from zero. So we're going to have to go in here and we're going to have to extend that time period.

Let's say set it to 100 milliseconds like that, let's leave it at 0.1 It could take a bit of a while to simulate that, but let's try that again, shall we? Now it's going to be hard to see that if we zoom in. So let's click on the circuit here. Bang. Look at this and you can actually see that window there.

Let's Uh Zoom to fit. Okay and Bingo! You can see it rise up like that. That's our RC time constant that it takes when you first switch on the supply or change the voltage or whatever. It doesn't respond instantly, but it eventually settles down to bingo.

What does it settle down to go across here? Exactly 100 m volts average. Trust me. if you drew a line straight through there, it would go right through the average point of that waveform. So there's our 1110th.

It's worked. Our 10% Duty cycle has translated to Uh 1/10th of that or 100 Ms output voltage. And if you look at the output on the Op amp over here, you can see that uh, that takes a little bit of time, but it it responds to the same value, but there's a little bit of an offset there that's going to be due to the offset voltage. But anyway, what we really care about here is this noise.

Look at the Ripple. You can see that the switching frequency because, um, the RC filter we're using is not uh, low enough in value to filter out all that noise. Who wants a power supply when you're trying to Output 100 molts? it's got. You know what's it got? 10 molts, A ripple on that.

Ah, hopeless. And that's with a filter frequency down here of 159 Herz Because if you do the math, use that Formula 1 over 2i RC That's that. The 3db cut off point of that filter is 159 Herz and we're trying to F filter out uh 10 khz. So as you can see, it's not terribly effective at all.

But let's try that again. If we actually change that to one microfarad, you'll find that this Uh Ripple here will decrease. We're increasing the capacitance by a factor of 10 so our Uh filter frequency will go from 159 Hertz to 15.9 Herz And you'll find that because this is all order of magnitude, the Ripple will also drop by an order of magnitude. so let's re simulate that so it's about 10 MTS at the moment.
Let's re simulate that and bang. it's slowly ramping up. It's ramping up. but as you can see, it's taking longer.

It's taking much longer to actually get up to frequency there cuz we've changed the RC time constant so you can see that's taken 54 milliseconds before it even. You know 50 odd milliseconds before it even sort of starts to level out like that. And that's not too bad actually. Now let's go in there and have a look at the Ripple.

We'll Zoom right into this window here and bingo, You can see it there it is. That's only about one. Well, what's that? Half a molt? Even. it's only half a molt.

Ripple Fantastic. So as you saw there, there was really quite a tradeoff between the Uh response time and the Uh and the filter Effectiveness or the filter attenuation. Now to do that, Uh, to get around that, we can add a second stage RC filter like we've done here. Exactly the same.

So we've gone back to our original 10K and 100n here, so that's 159 Htz nominal Uh 3db cut off, but we've added another identical one here 10K and 100n and we could do it with the opamp and use you know, various configurations like a salon key configuration and all that sort of stuff. But let's just, uh, keep it simple and put two Um RC filters in series like this and if you run it, this is what you get. The green line There is The value on here. like the exactly what we saw before.

Okay, that's got our like 10 molts of Ripple on it. It's huge, but our second one here after that. that is the Blue Line there. and check it out that is.

Let's put both on there and as you can see it's it's beautiful. it. and if we zoom in on that, let's zoom in on that part of it there. look at that.

the blue one smoother there. a baby's butt. There's hardly any Ripple on that at all. We're talking ah, .1 m.2 M volts or something.

It's tiny so that's just an easy way that you can get, uh, extra filtering on your Pwm. Just add a second RC filter stage. I Mean sure, you can up these values here. Okay, these, uh 10K uh, this, 10K and 100 in.

You know you can up those. but then your response time gets low so it's better to add this second stage here and then you can keep your response time fairly quick at 10 milliseconds or something like that. But um, it has much greater attenuation. so you know we're down in the hundreds of microv volts there now just by having a simple 10K and 100n like that.

a two-stage RC filter. Beautiful. Now what happens if you Pwm signal is say 5 Vols out. Now let's change it back to 5 Vols here.

but let's say because you got a 5V rail on your microcontroller. but you don't want to get 0 to 5 Vols out, you only want 0 to 1 Volt or something like that. Well, what can you do? It's easy. you can add a resistor in here to actually attenuate that.
So let's add that in and see what we get. So let's run it again. With that, we've got our 5V signal here. Okay, there's our 0 to 5V Pwm signal at 10% So what do we expect out expect half a volt 500 MTS here.

That was before we added this 10K though. So now we expect to have that again. Or .25 Vols 250 MTS Let's see if we get it. Bingo We do.

There's our 250 MTS but it's got the Ripple. But if we look on the output here, then bang There It Is Our Blue Line Our Blue Trace There, that's 250 molts. So let's run it again. With that, we've got our 5volt signal here.

Okay, there's our 0 to 5V Pwm signal at 10% So what do we expect out? We expect half a volt 500 molts here. That was before we added this 10K though. So now we expect to have that again. or 25 Vols 250 MTS Let's see if we get it.

Bingo We do. There's our 250 MTS but it's got the Ripple. But if we look on the output here, then bang There It Is Our Blue Line Our Blue Trace There, that's 250 molts. Now here's an interesting thing: I Just wanted to show you quickly: we've got an LT 1014 Opamp here.

I Just chose this generically just so we could get something working from the library. Now, it just so happens that this is a fairly, you know good Precision Uh, Op Bam's only got a couple hundred microvolts uh, offset voltage and you pay a bit of coin for this thing, so you'd expect it to work out quite well at low values. So let's actually try that now. I've changed my um, uh Pwm here to 0.1 microc uh compared to the 100 microc period.

So that's 1 1,000th of our 5 volts maximum uh Pwm voltage there. So if we're getting 5 volts, uh here with 1 1,000th on time, we expect 5 molts out of our filter. and if we run it Bingo that's exactly what we get. There's our 5 molts and that's the input to the well.

that's the first stage filter, second stage filter input to the Opamp 5 Ms Well, let's also add on the output of the opamp. What? Look at that 35 MTS What's going on? Well, it turns out that this, if you look at the data sheet for the LT 1014, it turns out that you can't actually, uh, go down to Zer volts unless you have a decent load on there. It's not a railto rail opamp, so just be careful if you're uh, actually, when you choosing an opamp, uh, like this in this grounded configuration and you don't have a negative uh Supply live voltage for that Op amp, just make sure that it's actually capable of zero volts on its output. Otherwise, if you use this fairly High Precision uh Op Amp, we'd get a 35 molt Uh output offset.

Terrible. So you might think that the solution to uh, this pwm uh thing and the tradeoff versus the the response time versus the attenuation and the Ripple and all that sort of stuff is to just up the frequency of your Pwm signal. Well, yeah, in theory that's great. The higher the Pwm frequency you use, the easier it is to filter out with better response time.
But uh, the microcontroller is going to have a limit uh to how high a Pwm frequency it can go based on the resolution. and generally you can change the resolution of these things. You might be able to use the and a 10bit resolution PW and you might be able to use it as an 8 bit one or as a Uh 10bit one for example. And it's going to have a maximum upper frequency.

You have to read the data sheets very carefully to get that uh sort of info, but generally you want to run them as fast as possible. All right, enough of the simulation stuff. Let's actually feed it into our circuit a PW um M signal to replace the pot which we uh used before in the previous videos and that's exactly what I've done. I'm using the function generator output of my Agilant scope here to actually replace the pot and I'm feeding it in Via a single RC filter which is what we've looked at and this is what I've got here instead of the voltage control pot we we've disconnected that and we're taking it down to a 10K and 100n low pass filter just as we looked at and the frequency I've got uh set.

as you can see here, if you go in here you can see I've got 100 khz uh frequency and our amplitude is 3.3 Vols So we're simulating a Uh a microcontroller generating that Pwm signal with uh a 3 .3 Vol rail the offset voltage because it this is a function gen that's got to be halfway in between and we got a 50% duty cycle of 50% on time. So if we're feeding in 3.3 volts and uh, by the way, I've also changed um, this feedback resistor here just to make the math easy, changed it to 10K so we'll have a gain oftimes two in this uh amplifier um control Loop here. So if we're feeding in 3.3 volts that we've got here, we should get some Ripple out of here of course because it's not uh that great this filter on its own and uh so but and at 50% duty cycle we'd expect to get 1.65 volts out of here. Multiply by two, we expect to get our 3.3 Vols out of here.

exactly what. And let's actually see if we get it. Well, if you have a look here, let's zoom out there it is. There's our output voltage.

it's pretty close. There's going to be some error in here. This isn't uh, perfect. but if it, uh, was, you use more more Precision uh, function Gen and stuff, you'd get exactly 3.3 So we're getting out exactly what we expect and this, uh, the green signal here which I'm triggering off.

There's our 3.3v um 10 khz uh Pwm signal and the yellow Trace Here is the AC coupled uh output on that RC filter there. So on the RC see RC filer right there. that's our yellow waveform there as you can see that uh, yellow waveform 100 MTS per division. We're getting 100 MTS Ripple on there and let's probe the output and see what we get and this is our output.

I've just in the output of our power supply our 3.3 Vol output. and as you can see, it's uh, there's not much on there at all where it's still at 100 MTS per division. but if we turn that up, you can actually see you can actually see the Ripple on on there. Now down at 10 MTS per division, we're getting about 5 Ms you know, 8 Mt worth of Ripple or something like that.
And look at these little high frequency stuff in here. Like that bit of ringing? Uh, there? That's uh, probably due to our probing and stuff like that. but uh, you really want to get rid of, um, this sort of stuff so that's not adequate. Uh Ripple if we just used that 159 Herz uh.

filter there, that's that's. really no good at all. I Don't like that one bit. Now you're probably asking, why did that uh.

output? Actually, why did that output Ripple drop from 100 molts to under 10 molts? It shouldn't have all. Just if we were, get in, that here shouldn't have all just passed through that straight to the output. Well, no, not really. Remember these caps we got here.

They're going to do some filtering as well and that's what you get if you replace the Uh 22 uh microfarad cap here down to 100 n Bingo And it turns out that I still had 47 microfarad of capacitance on the output there. So I took that off and what do you get? Magic. Look at that. Wham That's an absolute shocker.

and bingo, it's back to 100 molts. There you go. So it's actually now made its way all the way through. so all of our uh, noise, all of our Ripple that we had on our filter here has gone all the way through.

cuz now we don't have adequately adequate filter in on the output or the Um or the input to the set pin here. And what happens if we add the second RC filter in here Once again, 10K and 100n bang. There's our output voltage exactly the same scale as before, but our Ripple has dropped very very significantly. and once again, that's with no um, practically no uh, output filtering or no filtering on the set pin.

And if we replace our filtering back, our 22 mic here and a big uh Capac Capac on the output bang, there's our noise. It's suddenly vanish. These little spikes in here are going to be Du due to ground bounce and uh, stuff like that. You can actually see the bouncing there.

It's to do with probing and things like that, so don't worry about that. but the output noise there. look at that. Beautiful and what happens if we adjust the duty cycle here? Well let's give it a go, shall we? Let's drop it down to say 10% Ah, of course.

silly function Gen only allows us to go down to 20% but there you go. That's the expected 1.3 Vols or 20% of that 6.6 Vols cuz we got a times two amp in there. There you go. It uh, works fine and if you drop that, if you did drop that dudy cycle down to 1% or.

1% you'll find that the output voltage would follow. So there you go. That's a practical demonstration of how to replace your control pot with a the Pwm output or a deck output of a microcontroller piece of C Catch you next time.

Avatar photo

By YTB

28 thoughts on “Eevblog #225 – lab power supply design part 4 – pwm control”
  1. Avataaar/Circle Created with python_avatars William Walker says:

    All that fancy stuff. For a hobbyist, what's wrong with a transformer, full bridge rectifier, filtering and a pass transistor regulator circuit? Keep it simple.

  2. Avataaar/Circle Created with python_avatars Victory First says:

    HOW efficient is this unit ??? Thanks

  3. Avataaar/Circle Created with python_avatars Stuart Hatto says:

    11 years later, I am wondering how we could modify the project using an ESP32 and it's DAC – worth an investigation.

  4. Avataaar/Circle Created with python_avatars Bruno DUYE says:

    Thanks a lot, this is inspiring, fascinating !

  5. Avataaar/Circle Created with python_avatars Vivek Todmal says:

    You are the holy Bible of electronics

  6. Avataaar/Circle Created with python_avatars Maks F. says:

    Standing all that time, all that videos with that board on your shoulder is some kind of heroism! )))

  7. Avataaar/Circle Created with python_avatars Maysam Pkh says:

    Fantastic explanations… Bless u dave

  8. Avataaar/Circle Created with python_avatars theo van nieuwenhuizen says:

    What about using dither in the timer? This way you can increase output resolution.
    I mean with STM32's in 16 or 32 bit timer this is a very neat way to get fine tuning of the PWM output resolution.

  9. Avataaar/Circle Created with python_avatars José Batista says:

    You're Awesome!

  10. Avataaar/Circle Created with python_avatars Levi Willrich says:

    why not power your uc with a generic supply voltage then drive the pwm output with a transistor connected to the voltage source

  11. Avataaar/Circle Created with python_avatars Axelvad says:

    Can someone on here maybe help me explain whats wrong with my Advance / Gould os2200 Oscilloscope. It has a really highpitched noise. Is it the supply or crt? Cant use it even though it works fine excluding the noise.. the noie is 10 to 17khz

  12. Avataaar/Circle Created with python_avatars HEXMOD says:

    hello, i set frequency at 30KHz, could attiny85 handle it, im following your source code. thanks you

  13. Avataaar/Circle Created with python_avatars Tau says:

    Couldn't you also just power a fet from a voltage reference forgoing the need to power the whole micro this way?

  14. Avataaar/Circle Created with python_avatars Milan Hlaváček says:

    Why rc filter? You could propably use lc or is there something that i cant understand?

  15. Avataaar/Circle Created with python_avatars excited box says:

    The esp32 only costs $1.50 in quantity and $2-2.50 in single chip qty. Even dev boards can be bought for about $4. 16 PWM Channels that can go up to 25 bits and if I followed the tech reference charts correctly they can be clocked up to 80Mhz and adjusted quite freely depending on clock source. Should be possible to make a touch screen and WIFI controlled multichannel PSU using it. It also has 2 DACs but they are only 8 bit. The interesting part is the 18 12bit ADC channels.

  16. Avataaar/Circle Created with python_avatars Artjoms Pugacovs says:

    40 minutes and no information how to use pwm with transistor to make power supply.

  17. Avataaar/Circle Created with python_avatars Kristian Prokupek says:

    Nice. Which PWM frequency you use ? And what RC filter you use, simple, or 2-nd order ?

  18. Avataaar/Circle Created with python_avatars Fadi Safadi says:

    Hey is there a possible way to know how to program that microcontroller to drive the dac?

  19. Avataaar/Circle Created with python_avatars Denis STRYSZYK says:

    oops! PWM is from 0 to 255, 256 is just a zero with sometimes a carry flag…

  20. Avataaar/Circle Created with python_avatars Chris Engelbrecht says:

    AWESOME AWESOME AWESOME! Your way of explaining is very good! Thanks a million

  21. Avataaar/Circle Created with python_avatars Travel with sushi says:

    how to get a 40A constant current output

  22. Avataaar/Circle Created with python_avatars Erick Miller says:

    It's been a few years, do you name your nets yet? 🙂

  23. Avataaar/Circle Created with python_avatars edgeeffect says:

    It's a pity the project didn't stop just before this part… I'd have liked to have a nice newbie friendly schematic before all this microcontroller bullshit was added. I suppose I'm going to have to go back one step and do some development work myself.

  24. Avataaar/Circle Created with python_avatars Matt Taylor says:

    How do I contact you to ask a question not related to this video? I want to use dc motors from treadmills to power machines.

  25. Avataaar/Circle Created with python_avatars lleaves says:

    Very good thank you. I have watched all the videos in this P.S. design series. Looking forward to the next video in the series.

  26. Avataaar/Circle Created with python_avatars M7D Tbh says:

    Can you explain how the PW to voktage filter works

  27. Avataaar/Circle Created with python_avatars Ross Painting says:

    whats the highest voltage it can handle

  28. Avataaar/Circle Created with python_avatars Eric Sherwood says:

    WHY ARE YOU TALKING LIKE THAT??? NOBODY WHO WATCHES THESE IS 7.

Leave a Reply

Your email address will not be published. Required fields are marked *