Skip to content

feat: add -rtc flag to measure Notecard RTC drift#69

Merged
rayozzie merged 1 commit into
masterfrom
ray/us
May 26, 2026
Merged

feat: add -rtc flag to measure Notecard RTC drift#69
rayozzie merged 1 commit into
masterfrom
ray/us

Conversation

@rayozzie
Copy link
Copy Markdown
Contributor

Add a -rtc flag that measures the drift of the Notecard's real-time clock against the host computer's clock, emitting one line per second for seconds:

rtc: avgDriftMsPerSecond: driftSecsPerDay:

Each second the host clock is sampled alongside the Notecard's clock via card.time with "now":true, which reports the time as a floating-point . value.

To keep the reported figures stable rather than dominated by per-sample USB/serial latency jitter, two techniques are used:

  • Minimum round-trip filtering: each sample takes several rapid reads and keeps the one with the lowest host round-trip time, using the round-trip midpoint as the aligned host timestamp.

  • Least-squares regression: instead of deriving the rate from just the baseline and the current sample, the drift (microseconds of drift since start) is regressed against host-elapsed time across every sample collected so far. The slope is the drift rate, so per-sample noise averages out and both reported figures converge as the run lengthens. Regressing the drift residual directly avoids the catastrophic cancellation of computing a slope near 1.0 and subtracting 1.

Add a -rtc <n> flag that measures the drift of the Notecard's real-time
clock against the host computer's clock, emitting one line per second for
<n> seconds:

  <n> rtc: avgDriftMsPerSecond:<rate> driftSecsPerDay:<projected>

Each second the host clock is sampled alongside the Notecard's clock via
card.time with "now":true, which reports the time as a floating-point
<epoch-seconds>.<microseconds> value.

To keep the reported figures stable rather than dominated by per-sample
USB/serial latency jitter, two techniques are used:

  - Minimum round-trip filtering: each sample takes several rapid reads
    and keeps the one with the lowest host round-trip time, using the
    round-trip midpoint as the aligned host timestamp.

  - Least-squares regression: instead of deriving the rate from just the
    baseline and the current sample, the drift (microseconds of drift
    since start) is regressed against host-elapsed time across every
    sample collected so far. The slope is the drift rate, so per-sample
    noise averages out and both reported figures converge as the run
    lengthens. Regressing the drift residual directly avoids the
    catastrophic cancellation of computing a slope near 1.0 and
    subtracting 1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rayozzie rayozzie merged commit a94389a into master May 26, 2026
1 check passed
@rayozzie rayozzie deleted the ray/us branch May 26, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant