There are three things I do, in no special order:
1) Sample ten times at 1ms intervals. The delay between samples makes a
big difference on AVRs, or at least the Attiny85 and Atmega328/328P I've tested on. Both in stability, and in the value read.
2) I put a 0.1µF cap between the ADC pin and ground, as close to the pin as possible (I aim for less than 2mm between the solder blob for the pin and the solder blob for the cap, and a small package cap to reduce ESR/reactance/etc. in the leg/body of said cap.
3) I don't care that much if it bounces a couple notches. If the PWM value fluctuates a percent randomly it doesn't make much of a difference. That said, there isn't any fluctuation I can see on my scope. Obviously if your application is more sensitive, your mileage will vary.
If you do have a very sensitive application, I would do the above as well as adding 10µF and 100µF capacitors to the signal pin, and making sure that whatever the voltage source is for the ADC unit (on the 328/328P it has it's own VCC pin, the attiny it does not) is clean. A π filter (cap, inductor, cap) on said voltage source will help. The Atmega328 datasheet suggests having one for whatever that is worth.
If you're feeling expansive, making sure the voltage source for the pot is clean will help too.
How much is yours bouncing?
If it's only bouncing one count or so (say from 412 to 413) back and forth, you could play software schmidt trigger games with it. Something like having a "last" value and a "now" value and an "output" value, and only update the "output" value if the "now" value is more than a given amount larger/smaller than the "last" value. The "last" value being the previous "now" value.
I haven't actually done that, it just comes to mind.
What I've also done in the past is used the average of the last three (or two, or ten) read
cycles for what I'm doing. Say every 90ms you spend 10ms reading every 1ms. The ten values read every 90ms get combined into an intermediate value, then the last ten intermediate values are combined into a final value.
It results in fairly slow reactions to the pot actually moving, but will definitely reduce bounce.
A last piece of advice, if you have the time (in your code) sampling fairly often for 1/60th of a second (~17ms) will cancel out the house AC EMI for the most part, as you'll be getting values at most points of the induced waveform.
If you're feeling
really adventurous you could even use a floating pin to detect the zero crossing point of the AC EMI and start your read cycle there. That might be a touch excessive.
For my basic fan controller I only did #2 (well, and 3), I thought I'd done more, but nope! Still don't see any bounce in the PWM output though.
For the voltage to PWM converter, because it's a buck regulated voltage being read (and therefor noisy), I did 1 and 2 (and three..). The code is very simple, I don't have anything else I need the MCU to do while it's reading the values, so I can use delay() and not worry about the outside world while I read the incoming voltage. The PWM output of course is hardware and unaffected by delay().
Code:
inputValue = 0;
for (byte x = 0; x < 10; x++){
inputValue = inputValue + analogRead(A1);
delay(1);
}
inputValue = inputValue / 10;
That's in Arduino of course, but translating it to PIC should be easy enough, though I expect you already knew exactly what I meant by this point in my post