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

problem with nrf51822 ADC

Hi to all,

i am developing a device that in it i need to measure voltage of battery to report percentage of battery to user, but the voltage that i measure with ADC is different with voltage that i measured with multi-meter, for example multi-meter say that voltage battery is 2.25v and ADC say vltage is 1.962v, or multi-meter say that voltage battery is 2.983v and ADC say voltage is 2.880v. i use the following setting to config ADC:

adc_config.reference  = NRF_ADC_CONFIG_REF_VBG;
adc_config.resolution = NRF_ADC_CONFIG_RES_8BIT;
adc_config.scaling    = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD;
nrf_adc_configure(&adc_config);

// Enable ADC interrupt
nrf_adc_int_enable(ADC_INTENSET_END_Msk);
err_code = sd_nvic_ClearPendingIRQ(ADC_IRQn);
APP_ERROR_CHECK(err_code);

err_code = sd_nvic_SetPriority(ADC_IRQn, 3);
APP_ERROR_CHECK(err_code);

err_code = sd_nvic_EnableIRQ(ADC_IRQn);
APP_ERROR_CHECK(err_code);

and when program receive the interrupt, i use the following code to convert ADC value to mili volt:

#define ADC_PRE_SCALING_COMPENSATION    3                                            /**< 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 ADC_REF_VOLTAGE_IN_MILLIVOLTS   1200                                         /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
#define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE) ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 255) * ADC_PRE_SCALING_COMPENSATION)


void ADC_IRQHandler(void)
{  
    if (nrf_adc_conversion_finished())
    {
    	uint8_t  adc_result;
    	uint16_t batt_lvl_in_milli_volts;
    	uint8_t  percentage_batt_lvl;
    
    	nrf_adc_conversion_event_clean();
    
    	adc_result = nrf_adc_result_get();
    	batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result);
    	bl = batt_lvl_in_milli_volts;
    }
}
i can not understand that what is wrong, there is any one that can give me a advice to solve this problem??  there is any way better for measuring the battery level instead of using ADC??

thanks for your responses 

Parents Reply Children
No Data
Related