3rd order Sallen Key Unity Gain LPF - stability question - Page 1
Forum section: electronics / projects

author: JDW
author_rank: Frequent Contributor
timestamp: April 24, 2020, 03:20:33 am
content: I have been testing a 3rd order Sallen Key LPF on a breadboard and so far have not had problems, but I am curious about the potential for instability and oscillation. My existing design acts as a LPF but also a low source impedance input to an ADC pin on my PIC MCU. That is important since the maximum recommended impedance on ADC inputs on my PIC is 10k-ohm. I used the following online calculator to create the LPF design:http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htmR1 = R2 = R3 = 330k-ohmC1 = C2 = 1nFC3 = 480pFfc1 = 482.29HzMy chosen Op-Amp is a Microchip MCP601:https://www.mouser.jp/datasheet/2/268/21314f-29012.pdfHere's a partial schematic:The input comes from a car at R1 & R4. Specifically, there's an audio keypad on the steering wheel of many Toyota cars that let's you adjust Volume and Seek. When those buttons on the steering wheel are pressed, you get the voltages shown at right in my schematic. The voltages are fixed voltage for as long as the state shown persists, and the voltages seem to come from a resistor voltage-divided on the car side, with a maximum resistance of 3k-ohm. I am using my PIC16F1503's ADC input to read the voltage level via my LPF so my PIC knows what button is being pressed.As you can see in the okawa-denshi calculator above, the component values I used do not oscillate. However, if I were to plug in different resistance values within a 5% tolerance, I sometimes get shown an oscillation frequency. 5% resistors are cheaper than 1%, which has me thinking about oscillation.FYI, I am using large value resistors because the input impedance of the OP AMP is very high and can easily accommodate that. Also, using larger resistances allows me to use smaller capacitors, which is highly desirable for a shorter capacitor discharge time, which allows for a shorter ADC acquisition time.All said, I am curious to hear thoughts about the stability of my design over the tolerance range of the parts chosen on my schematic and whether it would be safe to use 5% tolerance resistors.Thank you.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 24, 2020, 06:01:52 pm
content: Did you adhere the instructions on proximity of bypass capacitor? Also, did you include an additional 1uF within 100mm?Can you show us your board or circuit hookup?

author: JDW
author_rank: Frequent Contributor
timestamp: April 24, 2020, 11:36:43 pm
content: Quote from: Wimberleytech on April 24, 2020, 06:01:52 pmI certainly appreciate your reply, but I'm a little confused by what you wrote. As I said, I have found NOTHING WRONG in my BREADBOARD testing of the circuit shown in my schematic. And as you can see in my schematic, I have a 0.1uF bypass capacitor (C4) on Vdd. And of course it is in close proximity to the Vdd pin. There is no instability at all IN MY TESTING. But I don't know if such will be the case as temperature changes have an impact on resistance values (within their tolerance, of course).The reason I posted is because I don't have extensive experience in FILTER DESIGN, and certainly not a 3rd order Low Pass using an op amp. I generated the design with that Japanese web page generator. The design seems to work fine in my testing on a breadboard, but my main concern is to ensure my current design will not oscillate as component values change within their tolerance range. My schematic currently shows 1% tolerance resistors, but I am inclined to use 5% tolerance resistors for reasons of cost. (Yes, even pennies matter.) But when I plug in different resistance values, all within a 5% tolerance, into that Japanese LPF calculator, there are some instances where the calculator shows an oscillation frequency. I take that to mean there would be some instability if resistance values were not exactly what my schematic shows. Maybe I am wrong in assuming that, I don't know. Again, that is why I posted here to find out.All said, I would appreciate hearing from someone experienced in LPF design, especially someone who understands the intricacies of a 3rd order LP Sallen Key filter such as the one presented in my schematic.Thank you!

author: nctnico
author_rank: Super Contributor
timestamp: April 25, 2020, 12:17:03 am
content: I'd use a 2 pole Sallen-Key filter and put an RC filter on the side of the ADC. This will shield the opamp from the ADC's capacitive sampling. Whether or not a Sallen-Key filter is prone to oscillation (peaking) depends on the steepness of the filter or better put: the phase margin. There might be better calculators out there which also let you specifiy the phase margin.Why is D1 there? If it is for over voltage protection then leave it out. First of all: never dump overvoltage into the supply rail. Secondly the input protection ESD diodes should be able to deal with any overvoltage situation since there is a 660k Ohm resistor in series (and the capacitor helps to get rid of spikes).

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 12:31:04 am
content: Quote from: JDW on April 24, 2020, 11:36:43 pmFirst, did you read the excerpt from the datasheet that I posted?I am pretty sure that your filter is not oscillating due to 5% variance in resistors. But, lets just say that I wrong.What is the frequency of oscillation? Can you show us an oscilloscope trace?

