Explainer
What decides time correlation in multi-device test data logging
Short answer
At roughly 1 Hz sampling, host receipt timestamps correlate camera frames, serial commands and thermocouple readings well enough for any skew budget of 100 milliseconds or wider. The budget itself is the deciding input. Only tolerances tighter than your measured transaction and transfer delays force a shared clock.
On this page
- How accurate do timestamps need to be for a 1 Hz test rig?
- What does each timestamp actually represent?
- How do I measure where my logging loop loses time?
- When do my devices need a shared clock?
- What is this kind of software called?
- How do I structure the logger so adding sensors does not shift the timing?
- What does every log record need so I can reconstruct the test later?
- Where should the logger run once it leaves the test bench?
- Questions asked
You do not need new logging software to fix this rig; you need a skew budget. Decide the largest acceptable time difference between a temperature reading, a motion event and a camera frame. At roughly 1 Hz sampling with serial transactions in the tens of milliseconds, host receipt timestamps hold correlation spread to around 25 milliseconds, so any budget of 100 milliseconds or wider runs without a shared clock. Tighter budgets buy device timestamps or one timing reference. This article gives the numbers, the check and the decision for each case.
How accurate do timestamps need to be for a 1 Hz test rig? #
At roughly 1 Hz sampling, host receipt timestamps are accurate enough whenever the acceptable skew between a temperature reading, a motion event and an image is 100 milliseconds or wider, because serial transactions and Gigabit frame transfers add only tens of milliseconds.
Sampling rate answers how often you record; it says nothing about how well two records must line up. That second number is a test requirement, not a software property, and no logger will propose it for you. Write it down as a skew budget: the largest time difference between a temperature value, a motion event and a frame that still leaves the test conclusion valid. A rig that only needs to know what the operator saw while the servo held position tolerates a quarter of the sample interval. A rig that has to establish whether motion preceded exposure needs an order of magnitude less.
Worked example, one sequential poll cycle on one worker, interval 1000 ms:
- Thermocouple frame, 32 bytes at 9600 baud with 8 data bits, no parity and one stop, which is 10 bits on the wire per byte: 32 × 10 ÷ 9600 = 0.033 s, so the message holds the line for 33 ms.
- Servo command and response, 8 bytes each way: (8 + 8) × 10 ÷ 9600 = 0.017 s, a 17 ms round trip.
- Camera frame, 1,000,000 bytes over Gigabit Ethernet: 1,000,000 × 8 ÷ 1,000,000,000 = 0.008 s, 8 ms of wire time.
The host stamps each arrival, so the stamps land at 33, 50 and 58 ms after the first request: a spread of 58 - 33 = 25 ms, or 2.5 percent of the interval. Decision: this rig runs on receipt stamps for any budget of 100 milliseconds or wider, and no shared clock is needed. What the arithmetic does not cover is the delay inside each device, from exposure end or thermocouple conversion to first byte on the wire, which the host cannot see; a budget tighter than those internal delays is not recoverable in software, it needs device-side stamps or a shared reference.
What does each timestamp actually represent? #
Stamp three separate moments and never merge them: when the host transmitted a command, when the response arrived, and when the device actually measured or exposed, which only a device-side timestamp can give and only when the vendor documents its clock and units.
A receipt stamp written when the response lands cannot recover the time the device spent measuring, buffering and queuing before it spoke, and relabeling response arrival as motion completion is wrong unless the controller's response body reports completion. Record the transmit stamp separately whenever command latency is part of the test. Production historians fail on exactly this distinction, and Why a PI value timestamp is not a receipt time works the same separation for archived process values.
How do I measure where my logging loop loses time? #
Time every stage with a monotonic clock for durations and a wall clock for calendar stamps, because wall-clock adjustments corrupt elapsed-time math and monotonic readings cannot be reviewed later against other records.
Four readings locate the loss:
- Command-to-response duration per transaction. A slow or missing response stalls every device behind it in a sequential loop; check framing and timeout handling before blaming the port.
- Scheduled poll time versus actual start. Drift that grows cycle over cycle means the scheduler is falling behind; compare total cycle time against the interval.
- Image retrieval duration. Host receive time includes the transfer and buffering the camera added after exposure.
- File-write duration and pending-record count. A queue that grows while acquiring means the writer cannot sustain the load; move writes to their own thread behind a bounded buffer.
If every stage finishes well inside the interval, leave the loop alone and fix only the stage that stalls. If the camera delivers more frames than the test records, select frames deliberately and mark the selection in the record; silent dropping makes later correlation untrustworthy.
When do my devices need a shared clock? #
Only a tolerance tighter than the delays you measured forces a shared timing reference: sub-millisecond host-to-device synchronization is commercially achievable, and a GPS-disciplined clock holds clock agreement to about one microsecond, so pick the rung from the budget instead of defaulting to hardware.
The ladder, cheapest first:
- Host receipt stamps: sufficient whenever the budget is wider than the measured transaction spread.
- NTP across the bench network: keeps device clocks aligned to a few milliseconds, adequate for budgets around ten milliseconds.
- IEEE 1588 PTP with hardware timestamping: sub-microsecond on supported Ethernet devices.
- GPS-disciplined reference: about one microsecond, usable where there is no network.
- Device-provided timestamps mapped to host time: no extra hardware, and the only rung left when a device has no synchronization input.
Decision: the rig in the worked example stops at the first rung; a budget at or below the transaction delays moves you to PTP, GPS or device stamps, chosen by the budget itself.
What is this kind of software called? #
Search for data acquisition and test and measurement logging software rather than data logging, because packages sold as DAQ software assume their own branded hardware and will not talk to your camera API or your servo protocol out of the box.
Whatever the label, a package passes or fails one check: does an adapter exist for every interface the rig uses, meaning camera acquisition, imager serial control, the servo protocol and the thermocouple messages. A logger that reads one supported device does not remove the other integrations, it relocates them. If nothing on the market passes the interface check, a small modular service with one adapter per interface is a legitimate end state at these sampling rates, not a failure; you keep the device access you already have and spend the effort on the fields in the record instead.
How do I structure the logger so adding sensors does not shift the timing? #
Give every interface its own adapter and its own worker, with the shared logger owning scheduling, formatting and storage, so a slow temperature response can never delay a motion record and a new sensor never inserts delay into devices already in service.
The adapter owns connection setup, framing, parsing, transaction timeouts and that device's error handling. Give each serial port a single owner, because competing readers consume each other's responses. Route unsolicited messages separately from pending replies, and overlap transactions only where the protocol can match a response to its request reliably. Validate a complete response before publishing a value, and keep malformed frames on disk for diagnosis rather than logging them as data. Stamp at receipt, before formatting or disk work. Keep motion limits and safe stopping in the servo controller; the logging application is not a substitute for the machine's safety functions.
What does every log record need so I can reconstruct the test later? #
Record six fields per record: device and channel identity, host receipt timestamp, the device's own timestamp when it exists, a sequence or transaction reference, the value with units and a quality state, and the image reference with frame metadata.
| Field | What it buys you |
|---|---|
| Device and channel identity | Separates values arriving from different interfaces |
| Host receipt timestamp | Puts every arrival on one host timeline |
| Device timestamp, when supplied | Preserves event timing with its documented clock and units |
| Sequence or transaction reference | Ties a response to its command and a frame to its trigger |
| Value, units, quality state | Separates valid readings from timeouts, parse failures and stale data |
| Image reference | Points from the event log to the frame stored out of band |
When a device keeps its own clock, store its original stamps and map each clock to host time; matching numeric values from unrelated clocks proves nothing. Why historian shows current time for backdated PLC data records the failure mode when software overwrites device stamps with its own clock instead.
Where should the logger run once it leaves the test bench? #
A service polling three devices at roughly 1 Hz writes a few kilobytes per second, so processing power never decides the host; the serial port count, sealed passive cooling and cabinet mounting decide it.
When the bench script becomes a permanent fixture at the rig, the choice turns into a hardware one: mount an industrial mini PC sized to the port count the rig actually uses, and carry the same adapters and stamps across unchanged. The correlation design above travels with the code. Final rule: define the skew budget first, run on receipt stamps whenever the budget is wider than your measured transaction spread, and spend on a timing reference only when the budget itself demands it.
Questions asked
One device offers no timestamp and no synchronization input, so what then?
Measure its offset once instead of guessing. Trigger a known event, compare the receipt stamp with the event time, and carry that measured offset as this channel's uncertainty from then on. The offset is part of the rig from the day it is measured and cannot be recovered after the fact, so write it into the test record beside the channel identity.
Should I store records as binary or ASCII?
At these sampling rates either format parses fast enough, so the write discipline matters more than the encoding. Use one writer thread, flush on a fixed interval or when the bounded buffer reaches a threshold, and keep images out of the record stream with a reference pointing to each stored frame. Binary saves disk; ASCII stays readable when a test is disputed.
How many sensors can I add before the timing breaks?
Apply a cycle budget: the sum of all transaction times on a shared worker should stay well under half the polling interval, so a single stalled transaction still fits inside the cycle. When one more device pushes the sum past that half, move its interface to its own serial port and worker thread instead of slowing every poll already in service.
Is Python fast enough, or does this need compiled code?
At one sample per second the language is never the bottleneck; blocking reads and one serial port doing every transaction are. Any language with thread support and serial libraries holds these budgets. Keep the stamp at receipt inside the reader, keep slow formatting and disk work in the writer, and interpreter overhead stays invisible in the numbers.