Microchip Technology AD1CON3, AD1CHS, AD1PCFG, AD1CSSL, ADC1BUF0 Family Reference Manual

...
Section 17. 10-bit Analog-to-Digital Converter (ADC)
HIGHLIGHTS
This section of the manual contains the following major topics:
17.1 Introduction..............................................................................................................17-2
17.2 Control Registers.....................................................................................................17-4
17
10-bit Analog-to-Digital
Converter (ADC)
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-1
PIC32 Family Reference Manual
Note: This family reference manual section is meant to serve as a complement to device
data sheets. Depending on the device variant, this manual section may not apply to all PIC32 devices.
Please consult the note at the beginning of the “10-bit Analog-to-Digital Converter (ADC)” chapter in the current device data sheet to check whether this document supports the device you are using.
Device data sheets and family reference manual sections are available for download from the Microchip Worldwide Web site at: http://www.microchip.com

17.1 INTRODUCTION

The PIC32 10-bit Analog-to-Digital Converter (ADC) includes the following features:
• Successive Approximation Register (SAR) conversion
• Up to 16 analog input pins
• External voltage reference input pins
• One unipolar differential Sample-and-Hold Amplifier (SHA)
• Automatic Channel Scan mode
• Selectable conversion trigger source
• 16-word conversion result buffer
• Selectable Buffer Fill modes
• Eight conversion result format options
• Operation during CPU Sleep and Idle modes
Figure 17-1 illustrates a block diagram of the 10-bit ADC. The 10-bit ADC can have up to 16
analog input pins, AN0 through AN15. In addition, there are two analog input pins for external voltage reference connections. These voltage reference inputs may be shared with other analog input pins and may be common to other analog module references. The actual number of analog input pins and external voltage reference input configuration will depend on the specific PIC32 device. Refer to the specific device data sheet for more information.
The analog inputs are connected through two multiplexers to one SHA. The analog input multiplexers can be switched between two sets of analog inputs between conversions. Unipolar differential conversions are possible on all channels, other than the pin used as the reference, using a reference input pin (see
The Analog Input Scan mode sequentially converts user-specified channels. A control register specifies which analog input channels will be included in the scanning sequence.
The 10-bit ADC is connected to a 16-word result buffer. Each 10-bit result is converted to one of eight 32-bit output formats when it is read from the result buffer.
Figure 17-1).
DS61104E-page 17-2 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)
SAR ADC
SHA
ADC1BUF0
ADC1BUF1
ADC1BUF2
ADC1BUFF
ADC1BUFE
AN0
AN15
AN1
VREFL
CH0SB<3:0>
CH0NA CH0NB
+
-
CH0SA<3:0>
Channel
Scan
CSCNA
Alternate
V
REF+
(1)
AVDD AVSS
VREF-
(1)
Input Selection
V
REFH
VREFL
VCFG<2:0>
Note 1: VREF+ and VREF- inputs can be multiplexed with other analog inputs.

Figure 17-1: 10-bit High-Speed ADC Block Diagram

17
10-bit Analog-to-Digital
Converter (ADC)
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-3
PIC32 Family Reference Manual

17.2 CONTROL REGISTERS

The ADC module has the following Special Function Registers (SFRs):
AD1CON1: ADC Control Register 1
AD1CON2: ADC Control Register 2
AD1CON3: ADC Control Register 3
The AD1CON1, AD1CON2 and AD1CON3 registers control the operation of the ADC module.
AD1CHS: ADC Input Select Register
The AD1CHS register selects the input pins to be connected to the SHA.
AD1PCFG: ADC Port Configuration Register
The AD1PCFG register configures the analog input pins as analog inputs or as digital I/O.
AD1CSSL: ADC Input Scan Select Register
The AD1CSSL register selects inputs to be sequentially scanned.
Table 17-1 provides a summary of all ADC-related registers, including their addresses and
formats. Corresponding registers appear after the summary, followed by a detailed description of each register. All unimplemented registers and/or bits within a register read as zero.
Table 17-1: ADC SFR Summary
Name
AD1CON1
AD1CON2
AD1CON3
AD1CHS
AD1PCFG
Legend: — = unimplemented, read as ‘0’. Note 1: This register has an associated Clear register at an offset of 0x4 bytes. These registers have the same name with CLR appended to the
(1,2,3)
31:24
23:16
15:8 ON SIDL FORM<2:0>
(1,2,3)
(1,2,3)
(1,2,3)
(1,2,3)
2: This register has an associated Set register at an offset of 0x8 bytes. These registers have the same name with SET appended to the
3: This register has an associated Invert register at an offset of 0xC bytes. These registers have the same name with INV appended to the
7:0 SSRC<2:0> CLRASAM ASAM SAMP DONE
31:24
23:16
15:8 VCFG<2:0> OFFCAL CSCNA
7:0 BUFS SMPI<3:0> BUFM ALTS
31:24
23:16
15:8 ADRC SAMC<4:0>
7:0 ADCS<7:0>
31:24 CH0NB CH0SB<3:0>
23:16 CH0NA CH0SA<3:0>
15:8
7:0
31:24
23:16
15:8 PCFG15 PCFG14 PCFG13 PCFG12 PCFG11 PCFG10 PCFG9 PCFG8
7:0 PCFG7 PCFG6 PCFG5 PCFG4 PCFG3 PCFG2 PCFG1 PCFG0
end of the register name (e.g.,AD1CON1CLR). Writing a ‘1’ to any bit position in the Clear register will clear valid bits in the associated register. Reads from the Clear register should be ignored.
end of the register name (e.g.,AD1CON1SET). Writing a ‘1’ to any bit position in the Set register will set valid bits in the associated register. Reads from the Set register should be ignored.
end of the register name (e.g., AD1CON1INV). Writing a ‘1’ to any bit position in the Invert register will invert valid bits in the associated register. Reads from the Invert register should be ignored.
Bit
31/23/15/7
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
(1,2)
(1)
Bit
27/19/11/3
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
DS61104E-page 17-4 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)
Table 17-1: ADC SFR Summary (Continued)
Name
AD1CSSL
ADC1BUF0 31:0 ADC Result Word 0 (ADC1BUF0<31:0>)
ADC1BUF1 31:0 ADC Result Word 1 (ADC1BUF1<31:0>)
ADC1BUF2 31:0 ADC Result Word 2 (ADC1BUF2<31:0>)
ADC1BUF3 31:0 ADC Result Word 3 (ADC1BUF3<31:0>)
ADC1BUF4 31:0 ADC Result Word 4 (ADC1BUF4<31:0>)
ADC1BUF5 31:0 ADC Result Word 5 (ADC1BUF5<31:0>)
ADC1BUF6 31:0 ADC Result Word 6 (ADC1BUF6<31:0>)
ADC1BUF7 31:0 ADC Result Word 7 (ADC1BUF7<31:0>)
ADC1BUF8 31:0 ADC Result Word 8 (ADC1BUF8<31:0>)
ADC1BUF9 31:0 ADC Result Word 9 (ADC1BUF9<31:0>)
ADC1BUFA 31:0 ADC Result Word A (ADC1BUFA<31:0>)
ADC1BUFB 31:0 ADC Result Word B (ADC1BUFB<31:0>)
ADC1BUFC 31:0 ADC Result Word C (ADC1BUFC<31:0>)
ADC1BUFD 31:0 ADC Result Word D (ADC1BUFD<31:0>)
ADC1BUFE 31:0 ADC Result Word E (ADC1BUFE<31:0>)
ADC1BUFF 31:0 ADC Result Word F (ADC1BUFF<31:0>)
Legend: — = unimplemented, read as ‘0’. Note 1: This register has an associated Clear register at an offset of 0x4 bytes. These registers have the same name with CLR appended to the
(1,2,3)
31:24
23:16
15:8 CSSL15 CSSL14 CSSL13 CSSL12 CSSL11 CSSL10 CSSL9 CSSL8
7:0 CSSL7 CSSL6 CSSL5 CSSL4 CSSL3 CSSL2 CSSL1 CSSL0
end of the register name (e.g.,AD1CON1CLR). Writing a ‘1’ to any bit position in the Clear register will clear valid bits in the associated register. Reads from the Clear register should be ignored.
2: This register has an associated Set register at an offset of 0x8 bytes. These registers have the same name with SET appended to the
end of the register name (e.g.,AD1CON1SET). Writing a ‘1’ to any bit position in the Set register will set valid bits in the associated register. Reads from the Set register should be ignored.
3: This register has an associated Invert register at an offset of 0xC bytes. These registers have the same name with INV appended to the
end of the register name (e.g., AD1CON1INV). Writing a ‘1’ to any bit position in the Invert register will invert valid bits in the associated register. Reads from the Invert register should be ignored.
Bit
31/23/15/7
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
Bit
27/19/11/3
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
17
10-bit Analog-to-Digital
Converter (ADC)
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-5
PIC32 Family Reference Manual
Register 17-1: AD1CON1: ADC Control Register 1
Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit
U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown) C = Clearable bit
bit 31-16 Unimplemented: Read as ‘0’
bit 15 ON: ADC Operating Mode bit
bit 14 Unimplemented: Read as ‘0’
bit 13 SIDL: Stop in Idle Mode bit
bit 12-11 Unimplemented: Read as ‘0’
bit 10-8 FORM<2:0>: Data Output Format bits
bit 7-5 SSRC<2:0>: Conversion Trigger Source Select bits
bit 4 CLRASAM: Stop Conversion Sequence bit (when the first ADC interrupt is generated)
Bit
31/23/15/7
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
Bit
27/19/11/3
Bit
26/18/10/2
25/17/9/1
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
R/W-0 U-0 R/W-0 U-0 U-0 R/W-0 R/W-0 R/W-0
(1)
ON
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/C-0
SIDL FORM<2:0>
SSRC<2:0> CLRASAM ASAM SAMP DONE
(1)
1 = ADC module is operating 0 = ADC is off
1 = Discontinue module operation when device enters Idle mode 0 = Continue module operation in Idle mode
011 = Signed Fractional 16-bit (DOUT = 0000 0000 0000 0000 sddd dddd dd00 0000) 010 = Fractional 16-bit (DOUT = 0000 0000 0000 0000 dddd dddd dd00 0000) 001 = Signed Integer 16-bit (DOUT = 0000 0000 0000 0000 ssss sssd dddd dddd) 000 = Integer 16-bit (DOUT = 0000 0000 0000 0000 0000 00dd dddd dddd) 111 = Signed Fractional 32-bit (DOUT = sddd dddd dd00 0000 0000 0000 0000) 110 = Fractional 32-bit (DOUT = dddd dddd dd00 0000 0000 0000 0000 0000) 101 = Signed Integer 32-bit (DOUT = ssss ssss ssss ssss ssss sssd dddd dddd) 100 = Integer 32-bit (DOUT = 0000 0000 0000 0000 0000 00dd dddd dddd)
111 = Internal counter ends sampling and starts conversion (auto convert) 110 = Reserved 101 = Reserved 100 = Reserved 011 = Reserved 010 = Timer3 period match ends sampling and starts conversion 001 = Active transition on INT0 pin ends sampling and starts conversion 000 = Clearing SAMP bit ends sampling and starts conversion
1 = Stop conversions when the first ADC interrupt is generated. Hardware clears the ASAM bit when the
ADC interrupt is generated.
0 = Normal operation, buffer contents will be overwritten by the next conversion sequence
Bit
Bit
24/16/8/0
(2)
Note 1: When using the 1:1 Peripheral Bus Clock (PBCLK) divisor, the user software should not read or write the
peripheral’s SFRs in the SYSCLK cycle immediately following the instruction that clears the module’s ON bit.
2: The DONE bit is not persistent in automatic modes. It is cleared by hardware at the beginning of the next
sample.
DS61104E-page 17-6 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)
Register 17-1: AD1CON1: ADC Control Register 1 (Continued)
bit 3 Unimplemented: Read as ‘0’
bit 2 ASAM: ADC Sample Auto-Start bit
1 = Sampling begins immediately after last conversion completes; SAMP bit is automatically set 0 = Sampling begins when SAMP bit is set
bit 1 SAMP: ADC Sample Enable bit
1 = The ADC SHA is sampling 0 = The ADC sample/hold amplifier is holding
When ASAM = 0, writing ‘1’ to this bit starts sampling. When SSRC = 000, writing ‘0’ to this bit will end sampling and start conversion.
bit 0 DONE: Analog-to-Digital Conversion Status bit
1 = Analog-to-digital conversion is done 0 = Analog-to-digital conversion is not done or has not started
Clearing this bit will not affect any operation in progress.
Note 1: When using the 1:1 Peripheral Bus Clock (PBCLK) divisor, the user software should not read or write the
peripheral’s SFRs in the SYSCLK cycle immediately following the instruction that clears the module’s ON bit.
2: The DONE bit is not persistent in automatic modes. It is cleared by hardware at the beginning of the next
sample.
(2)
17
10-bit Analog-to-Digital
Converter (ADC)
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-7
PIC32 Family Reference Manual

Register 17-2: AD1CON2: ADC Control Register 2

Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31-16 Unimplemented: Read as ‘0’ bit 15-13 VCFG<2:0>: Voltage Reference Configuration bits
bit 12 OFFCAL: Input Offset Calibration Mode Select bit
bit 11 Unimplemented: Read as ‘0’ bit 10 CSCNA: Scan Input Selections for CH0+ SHA Input for MUX A Input Multiplexer Setting bit
bit 9-8 Unimplemented: Read as ‘0’ bit 7 BUFS: Buffer Fill Status bit
bit 6 Unimplemented: Read as ‘0’ bit 5-2 SMPI<3:0>: Sample/Convert Sequences Per Interrupt Selection bits
bit 1 BUFM: ADC Result Buffer Mode Select bit
bit 0 ALTS: Alternate Input Sample Mode Select bit
Bit
31/23/15/7
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
Bit
27/19/11/3
Bit
26/18/10/2
Bit
25/17/9/1
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0 U-0
VCFG<2:0> OFFCAL CSCNA
R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
BUFS SMPI<3:0> BUFM ALTS
ADC VR+ ADC VR-
000
001
010
011
1xx
AVDD AVSS
External VREF+ pin AV SS
AVDD External VREF- pin
External VREF+ pin External VREF- pin
AVDD AVSS
1 = Enable Offset Calibration mode
VINH and VINL of the SHA are connected to VR-
0 = Disable Offset Calibration mode
The inputs to the SHA are controlled by AD1CHS or AD1CSSL
1 = Scan inputs 0 = Do not scan inputs
Only valid when BUFM = 1 (ADRES split into 2 x 8-word buffers). 1 = ADC is currently filling buffer 0x8-0xF, user should access data in 0x0-0x7 0 = ADC is currently filling buffer 0x0-0x7, user should access data in 0x8-0xF
1111 = Interrupts at the completion of conversion for each 16th sample/convert sequence 1110 = Interrupts at the completion of conversion for each 15th sample/convert sequence
0001 = Interrupts at the completion of conversion for each 2nd sample/convert sequence 0000 = Interrupts at the completion of conversion for each sample/convert sequence
1 = Buffer configured as two 8-word buffers, ADC1BUF(7...0), ADC1BUF(15...8) 0 = Buffer configured as one 16-word buffer ADC1BUF(15...0.)
1 = Uses MUX A input multiplexer settings for first sample, then alternates between MUX B and
MUX A input multiplexer settings for all subsequent samples
0 = Always use MUX A input multiplexer settings
Bit
24/16/8/0
DS61104E-page 17-8 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)

Register 17-3: AD1CON3: ADC Control Register 3

Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit
U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31-16 Unimplemented: Read as ‘0’
bit 15 ADRC: ADC Conversion Clock Source bit
bit 14-13 Unimplemented: Read as ‘0’
bit 12-8 SAMC<4:0>: Auto-sample Time bits
bit 7-0 ADCS<7:0>: ADC Conversion Clock Select bits
Bit
31/23/15/7
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
R/W-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
ADRC SAMC<4:0>
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
1 = ADC internal RC clock 0 = Clock derived from Peripheral Bus Clock (PBCLK)
11111 = 31 TAD
00001 = 1 TAD 00000 = 0 TAD (Not allowed)
11111111 = TPB • 2 • (ADCS<7:0> + 1) = 512 • TPB = TAD
• 00000001 = TPB • 2 • (ADCS<7:0> + 1) = 4 • TPB = TAD
00000000 = TPB • 2 • (ADCS<7:0> + 1) = 2 • TPB = TAD
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
ADCS<7:0>
(1)
Bit
27/19/11/3
(1)
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
17
10-bit Analog-to-Digital
Converter (ADC)
Note 1: TPB is the PIC32 Peripheral Bus clock time period. Refer to Section 6. “Oscillator” (DS61112) for more
information.
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-9
PIC32 Family Reference Manual

Register 17-4: AD1CHS: ADC Input Select Register

Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit
U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31 CH0NB: Negative Input Select bit for MUX B
bit 30-28 Unimplemented: Read as ‘0’
bit 27-24 CH0SB<3:0>: Positive Input Select bits for MUX B
bit 23 CH0NA: Negative Input Select bit for MUX A Multiplexer Setting
bit 22-20 Unimplemented: Read as ‘0’
bit 19-16 CH0SA<3:0>: Positive Input Select bits for MUX A Multiplexer Setting
bit 15-0 Unimplemented: Read as ‘0’
Bit
31/23/15/7
R/W-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
CH0NB CH0SB<3:0>
R/W-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
CH0NA CH0SA<3:0>
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
1 = Channel 0 negative input is AN1 0 = Channel 0 negative input is VR-
1111 = Channel 0 positive input is AN15 1110 = Channel 0 positive input is AN14 1101 = Channel 0 positive input is AN13
0001 = Channel 0 positive input is AN1 0000 = Channel 0 positive input is AN0
1 = Channel 0 negative input is AN1 0 = Channel 0 negative input is VR-
1111 = Channel 0 positive input is AN15 1110 = Channel 0 positive input is AN14 1101 = Channel 0 positive input is AN13
0001 = Channel 0 positive input is AN1 0000 = Channel 0 positive input is AN0
Bit
30/22/14/6
Bit
29/21/13/5
Bit
28/20/12/4
Bit
27/19/11/3
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
DS61104E-page 17-10 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)
Bit
(1,2)
27/19/11/3
Bit
Bit
26/18/10/2
Register 17-5: AD1PCFG: ADC Port Configuration Register
Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31-16 Unimplemented: Read as ‘0’ bit 15-0 PCFG<15:0>: Analog Input Pin Configuration Control bits
Bit
31/23/15/7
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PCFG15 PCFG14 PCFG13 PCFG12 PCFG11 PCFG10 PCFG9 PCFG8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PCFG7 PCFG6 PCFG5 PCFG4 PCFG3 PCFG2 PCFG1 PCFG0
1 = Analog input pin in Digital mode, port read input enabled, ADC input multiplexer input for this analog
input connected to AVss
0 = Analog input pin in Analog mode, digital port read will return as a ‘1’ without regard to the voltage on
the pin, ADC samples pin voltage
Bit
30/22/14/6
Bit
29/21/13/5
28/20/12/4
Bit
25/17/9/1
Bit
24/16/8/0
17
10-bit Analog-to-Digital
Converter (ADC)
Note 1: The AD1PCFG register functionality will vary depending on the number of ADC inputs available on the
selected device. Refer to the specific device data sheet for additional details on this register.
2: The AD1PCFG register is not available on all PIC32 devices. Refer to the specific device data sheet for
availability of this register.
Bit
(1)
27/19/11/3
Bit
Bit
26/18/10/2
Bit
25/17/9/1
Bit
24/16/8/0
Register 17-6: AD1CSSL: ADC Input Scan Select Register
Bit Range
31:24
23:16
15:8
7:0
Legend:
R = Readable bit W = Writable bit P = Programmable bit r = Reserved bit U = Unimplemented bit -n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31-16 Unimplemented: Read as ‘0’ bit 15-0 CSSL<15:0>: ADC Input Pin Scan Selection bits
Bit
31/23/15/7
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CSSL15 CSSL14 CSSL13 CSSL12 CSSL11 CSSL10 CSSL9 CSSL8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CSSL7 CSSL6 CSSL5 CSSL4 CSSL3 CSSL2 CSSL1 CSSL0
1 = Select ANx for input scan 0 = Skip ANx for input scan
Bit
30/22/14/6
Bit
29/21/13/5
28/20/12/4
Note 1: The AD1CSSL register functionality will vary depending on the number of ADC inputs available on the
selected device. Refer to the specific device data sheet for additional details on this register.
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-11
PIC32 Family Reference Manual
Acquisition Time
Conversion Time
ADC Total Sample Time
SHA is connected to the analog input pin for sampling.
SHA is disconnected from input and holds the signal.
Analog-to-digital conversion is started by the conversion trigger source.
Analog-to-digital conversion complete, result is written into the ADC result buffer. Optionally generate interrupt.

17.3 ADC OPERATION, TERMINOLOGY AND CONVERSION SEQUENCE

This section describes the operation of the ADC, the steps required to configure the converter, special features of the module, and provides examples of ADC configuration with timing diagrams and charts showing the expected output of the converter.

17.3.1 Overview of Operation

Analog sampling consists of two steps: acquisition and conversion (see Figure 17-2). During acquisition, the analog input pin is connected to the Sample and Hold Amplifier (SHA). After the pin has been sampled for a sufficient period, and the sample voltage is equivalent to the input, the pin is disconnected from the SHA to provide a stable input voltage for the conversion process. The conversion process then converts the analog sample voltage to a binary representation.
An overview of the ADC is presented in Figure 17-1. The 10-bit ADC has a single SHA. The SHA is connected to the analog input pins through the analog input multiplexers, MUX A and MUX B. The analog input multiplexers are controlled by the AD1CHS register. There are two sets of MUX control bits in the AD1CHS register. These two sets of control bits allow the two different analog input to be independently controlled. The ADC can optionally switch between MUX A and MUX configurations between conversions. The ADC can also optionally scan through a series of analog inputs using a single MUX.
Acquisition time can be controlled manually or automatically. The acquisition time may be started manually by setting the SAMP bit (AD1CON1<1>), and ended manually by clearing the SAMP bit in user software. The acquisition time may be started automatically by the ADC hardware and ended automatically by a conversion trigger source. The acquisition time is set by the SAMC bits (AD1CON3<12:8>). The SHA has a minimum acquisition period; refer to the specific device data sheet for acquisition time specifications.
Conversion time is the time required for the ADC to convert the voltage held by the SHA. The ADC requires one ADC clock cycle (T clock cycles. Therefore, a total of 12 TAD cycles are required to perform the complete conversion. When the conversion time is complete, the result is written into one of the 16 ADC result registers (ADC1BUF0 through ADC1BUFF).
The sum of the acquisition time and the analog-to-digital conversion time provides the total sample time (refer to Figure 17-2). There are multiple input clock options for the ADC that are used to create the TAD clock. The user must select an input clock option that does not violate the minimum T
The sampling process can be performed once, periodically, or based on a trigger as defined by the module configuration.
AD specification.
AD) to convert each bit of the result, plus two additional
B

Figure 17-2: ADC Sample/Conversion Sequence

DS61104E-page 17-12 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)
The start time for sampling can be controlled in software by setting the SAMP bit (AD1CON1<1>). The start of the sampling time can also be controlled automatically by the hard­ware. When the ADC operates in Auto-Sample mode, the SHA is reconnected to the analog input pin at the end of the conversion in the sample/convert sequence. The auto-sample function is controlled by the ASAM bit (AD1CON1<2>).
The conversion trigger source ends the sampling time and begins an analog-to-digital conversion or a sample/convert sequence. The conversion trigger source is selected by the SSRC<2:0> bits (AD1CON1<7:5>). The conversion trigger can be taken from a variety of hardware sources, or can be controlled manually in software by clearing the SAMP bit. One of the conversion trigger sources is an auto-conversion. The time between auto-conversions is set by a counter and the ADC clock. The Auto-Sample mode and auto-conversion trigger can be used together to provide endless automatic conversions without software intervention.
An interrupt may be generated at the end of each sample sequence or multiple sample sequences as determined by the value of the SMPI<3:0> bits (AD1CON2<5:2>). The number of sample sequences between interrupts can vary between 1 and 16. The user should note that the analog-to-digital conversion buffer holds the results of a single conversion sequence. The next sequence starts filling the buffer from the top even if the number of samples in the previous sequence was less than 16. The total number of conversion results between interrupts is the SMPI value. The total number of conversions between interrupts cannot exceed the physical buffer length.
17
10-bit Analog-to-Digital
Converter (ADC)
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-13
PIC32 Family Reference Manual

17.4 ADC MODULE CONFIGURATION

Operation of the ADC module is directed through bit settings in the appropriate registers. The following instructions summarize the actions and the settings. Options and details for each configuration step are provided in subsequent sections.
To configure the ADC module, perform the following steps:
1. Configure the analog port pins in AD1PCFG<15:0> (see 17.4.1).
2. Select the analog inputs to the ADC multiplexers in AD1CHS<32:0> (see 17.4.2).
3. Select the format of the ADC result using FORM<2:0> (AD1CON1<10:8>) (see 17.4.3).
4. Select the sample clock source using SSRC<2:0> (AD1CON1<7:5>) (see 17.4.4).
5. Select the voltage reference source using VCFG<2:0> (AD1CON2<15:13>) (see 17.4.7).
6. Select the Scan mode using CSCNA (AD1CON2<10>) (see 17.4.8).
7. Set the number of conversions per interrupt SMP<3:0> (AD1CON2<5:2>), if interrupts are to be used (see 17.4.9).
8. Set Buffer Fill mode using BUFM (AD1CON2<1>) (see 17.4.10).
9. Select the MUX to be connected to the ADC in ALTS AD1CON2<0> (see 17.4.11).
10. Select the ADC clock source using ADRC (AD1CON3<15>) (see 17.4.12).
11. Select the sample time using SAMC<4:0> (AD1CON3<12:8>), if auto-convert is to be used (see 17-2).
12. Select the ADC clock prescaler using ADCS<7:0> (AD1CON3<7:0>) (see 17.4.12).
13. Turn the ADC module on using AD1CON1<15> (see 17.4.14).
Note: Steps 1 through 12, above, can be performed in any order, but Step 13 must be the
final step in every case.
14. To configure ADC interrupt (if required): a) Clear the AD1IF bit (IFS1<1>) (see 17.7). b) Select ADC interrupt priority AD1IP<2:0> (IPC<28:26>) and subpriority AD1IS<1:0>
(IPC<24:24>) if interrupts are to be used (see 17.7).
15. Start the conversion sequence by initiating sampling (see 17.4.15).
DS61104E-page 17-14 © 2007-2011 Microchip Technology Inc.
Section 17. 10-bit Analog-to-Digital Converter (ADC)

17.4.1 Configuring Analog Port Pins

The AD1PCFG register and the TRISB register control the operation of the ADC port pins. AD1PCFG specifies the configuration of device pins to be used as analog inputs. A pin is configured as an analog input when the corresponding PCFGn bit (AD1PCFG<n>) = 0. When the bit = 1, the pin is set to digital control. When configured for analog input, the associated port I/O digital input buffer is disabled so it does not consume current. The AD1PCFG register is cleared at Reset, causing the ADC input pins to be configured for analog input by default at Reset.
TRIS registers control the digital function of the port pins. The port pins that are desired as analog inputs must have their corresponding TRIS bit set, specifying the pin as an input. If the I/O pin associated with an ADC input is configured as output, the TRIS bit is cleared, the ports digital output level (V
Note 1: When reading a PORT register that shares pins with the ADC, any pin configured

17.4.2 Selecting the Analog Inputs to the ADC Multiplexers

OH or VOL) will be converted. After a device Reset, all of the TRIS bits are set.
as an analog input reads as a ‘0’ when the PORT latch is read. Analog levels on any pin that is defined as a digital input (including the AN15:AN0 pins), but is not configured as an analog input, may cause the input buffer to consume current that is out of the device’s specification.
2: The AD1PCFG register is not available in all the PIC32 devices. Refer to the
specific device data sheet for availability.
17
10-bit Analog-to-Digital
Converter (ADC)
The AD1CHS register is used to select which analog input pin is connected to MUX A and MUX B. Each multiplexer has two inputs referred to as the positive and the negative input. The positive input to MUX A is controlled by the CH0SA<3:0> bits (AD1CHS<19:16>) and the nega­tive input is controlled by the CH0NA bit (AD1CHS<23>). The positive input for MUX B is con­trolled by the CH0SB<3:0> bits (AD1CHS<27:24>) and the negative input is controlled by the CH0NB bit (AD1CHS<31>).
The positive input can be selected from any one of the available analog input pins. The negative input can be selected as the ADC negative reference or AN1. The use of AN1 as the negative input allows the ADC to be used in Unipolar Differential mode. Refer to the specific device data sheet for AN1 input voltage restrictions when used as a negative reference.
Note: When using Scan mode, the CH0SA<3:0> bits may be overridden. Refer to
17.4.8 “Selecting the Scan Mode” for more information.

17.4.3 Selecting the Format of the ADC Result

The data in the ADC result register can be read as one of eight formats. The format is controlled by the FORM<2:0> bits (AD1CON1<10:8>). The user can select from integer, signed integer, fractional, or signed fractional as a 16-bit or 32-bit result. how a result is formatted. Ta b le 17-2 and Ta bl e 17-3 provide examples of results for the select results in each of the four formats with 32-bit and 16-bit results.
Note: There is no numeric difference between 32-bit and 16-bit modes. In 32-bit mode,
the sign extension is applied to all 32-bits. In 16-bit mode, the sign extension is applied only to the lower 16-bits of the result.
Figure 17-3 and Figure 17-4 illustrate
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-15
DS61104E-page 17-16 © 2007-2011 Microchip Technology Inc.
RAM Contents:
d09 d08 d07 d06 d05 d04 d03 d02 d01 d00
Read to Bus:
Integer
0000000000000000000000d09d08d07d06d05d04d03d02d01d00
Signed Integer
d09
d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00
Fractional (1.15)
d09 d08 d07 d06 d05 d04 d03 d02 d01 d00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Signed Fractional (1.15)
d09
d08 d07 d06 d05 d04 d03 d02 d01 d00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Figure 17-3: ADC Output Data Formats, 32-bit Mode

PIC32 Family Reference Manual
© 2007-2011 Microchip Technology Inc. DS61104E-page 17-17
RAM Contents:
d09 d08 d07 d06 d05 d04 d03 d02 d01 d00
Read to Bus:
Integer
0000000000000000000000d09d08d07d06d05d04d03d02d01d00
Signed Integer
0000000000000000d09
d09 d09 d09 d09 d09 d09 d08 d07 d06 d05 d04 d03 d02 d01 d00
Fractional (1.15)
0000000000000000d09d08d07d06d05d04d03d02d01d00000000
Signed Fractional (1.15)
0000000000000000d09
d08 d07 d06 d05 d04 d03 d02 d01 d00 d09 0 0 0 0 0

Figure 17-4: ADC Output Data Formats, 16-bit Mode

