gdaporta said:
The ADC input have a serial resistor of 150k, a grounded resistor of 15k and then a 47nF capacitor to ground.
Bad move with the series 150K. Read the datasheet under ADC's and you'll see that not more than 2.5K input impedance is recommended. Essentially you are charging an internal capacitor inside the PIC and when charged it begins the conversion to a 10-bit digital value. You need low impedance in order to charge the capacitor quickly, otherwise your acquisition times will have to be increased substantially and usually beyond your circuit requirements. The datasheet has some intense calculations to cover impedance and acquisition times.
Avoid all the calculations and drive the ADC input with an op-amp. This will provide you a solid low impedance interface to the ADC. Do your voltage level changing before or with the op-amp and all should be fine to start reading voltages accurately.
Also, consider taking several ADC samples, adding them, and then dividing by the number of samples to get a better average reading. A running average is not a real average. Taking a number of samples in powers of 2 make for very simple and easy binary math by simply shifting the number to the right by the number of samples in terms of 2^x.
Read 8 samples and add them, then shift the value 3 times to the right for the average result:
Code:
dim adc as word
dim i as byte
adc = 0
For i = 0 to 7
adc = adc + ADC_READ(0)
Next i
adc = adc >> 3 ' shift number right 3 times, 8 is 2^3
If you take 16 samples shift the result right 4 times, 32 samples, shift right 5 times, and so on... you get the picture, right.