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