How to start with sleepy code in nRF connect Desktop SDK

Hi Team,

How to start with the sleepy code in nRF connect desktop SDK, can anyone provide me a refernce which has clear insights?

Thanks,

Pranathi

Parents
  • Hi,

    Th enRF Connect SDK includes the Zephyr RTOS, where there is always a idle thread that enters sleep mode when idle. So you do not need to do anything special to enter sleep, other than don't do anything. Note that for instance having a main loop that runs continiously means using the CPU at all times, so if you do, you can for instance wait with k_sleep() to sleep for a specified ammount of time.

  • Hi,

    Can you provide me a sample code for some clear refernece for my side?

    I want to use a timer based sleep mechanism as such I want the board to wake up when I am trying to exhibit a functionlity and after executing it my board should go into sleep and wake up when the said functionlity to be executed. And FYI I am using nRF52840 DK.

    Thanks,

    Pranathi.

  • I am using a thread that is defined as

    K_THREAD_DEFINE(control, 1024, control_thread, NULL, NULL, NULL, -1, 0, 1000);
    And at the end of the entry "control_thread" function I am using k_sleep(K_MSEC(50));
    int main(void)
    {
        #My code#
        
        return 0;
    }
    
    void control_thread(void)
    {
        while(true)
        {
            #My logic#
            k_sleep(K_MSEC(50));
        }
    }
    
    K_THREAD_DEFINE(control, 1024, control_thread, NULL, NULL, NULL, -1, 0, 1000);
  • I see. Nothing obviously stands out here. If you comment out your logic and keep only the sleep, what current consumption do you measure then? If that is also high, you need to look somewhere else. Either in other parts of the application, or it oculd also be worth looking at your hardware and how you measure the current consumption.

  • My actual code consists the logic, I just shared you the syntax of where I was using the sleep.

    And I didn't check the current consumptions with the code as it is I provided in the above reply, I checked the currents  with my logic in it. That's why I have mentioned "my code" and "my logic" so that you can understand that there is some logic I have written there which I couldn't share in the dev zone as it is irrelevant. 

  • I understand. I am not interested in your logic, but if you measure a unexpected high current consumption and want input on what oculd cause it I need to know more about the application you run, the hardweare you are testing on and how you measure.

    So, if you would like to proceed, I suggest the following:

    1. Test with a simple application that has logging disabled and does nothing other than either return from main or have an empty main loop with a k_sleep with a long delay. This way, the CPU should sleep for a long time and no peripherals that can consume significant amount of power will be active.
    2. Measure the current consumption of that to get the base of your device.
    3. Is that much higher than expected? If so, we need to first look at  your hardware and measurment setup.
    4. Is it in the order of a few micro amps (which is expected)? If so, we need to look at your firmware to understand why you get an unexpected current consumption.
  • Thank you for your comprehension and guidance. I will notify you once I have completed the mentioned procedure.

Reply Children
  • I am using the nRF52840 development kit for my evaluation. 

    I currently bought it to 150 uA by using thi function (previously it was 4.8mA).

    pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
    in the main thread with K_sleep of 1000 micro seconds.
    I want to reduce the current consumtion from 150 uA, for which I was going through the datasheet
    I could see different sleep modes for the nRF52840 board, how do I enable them?
    Could you please provide me some reference to this? or suggest me a example code releted to enabling these sleep modes?
  • As I mentionned before, the CPU will sleep by default as long as you don't do anything. But if any peripherals etc are enabled, they will continue to be. What do you use in your application? A typical problem is UART if you have logging enabled. So the first thing you should make sure is to disable logging, by adding configs like these:

    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    CONFIG_SERIAL=n
    CONFIG_LOG=n

Related