Inconsistant A2D readings
I am having trouble getting consistent A2D readings across a voltage divider. I have two microchips, both PIC18F45k22 attached to PORTA.5 (AN4). I only really need one of them to read the analog value. I should be getting a reading around 33. When I tested a few months ago with a single chip my results varied from 29-34 which was fine. I may have had two chips attached on my proto, or just one, I'm not 100% positive. Now I get an initial value around 20 (not consistant) when I power up, but as I continue to monitor it fluctuates wildly by several hundred. The second microchip has A.5 set as an input and I have tried making it digital and analog, though I'm not sure if that has any affect on the first chip.
+5---/\/ 30k \/\---PORTA.5---/\/ 1k \/\---GND
Here is the code I'm using to poll
Code:
check_A2D:
ADCON1 =0
ADCON2 = %10000110
ADCON0 = %00010001 ' Set ADC channel to AN4 and enable ADC
pauseus 5
ADCON0.1 = 1 'start AC process
while adcon0.1 = 1
wend
Reg_value.byte0 = ADRESL
Reg_value.byte1 = ADRESH
return
I then display the results of Reg_value on some 7 segment LEDs. I checked my power supply and the voltage seems nice and steady. I'm kind of new to the analog world, so I very easily could not have some settings done correctly, but have tried a wide variety of register settings. I have some DT interrupts going on for a timer and one serial port, but I tried disabling them with the same results.
Thanks
David
Re: Inconsistant A2D readings
Hi,
The recommended source impedance for the ADC on the 45K22 is 3k, you have 30k - that might play a role in your results (see table 27-22 in the datasheet).
Since you have the acquisition time set to manual and such large source impedance perhaps you could try increasing the Pause 5 and see if that helps (or try reducing your source impedance to meet the recommended value of 3k). I'd probably also disconnect the signal from the second PIC until you get stable readings on the firts one.
/Henrik.
Re: Inconsistant A2D readings
I tried cutting the trace to the second pic and it didn't seem to have any effect. I adjusted the pause to Pauseus 10, pauseus 50 and pause 5. None seemed to help any. The resistors are surface mount, but I think I will try putting a 1k in parallel with the 30k and see if it at least stabilizes
Thanks
Re: Inconsistant A2D readings
I found the problem. I had two similar net names "Display Type" and "DisplayType" which should have been connected and weren't, so the microchip pin was effectively floating. I found it will playing with resistor values, so thanks Henrik for the help.