As mentioned I am decoupling, using averaging, and testing the ratio of two resistors hooked up to the same battery after the regulator.
Let me draw the schematic and I will post.
But before that, let me say that I switched from ADCIN to doing a manual ADCON0.1 = 1 reading, and now I get a stable value. So my problem is an erroneous use of the ADCIN command or a problem in the logic of my routine.
BEFORE:
Code:
DEFINE ADC_BITS 10 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
...
WSum = 0
Pause 100
For i = 0 to 49
ADCIn PinProbe, W0
Pause 10
WSum = WSum + W0
Next i
W0 = WSum / 50
NOW:
Code:
Pauseus 50 'Stabilize
ADCON0.1 = 1 'start the ADC
WHILE ADCON0.1 : WEND
W0.HighByte = ADRESH
W0.LowByte = ADRESL
It works, now the reading stays fixed and it is much faster. (I even didn't have to do any averaging)
Bookmarks