PDA

View Full Version : How can you understand ADCON?



Ramius
- 27th May 2017, 18:20
Hi All,
Trying to understand how to set "ADCON". We start with ADCON0, then ADCON1, then ADCON2. Is this the same as setting RA0-7 to either a 1 or a 0? 1 meaning the RA is analog and 0 meaning it is digital? Then would ADCON0 apply to the RA0-7 pins and ADCON1 the RB0-7 pins and ADCON2 the RC0-7 pins? If you do not define an ADCON what happens? YES, I did look at the data sheet for an 18F2520 and all I see is text! I have read other posts and nothing seems to be very clear.

Thanks, Ed

pedja089
- 27th May 2017, 18:29
Take look at http://ww1.microchip.com/downloads/en/devicedoc/39631a.pdf and page 226.

towlerg
- 28th May 2017, 15:16
Is this the same as setting RA0-7 to either a 1 or a 0? 1 meaning the RA is analog and 0 meaning it is digital?
I'm not sure that a very helpful way to view the situation. Generally PIC devices have 1 single ADC who's input is connected to a multiplexor, in turn the inputs to multiplexor are connected to external pins.

I don't know what device you are using so I can't go into specifics but for example on a 18F4550, ADCON bit 5-2 determine which multiplexor input is connected to the ADC. Bit 1 is set low to initiate a conversion and will go high when data is available. Bit 0 enables the ADC.

ADCON1 bit 6-7 allow you to offset the top and/or bottom reading of the ADC. Bits 3-0 determine which possible multiplexor inputs are used (analogue to use, digital for GPIO).

ADCON2 bit 7 determines the formatting of the 10 bit result in the high and low result registers, bit 5-3 set conversion time and bit 2-0 determine the ADC clock source.

If you take your time, set each bit in turn. It's helpful to use binary notation as it show exactly what is set and what is clear.

I hope that helps.