Go Down

### Topic: Debounce a Potentiometer? (Read 11458 times)previous topic - next topic

#### carlmal

##### Oct 19, 2011, 08:03 am
Even when I'm not touching the pot, analogRead returns a range of values, typically +/- 3.

Even mapping the 10bits to a range of 50-241 will still flicker +/- 1

How do you ignore the noise?  I have a 7 segment display showing the pot value and it jumps all over the place.

This method sort of works yet really sucks as I can't change the value by 1.

Code: [Select]
`  if(abs(prevPotValMap - potValMap)>1){    Serial.print("potValMap ");    Serial.println(potValMap);    prevPotValMap = potValMap;  }`

#1
##### Oct 19, 2011, 08:11 am
Try putting a 100nF cap from the analog input pin to ground.

You have a 100nF cap from Aref to ground as well, yes? (is included on most Arduino boards)
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### pito

#2
##### Oct 19, 2011, 09:26 am
You can filter/decouple in analog (as crossroads said) or in digital as well. Do averaging of the values (ie sum 32 pot measurements and divide by 32) or implement a low pass filter:
new_value=A*old_value+B*new_value
where A+B=1, and the smaller the B (ie. B=0.2) the bigger the filtering effect.
P.

#### carlmal

#3
##### Nov 01, 2011, 05:19 am
I've been struggling with this for a while.  Perhaps a plain old 10k pot is too erratic for what I need, which is:

Dial in BPM (Beats per Minute) and convert to the microSeconds for the display.

I only want a range of 50-240 BPMs out of thing, but it has to sit there rock steady and musical.

I wanted to dial in the integer portion only with the pot, and have inc+/dec- buttons for the 1/10s of a BPM.  A coarse/fine arrangement.

To eliminate a lot of things:
- I grabbed a spare Arduino (Freeduino)
- did the most basic analogRead() tut
- tried the smoothing tut with numReadings up to 40!
- tried the .1 uF cap over the middle and ground pins of the pot
- tried different pots
- did the software LPF with assorted values
- various averaging algo's

I hear of people getting stable +/- 1, what am I doing wrong?  Do I have to go discreet steppers like switches?  Hope not,  I don't need 6 switches for coarse, medium, fine +/-  that would be unusable in low light conditions -or- by anyone that's ingested intoxicants.

Geez, I'd have this wrapped up in minutes if it were a software UI.  I feel like such a stoopid boob.

Happy Halloween everybuddy!

Carl

#### carlmal

#4
##### Nov 01, 2011, 07:12 amLast Edit: Nov 01, 2011, 07:19 am by carlmal Reason: 1
Here's the potentiometer spazziness I'm talking about:

Looks like it is contained to 20mV, what is the period of the wave and what could it be tied to?

How do folks deal with this?

Thanks,
Carl

#### wb8nbs

#5
##### Nov 01, 2011, 05:17 pm
I had a similar problem with an Arduino app that used an external 78l05 voltage regulator.  The regulator had a low level oscillation at about 20 Mhz on the output.  The problem went away when I added a 0.1 ufd cap across the regulator input.
He who dies with the most software wins.

#### Grumpy_Mike

#6
##### Nov 01, 2011, 05:53 pm
Quote
the potentiometer spazziness

While you might not think that word is offensive, remember this is a world forum and in the UK this is a very offensive word to use, and I don't mean potentiometer.

You will always get a reading +/- 1 out of any A/D converter, that is the nature of converters. You need to do one or more of the things you have been told about:-
1) Add some capacitors to smooth the output.
2) Add some software to take the average and thus smooth the output.
3) Implement a threshold so that you only consider a number to have changed when it is say 3 or 4 units away from the previous reading. When you detect this distance then increment (or decrement) the number and look again.

#### carlmal

#7
##### Nov 01, 2011, 07:02 pm
My regrets for using the "s" word.  Here we use it to describe what someone being swarmed by mosquitoes looks like.

I've been doing more reading on the AREF as crossroads eluded to earlier, read your blog about decoupling, some forum archives here and on bildr.org, LPF on wiki.  One thing I could improve upon is move the cap away from the pot and nearer the input pin on the Arduino.

I will hook the scope up and watch the changes I make to the circuit and see if I'm improving things.  I was previoulsly trying to draw conclusions from the serial output.

From looking at the wave, it appears to be 1.75MHz  Just wonder what else clocks at that frequency...

#### wb8nbs

#8
##### Nov 02, 2011, 03:35 am
Hmm...  ten cycles in 0.55 microseconds.. Looks more like 18 Mhz to me.

Take a 0.1 or 0.01 ufd capacitor, ground one end then poke around the circuit with the other end and see if you find a spot that removes the oscillation.
He who dies with the most software wins.

#### liuzengqiang

#9
##### Nov 04, 2011, 03:36 pm
Have you tried the running average code?

http://arduino.cc/playground/Main/RunningAverage

Routinely doing USB host and device stuff
http://liudr.wordpress.com
https://www.tindie.com/stores/liudr/

#### carlmal

#10
##### Nov 04, 2011, 03:51 pm

I am making some progress.  Advice to put the coupling cap as close as possible to the Arduino pins is not to be ignored.  I had the cap over the pins of the pot, moving it near the Arduino made a big difference.  I will still need some additional smoothing from what I'm seeing so will try this averaging approach on the weekend.  I can see light at the end of the tunnel.

#### jfenwick

#11
##### Jun 19, 2012, 08:32 am
Wow, adding a 100nf capacitor between ground and the analog pin really works for this sort of problem. Kind of amazing.

#### Docedison

#12
##### Jun 19, 2012, 08:55 am
You measured 18 mHz?, the crystal runs @ 16 mHz?

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Go Up