author: JDW
author_rank: Frequent Contributor
timestamp: April 25, 2020, 12:31:20 am
content: @nctnicoI certainly appreciate your reply; but again, I am not an expert in filter design, and since you did not mention specifics in your recommendation, I don't clearly see how my circuit will really benefit from the RC addition you propose. I must repeat what I said in my opening post about the reason I used large resistors and small capacitors in combination with an op-amp, as opposed to just using a cheap R-C LPF instead of an op-amp -- "capacitor discharge time" affects my ADC acquisition time. As you can see from my schematic, my existing design uses small 1nF capacitors in the input side of the op-amp. Discharge time is short, which is what I want. Using an op-amp circuit and then adding and RC filter on the ADC side would, at least in my mind, defeat the purpose of my having used the op-amp filter in the first place.Again, I've tested the circuit on a breadboard, and I am not see any ill effects of "capacitive sampling" from the ADC to the output of the op-amp. Indeed, I've not read anyone online about the negatives of using an op amp on an ADC input. If anything, most forums (including the Microchip forum) are filled with talk recommending an op-amp to protect ADC inputs.My circuit is working on a breadboard, but I've not mass produced a PCB yet, hence my opening post. I am just curious if my resistor and capacitor values chosen are reasonable, and hearing specifics from someone with extensive experience in op-amp LPF design is desired. Also, I am wanting to know if I can reasonably get away with using 5% tolerance resistors (again, see my opening post for the schematic) rather than more expensive 1% resistors. I'm unsure if I even need more expensive C0G capacitors, or if X7R will suffice. And lastly, within the tolerance range of the components chosen, I am wanting to know if there is worry of oscillation or similar such instability. Thanks.

author: JDW
author_rank: Frequent Contributor
timestamp: April 25, 2020, 12:42:54 am
content: Quote from: Wimberleytech on April 25, 2020, 12:31:04 amYes, of course I read what you attached. I failed to mention the 1uF~10uF cap only because I already have a 33uF cap on the board. Indeed, the entire PCB is no where near 100mm in size, so the distance to my 33uF bulk cap is a non-issue.There is no oscillation now. As I said in my previous reply to you, the oscillation is ONLY what that Japanese web site calculator is telling me when I plug in different resistor values that are within a 5% tolerance, plus and minus, of the nominal 330k-ohm I have specified.Please open that calculator right now and plug in the resistance and capacitance values:http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htmR1 = R2 = R3 = 330kC1 = C2 = 1nC3 = 480pScroll down and you will see it says "The system does not oscillate."Now change the resistance values to something within a 5% tolerance, for example:R1 = R2 = 313.5kR3 = 330kC1 = C2 = 1nC3 = 480pFNote that it now says, "Oscillation frequency f = 111.11771320134"

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 01:03:22 am
content: Quote from: JDW on April 25, 2020, 12:42:54 amI did it. Yes it says it oscillates. I think it is wrong.Does your breadboard oscillate?

author: JDW
author_rank: Frequent Contributor
timestamp: April 25, 2020, 01:17:33 am
content: Quote from: Wimberleytech on April 25, 2020, 01:03:22 amThank you for doing that. Again, my breadboard circuit works fine in accordance with the resistors I am using right now at room temperature. But how do I test it for the oscillation mentioned by that calc? What pin on the chip, for example, do I probe? I don't understand what this oscillation is or how to test for it.Keep in mind that typing numbers into that calc is easy. The hard or impossible part is recreating that in real life. I don't have the resistors to recreate those EXACT values (plugged into the calc) on my breadboard. Hence, even if somebody could tell me, "put a scope on such-and-such a pin and then power on your board and look for such-and-such a frequency," I don't have resistors with values that perfectly match the numbers plugged into that calc. And yet, those numbers are realistic insofar as they COULD BE values of those resistors only because those values are "within tolerance."Next, if one contends the calc is incorrect with regard to Oscillation, one could also contend the calc is not sufficiently accurate to reply upon for general design.Lastly, because it is impossible for me to recreate on a breadboard every set of numbers I can plug into that LPF calc, I am hoping for an expert opinion, from someone with extensive experience in op-amp LPF design, who can tell me if my existing design is fine, and whether I can use 5% tolerance resistors, and whether I can use XR7 caps versus C0G.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 01:31:37 am
content: Quote from: JDW on April 25, 2020, 01:17:33 amThree things:1) analyze the circuit by hand and prove to yourself that you cannot get the required phase shift to achieve oscillation. This is some work because you will also have to take into account the phase shift associated with the opamp.2) Simulate it. Simulators are very helpful to run different cases to see if they oscillate.3) Run corner case examples with your breadboard.I am posting a simulation file for you. It is always best to confirm performance in the large-signal domain (transient response).

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 01:43:34 am
content: Quote from: JDW on April 25, 2020, 01:17:33 amIt appears that the bode plot from the calc site agrees with the LTSpice simulation

author: JDW
author_rank: Frequent Contributor
timestamp: April 25, 2020, 01:43:48 am
content: Quote from: Wimberleytech on April 25, 2020, 01:31:37 amThank you for your willingness to help, but I must repeat that I have zero experience with LPF design, as evidenced by the fact I used that online calc to create my existing design in the first place. As such, I do not know how to use your *.asc file. I also am unclear on the part of doing manual calculations for "phase shift" on the design I have presented. And lastly, I am not clear on your meaning of "run corner case examples."I fully realize that folks such as myself are extremely frustrating to you gentlemen who are knowledgeable on the subject. Some may rightfully contend that I have no business even considering use of such a filter when I know so little about the fundamentals of filter design, but the reason I posted here is for some serious hand-holding on the subject. Just treat me as a little kid who knows next to nothing on the subject. That will be a learning experience for me that will get me on the right track.My humble thanks for your time and kind consideration.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 01:59:49 am
content: Quote from: JDW on April 25, 2020, 01:43:48 amSure I will be patient!The .asc file is an LTSpice file. Most everyone that helps out on this forum is expert at using LTSpice. It is a free tool and extremely powerful. You should learn to use it. Alternatively, if you have access to another circuit simulator, use it instead.I spent 40+ years designing integrated circuits. When we say "corner cases" what we mean is run the various extreme cases for parameter variations. This includes temperature. In your case, that would be playing around with 5% (or 10%) variations in component values to see how the performance varies. Not sure what the worst case corners would be for the SK filter. One approach is to do Monte Carlo simulations and let the simulator run a statistical analysis for you.The SK filter is very robust...esp with opamp in unity gain. It is not going to oscillate unless you have a problem with the opamp itself.

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 12:48:54 pm
content: For a circuit to oscillate, it must feed back a signal to the input in phase with the signal that generated it. Kind of a clunky way to say it...a better way is the Barkhausen criterion: The magnitude of the gain in the loop is 1 and the phase shift is 0°. So, how do test this SK configuration. Knowing where to break the loop for this analysis can be tricky, but for the SK it is easy...break the loop at the output of the opamp. Then input a signal at the dangling end of C1 and analyze/calculate the transfer function to the now open output of the opamp. If you can get a gain of 1 at 0° then you have an oscillator. If you get a gain more than 1, generally you will still have an oscillator as the amplitude increases, nonlinearities will bring the gain down to one at some point.You can do this analysis in LTSpice and save yourself some algebra! But at some time in your life, you need to plow through this just once.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: April 25, 2020, 02:27:11 pm
content: Hi,(Wimberleytech - congratulations on reaching 1000 posts !!!)I will give you the answers without too much of an explanation:Frequency Domain resultTime domain - step inputThis modelling shows a well behaved 3 pole low pass filter.Stability AnalysisStability Model ResultsThe stability model results shows that there is 6dB of gain margin. This means that gain of the amplifier has to change from unity to x2 for oscillation.Gain SteppingThe opamp has been replaced with an amplifier so that I show the effect of increasing the gain:Gain step resultsThis model shows that the gain has to be increased to 2, a 6dB increase for oscillation.Regards,Jay_Diddy_B

