Audio Production
Timer rollover: elapsed bounds and coherent wrap evidence
Timer rollover preserves elapsed ticks modulo a counter range. Compare interval bounds, half-range ordering and the evidence needed for coherent wrap counts.

A wrapping timer can measure a short interval that crosses its maximum count. The count moves from its largest value to zero, but a modular difference still preserves the elapsed ticks within an appropriate bound. It does not reveal how many complete counter periods passed unseen.
Timer rollover preserves an elapsed count modulo the counter range. Recovering one physical interval from that residue requires an independently established bound or additional retained information. The crossing itself can be usable even though complete unseen periods remain ambiguous.
Elapsed-time recovery and temporal ordering also need different premises. A bound sufficient to identify a nonnegative elapsed interval can be too weak for a generic before-or-after comparison on a ring.
How modular arithmetic follows the counter through zero
Use a hypothetical counter with 256 states, numbered zero through 255. It advances one count per tick and returns to zero after 255. Let its modulus M be 256. Two captured endpoint counts are a equal to 250 and b equal to 7.
The ordinary numerical difference b minus a is minus 243. Its residue modulo 256 is 13. That result matches six ticks from 250 to zero followed by seven ticks from zero to 7.
The modular difference is computed in the mathematical counter domain defined here. It does not assert how a particular programming language evaluates an integer expression, promotes types, or handles signed overflow. Those implementation rules need their own validation.
The timer-input-capture guide gives the acquisition contract needed before using modular arithmetic on saved counts. Its hardware-latch boundary differs from a later handler-read boundary, and it explicitly requires a modulus plus an interval bound or extra wrap evidence for a wrapping timer. Once the endpoints belong to the intended events, the residue argument here determines what duration information they retain.
For a true elapsed count Δ, the final count satisfies b equal to a plus Δ modulo M. Subtracting endpoints therefore gives Δ modulo M. The wrap has preserved that residue while discarding the number of complete periods.
How counter wraparound leaves complete periods ambiguous
The endpoint pair 250 and 7 is consistent with Δ equal to 13, 269, 525, and any larger value obtained by adding another 256 ticks. Each interval ends at the same count because the added complete periods do not change the residue.
With Δ equal to 13, the path crosses zero once. With Δ equal to 269, it crosses zero twice from this starting count. The endpoint values alone cannot choose between those histories.
A known bound of zero no greater than Δ and Δ strictly less than M selects exactly one residue representative in that interval. Under that bound, 13 is the unique elapsed count. The bound includes intervals crossing zero and is not a requirement that the endpoint count increase numerically.
If Δ can equal M, a zero residue is already ambiguous between no elapsed ticks and one complete counter period. Equal endpoint counts do not prove zero duration. The strict upper bound matters at that boundary. To verify uniqueness, suppose two nonnegative intervals smaller than M have the same residue. Their difference must be an integer multiple of M, but its magnitude is smaller than M. The only such multiple is zero, so the two intervals are equal. Removing the bound removes that argument.
The monotonic-clock guide provides a domain and lifecycle check when interpreting counter wraparound. It requires readings used for a duration to share a valid clock domain and lifecycle, and explains that a reset can change the origin. A normal wrap in the declared ring and a domain reset are different histories. That guide does not derive the modular bound; it supports checking whether the counter progression assumed by the calculation remained applicable.
Even a correctly computed residue cannot reconstruct evidence that was never retained. Assigning zero complete periods because it is convenient would turn an interval assumption into a fabricated observation.
The Linux clocksource documentation describes finite counters that advance from zero to their maximum and wrap back to zero. It also requires coherent reads, because reading low and high portions across an update can produce an invalid combined value. Its clocksource mask records which bits are valid so the timekeeping code can handle wrapping. These are documented implementation requirements, not evidence that any arbitrary pair of raw readings identifies an unlimited interval.
Use an interval bound that matches the observation
The elapsed bound can come from a guaranteed maximum time between the relevant observations, an independently established event window, or additional retained state. It must apply to the actual endpoint acquisition interval. A desired polling rate is not a guarantee that every poll occurred within the bound.
Suppose one tick represents one millisecond in a declared model. The counter period is 256 milliseconds. The residue 13 represents 13 milliseconds only when the interval is known to be less than 256 milliseconds and the endpoints belong to the same counter lifecycle.
An unexpectedly delayed observation can violate that premise while producing an ordinary-looking residue. A 269 millisecond interval still produces 13. The arithmetic has not failed; the bound needed to interpret it has failed.
The model also assumes intentional progression through every count. A reset to zero or a change of counter domain is another event, not a normal wrap under the same equation. Endpoint subtraction across that discontinuity requires separate information.
The tick-to-time conversion is stipulated here; tick-rate calibration needs separate evidence. The modular difference identifies ticks only after the observation bound selects one consistent interval.
Half-range ordering uses a stricter convention
Sometimes the task is to determine whether one count is before or after another, without first supplying their direction in real time. A ring has no globally unique order. The count 7 can be shortly after 250 through zero, or far before it along a different admitted history.
A common local ordering convention interprets residues smaller than half the modulus as positive displacement and residues larger than half as negative displacement. For M equal to 256, the open positive range is below 128 ticks. A residue exactly 128 is equally far in the two directions and cannot receive an unambiguous order from that convention. Subtracting the endpoints in the reverse direction also produces 128, because 256 minus 128 equals 128. The same nonzero residue therefore appears for both orientations. Assigning it positive in both would violate a consistent before-and-after relationship; the convention must exclude or separately resolve that boundary.
This requires the true signed separation relevant to the comparison to lie within the chosen half-range. It is stricter than knowing a nonnegative elapsed interval is less than 256. The two operations solve different questions.
For example, if an independently known forward elapsed interval is 200 ticks, modular subtraction correctly returns 200 under the less-than-256 elapsed bound. A half-range signed interpretation instead assigns that residue a displacement of minus 56. Applying the ordering convention to that known-forward interval would use an invalid ordering premise.
A deadline comparison needs its own creation and observation bounds. Declaring a deadline on the ring without limiting how far ahead it was placed or how long observation was delayed can make a local before-or-after test misleading.
Establish the mathematical half-range bounds, then verify the chosen language-level comparison under its implementation rules. A signed expression alone supplies no evidence that the observed endpoints satisfy those bounds.
The Linux jiffies header provides a concrete local comparison implementation: time_after checks the sign of a converted unsigned-long difference. That source demonstrates a particular type-checked implementation pattern. Its presence does not justify using every possible separation on the counter ring; the half-range convention still needs the observation and deadline bounds described here, and other language implementations need their own validation.
A wrap count adds information if it is coherent
Separately retaining the number of wraps can extend the available count. If W is the complete-period count and c the raw timer value, an extended coordinate can be formed as WM plus c under the declared lifecycle. Subtracting coherent extended endpoints then uses the additional wrap evidence.
Maintaining W requires reliable observation or hardware support for every relevant wrap. If multiple wraps occur while one pending indication is retained, the indication may not contain their number. A software variable labeled wrap count is not proof that no wrap was missed. For a hypothetical single pending flag, two wraps before service can leave the same flag state as one wrap. Suppose the initial extended value is W equal to 10 and raw count 250, giving 2,810. After 269 ticks, the correct state is W equal to 12 and raw count 7, giving 3,079. If service increments W only once from the pending flag, it instead forms 2,823 and reports an interval of 13. The mistaken extended value reproduces the original residue ambiguity because the second wrap was never retained.
The wrap count and raw count must also describe the same boundary. If a reader obtains the old W just before a rollover and the new low raw count afterward, it can construct an extended value one full period too small. The opposite mixture can produce a value too large.
A coherent snapshot rule or another documented acquisition method is therefore part of the extended-counter evidence. Adding more numeric bits changes the information available only when their update and observation are reliable.
A stored electrical waveform can supply a separate observation of accessible events. Waveform export and storage are described for SKU 18623303850 on the Unbranded ZT-703S Electrical Testing page. Such a record can support an independently justified interval observation. The listing supplies no modulus, reset history, wrap retention, or coherent snapshot rule for an external timer. Connecting the waveform interval to that timer still requires the acquisition-domain relationship.
A waveform can show an accessible event interval while a software record shows raw counts. Connecting those observations requires a justified timing relationship and domain identity. A stored file does not independently supply an unseen wrap count.
An audio-acquisition record has its own sample rate and lifecycle. Four inputs and USB-C connectivity on the Focusrite AMZFCS4I4CR3X Red 4i4 Kit page, SKU 1894010824, identify that acquisition context; the listed balanced outputs and recording accessories accompany it. This product description contains no external timer-wrap ledger or snapshot contract. A recorded sample interval therefore cannot certify how many unobserved periods passed in a separate counter.
A duration record can retain both endpoint counts, modulus, lifecycle identity, and the independent maximum-interval evidence. If extended counts are used, it can also retain the wrap-acquisition and snapshot contract. Those details expose whether 13 meant a bounded short interval or only a residue shared by longer histories.