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,

    Any interrupt will wake the chip. You have configured your TIMER with CC=8000, which is 0.5ms. You also enabled interrupt when this CC is reached and also enabled short to clear it when internal timer reaches CC value

    NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
    

    So your system will have atleast one interrupt every 0.5ms from TIMER1 (more interrupts if there are other modules generating interrupts)

    You ask

    Why sleep will wake up when the timer is running and calling their interrupt? Previously, I using atmel with arduino as i able to put the system to sleep and timer running at the background

    You system goes to sleep, the timer is still running in the background like you expect, but the timer is waking up your system every 0.5ms. It does not matter what code you use, ATMEL or any other CPU, the idea is the same. The interrupt will wake the system up. Maybe in ATMEL solution you were not using interrupts ?

Reply
  • Hi adrianwong,

    Any interrupt will wake the chip. You have configured your TIMER with CC=8000, which is 0.5ms. You also enabled interrupt when this CC is reached and also enabled short to clear it when internal timer reaches CC value

    NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
    

    So your system will have atleast one interrupt every 0.5ms from TIMER1 (more interrupts if there are other modules generating interrupts)

    You ask

    Why sleep will wake up when the timer is running and calling their interrupt? Previously, I using atmel with arduino as i able to put the system to sleep and timer running at the background

    You system goes to sleep, the timer is still running in the background like you expect, but the timer is waking up your system every 0.5ms. It does not matter what code you use, ATMEL or any other CPU, the idea is the same. The interrupt will wake the system up. Maybe in ATMEL solution you were not using interrupts ?

Children
No Data
Related