newtonsrl
Junior Member level 3
Hi,
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:
just for test, I set the pin RB2/AN2 as digital output, so when the pin is in high state I should read 0x3FF, and when is low I should read 0x00.
Changing the state of LATB2 the result of the ADC conversion doesn't change, and the result is always 0x00.
Changing the state of the LATB11 the conversion result change to 0x3FF when high and 0x00 when low.
I've already verified the PCB and there is no mistake or other problem, no crosstalk or other things.
Could someone help me to figure out please?
Thank you very much.
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:
Code:
void ReadBatteryAdc()
{
//disable timer 4
T4CONbits.TON = 0;
CloseADC10();
//mPORTBSetPinsAnalogIn(BIT_2);
//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
DelayMs(100);
AD1CON1bits.SAMP = 1;
DelayMs(100);
while(AD1CON1bits.DONE == 0);
vBitLevel = ADC1BUF0;
//enable timer4
TickTouchInit();
TouchHardwareInit(NULL);
}
just for test, I set the pin RB2/AN2 as digital output, so when the pin is in high state I should read 0x3FF, and when is low I should read 0x00.
Changing the state of LATB2 the result of the ADC conversion doesn't change, and the result is always 0x00.
Changing the state of the LATB11 the conversion result change to 0x3FF when high and 0x00 when low.
I've already verified the PCB and there is no mistake or other problem, no crosstalk or other things.
Could someone help me to figure out please?
Thank you very much.