I made a custom board based on Microchip MEB (DM320005) and PIC32 Ethernet Starter Kit that use the MCU in subject.
My board has a touch screen that works fine, connected to AN11 AN12 AN13 and AN14.
The internal ADC10 of the pic convert the analog signal to X and Y position.
My board is powered by a Li-ion battery 3.7V and I need to know the battery voltage to have simple indication of the battery state, so I connected the battery to AN2 through a voltage divider.
I'm using the microchip touchscreen driver included in microchip framework V. 2013-06-15.
My problem is I cannot get the correct value of the adc for the AN2 channel. To do some tests I used the code below, took from the Microchip ADC reference:
//disable timer 4
T4CONbits.TON = 0;
//ADC_POT_PCFG = RESISTIVETOUCH_ANALOG;
TRISBbits.TRISB11 = 0;
TRISBbits.TRISB12 = 0;
TRISBbits.TRISB13 = 0;
TRISBbits.TRISB14 = 0;
TRISBbits.TRISB2 = 0;
LATBbits.LATB11 = 0;
LATBbits.LATB12 = 0;
LATBbits.LATB13 = 0;
LATBbits.LATB14 = 0;
LATBbits.LATB2 = 1;
AD1CHSSET = 0x0020000;
AD1CON1 = 0; // reset
AD1CON2 = 0; // AVdd, AVss, int every conversion, MUXA only
AD1CON3 = 0x1FFF; // 31 Tad auto-sample, Tad = 256*Tcy
AD1CON1 = 0x80E0; // Turn on A/D module, use auto-convert
AD1CSSL = 0; // No scanned inputs
AD1CON1bits.SAMP = 1;
while(AD1CON1bits.DONE == 0);
vBitLevel = ADC1BUF0;