Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Evgeny Mazovetskiy
#18637 Hello,

did someone try to use system_get_rtc_time() and system_rtc_clock_cali_proc() to calculate time?

3.2.13.
system_get_rtc_time Function:
Get RTC time, count by RTC clock period.
Example:
If system_get_rtc_time returns 10 (means 10 RTC cycles),
system_rtc_clock_cali_proc returns 5 (means 5us per RTC cycle),
then real time is 10 x 5 = 50 us


On my chip system_rtc_clock_cali_proc() returns random value in a range between 23500 and 24000, while system_get_rtc_time() is pretty accurate and looks perfectly linear.

Image

so the system_rtc_clock_cali_proc() does not look like a good candidate
User avatar
By JM Hdez
#38750 I found this question googling for guidance on the same issue. For those getting to this post looking for clarification on the same matter, it may be helpful to have a look to the code shown in:
https://gist.github.com/0x6e/c5038ce838f15e4e601a
That is an example extracted from Espressif Systems ESP8266 SDK API Guide.

According to this example, the system_rtc_clock_cali_proc() function returns a number that represents the equivalent system clock ticks of one RTC clock cycle. In practice, the value is not the mathematical ratio between System Clock and RTC Clock, but the relationship can be easily derived:

uint32_t RTC_Time;
uint32_t SYS_Time = system_get_time();
uint32_t cal_factor = system_rtc_clock_cali_proc();
RTC_Time = SYS_Time / ((cal_factor * 1000) >> 12) / 1000);

A couple of examples that may clarify the issue (note divisions represent math ratios):
Ex.1: cal_factor = 24560, would mean that: SYS_Time / RTC_Time = 5.996
Ex.2: SYS_Time = 1234567, and cal_factor = 24560, means RTC_Time = 1234567 / 5.996 = 205898 us

I hope this helps! At least this worked for me. :-)