author: Wimberleytech
author_rank: Super Contributor
timestamp: April 25, 2020, 02:38:27 pm
content: Quote from: Jay_Diddy_B on April 25, 2020, 02:27:11 pmNice work, and thanks.Here is a spice file reflecting with Jay showed us.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: April 25, 2020, 02:54:03 pm
content: Hi,Further to my last post.Component Variation - ToleranceMonte Carlo Analysis can be used to simulate random component variation.In LTspice the syntax is{mc(nominal value, tolerance)}{mc(10K,0.05)} - this is a 10k5% resistorA dummy parameter is used to run the simulation a number of times.Each time the model runs it uses a different set of parts. It is like building the circuit many times and comparing the results.Monte Carlo analysisFrequency DomainTime DomainI don't see any hint of instability from 5% components.Regards,Jay_Diddy_B

author: Someone
author_rank: Super Contributor
timestamp: April 25, 2020, 11:37:10 pm
content: Quote from: JDW on April 24, 2020, 11:36:43 pma) what tolerance do you expect on your capacitors? how does that relate to the variation/tolerance of the other components?b) the online "calculator" is probably incorrectQuote from: JDW on April 25, 2020, 12:31:20 amI'm not sure what you mean by "capacitor discharge time", as an idealised linear system the input from the sensor to the ADC can be completely described by a frequency response. Notably, most ADCs areimprovedby adding more capacitance on their input pin (reducing the impedance driving the input).

author: JDW
author_rank: Frequent Contributor
timestamp: April 26, 2020, 01:20:56 am
content: Quote from: Someone on April 25, 2020, 11:37:10 pmAlthough I appreciate your comment, it's clear you didn't read previous comments. I went into detail about tolerance. So for yourself and all others who later find this thread, please read through all previous comments. A lot of your questions are probably already answered there.Quote from: Jay_Diddy_B on April 25, 2020, 02:54:03 pmJay, I am humbled and eternally grateful for the time you so kindly spent on those simulations. That is the kind of hand-holding my feeble brain really needed. Thank you very much.It also seems clear that the calculator either was incorrect when it cited an Oscillation frequency as I varied the 330k resistors (within a 5% tolerance) OR their "Oscillation" means something other than what I am thinking. But thank you, Jay, for running the 5% resistor tolerance simulations to show the filter is indeed perfectly stable. Thank you also for showing that so long as I use 5% tolerance capacitors (e.g., C0G) all will be well. BRAVO!

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: April 26, 2020, 01:42:45 am
content: JDW,The simulation is showing the filter is stable with an op-amp that is working correctly.The LTspice simulation do not include the MCP601.If the real circuit doesn't work like the model, try a different op-amp.Regards,Jay_Diddy_B

author: Someone
author_rank: Super Contributor
timestamp: April 26, 2020, 02:55:01 am
content: Quote from: JDW on April 26, 2020, 01:20:56 amC0G is only the temperature stability/coefficient tolerance, it is a separate rating to the capacitor tolerance, and capacitor tolerance is usually specified in an extremely specific measurement with regard to excitation signal, frequency, DC bias. The tolerance of a capacitor in circuit is themultiplicativeresult of all its variances. EIA Class I ceramic capacitors are the exception to the rule with their very low sensitivities, almost every other capacitor type varies outside its nominal "tolerance" in real use.

author: JDW
author_rank: Frequent Contributor
timestamp: April 26, 2020, 03:03:03 am
content: Quote from: Someone on April 26, 2020, 02:55:01 amI appreciate the explanation, but if you could extend that explanation to Jay's LTSpice simulation, where he used 5% tolerance capacitors, that would be even more specific and helpful. But from what I can see in my breadboard test and in Jay's very kind simulation, the schematic put forth in my opening post seems to be a solid design, despite the fact it's not possible to simulate the Microchip Op-Amp in LTSpice.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: April 26, 2020, 03:49:24 am
content: Hi,You can work out what all the effects like temperature, tolerance, dc bias add up to and run the simulation with the tolerance set to accommodate all of the parameters.If I run the Monte Carlo analysis again with10% resistors25% capacitors, 5% for initial accuracy and 20% for other effectsI get:andNo hint of any instabilityRegards,Jay_Diddy_B

author: Someone
author_rank: Super Contributor
timestamp: April 26, 2020, 06:40:28 am
content: Quote from: JDW on April 26, 2020, 03:03:03 amThe MCP601 can be simulated in LTspice, but that requires a person with the motivation to do your work for you.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 26, 2020, 09:51:11 am
content: Note the extra RC filter referred to by nctnico is required due to special input characteristics of SAR ADCs. If you don't like the idea, you can think about it being a part of the ADC, not part of your filter. Though, this extra RC filter can participate in your filter response, as well. See ADC datasheets and appnotes for more information. Typically, R is small like 10-50 ohms, and C is small as well, some hundreds of pF.Often, with the suggested values (by the ADC manufacturer), the corner frequency of the RC is far above of the required Nyquist frequency, so it does not work for anti-aliasing. It's to filter large current spikes only.

