1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 18:35:54 +02:00

Picking time in the middle of the interval, not its edge, and reduce

error bound.

- cntr/tools/cntr/cntr.c (measure): use the middle of a round-trip interval
  for the sample's nominal time
- cntr/tools/cntr/cntr.c (measure): error bound is only +/- RTT/2, not
  +/- RTT
This commit is contained in:
Werner Almesberger 2010-08-26 00:52:50 -03:00
parent 5b73e8bb75
commit 85ab2c41d5

View File

@ -192,7 +192,7 @@ static void measure(usb_dev_handle *dev, double clock_dev_s, double error_goal)
usleep(100000); usleep(100000);
while (!get_sample(dev, &now)); while (!get_sample(dev, &now));
dc = now.cntr-start.cntr; dc = now.cntr-start.cntr;
dt = now.t0-start.t0; dt = (now.t0+now.t1)/2.0-(start.t0+start.t1)/2.0;
f = dc/dt; f = dc/dt;
if (f > 1000000.0) { if (f > 1000000.0) {
f /= 1000000.0; f /= 1000000.0;
@ -207,9 +207,9 @@ static void measure(usb_dev_handle *dev, double clock_dev_s, double error_goal)
error = 1.0/dc; /* one count */ error = 1.0/dc; /* one count */
else else
error = 0; error = 0;
error += (start.t1-start.t0)/dt;/* start sample read */ error += (start.t1-start.t0)/dt/2.0; /* start sample read */
error += (now.t1-now.t0)/dt; /* last sample read */ error += (now.t1-now.t0)/dt/2.0; /* last sample read */
error += clock_dev_s/dt; /* system clock deviation */ error += clock_dev_s/dt; /* system clock dev. */
if (error >= 1) { if (error >= 1) {
printf("\r(wait) "); printf("\r(wait) ");
fflush(stdout); fflush(stdout);