PWM Smoothing

Hi all,

I know a PWM output can be smoothed using a simple low pass filter and using the highest PWM frequency, but I'm having a little problem finding out what state the PWM pin is in during the low (or off) phase of the PWM. Is the pin open or draining? Basically what I mean is during the low phase is the pin grounded, grounded via a pull-down or just floating with no connection?

The reason I need to know this is because the smoothed output will be fed into an op-amp to decouple it (the output needs to be used to bias another circuit and the smoothing resistor would mess that up, thus it needs to be decoupled). Since an op-amp has a very high input resistance, the low pass capacitor will not be able to discharge quickly enough and the voltage will rise to 5V regardless of the PWM duty cycle if the PWM pin is open during the off phase. If it's syncing current to ground then all is fine.

Can't supply any diagrams or anything, all this is in my head only atm.


Not sure about the techie bits of your question but I can say that you'll be best off making sure that arduino ground (which sometimes connects through usb ground and your computer to mains EARTH) should go to one input of the op amp and smoothed pwm to the other. I'd usually have GND to the+input of the opamp directly, and smoothed pwm through 47kOhm same as a 47kOhm feedback resistor from op-amp output to the -input of the op amp. That gets a - voltage relative to gnd, but some op amps are much more stable that way around. It also needs + and - power supplies to the op amp. You can obtain +-12V in your computer ATX, or alternatively +-5V. Most op amps would work better with +-12V.

I think that you should buy a 0.1inch breadboard to try out stuff and break things.

In answer to your question, the pwm output low state will pull down whatever follows it. Add a resistance of about at least a kOhm to limit how much. You might find that two or three stages of tee bridge smoothing do what you want better than the opamp would.

PWM out 11 -========-------========-------========---- load to be biased such as a fet gate R1 | R2 | R3 | | C1 === === C2 | | | | GND ------------------------------------------------------------- GND to nfet source

R1=R2=R3 = 470kOhm = 4.7 x 10^5 Ohm RC > 0.04 seconds C1 = C2 = 100nF = 10^-7 F

You could have bigger capacitors - you've not said what you want to bias. I prefer to connect PWM more directly to the fet gate to use it as a chop, but that gets noisey.

Is the pin open or draining?

It is draining or to use the correct word sinking.

Thank you ad2049q and Grumpy_Mike

Ok, I'll try to explain what is going on. I'm wanting to use a pre-made dc-dc power board in a project (variable power supply). The power board has to have what the data sheet refers to as a trim resistor in order to control the output voltage. The obvious answer to that would be of course to use a digital potentiometer, but meh, who actually uses those if they can help it? After talking to a tech guy at the company who produces it, he informed me that the trim resistor forms the lower part of a voltage divider with the upper part being a 20k resistor on the unit and a reference voltage of 600mV. It seemed to me that if I smoothed a PWM output, decoupled it, then fed the smoothed decoupled output voltage through a, say, 8.7k resistor to the node of the two resistors in the divider (using a 1.2k resistor as the divider) then I would effectively change the voltage at that node from around 30mV to around 600mV which would encompass the entire operating range of the device.

I did initially try this with a simulator without decoupling (i.e. using the 8.7k resistor as part of the low pass filter) but I had to use a rather large capacitor to get the PWM smooth enough (as the capacitor also discharges through the trim resistor) and that also had the effect of causing a lag on the change in output voltage to about 100ms instead of just a few ms with the decoupled approach.

Can't quite get it from your description. Can you post a schematic because it dosen't sound quite right.

I think you are using the word decouple incorrectly. Do you mean isolate?

Just an R and C form only a first order filter. They do not roll off very fast, maybe you need a higher order filter. What speed do you want the change the output at?

the T bridge with 470kOhm x3 which I drew would not work in your application because .. well the huge resistors are wrong.

Sounds to me that your simulator is not quite the same as your arduino, which does pull outputs down during the down half of pwm and then pulls them up during the up half. In a simulator, I'd represent the pwm as an ideal 5V 0V square wave voltage source with a 200 Ohm resistance from its ouput to the arduino output pin. I think that what you want is what you'd get if you conected that T bridge I drew to the gate of a 1N2700 nfet or similar. I have suspicions that would be enough to be the lower half to go in your dc controller, but I have not checked. How about setting up on pinboard with the T bridge which I sketched to the gate of an nfet, 100 Ohms below it, some kOhms above it, and for testing put another 20kOhms above that to your external DC. That might need one more thing: make a potential divider to get something back down to the 5V range and check that with one of the analog inputs on the other side of your arduino. I'm not sure whether or not an almost constant voltage between 2V to 4V at this pwm output giving a constant (+-20%) current through the 20kOhms would do what you want. Perhaps it needs more stages and bigger capacitors.

Changed to “ISOLATOR” lol. The output is monitored by the microcontroller and adjusted to compensate for the unreliability and constantly changing resistance of the final load in order to keep the output power constant. In all honesty, a 100ms lag is fine, I was just trying to keep it as short as I could.

That diagram helped.

The op amp as you sketched it might even be ok but I thought that a 358 prefers a larger power supply than the single ended as sketched. It might work if given >8V. The 60mV bias at low pwm duty looks a bit small for many applications. What goes next in the system?

ad2049q: That diagram helped.

The op amp as you sketched it might even be ok but I thought that a 358 prefers a larger power supply than the single ended as sketched. It might work if given >8V. The 60mV bias at low pwm duty looks a bit small for many applications. What goes next in the system?

The op amp is powered via the 12V vcc rail. The dc-dc power module datasheet shows that the lowest acceptable voltage at that divider node is around 65mV and the highest 600mV, so I just have to be cafeful to keep the pwm duty cycle from the extremes, but I doubt it'd cause any damage anyway.

There's nothing really "next" as such, as the power module deals with everything else. The final output is a heating element for keeping moish at between 90C and 91C which has an alarmingly high thermal conductivity, hence the rapid response of the output, but I really don't think the response is critical to a second to be fair. I just like to get it as best as I can. I don't want exploding moish.

Thanks for all your help :)

More complex circuit, but to me it seems better as there's no chance of overloading the trimming circuit. What do you think?

Changed to "ISOLATOR" lol.

Ah, in this context what you actually have is a buffer.

New circuit look fine, try it.