uint16_t battery_adc_read_once(void) { uint32_t adc_result = 0; uint16_t batt_lvl_in_milli_volts=0; battery_start(); nrf_delay_ms(10); while( !(NRF_ADC->EVENTS_END) ) { nrf_delay_ms(10); } NRF_ADC->EVENTS_END = 0; adc_result = NRF_ADC->RESULT; NRF_ADC->TASKS_STOP = 1; #if DEBUG_UART_EN // DbgPrintf("adc_result:%d\r\n",adc_result); #endif //*batt_lvl_in_milli_volts = ((uint32_t)(ADC_RESULT_IN_MILLI_VOLTS(adc_result)) & 0xffff); batt_lvl_in_milli_volts = ((uint32_t)(ADC_RESULT_IN_MILLI_VOLTS(adc_result)) & 0xffff); #if DEBUG_UART_EN // DbgPrintf("milli_volts:%d\r\n",batt_lvl_in_milli_volts); #endif //when charging, battery voltage need adjust // if(charger_status()!= NoCharge) { //batt_lvl_in_milli_volts += BATTERY_VOLTAGE_ADJUSTMENT; // } return batt_lvl_in_milli_volts; }
/**@brief Battery measurement timer timeout handler. * * @details This function will be called each time the battery level measurement timer expires. * This function will start the ADC. * * @param[in] p_context Pointer used for passing some arbitrary information (context) from the * app_start_timer() call to the timeout handler. */ static void battery_level_meas_timeout_handler(void * p_context) { UNUSED_PARAMETER(p_context); battery_start(); }