Functional Description

Channel Switch List

The ADC provides a mechanism that allows software to configure the complete conversion sequence via an ADC channel switch list. Software can specify the target channel numbers to be converted with two registers (REG_ADC_CHSW_LIST_0 and REG_ADC_CHSW_LIST_1). The list length field in the REG_ADC_CONF[7:4] register can be configured to configure the number of channels in the sequence.

For example, consider the values configured for REG_ADC_CHSW_LIST_0 and REG_ADC_CHSW_LIST_1 as shown in the following table:

Register

[3:0]

[7:4]

[11:8]

[15:12]

[19:16]

[23:20]

[27:24]

[31:28]

REG_ADC_CHSW_LIST_0

0

1

2

3

4

5

9

0

REG_ADC_CHSW_LIST_1

1

9

5

4

3

2

1

0

If REG_ADC_CONF[7:4] is set to 9, the ADC converts only the first 10 (the value of REG_ADC_CONF[7:4] + 1) channels in the list. When operating in Auto mode, the ADC performs conversions sequentially from the first channel to the last channel specified in the list. Once the channel length count reaches the value configured in REG_ADC_CONF[7:4], the ADC restarts the conversion sequence from the first channel (as illustrated in the following figure).

../../../_images/auto_mode_waveform.svg

Auto mode waveform

The REG_ADC_LAST_CH[3:0] field indicates the last converted channel, which helps in tracking the current position within the sequence. Additionally, the REG_ADC_BUSY_STS[0] bit indicates the ADC’s busy status; it remains 1 while the ADC is actively processing a channel conversion.

Operation Mode

RTL8721Dx:

Ameba supports only one operation mode: auto mode.

Auto Mode

In auto mode, ADC continuously executes conversions without any trigger sources after auto channel switch register is set. Auto mode would not stop conversions until auto channel switch register is clear (register REG_ADC_AUTO_CSW_CTRL [0]) or the auto channel switch is disabled (register REG_ADC_CONF[3:1]).

In auto mode, ADC samples automatically by hardware without assistance of core or other modules, it can be applied to the situation where core resources are limited and real-time detection is required. Refer to Auto mode waveform for the auto mode waveform.

The ADC will scan the channels in the list in order. There is no interval between the adjacent channels, and the scanning speed only depends on the sampling rate of the ADC. At the end of the sampling period, the ADC immediately outputs the data to register and FIFO. So there is no need to set the CH switching time and settling time.

Because the sampled data is continuously filled into the register and FIFO when the REG_ADC_AUTO_CSW_CTRL [0] is set, if the data cannot be taken out, the data will be lost and the overflowed data will not be filled into the FIFO. For intermittent data getting from FIFO, FIFO clearing is recommended before getting.

However, there is a situation that needs to be paid attention to: if the internal resistance of the signal source sampled by ADC is very large, the input signal is easy to receive interference.

../../../_images/high_resistance_of_input_circuit.svg

The solution is as follows:

  1. Reduce the impedance

As shown in the following figure, operational amplifier (OA) provides extremely low output impedance.

../../../_images/operational_amplifier_or_a_resistance_divider.svg
  1. Arrange Grounding Isolation Channel in channel list

As shown in the following figure, using a GND channel (internal GND channel or external channel which is connected to GND), configure the channel list of ADC to: CH0, CH_GND, CH1, CH_GND, CH2 … CH5, CH_GND. This avoids crosstalk, and the resulting inter-channel delay depends on the sampling rate of the ADC and the configuration of the channel list.

../../../_images/add_grounding_isolation_channel.svg

Low Power Clock Source

RTL8721Dx:

The following figure shows the ADC clock generation tree. Users can configure ADC sample frequency by setting register REG_ADC_CLK_DIV[2:0].

../../../_images/clock_generation_tree_smart_lite_dplus.svg

After the system enters the low-power state, the ADC can execute sampling operations via auto mode, and the system can be woken up by an ADC interrupt.

Under auto mode, the ADC hardware automatically and continuously samples the external analog voltage. Users can preset high/low thresholds as well as comparison criteria. The CPU remains completely in sleep mode throughout the entire process, and the system is woken up only when the sampled voltage meets the predefined comparison criteria.

In the low-power state, only OSC clock can be selected as the ADC clock, allowing the system to be woken up.

Note

