Hello, I am trying to just make a demo program so I can view the Ato D value on my LCD. I am not having good luck. I looked at another post that discussed problems with A to D on the 16F876. I was using this as a guide but something is not right.
I am trying to read a pot on RA4/AN3. I am reading a value but as I adjust my pot the numbers do not count up in a linear fashion. It will count from 0 to 1 to 2 for 7/8 of the single turn pot and then the numbers jump to 255 very quickly. This is linear pot and I should be gettng a linear increase or decrease.
Here is my code and the settings that I believe are relavant. The code is supposed to read the voltage from the pot and update a LCD to tell me the output. Thanks for any help.
----------------------------------------
AD_AN3 VAR PORTA.4
AD_AN3_VALUE VAR byte
DEFINE ADC_BITS 8 ' set number of bits in result
DEFINE ADC_CLOCK 3 ' set clock source
DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
MENU:
LCDOUT $FE, 1 ' Clear LCD screen
A_D_AN3:
ADCON0 = %00001101
PAUSEUS 50 ' wait 50 microsec
' ADCON0.2 = 1 'start conversion(bit 2= 1)
' WHILE ADCON0.2 = 1
' WEND ' wait for conversion
ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
LCDOUT $FE, 1 ' Clear LCD screen
LCDOUT "A to D Value"
LCDOUT $FE, $C0, #AD_AN3_VALUE
PAUSe 100
BUTTON FUNCTION_BUTTON, 1, 255, 0, C2, 1, ON_TIME_FUNC
GOTO A_D_AN3
Bookmarks