1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PWM to DC converter?

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by BrianG, Dec 18, 2005.

  1. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    Hello,

    I'm trying to design a simple circuit to convert a PWM signal to variable DC. The PWM signal is a 5.5vpeak 50Hz square wave of varying duty cycles. However, I want a clean DC output. So, at say, 10% duty cycle, I want a clean .6vDC; at 20% I want a clean 1.2vDC; and so on until at 90%, the DC output is a clean 5.4v DC.

    Really, what I'm trying to do is create a circuit to take the PWM signal from a remote control car (hobby class) receiver (which would normally go to a servo) and have the output on (~6v) or off (0v), but would be nice to have the variable aspect for other uses. So far, I figured I'd use a basic op-amp input stage to buffer the signal against loading, use *something* (this is where I'm stuck) to filter the PWM signal to a clean DC level, and use another op-amp as a comparator to trigger the output. The buffer and the comparator works (easy enough), I'm just stuck on the PWM filtering part.

    I've searched here and googled for some clues but everything I've found talks about converting DV to a PWM signal, not the other way around. Any clues or anything would be greatly appreciated! Thanks in advance!
     
  2. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    To turn a PWM signal into a DC voltage, you could low-pass filter it... but at a frequency of 50Hz you would really need a huge time constant and it would be very slow to react to changes in duty cycle... in other words, not very practical.

    Personally, I would do it with a microcontroller, using a timer and an interrupt it wouldn't be that hard to measure the width of the pulse. That would eliminate the need for the buffer and comparator, just provide the digital output right from the microcontroller. not to mention, examples of using microcontrollers to interpret servo signals are already out there so you'd have something to start from
     
  3. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    Thanks for the reply.

    Since the output of the cap/resistor network is feeding the input of another high-impedance (10^12ohms) op-amp, I can use a smaller cap/resistor. That should solve the time constant issue. I was shooting for a simple circuit - a microcontroller setup is a little too complex for me to get into. I think I'll stick with analog for now. :)

    I'm goingo to borrow an oscilloscope from work tomorrow so I can see more of what's happening. There's only so much my old Fluke 87 will show me.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Roff

    Roff Well-Known Member

    Joined:
    May 16, 2003
    Messages:
    7,757
    Likes:
    89
    Location:
    Idaho, USA

    You need a lowpass filter. The tradeoffs are in complexity, delay, and ripple. For example, I tried a 3-pole active Bessel with cutoff frequency=5Hz. In this case, the ripple for your application would be 18mv p-p, and the delay from when the signal is applied to final value is around 120ms. You can get less ripple with a more complex filter, or with lower cutoff frequency, or both. The price you pay is more delay from a change in duty cycle to the new value being settled. Perhaps we can zero in on a solution if you can clarify what you can tolerate in terms of ripple and delay.
    Evandude's solution should have lower delay, although it would be very susceptible to noise and jitter.
     
  6. Roff

    Roff Well-Known Member

    Joined:
    May 16, 2003
    Messages:
    7,757
    Likes:
    89
    Location:
    Idaho, USA
    The op amp you choose has no bearing on the time constant(s) required. Time constant is the product R*C. If you make R smaller, C has to get bigger, and vice-versa.
     
  7. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    I think I can see where he was coming from with it. what you say is true, and whether you use a big R, or big C, or mid-range for both won't matter as long as the opamp has high enough input impedance to be considered a negligible load on the output of the low-pass filter. But if for some reason it had a lower input impedance, you would have to lean toward a larger C and smaller R.

    But, as BrianG himself pointed out, the opamp input impedance is so high as to be considered infinite...

    But what Ron says is right, using a straighforward analog approach of low-pass filtering, it's going to be all about tradeoffs of ripple vs. response time. I've got a half-baked idea floating around in my head for a way you might be able to achieve much faster response without the ripple problems and without a microcontroller, however it does involve a bit of digital logic; not sure if you were trying to keep it strictly analog, or just avoid programming :)
     
  8. Roff

    Roff Well-Known Member

    Joined:
    May 16, 2003
    Messages:
    7,757
    Likes:
    89
    Location:
    Idaho, USA
    Evan, I have a half-baked idea that is basically an integrator and a sample-and-hold. The integrator would get reset immediately following the sample-and-hold, before the beginning of the next cycle. It would require a calibration pot, and a very stable integration time constant or periodic recalibration.
    This circuit would also be much more susceptible to noise and jitter than the lowpass filter.
     
  9. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    that's pretty much where I was going with my idea too. I guess it will all come down to his requirements, and how stable the signal is.
     
  10. Roff

    Roff Well-Known Member

    Joined:
    May 16, 2003
    Messages:
    7,757
    Likes:
    89
    Location:
    Idaho, USA
    Oh, and a very important requirement: The frequency must be constant and stable for this to work.
     
  11. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    you're right, for general duty cycle measurement. In the specific case of measuring servo pulses, it wouldn't be so critical because only the width of the pulse is important, not the frequency at which they occur, which can vary widely (50Hz is a normal value based on about 20mS between pulses, but that is just to ensure smooth operation, you can pretty much pulse them as infrequently as you like). Based on that, it might be better to build a circuit that is specific to servo pulse measurement, rather than building one that is for general duty cycle measurement and adapting it for use on a servo.
     
  12. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    Wow, quite a few replies. Sorry it took so long, had a long day at work.

    Anyway, I was able to borrow a crappy o-scope from work, but was able to make some more measurements and I know what my problem is now.

    The frequency is right about 50Hz. By looking at the o-scope, it's actually around 52Hz, but that could be a calibration issue, the fault of a tiy display, or maybe that's what it is supposed to be. The frequency is constant whether channel 3 is in position A or B - just the duty cycle changes. Peak voltage is right around 4.8v.

    When channel 3 of the receiver is at position A, the duty cycle is 4%. When it is at position B, the duty cycle is 2%. Not much of a difference there to work with! Those servos must be pretty precise indeed!

    I checked these values on the throttle channel (2) and the steering channel (1) and they are the same, except I have a tad bit more range in duty cycle, but not much (maybe an extra 2% over the full ranges).

    So, my question now becomes: how do I turn a 2% change in duty cycle to a 0v or 6v output? The comparator in my original design would have to be VERY precisely set! If this cannot be accomplished using analog circuits, I'm open to other methods. However, the whole circuit must be kept very small. To complicate this futher, this circuit will be in an R/C truck along with servos running and a high amperage PWM drive motor controller driving a 3 phase brushless motor drawing upwards of 60-70 amps @ 14vdc (yes, you read right; 60-70 full amps), so noise can be an issue.
     
  13. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    well as I said, servos are PWM but they aren't based on duty cyle... the frequency at which the pulses occur is not important, 50Hz is just a typical value... what is important is the width of the pulses alone, NOT their width compared to the width of the cycle. if you try to do it as duty cycle, you will be dealing with like a 2% change as you found out... when really what you are dealing with is a pulse that varies between 1mS and 2mS, so what you need to focus on is measuring the width of that pulse, not finding the duty cycle.
     
  14. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    OK, that makes sense. So, how can I go about using the pulsewidth to generate the output I want simply, and using a design fairly impervious to noise (although I could shield the circuit).

    Thanks in advance!!
     
  15. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    of course a microcontroller is basically the smallest solution, you could use an 8-pin IC and no external parts except maybe a voltage regulator and decoupling cap...

    or maybe make a circuit where when a pulse comes in, it charges a capacitor up from zero volts, then using a comparator, if it crosses some voltage threshold, latch the output high... and if falling edge of a pulse is encountered and it isn't above the threshold, reset the output...
    not a fully developed idea, it just popped into my head, but it might give you something to start from...
     
  16. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    Hmmm, I've never worked with microcontrollers (at least that I can remember). Can you recommend some type of tutorial on common ucontroller ICs, how they work, and some sample applications? I was hoping this was going to be simple. hmmph.
     
  17. evandude

    evandude New Member

    Joined:
    Oct 1, 2003
    Messages:
    1,395
    Likes:
    5
    Location:
    Maine, USA
    I'd recommend the PIC series by microchip. there are a lot of tutorials, such as nigel goodwin's set of tutorials... getting into microcontrollers can take some time though... if you are looking for a workable solution for your application without a big delay, I still think that last idea I mentioned could work, if it makes any sense to other people :lol: if not, I can try to expand it a bit.
     
  18. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    How about some sort of pulse-stretcher/multiplier which will turn my 2ms and 4ms pulses into something like 10ms and 30ms, respectively? Then I can use my original idea for the rest since those duty cycles, 20% and 60%, will provide more of a change in capacitor charge. Yes, I realize the duty cycle is not important, but that's what I'll be working from.

    Thanks a bunch for the assistance! It's been about 10 years since I've really worked with electronics so I'm a bit rusty. :oops:

    Oh, and after reading some other posts on here; this isn't a homework assignment or anything. Pure hobby. :)
     
  19. Roff

    Roff Well-Known Member

    Joined:
    May 16, 2003
    Messages:
    7,757
    Likes:
    89
    Location:
    Idaho, USA
    2% 0f 20ms is only 0.4ms. Can you clarify your range of pulse width?
    I have an analog design for you that I can post if you are interested. It converts the pulse width range to a zero to 5 volt (or whatever) DC voltage, but I need to know the range.
    It's not simple. It has 3 ICs, a few transistors, and a handfull of resistors and capacitors.
    If that's too complex, I won't post it.
     
  20. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    You can use a monostable to stretch the pulses, but you first need to subtract the minimum value (1mS), so your pulses are then 0mS to 1mS, instead of 1mS to 2mS.

    You might try googling for speed controllers?, they work in a similar way.
     
  21. BrianG

    BrianG New Member

    Joined:
    Dec 18, 2005
    Messages:
    88
    Likes:
    0
    Location:
    Des Moines
    Sorry Ron, I guess I figured wrong in some of my percentage calculations. The pulses are indeed 20ms (50Hz), and have on times of about 1ms at the low end and 2ms at the high end (values may be a tad more or less - hard to read on the o-scope I'm using). Due to the size of the circuit I plan to make, I'd like to keep it as simple as humanly possible without trying to resort to surface mount. However, if you wouldn't mind, please post your idea. If my approach does not work, I might try something new. I am a bit rusty, but analog is what I'm most comfortable with. The microcontroller idea, while possibly the easiest and/or most elegant in the end, is not something I've dealt with and would require some background learning before I tackle it.

    So far, the monostable multivibrator approach seems to be the one I'll try next (thanks Nigel). Adding a 555 timer and a couple support components should be quite simple while not adding too much complexity to my existing circuit.

    Thanks to everyone for their ideas - it's appreciated!
     

Share This Page