0
\$\begingroup\$

I'm not terribly proficient when it comes to hardware, so please bear with me.

I've tried to google around to figure out how to choose values for a low pass filter to reduce noise on a potentiometer. Most of the articles I have read explain how to choose values based on frequency characteristics. That is a reasonable approach when you have that information.

In this situation, my digital input on an arduino is modulated by a potentiometer and I am seeing the values bouncing around a lot between 1 and zero when it's around the threshold. I would like to implement a low pass filter, but I am not sure how to choose my values since it's not clear to me what the frequency band I want to filter is (I do not have an oscilloscope).

This problem feels fairly simple, and so far i've seen a bunch of arduino tutorials to 'just implement a low pass filter'. But what I'm looking for is, how would an electric engineer approach choosing the right values for R and C given they are seeing a noisy analog input?

Also, this is not a question about any specific circuit I've built, this is more a general question about how to build low pass filters in practice.

Edit: Here is a bit more information.

I'm using an LM35 sensor, which operated in the \${mV}\$ range. The temperature from the sensor is \$\frac{output(mV)}{10mV}\$ so 400mV would be 40.0 degrees C. I wanted to use the potentiometer to modulate a 0-450 mV value to feed to a comparator (LM393) to determine whether the temperature is greater than some adjustable threshold. In order to set the Vcc pin of the potentiometer, I used a voltage divider \$\frac{10kΩ}{100kΩ + 10kΩ} * 5V = .454V = 454mV\$

The circuit looks like this, and \${V_{out}}\$ is going into one of the arduino digital inputs. I also feed the inputs of the comparators to analog inputs for inspection, and the potentiometer input bounces around quite a bit.

enter image description here

\$\endgroup\$
  • 3
    \$\begingroup\$ Welcome to EESE. There are a few different approaches to choosing the RC values. One is to make the RC time constant as large as you can possibly tolerate. Could you say a little more about what you are using the voltage for? That might help us understand the solution space a bit better. Also, what is the value of the potentioemter, and will it be near the middle setting most of the time or will it be used over the full range? Please edit your question to include the requested information. Just work it into the question anywhere. \$\endgroup\$ – mkeith Feb 7 at 2:09
  • 1
    \$\begingroup\$ Your sample rate and what you do with the values once you have them has a lot to do with the suggestions. Sometimes, you really do need an external filter. Sometimes, just averaging the values you get (or increasing the ADC rate and then averaging) is enough. In general, you want to add external parts if they provide a benefit you can't achieve in software. Extra parts just means more things to go wrong. But this depends on your software skills, too. So... who knows? Simplest is to add a small cap across the wiper and either side. But the filter effect then varies with the position. May be ok. \$\endgroup\$ – jonk Feb 7 at 2:39
  • \$\begingroup\$ The comparator output is digital, it is either on or off. What is the point of using ADC to read a binary value? Sure it should work, it just does not make much sense. Also, the comparator output can only pull low to ground, it cannot push the output high. So the comparator output must have a pull-up resistor to make it high when the comparator is not pulling low. The schematics attached do not show this. Put a 4.7 kohm resistor there, it should work better. \$\endgroup\$ – Justme Feb 7 at 5:17
  • \$\begingroup\$ @Justme Sorry about that, I drew the pictures from memory. I do have a 1k pull up resistor on the open collector output, and the comparator is indeed feeding a digital input. The inputs to the comparator are also being fed to analog inputs of the arduino purely so I can inspect them with the serial monitor, and the potentiometer bounces around a lot. When the threshold is close to the temperature, the digital output of the comparator goes between 1 and 0 a lot. \$\endgroup\$ – blueether Feb 7 at 6:19
  • 2
    \$\begingroup\$ @blueether OK, thanks for clarifying. Now that you mentioned that the digital output from comparator is noisy when at the treshold, it will not go away just by by filtering the inputs to the comparator. If you think about an ideal comparator, what the output is when input voltages are identical? Is it halfway between on and off, or flipping rapidly between both states? The comparator will flip between on and off. While filtering the comparator output might do the job, it would be best to build some hysteresis to stop the comparator oscillation. \$\endgroup\$ – Justme Feb 7 at 9:57
