This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading Battery Level nrf52840

Hi

I want to measure the battery lithium, this battery is the principal source (3.7v 300mh), the maximum voltage is 4.2 when the charge is full,

i'm using this code for to read the analog input  y calculate the battery level 

this is for to init

void saadc_callback_handler(nrf_drv_saadc_evt_t const * p_event)
{
	
}	

void saadc_init(void)
{
	ret_code_t err_code;
	nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
	
	err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
	APP_ERROR_CHECK(err_code);
	
	err_code = nrfx_saadc_channel_init(0,&channel_config);
	APP_ERROR_CHECK(err_code);
	
}

i am using the voltage devisor R1=1k and R2 =10k 

int main(void)
{
   
	log_init();
	saadc_init();
	
	
	nrf_saadc_value_t adc_val;
	
	NRF_LOG_INFO("APPlication Started!!");
	
	
    while (1)
    {
      nrfx_saadc_sample_convert(0,&adc_val);
			
			valueVoltaje = (adc_val * 4.2f / 1024)*0.91;// 1.07  calculo del parametro a utilizar para captura de voltaje de la bateria
			porcentaje = (valueVoltaje/4.2f)*100;
	}

i have a problem with the voltage calculating, its not the same multimeter measurement  

i have no idea if  i need to change some parameter or where I can see other example

this is the circuit

thank you and regards

sorry my English is not good 

Parents Reply Children
No Data
Related