ADC
概述
SDM ADC 是一种基于 Sigma-Delta 调制原理的模数转换器,其工作原理是通过对输入信号进行连续的高频采样和数字滤波,以实现高精度的模拟信号到数字信号转换。相比于传统的 ADC,SDM ADC 具有更高的分辨率、更低的功耗和更好的抗干扰能力。
功能特性
支持的输出数字信号位宽为24bits
支持单端输入100 ~ 1150 mv
支持差分输入±650mv
资源依赖
ADC
DMA
模式说明
同步读取(polling)
同步读取时首先开启adc模块,配置读取的信号,等待数据准备好并读取数据
同步读取时若已经有异步读取正在进行,则等待当前异步读取完成,并中断下一个异步读取,待同步读取完成后,继续完成后续异步读取
同步读取会同时读取多个数据取平均值
异步读取(DMA)
异步读取将需要读取的信号添加进链表,若当前没有正在进行的读取,则开启adc并配置dma来读取数据,并等待中断
连续异步读取可能被同步读取打断,但数据不会被破坏
异步读取将同时读取多个数据取平均值
测量说明
单端测量
单端输入测量范围的信号,内部adc将另一端选择为内部vcm,并测量两者的差分值,获取最大24bit整数数据。
名称 |
值 |
|---|---|
vcm |
500mv |
vrefpn |
650mv |
读取 adc 值 code 范围-8388608 ~ 8388607 电压转换公式如下:
差分测量
差分输入测量范围的信号,adc内部分别接被测信号的一端,并测量两者的差分值,获取最大24bit整数数据。
名称 |
值 |
|---|---|
vrefpn |
650mv |
读取 adc 值 code 范围-8388608 ~ 8388607 电压转换公式如下:
或使用 wq_adc_2_mv() 将code转换为电压
API 介绍
Typedefs
-
typedef void (*wq_adc_sig_read_cb)(WQ_ADC_INTR_SIG signal, int32_t value)
Typedef for callback function to read internal signals ADC value.
备注
This function is intended to be called from within an interrupt context.
- Param signal:
The ADC internal signal being read, represented by the WQ_ADC_INTR_SIG enum type
- Param value:
The ADC value read for the specified signal
-
typedef void (*wq_adc_ext_read_cb)(WQ_ADC_EXT_PORT port, int32_t value)
Typedef for callback function to read external ADC signal.
备注
This function is intended to be called from within an interrupt context.
- Param port:
The external ADC port being read, represented by the WQ_ADC_EXT_PORT enum type
- Param value:
The ADC value read for the specified port
-
typedef void (*wq_adc_diff_read_cb)(WQ_ADC_EXT_PORT portp, WQ_ADC_EXT_PORT portn, int32_t value)
Typedef for callback function to read differential ADC signal.
备注
This function is intended to be called from within an interrupt context.
- Param portp:
The positive terminal of the differential ADC signal, represented by the WQ_ADC_EXT_PORT enum type
- Param portn:
The negative terminal of the differential ADC signal, represented by the WQ_ADC_EXT_PORT enum type
- Param value:
The ADC value read for the specified differential signal
-
typedef void (*wq_adc_ccs_read_cb)(int32_t value)
Typedef for callback function to read constant current source ADC signal.
备注
This function is intended to be called from within an interrupt context.
- Param value:
The ADC value read for the constant current source signal
-
typedef void (*wq_adc_vtemp_read_cb)(float degrees)
Typedef for callback function to read voltage temperature ADC signal.
备注
This function is intended to be called from within an interrupt context.
- Param degrees:
The temperature value read from the voltage temperature ADC signal
Enums
-
enum WQ_ADC_INTR_SIG
Values:
-
enumerator WQ_ADC_INTR_SIG_VTEMP
Chip core temperature
-
enumerator WQ_ADC_INTR_SIG_VBAT
Battery voltage
-
enumerator WQ_ADC_INTR_SIG_VCHG
Charger voltage
-
enumerator WQ_ADC_INTR_SIG_VTEMP
-
enum WQ_ADC_EXT_PORT
Values:
-
enumerator WQ_ADC_EXT_PORT_0
Extern ADC port 0
-
enumerator WQ_ADC_EXT_PORT_1
Extern ADC port 1
-
enumerator WQ_ADC_EXT_PORT_2
Extern ADC port 2
-
enumerator WQ_ADC_EXT_PORT_3
Extern ADC port 3
-
enumerator WQ_ADC_EXT_PORT_4
Extern ADC port 4
-
enumerator WQ_ADC_EXT_PORT_5
Extern ADC port 5
-
enumerator WQ_ADC_EXT_PORT_0
Functions
-
WQ_RET wq_adc_init(void)
Init ADC module.
- 返回:
WQ_RET_OK success.
WQ_RET_FAIL mutex create fail.
WQ_RET_NOMEM no memory to save necessary data.
-
WQ_RET wq_adc_deinit(void)
Deinit ADC module.
- 返回:
WQ_RET_OK success.
WQ_RET_NOT_EXIST adc not inited.
-
float wq_adc_2_mv(int32_t adc, bool isdiff)
Convert raw adc value to voltage.
- 参数:
adc -- [in] raw adc code
isdiff -- [in] Is it a differential signal
- 返回:
float voltage in millivolts
-
WQ_RET wq_adc_signal_poll_read_value(WQ_ADC_INTR_SIG signal, int32_t *value)
Reads the ADC value of a specified internal signal This function is used to read the ADC value of a specified internal signal.
Before using this function, ensure that the internal signal is configured correctly and that the ADC module is initialized properly.
备注
The ADC value typically represents a digital approximation of the analog signal.
备注
Block until read is complete
- 参数:
signal -- [in] The internal signal whose ADC value needs to be read
value -- [out] raw adc code
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_signal_poll_read_voltage(WQ_ADC_INTR_SIG signal, float *vol)
Reads the ADC value of a specified internal signal This function is used to read the ADC value of a specified internal signal.
Before using this function, ensure that the internal signal is configured correctly and that the ADC module is initialized properly.
备注
The ADC value typically represents a digital approximation of the analog signal.
备注
Block until read is complete
- 参数:
signal -- [in] The internal signal whose ADC value needs to be read
vol -- [out] voltage at millivolts
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_signal_read_value(WQ_ADC_INTR_SIG signal, wq_adc_sig_read_cb cb)
Reads the ADC value of a specified internal signal This function is used to read the ADC value of a specified internal signal.
Before using this function, ensure that the internal signal is configured correctly and that the ADC module is initialized properly.
备注
The ADC value typically represents a digital approximation of the analog signal.
备注
Block until read is complete
- 参数:
signal -- [in] The internal signal whose ADC value needs to be read
cb -- [in] Callback when read done, invoke to give raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_ext_poll_read_value(WQ_ADC_EXT_PORT port, int32_t *value)
Opens a external port and measures its voltage.
This function is used to open a external port and measure its voltage. The pin will be configured in input mode for voltage measurement.
Before using this function, ensure that the pin is not occupied by other parts of the code. Additionally, consider the input impedance of the pin and the voltage range supported by the measurement system for accurate results.
备注
Block until read is complete
- 参数:
port -- [in] The pin number to be opened and measured
value -- [out] raw adc code
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_ext_poll_read_voltage(WQ_ADC_EXT_PORT port, float *vol)
Opens a external port and measures its voltage.
This function is used to open a external port and measure its voltage. The pin will be configured in input mode for voltage measurement.
Before using this function, ensure that the pin is not occupied by other parts of the code. Additionally, consider the input impedance of the pin and the voltage range supported by the measurement system for accurate results.
备注
Block until read is complete
- 参数:
port -- [in] The pin number to be opened and measured
vol -- [out] voltage at millivolts
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_ext_read_value(WQ_ADC_EXT_PORT port, wq_adc_ext_read_cb cb)
Opens a external port and measures its voltage.
This function is used to open a external port and measure its voltage. The pin will be configured in input mode for voltage measurement.
Before using this function, ensure that the pin is not occupied by other parts of the code. Additionally, consider the input impedance of the pin and the voltage range supported by the measurement system for accurate results.
- 参数:
port -- [in] The pin number to be opened and measured
cb -- [in] Callback when read done, invoke to give raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_diff_poll_read_value(WQ_ADC_EXT_PORT portp, WQ_ADC_EXT_PORT portn, int32_t *value)
This function is used to open two specific pins and measure the differential voltage between them. The pins will be configured in input mode for voltage measurement, and the voltage difference between the positive and negative terminals will be calculated.
Before using this function, ensure that the pins are not occupied by other parts of the code. Additionally, consider the input impedance of the pins and the voltage range supported by the measurement system for accurate results.
备注
Measurement accuracy: 24-bit
备注
Block until read is complete
- 参数:
portp -- [in] differential positive port
portn -- [in] differential negative port
value -- [out] raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_diff_poll_read_voltage(WQ_ADC_EXT_PORT portp, WQ_ADC_EXT_PORT portn, float *vol)
This function is used to open two specific pins and measure the differential voltage between them. The pins will be configured in input mode for voltage measurement, and the voltage difference between the positive and negative terminals will be calculated.
Before using this function, ensure that the pins are not occupied by other parts of the code. Additionally, consider the input impedance of the pins and the voltage range supported by the measurement system for accurate results.
备注
Measurement accuracy: 24-bit
备注
Block until read is complete
- 参数:
portp -- [in] differential positive port
portn -- [in] differential negative port
vol -- [out] voltage at millivolts
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_diff_read_value(WQ_ADC_EXT_PORT portp, WQ_ADC_EXT_PORT portn, wq_adc_diff_read_cb cb)
This function is used to open two specific pins and measure the differential voltage between them. The pins will be configured in input mode for voltage measurement, and the voltage difference between the positive and negative terminals will be calculated.
Before using this function, ensure that the pins are not occupied by other parts of the code. Additionally, consider the input impedance of the pins and the voltage range supported by the measurement system for accurate results.
备注
Measurement accuracy: 24-bit
- 参数:
portp -- [in] differential positive port
portn -- [in] differential negative port
cb -- [in] Callback when read done, invoke to give raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_ccs_poll_read_value(int32_t *value)
This function is used to generate a constant current of 25uA on WQ_ADC_EXT_PORT_2 and measure the voltage level at that pin. The pin will be configured to input mode for voltage measurement.
Before using this function, ensure that the
参见
WQ_ADC_EXT_PORT_2 is not occupied by other parts of the code.
备注
Block until read is complete
- 参数:
value -- [out] raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_ccs_poll_read_voltage(float *vol)
This function is used to generate a constant current of 25uA on WQ_ADC_EXT_PORT_2 and measure the voltage level at that pin. The pin will be configured to input mode for voltage measurement.
Before using this function, ensure that the
参见
WQ_ADC_EXT_PORT_2 is not occupied by other parts of the code.
备注
Block until read is complete
- 参数:
vol -- [out] voltage at millivolts
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_css_read_value(wq_adc_ccs_read_cb cb)
This function is used to generate a constant current of 25uA on WQ_ADC_EXT_PORT_2 and measure the voltage level at that pin. The pin will be configured to input mode for voltage measurement.
Before using this function, ensure that the
参见
WQ_ADC_EXT_PORT_2 is not occupied by other parts of the code.
- 参数:
cb -- [in] Callback when read done, invoke to give raw adc value
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_vtemp_poll_read(float *degrees)
Polling to read the chip core temperature.
备注
Block until read is complete
- 参数:
degrees -- [out] temperature at degrees celsius
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_vtemp_read(wq_adc_vtemp_read_cb cb)
Read chip core voltage.
- 参数:
cb -- [in] Callback when read done, invoke to give temperature
- 返回:
WQ_RET_OK success.
WQ_RET_INVAL Bad param.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
WQ_RET wq_adc_mic_open(const wq_adc_mic_cfg_t *cfg)
Enable adc mic mode.
参见
参见
WQ_ADC_EXT_PORT_0 is not occupied by other parts of the code.
参见
备注
Before using this function, ensure that the
备注
Mic bias need to be turned on separately
- 参数:
cfg -- [in] Pointer for mic mode config
- 返回:
WQ_RET_OK success.
WQ_RET_NOMEM no memory to save necessary data.
WQ_RET_NOSUPP Unsupported config.
WQ_RET_NOT_READY ADC not be inited.
-
struct wq_adc_mic_cfg_t