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

Use AREF1(pin0.06) as analog reference voltage for ADC instead of internal VBG

Dear Sir: Could I use the external reference AREF1(pin0.06) instead of internal VBG 1.2V for ADC operation ? I do the following settings to config using external reference

   nrf_adc_config.resolution = NRF_ADC_CONFIG_RES_10BIT;
   nrf_adc_config.scaling = NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE;
   nrf_adc_config.reference = NRF_ADC_CONFIG_REF_EXT_REF1;

But it doesn't work, is there any other settings before using external reference for ADC.

Thanks a lot

Parents
  • Hi,

    I will assume you are using nRF51. Essentially you will need to configure EXTREFSEL with AREF1 and REFSEL with External. Something like this should work (I use hardware registers by preference).

    static void adc_init(void)
    {	
    	/* Enable interrupt on ADC sample ready event*/		
    	NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
    	sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
    	sd_nvic_EnableIRQ(ADC_IRQn);
    	
    	NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_AnalogReference1 << ADC_CONFIG_EXTREFSEL_Pos) /* Bits 17..16 : ADC external reference pin selection. */
    					| (ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos)					     /*!< Use analog input 2 as analog input. */
    					| (ADC_CONFIG_REFSEL_External << ADC_CONFIG_REFSEL_Pos)					     /*!< Use external 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_10bit << ADC_CONFIG_RES_Pos);							     /*!< 8bit ADC resolution. */ 
    	
    	/* Enable ADC*/
    	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    }
    

    This answer also contains some useful information.

    Best regards,

    Øyvind

  • Yes, I try to change ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling to ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, but the voltage I read is also larger than 1.0V. The "previous code "you mentioned is my own code ? Yes, I can get value by the following code

    void mp_adc_config(void)
    {    
        nrf_adc_config_t nrf_adc_config = NRF_ADC_CONFIG_DEFAULT;
    
    		nrf_adc_config.resolution = NRF_ADC_CONFIG_RES_10BIT;
    		nrf_adc_config.scaling = NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE;
    		nrf_adc_config.reference = NRF_ADC_CONFIG_REF_EXT_REF1;
    
        nrf_adc_configure( (nrf_adc_config_t *)&nrf_adc_config);
    
        nrf_adc_int_enable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);  /*!< Interrupt enabled. */
        NVIC_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_HIGH);   //Configure the priority
        NVIC_EnableIRQ(ADC_IRQn);
    	
    		mp_adc_init();
    
    		nrf_adc_input_select(g_mpADC[MP_ADC_INDEX_TEMP].channel);
    }
    
Reply
  • Yes, I try to change ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling to ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, but the voltage I read is also larger than 1.0V. The "previous code "you mentioned is my own code ? Yes, I can get value by the following code

    void mp_adc_config(void)
    {    
        nrf_adc_config_t nrf_adc_config = NRF_ADC_CONFIG_DEFAULT;
    
    		nrf_adc_config.resolution = NRF_ADC_CONFIG_RES_10BIT;
    		nrf_adc_config.scaling = NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE;
    		nrf_adc_config.reference = NRF_ADC_CONFIG_REF_EXT_REF1;
    
        nrf_adc_configure( (nrf_adc_config_t *)&nrf_adc_config);
    
        nrf_adc_int_enable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);  /*!< Interrupt enabled. */
        NVIC_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_HIGH);   //Configure the priority
        NVIC_EnableIRQ(ADC_IRQn);
    	
    		mp_adc_init();
    
    		nrf_adc_input_select(g_mpADC[MP_ADC_INDEX_TEMP].channel);
    }
    
Children
No Data
Related