Best method for converting PWM to analog signal?

Thread Starter

tvist21

Joined Jun 11, 2021
20
I want to make a circuit that will convert a PWM signal to an analog signal.
I want the circuit to be able to work on higher frequencies as well though (up to 15 kHz).

Would an RC filter be the best method?
Any reference design examples for this?
 
Last edited:

crutschow

Joined Mar 14, 2008
29,779
Typically a low-pass RC filter can be used to recover the PWM analog modulation.
To determine the filter parameters, the following info is needed:
  • What is the amplitude of the PWM signal?
  • What is the highest frequency of the analog signal?
  • What accuracy and ripple level do you need for the recovered analog signal?
Don't see how you could use a DAC for that.
They need a digital/binary input.
 

atferrari

Joined Jan 6, 2004
4,593
Somewhere in the Microchip site there is an old AN on that subject.
Also in the MCHP forum there are some threads on the subject.
 

MrChips

Joined Oct 2, 2009
26,087
I would call an RC LP filter a running-integrator to differentiate it from a standard op amp integrator, which has no resistor in parallel with the capacitor.
I understand what you are saying.
The purpose of the parallel resistor is to create a "leaky" integrator (for those who are not familiar with the concept).
(It also matters whether the input signal is unipolar or bipolar.)

1648660271076.png



1648660293722.png
 

Ian0

Joined Aug 7, 2020
5,097
I would recommend an RCRC filter.
Active circuits might not cope so well with the steep rise- and fall-times of the signal
Inductors are well worth avoiding - if the load impedance is high and the frequency is low, the inductance required would be impractically large.
An RCRC gives a better suppression of the carrier than a simple RC filter.
 

LowQCab

Joined Nov 6, 2012
2,043
Yeah but an RCRCRC Circuit might be better depending on what You require ........

Put this Circuit into your favorite Circuit-Simulator.
The values shown create very little ripple on the Output, at the expense of Response-Time.
With a 20khz, ~12-Volt PWM Input, the Response-Time is something like
~0.1sec from zero to very close to max Output-Voltage-Swing, ( if I remember correctly, it's been a while ).
If that's too slow for your requirements, remove the third RC-Stage.
It will require an Output-Amplifier with
Offset-Voltage and Gain Adjustments to achieve your required Output-Voltage-Range.
.
.
.
PWM to Linear 1 .png
 

Ian0

Joined Aug 7, 2020
5,097
Yeah but an RCRCRC Circuit might be better depending on what You require ........
Note that each of the RC time constants is the same, but the resistors increase by a factor of 10 each time.
This approaches the maximum Q (of 0.5, critically damped) for this type of filter.
Using the same R and C values for each section would give a significantly lower Q (0.33) which is rather to shallow a roll-off.
 

LowQCab

Joined Nov 6, 2012
2,043
That may well be the price-you-pay for being lazy and letting a Simulation do the Math.
It had very good manners during simulation, maybe transients could cause a problem.
.
.
.
 

Ian0

Joined Aug 7, 2020
5,097
I wasn't criticising, just adding further explanation . . .
With a Q that low, it is very well behaved. With 10x resistor values at each stage, it gets the best Q it possibly can, and it's still critically damped.
 

MrsssSu

Joined Sep 28, 2021
190
Yeah but an RCRCRC Circuit might be better depending on what You require ........

Put this Circuit into your favorite Circuit-Simulator.
The values shown create very little ripple on the Output, at the expense of Response-Time.
With a 20khz, ~12-Volt PWM Input, the Response-Time is something like
~0.1sec from zero to very close to max Output-Voltage-Swing, ( if I remember correctly, it's been a while ).
If that's too slow for your requirements, remove the third RC-Stage.
It will require an Output-Amplifier with
Offset-Voltage and Gain Adjustments to achieve your required Output-Voltage-Range.
.
.
.
View attachment 263932
Hi sir:), does this circuit offers PWM signal duty cycle to be proportional to the DC Voltage Gain? Example, a 20% duty cycle would output a 2V , a 40% duty cycle would output a 4V, a 60% duty cycle would output a 6V . :)
 

Ian0

