Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any easy way to change the RTC clock source? #8073

Closed
1 task done
thepixy opened this issue Apr 13, 2023 · 8 comments
Closed
1 task done

Is there any easy way to change the RTC clock source? #8073

thepixy opened this issue Apr 13, 2023 · 8 comments
Labels
Status: Community help needed Issue need help from any member from the Community. Type: Feature request Feature request for Arduino ESP32

Comments

@thepixy
Copy link

thepixy commented Apr 13, 2023

Board

ESP32 (DOIT ESP32 DEVKIT V1)

Device Description

as above. On connections to external components right now

Hardware Configuration

Nothing connected. General feasibility question

Version

latest master (checkout manually)

IDE Name

Arduino

Operating System

Windows 10

Flash frequency

Don't know

PSRAM enabled

yes

Upload speed

115200

Description

The document at https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html explains that "To modify the RTC clock source, set CONFIG_RTC_CLK_SRC in project configuration". The document also tells that the default clock source is "Internal 150 kHz RC oscillator" and that another more stable option is "Internal 8.5 MHz oscillator, divided by 256 (~33 kHz)". Am I correct in saying there is no way to se the latter option programmatically from within a sketch done in the arduino IDE? By poking around I have found options for these clock sources in a header file called "sdkconfig.h", and there is another file I found, "sdkconfig" (with no extension) which sates in comments that is a file that was built, and should not be edited. That file does indeed show what clock source is enabled and which other ones aren't set. But no changes to either of those files affect anything when I compile a project in the IDE.

So again, just to confirm: First, is setting the clock source withing an arduino built sketch impossible? and Second, is there any way short of installing expressif's entire toolset, including python that could accomplish the clock source change?

Sketch

This is a general question about whether something is possible.

Debug Message

This is not an error report.

Other Steps to Reproduce

I don't know

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@thepixy thepixy added the Status: Awaiting triage Issue is waiting for triage label Apr 13, 2023
@mrengineer7777
Copy link
Collaborator

mrengineer7777 commented Apr 13, 2023

@thepixy

First, is setting the clock source withing an arduino built sketch impossible?

Probably true. CONFIG_RTC_CLK_SRC is a define in the IDF. This repository compiles IDF with specific settings into library files .a using arduino-lib-builder. The settings you see in sdkconfig.h have already been compiled into the .a files, so changing sdkconfig.h will have no effect.

Second, is there any way short of installing expressif's entire toolset, including python that could accomplish the clock source change?

There may be function calls to change the RTC clock source, but I'm not aware of them.
Other options:
Code in native IDF
Use IDF + Arduino as IDF component. That's been a headache in the past.

FYI changing RTC clock source to main oscillator may increase current consumption and may not work properly with sleep mode.

@mrengineer7777 mrengineer7777 added Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels Apr 13, 2023
@thepixy
Copy link
Author

thepixy commented Apr 13, 2023

Thanks mrengineer777, and I suspect what you're saying is true. I'm thinking my post might be better placed as a feature request. I can't see any reasonable reason why the clock source options could not be made into a simple core api call. In the mean time I'm a biz suspicious as to what th real default is in every board. I say that because I ran a test where I sync my systemtime to an NTP source, disconnect from WiFI to prevent any more resycing, and then displaying the system time every 5 minutes, using the "show timestamp" option in the arduino serial monitor. In 24 hours it only goes off by a few seconds, which sounds unbelievably good for an "RC Oscillator". And along with not having an api call to set the source, there doesn't seem to be one to test what it is currently.

@mrengineer7777
Copy link
Collaborator

The RTC on my demo board loses about 30 seconds per day. Not great, which is why I keep SNTP service on.
Try testing at a different temperature. RC oscillators are sensitive to temperature.

@thepixy
Copy link
Author

thepixy commented Apr 14, 2023

@mrengineer7777 Right! Honestly I got so used to using one of those cheap battery backed RTC add ons that use the DS3231 chips, from back in the days when WiFi connectivity wasn't a given, This project is the first time I though about using the NTP service. But this particular project only needs to send a daily email report, and the time is not the least bit critical. So I'm hoping to be able to just connect on a pre-programmed hour to send the daily report, and do an NTP time sync while I'm connected, and then disconnect. So anything within even a couple of minutes/day is tolerable. Just seems silly to not be able to depend on the better clock source option. In fact, even if I wanted to try the 32Khz crystal option I could not, because setting the clock source is not part of the API. Well it is what it is, so I'll make do. :-)

@mrengineer7777 mrengineer7777 added Type: Feature request Feature request for Arduino ESP32 and removed Type: Question Only question labels Apr 14, 2023
@mrengineer7777
Copy link
Collaborator

Feature request to add functions to control RTC clock source. Can someone verify these don't already exist?

@mrengineer7777 mrengineer7777 added the Status: Community help needed Issue need help from any member from the Community. label Apr 14, 2023
@moose4lord
Copy link

There was a discussion about ESP32 deep sleep timing instability here:
espressif/esp-idf#6687

@tomocchi3411 provided some nice code to assign the RTC to the 8M/256 source, as well as code to calibrate the RTC.

@Daniel-1276
Copy link

#7084

@Parsaabasi
Copy link

Hello,

Due to the overwhelming volume of issues currently being addressed, we have decided to close the previously received tickets. If you still require assistance or if the issue persists, please don't hesitate to reopen the ticket.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Community help needed Issue need help from any member from the Community. Type: Feature request Feature request for Arduino ESP32
Projects
Development

No branches or pull requests

5 participants