active lpf and simulation accuracy - Page 1
Forum section: electronics / beginners

author: Boschi
author_rank: Regular Contributor
timestamp: March 09, 2021, 10:48:42 pm
content: I want to filter PWM in order to have a cheap DAC, mainly because why not? I'm aiming for 12bit, and a normal 20db/decade filter wouldn't cut so I opted for a sallen key design. just to be sure I simulated the thing in LTspice, and I obtained wonderful results, with a settling time of about 350ms and a ripple of basically 0 (about 5uV pk-pk).how much can I trust these results? and in order to keep the real-world response, there is some best practice to follow or stuff to avoid?the op-amp that I would like to use would be an lm358, the lt1013 used in the simulation is better than of an order of magnitude in everything apart from bandwidth, which (I think?) for a cut off frequency this low it's adequate, and its the main parameter to look for.the PWM frequency is around 2.4Khz, the cut-off frequency is 10Hz and the lm358 supply voltage is +- 15V, so no problem risking going near ground or VCC. it still had some HF spikes, so I filtered some more with a first-order passive LPF and it took care of that (in the screenshot the signal is the clean one). R2 is there to slow down the op-amp a bit, but ill delete it because the two 10K resistors on the other side of the cap already do that.thanks!

author: srb1954
author_rank: Super Contributor
timestamp: March 10, 2021, 12:43:21 am
content: Quote from: Boschi on March 09, 2021, 10:48:42 pmThe results from the simulation will only be as accurate as the models used in the simulation, particularly the active devices. The LT1013 model should be reasonably good but I would carefully check any LM358 model before using it. You should set up some simulation test circuits to verify that the LM358 model conforms with the datasheet graphs.You can better verify the performance of the filter by doing a frequency sweep. This will typically show the response deviating from the desired one at higher frequencies, mostly due to limitations in the op amp performance. This is why the HF spikes are still getting through the active filter stage as the op amp is not performing well enough at the higher frequencies for it to maintain the correct Sallen & Key response.You should also allow for the real world passive components not behaving as well as the ideal components in the simulation. You can approximate such non-ideal behaviour by adding tolerances to components, adding ESR and ESL to the capacitors and stray capacitances between various circuit nodes.In summary, the simulation result is only an approximation to the real world performance but you can make that simulation more accurate by making the component models as close as possible to the performance of real world components.

author: rfclown
author_rank: Frequent Contributor
timestamp: March 10, 2021, 02:06:01 am
content: not answering your question, but another idea... I did a circuit years ago in which a design I was learning from had a filter with OP amps before an A/D. I decided to take an easier route and used a switch cap filter (MAX7401). One capacitor set the frequency, and I had a 8th order Bessel filter. I only had to put a single RC on the output to filter the clock frequency. This was for a 59 Hz corner to feed into a PIC12F675 for a cheap EEG.

author: oliviasmithh900
author_rank: Contributor
timestamp: March 10, 2021, 02:49:07 am
content: I think LM358 will do the trick here but I would also suggest you to go for Microcontroller

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 10, 2021, 04:33:09 am
content: BTW you get three poles basically for free -- it's when you need more, you need a second op-amp (or, well, more can technically be done with one, but the values need to be really precise). Just put an RC out front. The values all need to be recalculated of course:http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htmSo you can get even faster settling, for the same output ripple.Ripple, meanwhile -- the stopband is limited by op-amp GBW. The real pole in the 3rd order filter helps with this, it's right there at the input, no nasty feed-forward. Anyway, you may find LM358 isn't very good. (I mean, if you're settling to ~uV, you'll find it's really not any good at all...) With about a MHz GBW, it won't deal well with PWM switching noise; and its output impedance isn't all that low, at such frequencies. So, easy enough to find better candidates -- higher GBW, lower Zo will perform best here.The simulation should be about right, I'm guessing the LT1013 model is representative (and not like, a 3-terminal ideal op-amp approximation!). LT1013, that's their "improved 358" isn't it? So keep that in mind too. Anyway, if the simulated ripple is adequate, absolutely, go for it.BTW, if you can afford the bias current, consider a pull-down on the '358 output. Or a pull-up, whichever way works best, just as long as it's able to source or sink the worst-case load current, so the output stage remains biased in class A. LM358 has pretty terrible crossover distortion, enough that I don't even like to use it for control circuitry (mind, I stilldo, it's not a complete non-starter for me... just that I don'tliketo).BTW, if you haven't considered so already -- realize the PWM output from a logic device (MCU or whatever) is referenced to its supply. So all the variation, error, noise that's on that supply, goes into your output. For precision, first consider merely buffering it to VREF with a gate -- you can use a CD4069 (>5V) or 74HC1G04 (2-6V), powered by VREF and driven by the PWM source. Think of it as a level converter between dirty logic-level digital and clean analog -- it is a 1-bit DAC, after all!Ed: example:Note the buffering (top left), although I didn't know about how easy 3rd order filters were at the time, for shame.For best results, use an analog switch, SPDT, with the common node going to the filter, and the two ends (NC/NO) going to VREF+ and VREF- (typically GND, but now you have a choice ofwhereto connect it -- ground loop voltages can be subtracted out this way).These methods remove 1st order error (direct supply voltage variation). There's still a 2nd order effect, which is the edge crossing the logic threshold at a slightly different time depending on supply voltage -- this probably amounts to fractional nanoseconds of jitter, so it will only be an issue in extremely precise situations.And hey, PWM was good enough for the Fluke 5700 Calibrator!Tim

author: Boschi
author_rank: Regular Contributor
timestamp: March 10, 2021, 11:19:13 pm
content: @T3sl4co1l what do you recommend as a substitute? even better, what about a ne5532? 10MHZ, 9V/us, and .3R of output resistance at 10khz (It looks like there isn't a graph of output resistance vs frequency). if it doesn't work well, the 358 should still do fine, and if not a potentiometer is still doable (but digital control would be nice).

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 10, 2021, 11:57:26 pm
content: Yeah, that'll be better, or TL072, LM833, etc.Mind that the classic "improved-741" bipolars, like NE5532, are very power hungry: TI says max 16mA at 30V total supply. Poor bastard's gonna get HOT!(Or it's "improved-358", I forget; as I recall, story goes they took a basic amp and cranked up the bias current to reduce noise and distortion. So, it's a rather brute-force design, in terms of performance per idle dissipation.)Or a bunch of OPAs come to mind, if you need lower input offset or noise. Shop around.Tim

author: mawyatt
author_rank: Super Contributor
timestamp: March 11, 2021, 02:43:45 am
content: A few notes regarding the PWM DAC and active Sallen-Key filters, and using LM358 Op-Amps. The concept of using essentially PWM to form a DAC was patented long ago, the patent used a pair of digital inputs but basically was PWM, see patent 4958159, which has long since run out.The stop band rejection of the LM358 isn't very good due to the rather high open-loop output impedance of the LM358. As mentioned by forcing the output to have the NPN (or PNP) output emitter follower transistor biased on at zero output with a simple resistor to Vee (or Vcc) this helps lower this impedance. Also this 2nd Order Sallen-Key configuration has a path from the first capacitor directly to the output, and relies on the output impedance to attenuate this path. Fast edges can couple thru the input resistor, or around it by the parasitic PCB and/or device capacitance and thru the 1st filter cap directly to the output. This edge contains high frequencies where the LM358 output impedance isn't low and in fact inductive, which certainly doesn't help with attenuation. Often a simple series R and shunt C to ground can eliminate this thru coupling effect. You can simply split a portion of the input R into two resistors and add shunt C to ground between them. The value of the shunt C should be less than 10% of the 1st Input capacitor and the series resistor 10% of the 1st resistor to not have a serious effect on the transfer function near the 3dB corner. We used these concepts often with good results and this with the output impedance reduction were published in EDN ~30 years ago.On another note, you can built a 3rd Order Butterworth LP or HP with all equal Rs and Cs. This makes it easy to get actual measured precise filter performance and the LP has a series R shunt C to ground input which greatly attenuates any high frequency components from even entering the active filter function. This concept was also published in EDN long ago, and think Walt Jung of Analog Devices put this in his Active Filters book which I don't have (he discussed it after we published in EDN). You can reduce the unity gain amps to 2 by moving the input RC to the output but you lose the input shunting of higher frequency effects. Emitter followers can replace the unity gain amps but you lose the precise Butterworth transfer function. We utilized these 3rd order equal valued component Butterworth filters in numerous projects long ago, also with good results.Using simple CMOS to swing from VDD to Ground precisely, and use an accurate VDD from a reference has been a technique we've used for many decades from the mentioned PWM DAC, to the ultra-precision voltage divider without precison components (patent 5030848), and more recently to a precise square wave used for DMM AC calibration. Very powerful technique and good to see these concepts being utilized!!Here's a few simulations showing the effects of a a moderately fast edge pulse (3ns) coupling thru the Sallen-Key LM358 (discrete transistor model) based filter mentioned above. Note the AC response (Green Trace) to the standard configuration and the stop band bottoming out at only 8KHz!! Then the output becoming inductive as predicted and rising stop band. Now note the improvement (Blue) with the response with splitting the input resistor (10K & 90K) and adding a shunt C of 1000pF, and just adding the output resistor (1K) to Vee (Red) forcing the NPN output emitter follower device ON and finally doing both enhancements (lite Blue). The 2nd plot shows almost no effects on the pass band response by any of these techniques. The final plot shows the same color plots as above but with a 5 Volts 3ns rise and fall pulse of 100us with 10% duty cycle, please note the effects of the pulse edges wrt to the enhancement techniques.Anyway, hope this helps with the use of PWM DAC and the limitations of the classic Sallen-Key filter, and simple remedies of the issues related to poor output impedances of the LM358 and many other popular op-amps.Just realized the use of the series R splitting the input resistor was utilized in our precision ramp waveform generator that got published and made the cover of the 1992 and 1993 EDN Design Ideas Booklet, shown below. You can see the 3rd Order filter splits the 1st resistor to help attenuate the edges of the CMOS pulses.Best,