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

    Accuracy of RTC

    Scheduled Pinned Locked Moved Firmware
    esp32
    18 Posts 7 Posters 6.2k Views 7 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.
    • L Offline
      loboris
      last edited by loboris

      In the latest esp-idf there is the code for enabling RTC with external 32.768 crystal, but there are still some bugs and incompleteness. components/esp32/cpu_freq.c, for example, has a bug (probably left there intentionally because of incompleteness in other code). I have tested it, and very precise time is kept during the deep sleep, so I expect the complete code to be available soon.
      There is also an option in menuconfig to select external 32.768 xtal.

      J 1 Reply Last reply Reply Quote 1
      • J Offline
        jmarcelino @loboris
        last edited by

        @loboris very interesting, thank you for sharing that.

        Did you try it with the Pycom boards and a crystal on P19 + P20?

        L 1 Reply Last reply Reply Quote 0
        • L Offline
          littlebat @jmarcelino
          last edited by littlebat

          @jmarcelino said in Accuracy of RTC:

          In either case I don't think there is, for now, an intention to keep the time updated on the RTC while in deep sleep. The recently announced deepsleep shield for example seems to turn everything off.

          Yes but only for the pycom device revisions with the hardware issue. Of course soon there will be new revisions and some of us run on other hardware so hopefully it is flexible.

          1 Reply Last reply Reply Quote 0
          • L Offline
            loboris @jmarcelino
            last edited by

            @jmarcelino said in Accuracy of RTC:

            @loboris very interesting, thank you for sharing that.

            Did you try it with the Pycom boards and a crystal on P19 + P20?

            I've tested it with SparkFun ESP32 Thing. The 32.768 Khz crystal is connected to 32K_XP&32K_XN pins (P19+P20 on Pycom) so it should work on Pycom boards the same.
            The changes has to be made in couple of source files, I think it's better to wait the esp-idf team to finish the job. I've tested it with deep-sleep example and it works much better than with 150KHz wich has error of ~10%.

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jmarcelino @loboris
              last edited by

              @loboris
              Thanks, was just catching up with the ESP32 forum myself.

              "Note that we are observing issues on some boards with 32k xtal startup time... That's part of the reason why you don't see 32k xtal support in master yet. We are now working these issues."

              https://www.esp32.com/viewtopic.php?p=7269#p7269

              So wait and see I guess.

              1 Reply Last reply Reply Quote 0
              • B Offline
                BluCode
                last edited by

                If at all possible it would be great if there was an option to keep the RTC powered during deepsleep, as I will be using my board in an application the needs to know the time (or some relativity accurate estimation of the time) immediately after waking from deepsleep, in some cases without internet.

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jmarcelino @BluCode
                  last edited by

                  @BluCode
                  I recommend you use an external RTC for now for those applications.

                  For example the DS1307 is easy to interface over I2C and very very cheap (full module inc external eeprom can be had for <$1 http://www.ebay.com/itm/Arduino-I2C-RTC-DS1307-AT24C32-Real-Time-Clock-Module-For-AVR-ARM-PIC-SMD-/170910326110

                  Also it's self-battery powered, it'll keep the time for many years with issues caused by firmware upgrades or others.

                  B 1 Reply Last reply Reply Quote 0
                  • B Offline
                    BluCode @jmarcelino
                    last edited by

                    @jmarcelino My goal is to make a watch, so I unfortunately don't have space for that. I guess I will have to wait and see what the devs do, and maybe make my own micropython port.

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      Colateral @jmarcelino
                      last edited by Colateral

                      @jmarcelino I used an external 32Khz cristal on P19, P20.

                      I set first line of main, rtc= RTC(0,RTC.XTAL_32KHZ). I let the board powered monitored the time over 3 days and after that period I observed a delay of almost 3 secs (utime.localtime()) over the ntp time. I believe is a bug in the RTC using RTC.XTAL_32KHZ configuration

                      Another question: after machine.deepsleep(1) ... it is required always to reinit RTC(0,RTC.XTAL_32KHZ) ? ... or once keeps RTC.XTAL_32KHZ until hard reset or power off.

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

                        @Colateral 1 sec/day is a deviation of ~12ppm. That is within the typical tolerance of a crystal. You may get better precision by trimming it.

                        C 1 Reply Last reply Reply Quote 0
                        • C Offline
                          Colateral @robert-hh
                          last edited by

                          @robert-hh Thanks robert. It is not clear for me if you set RTC(0,RTC.XTAL_32KHZ) at the beg of program (main) , if pycom is working with this RTC.XTAL_32KHZ config. when is called utime.localtime() or is working with internal oscillator. I made a test and seems that both are working the same.

                          Can you explain how " You may get better precision by trimming it." ?

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

                            @Colateral You can slightly vary the frequency of a crystal by changing it's capacitive load. It is however anyhow difficult to get the crystal working with a development board, since the capacitive load is not known and may vary when moving the device. Actually I could net get stable oscillation when trying it once.
                            Edit: I repeated the test, and the oscillator worked, even with a little low amplitude of 400mV. The frequency seems OK. Observing it with an SDR shows 32768 Hz at a resolution of 0.1Hz. Note that FiPy is using the XTAL pins for the LTE modem.

                            C 1 Reply Last reply Reply Quote 0
                            • C Offline
                              Colateral @robert-hh
                              last edited by Colateral

                              @robert-hh said in Accuracy of RTC:

                              You can slightly vary the frequency of a crystal by changing it's capacitive load. It is however anyhow difficult to get the crystal working with a development board, since the capacitive load is not known and may vary when moving the device. Actually I could net get stable oscillation when trying it once.
                              Edit: I repeated the test, and the oscillator worked, even with a little low amplitude of 400mV. The frequency seems OK. Observing it with an SDR shows 32768 Hz at a resolution of 0.1Hz. Note that FiPy is using the XTAL pins for the LTE modem.

                              Thank you Robert. Can you point me which crystal and electrical schema (capacitors) have you use for this ? ... or FiPy used crystal and capacitors. I used the below schema with L04 ... but seems that I'm loosing 30s / day
                              The cristal and capacitors and L04 are on PCB mounted by a pick and place machine

                              11.jpg

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

                                @Colateral I used the same circuitry (10 pF capacitors) and a crystal with 12.5 pF load capacitance. The model is called MS1V-T1K from Micro Crystal Switzerland. It was the one easy to get from a local store. The 12.5 pF load capacitor would lead to ~22pF C1 C2 capacitors. Since I have a set-up with the LOPY4 development board + a carrier board +..., there is already a lot of unknown stray capacitance. Therefore the 10 pF work. I did however not run a test over a day yet to see the clock drift. I just measured the frequency of the crystal while running. But I can do this time drift test in the next days.

                                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