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

Using two ADC channel with interrupt

Hi! I would like to get adc sample from two different channels at the same time on my beacon (nrf1822), using the same interrupt. Is that possible?I mean I can use ADC_IRQhandler function for both conversion?If yes how can I write it in the code?Thank you

Parents
  • You can only sample one channel at the time. You will have to do the two conversions one after another and read the result and change the config register in between. The same interrupt will be used for both conversions.

    The time for one conversion is 20, 36 or 68 us depending on the bit mode (8, 9 or 10 bits), see Product Specification chapter 8.12.

  • I think I am doing some basic errors, because I have a timer that counts 2ms and then it starts the adc conversion and between the conversion of the two channel I don't want to start the timer.This is my piece of code, can you help me to find what doesn't work?

    void ADC_IRQHandler(void)
    {
    	/* Clear dataready event */
      NRF_ADC->EVENTS_END = 0;	
    	
    	//Invio a pacchetti di 20 bytes (ogni dato in uscita dall'adc è 2byte)
    	static uint8_t i=0;                 //usiamo static per evitare che modifichi il valore della variabile
    	static uint16_t adc_results[10];    
    		if (i<10)	
    {		
    			adc_results[i]=NRF_ADC->RESULT;
    			i=i+1;
    	NRF_ADC->TASKS_STOP = 1;
    	NRF_ADC->CONFIG=(ADC_CONFIG_PSEL_AnalogInput3 << ADC_CONFIG_PSEL_Pos);
    	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    	NRF_ADC->TASKS_START = 1;	
    	while (!NRF_ADC->EVENTS_END)
    	{}
    	NRF_ADC->EVENTS_END	= 0;
    	adc_results[i]=NRF_ADC->RESULT;
    		NRF_ADC->CONFIG=(ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos);
    			i=i+1;
    }
     NRF_ADC->TASKS_STOP = 1;
    	
    	//Release the external crystal
    	sd_clock_hfclk_release();
    }
    
Reply
  • I think I am doing some basic errors, because I have a timer that counts 2ms and then it starts the adc conversion and between the conversion of the two channel I don't want to start the timer.This is my piece of code, can you help me to find what doesn't work?

    void ADC_IRQHandler(void)
    {
    	/* Clear dataready event */
      NRF_ADC->EVENTS_END = 0;	
    	
    	//Invio a pacchetti di 20 bytes (ogni dato in uscita dall'adc è 2byte)
    	static uint8_t i=0;                 //usiamo static per evitare che modifichi il valore della variabile
    	static uint16_t adc_results[10];    
    		if (i<10)	
    {		
    			adc_results[i]=NRF_ADC->RESULT;
    			i=i+1;
    	NRF_ADC->TASKS_STOP = 1;
    	NRF_ADC->CONFIG=(ADC_CONFIG_PSEL_AnalogInput3 << ADC_CONFIG_PSEL_Pos);
    	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    	NRF_ADC->TASKS_START = 1;	
    	while (!NRF_ADC->EVENTS_END)
    	{}
    	NRF_ADC->EVENTS_END	= 0;
    	adc_results[i]=NRF_ADC->RESULT;
    		NRF_ADC->CONFIG=(ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos);
    			i=i+1;
    }
     NRF_ADC->TASKS_STOP = 1;
    	
    	//Release the external crystal
    	sd_clock_hfclk_release();
    }
    
Children
No Data
Related