# Specific ADC input not working on Microchip PIC PIC24FJ128GA202, other inputs work fine

I am trying to get an analog input working on my microcontroller. I am using the PIC 24FJ128GA204. The problem is that a specific input is not working, while other do work.

I want pin 26, AN9/C3INA/RP15/T3CK/T2CK/CTED6/CN11/RB15, to be the input. Other analog inputs seem to be working fine, but when I configure the input pin to be AN9 the results seem to be floating, even if I ground the input. The samples I get: 3987, 3987, 3988, 3989, 3989, 3987, etc. Below is the code I am using:

void initAD(){
//Pin used for ADC is pin 26 = RB15 = AN9

TRISBbits.TRISB15 = 1; //RB15 is input
ANSBbits.ANSB15 = 1; //analog mode

AD1CON1bits.MODE12 = 1; //set 12 bit mode operation
AD1CON1bits.ASAM = 1; //SAMP bit is auto-set

AD1CON2bits.PVCFG = 0b00; //00 = Vss, 01 = External VREF+

AD1CHSbits.CH0NA = 0; //negative is VREF-/AVSS
AD1CHSbits.CH0SA = 0b01001; //channel A AN9

AD1CHSbits.CH0NB = 0; //negative is VREF-/AVSS
AD1CHSbits.CH0SB = 0b01001; //channel B AN9

AD1CSSL = 0;            //No scanned inputs
}


and:

uint16_t ADread(){

}


Thanks for reading. If you have any suggestions, that would be great.

• Did you figure this out? I have the exact same problem - same part number, same input pin. All other pins are fine. May 8 '15 at 18:24
• Its the thing in the errata sheet, described below: AN9 is simply not available on the 28 pin devices. Had the same problem. If it wasn't for that thread, I would have never found this one, especially so, because 99.9% of the time if something is not working it is your fault not reading the datasheet correctly. I would have kept on searching this for days. Thanks for posting the question and thanks for hinting at the errata sheet. Oct 25 '17 at 13:32

PIC24FJ128GA204 Family Silicon Errata and Data Sheet Clarification

AN9 has been removed from all 28-Pin diagrams and tables. This analog channel is unimplemented in 28-pin devices.

But datasheet is not repaired..

• "The Devil is in the Details" I always say... Oct 16 '15 at 14:05
• I remember stumbling upon a PIC micro that had one of the ADC channels physically not connected to the multiplexer. Errata is always worth taking a look at ;) Oct 16 '15 at 16:13

The code looks correct to me. Check the rest of your code to see if you accidentally assigned some digital peripheral output to this channel. Better yet, instead of posting code fragments write a short sketch demonstrating this particular issue only, i.e., conf.bits plus main with AD init and poll and nothing else. It would also be helpful to know how you test.

Do you use DMA?

I think some dsPICs have dedicated ADCBUFx for every analog pin, others just use ADCBUF0 for every conversion.

You also need to configure other stuff...

Tell adc to convert for instance CH0:

Select which channels to scan: