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;
}