Description
Description
System time on my saml21-xpro seems to be quite innacurate, both compared to the RTC and to an external source. In about 1 hour I can see a drift of about 15 seconds which seems quite a lot.
Is this to be expected or could something be lying behind that could be analyzed better? (I can try to give a deeper look if this is not expected)
Steps to reproduce the issue
I did a simple application that has a loop that every minute reads the system time, reads the RTC time and prints them out. Something more or less like:
time_t rawtime;
struct tm *info;
struct tm curtime;
char buffer[80];
char buffer2[80];
int contatore=0;
while (1) {
time( &rawtime );
info = localtime( &rawtime );
strftime(buffer,80,"%x %H:%M:%S", info);
rtc_get_time(&curtime);
strftime(buffer2,80,"%x %H:%M:%S", &curtime);
printf("[CNT: %8d][SYS: %s][RTC: %s]\r\n",contatore,buffer,buffer2);
contatore++;
xtimer_sleep(60);
}
RTC is initialized at some known value at the beginning.
Expected results
I would expect them to run roughly at the same speed.
Actual results
I see a drift of about 15 seconds in an hour which sounds quite something to me. Compared to an external source (my PC) the time read from the RTC is the correct one, as that one is aligned (at least after a couple of hours and to a precision of 1 sec) to the PC.
What I see running the test is (I omit some iterations) for example:
RTC Start time is 18 November 2018 at 08:00:00
[CNT: 0][SYS: 01/01/70 00:00:00][RTC: 11/18/18 08:00:00]
[CNT: 1][SYS: 01/01/70 00:01:00][RTC: 11/18/18 08:01:00]
[CNT: 2][SYS: 01/01/70 00:02:00][RTC: 11/18/18 08:02:00]
[CNT: 3][SYS: 01/01/70 00:03:00][RTC: 11/18/18 08:03:00]
[CNT: 4][SYS: 01/01/70 00:04:00][RTC: 11/18/18 08:04:00]
[CNT: 5][SYS: 01/01/70 00:05:00][RTC: 11/18/18 08:05:01]
[CNT: 6][SYS: 01/01/70 00:06:00][RTC: 11/18/18 08:06:01]
[CNT: 7][SYS: 01/01/70 00:07:00][RTC: 11/18/18 08:07:01]
[CNT: 8][SYS: 01/01/70 00:08:00][RTC: 11/18/18 08:08:01]
[CNT: 9][SYS: 01/01/70 00:09:00][RTC: 11/18/18 08:09:02]
[CNT: 10][SYS: 01/01/70 00:10:00][RTC: 11/18/18 08:10:02]
....
[CNT: 59][SYS: 01/01/70 00:59:00][RTC: 11/18/18 08:59:14]
[CNT: 60][SYS: 01/01/70 01:00:00][RTC: 11/18/18 09:00:14]
[CNT: 61][SYS: 01/01/70 01:01:00][RTC: 11/18/18 09:01:15]
[CNT: 62][SYS: 01/01/70 01:02:00][RTC: 11/18/18 09:02:15]
.....
[CNT: 109][SYS: 01/01/70 01:49:00][RTC: 11/18/18 09:49:27]
[CNT: 110][SYS: 01/01/70 01:50:00][RTC: 11/18/18 09:50:27]
[CNT: 111][SYS: 01/01/70 01:51:00][RTC: 11/18/18 09:51:27]
So the system time seem to be running slower than the RTC/real one. While I could understand some degree of imprecision I would think that 15 seconds per hour sounds quite high. While the RTC (that could be tuned eventually) seems to perform quite ok.
Is this behaviour expected ?
I saw this behaviour on a custom hardware but then to clear doubts about the hardware implementation I tried also on the EVB and got the same results indeed. Also on custom hardware the RTC seemed to run fine, while the system time was drifting, but interestingly enough not always at the same speed, always lagging but not always at the same speed.