Only auto mode is supported for low-power operation on this chip.

Independent Comparison Event of Each Channel

The voltage monitoring function can be realized by using ADC, and each CH of ADC can be configured with two independent comparison thresholds and different comparison criterion. When the sample value of ADC reaches the configured condition, an interrupt can be detected in REG_ADC_INTR_STS.

The threshold of each channel can be configured in REG_ADC_COMP_TH_CHx, which contains both high threshold and low threshold. The comparison criterion of each channel can be configured in REG_ADC_COMP_CTRL. ADC comparison supports four different comparison criterion:

  • Vin < bit_adc_comp_th_l_chx

  • Vin > bit_adc_comp_th_h_chx

  • Vin >= bit_adc_comp_th_l_chx and Vin <= bit_adc_comp_th_h_chx

  • Vin < bit_adc_comp_th_l_chx or Vin > bit_adc_comp_th_h_chx.

For example, when configured as Vin < bit_adc_comp_th_l_chx or Vin > bit_adc_comp_th_h_chx, if the ADC conversion data exceeds the higher and lower threshold, an interrupt event will occur.

../../../_images/adc_comparison_event.svg
RTL8721Dx:

Two different interrupt generation modes (level detection and edge detection) are used to inform CPU of comparison match events. The level detection mode continuously reports the interrupt, while the edge detection mode reports it only once when the interrupt is generated.

Acquisition of Sampling Results

FIFO

RTL8721Dx:

Users can easily acquire ADC sample results from the ADC FIFO by reading the REG_ADC_DATA_GLOBAL register. The ADC stores all sampled results within this FIFO. The ADC FIFO has 64 entries, and each 20-bit FIFO data entry consists of a 4-bit channel number and 16-bit conversion data, as shown in the following figure.

../../../_images/fifo_structure_20bit.svg

Because the FIFO acts as a buffer between the data acquisition and data processing systems operating at different speeds, timely data retrieval is crucial to prevent data loss.

During normal operation, the ADC continuously writes data to the FIFO, while the system reads from it. If the system reads data slower than the ADC writes it, a FIFO overflow will occur. In the event of an overflow, any newly sampled data is discarded and will not be written to the FIFO, as shown in the figure above.

In addition to retrieving data promptly to avoid overflows, it is highly recommended to clear the ADC FIFO by setting REG_ADC_CLR_FIFO[0] before initiating any new data sampling process.

If the FIFO overflow interrupt (ADC_BIT_IT_FIFO_OVER_EN) is enabled, an interrupt signal is sent to the CPU NVIC upon a FIFO overflow. Similarly, if the FIFO empty interrupt (ADC_BIT_IT_FIFO_EMPTY_EN) is enabled, an interrupt is triggered when the FIFO becomes empty.

Additionally, users can set a custom FIFO full threshold by configuring REG_ADC_FULL_LVL[5:0]. When the FIFO full interrupt (ADC_BIT_IT_FIFO_FULL_EN) is enabled, an interrupt is sent to the CPU NVIC once the number of FIFO entries reaches this configured threshold, as shown in the following figure.

REG_ADC_FLR[5:0] indicates the current number of entries in the ADC FIFO.

../../../_images/fifo_interrupt.svg

Individual Channel Register

Each channel has its own data register to store its latest conversion result. These registers are named REG_ADC_DATA_CHx, where x represents the specific channel number (e.g., CH0).

RTL8721Dx:
  • REG_ADC_DATA_CHx[15:0] contains the latest conversion data for CHx.

  • REG_ADC_DATA_CHx[19:16] indicates the channel number associated with the latest conversion data.

  • REG_ADC_DATA_CHx[20] is a flag indicating a data overwrite event.

  • REG_ADC_DATA_CHx[21] is a flag indicating that a conversion is complete.

PAD Configuration

The ADC analog front-end(AFE) is an analog device and the analog signal enters the chip through the chip pins. Therefore there should be no significant digital signal interference and pull-up/pull-down circuits on this path.

If users want to use a GPIO pin as an ADC input pin, besides configuring the pin function as ADC, the digital circuit function of the selected pin should be disabled and the pin should be set as no pull state (including sleep state) as well.

Calibration

Each IC’s ADC is factory calibrated. The users can directly obtain the exact voltage conversion results that have been calibrated by calling ADC_GetVoltage() with conversion data as parameter.