Microchip Technology DM183037 Data Sheet

Page of 696
 2012 Microchip Technology Inc.
DS30575A-page 463
PIC18F97J94 FAMILY
22.5.2
CLOCKED CONVERSION TRIGGER
When ADRC = 1, the conversion trigger is under A/D
clock control. The SAMCx bits (ADCON3H<4:0>)
select the number of TAD clock cycles between the
start of sampling and the start of conversion. After the
start of sampling, the module will count a number of
TAD clocks specified by the SAMCx bits. The SAMCx
bits must always be programmed for at least one clock
cycle to ensure sampling requirements are met.
EQUATION 22-2:
CLOCKED CONVERSION 
TRIGGER TIME 
 shows how to use the clocked conversion
trigger with the sampling started by the user software.
FIGURE 22-6:
CONVERTING ONE CHANNEL, MANUAL SAMPLE START, T
AD
-BASED 
CONVERSION START   
EXAMPLE 22-2:
CONVERTING ONE CHANNEL, MANUAL SAMPLE START, T
AD
-BASED 
CONVERSION START CODE
T
SMP
 = SAMC<4:0> * T
AD
A/D CLK
SAMP
ADC1BUF0
T
SAMP
T
CONV
BSF AD1CON1, SAMP
Instruction Execution
DONE
int ADCValue;
ANSB
= 0x1000;
// all PORTB = Digital; RB12 = analog
AD1CON1 = 0x00E0; 
// SSRC<2:0> = 111 implies internal counter ends sampling
// and starts converting.
AD1CHS = 0x000C;
 
// Connect AN12 as S/H input.
// in this example AN12 is the input
AD1CSSL = 0;
AD1CON3 = 0x1F02; 
// Sample time = 31Tad, Tad = 3Tcy
AD1CON2 = 0;
AD1CON1bits.ADON = 1; 
// turn ADC ON
while (1) 
// repeat continuously
{
AD1CON1bits.SAMP = 1;
// start sampling, then after 31Tad go to conversion
while (!AD1CON1bits.DONE){};
// conversion done?
ADCValue = ADC1BUF0; 
// yes then get ADC value
} // 
repeat