Electronic – Sallen-Key filter using LM358 doesn’t act as supposed to when fed a 31.25 kHz PWM

active-filterfilteroperational-amplifierpwm

I want to create an Analog Voltage by filtering a PWM signal. After some googling, I found an active low pass filter topology with -40db/decade called the Sallen-Key topology. I tried implementing a circuit which would take a PWM with 31.25 kHz frequency and filter out anything but the DC component. When simulating with LTSpice this seems to work (if I use a dual supply), however when implementing on a breadboard using the LM358 dual Op-amp, the circuit behaves weird…

This is the circuit (OP27 is in my case the LM358):

It works at high duty cycles, but at low duty cycles really large voltage spikes appear.

This is how it behaves, as seen from my oscilloscope, at over 70% duty cycle (NOTE: RED is PWM input and blue is filter output):
At relatively high duty cycle the circuit works as expected, transforming a PWM value into an analog voltage

And this is how it behaves at about 50% duty cycle:

Notice the large, over 1V voltage spikes.

I did an FFT on both signals with following results:

High duty cycle:
High duty cycle

Mid-Low duty cycle:

As you can see, no extra harmonics appear, their amplitude just changes with varying duty cycle, however the filter seems to respond really weird.

Does anybody have an idea why this problem appears and how to fix it?

Best Answer

This looks like crossover distortion in the amplifier- it's really not fast enough to respond to the 30kHz input. You can try a pullup resistor of a few K on the output, but that will prevent the output from going all the way to ground, unless you have a negative supply.

This kind of thing (dependence on op-amp output impedance) is one of the reasons why I don't particularly care for S-K filters. You might do better with a passive filter, at least for the first stage where you've got very fast edges.

Related Topic