Pot jitters during ADC capture

# Thread: Pot jitters during ADC capture

1. ## Pot jitters during ADC capture

SOLVED: Henrik figured it out, this 18F26K22 doesn't like 10K pots on ADC.

https://www.picbasic.co.uk/forum/sho...893#post155893

================================================== ===

Posts moved from here: https://www.picbasic.co.uk/forum/sho...or-adc-reading

Henrik,

Do you think your routine would help potentiometer jitters?

I have new slide pots that have random jitters along the entire range of motion. ADC readings seems to vary by 10 points at times.
Last edited by Demon; - 12th August 2024 at 19:46.

2. Did you find this post helpful? |

## Re: New software filter for adc reading

I have not seen Henrik's piece of code, but as he noted it is not a sort or fast one.

In the mean time, maybe you can:

1. find the reason of the jitter/noise of the pot output.
2. try getting 10 samples, sort them, keep the middle 4 or 5 ones, add and divide by 4 or 5 to get the average.

seems a lot but is fast enough for most of the cases.

For a sorting routine see here: https://www.picbasic.co.uk/forum/sho...highlight=sort and this https://www.picbasic.co.uk/forum/con...orting-Numbers

Ioannis

3. Did you find this post helpful? |

## Re: New software filter for adc reading

It's a hardware issue, the pots are brand new. The slider overlaps multiple resistor changes. I don't get these jitters using my rotary pots.

I read the big ADC thread:
https://www.picbasic.co.uk/forum/sho...eading-Routine

- using 10-bit ADC on 18F26K22
- take 16 readings into a table
- sort using Melanie's routine
- take the median average
- add previous average twice and divide by 3 for exponential average

...still jitters.

I placed a small cap across VSS and wiper.

...still jitters.

I tried this low-pass filter with 16K and 10uF:
https://www.instructables.com/Smooth...iometer-Input/

...still jitters.

Tried shifting out low bit.

...still jitters.

Tried shifting out low 2 bits.

...still jitters.

Tried shifting out low 3 bits.

...still jitters.

Tried shifting out low 4 bits.

...mostly stable

But now the high range only goes up to 976 or so.

I'd have to convert to a ratio of 1023 for my variables (MS Flight Sim variables=0-1023).

4. Did you find this post helpful? |

## Re: New software filter for adc reading

Took the average of middle 4 entries, still jittered.

Gradually dropped off low bits until I was down to 6 high bits.

It jitters a LOT less. It's at a level that would be acceptable.

I guess that's the price I have to pay when I use the "most affordable new pots from China".
Last edited by Demon; - 5th August 2024 at 23:48.

5. Did you find this post helpful? |

## Re: New software filter for adc reading

did you do a test with a different regular pot instead if slider, and did you try, say a, 1 microfarad across Vss and slider tap ?

6. Did you find this post helpful? |

## Re: New software filter for adc reading

Originally Posted by Demon
Gradually dropped off low bits until I was down to 6 high bits.
Well, 4 bits down means the jitter is max 15 counts of the ADC... This is too much!

Cannot understand how can a pot have so much bad connection of its wiper... If you use this port in audio circuit, it should make a lot of noise! Even old and dusty pots, if stationary, do not have such behavior

But then you said that with rotary pots you do not observe any jitter. All the sliders do the same?

If yes, better dump them and get decent ones.

Ioannis

7. Did you find this post helpful? |

## Re: New software filter for adc reading

Sorry for the delay but the thread is a decade old so....
What's the value of the pot in question? Link to actual product or datasheet?

It certainly sounds like a hardware issue. If it works OK with a rorary pot, of the same value, then the slide pot is crap - obviously.

But, do you really NEED 10 bit resolution? Even if you throw away say 3 bits you still have 127 discrete values. On a 70mm long pot that's about 0.5mm movement. If the sim software expects 10bits then just shift the value left three digits.

8. Did you find this post helpful? |

## Re: New software filter for adc reading

if the slider pots had been sitting around for a few years then the wiper windings could be tarnished (not good electrical contact). might be able to spray/squirt some contact cleaner and vigorously move slider to get better contact

9. Did you find this post helpful? |

## Re: New software filter for adc reading