author: JDW
author_rank: Frequent Contributor
timestamp: April 27, 2020, 01:09:58 am
content: Quote from: Someone on April 26, 2020, 06:40:28 amI must assume you mean: "build a custom model of the Microchip MP601 Op-Amp IC from scratch in LTspice." I will take that under consideration. But as to your "...do your work for you" jab against me, such overlooks the fact that whenever anyone posts on an online forum, other people often chime it in to help, which at least partially amounts to "doing workforthe original poster."I would like to repeat my humble thanks toJay_Diddy_B. Some seem to contend that you offered me too much assistance, but I am sincerely grateful, Jay, not only in that your simulations can help put my feeble brain on the right track, but the fact that this being an open and public forum can no doubt help others as well in the future. Thank you, Jay!Quote from: Siwastaja on April 26, 2020, 09:51:11 amI certainly appreciate your very kindly having shared that insight on the RC filter! At the same time though, I would like to humbly ask you one question. Isn't that overthinking the current design? As I mentioned in my opening post, I am not doing precision A-to-D scanning of complex waveforms. All my circuit is doing is just looking for 2 voltage levels with a rather wide tolerance:Vol- pressed: 2.32v (ADC scanning tolerance to confirm a Vol- press: 1.6V~2.6V)Vol+ pressed: 1.44v (ADC scanning tolerance to confirm a Vol+ press: 0.7V~1.6V)(Voltages being scanned for from a car's steering wheel Audio keypad.)I would now like to mention one more thing. I was presented with an existing product on the market that does something similar, using a single ADC pin of an PIC12F1571 connected only to a single 22k-ohm 5% resistor to the outside world (i.e., connected straight to the car's output from the steering wheel Audio keypad). The PIC datasheet makes it abundantly clear that the source impedance should NOT be higher than 10k-ohm, and yet we have this product which has a 22k-ohm resistor, which adds to the resistances on the car side, which can be a maximum of 3k-ohm! And yet, I was told this product has been on the market for 3 years and has very few customer returns or complaints, which implies it does the voltage scanning just fine.But rather than just blindly copy what this other company did by putting ONLY a 22k-ohm resistor on my ADC input, which goes against what the PIC datasheet says (in my case, I am using a PIC16F1503), I am adding an op-amp LPF to ensure the source impedance seen by the ADC pin is very low, and my circuit also protects the PIC better than a mere resistor in the even of an incoming voltage spike, which could be 60V or even higher (albeit for a short duration). (My clamping diode D1 shown in my schematic in my opening post in large part deals with those incoming surges.) ADC resolution on the PIC12F1571 and on the PIC16F1503 is 10-bits.And so, my existing LPF design is, at least in my opinion, adequately attenuating external noise (from the car side). The only thing my current design does not have is the RC filter you spoke of, which apparently "attenuates the kick from switched capacitors in the ADC's input" as per this article:https://www.analog.com/en/analog-dialogue/articles/front-end-amp-and-rc-filter-design.htmlAs that article also states, the addition of an RC filter on the OUTPUT of an op-amp affects Settling Time. But in the case of my design, I have calculated the acquisition time to be about just under 5usec and in my Assembly code controlling the PIC16F1503, I have added a 20usec. delay to give adequate safety margin for my ADC input captures. I also have added a 50msec. delay between captures. In other words, I only sample the steering wheel keypad as fast as once every 50ms, with each capture duration being timed at no less than 20us. In my breadboard testing thus far, I've not had any issues.My thanks to everyone who have very kindly contributed in a positive way to this thread. I sincerely appreciated the hand-holding. It's been a learning experience.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 27, 2020, 12:24:58 pm
content: Quote from: JDW on April 27, 2020, 01:09:58 amFor this nearly DC operation, I have hard time understanding why you are specifying a 3rd order lowpass filter at all, I think this is unnecessary complication.Just use a first-order RC filter to begin with, no opamps required. C can be fairly large, like 100nF, R can be large enough (up to 10k?) to protect against excessive current into ADC-integrated clamp diodes, just sample at 20 samples/second or so, and you are done with extremely low complexity and part count. Detect presses by looking if you get the same within-the-range-of-that-button voltage reading for 3-4 consequtive samples.Higher order anti-alias LPFs matter when we require higher frequency AC performance,andlow-noise results,andif we have a lot of out-of-band high-frequency noise that would otherwise alias to our band of interest. For your case, none of these seem to be the case.

author: JDW
author_rank: Frequent Contributor
timestamp: April 27, 2020, 09:41:11 pm
content: Thank you for your suggestion, however I have already covered the use of only a RC filter earlier in this thread. It’s not a simple matter of just using a maximum of a 10K resistor in an RC filter because as I said before the car side keypad has up to 3K of source resistance. So when you factor in tolerances, any RC filter you would choose to design with need to have no more than a 6K resistor. Again, the ADC requirement specifies a “maximum“ of 10 K on source impedance. And as you decrease the resistance in snEC filter you will need to increase the capacitance, and as I said before I preferred to have smaller capacitors along the lines of nanofarads to keep the capacitor discharge time short. My opamp circuit may be overkill, but it does work well and provides a low source impedance voltage level to the ADC pin.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 28, 2020, 12:52:49 pm
content: This is a long post and may contain some small inaccuracies, bear with it, but you really need to get the basics right before jumping into calculations. There is a lot to grok here. I think your solution is severely overengineered; nothing wrong here, I like to sometimes overengineer to learn more, but the risk here is that with such low-demanding use case, you won't see any difference in the final result: it will just work, regardless of what filter you use. For example, if you just accidentally wire input directly to output, completely bypassing the filter, the end result will very likely work just perfectly!First, you need to understand the ADC requirements. Your typical SAR ADC has a tiny little DC leakage, which is in tens of megaohms; or you can think about it as a tiny bias current. This is usually negligible, and even unspecified, I'm just mentioning it for the sake of completeness.More importantly, and this is the key, every time the ADC samples, the input signal is connected to the internal sampling capacitor for a very short time, called thesampling time. Of course, connecting the input signal to a capacitor suddenly, causes current only limited by the total resistance to flow. If you have almost zero resistance, a huge current flows, possibly causing multitude of problems (hence some amount of R is suggested by nctnico earlier). In the opposite case, if you have too much resistance, the sampling cap charges slowly; and because the sampling time is only so long, charging the cap remains unfinished when the sampling time is over.High-speed ADCs typically require input impedances as low as 20-30 ohms, because the sampling time can be as short as some tens to hundreds nanoseconds. If the PIC ADC is specified at 10kOhms as you say, it means it must use a very long (relatively speaking) sampling time internally; it's likely in several microseconds, see the datasheet. This makes your life easier, you can live with some impedance.Also note, the level of accuracy you require affects the input resistance you can tolerate. For example, assuming sampling capacitor of 20pF, and input resistance of 10kOhms, R*C = 0.2 µs. This means, after 0.2µs of sampling, the result would be 37% off. After 0.4µs, error is 13.5% After 0.6µs, error is 5%. After 1.0µs, error is 0.7%. Say, your sampling time is set to 1µs (by design of the ADC, or sometimes it's user-configurable). Is error of 0.7% acceptable? Sometimes 0.7% is more than good enough, hence 10k source resistance is just fine; sometimes 0.7% is abysmally poor result and you need something orders of magnitude better, hence use longer sampling time, or lower source impedance.The giveaway is, you need to make a distinction between DC resistance and AC impedance. Adding a 100nF capacitor to the ADC input, like I suggested, very clearly satisfies the 10kOhm impedance requirement. Let's play with the impedance for a minute: for a typical ceramic capacitor (ESR = 20mOhms), mounted close (10nH stray) to the input pin, the impedance at the relevant frequency (inverse of the sampling time, 1µs for now) would beZ = R_esr + L_esl + 1/(2*pi*f*C ) = 0.02ohms + 2*pi*1MHz*10nH + 1 / (2*pi*1MHz*100nF) = 0.02ohms + 0.06ohms + 1.5ohmsFour orders of magnitude less than your allowed maximum of 10kOhms! Clearly, this impedance constraint is satisfied with the capacitor alone; then we only need to think about how we chargethat(externally added) capacitor.But, it makes more sense to look this in the time domain in terms of current and charge, IMO, so let's get rid of the complex impedance equations:Say, you have a 100nF input cap and a 20pF sampling cap. When the sampling occurs, in worst case, you transfer approx. 20p/100n = 0.02% of the charge from the input cap to the sampling cap. So the input cap voltage changes just by 0.02%. This is the error you will see in the result!Now, the only requirement left is that the 100nF input caps needs to be able to replenish. This condition is relaxed when compared to not using input cap; with no input cap, the input signal needs to be able to fully charge thesampling capduring the sampling time; with the added input cap (Cin >> Csampl), the input signal still needs to supply the same amount of charge (it's only the ADC what's consuming it, after all), but has the whole time window between two samples to work with. For example, if sampling time is 1µs, and sampling rate is 1ksamples/second, the input signal has a massive 1ms time to charge the input capacitor, and that input capacitor takes over the job of charging the ADC sampling cap in just 1µs.But, seeing the ADC is specified to work acceptably (by some arbitrary definition by the PIC datasheet writers) even with such a high input impedance as 10kOhms, you may not even need the input capacitor! You may actually neednothingat all.But, I strongly recommend using the input capacitor for near-DC measurements. It's cheap (a BOM reuse, your bog standard 0402 power supply bypassing cap does fine), small, does good job at suppressing high-frequency noise at -6dB/oct, protects the input from ESD, and, allows you to use very large input resistances (up until the DC leakage / bias currents start to be a problem), say, 100kOhm to even 1MOhm is usually just fine, with only one condition: don't sample too often. This is the simplest and cheapest way to sense battery voltages, thermistors, and similar.I rephrase the external input capacitor once more because I have seen it cause confusion: a capacitor that is much larger than the sampling cap (Cin >> Csampl) removes the sampling time from the equations, and replaces it with the sampling interval. The latter is typically at least an order of magnitude longer, often many.So, the circuit reduces to something like a 10kOhm resistor for limiting current to protection diodes (internal for low-cost solution; external for added robustness; you may want to use two resistors in series, with the midpoint clamped with external protection diodes). This resistor doesnotcause any significant accuracy problem as you seem to think, as won't your 3k source resistance; the ADC input (with the 100nF input cap) consumes practically zero current, so no voltage drop is generated over those resistors (except when the clamp diodes are conducting due to overvoltage). The input impedance simply doesn't matter much; 10kOhm spec is already quite forgiving, and adding the input cap makes it matter even less (because now we are only interested in theaveragecurrent the ADC consumes from the signal; not the peak current, which is handled by the input cap!)---On the other hand, if you want to look at this as a generic data acquisition system, you should start by specifying your requirements first.Let's start with the required bandwidth. So, you are detecting key presses. Fine, what's the shortest keypress you want to reliably detect? Let's say 100ms. Say you want to debounce by detecting two consecutive settled values, so for that, the bandwidth should be enough to settle in less than 50ms. So, pass-band BW is in order of 20Hz, and at 20Hz, the amplitude should be close enough to detect the key correctly.Then let's look at the accuracy of converted numbers. This is catch-all that should include voltage errors due to component tolerances, all noise, ADC resolution, nonlinearities, etc. Let's see your table of values to be detected:Seek+ 20mVSeek- 800mVVol+ 1440mVVol- 2320mVNoPush 3240mVLet's calculate the "dead bands" between these expected values:Seek+ 20mV(780mV)Seek- 800mV(640mV)Vol+ 1440mV(880mV)Vol- 2320mV(920mV)NoPush 3240mVNow let's assign valid ranges for detection, consuming half of these deadbands, leaving half of them to detect "illegal" values:Seek+ from min_possible to 20mV+780mV/4Seek- from 800mV-780mV/4 to 800mV+640mV/4Vol+ from 1440mV-640mV/4 to 1440mV+880mV/4Vol- from 2320mV-880mV/4 to 2320mV+920mV/4NoPush from 3240mV-920mV/4 to max_possibleNow what's the maximum allowable total error (due to all combined sources of error)? The smallest margin is between Seek- and Vol+, 640mV, which we divided by 4 to leave forbidden values inbetween. The maximum allowed error is thus +/-160mV, which is +/-4.8% of the (assumed) 3.3V signal and ADC range.Now, to add extra margin of safety, let's say we want +/-2% accuracy. This leads to the following conclusions:* 6 bits is enough resolution (each LSB is 1/64 = 1.56% of full range)* Signal-to-noise ratio needs to be 20*log10(2%) = -34dBNow, do you need low-pass filtering? Your signal clearly doesn't have intentional interfering components, it's basically a DC level defined by the push buttons. So outside the BW, there is just noise. How much?Now a key finding that they tell you in every signal processing 101 classroom is this, and this is true: analog filters become more expensive, larger, more costly, and more difficult (or impossible) to design taking component variations into account, the higher the order. This is why they tell you: use a simple/low-cost analog antialias filter, oversample, then implement a more steep (near to a brick-wall) filter in the digital domain. Of course, such complex way of thinking is not needed in your simple application, but the idea is the same. In your case, you won't need to implement a 512-tap FIR with a DSP, no, but you may want to look at the consecutive values in a loop to make sure you have steady values for 100ms, then react to the keypress. This basicallyisa digital low-pass filter tailored for the application.I don't know about the sample rate of your PIC ADC, or the processing power you have available, but let's say you really want that 20Hz BW. For that, the minimum Nyquist-defined sample rate is 40smps. I'm quite sure the PIC is able to sample at 1ksmps and run a simple filter at that frequency; with that, we are already at 25x oversampling, NICE. Now, the analog filter needs to be designed with the following parameters:Passband 0 .. 20 HzTransition region 20Hz..500HzStopband 500Hz (half the sample rate)... infThe digital filter takes care of the loong transition region of the cheap analog filter. Still, any signal over 500Hz will alias, and if you are unlucky, for example, a 10005Hz signal aliases as 5Hz. But do you have extremely strong signals over 500Hz? I don't think so, there is only noise, and noise emissions are regulated by law (for very good reasons).So I propose using a first-order RC filter, because it's very low cost (< 1 cent), requires no power supply, has tiny PCB area (< 1mm^2 possible), ... and is more than good enough for such purpose - actually it's good enough for an order of magnitude more demanding use cases, such as measuring battery voltages to 0.5% accuracy at tens of Hz!Let's say we use 22kOhm series resistance, plus 3kOhm source resistance (= total 25kOhm), and a 100nF capacitor.Corner frequency (-3dB) is at 1/(2*pi * 25e3 ohm * 100e-9 F) = 64HzSettling time to 1.8% accuracy (remember we specified 2%) is 3*tau = 3*R*C = 7.5ms. No problem detecting short keypresses!Attenuates noise (any unwanted signal) at 500Hz to 1/sqrt(1+(2*pi*500Hz*25e3Ohm*100e-9F)^2) = 12.6%Attenuates noise (any unwanted signal) at 5000Hz to 1/sqrt(1+(2*pi*5000Hz*25e3Ohm*100e-9F)^2) = 1.2%What's the worst possible case? We have a massive noise source at 501Hz singing somewhere, coupling into the wires. Now this would need to produce at least 1/12.6% * 160mV = 1.27V error signal so it would exceed our 160mV max error specification.At 5000Hz, the error signal (say, 5001Hz so it would alias at 1Hz) would need to be 1/1.2% * 160mV = 13.3V so it would pass through the 1st order RC filter badly enough.Connect a scope to your signal wires and measure what noise you see, while the car is running. I'm sure you won't see such huge noise sources. If you do, you likely need completely other ways of fixing and mitigating than increasing the order of analog LPF.Finally, I think this pseudocode describes what you need:Code:#define BUT_ILLEGAL -1#define BUT_SEEKP 0#define BUT_SEEKM 1#define BUT_VOLP 2#define BUT_VOLM 3#define BUT_NOPUSH 4#define ADC_BITS 8#define ADC_CNT(mv) ((256*mv)/3300)//Seek+ from min_possible to 20mV+780mV/4//Seek- from 800mV-780mV/4 to 800mV+640mV/4//Vol+ from 1440mV-640mV/4 to 1440mV+880mV/4//Vol- from 2320mV-880mV/4 to 2320mV+920mV/4//NoPush from 3240mV-920mV/4 to max_possiblestatic const uint8_t mins = {ADC_CNT(0), ADC_CNT(800-780/4), ... }; // generate tables according to the previous commentstatic const uint8_t maxs = {ADC_CNT(20+780/4), ...};// run every 10ms or so:uint8_t cur_adc = input_adc();int8_t cur_op = BUT_ILLEGAL; // -1 = illegalfor(int i = 0; i<5; i++){if(cur_adc > mins && cur_adc < maxs){cur_op = i;break;}}static int8_t prev_op = BUT_ILLEGAL;static uint8_t stable_cnt = 0;if(prev_op == cur_op){stable_cnt++;if(stable_cnt > 10){button_is_actually_pressed(cur_op);}}else{stable_cnt = 0;}prev_op = cur_op;Hope this helps.