# Unstable output of ADC

I am trying to read the voltage from analog sensor via ADC of pic18 microcontroller. It has 10 bit ADC i.e. 1024 steps. But measuring a voltage of 2 V range (approx) my result keeps fluctuating + and -2 the exact value. However the range i am working is narrow and precision is required. I checked the value of signal input at ADC pin of microcontroller ther i saw 70-100 mV disturbance, using capacitors i got it reduced to 30 - 40 mV but now it's not reducing further. Capacitor used 0.5 micro Farad.
I want to know how can we filter it further. Also i need a stable ADC output (should not fluctuate). Please help.

• So, it's got nothing to do with the ADC's ability to convert an analogue input voltage into a digital output value, yes? <you need to disclose more about the circuit and the sensor so, please post a schematic cropped to the relevant area and link the sensor's data sheet. Commented Jul 2, 2023 at 17:58

## 3 Answers

Average 8 readings. This will help with noise.

• Averaging can be a really good solution here. Using averaging I have designed circuits that could reliably make measurements to within ±1 ADC count and where in my case one ADC count was only ±2uV. Commented Jul 3, 2023 at 0:33
• thanks, thats helpful. Commented Jul 3, 2023 at 7:10
• hi user4574, my adc count is 5 mV but still after averaging 15 terms i am getting +-1 unit ADC fluctuation(though it's better than without averaging). How have you managed to get that good accuracy. Commented Jul 3, 2023 at 7:13
• i tried to get better resolution via applying lower reference voltage but it lead to more oscillations. Commented Jul 3, 2023 at 7:16
• @newbie If the averaged value is quite exactly between two digital values, you will experience jumping between these. No more averaging will help here. (BTW, the ratio will tell you the fraction of the LSB.) To avoid this jumping, you need to insert some hysteresis. Commented Jul 3, 2023 at 7:33

We refer to Microchip's specifications for PIC18F devices. You can bet that these specs are obtained with a very carefully set up test bed, with very stable and smooth supply voltages. OP's requirements are near these limits, which are quite likely RMS values. Expecting a never-changing result with a DC voltage applied is expecting a bit too much.

Pay attention to how these were measured - under different conditions (for example, measuring a source having higher source resistance/impedance) results can degrade. Also, a reference voltage less than +5v will likely degrade these specs.

OP's noise measurement at ADC input (30mV-40mV) can easily account for measurement fluctuations. Noise of reference voltage or noise on Vss can also add noise, so ensure that Vdd doesn't vary. This is especially important if DC supply (REFerence voltage) comes from a noisy switching supply. Filtering ADC input alone isn't enough. With a reference voltage of 5V, a least-significant-bit fluctuation of 5mV can flip the least-significant bit of the result.
Since the ADC is a successive approximation type sampling period is short (perhaps as short as 100ns). If sampling occurs on a noise peak, next sample likely gives a different result.

• ok so if we try to reduce the Vref in hope of greater accuracy or better resolution. We might actually get more fluctuations. Commented Jul 3, 2023 at 7:07
• Is there any way to keep op amps noise in check Commented Jul 3, 2023 at 7:14

You can try a median (not average) filter in software, if the goal is primarily to have a stable output. Median filters generally produce a very stable output as they completely disregard outliers.

One downside is they require a fair amount of computation power, since you need to sort your samples somehow.

• can you please elaborate how to use them , how to implement in program. Commented Jul 3, 2023 at 7:05
• i am using Mplab x Commented Jul 3, 2023 at 7:06