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

sleep function is not working when timer/RTC is running in nRF51822

nrf51822_sleep_and_timer.txt

Hi... I having tough time to make the sleep function to work when timer/RTC is running in the background of nRF51822. The attached text file containing my code. After comment out the start_timer() & start_RTC() in the setup() then the sleep function is working fine as I will only can be woke up by the external internal. If either one of this function : start_timer() or start_RTC() is uncommented from the setup() then the system is not going to sleep as I got to know it by checking on the serial monitor as it's keep on printing "Hello". Kindly assist. Thanks.

Parents
  • Hi adrianwong,

    I did not see the code where you calling your loop or sleep functions, but i assume you do it somewhere.

    You timer is programmed to generate an interrupt every 0.5ms, which is 2000/second. Which is very fast, so even if your system sleep, waking it up every 0.5ms and trying to do some interrupt handling/printing that takes some time.

    Your system is still going to sleep, you cannot see it because it wakes up so frequently that you cannot judge it from the print log.

  • Hi Adrianwong,

    Consider this below program

    RTC_INT_Handler()
    {
        some_logic;    
    }
    
    main()
    {
      config_RTC(0.5ms);
       ...
       ...
    
       forever
       {
          sleep();
          Serial.println("Activity");
       }
    }
    

    With above logic, your system will go to sleep, but will wakeup and execute the RTC_INT_Handler every 0.5ms, after it wakes up it will print your "Activity" and go to sleep again because you are executing sleep in a loop. After 0.5ms another RTC interrupt will wake the system and exectute the interrupt handler. When finished the next line "Activity" is printed again and the system will go to sleep.

    The amount of time the system stays in sleep depends on the number of interrupts waking the system. IF you want to save a lot of power, then you program RTC to give interrupts less frequently, so your system can stay in sleep mode most of the time.

    You can for example make RTC to give an interrupt every 1 second to update your clock, considering the system wake up time is few micro seconds + executing interrupt handler for few micro seconds, then your system will be sleeping 99.9% of the time.

Reply
  • Hi Adrianwong,

    Consider this below program

    RTC_INT_Handler()
    {
        some_logic;    
    }
    
    main()
    {
      config_RTC(0.5ms);
       ...
       ...
    
       forever
       {
          sleep();
          Serial.println("Activity");
       }
    }
    

    With above logic, your system will go to sleep, but will wakeup and execute the RTC_INT_Handler every 0.5ms, after it wakes up it will print your "Activity" and go to sleep again because you are executing sleep in a loop. After 0.5ms another RTC interrupt will wake the system and exectute the interrupt handler. When finished the next line "Activity" is printed again and the system will go to sleep.

    The amount of time the system stays in sleep depends on the number of interrupts waking the system. IF you want to save a lot of power, then you program RTC to give interrupts less frequently, so your system can stay in sleep mode most of the time.

    You can for example make RTC to give an interrupt every 1 second to update your clock, considering the system wake up time is few micro seconds + executing interrupt handler for few micro seconds, then your system will be sleeping 99.9% of the time.

Children
No Data
Related