18.4.2 Analog Inputs

Any analog input (external pin or internal analog signal) can be mapped to any channel by PINSEL[3:0] bits (ADnCHxCON[14:11]) for a positive input and by NINSEL[1:0] bits (ADnCHxCON[9:8]) for a negative input. The input can be configured as a single-ended or differential using DIFF bit (ADnCHxCON[15]).

The ANSELx registers for the I/O ports, associated with the analog input, are used to configure the corresponding pins as analog pins. A pin is configured as an analog input when the corresponding ANSELx bit = 1. When the ANSELx bit = 0, the pin is set to a digital control. The ANSELx bits are set when the device comes out of Reset, causing the ADC input pins to be configured as analog inputs by default. The TRISx registers control the digital function of the port pins. The port pin that is required as an analog input must have its corresponding bit set in the specific TRISx register, configuring the pin as an input. If the I/O pin associated with an ADC input is configured as an output by clearing the TRISx bit, the port’s digital output level will be converted. After a device Reset, all TRISx bits are set. The PORT register bit reads as ‘0’ if its corresponding pin is configured as an analog input. For more information on port pin configuration, refer to the “I/O Ports” chapter.