Hi all,
I'm using this below mentioned code :
int rtc_set_time(rtc_time_date_t ip)
{
time_t now;
struct tm t;
struct timeval val = {0,0};
if(ip.year<=2019&& ip.year>1970)
t.tm_year=ip.year-1900;
else
return 0;
if(ip.min<60 && ip.min>=0)
t.tm_min=ip.min;
else
return 0;
if(ip.mon>0 && ip.mon<13)
t.tm_mon=ip.mon-1;
else
return 0;
if(ip.hour>=0 && ip.hour<=23)
t.tm_hour=ip.hour;
else
return 0;
if(ip.sec>=0 && ip.sec<=60)
t.tm_sec=ip.sec;
else
return 0;
if(ip.mday>0 && ip.mday<=31)
t.tm_mday=ip.mday;
else
return 0;
t.tm_isdst=0;
now=mktime(&t);
val.tv_sec=now;
settimeofday(&val,NULL);
return 1;
}
void rtc_get_time(rtc_time_date_t *ip)
{
struct timeval val = {0,0};
time_t now;
struct tm t;
gettimeofday(&val,NULL);
now=val.tv_sec;
time(&now);
localtime_r(&now,&t);
(*ip).year=t.tm_year+1900;
(*ip).mon=t.tm_mon+1;
(*ip).mday=t.tm_mday;
(*ip).hour=t.tm_hour;
(*ip).min=t.tm_min;
(*ip).sec=t.tm_sec;
}
main()
{
rtc_time_date_t ip;
int check;
struct timeval val;
ip.year=(unsigned int)2019;
ip.mon=(unsigned int)5;
ip.mday=(unsigned int)20;
ip.hour=(unsigned int)17;
ip.min=(unsigned int)52;
ip.sec=(unsigned int)30;
check=rtc_set_time(ip);
if(check!=1)
{
printf("Set_time Failed \n");
return 0;
}
else
printf("Set_time Success\n");
vTaskDelay(50/portTICK_PERIOD_MS);
while(1)
{
rtc_get_time(&ip);
ESP_LOGI(TAG1,"\nYear:%d Month:%d Day:%d\nHour:%d,Min:%d,Sec:%d\n",
ip.year,ip.mon,ip.mday,ip.hour,ip.min,ip.sec);
ESP_LOGI(TAG1,"RTC Time %llu\n",rtc_time_get());
// printf("RTC Time %llu\n",rtc_time_slowclk_to_us(1,10));
vTaskDelay(5000/portTICK_PERIOD_MS);
}
}
where "rtc_time_date_t" is a structure variable that converts raw data into data required by "struct tm"
My CPU Frequency is 160 Mhz.
RTC clock source is internal 150 KHz clock.
1024 Number of cycles for RTC_SLOW_CLK calibration.
Timers used for gettimeofday function (RTC).
Main Xtal Frequency is autodetect.
My dirft after 15 hrs is -8 Minutes .
I dont want my device to sleep and fetch data . I want it to readily fetch the data.
Thanks,
Dhananjay Sutariya
Internal RTC Drifting -8 Minutes in 15 Hours.
-
- Posts: 41
- Joined: Thu Feb 28, 2019 12:21 pm
Re: Internal RTC Drifting -8 Minutes in 15 Hours.
Hi,
You can try to change in menuconfig the "RTC clock source" to from "Internal 150kHz oscillator" to "Internal 8.5MHz oscillator divided by 256". The accuracy should improve.
The online help in menuconfig provides more information:
You can try to change in menuconfig the "RTC clock source" to from "Internal 150kHz oscillator" to "Internal 8.5MHz oscillator divided by 256". The accuracy should improve.
The online help in menuconfig provides more information:
Code: Select all
- "Internal 8.5MHz oscillator divided by 256" option results in higher
deep sleep current (by 5uA) but has better frequency stability than
the internal 150kHz oscillator. It does not require external components.
--
Paul.
Paul.
-
- Posts: 41
- Joined: Thu Feb 28, 2019 12:21 pm
Re: Internal RTC Drifting -8 Minutes in 15 Hours.
Hi paul,papaluna wrote: ↑Tue May 21, 2019 8:00 amHi,
You can try to change in menuconfig the "RTC clock source" to from "Internal 150kHz oscillator" to "Internal 8.5MHz oscillator divided by 256". The accuracy should improve.
The online help in menuconfig provides more information:
Code: Select all
- "Internal 8.5MHz oscillator divided by 256" option results in higher deep sleep current (by 5uA) but has better frequency stability than the internal 150kHz oscillator. It does not require external components.
Thanks for the quick response, ill make that configurations and revert back to you in a while.
Thanks,
Dhananjay Sutariya
-
- Posts: 9761
- Joined: Thu Nov 26, 2015 4:08 am
Re: Internal RTC Drifting -8 Minutes in 15 Hours.
Note that without an external 32KHz crystal, you're still going to have a fair amount of drift; it's quite inevitable as on-chip oscillators never will get the precision an external crystal can have.
-
- Posts: 41
- Joined: Thu Feb 28, 2019 12:21 pm
Re: Internal RTC Drifting -8 Minutes in 15 Hours.
Hi ESP_SPRITE,ESP_Sprite wrote: ↑Tue May 21, 2019 8:33 amNote that without an external 32KHz crystal, you're still going to have a fair amount of drift; it's quite inevitable as on-chip oscillators never will get the precision an external crystal can have.
Can i connect this external pin to any other pin or is it mandatory to connect it to GPIO32 and GPIO33.
Does 32Khz provide perfect timing,and if drift how much percentage of drift is expected?
-
- Posts: 9761
- Joined: Thu Nov 26, 2015 4:08 am
Re: Internal RTC Drifting -8 Minutes in 15 Hours.
Yes, it needs to be connected to the RTC pins. It still won't give you zero drift, as there's nothing on this earth that has zero drift but if implemented correctly the drift will be limited to the tolerance of the crystal, which can be 10s of ppm (which converts to, say, a handful of minutes per year.)
Who is online
Users browsing this forum: ElectricThanhTung and 122 guests