10-bit A/D Converter (Mid-Range)

M
Section 23. 10-bit A/D Converter
HIGHLIGHTS
This section of the manual contains the following major topics:
Note 1: At present NO released mid-range MCU devices are available with this module.
Devices are planned, but there is no schedule for availability. Please refer to Microchip’s Web site or BBS for release of Product Briefs which detail the features of
devices.
If your current design requires a 10-bit A/D, please look at the PIC17C756 which has
a 12-channel 10-bit A/D. This A/D has characteristics which are identical to this module’s description.
 1997 Microchip Technology Inc.
Preliminary
DS31023A page 23-1
23
10-bit
A/D Converter
23.1 Introduction ..................................................................................................................23-2
23.2 Control Register ...........................................................................................................23-3
23.3 Operation .....................................................................................................................23-5
23.4 A/D Acquisition Requirements .....................................................................................23-6
23.5 Selecting the A/D Conversion Clock ............................................................................23-8
23.6 Configuring Analog Port Pins.......................................................................................23-9
23.7 A/D Conversions ........................................................................................................23-10
23.8 Operation During Sleep .............................................................................................23-14
23.9 Effects of a Reset.......................................................................................................23-14
23.10 A/D Accuracy/Error ....................................................................................................23-15
23.11 Connection Considerations ........................................................................................23-16
23.12 Transfer Function .......................................................................................................23-16
23.13 Initialization ................................................................................................................23-17
23.14 Design Tips ................................................................................................................23-18
23.15 Related Application Notes..........................................................................................23-19
23.16 Revision History .........................................................................................................23-20
PICmicro MID-RANGE MCU FAMILY
23.1
Introduction
The analog-to-digital (A/D) converter module can have up to eight analog inputs for a device.
The analog input charges a sample and hold capacitor. The output of the sample and hold capacitor 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 corresponding 10-bit digital number.
The analog reference voltages (positive and negative supply) are software selectable to either
the device’s supply voltages (AVDD, AVss) or the voltage level on the AN3/VREF+ and AN2/VREFpins.
The A/D converter has a unique feature of being able to operate while the device is in SLEEP
mode.
The A/D module has four 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)
The ADCON0 register, shown in Figure 23-1, controls the operation of the A/D module. The
ADCON1 register, shown in Figure 23-2, configures the functions of the port pins. The port pins
can be configured as analog inputs (AN3 and AN2 can also be the voltage references) or as digital I/O.
Figure 23-1:
10-bit A/D Block Diagram
CHS2:CHS0
111
AN7
110
AN6
101
AN5
100
VAIN
011
(Input voltage)
AN4
AN3
010
AN2
10-bit
Converter
A/D
001
AN1
PCFG0
000
AVDD
AN0
VREF+
Reference
voltage
VREF-
AVSS
DS31023A-page 23-2
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.2
Control Register
Register 23-1: ADCON0 Register
R/W-0
ADCS1
bit 7
bit 7:6
R/W-0
ADCS0
R/W-0
CHS2
R/W-0
CHS1
R/W-0
CHS0
R/W-0
GO/DONE
U-0
—
R/W-0
ADON
bit 0
ADCS1:ADCS0: A/D Conversion Clock Select bits
00 = FOSC/2
01 = FOSC/8
10 = FOSC/32
11 = FRC (clock derived from the internal A/D RC oscillator)
bit 5:3
CHS2:CHS0: Analog Channel Select bits
000 = channel 0, (AN0)
001 = channel 1, (AN1)
010 = channel 2, (AN2)
011 = channel 3, (AN3)
100 = channel 4, (AN4)
101 = channel 5, (AN5)
110 = channel 6, (AN6)
111 = channel 7, (AN7)
Note:
bit 2
For devices that do not implement the full 8 A/D channels, the unimplemented selections are reserved. Do not select any unimplemented channel.
23
GO/DONE: A/D Conversion Status bit
1 = A/D conversion in progress (setting this bit starts the A/D conversion which is
automatically cleared by hardware when the A/D conversion is complete)
0 = A/D conversion not in progress
bit 1
Unimplemented: Read as '0'
bit 0
ADON: A/D On bit
1 = A/D converter module is powered up
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’
 1997 Microchip Technology Inc.
Preliminary
- n = Value at POR reset
DS31023A-page 23-3
10-bit
A/D Converter
When ADON = 1
PICmicro MID-RANGE MCU FAMILY
Register 23-2:
ADCON1 Register
U-0
—
bit 7
U-0
—
R/W-0
ADFM
U-0
—
R/W-0
PCFG3
bit 7:6
Unimplemented: Read as '0'
bit 5
ADFM: A/D Result format select (also see Figure 23-6).
R/W-0
PCFG2
R/W-0
PCFG1
R/W-0
PCFG0
bit 0
1 = Right justified. 6 Most Significant bits of ADRESH are read as ’0’.
0 = Left justified. 6 Least Significant bits of ADRESL are read as ’0’.
bit 4
Unimplemented: Read as '0'
bit 3:0
PCFG3:PCFG0: A/D Port Configuration Control bits
PCFG AN7 AN6 AN5 AN4
0000
0001
0010
0011
0100
0101
011x
1000
1001
1010
1011
1100
1101
1110
1111
A
A
D
D
D
D
D
A
D
D
D
D
D
D
D
A
A
D
D
D
D
D
A
D
D
D
D
D
D
D
A
A
D
D
D
D
D
A
A
A
A
D
D
D
D
A
A
A
A
D
D
D
A
A
A
A
A
D
D
D
AN3
AN2
A
VREF+
A
VREF+
A
VREF+
D
VREF+
A
VREF+
VREF+
VREF+
VREF+
D
VREF+
A
A
A
A
D
D
D
VREFA
A
VREFVREFVREFD
VREF-
AN1 AN0 VREF+ VREF-
C/R
AVSS
AVSS
AVSS
AVSS
AVSS
AVSS
—
AN2
AVSS
AVSS
AN2
AN2
AN2
AVSS
AN2
8/0
7/1
5/0
4/1
3/0
2/1
0/0
6/2
6/0
5/1
4/2
3/2
2/2
1/0
1/2
A
A
A
A
A
A
D
A
A
A
A
A
A
D
D
A
A
A
A
A
A
D
A
A
A
A
A
A
A
A
AVDD
AN3
AVDD
AN3
AVDD
AN3
—
AN3
AVDD
AN3
AN3
AN3
AN3
AVDD
AN3
A = Analog input
D = Digital I/O
C/R = # of analog input channels / # of A/D voltage references
Legend
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as ‘0’
- n = Value at POR reset
Note 1: On any device reset, the port pins that are multiplexed with analog functions (ANx)
are forced to be an analog input.
DS31023A-page 23-4
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.3
Operation
The ADRESH:ADRESL registers contains 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, the GO/DONE bit
(ADCON0<2>) is cleared, and A/D interrupt flag bit, ADIF, is set. The block diagrams of the A/D
module are shown in Figure 23-1.
After the A/D module has been configured as desired, 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 sample time, see Subsection 23.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.
2.
3.
4.
5.
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 (ADCON0)
Configure A/D interrupt (if desired):
• Clear the ADIF bit
• Set the ADIE bit
• Set the GIE bit
Wait the required acquisition time.
Start conversion:
• Set the GO/DONE bit (ADCON0)
Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared or ADIF bit to be set
23
6.
7.
• Waiting for the A/D interrupt
Read A/D Result register pair (ADRESH:ADRESL), clear the ADIF bit, if required.
For next conversion, go to step 1 or step 2 as required.
Figure 23-2 shows the conversion sequence, and the terms that are used. Acquisition time is the
time that the A/D module’s holding capacitor is connected to the external voltage level. Then
there is the conversion time of 12 TAD, which is started when the GO bit is set. The sum of these
two times is the sampling time. There is a minimum acquisition time to ensure that the holding
capacitor is charged to a level that will give the desired accuracy for the A/D conversion.
Figure 23-2: A/D Conversion Sequence
A/D Sample Time
Acquisition Time
A/D Conversion Time
A/D conversion complete,
result is loaded in ADRES register.
Holding capacitor begins acquiring
voltage level on selected channel
ADIF bit is set
When A/D conversion is started (setting the GO bit)
When A/D holding capacitor starts to charge.
After A/D conversion, or when new A/D channel is selected
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-5
10-bit
A/D Converter
OR
PICmicro MID-RANGE MCU FAMILY
23.4
A/D Acquisition Requirements
For the A/D converter to meet its specified accuracy, the charge holding capacitor (CHOLD) must
be allowed to fully charge to the input channel voltage level. The analog input model is shown in
Figure 23-3. The source impedance (RS) and the internal sampling switch (RSS) impedance
directly affect the time required to charge the capacitor CHOLD. The sampling switch (RSS) impedance varies over the device voltage (VDD), Figure 23-3. The maximum recommended impedance for analog sources is 10 kΩ. As the impedance is decreased, the acquisition time may be
decreased. After the analog input channel is selected (changed) this acquisition must be done
before the conversion can be started.
To calculate the minimum acquisition time, Equation 23-1 may be used. This equation assumes
that 1/2 LSb error is used (1024 steps for the A/D). The 1/2 LSb error is the maximum error
allowed for the A/D to meet its specified resolution.
Equation 23-1:
TACQ =
=
Amplifier Settling Time +
Holding Capacitor Charging Time +
Temperature Coefficient
TAMP + TC + TCOFF
Equation 23-2:
VHOLD
or
Tc
Acquisition Time
A/D Minimum Charging Time
=
(VREF - (VREF/2048)) • (1 - e(-Tc/CHOLD(RIC + RSS + RS)))
=
-(120 pF)(1 kΩ + RSS + RS) ln(1/2047)
Example 23-1 shows the calculation of the minimum required acquisition time TACQ.
This calculation is based on the following application system assumptions.
CHOLD
Rs
Conversion Error
VDD
Temperature
VHOLD
Example 23-1:
TACQ =
=
=
≤
=
=
=
120 pF
10 kΩ
1/2 LSb
5V → Rss = 7 kΩ
50°C (system max.)
0V @ time = 0
(see graph in Figure 23-3)
Calculating the Minimum Required Acquisition Time (Case 1)
TAMP + TC + TCOFF
Temperature coefficient is only required for temperatures > 25°C.
DS31023A-page 23-6
TACQ =
2 µs + Tc + [(Temp - 25°C)(0.05 µs/°C)]
TC =
-CHOLD (RIC + RSS + RS) ln(1/2047)
-120 pF (1 kΩ + 7 kΩ + 10 kΩ) ln(0.0004885)
-120 pF (18 kΩ) ln(0.0004885)
-2.16 µs (-7.6241)
16.47 µs
TACQ =
2 µs + 16.47 µs + [(50°C - 25°C)(0.05 µs/°C)]
18.47 µs + 1.25 µs
19.72 µs
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
Now to get an idea what happens to the acquisition time when the source impedance is a minimal value (RS = 50 Ω). Example 23-2 shows the same conditions as in Example 23-1 with only
the source impedance made a minimal value (RS = 50 Ω).
Example 23-2:
TACQ =
Calculating the Minimum Required Acquisition Time (Case 2)
TAMP + TC + TCOFF
Temperature coefficient is only required for temperatures > 25°C.
TACQ =
2 µs + Tc + [(Temp - 25°C)(0.05 µs/°C)]
TC =
-CHOLD (RIC + RSS + RS) ln(1/2047)
-120 pF (1 kΩ + 7 kΩ + 50 Ω) ln(0.0004885)
-120 pF (8050 Ω) ln(0.0004885)
-0.966 µs (-7.6241)
7.36 µs
TACQ =
2 µs + 16.47 µs + [(50°C - 25°C)(0.05 µs/°C)]
9.36 µs + 1.25 µs
10.61 µs
Note 1: The reference voltage (VREF) has no effect on the equation, since it cancels itself
out.
Note 2: The charge holding capacitor (CHOLD) is not discharged after each conversion.
Note 3: The maximum recommended impedance for analog sources is 10 kΩ. This is
required to meet the pin leakage specification.
Figure 23-3: Analog Input Model
VDD
Rs
VT = 0.6V
ANx
CPIN
5 pF
VAIN
Sampling
Switch
VT = 0.6V
RIC ≤ 1k
SS
RSS
I leakage
± 100 nA
CHOLD = 120 pF
VSS
Legend CPIN
= input capacitance
VT
= threshold voltage
I LEAKAGE = leakage current at the pin due to
various junctions
RIC
SS
CHOLD
= interconnect resistance
= sampling switch
= sample/hold capacitance (from DAC)
 1997 Microchip Technology Inc.
