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
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.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
Thanks
David




Bookmarks