nRF5340, enter low-power/sleep while timer enabled

I'm working on optimizing power consumption in my project (using nRF5340DK; as well as Power Profiler Kit 2 which is connected to DK's VDD measurement point as an ampere meter). After trial and error, I've narrowed down the timer (set up similarly to the timer example at NCS v2.5.0, modules/hal/nordic/nrfx/samples/src/nrfx_timer/timer/) as having the biggest impact towards power. When initializing the timer, I got an average current draw of almost 1mA; when it's not initialized, I see about 0.2mA.

Several questions:

  1. Is it expected to see that amount of additional current draw due to just simply setting up the timer?
  2. What are my options for bringing the current down as low as possible, while still being able to have the timer running?
    1. It appears possible when I was using k_sleep() in my main loop, as mentioned here. Though this seems to put the thread to sleep, but not the CPU.
    2. But I just recently discovered using sys_poweroff() as mentioned in this sample, which seems to put the entire CPU to sleep if I'm not mistaken. I'm investigating at the moment on my end too but I'm not sure if the timer can be used to wake the CPU back up.
  3. Are there any other methods of setting up timers that lend itself better to low power applications?

I'd appreciate any feedback for this. Thank you!

Parents
  • (OP replying) Somewhat related question, but is it possible to cancel the remainder of a k_sleep() call within an interrupt handler?

    void interrupt_handler(void)
    {
      restart_timer();  // for example, with RTC, this is counter_set_channel_alarm()
      
      cancel_ksleep();                  // DOES SOMETHING LIKE THIS EXIST...
    }
    
    int main()
    {
      init_timer();
    
      while (true) {
        execute_other_code();    // ... SO THAT THIS EXECUTES MORE THAN ONCE?
    
        k_sleep(K_FOREVER);
      }
    }

    I realize this may not be common to do; for example, I know that things happening periodically could just be put in the main loop with k_sleep(SOME_AMOUNT_OF_TIME). But it may be possible that my project would benefit from something like this what with the timers and other complex portions of our code.

Reply
  • (OP replying) Somewhat related question, but is it possible to cancel the remainder of a k_sleep() call within an interrupt handler?

    void interrupt_handler(void)
    {
      restart_timer();  // for example, with RTC, this is counter_set_channel_alarm()
      
      cancel_ksleep();                  // DOES SOMETHING LIKE THIS EXIST...
    }
    
    int main()
    {
      init_timer();
    
      while (true) {
        execute_other_code();    // ... SO THAT THIS EXECUTES MORE THAN ONCE?
    
        k_sleep(K_FOREVER);
      }
    }

    I realize this may not be common to do; for example, I know that things happening periodically could just be put in the main loop with k_sleep(SOME_AMOUNT_OF_TIME). But it may be possible that my project would benefit from something like this what with the timers and other complex portions of our code.

Children
Related