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

  • 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

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

Reply Children
Related