void ADCInit void AD1CON1 turn ADC OFF AD1CON1bits SSRC Internal count

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void ADCInit(void)
{ AD1CON1 = 0; // turn ADC OFF
AD1CON1bits.SSRC = 7; // Internal counter ends sampling
//and starts conversion (auto convert)
AD1CON1bits.ASAM = 1; // Sampling begins immediately after
//last conversion completes; SAMP bit is automatically set.
AD1CON2 = 0;
AD1CON2bits.CSCNA = 1; // Scan inputs
AD1CON2bits.SMPI = 3; // Interrupts at the completion
//of conversion for each (N+1) sample/convert sequence
AD1CON3 = 0;
AD1CON3bits.SAMC = 15; // Auto-Sample Time bits N Tad
AD1CON3bits.ADCS = 8; // Tad = N Tcy
AD1CHS = 0;
AD1PCFG = ~(1<<0 | 1<<1 | 1<<6); // 0-analog 1-digital
AD1CSSL = (1<<0) | (1<<1) | (1<<6) ; // select scan input V12, V6, Irele
AD1CON1bits.ADON = 1; // turn ADC ON
}