Joined Aug 7, 2020
5,097
Hi sir:), does this circuit offers PWM signal duty cycle to be proportional to the DC Voltage Gain? Example, a 20% duty cycle would output a 2V , a 40% duty cycle would output a 4V, a 60% duty cycle would output a 6V . :)
Yes, if your PWM is 10V amplitude.
[edit] but don’t forget that it is at quite a high impedance. You might need to buffer it.
 
Last edited:

MrsssSu

Joined Sep 28, 2021
190
Why does the integrator circuit from this TI document show a triangle wave?
Your picture shows a sine wave.
My goal is to get a smooth sustained DC signal at 1.4V if I have a 50% duty cycle.
This is my circuit so far, where R5 & R7 reduce the PWM signal so it lies between the op amp's 0.3V - 2.5V rails.
The rest of the circuit is pretty much from the TI document.

View attachment 263962
Hi there, do you want to use LT Spice instead? I think its better and commonly used by a lot of people too. Try to simulate in LT Spice to check your result :)
 

MrChips

Joined Oct 2, 2009
26,087
Why does the integrator circuit from this TI document show a triangle wave?
Your picture shows a sine wave.
I said that an integrator and a low-pass filter are the same thing.

If you want to analyze a filter circuit from a frequency perspective, i.e. to show the frequency spectrum response, you input a sine wave. With a sine wave input, the output will be a sine wave if the circuit is linear, i.e. it does not distort the signal.

A true integrator will output a linear ramp when the input is a DC signal. A positive input voltage will produce a ramp with a positive slope. Conversely, a negative input voltage will produce a ramp with a negative slope (for a non-inverting opamp circuit).

The PWM input must be perfectly balance between positive and negative values, i.e. the average DC value must be zero.

1648729245871.png

If the PWM signal is not balanced about 0V or it is unipolar, e.g. between 0V and 5V, then every time the signal is positive the output voltage will rise. It would keep rising until it has no more room to grow, i.e. it reaches the limits of the opamp's supply voltage. This is why you need a "leaky" integrator, one that self discharges on the off state of the PWM signal. You provide a discharge path for the capacitor by putting a resistor across the capacitor.
1648729968374.png

To function as a PWM to analog converter you are operating the low pass filter with a very long time constant, i.e. well below the LP filter upper cut-off frequency. If you are converting PWM to audio then I would do it in two stages. Firstly I would integrate the PWM signal to produce the triangular waveforms. I would feed this into a second low-pass filter to attenuate the PWM clock frequency.
 

LowQCab

Joined Nov 6, 2012
2,043
A detailed description of the overall end goal of this project,
and the specifications of the Source of the PWM Input,
and all of the required characteristics of the Analog-Output are needed to
create the desired Circuit, and would save a tremendous amount of time by reducing all the
"Nickle & Dime", Q & A, type of discussion.

Everybody's just guessing otherwise.

Every bit of information needs to be summarized and put into a single outline of the project.
.
.
.
 

crutschow

Joined Mar 14, 2008
29,779
If you answer my questions in post #3, we can all give you better answers to meet your requirements.
As of now, we are mostly guessing, as LQC noted.
 

Thread Starter

tvist21

Joined Jun 11, 2021
20
A detailed description of the overall end goal of this project,
and the specifications of the Source of the PWM Input,
and all of the required characteristics of the Analog-Output are needed to
create the desired Circuit, and would save a tremendous amount of time by reducing all the
"Nickle & Dime", Q & A, type of discussion.

Everybody's just guessing otherwise.

Every bit of information needs to be summarized and put into a single outline of the project.
.
.
.
Good point.

The point of this circuit is to control a Buck LED Driver (AL8861Y-13), which has a Vset pin to control the output current.
This Buck LED Driver is stepping down 12Vdc to a constant current of 150mA. I actually have 4 of these buck LED drivers what control individual channels of an RGBW LED.

An external 12Vdc controller that has low side switches would be outputting the PWM signal that needs to be converted to DC. That DC signal would connect to the Vset pin of the Buck LED Driver. The reason I would like the signal to be DC instead of PWM connected to the Vset pin of the Buck LED Driver is because this Buck LED Driver has a 500Hz limit and I want it to be able to accept any controller at any frequency (probably below 30 kHz though).

Ideally I would just be able to find a Buck LED Driver that could accept a much higher frequency.
 
Top