Originally Posted by amgen
did you do a test with a different regular pot instead if slider, and did you try, say a, 1 microfarad across Vss and slider tap ?
I had made tests a few days ago using various ceramic and electrolytics up to 10uF with no improvement.

I have one last thing to test, gonna report back.

10. Did you find this post helpful? |

## Re: New software filter for adc reading

Originally Posted by Ioannis
...All the sliders do the same? ...
I have 3 sizes, 45, 60 and 100 mm, all the same mediocre performance.

11. Did you find this post helpful? |

## Re: New software filter for adc reading

Originally Posted by HenrikOlsson
Sorry for the delay but the thread is a decade old so....
What's the value of the pot in question? Link to actual product or datasheet?

It certainly sounds like a hardware issue. If it works OK with a rorary pot, of the same value, then the slide pot is crap - obviously.

But, do you really NEED 10 bit resolution? Even if you throw away say 3 bits you still have 127 discrete values. On a 70mm long pot that's about 0.5mm movement. If the sim software expects 10bits then just shift the value left three digits.
No rush here Henrik.

It's a linear 10K slide, my rotaries are 5K, but that shouldn't matter. If anything, the slides should be even more smooth since they have more distance to produce a variation in resistance.

I have 3 uses for these:

- flaps, 45mm with 4 detents (created with 3D printed housing since it cost a gazillion to add in pot).
- mixture, 60mm, doesn't require that much precision.
- throttle, 100mm, this is the important one since players can tweak their throttle in very small increments when landing.

6 bits would give me 64 values, like I said, I could make due with that if I have to.

This isn't old stock. I had to wait a month for manufacturing. Then they had quality control issues (housing pins not completely bent horizontally so the pot wobbled on PCB). They redid the order, but still, was not impressed.

The pots passed static tests, but now I'm starting to code and the first thing I tackled was pot debounce since that was left "unanswered" when I was testing stand-alone switch debouncing.

I'm just disappointed in the low quality straight from the manufacturer.

12. Did you find this post helpful? |

## Re: New software filter for adc reading

Originally Posted by amgen
if the slider pots had been sitting around for a few years then the wiper windings could be tarnished (not good electrical contact). might be able to spray/squirt some contact cleaner and vigorously move slider to get better contact
Nah, not even new-old-stock.

These were built for me.

13. Did you find this post helpful? |

## Re: New software filter for adc reading

I had one last thing to test:

The slide pot was soldered onto a new PCB from JLCPCB. It's just the pot with a connector, nothing else to interfere (I do this to test all my devices).

I had used a 3-pin header to connect to the breadboard (brand new, very tight, no jiggleness in connections).

I tried again, but this time using a female header socket, and used jumper wires to connect straight to the PIC on the breadboard.

Same jitters, so I've eliminated the header connector as possible issue (the PCB only holds by those 3 pins, so it had some
movement).

Looks like I'm down to stripping the bottom 4 bits.

One last possibility, finding a PIC on JLCPCB with at least 8 pins with 12-bit ADC. Not my favourite idea; I was looking at using the TQFP-64 16F1937 for my LEDs, switches, pots and encoders. If I have to buy PICs in bulk later, I wanted to limit my use to 1 for USB, 1 for I/O to limit costs.

14. Did you find this post helpful? |

## Re: New software filter for adc reading

I am not sure if my comments will help. I am putting in some check points for you to look at.

Is it possible you are reading the ADC too fast / very frequently ? Usually, you need to allow a settling time between setting the ADC channel to read and acquiring the channel value. If that is not handled correctly, you may see such problems that you describe. usually, a 1 or 2 count variation on an averaged value is reasonably steady for a 10bit adc.

If it is not in firmware (since you say so - the rotary pots do not exhibit such jitter), you could possibly look towards the hardware. Are the pots you compare - rotary and slider - of the same value? Are they both LINear or LOG types? A review of these will help

Thridly, you should ensure that your grounds do not form what is known as a ground loop. This can disturb the ADC acquisition if the ground currents change the measured voltage by a few mV (for 10bit @5V, it is approx 5mV for LSB). So, ensure that any heavy currents are properly routed to the power supply. Examples of such current - 7 segment display currents passing through a sink device (maybe a ULN2003 or such) whose ground is connected to the CPU which then connects to the power ground. The current flow should ideally be from CPU ground to ULN2003 ground to power supply ground. To identify such a ground loop, I would connect a fly-wire to the power ground and then touch various grounds in the circuit to identify where the error is mitigated.

15. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Tried shifting out low 4 bits.

...mostly stable

But now the high range only goes up to 976 or so.
kinda makes me wonder how that can even work

perhaps show your code

16. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

I have to clean it up first. It's a mess from all the trials.

17. 1 out of 1 members found this post helpful. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

You had slide pots made for you? That can't be cheap...

It's a linear 10K slide, my rotaries are 5K, but that shouldn't matter.
With those values it probably does not matter but don't just write it off.
The sample & hold circuit in the ADC works by temporarily connecting a small capacitor to the selected input. This capacitor is charged thru the impedance of the voltage source (your potentiometer) - which varies depending on where along the "track" the slider is positioned. If the jitter is worse with the slider closer to the bottom than to the top it could be an issue.

Look at section 17.4 (or table 27.21) of the datasheet for the 26K22. It states that the maximum recommended impedance is 3k.

If nothing else you could try filtering the wiper voltage with a capacitor, say 1uF and then buffer the signal with a rail-to-rail OP before feeding it to the PIC.

18. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

With these pots (slider 10K) I would first use an opamp as buffer, feed a 1K series resistor, then a parallel 10uF cap and then a buffer opamp again before driving PIC input.

Just to be sure...

Most PIC I used before had 10K input impedance of Sample and Hold ciruit. This 3K that Henrik mentioned is too low for a 10K pot!

Ioannis

19. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Originally Posted by HenrikOlsson
You had slide pots made for you? That can't be cheap....
(made for me) as in I ordered them on Alibaba, but they were stock, no customizations. They only mods I had done, were within the company's available options (single slide, longer handle, dust cover, etc).

Originally Posted by HenrikOlsson
...If the jitter is worse with the slider closer to the bottom than to the top it could be an issue...
I just checked, it's similar at both ends (visibly 3-4 bits jittering on my LCD display)

Originally Posted by HenrikOlsson
...Look at section 17.4 (or table 27.21) of the datasheet for the 26K22. It states that the maximum recommended impedance is 3k. ...
Oh snap, I've been seeing everywhere that 10K is the accepted norm for ADC on Microchip PICs. Never even checked the specific datasheet (that and my mind is having a hard time using the word impedance and associating it with resistance - don't ask me why).

Originally Posted by HenrikOlsson
... If nothing else you could try filtering the wiper voltage with a capacitor, say 1uF and then buffer the signal with a rail-to-rail OP before feeding it to the PIC.
Starting to google that now...

20. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Originally Posted by Ioannis
With these pots (slider 10K) I would first use an opamp as buffer, feed a 1K series resistor, then a parallel 10uF cap and then a buffer opamp again before driving PIC input....
I had never seen that suggested in my "debounce potentiometer" research. Starting to look into it (after I understand what it's doing ).

Originally Posted by Ioannis
... Most PIC I used before had 10K input impedance of Sample and Hold ciruit. This 3K that Henrik mentioned is too low for a 10K pot! ...
First time I hear that too.

21. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Originally Posted by HenrikOlsson
... Look at section 17.4 (or table 27.21) of the datasheet for the 26K22. It states that the maximum recommended impedance is 3k. ...
Henrik, is it possible your datasheet has an error?

Is it possible you were looking at a low-voltage variant?

Mine says 10K max. I had actually highlighted it during my research on ADC.

(turns out Mr E really did teach me to RTFM )

22. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

The higher the source (pot) resistance the greater the error in the voltage that PIC ADC will read. So, adding an opamp as a buffer will add no load to the source (pot) as it ihas very large input resistance (impedance that is) and too low, in the order of ohms output resistance. So it will drive any ADC input with no error introduced. For your experiments I proposed two opamps to buffer the r-c filter, as this filter will increase source resistance.

Ioannis

23. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

I'm looking at this post:

https://electronics.stackexchange.co...c-analog-input

I have 3 slide pots, so I found a quad op-amp OPA4314 at JLCPCB:

https://wmsc.lcsc.com/wmsc/upload/fi...WR_C129333.pdf

Interesting stuff. This never came up in my research to debounce a pot. They quickly lose me when they talk about frequencies and Nyquist. I'm assuming this relates with audio. I'm just sampling a pot and wouldn't know how to tweak that R/C combo.

The R/C combo here is WAAAAY lower:

https://electronics.stackexchange.co...t-input-to-adc

Found an explanation on how to chose the R/C combo between a buffer and ADC here:

https://electronics.stackexchange.co...-an-adc-input:

It points to a TI note that suggests 100R/1nF for the OPAx365 (in the image). I'm assuming this is an excellent starting point; TI describes it as "ideal for driving sampling analog-to-digital converters (ADCs)".

https://wmsc.lcsc.com/wmsc/upload/fi...BVR_C96626.pdf

Only available in single and dual, but still relatively cheap (from what I expected, I'm just happy it's available at JLCPCB).
Last edited by Demon; - 8th August 2024 at 02:38.

24. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

a voltage follower amp is really only a benefit if the signal source impedance is so high that the adc input loads the signal so much to make it inaccurate. it will not smooth out a crappy pot if anything it may accentuate it.
a lowpass filter will help whether its analog pre adc or digital post adc will make little difference
right now I'm working with FSR'S [force sensitive resistors] with 200k to 500k resistances on a pic 16f18426
no problem what so ever

what do the pots perform like when measured on a ohmmeter [an analog one would be ideal]
if they are really that bad then the resolution achievable will be low no matter how you go about it
especially if there are dead spots
Last edited by richard; - 8th August 2024 at 04:09.

25. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Richard has good point regarding crappy source signal.

As noted before, if the pot is so bad it will be very difficult to clean the signal.

The r-c values depend on the signal frequency that they will filter. Your pot signal is really slow and needs big cap and resistor values, called time constant.

Having big r-c values driving Adc is difficult so a buffer is needed.

Ioannis
Last edited by Ioannis; - 8th August 2024 at 11:59.

26. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

robert states
Tried shifting out low 4 bits.

...mostly stable
that means the pot resistance must vary in leaps of over 160 ohms [assuming correct technique]
no amount of lpf will be useful in getting stable readings from "fine" movements under those conditions

27. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Well, yes. Tossing lower 4 bits of 10 total means clearly that the source signal is too bad to be useful. If Robert insist on using those pots, then based on the fact that the wiper moves slowly, he should have a really big time constant on the R-C network to compensate for the "noise". And then he should also add buffers with such high Pot and R-C values. All these add extra cost. Better chose a better pot and done with it.

Ioannis

28. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Originally Posted by Demon
Interesting stuff. This never came up in my research to debounce a pot.
Maybe because you do not debounce a pot but only a switch or push button. Pots are filtered in the rare case of noise. Usually are rock stable and with a couple of averaging there is no problem.

Ioannis

29. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Not that it matters much but I'm reading revision H of the datasheet. It's what Microchip currently serves on their website:
https://www.microchip.com/en-us/prod...document-table

But as have been said, it should not make that much of a difference in this case.

30. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Yes you are right Henrik. The only problem with the low impedance is that the reading of the ADC will have more error. But the jitter is a different matter.

In any case I am surprised that the ADC has such a low input impedance. Was taking for granted that all PIC are in the range of 10K...

Ioannis

31. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

Originally Posted by HenrikOlsson
...Look at section 17.4 (or table 27.21) of the datasheet for the 26K22. It states that the maximum recommended impedance is 3k...
HENRIK FOR THE WIN!

I migrated to a 16F1937 and the pot is now acting marvelously. I now jitters at most only 1 value (what I initially expected when the wiper straddles zones).

WOOT!!!

32. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

I do not think this made the difference...! Probably a bad connection.

The lower sample and hold impedance would add error to your A-to-D conversion. Not jitter.

Ioannis

33. Did you find this post helpful? |

## Re: Pot jitters during ADC capture

I do not think this made the difference...! Probably a bad connection.
+1
me too or bad code

#### Members who have read this thread : 11

You do not have permission to view the list of names.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts