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

SAADC not as expected

I'm trying to sample ADC signal using 12 bit ADC resolution, but the digital signal doesn't match the original one seen in the Oscilloscope.

Here are my ADC configurations:

saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;

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;

and sample rate = 250ms.

Here is the signal measured in Oscilloscope (20.5 seconds):

scope

And here is the digital signal (same 20.5 seconds):

What could be causing these huge differences? I'm expecting to see a sinus-like wave but all I'm seeing is noise.

Can you tell me please what is the optimal configuration for my design? Particularly, gain, reference voltage, etc.

Also, I see that the only options for the reference voltage are 1/4 and 0.6 ("internal"). Isn't there an option to leave it as is? i.e. as it is applied to the BLE on the hardware level?

Please note that the signal is hardware-amplified outside the module, and the input signal as in the first image above is between 0-3V.

Thanks

  • Problem solved by oversampling 4x.

    Changed SAADC_CONFIG_OVERSAMPLE from 0 to 2 in file sdk_config.h of ble_app upart.

    Also I changed sample rate to 100ms to make it faster...

    Here's the new sampling graph:

    digital with oversampling

  • Hi Alaa, I'm actually working on the SAADC of the nRF52, in the SDK 15.0.

    Could you share with me the screen page of all the ADC configuration that you've made, because I don't know how to configure the Gain et the Resolution of my ADC,Thank you.

  • Hi,
    I'm using SDK 14 and I'm using the configurations that appear in the ble_app_uart__saadc_timer_driven__scan_mode example here:
    https://github.com/NordicPlayground/nRF52-ADC-examples
    Here's my init function:

    void saadc_init(void)
    {
        ret_code_t err_code;
    	
        nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
        saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    	
        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_4;
        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_4;
        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);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);   
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }

    SAADC_SAMPLES_IN_BUFFER is 3 because I need to sample 3 ADC channels. You should adjust accordingly.

    Also note the SAADC configurations in the sdk_config.h file (SAADC_ENABLED 1 , etc.)

    About the resolution, there are 2 places:

    1. in sdk_config.h: SAADC_CONFIG_RESOLUTION 2 //2 means 12 bit

    2. in the saadc_init() function above: saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT

    Make sure they're both set on the same resolution, although I think only #2 counts.

  • Hi Alaa,

    How can you use multiple channels with oversampling?

    As you wrote above without oversampling the measured result is very noisy.

    Thanks

Related