Repository navigation
Stamp chunks from a scan-count fit; add timestamp_offset_us - #10
Merged
Merged
Conversation
Timestamps were the poll time, 627 us late on average with 297 us SD (measured on a Pi 5 against a bracketed GPIO edge). Now each chunk is stamped from a lower-envelope line of scan count vs. poll time over the last 30 s, which tracks the device/host rate ratio. If recent polls sit above the line (host clock slewed by NTP), the line is lifted to them. - timestamp_offset_us (config) / --ts-offset-us (CLI) subtracts the remaining fixed transport latency (~93 us on a Pi 5); default 0. - scripts/gpio_latency_test: Raspberry Pi 5 procedure to measure it. Result on Pi 5: mean 95-97 us, SD ~7.5 with offset 0; mean 2.8 us with offset 93 (SD is mostly the test's 20 us sample spacing).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9.
Changes
MCCDevice::stampFor): each poll that sees new scans records(scan count, local_clock()). The chunk stamp comes from the line under all points of the last 30 s that is highest at their mean count (lower convex hull edge). This removes the 0–1 ms poll delay and tracks the DAQ/host rate ratio. Reset on scan restart.timestamp_offset_us(config file, saved/loaded by the GUI) /--ts-offset-us(CLI): subtracted from every stamp. Default 0.scripts/gpio_latency_test: Raspberry Pi 5 calibration (GPIO edge bracketed inCLOCK_MONOTONIC→ DAQ CH1).Measurements (Pi 5, Debian 13, USB-1608FS-Plus, 2 ch @ 50 kHz, ~1200 edges / 300 s, all localhost, inlet without clock sync)
SD is mostly the 20 µs sample spacing of the edge measurement.
Window/guard choice from offline replay of dumped poll points (15 min run): a 120 s window wanders ~1.4 µs less on a free-running clock, but under an NTP ramp (0.075 ppm/s, as observed) 30 s stays within ~5 µs vs ~15 µs. Synthetic 200–500 ppm slews: unguarded hull errs 11–15 ms, guarded worst case 300–400 µs. CPU unchanged (1 ms polling, ~5% on the Pi).
macOS (Mac mini, Apple silicon, macOS 27)
DAQ on the Mini, Pi GPIO16 → CH1; Pi
CLOCK_MONOTONIC→ PiCLOCK_REALTIME(gPTP grandmaster over a direct cable) → Mini mach_absolute via hardware-timestamped gPTP sync pairs →local_clock.Uncertainty: ~1 µs from the reference plus the unknown fixed offset of the Mac's adapter→mach cross-timestamp.
Rate/channel sweep (offset 0, 300 s each): the latency depends on acquisition settings, so the README now says to calibrate at your own settings.
Evaluated and dropped: DIO loopback calibration
Toggling the DAQ's own DIO0 (looped to an AI) with
ulDBitOutbracketed bylocal_clock(): the write takes 1.07–1.72 ms (full-speed control transfer) and the pin switches 0.71–1.39 ms into it, so truth-free bounds were −156 ≤ λ ≤ 813 µs. The out/in split is a host USB-stack property, so it cannot calibrate λ.