12 Replies Latest reply on Nov 3, 2015 3:17 PM by userc_15723 Branched to a new discussion.

    clock reference/RTC during deep sleep?

      Hi there,


      following the discussion board and by testing the rtc_sample, I've been trying to figure out wether the BCM20737 does support any clock reference during deep sleep (HID off) without an external crystal. So far, I've found one success reports and several questions in the same direction. However (from my own experience also) there is no way to have a ticking clock during deep sleep. Can somebody confirm this? Or suggest a solution that does not require external components?




        • 1. Re: clock reference/RTC during deep sleep?

          The part provides the ability to wake from Deep Sleep  (i.e. no state information is maintained) after a configured amount of time, both with the internal LPO or an external Xtal:


          • With internal clock, it can wake from Deep Sleep  anywhere from 64mS to ~36 Hrs
          • With external 32 KHz xtal, 128mS to ~144 Hrs


          The rtc_sample application was created to demonstrate the use of an external 32K Xtal as it was assumed that the order of magnitude accuracy of the time maintained with the an external Xtal would be desired over the internal LPO for most applications.


          In addition, the external clock equates to better sleep clock accuracy & lower sleep current of about 20% (internal LPO runs at 128KHz, so higher dynamic power).


          Specificaly, the external clock is utilized when increased sleep clock accuracy (PPM) is needed.  As such, recall that as part of the connection event, the master and slave exchange sleep clock accuracy (PPM) and the accuracy is used to determine the uncertainty window of the slave device for the duration of the connection event. Essentially, this means that more accurate clocks can actually save power.

          • 2. Re: clock reference/RTC during deep sleep?

            Thanks for the answer. To clarify, with external component I meant an additional RTC. As far as I understood there is no way to get the amount of time the part spent during deep sleep, right? A timed wakeup with the RTC is working for me. However getting the time spent in deep sleep when woken up via GPIO is not. The RTC always resets to zero after wakeup. Is there another clock source that ticks during deep sleep or an rtc sample, in which the BLE stack is enabled?

            • 3. Re: clock reference/RTC during deep sleep?

              This thread posted by ldgirod addresses the same issue: Re: Is there any way to discover how much time has elapsed while asleep?


              My understanding is that the internal LPO is still running during HIDOFF as it too can be used to wake from a timed wake-up (even though it has some drawbacks as already noted).


              I will need to ask the developers if there is an example somewhere that shows how to wake from deep sleep using one of the two internal clocks.



              • 4. Re: clock reference/RTC during deep sleep?

                I stand corrected.


                I spoke with the developers and confirmed that there are no clocks running when the part is in deep sleep.


                The only thing we could think of to measure time spent in deep sleep would involve writing NVRAM before going to deep sleep and then read NVRAM in the _create function and calculate the difference.  This will obviously not work if you need to go into deep sleep often, but may be an option if your requirements for deep sleep are less frequent.

                • 5. Re: clock reference/RTC during deep sleep?

                  That's what my current work-around involves. Storing the time awake + the amount of wakeups by timed wakes. This is a very crude solution. Also the resolution of this "virtual" clock is then limited by the duration of the sleep cycle, as well as the resolution of the wake-up by GPIO time is fairly limited.


                  This is also makes me wonder about the usefulness of the RTC. Besides calling it an RTC, which implies that it runs even when the part is sleeping, it's just a small library that maps seconds since epoch to a calendar date then (rather than being an actual component of the µC)?!.  However the comment in the rtc_sample seems to contradict that:


                                // Set up the original reference time instead of using 01/01/2010, 00:00:00 as the reference

                                // because this is a wake from deep sleep. The HW clock keeps running in deep sleep so when

                                // we wake up, the FW needs to know what was used as the original reference time.



                  I guess, there was no follow-up on this thread: Re: Keeping the RTC running during Deep Sleep?. There the RTC seemed to be running during deep-sleep. To the best of my knowledge, i'm also using a 20737 (actually it's the ack.me AMS0002 module). So maybe that's why it's not working for me.


                  Thanks for your quick replies, very much appreciated.

                  • 6. Re: clock reference/RTC during deep sleep?

                    Adding the ACKme team as one of them may know for certain: madmax and shyoc_2185486


                    I also sent a note to the original firmware engineer to confirm as well.  He is out this week on PTO, but should respond when he returns.

                    • 7. Re: clock reference/RTC during deep sleep?

                      Figured out what my problem/misunderstanding was. rtc_init() zeroes the RTC unconditionally, so removing this call and just using the rtc "un-initialiazed" works fine. The RTC also ticks in deep-sleep from the internal 128kHz resonator. Not sure what rtc_init()  is for, but problem solved. Thanks.

                      • 8. Re: clock reference/RTC during deep sleep?

                        Thanks for the update Philipp!

                        • 9. Re: clock reference/RTC during deep sleep?

                          I am already referring to rtc_sample.  I am asking: how can I set it up using the INTERNAL 128kHz OSCILLATOR instead of the external oscilator?




                          • 10. Re: clock reference/RTC during deep sleep?

                            This is working for me on the tag3 board and on my custom board (no external crystal):

                            $ diff rtc_sample_ORIG.c rtc_sample.c


                            <       rtcConfig.oscillatorFrequencykHz = RTC_REF_CLOCK_SRC_32KHZ;


                            >       //rtcConfig.oscillatorFrequencykHz = RTC_REF_CLOCK_SRC_32KHZ;


                            <     bleapputils_changeLPOSource(LPO_32KHZ_OSC, FALSE, 250);


                            >     //bleapputils_changeLPOSource(LPO_32KHZ_OSC, FALSE, 250);


                            <                       devLpmConfig.wakeFromHidoffRefClk = HID_OFF_TIMED_WAKE_CLK_SRC_32KHZ;


                            >                       devLpmConfig.wakeFromHidoffRefClk = HID_OFF_TIMED_WAKE_CLK_SRC_128KHZ;

                            1 of 1 people found this helpful
                            • 11. Re: clock reference/RTC during deep sleep?

                              Have a question here.  I am using the rtc_sample.c as I have an issue with the RTC I am trying to fix.


                              When you run the RTC, and it goes to sleep and wakes up, it does seem to know that it has been asleep and has advanced the clock.  Are you saying this only works from a TIMED WAKE, and will not work properly from a GPIO INTERRUPT?


                              Based on the output here, and how we have been using the RTC in our firmware, there is some kind of accumulator running that is used to calculate the RTC, and it continues to run while in DEEP SLEEP.  Otherwise, how does it get the Current Date/Time is and the seconds since bigbang?


                              Here is some output from rtc_sample.c as an example:

                              08:56:57 - 08:56:57 -

                              08:56:57 - 08:56:57 - Entering deep sleep.

                              08:58:57 - 08:58:57 - rtc_sample_create()

                              08:58:57 - 08:58:57 -

                              08:58:57 - 08:58:57 - Waking from deep sleep because the timer went off or a GPIO triggered while waiting for timer to expire.

                              08:58:57 - 08:58:57 - 020106030304000409bb8104

                              08:58:57 - 08:58:57 - 020a81

                              08:58:57 - 08:58:57 - Time base is:

                              08:58:57 - 08:58:57 - Jan 0 00:00:00 0000

                              08:58:57 - 08:58:57 - Number of free bytes in RAM: 26548

                              08:58:57 - 08:58:57 -

                              08:58:57 - 08:58:57 - blecm evt handler:

                              08:58:57 - 08:58:57 - 0e0401082000

                              08:58:57 - 08:58:57 -

                              08:58:57 - 08:58:57 - blecm evt handler:

                              08:58:57 - 08:58:57 - 0e0401092000

                              08:58:57 - 08:58:57   bd_addr[5:2] = 20 73 6A 18

                              08:58:57 - 08:58:57   bd_addr[1:0] = B770 00

                              08:58:57 - 08:58:57   Fine Timer(1024 ms, 1/sec)

                              08:58:57 - 08:58:57   Fine TImer tick 80

                              08:58:57 - 08:58:57   Normal Timer(0 s, 0 tick)

                              08:58:58 - 08:58:58 - Current date/time is:

                              08:58:58 - 08:58:58 - Jul 15 12:04:17 2014

                              08:58:58 - 08:58:58 - Its been 143121857 seconds since bigbang.

                              • 12. Re: clock reference/RTC during deep sleep?


                                Try calling rtc_init() only when mia_isResetReasonPor() returns true.