Specifications

© 2006 Microchip Technology Inc. DS70183A-page 16-23
Section 16. Analog-to-Digital Converter (ADC)
A
D
C
16
Example 16-1: Converting 1 Channel, Manual Sample Start,
Manual Conversion Start Code
Figure 16-6 is an example where setting the ASAM bit initiates automatic sampling and clearing
the SAMP bit terminates sampling and starts conversion. After the conversion completes, the
ADC module automatically returns to a sampling state. The SAMP bit is automatically set at the
start of the sample interval. The user software must time the clearing of the SAMP bit to ensure
adequate sampling time of the input signal, understanding that the time between clearing of the
SAMP bit includes the conversion time as well as the sampling time. See Example 16-2 for code
example.
Figure 16-6: Converting 1 Channel, Automatic Sample Start, Manual Conversion Start
AD1PCFGL = 0xFFFB; // all PORTB = Digital; RB2 = analog
AD1CON1 = 0x0000; // SAMP bit = 0 ends sampling ...
// and starts converting
AD1CHS0 = 0x0002; // Connect RB2/AN2 as CH0 input ..
// in this example RB2/AN2 is the input
AD1CSSL = 0;
AD1CON3 = 0x0002; // Manual Sample, Tad = internal 2 Tcy
AD1CON2 = 0;
AD1CON1bits.ADON = 1; // turn ADC ON
while (1) // repeat continuously
{
AD1CON1bits.SAMP = 1; // start sampling ...
DelayNmSec(100); // for 100 mS
AD1CON1bits.SAMP = 0; // start Converting
while (!AD1CON1bits.DONE);// conversion done?
ADCValue = ADC1BUF0; // yes then get ADC value
} // repeat
ADC Clock
SAMP
ADC1BUF0
TSAMP
TCONV
BCLR AD1CON1,SAMP
Instruction Execution
TCONV
BSET AD1CON1,ASAM BCLR AD1CON1,SAMP
TSAMP
TAD0 TAD0
DONE