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

Battery volatge Problem in nrf51822

hi, In my setup, I have a 3.7 V battery divided down to the bandgap range using a 100k and 100k resistors, so the voltage at the ADC input is 3.7 * (100/200) = 1.85 V. I am getting constant high voltage. can any suggest me plz? Details of the code given below:

void ADC_Config(void)
{

  NRF_ADC->CONFIG = (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos)
  | (ADC_CONFIG_PSEL_AnalogInput0 << ADC_CONFIG_PSEL_Pos) 	  /*!< Use analog input 0 */
  | (ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling  << ADC_CONFIG_REFSEL_Pos)	/*!< Use Supply voltage with prescale value of 1/2 as reference for ADC conversion. */
  | (ADC_CONFIG_INPSEL_AnalogInputNoPrescaling << ADC_CONFIG_INPSEL_Pos) 	/*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
  | (ADC_CONFIG_RES_10bit 	    << ADC_CONFIG_RES_Pos); 	 /*!< 10bit ADC resolution. */


}



float ADC_MONITOR(void)
{
unsigned int adc_result;
float adc_voltage = 0;
batt_level=0;
NRF_ADC->ENABLE = 1; /* Bit 0 : ADC enable. */

NRF_ADC->EVENTS_END=0;	/*End conversion before sampling*/

NRF_ADC->TASKS_START = 1;/* start ADC conversion*/


while (!NRF_ADC->EVENTS_END) /*wait for conversion to end*/
{
}


adc_result=0;
adc_result = NRF_ADC->RESULT;
nrf_delay_ms(50);

adc_voltage=(float)((adc_result*1.8*2)/(1023.0));/*calculate the voltage after getting result*/


batt_level = adc_voltage;	
NRF_ADC->TASKS_STOP = 1;	
 NRF_ADC->ENABLE = 0;	
return batt_level;
	}
Parents
  • Hello Rahul Sahu

    You have set your prescaling to 1 and your reference to VDD/2. If you see table 311, page 165 of the nRF51 series reference manual you will see that with those settings the ADC will have a range of 0-1.5 V. Your battery voltage is therefore outside the ADC's range and the result will always return as maximum. You will either have to change the ADC settings, or reduce the AIN voltage. I recommend you read this blogpost for guidance on battery measurements using the ADC of the nRF51.

    Best regards

    Jørn Frøysa

Reply
  • Hello Rahul Sahu

    You have set your prescaling to 1 and your reference to VDD/2. If you see table 311, page 165 of the nRF51 series reference manual you will see that with those settings the ADC will have a range of 0-1.5 V. Your battery voltage is therefore outside the ADC's range and the result will always return as maximum. You will either have to change the ADC settings, or reduce the AIN voltage. I recommend you read this blogpost for guidance on battery measurements using the ADC of the nRF51.

    Best regards

    Jørn Frøysa

Children
Related