15. ADC

15. Analog-to-digital converter ADC

15.1 ADC Introduction

The CH559 chip provides 10-bit or 11 optional successive approximation analog-to-digital converters. The converter has 8 analog signal input channels, which can be time-sharing acquisition.

ADC main features:

  1. Select 10-bit or 11-bit resolution.
  2. ADC analog input voltage range: 0 to VDD33.
  3. Maximum 1MSPS sampling rate.
  4. Supports automatic alternate channel mode for automatic alternate conversion between two input channels.
  5. Built-in 2-level FIFO, supporting automatic sampling and DMA.

15.2 ADC Register

Table 15.2.1 ADC related register list

NameAddressDescriptionReset value
ADC_EX_SWF7hADC extended analog switch control register00h
ADC_SETUPF6hADC setting register08h
ADC_FIFO_HF5hFIFO high byte of ADC (read only)0xh
ADC_FIFO_LF4hFIFO low byte of ADC (read only)xxh
ADC_FIFOF4hADC_FIFO_L and ADC_FIFO_H form a 16-bit SFR0xxxh
ADC_CHANNF3hADC channel selection register00h
ADC_CTRLF2hADC control register00h
ADC_STATF1hADC status register04h
ADC_CK_SEEFhADC clock division setting register10h
ADC_DMA_CNEEhDMA Remaining Count Register00h
ADC_DMA_AHEDhDMA current buffer address high byte0xh
ADC_DMA_ALEChDMA current buffer address low bytexxh
ADC_DMAEChADC_DMA_AL and ADC_DMA_AH form a 16-bit SFR0xxxh

DMA current buffer address (ADC_DMA):

BitNameAccessDescriptionReset value
[7:0]ADC_DMA_AHRWThe current high byte of the DMA address, which can be preset to the initial value. It automatically increases after DMA. Only the lower 4 bits are valid. The upper 4 bits are fixed at 0. Only the first 4K of xRAM are supported.0xh
[7:0]ADC_DMA_ALRWLow byte of the current DMA address, which can be preset to the initial value. It is automatically increased after DMA. Only the upper 7 bits are valid. The lowest bit is fixed at 0. Only even addresses are supported.xxh

DMA Remaining Count Register (ADC_DMA_CN):

BitNameAccessDescriptionReset value
[7:0]ADC_DMA_CNRWThe current remaining DMA count, which can be preset to the initial value, and is automatically reduced after the DMA operation00h

Clock divider setting register (ADC_CK_SE):

BitNameAccessDescriptionReset value
7bADC_CHK_CLK_SELRWAIN7 level detection delay clock frequency selection, if this bit is 0, low speed 1x clock frequency. If this bit is 1, high speed 4x clock frequency0
[6:0]MASK_ADC_CK_SERWADC clock division factor to set the internal ADC working clock10h

ADC status register (ADC_STAT):

BitNameAccessDescriptionReset value
7bADC_IF_DMA_ENDRWDMA complete interrupt flag. A 1 in this bit indicates an interrupt; a 0 in this bit indicates no interrupt. Cleared on write 1 or cleared on ADC_DMA_CN0
6bADC_IF_FIFO_OVRWThis bit is 1 to indicate FIFO overflow interrupt; if this bit is 0, there is no interrupt. Write 1 clear0
5bADC_IF_AIN7_LOWRWThis bit is 1 to indicate that the AIN7 low-level interrupt was detected.0
4bADC_IF_ACTRWThis bit is 1 to indicate an ADC conversion completion interrupt. Write 1 to clear it.0
3bADC_AIN7_INTR0This bit is 1 to indicate the delay state of the AIN7 input low level0
2bADC_CHANN_IDR0is the current channel identification flag in the automatic alternate channel mode. 0 means AIN0 or AIN6. 1 means AIN1 or AIN4 or AIN70
2bADC_DATA_OKROIn the manual channel selection mode, the ADC conversion is completed and the result is ready. A 1 indicates that the ADC data is ready and the ADC converter is idle. A 0 indicates that the ADC is in progress and the data is not ready.1
[1:0]MASK_ADC_FIFO_CNTR0ADC FIFO current count00b

MASK_ADC_FIFO_CNT consists of bADC_FIFO_CNT1 and bADC_FIFO_CNT0, which is used to display the ADC’s FIFO count.

MASK_ADC_FIFO_CNTDescription
00bFIFO is empty.If the FIFO is read, it will directly return the current ADC result value.
01b1 data in FIFO
10bFIFO is full, there are 2 data in FIFO
11bunknown error

ADC Control Register (ADC_CTRL):

BitNameAccessDescriptionReset value
7bADC_SAMPLERWIn the manual sampling mode, it is the sampling control bit. Set it first and then clear it to 0 to generate a high-level pulse to start the ADC once. In the automatic sampling mode, it is the sampling pulse state of automatic sampling.0
6bADC_SAMP_WIDTHRWSampling pulse width control bit in auto sampling mode, 0 for 1 ADC clock width; 1 for 2 ADC clock width0
5bADC_CHANN_MOD1RWADC channel mode high0
4bADC_CHANN_MOD0RWADC channel mode low0
[3:0]MASK_ADC_CYCLERWADC running cycle number, 0 means manual sampling; non-zero value means setting the running cycle of automatic sampling (counted by ADC clock)0000b

MASK_ADC_CHANN consisting of bADC_CHANN_MOD1 and bADC_CHANN_MOD0 is the ADC channel control mode flag.

MASK_ADC_CHANNDescription
00bManually select channel mode, set ADC_CHANN to select current input channel
01bAuto alternate channel mode, switch between AIN0 and AIN1 automatically
10bAuto Alternate Channel Mode, automatically alternate between AIN6 and AIN4
11bAuto Alternate Channel Mode, automatically alternate between AIN6 and AIN7

