/**
* Battery level conversion from ADC to a percentage:
*
* The maximum ADC value for the battery voltage level is 511 for a
* 10-bit conversion. The ADC value is references vs. 1.25v and
* this maximum value corresponds to a voltage of 3.75v.
*
* For a coin cell battery 3.0v = 100%. The minimum operating
* voltage of the CC2540 is 2.0v so 2.0v = 0%.
*
* To convert a voltage to an ADC value use:
*
* (v/3)/1.25 * 511 = adc
*
* 3.0v = 409 ADC
* 2.0v = 273 ADC
*
* We need to map ADC values from 409-273 to 100%-0%.
*
* Normalize the ADC values to zero:
*
* 409 - 273 = 136
*
* And convert ADC range to percentage range:
*
* percent/adc = 100/136 = 25/34
*
* Resulting in the final equation, with round:
*
* percent = ((adc - 273) * 25 + 33) / 34
*/
这是 TI 官方给的一个demo,其电压源为 VDD/3。
看了这个例子,然后完成了自己项目中的需求。我想,以后再遇到检测 MCU 电压的时候就很驾轻就熟了。
附:我的项目中用到的是14bit的分辨率,参考电压为内部的1.25v,转换公式如下:
(102V/(510+102))/1.25 * 8192 = ADC