Calculating battery remaining capacity


I am currently working on calculating a Li-ion battery;s remaining capacity. As far as I know, I should read the raw value via SAADC. then convert the value back to voltage and calculate with the battery's discharging settings. From the SAADC_LOW_POWER example, I have managed to successfully read values from VDD and print it to my terminal. However, the values that I was getting was quite different from the readings on my voltage meter.

After I plugged in my Li-ion battery to the board, I was getting between 880 to 900 from the adc. From the nRF52832 guide, page 353, the digital output from SAADC can be calculated back to voltage. Converting back to voltage will be 900* (1/6)/(0.6) * 2^10 = 3.16V (the voltage input n was disabled from my code). But my battery was outputting 3.9V measured from a voltage meter. I have also noticed that after I unplug my battery, the VDD value did not decreased to 0 but showing value 814(about 2.86V).

I am now confused of how to measure battery voltage from my nRF52 Development Kit. Is there anything I am missing or I am on a completely wrong track?

Here are some code from my program:

1. SAADC settings:

    saadc_config.low_power_mode = true;                                                   
    saadc_config.resolution = NRF_SAADC_RESOLUTION_10BIT;                             
    saadc_config.oversample = SAADC_OVERSAMPLE;                                       
    saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;                           
    //Initialize SAADC
    err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);                     
    //Configure SAADC channel
    channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;                            
    channel_config.gain = NRF_SAADC_GAIN1_6;                                            
    channel_config.acq_time = NRF_SAADC_ACQTIME_10US;                                   
    channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;                                  
    channel_config.pin_p = NRF_SAADC_INPUT_VDD;                                         
    channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;                                    
    channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;                            
    channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;

2.  Code of converting ADC raw value to voltage:

int16_t raw_res = p_event->data.done.p_buffer[i];// Raw result from ADC
float true_voltage = raw_res * 3.6 / 1024;

No Data
Reply Children