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 Reply Children
  • 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.

  • I have now updated my previous reply to a working link, thank you for letting me know.
    The contents of the link is what I also pasted into my previous comment, namely that you still need to initialize the ADC.

    In the code you have shared you are only creating a default config structure, but you are not actually using it for anything.
    Please see the ADC Example from the SDK, to see how you may go about initializing the ADC.

    Best regards,
    Karl

  • Sorry but I am not able to get can you please directly write the for sampling 2 channel ADC, as i not that good in programming this, can you please write the code for my above shown example code for sampling 2 channel ADC

Related