Sallen-Key Low Pass Filter for converting PWM to DC - Page 1
Forum section: electronics / beginners

author: bitshift
author_rank: Regular Contributor
timestamp: December 26, 2015, 06:36:20 am
content: Hi all,I'm designing a filter to convert PWM a to DC value. What I've come up with is a Sallen-Key low pass filter into a standard RC low pass filter. The Sallen-Key filter does the bulk of the filtering, the RC filter is there to smooth out the spikes at the PWM frequency. R4 and R5 are there to set the gain of the filter to 1.22 since I need a range of 0-6V from the 5V PWM signal. R1=R2 and C1=C2 are chosen so that the Sallen-Key has a maximally flat response in the pass band. I've included a schematic of the circuit and the simulations in LT Spice:The blue trace is after the RC filter at R3. The green trace is after the Sallen-Key filter at the junction of the op amp and R3.Zoomed in section once the filter comes to a steady state.I've come up with the values for the filters by trial and error. My questions are quite broad so please bare with me:What sort of procedure would a real engineer use to design such a filter?How would one choose the cutoff frequency for the filter?What considerations need to be taken into account regarding the size of the resistors and capacitors? For example to get the same cutoff frequency you could either go with a large resistor and small capacitor or a small resistor and large capacitorIs it necessary in such an application to choose R1=R2 and C1=C2 for a maximally flat pass band?I've also attached the LT Spice simulation.

