Re: ADC setup on 12F1822 ??
works for me
Code:
#CONFIG
cfg1 = _FOSC_INTOSC
cfg1&= _WDTE_ON
cfg1&= _PWRTE_OFF
cfg1&= _MCLRE_OFF
cfg1&= _CP_OFF
cfg1&= _CPD_OFF
cfg1&= _BOREN_ON
cfg1&= _CLKOUTEN_OFF
cfg1&= _IESO_ON
cfg1&= _FCMEN_ON
__CONFIG _CONFIG1, cfg1
cfg2 = _WRT_OFF
cfg2&= _PLLEN_OFF
cfg2&= _STVREN_ON
cfg2&= _BORV_19
cfg2&= _LVP_OFF
__CONFIG _CONFIG2, cfg2
#ENDCONFIG
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
ADCON1=$f0 'rc clk vdd ref right justify
osccon=$6A '4 mhz
anselA=1 'dig i/o
' CMCON0=7 ' compare off
trisA=001
adval var word
main:
pause 5
ADCIN 0, adval
lata=0
if adval > 500 then lata.2= 1 'led1
if adval> 200 then lata.1=1' led2
goto main
Re: ADC setup on 12F1822 ??
Thanks ^^^
I am doing the same register setups as you show, except that I'm using AN2 (ANSELA=%0100, TRISA=%01100). In addition I have ADCON0.0=1 (enable ADC). I'll try removing this. I'll work on this and post my results.
Thanks again!
Re: ADC setup on 12F1822 ??
ADCON0.0=1 serves no purpose the ADCIN code will do that for you
Re: ADC setup on 12F1822 ??
This may be obvious but since you didn't post your code I'll say it anyway.
The variable you're putting the result in is declared as a WORD, right?
/Henrik.
Re: ADC setup on 12F1822 ??
looks like "Occam's Razor" may have struck again
Re: ADC setup on 12F1822 ??
Quote:
Originally Posted by
HenrikOlsson
... The variable you're putting the result in is declared as a WORD, right? /Henrik.
Yes, it's a WORD. But thanks!
Re: ADC setup on 12F1822 ??
Not sure if you figured this out, but 10bit AD need to be read out as RIGHT justified, and 8 bit reads should be LEFT justified. Here's a config that works for 8-bit:
ADCON0.0 = 1 ' AD ON
ANSELA = %00000001 ' select analog vs digital (1=analog)
ADCON1.7 = 1 ' bit7 = 1 = LEFT justified
define adc_bits 8 ' set ADC as 8 bit
Re: ADC setup on 12F1822 ??
Thank you^^^. Yes, I got it sorted out. I think my initial confusion resulted from some interaction between PBP3 DEFINEs for the ADC module and some direct settings I was also doing on some ADC-related registers. Everythings good now. Thanks again!