Two things I have noticed in your code:
1/. The 16F1826 has a 10 bit ADC whereas you have defined an 8 bit setup
2/. ADCCON0 = %00001001 sets the ADC channel to be AN9 where you are trying to use AN2
Cheers
Barry
VK2XBP
Two things I have noticed in your code:
1/. The 16F1826 has a 10 bit ADC whereas you have defined an 8 bit setup
2/. ADCCON0 = %00001001 sets the ADC channel to be AN9 where you are trying to use AN2
Cheers
Barry
VK2XBP
Hey Barry!
Thanks so much!!!
This did it!
I actually thought you could tell a 10-bit ADC to work as an 8-bit. But no worries! All is perfect once again!!DEFINE OSC 4
DEFINE ADC_BITS 10 ' 10 bit A/D Conversion
DEFINE ADC_CLOCK 4
DEFINE ADC_SAMPLEUS 50 ' 50 uS A/D sample time
PORTA = 0
PORTB = 0
TRISA = %00101100
TRISB = %00000000
ADCON1 =%11000000 'Right justified
ANSELA =%00000010 ' AN2 on PortA.2 analog
ANSELB =%00000000 ' Digital inputs
Hi SOTATOSA
10 bit A/D converters do work in 8 bit mode. Just set LEFT justified and the 8 MSBs are held in the ADRESH register and the 2 LSBs are held in the ADRESL register bits 6 and 7 which you ignore. ADRESH register contains the 8 bit result. I think this is how DEFINE ADC_BITS 8 works. Setting 8 bit conversion AND RIGHT justified would cause some confusion. Hope this helps.
Phil
this tutorial helped me understand A/D a little better...
http://www.microcontrollerboard.com/...converter.html
and here is another good tutorial...
http://www.edaboard.com/nextoldesttoentry1570.html
Last edited by Heckler; - 11th February 2014 at 22:39.
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Thanks for all the replies. Making some kind of sense now! :-)
Bookmarks