author: pmbrunelle
author_rank: Regular Contributor
timestamp: December 26, 2015, 07:33:54 am
content: 1. I don't think that there's a step-by-step procedure to design anything. But in general, start off with the simplest thing that works. I would convert the 0-5 V PWM to 0-6 V PWM, and then look into low-passing it after. Can you do this without an opamp?2. The first step is to determine how much determine how much ripple attenuation you want, and then based on the order of filter you expect to use, you know the attenuation per decade above the corner frequency. So then you know how many decades the corner frequency should be below the PWM frequency. But if the corner frequency is too low, probably the filter will be slow-responding in the time domain. So, hopefully you can find a good compromise.3. Impedances too low - excess loading of opamp/previous stage, distortion, costly/hard-to-find passives (ex. C0G doesn't exist in high value capacitances). Impedances too high - opamp input currents can become significant, parasitic parameters become more important, more noise.4. That combination of parts doesn't give Butterworth, but you shouldn't care about a maximally flat frequency response anyway. For this kind of filter, you want something that doesn't ring in the time domain.

author: bitshift
author_rank: Regular Contributor
timestamp: December 26, 2015, 08:27:20 am
content: Thank you for your responsesQuote from: pmbrunelle on December 26, 2015, 07:33:54 amJust to understand, what are you trying to avoid by moving the gain before the filter?Quote from: pmbrunelle on December 26, 2015, 07:33:54 amAre there any rules of thumb when it comes to picking how many decades the corner frequency should be below the PWM frequency?Quote from: pmbrunelle on December 26, 2015, 07:33:54 amAhhh ofcourse! Thank youQuote from: pmbrunelle on December 26, 2015, 07:33:54 amIs this because of the RC filter afterwards or the gain on the op amp?

author: bitshift
author_rank: Regular Contributor
timestamp: December 26, 2015, 08:27:59 am
content: Quote from: blueskull on December 26, 2015, 08:08:10 amWhat type of filter would then be better?

author: Kleinstein
author_rank: Super Contributor
timestamp: December 26, 2015, 09:36:11 am
content: In principle the filters are OK, at least at relatively low frequencies. But one should definitely have the passive RC filter first, so the OP will not see the highest frequency components. A second passive stage might be worth while.As allready mentioned use a higher impedance (more like 10-500 K): This makes filter capacitors smaller and the load to the OP is not as large. Also the ouput impedance of the PWM source is less important (FET on resistance is temperature dependent). No need to use super stable capacitors - they just have to be low leakage.Having moderate gain in the filter stage is OK and often much easier than amplifying the PWM signal.Filtered PWM is good for slow, high resolution outputs. So the reponse close to the transistion does not need to be flat - there usually is a large unused band. The resistors don't have to be the same at the filter - usually slightly different values are better. For convenience often same capacitor values are used.If high resolution (e.g. > 12 Bit) and relatively fast response is needed, one should consider not using simple PWM, but a second level of modulation: The PWM output software modulated between two values to give higher resultion. This makes it a first order sigma delta converter.

author: pmbrunelle
author_rank: Regular Contributor
timestamp: December 26, 2015, 04:05:57 pm
content: If you have the 6 V rail already available, then I would prefer for the PWM to be generated by alternately switching between the 0 V rail and 6 V rail.If you have gain-setting resistors in the filter stage, the output voltage range will be affected by the resistor tolerances. I don't know if this matters to you.Without the gain, no matter what parts you use, regardless of initial component tolerances (within reason), and regardless of any temperature drifts, the low-frequency/DC response will be similar, so your filter will work the same for the purpose of turning PWM to DC.1st order = 20 dB/decade2nd order = 40 dB/decade3rd order = 60 dB/decadeAnd so on...

author: bitshift
author_rank: Regular Contributor
timestamp: December 27, 2015, 09:27:58 am
content: Quote from: Kleinstein on December 26, 2015, 09:36:11 amIn the spice simulation, moving the RC filter before didn't seem to make a difference. To be sure, I tested it on the bench and it's much betterAC coupled output of the filter with the RC filter second:AC coupled output of the filter with the RC filter first:Quote from: Kleinstein on December 26, 2015, 09:36:11 amAfter increasing the resistors and decreasing the capacitors at the Sallen-Key filter by an order of magnitude, the step response was greatly improved. Could this be because of the smaller load on the op amp?

author: Kleinstein
author_rank: Super Contributor
timestamp: December 27, 2015, 10:06:05 am
content: With the RC filter, the load also has an influence, usually raising the transition frequency. You have to think the resistor before and after the resistor to be effectively in parallel. So the resitor following the RC filter should be at least as high as the one of the filter, better larger by factor of 2-10.With higher impedance of the circuit, the OPs output looks more like low impedance. Also the type op OP might be important - if it's an LM358 /324 one could try something like 1 K to ground at the output, to make the output stage lower impedance.In a perfect linear world (just as the spice simulation with simplified OP modells), there should be no difference if the filters are changing position. The not so perfect parts, like limited slew rate and other more subtile imperfections can make a difference.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 27, 2015, 01:39:44 pm
content: http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htmIn general, practical filter types have multiple sections where the cutoff frequencies (and the amount of peaking as they cross cutoff) are spaced around the desired cutoff frequency, in such a way that the peakiness of one stage compensates for the droop of another, and so on.We refer to the cutoff frequencies of a network as poles (more exactly, poles are the factors in the denominator of the equation for Vo/Vin). Practical filter types (the named ones: Bessel, Butterworth, Chebyshev, etc.) are synthesized in this way, starting from a theoretical polynomial and working backwards to find the parts values. (In an active filter, the values are always defined by R*C time constants. In a passive one, it's the resonant frequency 1/(2*pi*sqrt(L*C)).)The poles are generally placed on a circle (or ellipse, or off-center), and are always mirror symmetrical. So if you have an even number of poles, all are complex (= they have some amount of ringing or peaking*). If you have an odd number of poles, exactly one pole will be real (i.e., no ringing/peaking -- a straight up RC).*Which, by the way, means you must have active gain, or LC reactances, to be able to implement such a filter. An RCRC filter can't achieve any peaking, so while it's somewhat sharper than a single RC, it's still pretty poor!What this means is...Any time you have a simple, even order, low or high pass filter, you can add an RC in front of it (or after it, but before is better) to get a one-degree-better filter!Why is it better in front? The op-amp output is simply the output, period, so you can use that to drive other loads without much worry.The downside is, it shifts all the parts values, but that's where the above calculator(s) come in.As for guessing -- you can do pretty well that way, but you might've missed something on, effectively -- where you put those poles. Was it sharp enough? Peaked? Is the RC rolloff in the right place? This way you'll know everything is in order.Also, the nice thing about lowish order filters (<= 3rd, maybe 4th and 5th too) is they aren't really precise enough to be a big deal, so you can fudge the R and C values into standard values without too much trouble. Use the AC Analysis (frequency sweep) to tell what frequencies are best.Also also, as for edges -- you'll notice an op-amp is most certainly not an ideal gain block (indeed, necessarily so!). It's also not an ideal integrator (which is, at least, a much better approximation to the real thing; and this property skews the RC values needed, based on the amp's GBW). It takes some delay before the output reacts to the input, and this means some "edges" from the input will always couple through an active filter. It can be worthwhile to add a small LC or CLC filter in front, even if the cutoff frequency is quite high (on par with the switching frequency, even), to help attenuate these edges because the op-amp can't do it alone. And, if the LC cutoff frequency is much higher than the filter's, you probably don't need to worry about tweaking the filter's values further.An LC filter has impedance as well as frequency, so you need to match it to the system impedance. If you start with a 3rd order active filter, then you could consider the first capacitor (which is in parallel with the input signal, a good place for additional filtering). If you split that capacitor into two halves (each C' = C/2), then add an inductor between them (such that L ~= R^2 * C', where R is the parallel equivalent of the two adjacent resistors), you'll get that inductive filtering action as well.Tim