PicBasic Pro
17C756A
4 Mhz
Slow Learner at the wheel.

I am trying to use the ADC on a PIC for the first time and I have hit problems. I have spent several hours trying to work out the problem, but to no avail, your help would be most appreciated. I am trying to read the value of three different voltages on three different PIC pins of my 17C756A. The voltages to be measured are all in the range of 0 to 5V, and one of these to be measured, is simply a 10K Pot with its 2 ends connected to +5V and 0V and the wiper to PortG1. I have tied the A-VDD pin to the supply voltage +5V and tied the A-VSS pin to 0V. To experiment to see if I am reading anything or not, I have put a simple routine in so the the voltage on PortG1 is stored as value B21 (the other two values to be stored as B22 and B23). The value of these three variables is displayed on an LCD and re-read every 500. I am not reading the voltage correctly because the result (although stable if you leave the pot alone) is not 0-255 but something like either of the following:- 64, 128, 196, but not linear nor in the correct order, please would some kind soul look at my code and tell me where I am going wrong.

B21 VAR BYTE
B22 VAR BYTE
B23 VAR BYTE

TRISB = %00110000
TRISC = %00000100
TRISD = %11111111
TRISE = %1101
TRISF = %00000000
TRISG = %11101110

ADCON1 = %000000001110

ADCON1.7 = 1

DEFINE LCD_DREG PORTF
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 7
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

GoTo MAIN

MAIN:

GOSUB LCDIT
PAUSE 500
GOTO MAIN


LCDIT: ADCIN 0, B23
ADCIN 1, B22
ADCIN 2, B21
LCDOut $FE,1,#B7
LCDOut $FE,$14,#B8
LCDOut $FE,$14,#B21
LCDOut $FE,$14,#B22
LCDOUT $FE,$14,#B23
LCDOUT $FE,$C0,"Readings "
RETURN

I have stripped out the code which I think is unecessary.