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

ADC reading problem on nrf51

Hi,

I would like to read and update value of the characteristic received from AD pin AIN0. I already tested the following code, where I got very weird results (value is approximately 0x01EE all the time). The code was tested on PCA10005 board. I used AIN0 (NRF_ADC_CONFIG_INPUT_0) channel for data acquisition. Is it possible that defined NRF_ADC_CONFIG_INPUT_0 does not correspond with AIN0 pin on the PCA10005 board?

Many thanks for your help in advance.

      static void adc_configure(void)
    {	
    		
    	ret_code_t err_code = nrf_drv_adc_init(NULL, adc_event_handler);
    	 APP_ERROR_CHECK(err_code);	 
        //channel.config.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD;
    	 
    	static nrf_drv_adc_channel_t 	 adc_1   = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_0);
    	adc_1.config.config.input = (uint32_t)NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE ;
    	 nrf_drv_adc_channel_enable(&adc_1);
    		
    	err_code = nrf_drv_adc_buffer_convert(&adc_1_buf,1);	
    	APP_ERROR_CHECK(err_code);	 	 
    }
    


     static void adc_timer_handler(void * p_context)
        { 
        	
        	
        	nrf_drv_adc_sample();
        	
        	
        }

void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
{
	
	 if(p_event->type == NRF_DRV_ADC_EVT_DONE)
	 {
		 nrf_adc_value_t  adc_result;
		 uint32_t 				err_code;	 

		 
		 adc_result = p_event->data.done.p_buffer[0];
		 
		 err_code = nrf_drv_adc_buffer_convert(p_event->data.done.p_buffer,1);
		 
	   err_code = ble_adcs_1_update(&m_adcs,adc_result);
	 }
	
	
}
Parents
  • AIN0 (P0.26/XL2) is one of the pins used for 32kHz crystal (the other is AIN1/P0.27/XL1). As described in the user guide part 5.1.7, pin header P4 decides if a crystal is used or AIN0/AIN1. Adding the picture here for easier access:

    image description

    The jumper should be placed between 3 and 5.

    Also note that you are using VBG as reference which will saturate at 1.2V, so the voltage you are reading have to be lower than that or you have to use scaling (or else you are saturating), See here.

Reply
  • AIN0 (P0.26/XL2) is one of the pins used for 32kHz crystal (the other is AIN1/P0.27/XL1). As described in the user guide part 5.1.7, pin header P4 decides if a crystal is used or AIN0/AIN1. Adding the picture here for easier access:

    image description

    The jumper should be placed between 3 and 5.

    Also note that you are using VBG as reference which will saturate at 1.2V, so the voltage you are reading have to be lower than that or you have to use scaling (or else you are saturating), See here.

Children
No Data
Related