Hello,
I'm powering a Readbear BLE nano using a CR2450 coin cell battery. The firmware application is written using mbed. How can I measure the battery level of the CR2450 over time using the Nordic mbed API and libraries?
Thanks, Chris
Hello,
I'm powering a Readbear BLE nano using a CR2450 coin cell battery. The firmware application is written using mbed. How can I measure the battery level of the CR2450 over time using the Nordic mbed API and libraries?
Thanks, Chris
I've never heard of any API capable of providing such features. I firmly believe you have to measure the hardware using an amp meter/scope or current analyzer
There's a API in the Nordic SDK to measure battery voltage. See here using a voltage divider, but how would I do this using the mbed APIs?
I guess there should be API calls for using the ADC in mbed as well (I've never used it though). Using a divider that yields below 2.5V when battery is at 3V should be sufficient. So by just using the ADC on the divided battery voltage every now and then should suffice.
It looks from here and here that the analogIn API can only be configured to use the ADC input pins and reference VDD 1/3 prescaler. I would recommend to make your own init and read function with VBG reference and VDD/3 input:
void adc_init()
{
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
NRF_ADC->CONFIG = (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos) |
(ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) |
(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
(ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos) |
(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
}
uint16_t adc_read()
{
NRF_ADC->EVENTS_END = 0;
NRF_ADC->TASKS_START = 1;
while (!NRF_ADC->EVENTS_END) {
}
return (uint16_t)NRF_ADC->RESULT; // 10 bit
}
Correct me if some of this is wrong as I did not test it.
I found a couple examples that are similar to yours. Your version seems simpler. I'm not sure which one to use. They are all very similar. Which one do you think would work the best?