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

  • Could you try to run the ADC example from the SDK that I referenced earlier, and see if you can get that up and running on your board?
    Please do, and try to understand what is being done in the examples code.

    In order to sample the 2 channels without using any timers or event handler, and with the default ADC and channel configuration, what you would have to add to your application might look something like this:

    #include "nrf_drv_adc.h"
    
    static const nrf_drv_adc_channel_t m_channel_config_1 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_1);
    static const nrf_drv_adc_channel_t m_channel_config_2 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2);
    
    static volatile nrf_adc_value_t sample_channel_1 = 0;
    static volatile nrf_adc_value_t sample_channel_2 = 0;
    
    static void adc_init(void)
    {
        ret_code_t err_code;
        nrf_drv_adv_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
        
        err_code = nrf_drv_adc_init(&config, NULL)
        APP_ERROR_CHECK(err_code);
    }
        
    static void user_adc_sample_channel_1(void)
    {
        nrf_drv_adc_sample_convert(&m_channel_config_1, &sample_channel_1);
    }
    
    static void user_adc_sample_channel_2(void)
    {
        nrf_drv_adc_sample_convert(&m_channel_config_2, &sample_channel_2);
    }
    
    


    The result will be placed in the global sample variables.
    Hope this is what you were looking for.

    For future reference I highly recommend reading up on the API Reference for the driver you intend on using, to gain a better understanding of the functions and modules you are trying to use.

    Best regards,
    Karl

  • I think there some misunderstanding nrf_adv_convert_single i didn't found any of reference in nrf SDK nrf_adc_convert_single if it is this then it takes only one argument i.e Analog i/p

    NRF_ADC_CONFIG_INPUT_1

    Please correct me i am missing some thing.

  • This i have done already  also once again done after your post but still the values are not updating, constant values are coming like 538,507 with load without load

  • Which pins are you connecting your load to? Are you certain that you are connecting to the right pins? - A connection diagram would be a good way to verify this.
    How have you measured the voltage, so that you know it does not correspond to the ADC raw output 538?
    What formula are you using to convert the raw ADC outputs to voltage?

    Best regards,
    Karl

Reply Children
  • I have BLE 400 Waveshare board i am connecting to AN0 pin and AN1 pin and giving 3.3v on that and also for checking connecting it to ground using 10 bit ADC which can give o/p as 2^10 i.e. upto 1024 certainly with or without i/p its giving same value, there is no formula i am using right now i just want some o/p but its giving the o/p as mentioned above queries.

  • Please verify that you are using the correct pins on the Waveshare board. Could you share with me the pinout of the waveshare board you are using, and how you are testing it?

    Akshay Khairkar said:
    i am connecting to AN0 pin and AN1 pin

    I assume you then have changed the code I provided earlier, to reflect this?
    Please share with me the code you are currently running.

    Akshay Khairkar said:
    10 bit ADC which can give o/p as 2^10 i.e. upto 1024 certainly with or without i/p its giving same value, there is no formula i am using right now i just want some o/p but its giving the o/p as mentioned above queries.

    I do not know what you mean by "o/p", but I agree that reading values in the 500 range using the 10-bit ADC configuration sounds strange.

    Best regards,
    Karl

  • Output (O/p) is nothing but value i am getting after reading ADC, I just want ADC to give me some values according to my input to AN0 or AN1 pin still i am not getting any values.Please suggest me if any other ways if available to read multichannel ADC values or tell me if it is hardware restriction

  • Akshay Khairkar said:
    value i am getting after reading ADC, I just want ADC to give me some values according to my input to AN0 or AN1 pin still i am not getting any values

    You are not giving me a lot to work with here, since you are not answering my questions.
    Please, take a look at what I asked about in my previous reply, and answer the questions I wrote you.
    I require more information in order to help you resolve this issue.

    Akshay Khairkar said:
    or tell me if it is hardware restriction

    I assure you there are no hardware restrictions on reading multiple channels of the ADC. Do not worry, the issue here is not hardware restrictions.

    Best regards,
    Karl

  • static nrf_drv_adc_channel_t m_channel_config_0 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_0);
    static nrf_drv_adc_channel_t m_channel_config_1 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_1);
    
    static  nrf_adc_value_t sample_channel_0 = 0;
    static  nrf_adc_value_t sample_channel_1 = 0;
    
    static void adc_init(void)
    {
        ret_code_t err_code;
        nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
        
        err_code = nrf_drv_adc_init(&config, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    //Error Code:H1600
    void user_adc_init0(){
             nrf_drv_adc_sample_convert(&m_channel_config_0, &sample_channel_0);
      
             nrf_delay_ms(1000);
    
             printf("\r\n  0 :%d\r\n",sample_channel_0);
       
    }
    //Error Code:H1700
    void user_adc_init1(){
       
       
          nrf_drv_adc_sample_convert(&m_channel_config_1, &sample_channel_1);
       
            printf("\r\n  1 : %d\r\n",sample_channel_1);
    }
    int main(void)
    {
    
    adc_init();
    for (;;)
        {
          printf("\r\n for Start!\r\n");
          user_adc_init0();
          nrf_delay_ms(100);
          user_adc_init1();
          nrf_delay_ms(100);
          nrf_delay_ms(2000);
          printf("\r\nADC fin!\r\n");
          
          printf("\r\n  0 :%d\r\n",sample_channel_0);
          printf("\r\n  1 : %d\r\n",sample_channel_1);
          
         }
    }
    
    

Related