6 ADC相关

6.1 55系列ADC校准原理

sf32lb55x芯片,为10bit的ADC,In order to ensure the accuracy of ADC sampling;;
校准原理:
芯片出厂时, 会测量每个芯片在1.0V和2.5V的ADC值,写入到flash内factory区,ID为FACTORY_CFG_ID_ADC.;
ADC初始化sifli_adc_init时, 会从flash的factory区域,读出这两个值,即变量vol10,vol25, 也就是对应的电压值1.0v和2.5v;

通过函数

sifli_adc_calibration(cfg.vol10, cfg.vol25, vol1, vol2, &off, &rat);
#define ADC_STANDARD_X3_VOL1           (1000)
#define ADC_STANDARD_X3_VOL2           (2500)

Calculate a linear line between the ADC value and the voltage value of the corresponding register;;
得到该直线的偏移值offset和线性比率ratio, offset 值是计算出来的0V对应的寄存器值;

The values read by ADC in the future are the corresponding voltage values obtained through this offset and radio ratio;;
备注:
The early version used two sampling points of 1V and 2.5V as ADC check points;

#define ADC_STANDARD_X3_VOL1           (1000)
#define ADC_STANDARD_X3_VOL2           (2500)

新的版本, 采用的0.3V和0.8V两个采样点作为ADC校验点

#define ADC_STANDARD_X1_VOL1           (300)
#define ADC_STANDARD_X1_VOL2           (800)

区别0.3V和0.8V两个采样点的校准方法, 这两个校准值最高bit被置1, 如下:

alt text

if ((cfg.vol10 & (1 << 15)) && (cfg.vol25 & (1 << 15))) // small range, use X1 mode

对应的sifli_adc_get_mv计算方法, 也会针对两种校准范围adc_range不同, 算法也会不一样;

在0.3V和0.8V两个采样点的校准方法时, 电压在接近0V和超过1V之后,精准度都不够,另外该模式下,软件寄存器ADC_CFG_RE关闭了GPADC_ADC_CFG_REG1_ANAU_GPADC_ATTN3X模式, 即关闭了内部的分压电阻,因此ADC测试点不能直接接超过1.1V电压,否则可能会烧芯片;

alt text
在采用1V,2.5V两个采样点作为ADC校验点的校准方式时,会寄存器配置开启GPADC_ADC_CFG_REG1_ANAU_GPADC_ATTN3X模式, 芯片内的分压电阻会被启用,衰减3倍,输入电压即不能超过3.3V

6.2 ADC采样Vbat电池电压不准 debug方法

a,万用表测试采样点电平,目前推荐分压电路为 1M/220k 1%精度的分压电阻;
Therefore, the level at the sampling place should be within the corresponding voltage as follows. If not, it is necessary to confirm the value and accuracy of the voltage dividing resistor;;
(注意:用万用表或者示波器测量采样点电压, 由于有引入设备输入阻抗,会导致30mV的电压跌落)

alt text

alt text
b,After power-on and boot-up, and after sleep wake-up, the sampling of ADC may be inaccurate for about 300ms;,如下图:

alt text
Use an oscilloscope to capture the sampling waveform of ADC at startup, you can find that except for the initial default high level, there is also charge and discharge caused by the rc circuit, which causes the sampling to stabilize after about 350ms;。In practical applications, it is necessary to add delay sampling according to the actual situation or filter out the unstable sampling values in front;
c,There are also the following sampling point waveforms after entering standby;:

alt text
从standby醒来后,采样点如下波形:

alt text
The reason here is that PB10 is internally pulled up by default when not initialized, and is used as ADC input. In pinmux.c, it needs to be configured as PIN_NOPULL and PIN_ANALOG_INPUT mode;;
如下图,缺少如下红框这条设置为PIN_ANALOG_INPUT模式,导致如上的PB10内部上拉电阻被使能, 出现偶尔采样电压很高;

alt text
d, 55x芯片没有进行过校准;
芯片出厂都会校准过,校准后,会在flash的工厂区有ADC校准参数, 具体参考ADC校准原理一章l

6.3 ADC注意事项

a, The maximum sampling value of 55x is 1.1V, and that of 56x and 52x is 3.3V. The sampling voltage cannot be greater than this value, otherwise it is easy to damage the ADC module;
b, When the log uart print of 56x is connected to an external PC, the reference level of the external hardware serial port tool used must match the IO level, otherwise it will affect the sampling accuracy of ADC;,比如IO电平是3.3v,外部连接的硬件串口工具参考电平为5V,采样出来的adc就会比正常低很多,4V电池有可能检测出来只有3.3V。
c, When using a multimeter to measure the voltage at the sampling point, due to the introduction of resistance, the measured value is generally slightly smaller than the actual value;