This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Battery Service

Part Number: CC2541
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?

  • Hi,

    The battery voltage can be between 3V (100% loaded - ADC measures 409) and 2.0V (0% loaded - ADC measures 273). Then we calculate in order to convert an ADC value varying between 273 and 409 to a percentage (between 0 and 100).

    sadasivam arumugam said:
    * (v/3)/1.25 * 511 = adc

    => This comes from the ADC: as mentioned, the reference value is three times smaller than the actual value. In addition the value returned at full scale by the ADC is 511.

    sadasivam arumugam said:
    percent = ((adc - battery_min)*Numerator + (denominator -1)/denominator

    => this is a way to force an integer division to round the result (instead of truncate it).

    I hope this will help,

    Regards,

  • Yes, This helps me. 

    And if we use external reference voltage as 3.32 then how will the ADC equation changes

  • Hi,

    You have to adapt the code with the characteristics of your own project. I cannot do this for you as I do not have all the characteristics of your project.

    If you change the reference voltage, I assume you are changing also the maximum and minimum battery voltage, the maximum value measured by the ADC, and so on and so forth.

    Regards,

  • Yes. I am changing the voltage max and min as per reference voltage.