Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Microcontroller Pulse Width Modulation to Analog DC Voltage

  1. Jul 20, 2016 #1
    What are some effective ways to convert a Pulse Width Modulation from a Microcontroller to a DC Voltage as a function of Pulse Width?

    1. Use a low pass filter to remove the unwanted harmonics and leave only the 0th term of the Fourier Series. What produces a better DC Voltage an Active or a Passive Filter.

    2... Any other methods.


    I want to use a Microcontroller and the duty cycle of the PWM to generate an output voltage that is a function of duty cycle and then use an OP-AMP to increase the voltage to operating range of the DC Motor.

    Example before OP-AMP Gain

    @ 0% Duty DC Voltage = 0V
    @50% Duty DC Voltage = 2.5V
    @100% Duty DC Voltage = 5V
  2. jcsd
  3. Jul 20, 2016 #2


    User Avatar
    Science Advisor

    The motor itself is a pretty good low pass filter so at the most you would need a single pole RC for additional filtering either before or as part of the op-amp driver. This is of course assuming that the pulse repetition rate is sufficiently above the motor mechanical resonance, typically easy to do.
  4. Jul 21, 2016 #3
    Thanks Tom. Have you ever heard of using a pair of PWMs to produce an a DC Voltage
  5. Jul 21, 2016 #4


    User Avatar
    Gold Member

    Driving the motor with a pwm signal will result in linear control (moving the signal from 10% to 20% duty cycle will result in a 100% power increase). The same in NOT true of voltage (changing the voltage from 1 V to 2 V. Controlling the motor directly with a PWM signal is preferred.

    In fact many analog motor controllers will change the analog control signal to PWM to drive the motor itself. If it is a voltage range problem, just provide a power amplifier to boost the voltage of the pwm signal.
  6. Jul 22, 2016 #5
    Okay. I have never use PWM. Can you still use it with a PID controller and an encoder? That is my reason for wanting to filter the PWM to DC Voltage and pass it to a controller then the motor.
  7. Jul 22, 2016 #6


    User Avatar
    Science Advisor

    (Thought I posted the first half of this yesterday but it showed up as still being edited today. So here it is.)

    No, can't say as I have. What did you have in mind?

    BTW, if you are after a linear duty cycle vs speed, as @donpacino pointed out just use PWM directly to the motor without low pass filtering. It works much better

    Yes, it's done all the time in Industrial control. There are probably a few quirks to watch out for, but they tend to be hidden in the 'black box' processing of the drives. One thing that comes to mind is minimum motor movement per pulse versus the control deadband. Get it wrong and it is guaranteed to hunt.
  8. Jul 23, 2016 #7
    Got it. Thanks for the tips. I need to draw up the controller and solve the Laplace transform with the PWM as an input and see if it all makes sense. I needed to ask about the PWM b/c I don't have much exp. with it. And I didn't know if it was common to filter it or use it as is. Thanks
  9. Jun 4, 2017 #8
    Well I know this is an old post. But I did come up with a way to directly control a dc motor with two pwm signals without the use of a bridge.

    1. Setup two PWM signals with the same period and amplitude of Vmax
    2. Pass both signals thru a differential amplifier to get a differential signal
    3. Pass the differential signal thru a band pass filter and only allow the 0th frequency to pass
    4. Filtered Differential signal is now a function of +/- Vmax and the duty cycles of the two PWM.
    5. You can now run the dc motor forward and reverse by changing the relationship between the to duty cycles.

    4. Might be a waste of power but if we keep the current and voltage small and then use an amplifier with a large gain after 5 that should minimize the power loss of the filter and still provide the needed voltage to run the motor.
  10. Jun 4, 2017 #9


    User Avatar
    Science Advisor

    Yea, that works. If the diff-amp has differential outputs and the motor is connected across them, you are using the output stages as the bridge. If it's single ended output, realize that the dual power supplies to the diff-amp and the totem-pole diff-amp output comprise a half bridge.
  11. Jun 5, 2017 #10
    Sweet. I will have look up some of the details of totem pole and half bridge, but I think I understand what you are saying.
  12. Jun 8, 2017 #11
    One question... Can the differential amplifier back feed noise from either PWM signal into the other. I wouldn't want current feedback into the controller/computer. If so would a diode help with this or would it create other issues.
  13. Jun 9, 2017 #12


    User Avatar
    Science Advisor

    Not if everything is working properly. It's sort of like asking 'Can my car crash me into that tree beside the road?' Well, if you steer toward the tree, yes; or if a front wheel falls off, maybe.

    That would probably overly complicate the design, although that couldn't be determined without a complete design review (which I'll leave to others if you feel you need it).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted