4.9. ADC and Temperature Sensor

RP2040 has an internal analogue-digital converter (ADC) with the following features:

Figure 114. ADC
Connection Diagram

ADC Connection Diagram showing GPIO pins 26-29 connected to analogue inputs 0-3, and a Temperature Sensor (on chip) connected to input 4. The inputs are selected via the ain_sel register and connected to the ADC block.

The diagram illustrates the ADC connection. On the left, four GPIO pins (GPIO[26], GPIO[27], GPIO[28], and GPIO[29]) are shown. Each pin has a dashed box containing an 'Analogue input' and a 'Digital pad'. The 'Analogue input' lines connect to a vertical bus labeled 'ain_sel' with values 0, 1, 2, and 3 respectively. A 'Temperature Sensor (on chip)' block connects to the 'ain_sel' bus at value 4. The 'ain_sel' bus then connects to the 'ADC' block on the right.

ADC Connection Diagram showing GPIO pins 26-29 connected to analogue inputs 0-3, and a Temperature Sensor (on chip) connected to input 4. The inputs are selected via the ain_sel register and connected to the ADC block.

NOTE

When using an ADC input shared with a GPIO pin, the pin's digital functions must be disabled by setting IE low and OD high in the pin's pad control register. See Section 2.19.6.3, "Pad Control - User Bank" for details. The maximum ADC input voltage is determined by the digital IO supply voltage (IOVDD), not the ADC supply voltage (ADC_AVDD). For example, if IOVDD is powered at 1.8V, the voltage on the ADC inputs should not exceed 1.8V even if ADC_AVDD is powered at 3.3V. Voltages greater than IOVDD will result in leakage currents through the ESD protection diodes. See Section 5.5.3, "Pin Specifications" for details.

4.9.1. ADC controller

A digital controller manages the details of operating the RP2040 ADC, and provides additional functionality:

4.9.2. SAR ADC

The SAR ADC (Successive Approximation Register Analogue to Digital Converter) is a combination of digital controller, and analogue circuit as shown in Figure 115 .

Figure 115. SAR ADC Block diagram

Block diagram of the SAR ADC. The SAR controller is the central digital component, receiving conv_ready, conv_start, and conv_done signals, and outputting result_dout and conv_error. It controls the analogue circuit via sar_sample, sar_compare_buse, and sar_comp_enable signals. The analogue circuit includes a DAC, a Sample and hold block, and a Comparator. The DAC receives SAR control signals from the controller and outputs to the Comparator. The Sample and hold block receives the analogue input (ain_sel <2:0>) and outputs to the Comparator. The Comparator outputs the sar_comp_result signal back to the controller.
Block diagram of the SAR ADC. The SAR controller is the central digital component, receiving conv_ready, conv_start, and conv_done signals, and outputting result_dout and conv_error. It controls the analogue circuit via sar_sample, sar_compare_buse, and sar_comp_enable signals. The analogue circuit includes a DAC, a Sample and hold block, and a Comparator. The DAC receives SAR control signals from the controller and outputs to the Comparator. The Sample and hold block receives the analogue input (ain_sel <2:0>) and outputs to the Comparator. The Comparator outputs the sar_comp_result signal back to the controller.

The ADC requires a 48MHz clock ( clk_adc), which could come from the USB PLL. Capturing a sample takes 96 clock cycles ( \( 96 \times 1/48\text{MHz} \) ) = 2µs per sample (500ksps). The clock must be set up correctly before enabling the ADC.

Once the ADC block is provided with a clock, and its reset has been removed, writing a 1 to CS.EN will start a short internal power-up sequence for the ADC's analogue hardware. After a few clock cycles, CS.READY will go high, indicating the ADC is ready to start its first conversion.

The ADC can be disabled again at any time by clearing CS.EN, to save power. CS.EN does not enable the temperature sensor bias source (see Section 4.9.5 ). This is controlled separately.

