PWM output to analog input - Page 1
Forum section: electronics / beginners

author: fozzyvis
author_rank: Regular Contributor
timestamp: October 22, 2012, 08:12:03 pm
content: Hi,Subject line isn't really descriptive, but couldn't find a better one.My bench supply has 10k ohm linear pots for setting the U and I levels, driven at 10Vdc.Problem is, they're single turn pots, and there's to much play to set a correct value and have it stay there.I've tried replacing them by a pic pwm output over a BC547 (to connect it to the 10Vdc), and an R/C filter behind it.Schematic in attachment, might be a bit more clear.It's working the way I want it to, except I can't get more than 6.23V at the output.The 100k resistor has over 3volts over it at minimum duty cycle. If I replace it by a lower value the cap discharges to quickly.I've tried a couple of different values but I'm can't seem to find a working solution. I realise it probably isn't possible to get the output all the way to Vdd levels, but this seems really low.So... What am I doing wrong?

author: poptones
author_rank: Frequent Contributor
timestamp: October 22, 2012, 08:21:16 pm
content: Why not go at it the other way around? Use the pic to generate 0-3v and use an opamp to get it to 0-10v?

author: PA0PBZ
author_rank: Super Contributor
timestamp: October 22, 2012, 08:22:25 pm
content: What output do you get when you disconnect the base? I guess it is also something in the range of 6-7 volts.If so, it looks like you are driving a low impedance input on your output, try to find out what you are driving and see if you can make a modification. It could be as simple as a resistor to ground.

author: fozzyvis
author_rank: Regular Contributor
timestamp: October 22, 2012, 08:32:44 pm
content: @Poptones:I looked into using an opamp, but I couldn't find out how to use it to amplify a DC signal. Most of the tutorials/... I found where about AC signals with a positive and a negative supply to the opamp. It seemed a bit hard and I thought this should work as well. Keep it simple and stupid.At least, that's what I thought.@Paopbz:You're right. The output stays around the same level.Does that mean that the input on the PSU that I'm trying to regulate asks too much current? More than "my" circuit can supply?

author: PA0PBZ
author_rank: Super Contributor
timestamp: October 22, 2012, 09:19:52 pm
content: Quote from: fozzyvis on October 22, 2012, 08:32:44 pmYes, exactly. Since there is like 3 volts over the 100K resistor it looks like you are trying to feed a circuit with an input resistance of something like 220K. So either create a low impedance output using an op amp (google voltage follower) or find out what you are trying to drive and see if you can modify it.

author: fozzyvis
author_rank: Regular Contributor
timestamp: October 22, 2012, 10:15:31 pm
content: @PA0PBZFoundthis linkand read through it.Seems it (sort of) works!Output goes all the way up now.Above a certain duty cycle my output on the capacitor seems to go a bit below zero and I can't seem to get the output on the opamp below about 6 volts anymore, but I guess I made a small mistake when wiring things up. Will check again tomorrow when I have a fresh eye.For now I can go to bed as a happy man.Thanks!

author: poptones
author_rank: Frequent Contributor
timestamp: October 22, 2012, 10:35:52 pm
content: Using an opamp AND the transistor is kinda pointless. You should be able to use a pic pin, a capacitor, an opamp and two resistors and get the 0-10V you want.

author: Psi
author_rank: Super Contributor
timestamp: October 23, 2012, 12:52:36 am
content: Yeah, the transistor just makes things complicated for no reason.MCU PWM out -> resistor in series and cap to gnd --> opamp input with gain set to give 10V out at max inputIf you want to get the pwm output a bit more filtered you can use more/better filter stages.A single RC is normally enough for most applications though.

author: GK
author_rank: Super Contributor
timestamp: October 23, 2012, 01:37:43 am
content: If you are going to go the op-amp route, the logical thing to do is to implement an active filter with gain, having a 2-pole or greater roll-off. That way you get much better ripple attenuation for only a few extra passive components.Just for a simple example, a 2-pole Sallen-Key low-pass filter (see the circuits at the lower half of the page):http://sim.okawa-denshi.jp/en/OPseikiLowkeisan.htm

