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

Problem stopping ADC and restart again

Hello,

I am trying to get a low consumption and I detect that the activation of the ADC increases the consumption.
So I am trying to configure the ADC and when I make the conversion I try to desactivate it completly.

I desactivate the ADC using this functions:

nrf_drv_saadc_uninit();
NVIC_ClearPendingIRQ(SAADC_IRQn);

I detect in my code that I can not desactivate the ADC as quickly as I want.
I can not desactivate it as soon as I have the last read adc conversion. i have to delay about 5 ms to apply this functions.

I would like to know why I need this delay to execute this functions.
If not I do this delay then I can not restart the ADC again .

  • Hi,

    You should not need any delay before uninitializing the SAADC. What is the issue when you do not add the delay? 

    Where are you calling the uninit function? Please post some code showing what you are trying to do, and how you have configured the SAADC.

    Which SDK version are you using?

    Best regards,
    Jørgen

  • Hello Jørgen,

    If I don't do the delay then I can no restart the ADC.

    #define NRF_DRV_SAADC_LULABYTES_CHANNEL_CONFIG_SE(PIN_P) \
    {                                                      \
        .resistor_p = NRF_SAADC_RESISTOR_DISABLED,         \
        .resistor_n = NRF_SAADC_RESISTOR_DISABLED,         \
        .gain       = NRF_SAADC_GAIN1_4,                   \
        .reference  = NRF_SAADC_REFERENCE_INTERNAL,        \
        .acq_time   = NRF_SAADC_ACQTIME_10US,              \
        .mode       = NRF_SAADC_MODE_SINGLE_ENDED,         \
        .pin_p      = (nrf_saadc_input_t)(PIN_P),          \
        .pin_n      = NRF_SAADC_INPUT_DISABLED             \
    }

    void saadc_init(void){
            ret_code_t err_code;
        
            //
            adc_stat = 0x00;
            nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_LULABYTES_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);            // NEW VERSION
        
        err_code = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(err_code);

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

        err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
        
    }

    Best regards,

    Juan

  • Please answer my other questions as well:

    • Where are you calling the uninit function?
    • Which SDK version are you using?

    Have you tried calling nrf_drv_saadc_abort before uninit, to make sure no sample/conversion is in progress? You should also make sure you set the symbol DEBUG_NRF, to enable the ASSERT that checks if the timeout is reached without the STOPPED event being received.

  • Hello Jørgen,

    I am using 2.0.0-7.alpha. In the Nordic Semiconductors web I downlad the s132_nrf52_6.1.0_API.

    I would like to update it in my project, but when I modify the files the project launch more than 50 errors in the compilation.

    Is this normal?

    Thanks in advance.

    Juan

  • Those are softdevice versions. You can't simply download a new softdevice and replace the old, this will give you a lot of compilation errors.

    As you can see from the compatibility matrix, softdevice 2.0.0-7.alpha was supported by SDK v11.0.0-2.alpha, while softdevice v6.0.0 is supported by SDK 15.0.0 (softdevice v6.1.0 is still not supported by the SDK). I would recommend that you download the latest SDK and start with this instead of the old version. Please have a look at the getting started section in the infocenter.

Related