The ADC input is capacitive, and when sampling, it places about 1pF across the input (there will be additional capacitance from outside the ADC, such as packaging and PCB routing, to add to this). The effective impedance, even when sampling at 500ksps, is over 100kΩ, and for DC measurements there should be no need to buffer.

4.9.2.1. One-shot Sample

Writing a 1 to CS.START_ONCE will immediately start a new conversion. CS.READY will go low, to show that a conversion is currently in progress. After 96 cycles of clk_adc, CS.READY will go high. The 12-bit conversion result is available in RESULT.

The ADC input to be sampled is selected by writing to CS.AINSEL, any time before the conversion starts. An AINSEL value of 0...3 selects the ADC input on GPIO 26...29. AINSEL of 4 selects the internal temperature sensor.

i NOTE

No settling time is required when switching AINSEL.

4.9.2.2. Free-running Sampling

When CS.START_MANY is set, the ADC will automatically start new conversions at regular intervals. The most recent conversion result is always available in RESULT, but for IRQ or DMA driven streaming of samples, the ADC FIFO must be enabled ( Section 4.9.2.4 ).

By default ( DIV = 0), new conversions start immediately upon the previous conversion finishing, so a new sample is produced every 96 cycles. At a clock frequency of 48MHz, this produces 500ksps.

Setting DIV.INT to some positive value \( n \) will trigger the ADC once per \( n + 1 \) cycles, though the ADC ignores this if a conversion is currently in progress, so generally \( n \) will be \( \geq 96 \) . For example, setting DIV.INT to 47999 will run the ADC at 1ksps, if running from a 48MHz clock.

The pacing timer supports fractional-rate division (first order delta sigma). When setting DIV.FRAC to a nonzero value,

the ADC will start a new conversion once per \( 1 + \text{INT} + \frac{\text{FRAC}}{256} \) cycles on average, by changing the sample interval between \( \text{INT} + 1 \) and \( \text{INT} + 2 \) .

4.9.2.3. Sampling Multiple Inputs

CS.RROBIN allows the ADC to sample multiple inputs, in an interleaved fashion, while performing free-running sampling. Each bit in RROBIN corresponds to one of the five possible values of CS.AINSEL . When the ADC completes a conversion, CS.AINSEL will automatically cycle to the next input whose corresponding bit is set in RROBIN .

The round-robin sampling feature is disabled by writing all-zeroes to CS.RROBIN .

For example, if AINSEL is initially 0, and RROBIN is set to 0x06 (bits 1 and 2 are set), the ADC will sample channels in the following order:

  1. 1. Channel 0
  2. 2. Channel 1
  3. 3. Channel 2
  4. 4. Channel 1
  5. 5. Channel 2
  6. 6. Channel 1...

i NOTE

The initial value of AINSEL does not need to correspond with a set bit in RROBIN .

4.9.2.4. Sample FIFO

The ADC samples can be read directly from the RESULT register, or stored in a local 8-entry FIFO and read out from FIFO . FIFO operation is controlled by the FCS register.

If FCS.EN is set, the result of each ADC conversion is written to the FIFO. A software interrupt handler or the RP2040 DMA can read this sample from the FIFO when notified by the ADC's IRQ or DREQ signals. Alternatively, software can poll the status bits in FCS to wait for each sample to become available.

If the FIFO is full when a conversion completes, the sticky error flag FCS.OVER is set. The current FIFO contents are not changed by this event, but any conversion that completes whilst the FIFO is full will be lost.

There are two flags that control the data written to the FIFO by the ADC:

CAUTION

Conversion errors produce undefined results, and the corresponding sample should be discarded. They indicate that the comparison of one or more bits failed to complete in the time allowed. Normally this is caused by comparator metastability, i.e. the closer to the comparator threshold the input signal is, the longer it will take to make a decision. The high gain of the comparator reduces the probability that no decision is made.

4.9.2.5. DMA

The RP2040 DMA (Section 2.5) can fetch ADC samples from the sample FIFO, by performing a normal memory-mapped read on the FIFO register, paced by the ADC_DREQ system data request signal. The following must be considered:

Once the ADC is suitably configured, the DMA channel should be started first, and the ADC conversion should be started second, via CS.START_MANY. Once the DMA completes, the ADC can be halted, or a new DMA transfer promptly started. After clearing CS.START_MANY to halt the ADC, software should also poll CS.READY to make sure the last conversion has finished, and then drain any stray samples from the FIFO.

4.9.2.6. Interrupts

An interrupt can be generated when the FIFO level reaches a configurable threshold FCS.THRESH. The interrupt output must be enabled via INTE.

Status can be read from INTS. The interrupt is cleared by draining the FIFO to a level lower than FCS.THRESH.

4.9.2.7. Supply

The ADC supply is separated out on its own pin to allow noise filtering.

4.9.3. ADC ENOB

The ADC was characterised and the ENOB of the ADC was measured. Testing was carried out at room temperature across silicon lots, with tests being done on 3 typical (tt) as well as 3 fast (ff) and 3 slow (ss) corner RP2040 devices. The typical, minimum, and maximum values in Table 566 reflect the silicon used in the testing.

Table 565. Parameters used during the testing.

ParameterValue
Sample rate250ksps
ParameterValue
FFT window5 term Blackman-Harris
FFT bins4,096
FFT averagingnone
Input level min1
Input level max4,094
Input frequency997Hz

It should be noted that THD is normally calculated using the first 5 or 6 harmonics. However as INL/DNL errors (see Section 4.9.4 ) create more than this, the first 30 peaks are used. This makes the THD value slightly worse, but more representative of reality.

Table 566. Results for various parts tested (fast, slow, and typical).

MinTypicalMax
THD 1-55.6dB55dB-54.4dB
SNR60.9dB61.5dB62.0dB
SFDR59.2dB59.9dB60.5dB
SINAD53.6dB54.0dB54.6dB
ENOB8.68.78.8

1 As the INL creates a large number of harmonics, the highest 30 peaks were used. This is different from conventional calculations of THD.

! IMPORTANT

Testing was carried out using a board with a low-noise on-board voltage reference as, when characterising the ADC, it is important that there are no other noise sources affecting the measurements.

4.9.4. INL and DNL

Integral Non-Linearity (INL) and Differential Non-Linearity (DNL) are used to measure the error of the quantisation of the incoming signal that the ADC generates. In an ideal ADC the input-to-output transfer function should have a linear quantised transfer between the analogue input signal and the digitised output signal. The RP2040 ADC INL values for each binary result are shown in Figure 116 , illustrating that the error is a sawtooth rather than the expected curve.

Figure 116. ATE machine results for INL (RP2040).

Figure 116: ATE machine results for INL (RP2040). The plot shows Amplitude (Y-axis, ranging from -6 to 7) versus Samples (X-axis, ranging from 0 to 4000). The signal is a noisy, sawtooth-like waveform with sharp vertical spikes at approximately 512, 1536, 2560, and 3584 samples, indicating INL errors.
Figure 116: ATE machine results for INL (RP2040). The plot shows Amplitude (Y-axis, ranging from -6 to 7) versus Samples (X-axis, ranging from 0 to 4000). The signal is a noisy, sawtooth-like waveform with sharp vertical spikes at approximately 512, 1536, 2560, and 3584 samples, indicating INL errors.

Nominally an ADC moves from one digital value to the next digital value, colloquially expressed as “no missing codes”. However, if the ADC skips a value bin this would cause a spike in the Differential Non-Linearity (DNL) error. These types of error often only occur at specific codes due to the design of the ADC.

The RP2040 ADC has a DNL which is mostly flat, and below 1 LSB. However at four values — 512, 1536, 2560, and 3,584 — the ADC’s DNL error peaks, see Figure 117

Figure 117. ATE machine results for DNL (RP2040).

Figure 117: ATE machine results for DNL (RP2040). The plot shows Amplitude (Y-axis, ranging from -1 to 8) versus Samples (X-axis, ranging from 0 to 4000). The signal is a noisy baseline with sharp vertical spikes at approximately 512, 1536, 2560, and 3584 samples, labeled with their respective sample numbers, indicating DNL errors.
Figure 117: ATE machine results for DNL (RP2040). The plot shows Amplitude (Y-axis, ranging from -1 to 8) versus Samples (X-axis, ranging from 0 to 4000). The signal is a noisy baseline with sharp vertical spikes at approximately 512, 1536, 2560, and 3584 samples, labeled with their respective sample numbers, indicating DNL errors.

The INL and DNL errors come from an error in the scaling of some internal capacitors of the ADC. These capacitors are small in value (only tens of femto Farads) and at these very small values, chip simulation of these capacitors can deviate slightly from reality. If these capacitors had matched correctly, the ADCs performance could have been better.

These INL and DNL errors will somewhat limit the performance of the ADC dependent on use case (See Errata RP2040-E11 ).

4.9.5. Temperature Sensor

The temperature sensor measures the \( V_{be} \) voltage of a biased bipolar diode, connected to the fifth ADC channel (AINSEL=4). Typically, \( V_{be} = 0.706V \) at 27 degrees C, with a slope of \( -1.721mV \) per degree. Therefore the temperature can be approximated as follows:

\[ T = 27 - (\text{ADC\_voltage} - 0.706)/0.001721 \]

As the \( V_{be} \) and the \( V_{be} \) slope can vary over the temperature range, and from device to device, some user calibration may be required if accurate measurements are required.

The temperature sensor’s bias source must be enabled before use, via CS.TS_EN . This increases current consumption on ADC_AVDD by approximately 40µA.

Image: Note icon

NOTE

The on board temperature sensor is very sensitive to errors in the reference voltage. If the ADC returns a value of 891 this would correspond to a temperature of 20.1°C. However if the reference voltage is 1% lower than 3.3V then the same reading of 891 would correspond to 24.3°C. You would see a change in temperature of over 4°C for a small 1% change in reference voltage. Therefore if you want to improve the accuracy of the internal temperature sensor it is worth considering adding an external reference voltage.

Image: Note icon

NOTE

The INL errors, see Section 4.9.4 , aren’t in the usable temperature range of the ADC.

4.9.6. List of Registers

The ADC registers start at a base address of 0x4004c000(defined as ADC_BASE in SDK).

Table 567. List of ADC registers

OffsetNameInfo
0x00CSADC Control and Status
0x04RESULTResult of most recent ADC conversion
0x08FCSFIFO control and status
0x0cFIFOConversion result FIFO
0x10DIVClock divider. If non-zero, CS_START_MANY will start conversions at regular intervals rather than back-to-back.
The divider is reset when either of these fields are written.
Total period is 1 + INT + FRAC / 256
0x14INTRRaw Interrupts
0x18INTEInterrupt Enable
0x1cINTFInterrupt Force
0x20INTSInterrupt status after masking & forcing

ADC: CS Register

Offset: 0x00

Description

ADC Control and Status

Table 568. CS Register

BitsDescriptionTypeReset
31:21Reserved.--
20:16RROBIN : Round-robin sampling. 1 bit per channel. Set all bits to 0 to disable. Otherwise, the ADC will cycle through each enabled channel in a round-robin fashion.
The first channel to be sampled will be the one currently indicated by AINSEL. AINSEL will be updated after each conversion with the newly-selected channel.
RW0x00
15Reserved.--
BitsDescriptionTypeReset
14:12AINSEL : Select analog mux input. Updated automatically in round-robin mode.RW0x0
11Reserved.--
10ERR_STICKY : Some past ADC conversion encountered an error. Write 1 to clear.WC0x0
9ERR : The most recent ADC conversion encountered an error; result is undefined or noisy.RO0x0
8READY : 1 if the ADC is ready to start a new conversion. Implies any previous conversion has completed.
0 whilst conversion in progress.
RO0x0
7:4Reserved.--
3START_MANY : Continuously perform conversions whilst this bit is 1. A new conversion will start immediately after the previous finishes.RW0x0
2START_ONCE : Start a single conversion. Self-clearing. Ignored if start_many is asserted.SC0x0
1TS_EN : Power on temperature sensor. 1 - enabled. 0 - disabled.RW0x0
0EN : Power on ADC and enable its clock.
1 - enabled. 0 - disabled.
RW0x0

