Hello !!! i have a little doubt about the ADC ... can anyone help me ??

i have a USB interface (Hard) with a 18F2550 pic, on wich i can turn on/off some leds by the Soft in Visual Net... i want to use the Inputs and read some data, i read the input data in the Digital Input, and that was correct, but i still can not read the input data in the Analogic Input .. can anyone help me and tell me if im writing bad the code of the ADC or something like that ?? all the comunication is fine, and in the terminal input i can read with the multimeter the voltage (2.5 volts) that im sending to the pic, so there is a signal !!!

thks a lot !!!! really a lot !!!

Frank

______________________________________________


DEFINE OSC 12

USBBufferSizeMax con 8 ' maximum buffer size
USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output

' the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
USBBufferCount Var Byte

ADCON1 = $0D ' inicializar el registro hace que adc0 - 3 sean entradas analogicas.
TRISA = $0F ' el Puerto A lo declara como Entradas
TRISB = 0 ' el Puerto B lo declara como Salidas
CMCON = 7 ' deshabilitar los comparadores

' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
usbinit ' initialise USB...
ProgramStart:
gosub DoUSbiN
gosub DoUSBOut

GOSUB DoTemp
GOSUB DoAna

PORTB=USBBuffer[7]
goto ProgramStart

' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available
return

' ************************************************** **********
' * wait for USB interface to attach *
' ************************************************** **********
DoUSBOut:
USBBufferCount = USBBufferSizeTX ' TX buffer size
USBService ' keep connection alive
USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
return

' ************************************************** **********
' * Parte nueva del codigo para medir la Temperatura *
' ************************************************** **********

DoTemp:
'Configurar como input (Puerto A, Entrada 4, Pin 6 como Entrada)
TRISA.4 = 1

' Declara las Variables para la Temperatura
FREC VAR WORD
ZERO VAR WORD
RES VAR WORD
RES1 VAR WORD
RES2 VAR WORD
RES3 VAR WORD

' Hace la medición de la Frecuencia de entrada al Pic y realiza
' operaciones para dar la Temperatura
COUNT PORTA.4, 1000, FREC
ZERO = 30750
RES = FREC * 10
RES1 = RES - ZERO
RES2 = 65535 - RES1
RES3 = RES1 / 140

' Cada Variable la asigna a un bit del buffer para poder ser leido
' por el sistema
USBBuffer[0] = "T"
USBBuffer[1] = FREC
USBBuffer[2] = ZERO
USBBuffer[3] = RES
USBBuffer[4] = RES1
USBBuffer[5] = RES2
USBBuffer[6] = RES3

' Envia a subrutina de USBOut y regresa al programa
GOSUB DoUSBOut
PORTB=USBBuffer
RETURN


' ************************************************** **********
' * Parte nueva del codigo para probar entrada Analoga *
' ************************************************** **********

DoAna:
'Configurar como input (Puerto A, Entrada 1, Pin3 como Entrada)
TRISA.2 = 1

' Declara las Variables para la Medicion del Voltaje del Pot
VOLTPOT VAR WORD
MIL VAR WORD
RESANA VAR WORD

' Hace la medición del Voltaje de entrada al Pic y realiza
' operaciones
COUNT PORTA.2, 1000, VOLTPOT
MIL = 1000
RESANA = VOLTPOT * MIL

' Cada Variable la asigna a un bit del buffer para poder ser leido
' por el sistema
USBBuffer[0] = "V"
USBBuffer[1] = VOLTPOT
USBBuffer[2] = MIL
USBBuffer[3] = RESANA

' Envia a subrutina de USBOut y regresa al programa
GOSUB DoUSBOut
PORTB=USBBuffer
RETURN

__________________________________________________ ________