Hello all
I'm trying to use a new chip to me, an 16f1826. I liked the idea of the 4.086 internal voltage reference. I wrote the test code below, trying to follow the datasheet. Unlike others, I've never had a problem using ADCIN so I am using it. The program compiles, loads and runs, but the display reads 00001, 00002 and 00003, depending on what my test pot is set to. Interestingly, it does correspond to 1, 2 and 3 volts input, but I'm assuming its coincidental since its a 10 bit register. The Microchip errata says that in my silicon version there is sometimes a flaw in the ADC circuit such that the "done" bit never comes true but I'm assuming thats not the problem because it does change its value and updates each cycle through. Any thoughts or comments would be appreciated.
Take care
Alec
Code:
'****************************************************************
'* Name : 16f1826_test *
'* Author : alec noble *
'* Notice : Copyright (c) 2012 alec noble *
'* : All Rights Reserved *
'* Date : 8/31/2012 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _MCLRE_ON & _CLKOUTEN_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_OFF
#ENDCONFIG
OSCCON = %01111010 '16 mhz internal clock, PLL off
DEFINE OSC 16
'define adc_bits = 10
TRISA = %00000001 'RA0 input, all others output
trisb = %00000001
FVRCON = %11000011 'Fixed voltage reference on, comparator and output off, set to 4.096
ANSELA = 1 'AN0 analog, all others digital
ANSELB = 0 'all port B digital
ADCON1 = %11100011 'right justified, clock = fosc/64, neg ref = Vss, pos ref = FVR
ADC var word
txpin var portb.0
ADC = 0
Pause 500 ' let everything stabilize
SEROUT2 txpin, 84, [24] 'turn serial LCD on
main:
ADCIN 0, adc
SEROUT2 txpin, 84, [12]
PAUSE 5
SEROUT2 txpin, 84, [128, dec5 adc]
pause 250
goto main
Bookmarks