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

  • 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);
          
         }
    }
    
    

  • So here is my code for sampling 2 ADC channels and just printing the values of ADC, i just want ADC to give me values in printf statement according to the i/p like if i am giving  some voltages over this maybe between 1.0V to 3.3v so i should get the values according to voltage i.e.in between 0 - 1024 , but the values  i am getting are not changing i.e with or without input i am getting same values.

  • Akshay Khairkar said:
    i.e with or without input i am getting same values.

    And what values are these? What is this program outputting? You need to tell me what is happening.
    You need to give me all the available information, so that I may best help you.

    I see from your code that you have changed the sample_channel_* variable types from static volatile in the code I provided you earlier. Why have you done this?
    If they are not declared as volatile then the compiler will optimize them to a constant value of 0.

    By omitting such details, or making changes without telling me, you are making it very hard to help you.

    In the future, please write out your problem description, symptoms and goals as clearly as possible in order for others to be able to help you.
    This will reduce the time it takes for you to receive help, and the time it takes to give this help.

    Please try to change the samples' type back to static volatile, and let me know what you observe when running the program.

    Best regards,
    Karl

  • Values i am getting 528 or 536 in printf statement as already told to you in the conversation.

    Yeah, in future i will do so I thought that was sufficient to be understandable.

    If i am making it volatile compiler giving me error which is as below

    error: passing argument 2 of 'nrf_drv_adc_sample_convert' discards 'volatile' qualifier from pointer target type [-Werror=discarded-qualifiers]
    644 | nrf_drv_adc_sample_convert(&m_channel_config_0, &sample_channel_0);
    | ^~~~~~~~~~~~~~~~~
    In file included from main.c:68:
    components/drivers_nrf/adc/nrf_drv_adc.h:234:57: note: expected 'nrf_adc_value_t *' {aka 'short int *'} but argument is of type 'volatile nrf_adc_value_t *' {aka 'volatile short int *'}
    234 | nrf_adc_value_t * p_value);
    | ~~~~~~~~~~~~~~~~~~^~~~~~~
    cc1: all warnings being treated as errors
    make: *** [components/toolchain/gcc/Makefile.common:135: _build/nrf51422_xxac_main.c.o] Error 1

    I am using visual studio for programming

  • Akshay Khairkar said:
    Values i am getting 528 or 536 in printf statement as already told to you in the conversation.

    Thank you for clarifying, this is hard for me to know when you are not being specific and saying things like "not getting any values".

    I would not expect values in the 500 range when the pins are connected to either ground or VDD, I therefore suspect that these pins either is used for something else on the waveboard, or that you are connecting the wrong pins.

    Could you please share the datasheet and pinout of the waveboard device you are working with?
    Please also specify exactly which pins you are using on the board - do not say AIN0 and AIN1, unless they are marked as such on the board itself.

    Akshay Khairkar said:
    Yeah, in future i will do so I thought that was sufficient to be understandable.

    Thank you, I appreciate it.

    Looking forward to resolving this issue together,

    Best regards,
    Karl

Reply
  • Akshay Khairkar said:
    Values i am getting 528 or 536 in printf statement as already told to you in the conversation.

    Thank you for clarifying, this is hard for me to know when you are not being specific and saying things like "not getting any values".

    I would not expect values in the 500 range when the pins are connected to either ground or VDD, I therefore suspect that these pins either is used for something else on the waveboard, or that you are connecting the wrong pins.

    Could you please share the datasheet and pinout of the waveboard device you are working with?
    Please also specify exactly which pins you are using on the board - do not say AIN0 and AIN1, unless they are marked as such on the board itself.

    Akshay Khairkar said:
    Yeah, in future i will do so I thought that was sufficient to be understandable.

    Thank you, I appreciate it.

    Looking forward to resolving this issue together,

    Best regards,
    Karl

Children
No Data
Related