Preliminary
6V
5V
VDD 4V
3V
2V
5 6 7 8 9 10 11
Sampling Switch
( kΩ )
DS31023A-page 23-7
10-bit
A/D Converter
Note 4: After a conversion has completed, a 2.0TAD delay must complete before acquisition
can begin again. During this time the holding capacitor is not connected to the
selected A/D input channel.
23
PICmicro MID-RANGE MCU FAMILY
23.5
Selecting the A/D Conversion Clock
The A/D conversion time per bit is defined as TAD. The A/D conversion requires 11.5TAD per
10-bit conversion. The source of the A/D conversion clock is software selected. The four possible
options for TAD are:
•
•
•
•
2TOSC
8TOSC
32TOSC
Internal RC oscillator
For correct A/D conversions, the A/D conversion clock (TAD) must be selected to ensure a minimum TAD time of 1.6 µs as shown in parameter 130 of the “Electrical Specifications” section.
Table 23-1 show the resultant TAD times derived from the device operating frequencies and the
A/D clock source selected. These times are for standard voltage range devices.
Table 23-1: TAD vs. Device Operating Frequencies (for Standard, C, Devices)
AD Clock Source (TAD)
Operation
2TOSC
8TOSC
32TOSC
RC
Legend:
Note 1:
2:
3:
4:
ADCS1:ADCS0
Device Frequency
20 MHz
5 MHz
1.25 MHz
333.33 kHz
00
100
400
1.6 µs
6 µs
01
400 ns(2)
1.6 µs
6.4 µs
24 µs(3)
(3)
10
1.6 µs
6.4 µs
25.6 µs
96 µs(3)
(1,4)
(1,4)
(1,4)
11
2 - 6 µs
2 - 6 µs
2 - 6 µs
2 - 6 µs(1)
Shaded cells are outside of recommended range.
The RC source has a typical TAD time of 4 µs.
These values violate the minimum required TAD time.
For faster conversion times, the selection of another clock source is recommended.
For device frequencies above 1 MHz, the device must be in SLEEP for the entire conversion, or the A/D
accuracy may be out of specification.
ns(2)
ns(2)
Table 23-2: TAD vs. Device Operating Frequencies (for Extended, LC, Devices)
AD Clock Source (TAD)
Operation
2TOSC
8TOSC
32TOSC
RC
Legend:
Note 1:
2:
3:
4:
ADCS1:ADCS0
Device Frequency
4 MHz
2 MHz
DS31023A-page 23-8
µs(2)
1.25 MHz
333.33 kHz
00
500
1.0
1.6
6 µs
01
2.0 µs(2)
4.0 µs
6.4 µs
24 µs(3)
10
8.0 µs
16.0 µs
25.6 µs(3)
96 µs(3)
(1,4)
(1,4)
(1,4)
11
3 - 9 µs
3 - 9 µs
3 - 9 µs
3 - 9 µs(1,4)
Shaded cells are outside of recommended range.
The RC source has a typical TAD time of 6 µs.
These values violate the minimum required TAD time.
For faster conversion times, the selection of another clock source is recommended.
For device frequencies above 1 MHz, the device must be in SLEEP for the entire conversion, or the A/D
accuracy may be out of specification.
ns(2)
Preliminary
µs(2)
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.6
Configuring Analog Port Pins
The ADCON1 and TRIS registers control the operation of the A/D port pins. The port pins that
are desired as analog inputs must have their corresponding TRIS bits set (input). If the TRIS bit
is cleared (output), the digital output level (VOH or VOL) will be converted.
The A/D operation is independent of the state of the CHS2:CHS0 bits and the TRIS bits.
Note 1: When reading the port register, any pin configured as an analog input channel will
read as cleared (a low level). Pins configured as digital inputs, will convert an analog
input. Analog levels on a digitally configured input will not affect the conversion
accuracy.
Note 2: Analog levels on any pin that is defined as a digital input (including the AN7:AN0
pins), may cause the input buffer to consume current that is out of the devices specification.
23
10-bit
A/D Converter
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-9
PICmicro MID-RANGE MCU FAMILY
23.7
A/D Conversions
Example 23-3 shows how to perform an A/D conversion for the PIC17C756. The PORTF and
lower four PORTG pins are configured as analog inputs. The analog references (VREF+ and
VREF-) are the device AVDD and AVSS. The A/D interrupt is enabled, and the A/D conversion
clock is FRC. The conversion is performed on the AN0 pin (channel 0).
Note:
The GO/DONE bit should NOT be set in the same instruction that turns on the A/D,
due to the required acquisition time requirement.
Clearing the GO/DONE bit during a conversion will abort the current conversion. The A/D result
register pair will NOT be updated with the partially completed A/D conversion sample. That is,
the ADRESH:ADRESL registers will continue to contain the value of the last completed conversion (or the last value written to the ADRESH:ADRESL registers). After the A/D conversion is
aborted, a 2TAD wait is required before the next acquisition is started. After this 2TAD wait, acquisition on the selected channel is automatically started.
Example 23-3:
;
;
;
;
A/D Conversion
BSF
CLRF
STATUS, RP0
ADCON1
BSF
BCF
MOVLW
MOVWF
BCF
BSF
BSF
PIE1, ADIE
STATUS, RP0
0xC1
ADCON0
PIR1, ADIF
INTCON, PEIE
INTCON, GIE
;
;
;
;
;
;
;
;
;
;
Select Bank1
Configure A/D inputs,
result is left justified
Enable A/D interrupts
Select Bank0
RC Clock, A/D is on, Channel 0 is selected
Clear A/D interrupt flag bit
Enable peripheral interrupts
Enable all interrupts
Ensure that the required sampling time for the selected input
channel has elapsed. Then the conversion may be started.
BSF
:
:
:
ADCON0, GO
; Start A/D Conversion
; The ADIF bit will be set and the GO/DONE
; bit is cleared upon completion of the
;
A/D Conversion.
Figure 23-4: A/D Conversion TAD Cycles
Tcy - TAD TAD1 TAD2 TAD3 TAD4 TAD5 TAD6 TAD7 TAD8 TAD9 TAD10 TAD11
b0
b3
b1
b2
b0
b4
b5
b7
b6
b8
b9
Conversion Starts
Holding capacitor is disconnected from analog input (typically 100 ns)
Set GO bit
Next Q4: ADRES is loaded,
GO bit is cleared,
ADIF bit is set,
holding capacitor is connected to analog input.
DS31023A-page 23-10
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
Figure 23-5:
Flowchart of A/D Operation
ADON = 0
Yes
ADON = 0?
No
Acquire
Selected Channel
Yes
GO = 0?
No
A/D Clock
= RC?
Yes
Start of A/D
Conversion Delayed
1 Instruction Cycle
Finish Conversion
GO = 0,
ADIF = 1
No
No
Device in
SLEEP?
Yes
SLEEP
Instruction?
Yes
Abort Conversion
GO = 0,
ADIF = 0
Finish Conversion
GO = 0,
ADIF = 1
Wait 2TAD
No
No
SLEEP
Power-down A/D
Wait 2TAD
23
Stay in Sleep
Power-down A/D
10-bit
A/D Converter
Finish Conversion
GO = 0,
ADIF = 1
Wake-up Yes
From Sleep?
Wait 2TAD
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-11
PICmicro MID-RANGE MCU FAMILY
23.7.1
Faster Conversion - Lower Resolution Trade-off
Not all applications require a result with 10-bits of resolution, but may instead require a faster
conversion time. The A/D module allows users to make the trade-off of conversion speed to resolution. Regardless of the resolution required, the acquisition time is the same. To speed up the
conversion, the clock source of the A/D module may be switched so that the TAD time violates
the minimum specified time (see the applicable electrical specification). Once the TAD time violates the minimum specified time, all the following A/D result bits are not valid (see A/D Conversion Timing in the Electrical Specifications section). The clock sources may only be switched
between the three oscillator versions (cannot be switched from/to RC). The equation to determine the time before the oscillator can be switched is as follows:
Conversion time
Where: N
= TAD + N • TAD + (11 - N)(2TOSC)
= number of bits of resolution required.
Since the TAD is based from the device oscillator, the user must use some method (a timer, software loop, etc.) to determine when the A/D oscillator may be changed. Example 23-4 shows a
comparison of time required for a conversion with 4-bits of resolution, versus the 10-bit resolution
conversion. The example is for devices operating at 20 MHz (The A/D clock is programmed for
32TOSC), and assumes that immediately after 6TAD, the A/D clock is programmed for 2TOSC.
The 2TOSC violates the minimum TAD time since the last 4 bits will not be converted to correct
values.
Example 23-4:
4-bit vs. 8-bit Conversion Times
Freq.
(MHz)(1)
Resolution
4-bit
10-bit
20
1.6 µs
1.6 µs
TAD
TOSC
20
50 ns
50 ns
2TAD + N • TAD + (11 - N)(2TOSC)
20
8.7 µs
17.6 µs
Note 1: A minimum TAD time of 1.6 µs is required.
2: If the full 8-bit conversion is required, the A/D clock source should not be changed.
DS31023A-page 23-12
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.7.2
A/D Result Registers
The ADRESH:ADRESL register pair is the location where the 10-bit A/D result is loaded at the
completion of the A/D conversion. This register pair is 16-bits wide. The A/D module gives the
flexibility to left or right justify the 10-bit result in the 16-bit result register. The A/D Format Select
bit (ADFM) controls this justification. Figure 23-6 shows the operation of the A/D result justification. The extra bits are loaded with ‘0’s’. When an A/D result will not overwrite these locations (A/D
disable), these registers may be used as two general purpose 8-bit registers.
Figure 23-6: A/D Result Justification
10-Bit Result
ADFM = 0
ADFM = 1
0
2107
7
0000 00
ADRESH
RESULT
ADRESL
10-bits
7
0765
RESULT
ADRESH
0
0000 00
ADRESL
10-bits
23
Left Justified
Right Justified
10-bit
A/D Converter
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-13
PICmicro MID-RANGE MCU FAMILY
23.8
Operation During Sleep
The A/D module can operate during SLEEP mode. This requires that the A/D clock source be set
to RC (ADCS1:ADCS0 = 11). When the RC clock source is selected, the A/D module waits one
instruction cycle before starting the conversion. This allows the SLEEP instruction to be executed,
which eliminates all internal digital switching noise from the conversion. When the conversion is
completed the GO/DONE bit will be cleared, and the result is loaded into the ADRES register. If
the A/D interrupt is enabled, the device will wake-up from SLEEP. If the A/D interrupt is not
enabled, the A/D module will then be turned off, although the ADON bit will remain set.
When the A/D clock source is another clock option (not RC), a SLEEP instruction will cause the
present conversion to be aborted and the A/D module to be turned off (to conserve power),
though the ADON bit will remain set.
Turning off the A/D places the A/D module in its lowest current consumption state.
Note:
23.9
For the A/D module to operate in SLEEP, the A/D clock source must be set to RC
(ADCS1:ADCS0 = 11). To allow the conversion to occur during SLEEP, ensure the
SLEEP instruction immediately follows the instruction that sets the GO/DONE bit.
Effects of a Reset
A device reset forces all registers to their reset state. This forces the A/D module to be turned off,
and any conversion is aborted.
The value that is in the ADRESH:ADRESL registers is not modified for a Power-on Reset. The
ADRESH:ADRESL registers will contain unknown data after a Power-on Reset.
DS31023A-page 23-14
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.10
A/D Accuracy/Error
In systems where the device frequency is low, use of the A/D RC clock is preferred. At moderate
to high frequencies, TAD should be derived from the device oscillator.
The absolute accuracy specified for the A/D converter includes the sum of all contributions for
quantization error, integral error, differential error, full scale error, offset error, and monotonicity.
It is defined as the maximum deviation from an actual transition versus an ideal transition for any
code. The absolute error of the A/D converter is specified at < ±1 LSb for VDD = VREF (over the
device’s specified operating range). However, the accuracy of the A/D converter will degrade as
VDD diverges from VREF.
For a given range of analog inputs, the output digital code will be the same. This is due to the
quantization of the analog input to a digital code. Quantization error is typically ± 1/2 LSb and is
inherent in the analog to digital conversion process. The only way to reduce quantization error is
to increase the resolution of the A/D converter.
Offset error measures the first actual transition of a code versus the first ideal transition of a code.
Offset error shifts the entire transfer function. Offset error can be calibrated out of a system or
introduced into a system through the interaction of the total leakage current and source impedance at the analog input.
Gain error measures the maximum deviation of the last actual transition and the last ideal transition adjusted for offset error. This error appears as a change in slope of the transfer function.
The difference in gain error to full scale error is that full scale does not take offset error into
account. Gain error can be calibrated out in software.
Linearity error refers to the uniformity of the code changes. Linearity errors cannot be calibrated
out of the system. Integral non-linearity error measures the actual code transition versus the ideal
code transition adjusted by the gain error for each code.
The maximum pin leakage current is specified in the Device Data Sheet electrical specification
parameter D060.
In systems where the device frequency is low, use of the A/D RC clock is preferred. At moderate
to high frequencies, TAD should be derived from the device oscillator. TAD must not violate the
minimum and should be minimized to reduce inaccuracies due to noise and sampling capacitor
bleed off.
In systems where the device will enter SLEEP mode after the start of the A/D conversion, the RC
clock source selection is required. In this mode, the digital noise from the modules in SLEEP are
stopped. This method gives high accuracy.
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-15
10-bit
A/D Converter
Differential non-linearity measures the maximum actual code width versus the ideal code width.
This measure is unadjusted.
23
PICmicro MID-RANGE MCU FAMILY
23.11
Connection Considerations
If the input voltage exceeds the rail values (VSS or VDD) by greater than 0.3V, then the accuracy
of the conversion is out of specification.
An external RC filter is sometimes added for anti-aliasing of the input signal. The R component
should be selected to ensure that the total source impedance is kept under the 10 kΩ recommended specification. Any external components connected (via hi-impedance) to an analog
input pin (capacitor, zener diode, etc.) should have very little leakage current at the pin.
23.12
Transfer Function
The ideal transfer function of the A/D converter is as follows: the first transition occurs when the
analog input voltage (VAIN) is 1 LSb (or Analog VREF / 1024) (Figure 23-7).
Figure 23-7: A/D Transfer Function
3FFh
Digital code output
3FEh
003h
002h
001h
1023.5 LSb
1023 LSb
1022 LSb
1022.5 LSb
3 LSb
2.5 LSb
2 LSb
1.5 LSb
1 LSb
0.5 LSb
000h
Analog input voltage
DS31023A-page 23-16
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.13
Initialization
Example 23-5 shows an initialization of the A/D module.
Example 23-5:
BSF
CLRF
BSF
BCF
MOVLW
MOVWF
BCF
BSF
BSF
;
;
;
;
A/D Initialization
STATUS, RP0
ADCON1
PIE1, ADIE
STATUS, RP0
0xC1
ADCON0
PIR1, ADIF
INTCON, PEIE
INTCON, GIE
;
;
;
;
;
;
;
;
;
Select Bank1
Configure A/D inputs
Enable A/D interrupts
Select Bank0
RC Clock, A/D is on, Channel 0 is selected
Clear A/D interrupt flag bit
Enable peripheral interrupts
Enable all interrupts
Ensure that the required sampling time for the selected input
channel has elapsed. Then the conversion may be started.
BSF
:
:
:
ADCON0, GO
; Start A/D Conversion
; The ADIF bit will be set and the GO/DONE
; bit is cleared upon completion of the
;
A/D Conversion.
23
10-bit
A/D Converter
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-17
PICmicro MID-RANGE MCU FAMILY
23.14
Design Tips
Question 1:
I find that the Analog to Digital Converter result is not always accurate.
What can I do to improve accuracy?
Answer 1:
1.
2.
3.
Make sure you are meeting all of the timing specifications. If you are turning the module
off and on, there is a minimum delay you must wait before taking a sample. If you are
changing input channels, there is a minimum delay you must wait for this as well, and
finally there is TAD, which is the time selected for each bit conversion. This is selected in
ADCON0 and should be between 1.6 and 6 µs. If TAD is too short, the result may not be
fully converted before the conversion is terminated, and if TAD is made too long the voltage
on the sampling capacitor can droop before the conversion is complete. These timing
specifications are provided in the “Electrical Specifications” section. See the device
data sheet for device specific information.
Often the source impedance of the analog signal is high (greater than 1k ohms) so the
current drawn from the source to charge the sample capacitor can affect accuracy. If the
input signal does not change too quickly, try putting a 0.1 µF capacitor on the analog input.
This capacitor will charge to the analog voltage being sampled and supply the instantaneous current needed to charge the 120 pF internal holding capacitor.
Finally, straight from the data book: “In systems where the device frequency is low, use of
the A/D clock derived from the device oscillator is preferred...this reduces, to a large
extent, the effects of digital switching noise.” and “In systems where the device will enter
SLEEP mode after start of A/D conversion, the RC clock source selection is required.This
method gives the highest accuracy.”
Question 2:
After starting an A/D conversion may I change the input channel (for my
next conversion)?
Answer 2:
After the holding capacitor is disconnected from the input channel, typically 100 ns after the GO
bit is set, the input channel may be changed.
Question 3:
Do you know of a good reference on A/D’s?
Answer 3:
A very good reference for understanding A/D conversions is the “Analog-Digital Conversion
Handbook” third edition, published by Prentice Hall (ISBN 0-13-03-2848-0).
DS31023A-page 23-18
Preliminary
 1997 Microchip Technology Inc.
Section 23. 10-bit A/D Converter
23.15
Related Application Notes
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the Mid-Range MCU family (that is they may be written for the Base-Line, or High-End families), but the concepts are pertinent, and could be used
(with modification and possible limitations). The current application notes related to the 10-bit A/D
module are:
Title
Application Note #
Using the Analog to Digital Converter
AN546
Four Channel Digital Voltmeter with Display and Keyboard
AN557
23
10-bit
A/D Converter
 1997 Microchip Technology Inc.
Preliminary
DS31023A-page 23-19
PICmicro MID-RANGE MCU FAMILY
23.16
Revision History
Revision A
This is the initial released revision of the 10-bit A/D module description.
DS31023A-page 23-20
 1997 Microchip Technology Inc.