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

Understanding power consumption.

Hi,

I'm trying to figure out what could make the current consumption difference between your blinky example with freertos and with the timer example ?

Here is my configuration :

- Board : pca10056

- Low voltage mode, with REG1 as DC/DC and REG0 as LDO

- Deep Sleep mode enabled in the timer example

I disabled leds control (so it doesn't blink any leds) to only monitor the mcu consumption. Here are the 2 code snippets :

With Freertos :

TaskHandle_t  led_toggle_task_handle;   /**< Reference to LED0 toggling FreeRTOS task. */

/**@brief LED0 task entry function.
 *
 * @param[in] pvParameter   Pointer that will be used as the parameter for the task.
 */
static void led_toggle_task_function (void * pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    while (true)
    {
        /* Delay a task for a given number of ticks */
        vTaskDelay(TASK_DELAY);
        /* Tasks must be implemented to never return... */
    }
}

int main(void)
{
    ret_code_t err_code;

    NRF_POWER->DCDCEN = 0x01; // enable REG0 DC/DC converter 

    /* Initialize clock driver for better time accuracy in FREERTOS */
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    /* Configure LED-pins as outputs */
    bsp_board_init(BSP_INIT_LEDS);

    /* Create task for LED0 blinking with priority set to 2 */
    UNUSED_VARIABLE(xTaskCreate(led_toggle_task_function, "LED0", configMINIMAL_STACK_SIZE + 200, NULL, 2, &led_toggle_task_handle));

    /* Activate deep sleep mode */
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

    /* Start FreeRTOS scheduler. */
    vTaskStartScheduler();

    while (true)
    {
        /* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
         * in vTaskStartScheduler function. */
    }
}

With Timer :

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

volatile bool timer_flag = false;

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    timer_flag = true;
}


void sample_loop()
{
    // Wait for the timer to expire
    while(timer_flag == false)
    {
        __WFI(); // go to sleep mode
    }

    timer_flag = false;// reset timer flag
}

/**
 * @brief Function for main application entry.
 */
int main(void)
{
    const uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    NRF_POWER->DCDCEN = 0x01; // Enable REG1 DC/DC 
    NRF_POWER->TASKS_CONSTLAT = 0x01; // Enable constant latency low power mode
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // activate deep sleep mode

    //Configure all leds on board.
    bsp_board_init(BSP_INIT_LEDS);

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER_LED);

    while (1)
    {
        sample_loop();
    }
}

The current consumption is approximately 0.5mA higher with the use of timer compared to freertos. Can you explain to me where does it come from please ?

Our device will be battery powered so it's pretty important to know.. We thought that getting rid of Freertos would improve power consumption...

Best regards,

Hugo

Parents Reply Children
No Data
Related