This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Selective sampling of ADC channels at run time

I am using a 52810 custom board and the SAADC module.

It is used for sampling one analog input through AIN2 and the battery voltage directly by setting the pin to VDD

As per the documentation, since more than one channel is configured/enabled, it goes into scan mode.

i need to measure the analog input at AIN2 for 15 seconds.

However, i do not need to measure the battery voltage in every scan. I only want to measure it once every 5 seconds to check for voltage drop.

Is this possible ?

Regards

Chary BS

Parents
  • Hello Einar,

    Thanks for the clarification ....

    Is the following code correct in order to add the second channel to the SAADC initial configuration? I just added channel to use VDD as input.. andinitialized it.

    <code>

    void saadc_init(void)
    {
        ret_code_t err_code;
        nrf_saadc_channel_config_t channel0_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);

        nrf_saadc_channel_config_t channel1_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);   //To measure the battery voltage.

        err_code = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_channel_init(0, &channel0_config);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_channel_init(1, &channel1_config);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }

    </code>

    Regards

    Chary BS

  • Hi Einar,

    This example from Nordic confirmed the answer to my question - it seems a trivial question in hind sight :-)

    https://github.com/NordicPlayground/nRF52-ADC-examples/blob/master/ble_app_uart__saadc_timer_driven__scan_mode/main.c

    But it would be good to have a channel index returned along with the callback, so that we can identify the data source and apply any processing logic based on that.... just a suggestion from my side !

    Cheers

    Chary BS

Reply Children
Related