Other Parts Discussed in Thread: CC2540
Hi,
Please find the bwlow snippet:
/**
* 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
* percent = ((adc - battery_min)*Numerator + (denominator -1)/denominator
*/
Can you explain on this ADC conversion equation and percentage equation?