PDA

View Full Version : 18f4620 & ADC confusion



JohnP
- 7th January 2008, 21:40
I've been working with the 16F877A and haven't had any ADC problems. Now with the 18F4620 I can't seem to read any ADC voltages. I'm trying to monitor certain voltages including the voltage at the devices battery with and without external power supplied.

Here is my set up:

Assume only reading value on an 8.4 V LI-Poly battery.
Battery voltage is being sensed at the middle of a voltage divider
<< --- 10K --T -- 3.3K---Vss
Reading at the center of the above divider I would expect the max input voltage sensed (without damage to the PIC) is 20 Volts which would be sensed across the divider as as 1/4 of the input or 5VDC. My input may be 10 Volts max so I should expect to read about 2.5 VDC at the input to the ADC.

I'm using AN7 (RE2) as my analog input pin being connected to the center of the divider.

Here is the PBP code being used:
DEFINES-----------------------------------------------------------
define ADC_BITS 10
define ADC_CLOCK 3
define ADC_SAMPLESUS 50
define OSC 40

ROUTINE-----------------------------------------------------------
Chk_Volts:
TRISe.2 = 1
ADCON0 = %00011101
ADCON1 = %00000111
ADCON2 = %10111111
PAUSE 10
adcin 7, volts_10
pause 200
SEROUT LCD, LCD_Mode,[12, "Volts_10: ",#volts10," "]
----------------------------------------------------------------------

I have 7 new boards with the PIC18F4620 installed as described above. All functions work well except for ADC input. Never had problems doing almost the same thing with the 16F877A.

Any ideas out there as to what I am doing wrong?

John P, Virginia Beach, VA USA

JohnP
- 7th January 2008, 21:57
Re-reading my post I left out the following:

Variable: Volts10 VAR Word

I am assuming to get an ADC result ranging from 0 to 1023 () VDC to 20 VDC)

The SEROUT command displays the Volts10 result on a Seetron 4x20 LCD and that part works just fine when similarly used for all other routines Whoops...

Just found the problem while re-reading this post (DUH!!!) I've been using the variable Volts_10 as the ADC result and displaying the Variable Volts10 to the LCD. othink I've been shooting this problem for about a week!!

With a 10.6 VDC input, the ADC result in Volts_10 is 495.

Thanks guys - I am embarassed.

John P

mister_e
- 7th January 2008, 22:06
http://www.mister-e.org/Pics/woohoo

Don't worry... it happen to everybody.

JohnP
- 7th January 2008, 22:18
Steve,
It supposed to happen to everybody


ELSE!!

John P

mister_e
- 7th January 2008, 22:20
bah... where would be the fun? ;)