Hello,
I am using 10 bit ADC read VDD voltage convert into mv without using any external voltage divider circuit, as per following function:
static void adc_configure_battery(void) { ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler); APP_ERROR_CHECK(err_code);
nrf_saadc_channel_config_t config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
err_code = nrf_drv_saadc_channel_init(3, &config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(&adc_battery_buf[0], 1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(&adc_battery_buf[1], 1);
APP_ERROR_CHECK(err_code);
}
And following function is use for conversion battery mv into percentage:
/* - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
-
- Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
-
- Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
-
- Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)*/
static uint8_t battery_level_in_percentage(const uint16_t mvolts) { uint8_t battery_level;
if (mvolts >= 3000)
{
battery_level = 100;
}
else if (mvolts > 2900)
{
battery_level = 100 - ((3000 - mvolts) * 58) / 100;
}
else if (mvolts > 2740)
{
battery_level = 42 - ((2900 - mvolts) * 24) / 160;
}
else if (mvolts > 2440)
{
battery_level = 18 - ((2740 - mvolts) * 12) / 300;
}
else if (mvolts > 2100)
{
battery_level = 6 - ((2440 - mvolts) * 6) / 340;
}
else
{
battery_level = 0;
}
return battery_level;
}
But problem is when i measure battery volatge it get sometime 58% sometime 70% means its variation in battery percentage. So how i can stable this battery percentage and i need this percentage is decrease as per battery voltage drain. So please suggest me any specific formula for AA battery. I am using two AA battery for my device is 1.5*2= 3V.