Non Linearity In PWM Low Pass Filter

Hello everyone, I am trying to convert PWM to DC voltage via a low pass filter. The frequency is 40kHZ and then i have used a LM358 Op amp to amplify the voltage. I am varying the PWM from 9% to 100%. However, when i get to 100% the linearity of the DC voltage isnt working and the voltage is less than expected. I am aware of LM358 being an old IC , and i have tried using a newer one, but the results are still the same. I realized that the non-linearity stems from the Low Pass filter itself, i cant seem to solve it especially for the high duty cycle value. Any help is much appreciated. I have attached the image.

Hiw about giving us the information
about your circuit:
(I fon't see any units anywhere. Is there some reason you are not telling us the following ?
Please ste the following in the text of your
post.:
Input voltage : ?
arduino used: ?
Op amp voltage 25V ? (to an arduino ?)

Op amp gain: (looks to be 5)
Use an LT1215 op amp.
Low Pass Filter values ?
State them in the text of your post .

Thanks for the reply...
Input voltage : 25V DC input
arduino used: Have not used an Arduino yet, simulated using 5V 2mA PWM CMOS Supply

Op amp gain: Gain is 5

Low Pass Filter values R=4kOhms and C=47u

The Opamp used is LM358, however i can try using the one recommended above. When i simulated the filter part in the LtSpice, i got linear values of the DC voltage up until 90% Duty Cycle. So i feel that part of the error stems from the filter.

Do you want to tellbus why the op amp supply is 25 V when the input voltage is 5V ?
Does that make any sense ?
If your trying to amplify a 5V input with a gain
of 5 to obtain a 25V iutput don't you think you should say that in your post ? I did't see it.
All I saw is your not getting a rail to rail output out if a NON--rail to rail op amp. So what else us new?
The problem is less to do with the op amp your using being old than to do with your knowledge
( or lack thereof) if op amps. An LM358 can
operate up to 36V. If you changed the op amo
supply voltage to 30V I think you'll get a different
result. Try googling "rail to rail op amps".
(you'll NEVER get 25V out of an LM358 running
on 25V. What were you thinking ?
There is nothing wrong with the LPF.
You just don't know about 'headroom'.

Hello Samuel,
Welcome to the forum.

If I have understood correctly you want to get an output of 25V using a 25V supply, is that correct? You are going to struggle to do that. To stand any chance you need a rail to rail op-amp, but if it were me I wouldn't even try, I'd use a supply voltage maybe 2V or more above the maximum output I was looking for.

Are you just experimenting to learn stuff or is this for a particular application?

Hello Perry
Thank you for the reply, I fully understand your advice and i will apply it to modify my circuit. I am doing some simulations for a project proposal, and that is why i am analyzing this part.
One other question, I have another problem though with the low pass filter. I need the filter to convert the PWM to DC voltage linearly. I simulated the filter stage alone without the opamp and the voltage is linear up until 90% and then the linearity is not observed anymore, the voltage generated is lower. I have tried even having 4th order filter, but i keep getting a less linear filtered DC. Could there be a solution to this problem.
Thanks

Oh i will also check about the "Headroom"..it will solve some of the linearity problems
Thanks

It does this up until 90% and then the linearity is not observed anymore

I assume that's because of the op-amp. What do you get if you disconnect the op-amp from C5 / R1 (it it R1?) junction and just measure the voltage at that junction? Is that linear? I don't think adding more filter stages will help.

I realized that the non-linearity stems from the Low Pass filter itself,

No your non-linearity is not coming from the filter it is coming from the op-amp. A simple RC filter is linear, that is just physics.

Thanks for the replies.
When i isolate the filter i get a nearly linear relationship i have attached the results in the picture. The maximum pwm is 25u...The graph is only a slight offset from the linear trendline. Ought it be purely linear?

Did you change the op amp supply voltsge yo 30V
like I told you ?

Yes i did change the voltage as you advised, and for the voltage obtained is different.

Hi,
Why haven't you built this project to prove its operation?

Any reason you aren't using an external DtoA converter to ensure your linearity?

Now is the time to get down and dirty, get your project parts out and connect it all.

What is the application?

Thanks.. Tom.. :slight_smile:

The 'application' is getting a passing grade in the class.

Are you going to tell us the output voltage obtained
after changing the LM358 supply voltage to 30V ?

The graph is only a slight offset from the linear trendline. Ought it be purely linear?

I would be suspicious if it were exactly linear. Nothing is perfect, everything has errors.

Samuel_III:
Hello everyone, I am trying to convert PWM to DC voltage via a low pass filter. The frequency is 40kHZ and then i have used a LM358 Op amp to amplify the voltage.

The LM358 is too slow for this, it starts to run out of signal swing at audio frequencies and will be attrocious at 40kHz.

TomGeorge:
Hi,
Why haven't you built this project to prove its operation?

Any reason you aren't using an external DtoA converter to ensure your linearity?

Now is the time to get down and dirty, get your project parts out and connect it all.

What is the application?

Thanks.. Tom.. :slight_smile:

Hi Tom
i came up with the Spice simulation as a start point, as i am still new in this field, and i aim to improve the schematic first then try it on a real circuit. But i will also research more on your advice .regards

Your Spice model of the LM358 must be wrong!

PerryBebbington:
I would be suspicious if it were exactly linear. Nothing is perfect, everything has errors.

Okay Perry, its a bit close to the linear profile, let me work on the aforementioned suggestions to try and improve it.

MarkT:
Your Spice model of the LM358 must be wrong!

I have tried other models of the same op-amp, but i have the same result.