Forum: µC & Digital Electronics PIC24EP512GU810 - ADC MCP9700: no realistic values

Author: sbruegmann (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi guys,
I'm new to this whole microcontroller thing and might therefore easilly 
lack of some knowledge. After going through many forums I still couldn't 
figure out, how to get my 12-bit ADC conversion working.
In my card I have a PIC24EP512GU810 processor connected to a thermometer 
sensor MCP9700 on pin RB2. As I said, I tried many examples and read the 
datasheet over and over. Maybe I'm just too stupid. But perhaps you 
could help me.
Here is the relevant code:
void initadcExample(void){
/* Set port configuration */ 
ANSELBbits.ANSB0 = 0; // Ensure AN0/RB0 is analog
ANSELBbits.ANSB1 = 0; // Ensure AN1/RB1 is analog
ANSELBbits.ANSB2 = 1; // Ensure AN2/RB2 is analog
ANSELBbits.ANSB5 = 0; // Ensure AN5/RB5 is analog
/* Initialize and enable ADC module */
AD1CON1 = 0x000C; // Enable simultaneous sampling and auto-sample
AD1CON2 = 0; // 0x0300; // Sample 4 channels
AD1CON3 = 0; // 0x000F;
AD1CON1bits.AD12B  = 1;              // 12-bit ADC operation  => CHPS, CH123NB, CH123SB, CH123NA, CH123SA unimplemented
AD1CON4 = 0x0000;
AD1CSSH = 0x0000;
AD1CSSL = 0x0000;
AD1CHS0bits.CH0SA = 2; // Select AN2 for CH0 +ve input
AD1CHS0bits.CH0NA = 0; // Select Vref- for CH0 -ve input
AD1CHS123bits.CH123SA = 0; // Select AN0 for CH1 +ve input
// Select AN1 for CH2 +ve input
// Select AN2 for CH3 +ve input
AD1CHS123bits.CH123NA = 0; // Select Vref- for CH1/CH2/CH3 -ve inputs
AD1CON1bits.ADON = 1;

int readadc(){
  AD1CON1bits.SAMP = 0; // Start the conversions
  while(!_AD1IF); // wait for all 4 conversions to be done
  _AD1IF = 0; // Clear conversion done status bit
    return ADC1BUF0;                // result stored in ADC1BUF3

Author: Beginner (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi sbruegmann,

a PIC controller is really challenging for a newcomer, you should better 
try an AVR first. As your post is half a year old already, did you make 
any progress so far?

Best regards...


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.