Skip to main content
Topic: Analog Input (Read 1056 times) previous topic - next topic

Analog Input

I am trying to use AN2 and AN3 on this board as analog inputs (PGC & PGD). I am having trouble getting the board to read the correct values, I've tried 10-bit and 12-bit modes. The only values I've got out of ADC1BUF0 are 0 and 32767, both times when I have read those values I had no inputs on the pins. If I must use a negative reference to use these pins I would like to use AN0 or AN1 which are unused and right beside them, I've bascially tried everything and have read the manual, but can't figure out how to get these analog inputs to work. Could anyone give me some direction or code? Here is what I have now in the InitHardware function:

       AD1PCFGL = 0xFFFF; //digital pins
   AD1PCFGLbits.PCFG2 = 0;
   AD1PCFGLbits.PCFG3 = 0;
   
   AD1CON1bits.FORM   = 3;      // Data Output Format: Signed Fraction (Q15 format)
   AD1CON1bits.SSRC   = 2;      // Sample Clock Source: GP Timer starts conversion
   AD1CON1bits.ASAM   = 1;      // ADC Sample Control: Sampling begins immediately after conversion
   AD1CON1bits.AD12B  = 0;      // 12-bit ADC operation turned off
   
   AD1CON3bits.ADRC = 0;      // ADC Clock is derived from Systems Clock
   AD1CON3bits.ADCS = 63;   
   AD1CON2bits.CHPS  = 1;      // Converts CH0
   
    //AD1CHS0bits.CH0SA=2;      // MUXA +ve input selection (AN5) for CH0
   AD1CHS0bits.CH0NA=0;      // MUXA -ve input selection (Vref-) for CH0

   IFS0bits.AD1IF = 0;         // Clear the A/D interrupt flag bit
        IEC0bits.AD1IE = 0;         // Do Not Enable A/D interrupt
   AD1CON1bits.ADON = 1;

Thanks in advance.

Re: Analog Input

Reply #1
Hi frontline,

I'm not sure about this one, but I'll look into it and add a how-to on dangerousprototypes when I figure it out.
Got a question? Please ask in the forum for the fastest answers.