Section 17. 10-bit Analog-to-Digital Converter (ADC)
17
Converter (ADC)
10-bit Analog-to-Digital
PIC32 Family Reference Manual

Table 17-2: Numerical Equivalents of Select Result Codes for FORM<2> (AD1CON1<10>) = 1, 32-bit Result

VIN/VR
1023/1024
1022/1024
513/1024
512/1024
511/1024
1/1024
0/1024
10-bit
Output Code
11 1111 1111 0000 0000 0000 0000
11 1111 1110 0000 0000 0000 0000
10 0000 0001 0000 0000 0000 0000
10 0000 0000 0000 0000 0000 0000
01 1111 1111 0000 0000 0000 0000
00 0000 0001 0000 0000 0000 0000
00 0000 0000 0000 0000 0000 0000
32-bit Integer Format
0000 0011 1111 1111
= 1023
0000 0011 1111 1110
= 1022
0000 0010 0000 0001
= 513
0000 0010 0000 0000
= 512
0000 0001 1111 1111
= 511
0000 0000 0000 0001
= 1
0000 0000 0000 0000
= 0
32-bit Signed
Integer Format
0000 0000 0000 0000 0000 0001 1111 1111
= 511
0000 0000 0000 0000 0000 0001 1111 1110
= 510
•••
0000 0000 0000 0000 0000 0000 0000 0001
= 1
0000 0000 0000 0000 0000 0000 0000 0000
= 0
1111 1111 1111 1111 1111 1111 1111 1111
= -1
•••
1111 1111 1111 1111 1111 1110 0000 0001
= -511
1111 1111 1111 1111 1111 1110 0000 0000
= -512
32-bit Fractional
Format
1111 1111 1100 0000 0000 0000 0000 0000
= 0.999
1111 1111 1000 0000 0000 0000 0000 0000
= 0.998
1000 0000 0100 0000 0000 0000 0000 0000
= 0.501
1000 0000 0000 0000 0000 0000 0000 0000
= 0.500
0111 1111 1100 0000 0000 0000 0000 0000
= .499
0000 0000 0100 0000 0000 0000 0000 0000
= 0.001
0000 0000 0000 0000 0000 0000 0000 0000
= 0.000
32-bit Signed
Fractional Format
0111 1111 1100 0000 0000 0000 0000 0000
= 0.499
0111 1111 1000 0000 0000 0000 0000 0000
= 0.498
0 000 0000 0100
0000
0000 0000 0000 0000
= 0.001
0000 0000 0000 0000 0000 0000 0000 0000
= 0.000
1111 1111 1100 0000 0000 0000 0000 0000
= -0.001
1000 0000 0100 0000 0000 0000 0000 0000
= -0.499
1000 0000 0000 0000 0000 0000 0000 0000
= -0.500

Table 17-3: Numerical Equivalents of Select Result Codes for FORM<2> (AD1CON1<10>) = 0, 16-bit Result

VIN/VR
1023/1024
1022/1024
513/1024
512/1024
511/1024
1/1024
0/1024
10-bit
Output Code
11 1111 1111 0000 0011 1111 1111
11 1111 1110 0000 0011 1111 1110
10 0000 0001 0000 0010 0000 0001
10 0000 0000 0000 0010 0000 0000
01 1111 1111 0000 0001 1111 1111
00 0000 0001 0000 0000 0000 0001
00 0000 0000 0000 0000 0000 0000
16-bit Integer Format
= 1023
= 1022
= 513
= 512
= 511
= 1
= 0
16-bit Signed
Integer Format
0000 0001 1111 1111
= 511
0000 0001 1111 1110
= 510
•••
0000 0000 0000 0001
= 1
0000 0000 0000 0000
= 0
1111 1111 1111 1111
= -1
•••
1111 1110 0000 0001
= -511
1111 1110 0000 0000
= -512
16-bit Fractional
Format
1111 1111 1100 0000
= 0.999
1111 1111 1000 0000
= 0.998
1000 0000 0100 0000
= 0.501
1000 0000 0000 0000
= 0.500
0111 1111 1100 0000
= .499
0000 0000 0100 0000
= 0.001
0000 0000 0000 0000
= 0.000
16-bit Signed
Fractional Format
0111 1111 1100 0000
= 0.499
0111 1111 1000 0000
= 0.498
0 000 0000 0100
0000
= 0.001
0000 0000 0000 0000
= 0.000
1111 1111 1100 0000
= -0.001
1000 0000 0100 0000
= -0.499
1000 0000 0000 0000
= -0.500
DS61104E-page 17-18 © 2007-2011 Microchip Technology Inc.
Loading...
+ 42 hidden pages