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:
• 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.
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:8ON—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
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.
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
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.
R = Readable bitW = Writable bitP = Programmable bitr = Reserved bit
U = Unimplemented bit-n = Bit Value at POR: (‘0’, ‘1’, x = Unknown)
bit 31-16Unimplemented: Read as ‘0’
bit 15-13VCFG<2:0>: Voltage Reference Configuration bits
bit 12OFFCAL: Input Offset Calibration Mode Select bit
bit 11Unimplemented: Read as ‘0’
bit 10CSCNA: Scan Input Selections for CH0+ SHA Input for MUX A Input Multiplexer Setting bit
bit 9-8Unimplemented: Read as ‘0’
bit 7BUFS: Buffer Fill Status bit
bit 6Unimplemented: Read as ‘0’
bit 5-2SMPI<3:0>: Sample/Convert Sequences Per Interrupt Selection bits
bit 1BUFM: ADC Result Buffer Mode Select bit
bit 0ALTS: Alternate Input Sample Mode Select bit
Bit
31/23/15/7
U-0U-0U-0U-0U-0U-0U-0U-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-0U-0U-0U-0U-0U-0U-0U-0
————————
R/W-0R/W-0R/W-0R/W-0U-0R/W-0U-0U-0
VCFG<2:0>OFFCAL—CSCNA——
R/W-0U-0R/W-0R/W-0R/W-0R/W-0R/W-0R/W-0
BUFS—SMPI<3:0>BUFMALTS
ADC VR+ADC VR-
000
001
010
011
1xx
AVDDAVSS
External VREF+ pinAV SS
AVDDExternal VREF- pin
External VREF+ pinExternal VREF- pin
AVDDAVSS
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
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.1Overview 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
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 hardware. 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.
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).
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.2Selecting 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 negative input is controlled by the CH0NA bit (AD1CHS<23>). The positive input for MUX B is controlled 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.3Selecting 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.