© 2004 Microchip Technology Inc. DS70064C-page 17-19
Section 17. 10-bit A/D Converter
10-bit A/D
Converter
17
Figure 17-5 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
module will automatically return 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 17-2 for code
example.
Figure 17-5: Converting 1 Channel, Automatic Sample Start, Manual Conversion Start
Example 17-2: Converting 1 Channel, Automatic Sample Start,
Manual Conversion Start Code
ADCLK
SAMP
ADCBUF0
TSAMP
TCONV
BCF ADCON1,SAMP
Instruction Execution
TCONV
BSF ADCON1,ASAM BCF ADCON1,SAMP
TSAMP
TAD0 TAD0
DONE
ADPCFG = 0xFF7F; // all PORTB = Digital but RB7 = analog
ADCON1 = 0x0004; // ASAM bit = 1 implies sampling ..
// starts immediately after last
// conversion is done
ADCHS = 0x0007; // Connect RB7/AN7 as CH0 input ..
// in this example RB7/AN7 is the input
ADCSSL = 0;
ADCON3 = 0x0002; // Sample time manual, Tad = internal 2 Tcy
ADCON2 = 0;
ADCON1bits.ADON = 1; // turn ADC ON
while (1) // repeat continuously
{
DelayNmSec(100); // sample for 100 mS
ADCON1bits.SAMP = 0; // start Converting
while (!ADCON1bits.DONE); // conversion done?
ADCValue = ADCBUF0; // yes then get ADC value
} // repeat