Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading ADC with a double buffer

Hi,

I have a question about ADC reading in ble_app_uart__saadc_timer_driven__scan_mode in SDK 14.

Let's say I'm using a double buffer, and I have 3 ADC channels (so SAADC_SAMPLES_IN_BUFFER=3)

Now I look in p_event->data.done.p_buffer[ i ] . Is the following correct:

p_event->data.done.p_buffer[ 0 ] => Value of channel 0

p_event->data.done.p_buffer[ 1 ] => Value of channel 1

p_event->data.done.p_buffer[ 2 ] => Value of channel 2

I'm not sure because somehow I'm reading almost the same data from [0] and [2], and [1] is about x2 of the other too.

Data example:

201 420 201
199 418 201
201 416 199
201 414 200
199 413 196
194 409 195
197 413 197
198 414 196
195 410 192
197 413 199
198 416 196
198 417 199
197 413 198
200 415 197
200 417 198
197 415 197
196 410 195
196 409 194
195 411 194
200 415 199

Can you assist please?

Thanks

  • Hello,

    Do you have 3 different gpios measureing these values? Are they connected/shorted to anything? Or do you have one input GPIO, and it stores the values into three different sections in the buffer?

     

    Best regards,

    Edvin

  • 3 different GPIOS (AIN0, AIN1, AIN2). And here's the initialization:

        nrf_saadc_channel_config_t channel_0_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
        channel_0_config.gain = NRF_SAADC_GAIN1_6;
        channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
        nrf_saadc_channel_config_t channel_1_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
        channel_1_config.gain = NRF_SAADC_GAIN1_6;
        channel_1_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
        nrf_saadc_channel_config_t channel_2_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
        channel_2_config.gain = NRF_SAADC_GAIN1_6;
        channel_2_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
        err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(1, &channel_1_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(2, &channel_2_config);
        APP_ERROR_CHECK(err_code);

    I just disabled OVERSAMPLING and now it's working well. Each channel looks independent now. Is there a way to make it work with oversampling enabled? Why would oversampling (of 4x) cause this behavior?

    Thanks

  • Oversampling should not cause a higher value. When the error occured, did you have oversampling on all the channels, or only one of them? And in addition to oversampling, was the rest of the channel_config settings the same?

     

    Best regards,

    Edvin

  • Hi Edvin,

    Yes, channel_config settings for 0,1,2 were the same like appears in the code I posted.

    And about oversampling, I just changed the variable SAADC_CONFIG_OVERSAMPLE in sdk_config.h to 2. Do I have to do anything else to turn it on correctly?

    Thanks!

  • Did you measure the same source with all three pins, or was channel 1 measuring something else?

     

    What chip do you use? nRF52832 or nRF52840?

    And you say that you used SDK14. Is that SDK14.0.0, SDK14.1.0 or SDK14.2.0?

     

    BR,

    Edvin

Related