ADC channel selection register (ADC_CHANN):

BitNameAccessDescriptionReset value
[7:0]ADC_CHANNRWSelect the current ADC analog input channel, select one from the 8 channels, bits 0~7 correspond to AIN0~AIN7 respectively00h

ADC’s FIFO port (ADC_FIFO):

BitNameAccessDescriptionReset value
[7:0]ADC_FIFO_HROADC FIFO high byte, only the lower 4 bits are valid, the upper 4 bits are fixed to 00xh
[7:0]ADC_FIFO_LROADC FIFO low bytexxh

ADC setup register (ADC_SETUP):

BitNameAccessDescriptionReset value
7bADC_DMA_ENRWThis bit is 1 to enable the DMA and DMA interrupts of the ADC. 0 to disable the enable0
6bADC_IE_FIFO_OVRWThis bit is 1 to enable the FIFO overflow interrupt. This bit is 0 to disable the enable0
5bADC_IE_AIN7_LOWRWThis bit is 1 to enable detection of AIN7 low-level interrupt0
4bADC_IE_ACTRWThis bit is 1 to enable the ADC conversion completion interrupt. This bit is 0 to disable the enable0
3bADC_CLOCKROCurrent level of the internal ADC clock signal0
2bADC_POWER_ENRWADC power control bit of the sampling conversion module. This bit is 0 to turn off the power of the ADC module and enter the sleep state. A bit of 1 to turn on0
1bADC_EXT_SW_ENRWPower control bit of the extended analog switch module. This bit is 0 to disable the extended analog switch module. 1 to enable the bit.0
0bADC_AIN7_CHK_ENRWDetect the power control bit of AIN7 low-level module. This bit is 0 to disable detection of AIN7 low-level module. 1 to enable0

ADC extended analog switch control register (ADC_EX_SW):

BitNameAccessDescriptionReset value
7bADC_SW_AIN7_HRWAIN7 channel internal analog switch connection control, this bit is 1 internally connects AIN7 to VDD33. This bit is 0 to disconnect AIN7 from VDD330
6bADC_SW_AIN6_LRWAIN6 channel internal analog switch connection control, this bit is 1 internally connects AIN6 to GND. This bit is 0 to disconnect AIN6 from GND0
5bADC_SW_AIN5_HRWAIN5 channel internal analog switch connection control, this bit is 1 internally connects AIN5 to VDD33. This bit is 0 to disconnect AIN5 and VDD330
4bADC_SW_AIN4_LRWAIN4 channel internal analog switch connection control, this bit is 1 internally connects AIN4 to GND. This bit is 0 to disconnect AIN4 from GND0
3bADC_EXT_SW_SELRWOn-resistance value selection bit of the internal analog switch. This bit is 0 to select high resistance, about 800Ω. This bit is 1 to select low resistance, about 300Ω0
2bADC_RESOLUTIONRWADC resolution selection bit, this bit is 0 to select 10-bit resolution. This bit is 1 to select 11-bit resolution0
1bADC_AIN7_DLY1RWDelay control bit for detecting AIN7 low level 10
0bADC_AIN7_DLY0RWDelay control bit for detecting AIN7 low level 00

bADC_AIN7_DLY1 and bADC_AIN7_DLY0 form MASK_ADC_AIN7_DLY, which is used to select the delay after detecting the level change of AIN7: 00 is no delay, 01 is the longest delay, 10 is the longer delay, and 11 is the shorter delay.

15.3 ADC Functions

ADC sampling mode configuration steps:

  1. Set the bADC_POWER_EN bit in the ADC setting register ADC_SETUP to 1 to enable the ADC module.
  2. Set the clock divider setting register ADC_CK_SE, select the clock frequency, the highest frequency is 12MHz, and it is recommended not to be lower than 1MHz.
  3. Clear the existing data in the FIFO. If you need to use interrupt or DMA, then make the relevant settings here.
  4. For the automatic sampling mode, the ADC channel selection register ADC_CHANN should be set first.
  5. Set bADC_SAMPLE and MASK_ADC_CYCLE in the ADC control register ADC_CTRL.If MASK_ADC_CYCLE is set to 0, it is a manual sampling mode.If MASK_ADC_CYCLE is set to a non-zero value, it is an automatic sampling mode.At this time, MASK_ADC_CYCLE is a continuous and automatic sampling. Clock cycle.
  6. For the manual sampling mode, set the ADC channel selection register ADC_CHANN to select the ADC analog signal input channel.
  7. If it is in manual sampling mode, you need to set the bADC_SAMPLE bit to 1 and clear it after delaying at least one ADC clock cycle to complete an analog signal sampling and start an ADC conversion.
  8. Wait for the bADC_IF_ACT bit in the ADC status register ADC_STAT to be 1, indicating that the ADC conversion is complete, and the result data can be read through the ADC_FIFO.
  9. Or read MASK_ADC_FIFO_CNT of ADC status register ADC_STAT to get the FIFO count, and then read some data through ADC_FIFO. It is recommended to discard the first ADC result data, because there may be incomplete sampling.
  10. For DMA steps: Set ADC_DMA as the start address value of the user-defined data buffer, set ADC_DMA_CN as the user-defined DMA remaining count, and set the bADC_DMA_EN bit in ADC_SETUP to 1 to enable the DMA function.
  11. There are 12 bits of ADC result data, among which bits 0 ~ 10 are ADC values, bits 11 are flag bits, bits 12 ~ 15 are always 0. For manual channel selection mode, bit 11 is always 0; for automatic alternate channel mode, bit 11 indicates the channel identification flag of the ADC value, refer to bADC_CHANN_ID description.