[time-nuts] Time syncing question

Tom Van Baak tvb at leapsecond.com
Mon Aug 28 20:01:59 EDT 2006


> Tom, thanks for your very clear and simple reply. I may be over thinking
> about the problem and trying to make it more complicated than it is.
>
> The target device is a phone system. The time is used for call logging and
> display on the phones. Considering that the device's RTC doesn't keep very
> good time now, do you think I should worry about adjusting the time
> incrementally, or just do it in one jump? I'm mostly concerned about a
> negative time correction. This would certainly throw off the logging. On
the
> other hand, a large + or - time correction would be a one-time situation
and
> would be easily spotted in the log.

I'd say one jump if you just want to get the job done,
but incrementally if you want a cleaner solution or if
you think you might need to do this more than once.

Given that you can't change the firmware inside the
phone gizmo, about all you can do it replace one
large visible jump with many small invisible jumps
spread over time. Easy to do.

Here's what I did on a similar project a while back.
Your specs aren't quite the same as mine, but
you get the idea. My goal was to slowly adjust
time by N seconds -- in small 1/4 second jumps
timed such that a user would not likely see whole
number seconds ever go negative. It worked pretty
well. The pseudo code went something like this:

    // see if device time needs to be reset
    while (1) {
        dt = get_PC_time() - get_device_time()
        if (abs(dt) > 1 second) {
            wait_for_half();
            bump_by_quarter();
        }
        sleep a few seconds; // limit slew rate
    }

    // wait until near the middle of a second
    wait_for_half() {
        while (1) {
            ms = get_device_time to ms accuracy mod 1 second
            if (ms >= 350 or ms <= 650) {
                break;
            }
            sleep 50 ms
        }
    }

    // advance/retard device time by 1/4 second
    bump_by_quarter(dt) {
        if (dt > 0) {
            set_device_time(get_device_time() + 250 ms)
        } else {
            set_device_time(get_device_time() - 250 ms)
        }
    }

Something like this should work for you too.

/tvb







More information about the time-nuts mailing list