I've built a clock out of a PIC16F877, some LEDs and other stuff…
To set the time in 5 minute intervals, I'm using a 22K ohm potentiometer connected between GND and +5V with the contact connected to analog input RA0 on my MCU.
It works, but it badly fluctuates between values. It's a 10bit ADC, and I'm looking at the most significant 8bits, and if I get my pot roughly in the center, I get an average reading of 128, but it flickers between 127, 128 and 129… even if I leave it alone and don't touch it.
How can I stablise the reading? I could probably write firmware to take an average reading, which may help a bit, but before I mess around with that wondered if there is something I could add (caps, resistors, etc) to my circuit to make it more stable? In this part of the circuit, I just have the pot connected to the MCU, nothing else.
Best Answer
You have noise in your system, plain and simple. How you handle it is the same ways that you handle any other noise: remove the source of the noise, or filter out the noise. Some things to consider are: