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

battery level percentage for nrf52832

I am new to nrf52832. I am using pcaboard10040 ,sdk12.3.0 and softdevice s132. I am using  battery_level_in_percent function for calculating percentage level of battery. But every time I got 100% level on nrfconnect app.But actual voltage I measured on multimeter is 2.6v

Thanks in Advance.

Parents
  • Hi

    Is the board connected to a USB cable as well as the battery? In that case the input voltage on the boardwill be over 3V which causes the function to always show 100% battery voltage, as the function takes values from the boards voltages and not the battery directly. 

    If this does not solve your problem you have to specify what you mean by sending battery status in manufacturing specific data, as it is not clear what you do here.

    Best regards,

    Simon

  • I am just reading battery status using battery_level_in_percent and send it one of field of manufacturing specific data.

  • Which kind of manuf_specific_data are you referring to? Is it in a BLE service/characteristic, or in your advertising data?

    Best regards,

    Simon

  • Hi,

    {len, datatype, data}

    {0x02, 0xFF,   0x64}

    This is my packet through which i am sending updated battery status using battery_level_in_percent api, no external power is used, nrf is running only on battery CR 2032 3v. 

    code snippet for battery calculation as following.

    
    #define ADC_REF_VOLTAGE_IN_MILLIVOLTS     600                                          /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
    #define ADC_PRE_SCALING_COMPENSATION      6                                            /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
    #define DIODE_FWD_VOLT_DROP_MILLIVOLTS    270                                          /**< Typical forward voltage drop of the diode that is connected in series with the voltage supply. This is the voltage drop when the forward current is 1mA. Source: Data sheet of 'SURFACE MOUNT SCHOTTKY BARRIER DIODE ARRAY' available at www.diodes.com. */
    #define ADC_RES_8BIT                     255   
    
    #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
            ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / ADC_RES_8BIT) * ADC_PRE_SCALING_COMPENSATION)
    
    void battery_level_get_callback(nrf_drv_saadc_evt_t const * p_event)
    {
    				nrf_saadc_value_t adc_result;
            uint16_t          batt_lvl_in_milli_volts;
           
    			
            adc_result = p_event->data.done.p_buffer[0];
    
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
    
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
            
    				batt_lvl_in_milli_volts=ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                                      DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    			
    				percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts);
    			
    			
    				nrf_drv_saadc_uninit();
            NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
            NVIC_ClearPendingIRQ(SAADC_IRQn);
        }
    }
    
    
    
    void saadc_init(void)
    {
        ret_code_t err_code;
    	  err_code = nrf_drv_saadc_init(NULL, battery_level_get_callback);
        APP_ERROR_CHECK(err_code);
    	
        nrf_saadc_channel_config_t channel_config 
            = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
    
       
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    	
    		
    }
    

Reply
  • Hi,

    {len, datatype, data}

    {0x02, 0xFF,   0x64}

    This is my packet through which i am sending updated battery status using battery_level_in_percent api, no external power is used, nrf is running only on battery CR 2032 3v. 

    code snippet for battery calculation as following.

    
    #define ADC_REF_VOLTAGE_IN_MILLIVOLTS     600                                          /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
    #define ADC_PRE_SCALING_COMPENSATION      6                                            /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
    #define DIODE_FWD_VOLT_DROP_MILLIVOLTS    270                                          /**< Typical forward voltage drop of the diode that is connected in series with the voltage supply. This is the voltage drop when the forward current is 1mA. Source: Data sheet of 'SURFACE MOUNT SCHOTTKY BARRIER DIODE ARRAY' available at www.diodes.com. */
    #define ADC_RES_8BIT                     255   
    
    #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
            ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / ADC_RES_8BIT) * ADC_PRE_SCALING_COMPENSATION)
    
    void battery_level_get_callback(nrf_drv_saadc_evt_t const * p_event)
    {
    				nrf_saadc_value_t adc_result;
            uint16_t          batt_lvl_in_milli_volts;
           
    			
            adc_result = p_event->data.done.p_buffer[0];
    
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
    
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
            
    				batt_lvl_in_milli_volts=ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                                      DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    			
    				percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts);
    			
    			
    				nrf_drv_saadc_uninit();
            NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
            NVIC_ClearPendingIRQ(SAADC_IRQn);
        }
    }
    
    
    
    void saadc_init(void)
    {
        ret_code_t err_code;
    	  err_code = nrf_drv_saadc_init(NULL, battery_level_get_callback);
        APP_ERROR_CHECK(err_code);
    	
        nrf_saadc_channel_config_t channel_config 
            = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
    
       
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    	
    		
    }
    

Children
No Data
Related