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

Clock control in RTC interrupt

Hi all!

I am developing an nRF52 application that uses RTC interrupt to measure an ADC value every 100 ms. Depending on the measured value the chip shall either go back to sleep or execute an algorithm. We are in the beginning of the project and one of the first tasks is to evaluate if we can get the power consumption low enough. Currently I am just running the RTC interrupt every 100 ms and then go back to sleep. The current is measured with a Keysight power analyzer and the execution time for the interrupt is measured by toggling a GPIO connected to an oscilloscope. My intention was to just use the internal 32 kHz RC oscillator during the interrupt. The RTC timing measurement however indicates that the interrupt is executed in 2.9 us which makes me suspect that it runs on 64 MHz. Calling nrf_drv_clock_hfclk_is_running() however return false. During this there is a max peak current of 7.2 mA. Just to execute the interrupt without even starting the SAADC uses around 170 nC which is too much for our needs. Calling nrf_drv_clock_hfclk_is_running() however return false. Anyone that can explain what is happening? Also see code pasted below.

static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { uint32_t err_code;

if (nrf_drv_clock_hfclk_is_running())
{
    nrf_gpio_pin_set(ARDUINO_0_PIN);
}
else
{
    nrf_gpio_pin_set(ARDUINO_1_PIN);
}

if (int_type == NRF_DRV_RTC_INT_COMPARE0)
{
    err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true);
    APP_ERROR_CHECK(err_code);
    nrf_drv_rtc_counter_clear(&rtc);
}
nrf_gpio_pin_clear(ARDUINO_0_PIN);
nrf_gpio_pin_clear(ARDUINO_1_PIN);

}

static void rtc_config(void) { uint32_t err_code;

//Initialize RTC instance
nrf_drv_rtc_config_t rtc_config;
rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(10);
err_code = nrf_drv_rtc_init(&rtc, &rtc_config, rtc_handler);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_rtc_cc_set(&rtc,0,1,true);
APP_ERROR_CHECK(err_code);

//Power on RTC instance
nrf_drv_rtc_enable(&rtc);

}

int main(void) { lfclk_config();

nrf_gpio_cfg_output(ARDUINO_0_PIN);
nrf_gpio_cfg_output(ARDUINO_1_PIN);

rtc_config();

while (true)
{
    __WFE();
    __SEV();
    __WFE();

}

}

Thanks in advance, Mattias

Related