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

Multichannel use of ADC in NRF51822

I want to measure voltages at all 8 channels but when I am enabling all channels its sending the values once only and after that its not sending anything, my requirement is i don't want to use any handler,i am using polling method simultaneously to sample ADC,please suggest if any code available or any support message for the same.

Parents
  • Yes I want to sample all 8 channels, continuously without using  handler,I want to prefer sampleconvert() func because there is need afterwards, ii am not using any timer and don't want use it. I just want to sample all ADC pins continuously.

  • Akshay Khairkar said:
    Yes I want to sample all 8 channels, continuously without using  handler,I want to prefer sampleconvert() func because there is need afterwards, ii am not using any timer and don't want use it. I just want to sample all ADC pins continuously.

    This means that you will have to reconfigure for every channel, and call the sample function in a loop.
    Which SDK version are you using?

    I understand that you do not want to use a handler or a timer, but is there a particular reason for this? Your general application performance might be considerably worse if you do nothing to time or otherwise control when and how fast the samplings happen - but you are of course free to do so.

    Best regards,
    Karl

Reply
  • Akshay Khairkar said:
    Yes I want to sample all 8 channels, continuously without using  handler,I want to prefer sampleconvert() func because there is need afterwards, ii am not using any timer and don't want use it. I just want to sample all ADC pins continuously.

    This means that you will have to reconfigure for every channel, and call the sample function in a loop.
    Which SDK version are you using?

    I understand that you do not want to use a handler or a timer, but is there a particular reason for this? Your general application performance might be considerably worse if you do nothing to time or otherwise control when and how fast the samplings happen - but you are of course free to do so.

    Best regards,
    Karl

Children
  • Yes will need to reconfigure every time.

    I will be modifying afterwards but right now I want to do this only.

    I am using SDK12.3.0 

  • Akshay Khairkar said:

    Yes will need to reconfigure every time.

    I will be modifying afterwards but right now I want to do this only.

    Great, then we are on the same page on this. Using the driver might be easier for you, but then you will have to use an event handler. Please see the nrf_drv_adv_sample function documentation.

    Akshay Khairkar said:
    I am using SDK12.3.0 

    Then you will probably want to use the nrf_adc_convert_single function directly.

    Best regards,
    Karl

  • void user_adc_init0(){
        printf("\r\nIn ADC0\r\n");
        //if(count==0)
       // {
        // static nrf_drv_adc_channel_t channel0 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_0);
        // nrf_drv_adc_channel_enable(&channel0);
         //res=nrf_drv_adc_sample_convert(&channel0,&adc_val[0]);
         
         
         res=nrf_adc_convert_single 	( NRF_ADC_CONFIG_INPUT_1) 	;
         nrf_delay_ms(100);
         
         
        // NRF_ADC->TASKS_STOP = 1;=
       //  nrf_drv_adc_channel_disable(&channel0);
        
        // NRF_ADC->CONFIG &= (~ADC_CONFIG_PSEL_Msk);
         //nrf_adc_stop();
    
         count=1;
        //}
       
    }
    //Error Code:H1700
    void user_adc_init1(){
       
        //if(count==1)
        //{
            //static nrf_drv_adc_channel_t channel1 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_1);
           // nrf_drv_adc_channel_enable(&channel1);
          //  nrf_drv_adc_sample_convert(&channel1,&adc_val[1]);
          
          
            res=nrf_adc_convert_single 	( NRF_ADC_CONFIG_INPUT_1) 	;
            nrf_delay_ms(100);
            
            
            //NRF_ADC->CONFIG &= (~ADC_CONFIG_PSEL_Msk);
           // count=0;
           // nrf_adc_stop();
    
        /// }
        // nrf_drv_adc_channel_disable(&channel0);
    }
    
    int main(void)
    {
        uint32_t err_code;
        bool erase_bonds;
    
        // Initialize.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        uart_init();
    
        buttons_leds_init(&erase_bonds);
        ble_stack_init();
        gap_params_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        printf("\r\nUART Start!\r\n");
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    
        // Enter main loop.
        for (;;)
        {
          printf("\r\n for Start!\r\n");
          user_adc_init0();
          nrf_delay_ms(100);
          user_adc_init1();
          nrf_delay_ms(100);
          /*user_adc_init2();
          nrf_delay_ms(100);
          user_adc_init3();
          nrf_delay_ms(100);
          user_adc_init4();*/
          nrf_delay_ms(2000);
              printf("\r\nADC fin!\r\n");
    
    

    This is the code I am working on as per your instructions tried  nrf_adc_convert_single still result is coming 0,0 while giving signal also.

  • Please read the function documentation, it states:

    This function selects the desired input, starts a single conversion, waits for it to finish, and returns the result. After the input is selected, the analog-to-digital converter is left in STOP state. The function does not check if the ADC is initialized and powered.

    You will still need to initialize and configure the ADC peripheral. From the provided code, it seems you do not do this.

    For future reference, please remove all commented out code if it serves no purpose for what you would like us to have a look at, it drastically decreases the readability of your code. If you are "keeping it for later", then I would recommend making use of a separate file to store this code.

    Best regards,
    Karl

  • nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;

    void user_adc_init0(){
    printf("\r\nIn ADC0\r\n");
    res=nrf_adc_convert_single ( NRF_ADC_CONFIG_INPUT_0) ;
    nrf_delay_ms(100);
    printf("\r\n 0 :%ld\r\n",res);

    }
    //Error Code:H1700
    void user_adc_init1(){
    res=nrf_adc_convert_single ( NRF_ADC_CONFIG_INPUT_1) ;
    nrf_delay_ms(100);
    printf("\r\n 1 : %ld\r\n",res);
    }

    Sorry for the inconvenience caused earlier,can you please suggest me is there anything else required for initialization of ADC,as the Link you have provided is not working.

Related