26 Section 26. 10-bit A/D Converter

/table> Yahoo! is not affiliated with the authors of this page or responsible for its content.
26 Section 26. 10-bit A/D Converter
2000 Microchip Technology Inc.
DS39527A-page 26-1
10
-bi
t
A
/
D
C
o
n
ver
te
r
26
Section 26. 10-bit A/D Converter
HIGHLIGHTS
This section of the manual contains the following major topics:
26.1 Introduction .................................................................................................................. 26-2
26.2 Control Register ........................................................................................................... 26-4
26.3 Operation ..................................................................................................................... 26-7
26.4 A/D Acquisition Requirements ..................................................................................... 26-8
26.5 Selecting the A/D Conversion Clock .......................................................................... 26-10
26.6 Configuring Analog Port Pins..................................................................................... 26-11
26.7 A/D Conversions ........................................................................................................ 26-12
26.8 Operation During SLEEP ........................................................................................... 26-16
26.9 Effects of a RESET .................................................................................................... 26-16
26.10 A/D Accuracy/Error .................................................................................................... 26-17
26.11 Connection Considerations ........................................................................................ 26-18
26.12 Transfer Function ....................................................................................................... 26-18
26.13 Initialization ................................................................................................................ 26-19
26.14 Design Tips ................................................................................................................ 26-20
26.15 Related Application Notes.......................................................................................... 26-21
26.16 Revision History ......................................................................................................... 26-22 PIC18C Reference Manual
DS39527A-page 26-2
2000 Microchip Technology Inc.
26.1
Introduction
The 10-bit Analog-to-Digital (A/D) Converter module can have up to sixteen analog inputs.
The analog input charges a sample and hold capacitor. The output of the sample and hold capac-
itor is the input into the converter. The converter then generates a digital result of this analog level
via successive approximation. This A/D conversion of the analog input signal results in a corre-
sponding 10-bit digital number.
The analog reference voltages (positive and negative supply) are software selectable to either
the devices supply voltages (AV
DD
, AVss) or the voltage level on the AN3/V
REF
+ and AN2/V
REF
-
pins.
The A/D converter has the unique feature of being able to convert while the device is in SLEEP
mode.
The A/D module has five registers. These registers are:
A/D Result High Register (ADRESH)
A/D Result Low Register (ADRESL)
A/D Control Register0 (ADCON0)
A/D Control Register1 (ADCON1)
A/D Control Register2 (ADCON2)
The ADCON0 register, shown in
Register 26-1
, selects the input channel of the A/D module. The
ADCON1 register, shown in
Register 26-2
, configures the functions of the port pins and the Volt-
age Reference for the A/D module. The port pins can be configured as analog inputs (AN3 and
AN2 can also be the Voltage References) or as digital I/O. ADCON2 selects the A/D conversion
clock source and the format of the A/D result. 2000 Microchip Technology Inc.
DS39527A-page 26-3
Section 26. 10-bit A/D Converter
10
-bi
t
A
/
D
C
o
n
ver
te
r
26
Figure 26-1: 10-bit A/D Block Diagram
(Input voltage)
V
AIN
V
REF
-
(Reference
Voltage)
AV
DD
PCFG0
CHS3:CHS0
AN7
AN6
AN5
AN4
AN3
AN2
AN1
AN0
0111
0110
0101
0100
0011
0010
0001
0000
A/D
Converter
AN11
AN10
AN9
AN8
1011
1010
1001
1000
V
REF
+
AV
SS
AN12
1100
AN13
1101
AN14
1110
AN15
1111
Note:
Not all 16 input channels may be implemented on every device. Unimplemented selections
are reserved and must not be selected. PIC18C Reference Manual
DS39527A-page 26-4
2000 Microchip Technology Inc.
26.2
Control Register
ADCON0 (
Register 26-1
) is used to select the analog channel. ADCON1 (
Register 26-2
) config-
ures the port logic to either analog or digital inputs and the voltage reference source for the A/D.
ADCON2 (
Register 26-3
) selects the source of the A/D clock and the justification of the result.
Register 26-1: ADCON0 Register
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 7
bit 0
bit 7-6: Unimplemented: Read as 0
bit 5-2: CHS3:CHS0: Analog Channel Select bits
0000
= channel 0, (AN0)
0001
= channel 1, (AN1)
0010
= channel 2, (AN2)
0011
= channel 3, (AN3)
0100
= channel 4, (AN4)
0101
= channel 5, (AN5)
0110
= channel 6, (AN6)
0111
= channel 7, (AN7)
1000
= channel 8, (AN8)
1001
= channel 8, (AN9)
1010
= channel 10, (AN10)
1011
= channel 11, (AN11)
1100
= channel 12, (AN12)
1101
= channel 13, (AN13)
1110
= channel 14, (AN14)
1111
= channel 15, (AN15)
bit 1:
GO/DONE: A/D Conversion Status bit
1 = A/D conversion in progress. Setting this bit starts an A/D conversion cycle.
This
bit is automatically cleared by hardware when the A/D conversion is completed.
0 = A/D conversion not in progress
bit 0:
ADON: A/D On bit
1 = A/D converter module is operating
0 = A/D converter module is shut off and consumes no operating current
Legend
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as 0
- n = Value at POR reset
1 = bit is set
0 = bit is cleared x = bit is unknown 2000 Microchip Technology Inc.
DS39527A-page 26-5
Section 26. 10-bit A/D Converter
10
-bi
t
A
/
D
C
o
n
ver
te
r
26
Register 26-2: ADCON1 Register
U-0
U-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
VCFG1
VCFG0
PCFG3
PCFG2
PCFG1
PCFG0
bit 7
bit 0
bit 7-6:
Unimplemented: Read as 0
bit 5-4:
VCFG1:VCFG0: Voltage Reference Configuration bits
bit 3-0:
PCFG3:PCFG0: A/D Port Configuration Control bits
(1)
A = Analog input D = Digital I/O
Note 1: Selection of an unimplemented channel produces a result of 0xFFF.
Legend
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as 0
- n = Value at POR reset
1 = bit is set
0 = bit is cleared
x = bit is unknown
A/D V
REF
H
A/D V
REF
L
00
A
VDD
A
VSS
01
External V
REF
+
A
VSS
10
A
VDD
External
V
REF
-
11
External
V
REF
+
External V
REF
-
AN15
AN14
AN13
AN12
AN11
AN10
AN9
AN8
AN7
AN6
AN5
AN4
AN3
AN2
AN1
AN0
0000
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
0001
D
D
A
A
A
A
A
A
A
A
A
A
A
A
A
A
0010
D
D
D
A
A
A
A
A
A
A
A
A
A
A
A
A
0011
D
D
D
D
A
A
A
A
A
A
A
A
A
A
A
A
0100
D
D
D
D
D
A
A
A
A
A
A
A
A
A
A
A
0101
D
D
D
D
D
D
A
A
A
A
A
A
A
A
A
A
0110
D
D
D
D
D
D
D
A
A
A
A
A
A
A
A
A
0111
D
D
D
D
D
D
D
D
A
A
A
A
A
A
A
A
1000
D
D
D
D
D
D
D
D
D
A
A
A
A
A
A
A
1001
D
D
D
D
D
D
D
D
D
D
A
A
A
A
A
A
1010
D
D
D
D
D
D
D
D
D
D
D
A
A
A
A
A
1011
D
D
D
D
D
D
D
D
D
D
D
D
A
A
A
A
1100
D
D
D
D
D
D
D
D
D
D
D
D
D
A
A
A
1101
D
D
D
D
D
D
D
D
D
D
D
D
D
D
A
A
1110
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
A
1111
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D PIC18C Reference Manual
DS39527A-page 26-6
2000 Microchip Technology Inc.
Register 26-3: ADCON2 Register
R/W-0
U-0
U-0
U-0
U-0
R/W-0
R/W-0
R/W-0
ADFM
ADCS2
ADCS1
ADCS0
bit 7
bit 0
bit 7:
ADFM: A/D Result Format Select bit
1 = Right justified
0 = Left justified
bit 6-3:
Unimplemented: Read as 0
bit 2-0:
ADCS2:ADCS0: A/D Conversion Clock Select bits
000
= F
OSC
/2
001
= F
OSC
/8
010
= F
OSC
/32
011
= F
RC
(clock derived from an internal RC oscillator, 1 MHz maximum frequency)
100
= F
OSC
/4
101
=
F
OSC
/16
110
= F
OSC
/64
111
= F
RC
(clock derived from an RC oscillator, 1 MHz maximum frequency)
Legend
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as 0
- n = Value at POR reset
1 = bit is set
0 = bit is cleared
x = bit is unknown 2000 Microchip Technology Inc.
DS39527A-page 26-7
Section 26. 10-bit A/D Converter
10
-bi
t
A
/
D
C
o
n
ver
te
r
26
26.3
Operation
The ADRESH:ADRESL registers contain the 10-bit result of the A/D conversion. When the A/D
conversion is complete, the result is loaded into this A/D result register pair (ADRESH:ADRESL),
the GO/DONE bit (ADCON0 register) is cleared, and A/D interrupt flag bit, ADIF, is set. The block
diagram of the A/D module is shown in
Figure 26-1
.
After the A/D module has been configured, the signal on the selected channel must be acquired
before the conversion is started. The analog input channels must have their corresponding TRIS
bits selected as inputs. To determine acquisition time, see Subsection
26.4 A/D Acquisition
Requirements.
After this acquisition time has elapsed, the A/D conversion can be started. The
following steps should be followed for doing an A/D conversion:
1.
Configure the A/D module:
Configure analog pins, Voltage Reference, and digital I/O (ADCON1)
Select A/D input channel (ADCON0)
Select A/D conversion clock (ADCON0)
Turn on A/D module (A