EmbDev.net

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


von sbruegmann (Guest)


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:
1
void initadcExample(void){
2
/* Set port configuration */ 
3
ANSELA = ANSELB = ANSELC = ANSELD = ANSELE = ANSELG = 0x0000;
4
ANSELBbits.ANSB0 = 0; // Ensure AN0/RB0 is analog
5
ANSELBbits.ANSB1 = 0; // Ensure AN1/RB1 is analog
6
ANSELBbits.ANSB2 = 1; // Ensure AN2/RB2 is analog
7
ANSELBbits.ANSB5 = 0; // Ensure AN5/RB5 is analog
8
/* Initialize and enable ADC module */
9
AD1CON1 = 0x000C; // Enable simultaneous sampling and auto-sample
10
AD1CON2 = 0; // 0x0300; // Sample 4 channels
11
AD1CON3 = 0; // 0x000F;
12
AD1CON1bits.AD12B  = 1;              // 12-bit ADC operation  => CHPS, CH123NB, CH123SB, CH123NA, CH123SA unimplemented
13
AD1CON4 = 0x0000;
14
AD1CSSH = 0x0000;
15
AD1CSSL = 0x0000;
16
AD1CHS0bits.CH0SA = 2; // Select AN2 for CH0 +ve input
17
AD1CHS0bits.CH0NA = 0; // Select Vref- for CH0 -ve input
18
AD1CHS123bits.CH123SA = 0; // Select AN0 for CH1 +ve input
19
// Select AN1 for CH2 +ve input
20
// Select AN2 for CH3 +ve input
21
AD1CHS123bits.CH123NA = 0; // Select Vref- for CH1/CH2/CH3 -ve inputs
22
AD1CON1bits.ADON = 1;
23
}
24
25
int readadc(){
26
  AD1CON1bits.SAMP = 0; // Start the conversions
27
  while(!_AD1IF); // wait for all 4 conversions to be done
28
  _AD1IF = 0; // Clear conversion done status bit
29
    return ADC1BUF0;                // result stored in ADC1BUF3
30
}

von Beginner (Guest)


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...

Reply

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.