A vibration recorder has a 20 MHz passive quartz crystal next to the microcontroller. Its frequency is close to nominal on the bench, yet the LSM6DSO log slowly separates from another recorder after the two start in alignment. Before tightening the clock specification, find out which device generated each timestamp. The time of a mechanical event, the sensor’s count, and the time when the host reads the sensor can all end up in the same column.
Trace the clock to the counter
In this example the host oscillator uses the 20 MHz passive crystal. Its clock is divided for a host timer. The LSM6DSO can provide its own timestamps alongside sensor data. ST application note AN5192 explains how the four timestamp registers form a 32-bit unsigned count and gives a nominal 25 µs step. This count uses the sensor’s timing base. The host SPI connection does not transfer the host oscillator's time base to that counter.
A host timer captured when a data read starts records the bus transaction. A sample can sit in a FIFO, or wait while an interrupt is serviced. An occasional delay under load can move the host read time back and forth. A growing discrepancy over successive windows makes it worth comparing the rates of the two clocks independently.
Convert the same count twice
The AN5192 timestamp section gives an adjustment for the nominal 40,000 steps per second. Multiply the nominal rate by one plus the decoded calibration value times 0.0015, then take the reciprocal to obtain seconds per step. Suppose the decoded calibration value for the example device is +10. The rate would be 40,600 counts per second, or approximately 24.63 µs per step. A difference of 40,000 counts corresponds to about 0.98522 s, even though fixed nominal scaling reports one second. The 14.78 ms discrepancy in this example checks unit and sign handling. Production settings must come from the actual sensor.
For another check, apply an independent ten-second reference interval. With the assumed rate, the count should advance by about 406,000. Fixed scaling at 25 µs reports 10.15 seconds. Replacing the host’s crystal with a perfectly accurate 20 MHz active oscillator would leave the calculation error in that sensor-derived column. Apply the vendor's conversion to the real calibration reading before investigating temperature effects or synchronizing the two time bases.
Separate slope, delivery delay and wraparound
Use an independent timing reference to trigger host capture at regular intervals where practical. Save the raw sensor counter, host capture count, FIFO or data-ready state, and when the host actually read the data. A persistent slope supports checking the timestamp multiplier. Errors clustered around host activity support examining interrupt or bus delay. Jumps limited to sleep, reset or rollover need event boundaries in the log. A straight-line fit over one run cannot restore a period in which the clock stopped.
At the nominal 25 µs step, a 32-bit counter takes about 29.83 hours to wrap. The ST application note also states that the timestamp counter does not operate when both sensing units are powered down. Use unsigned differences for continuous samples spaced less than one rollover period apart. Start a new time segment after a reset or a gap that makes the count ambiguous. Test wrap boundaries by replaying raw counters and check stop and restart behavior on hardware.
Sometimes the separation is approximately constant. Apply a repeatable mechanical stimulus at a fixed location and capture its trigger on an independent recorder. If the time difference stays similar even after a longer run, examine filter delay, detection thresholds and where the timestamp was assigned. If it grows with the observation window, return to the rate comparison. Record offset and slope separately.
Decide whether a crystal change is warranted
Measure the host clock against an independent reference first. Use a long enough interval to see frequency error, and compare the sensor counter’s rate over the same period. If the host misses its error allocation, examine load capacitance, layout and temperature for the 20 MHz passive crystal. For a 20 MHz active oscillator, verify the exact device's stability, supply and test load. A better host clock can improve the host time axis. Aligning the records still requires converting the sensor’s counters into that time domain.
On a purchasing request, write the crystal frequency, tolerance and package on the part line. Put timestamp scaling and sleep or reboot test conditions into the system acceptance criteria. Ask engineering which counter is responsible, when the error appears and whether it grows with time. Those three observations can determine whether to quote another oscillator, change the conversion code or rerun the timing test.
