Microchip Technology DM183037 Data Sheet

Page of 696
PIC18F97J94 FAMILY
DS30575A-page 462
 2012 Microchip Technology Inc.
FIGURE 22-4:
CONVERTING ONE CHANNEL, MANUAL SAMPLE START, MANUAL 
CONVERSION START
EXAMPLE 22-1:
CONVERTING ONE CHANNEL, MANUAL SAMPLE START, MANUAL 
CONVERSION START CODE
FIGURE 22-5:
CONVERTING ONE CHANNEL, AUTOMATIC SAMPLE START, MANUAL 
CONVERSION START   
A/D CLK
SAMP
ADC1BUF0
T
SAMP
T
CONV
BCF AD1CON1, SAMP
BSF AD1CON1, SAMP
Instruction Execution
DONE
int ADCValue;
ANSB
= 0x0001; 
// AN2 as analog, all other pins are digital
AD1CON1 = 0x0000; 
// SAMP bit = 0 ends sampling and starts converting
AD1CHS = 0x0002; 
// Connect AN2 as S/H+ input
// in this example AN2 is the input
AD1CSSL = 0;
AD1CON3 = 0x0002;
 
// Manual Sample, Tad = 3Tcy
AD1CON2 = 0;
AD1CON1bits.ADON = 1; 
// turn ADC ON
while (1) 
// repeat continuously
{
AD1CON1bits.SAMP = 1; 
// start sampling...
Delay();
// Ensure the correct sampling time has elapsed
// before starting conversion.
AD1CON1bits.SAMP = 0;
// start converting
while (!AD1CON1bits.DONE){};
// conversion done?
ADCValue = ADC1BUF0; 
// yes then get ADC value
}
A/D CLK
SAMP
ADC1BUF0
T
SAMP
T
CONV
BCF AD1CON1, SAMP
T
CONV
BSF AD1CON1, ASAM
BCF AD1CON1, SAMP
T
SAMP
T
AD
0
T
AD
0
Instruction Execution