Go Down

Topic: Doubling pwm output voltage. (Read 13504 times) previous topic - next topic


I'm pretty sure that kind of 0-10vdc control voltage won't work with plain PWM. You are most likely going to need to follow up the PWM voltage amplifier with a either active low pass or passive low pass filter.



Apr 22, 2009, 07:42 am Last Edit: Apr 22, 2009, 09:21 am by koyaanisqatsi Reason: 1
Total rewrite: I should have done more test points in the simulator.  The PWM to 0-10V conversion circuit I posted and removed does not work and I haven't come up with one that does yet.   :'(

I'm going to try to solve this, but someone else may have a better idea.   Maybe there is something pre-built?


The PWM to 0-10V conversion circuit I posted and removed does not work

Why not, it looks OK to me. What is the problem?


The output at 0%, 50% and 100% PWM was good, but values in between those are _really_ unstable and non-linear.  It looks like the problem is that when the transistor switches on, the low-pass filter cap discharges (very/too) quickly.  It's erratic and the base current fluctuates a lot.   So the collector voltage fluctuates accordingly, causing the output signal to bounce all over the place.

Last night I played with different resistor/capacitor values and tried biasing the transistor a couple different ways, but so far I haven't found the right setup.  This is one of those problems that I now MUST solve for my own sanity, even if no one was ever going to use the circuit.  ;)  If I have time this weekend I'll bread board it and see what the real-world behavior is like.

I can think of other possible solutions using either an Op Amp or an LM317, but depending on the OP's electronics skills, that may be a little overly complicated.  

(Hmmm, if I can solve this, maybe I'll wrap it up into a PWM-analog conversion shield.  I've been looking for a reason to try and design a shield.   8-) )


the low-pass filter cap discharges (very/too) quickly

Didn't see a low pass filter on what you posted maybe you are simulating something else?

If the capacitor is straight on the collector then there will be trouble but you should have a series resistor first. Then the charge is the series resistor plus the collector resistor and the discharge is just the series resistor. For a proper filter you have to consider both the input and output impedance, as I am sure you know. I would suggest reducing the base resistor as a start.

Best of luck.

Vancouver Reefer

Me too, all i see is 2 resistors and a 2n2222. And im good with electronics building, its just been over 10 years since i did any electronic design, hence why im always bugging for help on here!!! lol



If you do find the pwm signal isn't good enough and you need a proper analog out, take a look at this appnote: http://ww1.microchip.com/downloads/en/AppNotes/00538c.pdf

In figure 4 you'll see a solution that should fit your needs. It uses an active low pass filter. For twice the gain you need to add another resistor (R2) that is twice the value of R. R2 should replace the short circuit between the - sign of the op amp and the analog output


Apr 22, 2009, 08:08 pm Last Edit: Apr 22, 2009, 08:13 pm by koyaanisqatsi Reason: 1
Ah, cool! That App Note confirms my idea of using an op amp instead.  I hadn't started a circuit on it and the example they give is a good and simple starting point.

Sorry, I took down the PWM-to-Analog circuit diagram I was working on because it didn't work.  It's still at this link if you want to see what I was doing:


It's weird to post and then edit the post because _I_ know what was there before I changed it.  But I forget that someone who never saw the original post will be lost when they read the edits and have no original to reference.    :P


OK that makes more sense, the problem is with the diode, you don't need it and it screws up the impedance when the line is low.

Using an op-amp to implement a 2nd order filter would be better though.

With high order filters you can remove the PWM signal and allow changes in the DC output to occur faster. That is the problem with just using a large RC value filter the signal is smoothed but the speed you can change the DC level is also reduced.

Vancouver Reefer


Apr 22, 2009, 09:42 pm Last Edit: Apr 22, 2009, 09:45 pm by darudude Reason: 1
There is one thing I don't get.

If the PWM frequency of the Arduino is 500 Hz, what is the frequency I would want in the pass band? Also would this be my 3db freq with my actual freq being magnitudes higher?

Also for a gain of 2, would I just need to make sure my db is around 6 @ 3db frequency?

Grumpy, I would love if you wrote a tutorial on this subject, I love your current tutorials and this would be something that I am sure a ton of people would find useful.

Vancouver Reefer: The values you chose for r1 and the cap are the exact one from the appnote. Those work for the freq required by that appnote, it might be different from the frequency you require.


Vancouver Reefer: First off that is only a first order filter, if you are using an op amp you can implement a second order filter. The way you tell is that a second order filter has frequency dependent components (capacitors) in the feedback loop.

The filter rolls of at 3dB per octave, per order, so a second order filter rolls off twice as fast as a first order one. You can get a second order with each op amp, so with three op amps you can have a 6th order filter. That rolls off at 18dB per octave. An octave by the way is a doubling of frequency.

Second that 8K in the feedback loop isn't doing anything it might as well not be there (replace by a short).

darudude:- Thanks for the complement flattery will get you everywhere.  ;)
I have considered the PWM tutorial although I have some real projects on at the moment. (Latest in the Exhibition area today)

I would set the 3dB frequency at the maximum frequency you want to change the DC output. Then the PWM will be attenuated the maximum it can afford to be with the attenuation dependent on the filter order.
Filter gain and attenuation are essentially separate quantities. If you are designing an active filter ou can have what ever gain you design into it.

Vancouver Reefer

You lost me Mike lol.

So what i think your saying is that:

1.  I need to change R1 to say 10k and R2 to 20K so that the resistors work.

2. Every time you add an op amp onto the output, you in effect double the pwm voltage that can be controlled. Ie:

If i added another opamp with a supply voltage of +/-20v i would then be able to control 0-20v with pwm???

Im only wanting to control 0-10v so if the above circuit works with the new resistor values then i will be happy with that!



I need to change R1 to say 10k and R2 to 20K so that the resistors work.

Making R1 bigger will increase the smoothness. R2 is not doing anything replace it with a short, make it 20K leave it alone it will not affect what this circuit does. In short this circuit is not a very good use of an op amp.

Every time you add an op amp onto the output, you in effect double the pwm voltage that can be controlled.


Every time you use an op amp stage (and appropriate capacitors)  you increase the roll off. Don't confuse roll off with roll up (given your name). Roll off means by how much the high frequencies are cut down. A rate of 3dBs per octave means that by the time you get to 200Hz the signal is only half what it was at 100Hz, and at 400Hz it is a quarter as much as at 100Hz (3dB = half, 6dB = quarter).

would then be able to control 0-20v with pwm?

If you want to control a bigger voltage then just put the collector load of the first transistor up to 20V.


Grumpy: Why is r2 insignificant? Doesn't it effect the gain? On all first order op amp filters I've seen R2 is used for gain. Also according to vancouver's schematic he has now got rid of the transistor and is just using the opamp and the pwm pin.

Also what second order filter would you suggest? just two op amps back to back? or a biquadratic?

Go Up