Professional Documents
Culture Documents
HIGHLIGHTS
This section of the manual contains the following major topics: 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 Conguring 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
23
10-bit A/D Converter
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 Microchips 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 modules description.
Preliminary
The ADCON0 register, shown in Figure 23-1, controls the operation of the A/D module. The ADCON1 register, shown in Figure 23-2, congures the functions of the port pins. The port pins can be congured 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 (Input voltage) 011 010 10-bit Converter A/D PCFG0 AVDD VREF+ Reference voltage VREFAN2 001 AN1 000 AN0 AN4 AN3
AVSS
DS31023A-page 23-2
Preliminary
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: For devices that do not implement the full 8 A/D channels, the unimplemented selections are reserved. Do not select any unimplemented channel.
23
10-bit A/D Converter
bit 2
GO/DONE: A/D Conversion Status bit When ADON = 1 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 bit 0
Unimplemented: Read as '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 - n = Value at POR reset U = Unimplemented bit, read as 0
Preliminary
DS31023A-page 23-3
Unimplemented: Read as '0' ADFM: A/D Result format select (also see Figure 23-6). 1 = Right justied. 6 Most Signicant bits of ADRESH are read as 0. 0 = Left justied. 6 Least Signicant bits of ADRESL are read as 0.
Unimplemented: Read as '0' PCFG3:PCFG0: A/D Port Conguration 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 A VREF+ A VREF+ A VREF+ D VREF+ A VREF+ VREF+ VREF+ VREF+ D VREF+ AN2 A A A A D D D VREFA A VREFVREFVREFD VREFAN1 AN0 VREF+ VREFA 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 AVSS AVSS AVSS AVSS AVSS AVSS AN2 AVSS AVSS AN2 AN2 AN2 AVSS AN2 C/R 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 = Analog input D = Digital I/O C/R = # of analog input channels / # of A/D voltage references
Legend R = Readable bit W = Writable bit - n = Value at POR reset U = Unimplemented bit, read as 0
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
2.
3. 4. 5.
23
10-bit A/D Converter
Figure 23-2 shows the conversion sequence, and the terms that are used. Acquisition time is the time that the A/D modules 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
Preliminary
DS31023A-page 23-5
TACQ =
TAMP + TC + TCOFF
A/D Minimum Charging Time
Equation 23-2:
VHOLD or Tc
= =
(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 = = = = = 120 pF 10 k 1/2 LSb 5V Rss = 7 k 50C (system max.) 0V @ time = 0
TAMP + TC + TCOFF 2 s + Tc + [(Temp - 25C)(0.05 s/C)] -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 2 s + 16.47 s + [(50C - 25C)(0.05 s/C)] 18.47 s + 1.25 s 19.72 s
TACQ = TC =
TACQ =
DS31023A-page 23-6
Preliminary
TAMP + TC + TCOFF 2 s + Tc + [(Temp - 25C)(0.05 s/C)] -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 2 s + 16.47 s + [(50C - 25C)(0.05 s/C)] 9.36 s + 1.25 s 10.61 s
TACQ = TC =
TACQ =
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 specication. 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
10-bit A/D Converter
Rs
ANx
VAIN
CPIN 5 pF
VT = 0.6V
I leakage 100 nA
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)
6V 5V VDD 4V 3V 2V
5 6 7 8 9 10 11 Sampling Switch ( k )
Preliminary
DS31023A-page 23-7
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 Specications 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 20 MHz ns(2) ns(2) Device Frequency 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 specication. 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 4 MHz ns(2) s(2)
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 specication.
DS31023A-page 23-8
Preliminary
23
10-bit A/D Converter
Preliminary
DS31023A-page 23-9
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:
BSF CLRF BSF BCF MOVLW MOVWF BCF BSF BSF ; ; ; ;
A/D Conversion
STATUS, RP0 ADCON1 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
Yes ADON = 0?
Yes GO = 0?
No
Yes
Device in SLEEP? No
Yes
Wait 2TAD
No
23
10-bit A/D Converter
Wait 2TAD
Wait 2TAD
Preliminary
DS31023A-page 23-11
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
7 0000 00
2107
0765
0 0000 00
RESULT
ADRESL 10-bits
RESULT
ADRESH 10-bits
ADRESH
ADRESL
23
10-bit A/D Converter
Right Justied
Left Justied
Preliminary
DS31023A-page 23-13
23.9
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 modied for a Power-on Reset. The ADRESH:ADRESL registers will contain unknown data after a Power-on Reset.
DS31023A-page 23-14
Preliminary
23
10-bit A/D Converter
Preliminary
DS31023A-page 23-15
23.12
Transfer Function
The ideal transfer function of the A/D converter is as follows: the rst 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
003h
002h 001h
000h 1022.5 LSb 1023.5 LSb 1022 LSb 1023 LSb 0.5 LSb 1.5 LSb 2.5 LSb 1 LSb 2 LSb 3 LSb
DS31023A-page 23-16
Preliminary
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
Preliminary
DS31023A-page 23-17
I nd that the Analog to Digital Converter result is not always accurate. What can I do to improve accuracy?
2.
3.
Question 2: Answer 2:
After starting an A/D conversion may I change the input channel (for my next conversion)?
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: 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
23
10-bit A/D Converter
Preliminary
DS31023A-page 23-19
DS31023A-page 23-20