Battery level Reading Error

Hi,

I am trying to use cr2032 battery with nrf52840 to measure the battery level.

To begin with, I first integrated the battery level measuring code in my  application from ble_app_hrs which is located in the examples/ble_peripheral/ which did not work at all and then i tried to code normally using 14 bit resolution for better accuracy.

For simulation, I am using DC Power Supply to change the voltage, NRF_SAADC_INPUT_VDD as the input channel and nrf connect app so as to validate the measurement. However, battery percentage is 100  from 3.3V to 2.5V / 2.4V and started to decrease only after 2.5V from 100%.It was showing 98% for 2.4V, 80% for 2.1 V and decreasing further up to 58% for 1.8V Could anyone please help me on how to accurately measure battery level of nrf52840 with CR2032 battery from 3.3V? Code Snippets are attached .

Parents Reply
  • Hi,

    Thanks for the repo. Baremetal code worked perfectly fine. However, I faced a challenge with high frequency clock, I just commented out that high frequency clock and integated the code, as I do not need the values to be too accurate . Still that is a problem which I am not bale to get it into my head along with the api's issue with which this thread started. I tried to apply the same concept of the baremetal code in the api, but still I faced the same challenge.

Children
  • Hi,

    Shouri said:
    I faced a challenge with high frequency clock, I just commented out that high frequency clock and integated the code, as I do not need the values to be too accurate

    As the SoftDevice is enabled here, you need to use the SoftDevice APIs for clock control, or alternatively (or perhaps better), use the clock driver, which will use the SoftDevice APIs. Accessing the clock registers directly will cause the SoftDevice to assert.

    Shouri said:
    Still that is a problem which I am not bale to get it into my head along with the api's issue with which this thread started. I tried to apply the same concept of the baremetal code in the api, but still I faced the same challenge.

    Which APIs are you referring to here? If you got the ADC reading workign, the only thing left is to use a function that maps the voltage to a battery percentage (which will be very inaccurate, but that is how it is), and then update the battery percentage characteristic. For the first, you can use battery_level_in_percent() if that is good enough for you, or make your own. Lastly, call ble_bas_battery_level_update() with  the new battery level. This is demonstrated in the proximity example (examples/ble_peripheral/ble_app_proximity/main.c).

Related