ADC: RESULT Register

Offset: 0x04

Table 569. RESULT Register

BitsDescriptionTypeReset
31:12Reserved.--
11:0Result of most recent ADC conversionRO0x000

ADC: FCS Register

Offset: 0x08

Description

FIFO control and status

Table 570. FCS Register

BitsDescriptionTypeReset
31:28Reserved.--
27:24THRESH : DREQ/IRQ asserted when level >= thresholdRW0x0
23:20Reserved.--
19:16LEVEL : The number of conversion results currently waiting in the FIFORO0x0
15:12Reserved.--
11OVER : 1 if the FIFO has been overflowed. Write 1 to clear.WC0x0
10UNDER : 1 if the FIFO has been underflowed. Write 1 to clear.WC0x0
9FULLRO0x0
8EMPTYRO0x0
7:4Reserved.--
BitsDescriptionTypeReset
3DREQ_EN : If 1: assert DMA requests when FIFO contains dataRW0x0
2ERR : If 1: conversion error bit appears in the FIFO alongside the resultRW0x0
1SHIFT : If 1: FIFO results are right-shifted to be one byte in size. Enables DMA to byte buffers.RW0x0
0EN : If 1: write result to the FIFO after each conversion.RW0x0

ADC: FIFO Register

Offset: 0x0c

Description

Conversion result FIFO

Table 571. FIFO Register

BitsDescriptionTypeReset
31:16Reserved.--
15ERR : 1 if this particular sample experienced a conversion error. Remains in the same location if the sample is shifted.RF-
14:12Reserved.--
11:0VALRF-

ADC: DIV Register

Offset: 0x10

Description

Clock divider. If non-zero, CS_START_MANY will start conversions at regular intervals rather than back-to-back.

The divider is reset when either of these fields are written.

Total period is \( 1 + \text{INT} + \text{FRAC} / 256 \)

Table 572. DIV Register

BitsDescriptionTypeReset
31:24Reserved.--
23:8INT : Integer part of clock divisor.RW0x0000
7:0FRAC : Fractional part of clock divisor. First-order delta-sigma.RW0x00

ADC: INTR Register

Offset: 0x14

Description

Raw Interrupts

Table 573. INTR Register

BitsDescriptionTypeReset
31:1Reserved.--
0FIFO: Triggered when the sample FIFO reaches a certain level.
This level can be programmed via the FCS_THRESH field.
RO0x0

ADC: INTE Register

Offset: 0x18

Description

Interrupt Enable

Table 574. INTE Register

BitsDescriptionTypeReset
31:1Reserved.--
0FIFO: Triggered when the sample FIFO reaches a certain level.
This level can be programmed via the FCS_THRESH field.
RW0x0

ADC: INTF Register

Offset: 0x1c

Description

Interrupt Force

Table 575. INTF Register

BitsDescriptionTypeReset
31:1Reserved.--
0FIFO: Triggered when the sample FIFO reaches a certain level.
This level can be programmed via the FCS_THRESH field.
RW0x0

ADC: INTS Register

Offset: 0x20

Description

Interrupt status after masking & forcing

Table 576. INTS Register

BitsDescriptionTypeReset
31:1Reserved.--
0FIFO: Triggered when the sample FIFO reaches a certain level.
This level can be programmed via the FCS_THRESH field.
RO0x0