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

ADC read is not completeing

I'm working with an nrf51822 with the s110 softdevice. So I'm trying to read an analog signal from multiple pins. My program will run fine for quite some time. Eventually though for some reason the program gets caught up in the while loop of my get_adc function. So for some reason the adc is not completing its reading. I've seen a couple of other people with similar problems however I haven't found any solutions that worked. Below I've included my get_adc() function. I tried placing a delay between my configure and start as that was suggested however that didn't do the trick. Does anyone have any clue why the adc is not completing the read?

static uint16_t get_adc(uint8_t analogInput)
{
	uint16_t adc_result = 0;
	
	NRF_ADC->INTENSET = 0;   // disable interrupt
	NRF_ADC->EVENTS_END = 0;
  NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;    // Enable ADC
	
	// config ADC
	NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) 										/* Bits 17..16 : ADC external reference pin selection. */
									| (analogInput << ADC_CONFIG_PSEL_Pos)																				/*!< Use analog input X as analog input. */
									| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)														/*!< Use internal 1.2V bandgap voltage as reference for conversion. */
									| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) 	/*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
									| (ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos);																/*!< 8bit ADC resolution. */ 
	
	// start ADC conversion
	NRF_ADC->TASKS_START = 1;
	
	// wait for conversion to end
	while (!NRF_ADC->EVENTS_END) {};
	
	NRF_ADC->EVENTS_END = 0;
	
	// save results
	adc_result = NRF_ADC->RESULT;
	
	// stop ADC conversion to save power
	NRF_ADC->TASKS_STOP = 1;
		
	return adc_result;
}
Parents Reply Children
Related