EasyManua.ls Logo

Microchip Technology dsPIC30F - Page 445

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
© 2004 Microchip Technology Inc. DS70065C-page 18-15
Section 18. 12-bit A/D Converter
12-bit A/D
Converter
18
Example 18-1: Converting 1 Channel, Manual Sample Start,
Manual Conversion Start Code Example
Figure 18-4 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.
Figure 18-4: Converting 1 Channel, Automatic Sample Start, Manual Conversion Start
ADPCFG = 0xFFFB; // all PORTB = Digital; RB2 = analog
ADCON1 = 0x0000; // SAMP bit = 0 ends sampling ...
// and starts converting
ADCHS = 0x0002; // Connect RB2/AN2 as CH0 input ..
// in this example RB2/AN2 is the input
ADCSSL = 0;
ADCON3 = 0x0002; // Manual Sample, Tad = internal 2 Tcy
ADCON2 = 0;
ADCON1bits.ADON = 1; // turn ADC ON
while (1) // repeat continuously
{
ADCON1bits.SAMP = 1; // start sampling ...
DelayNmSec(100); // for 100 mS
ADCON1bits.SAMP = 0; // start Converting
while (!ADCON1bits.DONE); // conversion done?
ADCValue = ADCBUF0; // yes then get ADC value
} // repeat
ADCLK
SAMP
ADCBUF0
TSAMP
TCONV
BCF ADCON1,SAMP
Instruction Execution
TCONV
BSF ADCON1,ASAM BCF ADCON1,SAMP
TSAMP
TAD0
TAD0

Table of Contents

Other manuals for Microchip Technology dsPIC30F