Author Topic: PWM output to analog input  (Read 7497 times)

0 Members and 1 Guest are viewing this topic.

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
PWM output to analog input
« on: October 22, 2012, 08:12:03 pm »
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?
 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: 00
Re: PWM output to analog input
« Reply #1 on: October 22, 2012, 08:21:16 pm »
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?
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5127
  • Country: nl
Re: PWM output to analog input
« Reply #2 on: October 22, 2012, 08:22:25 pm »
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.
Keyboard error: Press F1 to continue.
 

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
Re: PWM output to analog input
« Reply #3 on: October 22, 2012, 08:32:44 pm »
@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?
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5127
  • Country: nl
Re: PWM output to analog input
« Reply #4 on: October 22, 2012, 09:19:52 pm »
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?
Yes, 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.
Keyboard error: Press F1 to continue.
 

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
Re: PWM output to analog input
« Reply #5 on: October 22, 2012, 10:15:31 pm »
@PA0PBZ
Found this link and 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!

 

Offline poptones

  • Frequent Contributor
  • **
  • Posts: 709
  • Country: 00
Re: PWM output to analog input
« Reply #6 on: October 22, 2012, 10:35:52 pm »
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.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9946
  • Country: nz
Re: PWM output to analog input
« Reply #7 on: October 23, 2012, 12:52:36 am »
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 input

If 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.
« Last Edit: October 23, 2012, 01:02:07 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline GK

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: PWM output to analog input
« Reply #8 on: October 23, 2012, 01:37:43 am »
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


Bzzzzt. No longer care, over this forum shit.........ZZzzzzzzzzzzzzzzz
 

Offline mamalala

  • Supporter
  • ****
  • Posts: 777
  • Country: de
Re: PWM output to analog input
« Reply #9 on: October 23, 2012, 05:12:38 pm »
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
 

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
Re: PWM output to analog input
« Reply #10 on: October 23, 2012, 06:05:12 pm »
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.

True. 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...
 

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
Re: PWM output to analog input
« Reply #11 on: October 25, 2012, 08:28:57 pm »
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?
 

Offline ptricks

  • Frequent Contributor
  • **
  • Posts: 671
  • Country: us
Re: PWM output to analog input
« Reply #12 on: October 25, 2012, 09:14:03 pm »
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 Hz

The 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

« Last Edit: October 25, 2012, 09:15:47 pm by ptricks »
 

Offline GK

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: PWM output to analog input
« Reply #13 on: October 25, 2012, 10:54:45 pm »
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?


Most 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.
Bzzzzt. No longer care, over this forum shit.........ZZzzzzzzzzzzzzzzz
 

Offline GK

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: PWM output to analog input
« Reply #14 on: October 25, 2012, 10:57:32 pm »
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 Hz

The 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


The 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.
Bzzzzt. No longer care, over this forum shit.........ZZzzzzzzzzzzzzzzz
 

Offline fozzyvisTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: be
    • Project site
Re: PWM output to analog input
« Reply #15 on: November 03, 2012, 07:36:09 pm »
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...
« Last Edit: November 03, 2012, 09:07:50 pm by fozzyvis »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf