Microcontroller Pulse Width Modulation to Analog DC Voltage

AI Thread Summary
Effective methods to convert Pulse Width Modulation (PWM) from a microcontroller to a DC voltage include using a low pass filter to eliminate unwanted harmonics, with discussions on the benefits of active versus passive filters. The PWM duty cycle directly correlates to the output voltage, with examples showing voltage outputs at varying duty cycles. Directly driving a motor with PWM is preferred for linear control, while filtering may be necessary for PID controllers and encoders. A novel approach involves using two PWM signals with a differential amplifier to control motor direction, emphasizing the importance of proper design to avoid noise feedback. Overall, understanding PWM and its applications in motor control is crucial for effective implementation.
SSGD
Messages
49
Reaction score
4
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.

Background.

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
 
Engineering news on Phys.org
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.
 
  • Like
Likes cnh1995, jim hardy and SSGD
Thanks Tom. Have you ever heard of using a pair of PWMs to produce an a DC Voltage
 
SSGD said:
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.

Background.

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

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.
 
  • Like
Likes SSGD, berkeman and Tom.G
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.
 
(Thought I posted the first half of this yesterday but it showed up as still being edited today. So here it is.)

SSGD said:
Thanks Tom. Have you ever heard of using a pair of PWMs to produce an a DC Voltage
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

SSGD said:
Can you still use it with a PID controller and an encoder?
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.
 
  • Like
Likes SSGD
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
 
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.
 
SSGD said:
2. Pass both signals thru a differential amplifier to get a differential signal
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.
 
  • #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.
 
  • #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.
 
  • #12
SSGD said:
Can the differential amplifier back feed noise from either PWM signal into the other.
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.

SSGD said:
If so would a diode help with this or would it create other issues.
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).
 
Back
Top