2
\$\begingroup\$
  • The ADCs will have a specific maximum input impedance mentioned in the datasheet (for most of the MCUs). Even the recommend series resistor and the capacitor can be found.

  • Since the signal is from a potentiometer, it is a slow changing signal. A capacitor of value 10nF or even 100nF at the input of the capacitor will help reduce the sampling glitch. The internal sample and hold capacitor will then be easily charged with the external capacitor.

  • The internal capacitor wil be of a very small value in 10s of pF. So, a 10nF or a 100nF External capacitance will not see any loading when the sample and hold capacitor is made to come in contact with the ADC line

  • In software, you can employ, moving average as well to reduce the noise further.

  • The external R and C together define the time constant. Waiting for several RC time constants (10x or even higher) before reading the value of ADC register yields more accurate result.

  • If the potentiometer adds higher input impedance than the ADC expected value, opamp in a voltage follower mode can be used, I'd feasible, bringing down t output impedance of the signal source.

\$\endgroup\$
1
\$\begingroup\$

In this situation, my analog input on an arduino is modulated by a potentiometer and I am seeing the values bouncing around a lot. I would like to implement a low pass filter

Given the schematic you posted, it seems unlikely that the potentiometer output is so noisy - unless you have some troubles with the power supply. You could anyway put a capacitor at the output.

It is not clear when you say "the values bouncing a lot": do you use the arduino to read from the potentiometer, or to read the comparator output? And are you sure your routine is correct (let enough time to sample the input and enough time to the ADC to make the conversion).

That said, I think comparators are very sensitive to noise, may be you could use your arduino to read directly the output of the sensor, perhaps amplified via an operational. Doing so, you can make a filter in software which will grant you much more control; it should be easy because normally temperature varies very slowly, so the software should have a lot of time to filter. And you can also add some hysteresis; or some prediction: if you see the temperature is raising quickly, you can predict - ahead of time - it will reach the setpoint or whatever (there is always some inertia).

\$\endgroup\$
  • \$\begingroup\$ Thanks for this comment and this perspective, very helpful! To answer your question, I am using the arduino to read analog input connected to potentiometer AND digital input connected to comparator output. I have no delay in my loop, however I had assumed the MCU is slower than the analog sensor... is this a bad assumption? Adding hysteresis is an interesting idea, though I'm not sure if that would work since it's bouncing +-6-8 degrees in both directions. I will think on it though. \$\endgroup\$ – blueether Feb 7 at 17:08
  • \$\begingroup\$ @blueether hmm... I would assume the MCU is much more fast than any temperature sensor around, and anyway much faster than any temperature change in the world (if not extreme applications). Just to say. Anyway filtering and resampling and delaying and predicting should not be a heavy load for an MCU (if not already overloaded). \$\endgroup\$ – linuxfan says Reinstate Monica Feb 7 at 17:15
0
\$\begingroup\$

1Kohm and 1uF should work fine. Why?

Consider the equivalent input current of the ADC.

I = frequency * charge_per_sample

I = F * (C * V)

At 1 MHz sample rate , 10pF Csample(inside the ADC), you have

I = 1e6 * 1e-11 * 5volts = 5 e-5 = 50 uA

50 uA can be inverted, to find the Rerror is 20,000 ohms per volt. Thus for 1 millivolt drop, the series R can only be 20 ohms.

However, you will be adjusting the pot, so there is no accuracy requirement.

And your voltage is not 5 volts, but 0.5 volts.

Just place a 1Kohm in series with ADC input, and place 1uF from ADC input to ground.

This provides 159Hz input filter, plenty to remove most AM radio and black-brick switch-reg trash.

\$\endgroup\$
  • \$\begingroup\$ "50 uA an be inverted, to find the Reror is 20,000 ohms per volts" I guess you need to reevalute this sentence, now, it makes no sense. If a Reror would be a resistor, its units are not ohms/volt of course. \$\endgroup\$ – Huisman Feb 7 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.