04-03-2019 02:59 PM
Hi everyone,
I am using Xilinx Zynq ZC706 with linux OS running in it made with yocto project. Though while reading the time using POSIX APIs "clock_gettime()" I see some inaccuracy in updating the time at about 3.3ms timer cycle. So I was thinking to read directly from the time registers. Can any one shed some light if anyone has experience this problem and how can I read the time more accurately?
04-10-2019 10:49 PM
HI @piyushj ,
Did you try with devmem command to observe the delay?
05-09-2019 03:31 AM
Thanks for the help. FInally I read the time through the Globaltimer registers. I simply opened the memory with open() and gave input of proper registers.
if ((mem = open ("/dev/mem", O_RDWR | O_SYNC)) == -1) fprintf(stderr, "Cannot open /dev/mem\n"), exit(1);
//base register values of Globaltimer base_ptr = mmap (0, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, mem, BASE_ADDRESS); if(base_ptr == (void *) -1) { printf("Memory map failed. error %i\n", base_ptr); perror("mmap"); } valuetimer_low = (unsigned int*)(base_ptr + TIMER1_CONT_LOW); printf("Timer1_low = %u \n", *valuetimer_low); valuetimer_high = (unsigned int*)(base_ptr + TIMER1_CONT_HIGH); printf("Timer1_high = %u \n", *valuetimer_high);
Thanks,
05-09-2019 06:11 AM
@piyushj wrote:
Though while reading the time using POSIX APIs "clock_gettime()" I see some inaccuracy in updating the time at about 3.3ms timer cycle.
Which clock source did you use for your experiments? You'd want CLOCK_MONOTONIC_RAW, otherwise you will see (intentional) adjustments to the clock, to keep it in sync with NTP.
05-09-2019 06:15 AM
Hi, Thanks for the quick reply. I used CLOCK_MONOTONIC. What is the range of this adjustments?
05-09-2019 06:25 AM
@piyushj wrote:
Hi, Thanks for the quick reply. I used CLOCK_MONOTONIC. What is the range of this adjustments?
It will depend on the actual frequency of the underlying clock (eg. the h/w oscillator). These tend to drift with temperature, too. But some crystals are considerably off, and will thus need quite frequent correction, while others will be much more steady.
Quoting from the manpage:
CLOCK_MONOTONIC Clock that cannot be set and represents monotonic time since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP.
CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)
Similar to CLOCK_MONOTONIC, but provides access to a raw hard‐
ware-based time that is not subject to NTP adjustments or the
incremental adjustments performed by adjtime(3).
05-09-2019 06:43 AM
Thank yo very much for heads up!