This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Redbear BLE nano / CR2450 / Battery level

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

Parents
  • 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.

  • The first one is more or less the same, the second one also except for that it does the initialization (adc_init) every time.

Reply Children
No Data
Related