Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Use of RTC with XTAL and deepsleep

    Scheduled Pinned Locked Moved Discussion
    rtcxtal32deepsleeppower saving
    6 Posts 5 Posters 1.6k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jardar
      last edited by

      I have a few questions regarding use of the RTC (real time clock).

      1. Is there a difference in accuracy and power consumption when using the RTC with XTAL_32KHZ vs. INTERNAL_RC
      2. Will the RTC need to be reinitalized after a deepsleep to make it use XTAL_32KHZ or INTERNAL_RC
      3. Will deep sleep have any affect on the accuracy of the RTC?
      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @Jardar
        last edited by

        Hi @jardar

        You will get better accuracy - including timing deepsleep wake, especially if you're having long sleep times - using an external crystal at the expense of slightly higher power consumption. I don't however have quantitative data on this to share and it'll also vary depending on the crystal used.

        On the normal firmware you'll need to tell RTC to enable XTAL_32KHZ every time, because the pycom-esp-idf is compiled with

        CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=

        so this reverts to the internal clock every deepsleep cycle.

        If you're using an external crystal I'd recommend compiling a custom firmware with the external crystal enabled: Component config->ESP32-specific->"Timers used for gettimeofday" and "RTC clock source"

        1 Reply Last reply Reply Quote 0
        • J Offline
          jas_xcs
          last edited by

          Hi,

          I'm trying to setup the RTC to use the external XTAL while in deep-sleep. I create an RTC and set its source to XTAL_32KHZ right before entreing the deep-sleep mode. Everything seems to work fine, but accuracy is still a mess (2 seconds diff over a 10-min sleep time), exactly the same as when using the internal RC oscillator.

          It looks like the ESP32 is still using the internal clock, because if I remove the crystal, it does the same.

          My test code:

          import machine
          import time
          
          rtc = machine.RTC()
          rtc.init(source=rtc.XTAL_32KHZ)
          time.sleep_ms(1)
          machine.deepsleep(60000)      
          

          Any thoughts on this? What am I missing?

          Thanks,
          Javi

          1 Reply Last reply Reply Quote 0
          • T Offline
            t0000899
            last edited by t0000899

            Hi @jmarcelino ,
            Is it still true that one would need a special firmware to use external RTC crystal in machine.deepsleep?

            If so, could it be possible to select a firmware with a 32768 Hz external cystal enabled in "Advanced Settings" in Firmware Update Tool?
            Or update deep sleep documentation to remind that external crystal is not used to count machine.deepsleep time?

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @t0000899
              last edited by robert-hh

              @t0000899 In my test I also had the impression that the external XTAL is not used. I connected one, made it working. At least I believe so. Getting a crystal to oscillate is not easy. It is not just soldering it to the pins. But the time lapse compared to an external RTC clock was still the same. Even injecting a 32kHz signal with an external generator did not change the figure. I have to investigate further.

              T 1 Reply Last reply Reply Quote 0
              • T Offline
                t0000899 @robert-hh
                last edited by

                @robert-hh
                I have the same impression. I had a 15 minutes deep sleep cycle running the night and the time was ~4 minutes off in the morning.

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom