nrf52832 constantly consuming higher current of 3.4ma after reading adc value using using saadc in blocking mode

Hi,

I am developing my application on top of low power node example available nrf sdk for mesh v5.0.0. The idea behind the application is that after the node is provisioned and model publication is set, node should periodically measure battery voltage, calculate battery percentage and send the values over mesh to the desired address set in model publication state and return to the idle state. In idle state after provisioning, the node consumes only around 70ua. But after reading adc value using saadc in blocking mode, the node is constantly consuming 3.4 ma and not returning to the idle state. I am guessing that the CPU is not going back to sleep after reading battery voltage and SAADC is keeeping the CPU awake. Can someone help me to complletely disable the SAADC peripheral?

I am attaching the routine which I use to initialize and deinitialize the SAADC peripheral before and after reading ADC value and also the routine to read ADC value. Thanks!

//Initialization routine
void saadc_init(void)
{
    nrfx_err_t err_code;
    ret_code_t ret_code; 

    nrf_drv_saadc_config_t saadc_config_t;
    saadc_config_t.resolution = NRF_SAADC_RESOLUTION_12BIT;
    saadc_config_t.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
    saadc_config_t.low_power_mode = true;
    saadc_config_t.interrupt_priority = APP_IRQ_PRIORITY_LOW;

    nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    //err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler);
    //APP_ERROR_CHECK(err_code);

    //err_code = nrfx_saadc_channel_init(0, &channel_config);
    //APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Initializing channel");
    ret_code = nrf_drv_saadc_init(&saadc_config_t, NULL);
    APP_ERROR_CHECK(ret_code);
    if(ret_code == NRFX_SUCCESS)  NRF_LOG_INFO("Initialized channel");

    NRF_LOG_INFO("Enabling Channel");
    err_code = nrfx_saadc_channel_init(0, &channel_config);
    APP_ERROR_CHECK(err_code);
    if(err_code == NRFX_SUCCESS)  NRF_LOG_INFO("Enabled channel");
}

//Deinitialization routine
void saadc_deinit(void)
{
    nrfx_err_t err_code;
    
    NRF_LOG_INFO("Disabling Channel");
    err_code = nrfx_saadc_channel_uninit(0);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Disabled channel");

    NRF_LOG_INFO("Uninitializing channel");
    nrf_drv_saadc_uninit();
    NRF_LOG_INFO("Deinitialized channel");
}

//Reading ADC value in blocking mode
void readBtryVtg(void)
{ 
     nrfx_err_t err = NRF_SUCCESS;
     for(uint8_t sample=0; sample < NO_OF_ADC_SAMPLES; sample++) {
       err = nrfx_saadc_sample_convert(0, &adcVal);
       adcValSum += adcVal;
     }
     adcValAvg = adcValSum / NO_OF_ADC_SAMPLES;
     adcValAvg *= 2;
     btryVtgAvg = ((adcValAvg * (3.6 / 4096)) * 1000); 
     btryVtgAvg = (btryVtgAvg > 2999) ? 2999 : btryVtgAvg;
     btryVtgMap = (((float)(btryVtgAvg/1000.0) - MIN_BTRY_VTG) / (MAX_BTRY_VTG - MIN_BTRY_VTG));
     NRF_LOG_INFO("ADC val - %d\r\n",adcValAvg);
     NRF_LOG_INFO("Battery voltage mapped " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(btryVtgMap));
}



Parents
  • Hi

    Have you checked wether low power Saadc mode enabled in config or not? Macro for low power Saadc is 
    NRFX_SAADC_CONFIG_LP_MODE  - Enabling low power mode 

    The difference between the low-power mode and normal mode is that in low-power mode the START task is not triggered until the sample function is called, while in normal mode, START task is triggered when the buffer_convert function is called to setup the buffers. The SAADC peripheral support EasyDMA, allowing sampling of channels directly to RAM using PPI, without CPU intervention. When low-power mode is enabled, the CPU is required to trigger sampling, and it will only work with a buffer size of 1 sample. In case of high sample rate, there is little or no benefit from the low-power mode. The low-power mode is implemented exactly for the scenario that you describe.

    I hope it helps.

Reply
  • Hi

    Have you checked wether low power Saadc mode enabled in config or not? Macro for low power Saadc is 
    NRFX_SAADC_CONFIG_LP_MODE  - Enabling low power mode 

    The difference between the low-power mode and normal mode is that in low-power mode the START task is not triggered until the sample function is called, while in normal mode, START task is triggered when the buffer_convert function is called to setup the buffers. The SAADC peripheral support EasyDMA, allowing sampling of channels directly to RAM using PPI, without CPU intervention. When low-power mode is enabled, the CPU is required to trigger sampling, and it will only work with a buffer size of 1 sample. In case of high sample rate, there is little or no benefit from the low-power mode. The low-power mode is implemented exactly for the scenario that you describe.

    I hope it helps.

Children
  • Hi Khawaja, 

    I tried enabling the recommended macro and also SAADC_CONFIG_LP_MODE. Enabling both of them doesn't seem to be making a difference. Still I am seeing a constant 3.4ma current consumption after reading adc value once and deinitializing adc peripheral. Once deinitiliazed, the current consumption should drop down to 70ua right? Its not the case here. I am taking an average of 200 samples at a time to calculate battery percentage by measuring the battery voltage. 

Related