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

Why Battery level is always 100?

static void adc_init(void)

{

/* Enable interrupt on ADC sample ready event*/		

NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   

sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  

sd_nvic_EnableIRQ(ADC_IRQn);

NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) 
		| (ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos)					
		| (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling << ADC_CONFIG_REFSEL_Pos)							
		| (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) 
		| (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos);									

/* Enable ADC*/
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;

}

void ADC_IRQHandler(void)

{

uint8_t adc_result;
	
    NRF_ADC->EVENTS_END = 0;	

ADC_Value = (NRF_ADC->RESULT)/255*100;

    NRF_ADC->TASKS_STOP = 1;

sd_clock_hfclk_release();

}

The result of this source is always 100.

The amount of the battery is falling but 100.

What is the problem?

I have connected the battery to the VTG and GND.

What part did wrong?

  • Hi, I think this depends on what battery you are using.

    If you see app_util.h, you'll see this block reference.

    /** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
    
    *
    *  @details The calculation is based on a linearized version of the battery's discharge
    *           curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
    *           is considered to be the lower boundary.
    *
    *           The discharge curve for CR2032 is non-linear. In this model it is split into
    *           4 linear sections:
    *           - 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)
    *
    *           These numbers are by no means accurate. Temperature and
    *           load in the actual application is not accounted for!
    *
    *  @param[in] mvolts The voltage in mV
    *
    *  @return    Battery level in percent.
    */
    

    As you see, the function

    static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
    

    returns results following the reference. The CR2032 is a coin cell.

    So if you use other batteries, the result would be quite different.

    In my case, I use a custom board attaching two AA batteries in series.

    So I also get 100% most of the time, unless the battery level has decreased dramatically.

    So in short,

    the program doesn't have problem. This depends on what battery you use.

    If you want to see the percentage drop from any Nordic App,

    how about connecting your kit or board to the power supply and switch the voltage level?

    Then you'll see the level dropping.

    -Regards, Mango922

  • Thank you for reply, Mango922

    Good. Thanks understood to.

    but I need a voltage higher than 4.5V

    If I need a voltage higher than 4.5V, Will always get 100 results?

    Result of My source is always 1023. (ADC 10bit)

    In this case, Do I need to use the PSEL??

    or PSEL also did the same results?

    3V is enough order to operate the nrf51822.

    But I uses the OLED, the OLED fit a lack of action.

  • Hi, since I do not know your schematic, my answer could not satisfy you.

    Aren't you using voltage regulator? The supply voltage should be 1.8~3.6V to the MCU (ref. nRF51822_PS v3.1).

    I'll make a guess that you are using 5V battery for your OLED and this battery is also an input for a

    3.3V regulator. Then always, the result will be 100 percent

    if you have inserted 5V (or 4.5V) to the ADC input.

    One more thing, I don't know why you are mentioning about PSEL.

    If you are not using the Nordic's SDK and coding by yourself and setting all the registers, I hope you

    should look at the datasheet (nRF51_Series_Reference_manual v3.0) .

    However, looks like you are using the API and the example codes right?

    Then I think there doesn't need many editing the code above.

  • You wrote in a comment to Mango922:

    but I need a voltage higher than 4.5V

    If I need a voltage higher than 4.5V, Will always get 100 results?

    Result of My source is always 1023. (ADC 10bit)

    Please read section 31.1.1 Set input voltage range in the nRF51 Series Reference manual. Here it is written:

    There are two rules to follow to find the maximum input voltage allowed on the AIN pins:

    1. The ADC should not be exposed to higher voltage than 2.4 V on an AIN pin after prescaling: Input voltage x prescaling = max. 2.4 V. 31 Analog to Digital Converter (ADC) Page 166
    2. A GPIO pin must not be exposed to higher voltage than VDD + 0.3 V, according to the Absolute maximum ratings from the nRF51x22 Product Specification.

    Also please read section 31.1.2 Using a voltage divider to lower voltage.

Related