author: mamalala
author_rank: Unknown
timestamp: October 23, 2012, 05:12:38 pm
content: Why not simply rip out the potentiometers and replace them with multiturn pot's? That's what i did with my bench supply here. Git a bunch of nice wirewound multiturn potentiometers from Bourns on eBay, something around 2 Euro each.Greetings,Chris

author: fozzyvis
author_rank: Regular Contributor
timestamp: October 23, 2012, 06:05:12 pm
content: Quote from: mamalala on October 23, 2012, 05:12:38 pmTrue. That would have been the easiet (and my first thought), but then I decided I wanted to do the PWM/RC filter thingie as I've never tried that. Kind of as a learning project. If it wasn't for that, replacing them would have been the way to go.I'm looking at the other answers/options above but will need som time to try and figure things out.My first idea was to try with an opamp (never done that before either), but I mostly found basic explanation about them when used to amplify AC signals with a positive and a negative supply, that's why I abandoned that idea...

author: fozzyvis
author_rank: Regular Contributor
timestamp: October 25, 2012, 08:28:57 pm
content: I've tried to go the opamp route, without the transistor.If this works I'll try to skip the RC filter in front of the opamp and go for the 2-pole Sallen-Key low-pass filter.I had 741CN opamps lying around so I took those.R1 and R2 (R1 between output and inverting input, R2 inverting input to ground) are both 10k Ohm.I didn't really know what kind of values to go for, but somewhere in the kilo ohm region seemed safe.Positive supply to the 10V rail, negative to ground.This should give me a gain of two (Uout = Uin * (1 + 10k/10k), correct?The output doesn't go all the way up to 10V, but max out at 8.8V. I suppose this is normal, and that's what makes a rail-to-rail opamp special.I could take a 7812, put a diode behind it, and have 11.3 V as a positive supply for the opamp.What I don't understand is why the output doesn't drop below about 3.5V.I left the two offset-null pins unconnected as I read that that is the way I should keep them.Could anyone point me in the right direction?

author: ptricks
author_rank: Frequent Contributor
timestamp: October 25, 2012, 09:14:03 pm
content: Your RC filter has the wrong values unless you are operating the PWM at under 1.5Hz .The formula for the values is fc=1/(2*pi*R*C)So your current filter is fc=1/(2*3.14*100000*.000001) or 1.59 HzThe RC filter output will be half of the input voltage, so a 5V PWM will only reach 2.5V after filtering.Feed that into an opamp with a gain of 4 and you have your 10 volts out.In the basic opamp you would use R2 of 3k ohms and R1 of 1k ohms.Gain = 1+(R2/R1)http://www.technologystudent.com/elec1/opamp2.htm

author: GK
author_rank: Super Contributor
timestamp: October 25, 2012, 10:54:45 pm
content: Quote from: fozzyvis on October 25, 2012, 08:28:57 pmMost opamps can only swing to within 2 or 3 volts of the supply rails. If you want the output of you 741 to go down to 0V you will need a negative supply rail.

author: GK
author_rank: Super Contributor
timestamp: October 25, 2012, 10:57:32 pm
content: Quote from: ptricks on October 25, 2012, 09:14:03 pmThe corner frequency of the filter has to be a fair bit lower than the PWM switching frequency if you want adequate averaging and minimal ripple. This is particularly so for a 1-pole filter than only rolls off at a 20dB/decade rate.Also, 5V PWM at 100% duty cycle = 5V out after filtering.

author: fozzyvis
author_rank: Regular Contributor
timestamp: November 03, 2012, 07:36:09 pm
content: I've gone through the options and I'm starting to think towards forgetting about the uC, PWM and opamp and simply using multiturn pots instead.It feels a bit like giving up, but having to create separate 13V and negative rails just to get down to 0 volts seems overly complicated, no?I'm glad I've gained at least some basic experience with opamps through this though...