UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor piyushj
Visitor
494 Views
Registered: ‎03-06-2019

Reading time on ZC706 through registers

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?

0 Kudos
6 Replies
Moderator
Moderator
422 Views
Registered: ‎06-27-2017

Re: Reading time on ZC706 through registers

HI @piyushj ,

Did you try with devmem command to observe the delay?

 

Best Regards
Kranthi
--------------------------
Don't forget to reply, kudo, and accept as solution.
0 Kudos
Highlighted
Visitor piyushj
Visitor
374 Views
Registered: ‎03-06-2019

Re: Reading time on ZC706 through registers

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,

0 Kudos
Scholar rfs613
Scholar
364 Views
Registered: ‎05-28-2013

Re: Reading time on ZC706 through registers


@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.

0 Kudos
Visitor piyushj
Visitor
359 Views
Registered: ‎03-06-2019

Re: Reading time on ZC706 through registers

Hi, Thanks for the quick reply. I used CLOCK_MONOTONIC. What is the range of this adjustments?

0 Kudos
Scholar rfs613
Scholar
355 Views
Registered: ‎05-28-2013

Re: Reading time on ZC706 through registers


@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).
0 Kudos
Visitor piyushj
Visitor
348 Views
Registered: ‎03-06-2019

Re: Reading time on ZC706 through registers

Thank yo very much for heads up!

0 Kudos