A test generator sends two equal pulses. The scope sees both, but the PIC16F18877 log has only the first. Its width converts correctly, and the board's 20 MHz quartz crystal passes an independent frequency check. Shorten the low interval between identical pulses, and see whether the point at which the second one is lost tracks the firmware's rearm time.
The gate needs to be rearmed after each acquisition
In Microchip's Timer1 single-pulse gate mode, software selects the mode and sets GGO/DONE. The next active gate edge allows counting, and the trailing edge automatically clears the bit. Subsequent gate events cannot advance Timer1 until software sets it again. This protects the completed measurement. Other work before rearming, however, can create a gap in acquisition.
The example takes FOSC/4 from the board's 20 MHz crystal and sets the Timer1 prescaler to one. That makes 5 MHz, or 0.2 µs per count. An independently generated 50 µs high pulse should produce a count near 250. Measure the low interval separately at the scope. A tick is the conversion scale, not a full timing guarantee for the gate, its synchronization, and the initial state.
Sweep through the interval where firmware misses an event
Clear and arm under a known initial state and generate one pulse. Verify its polarity, level, width, and monotonic edges at the input. Then use GPIO markers to show when software reads the result and rearms, and keep the raw counts and event IDs. Markers consume time. Verify the practical limit again without debugger halts and with as little added work as possible. Buffer measurements and send them to the host after the test.
Next, apply two pulses, both still 50 µs high. Suppose rearming takes about 32 µs from the first falling edge. Try low intervals of 60 and 20 µs. The second rising edge is about 28 µs after rearming in the long case and 12 µs before rearming in the short case. Expect different results. At the boundary, verify the actual ordering of the input edge and rearming. The illustrative delay is not a device gate timing specification.
Make the second pulse 70 µs high, or about 350 ticks, so its width identifies it in the log. Follow the short-interval pair with a third pulse after a long gap. A record with the first result, no 350-count result, and a recovered third result supports a missed edge during the unarmed interval if all three pulses are verified at the pin.
Make separate faults produce separate signatures
Add a known delay to the firmware before rearming, keeping the generator and initialization fixed. If the range of missing second pulses expands by that delay, the bench has reproduced the rearm bottleneck. Repeat with debug printing off to see whether the delay comes from serial output, a competing interrupt, or the capture read itself. Improving crystal accuracy changes the tick scale and cannot remove that acquisition gap.
Check for stale counts and flags as well. Record the initial count and follow the specified read and initialization sequence before rearming. If the long-gap second reading is consistently near 600, the sum of 250 and 350, see whether the counter retained the previous result. If the hardware flag changes on the second edge but the host sees one interrupt record, investigate the service routine and log. If the first width also disagrees with the scope, check input source, timer source, prescaling, and polarity independently.
Overflow can make a longer pulse look short. At 5 MHz, a 16-bit timer starting at zero completes 65,536 counts in 13.1072 ms. The product needs separate overflow handling if its pulses can exceed that range. Repeat with one pulse near the supported width limit to distinguish timer capacity from the rearm constraint.
Record a practical minimum gap
Restore the real loading and combine the shortest expected gap with the heaviest processing load. Compare generated pulses, counter results, and reported results over continuous traffic. Record logging and interrupt settings and retain the input trace and firmware markers. If reporting delays every rearm, move it outside the capture path or evaluate a continuous capture unit with buffered timestamps. Record the accepted continuous gap separately from the one-pulse result.
Repeat the same pulse pairs at stable temperature and record the longest rearm time as well as the typical value. The usable spacing needs margin for processing and gate setup. Deliberately reproduce one missed pulse and confirm that the station rejects it by sequence count even when both pulses have the same shape.
Compare the original and candidate 20 MHz quartz crystals with identical gate settings. If both capture every required event but the width scale moves with the reference frequency, check that frequency independently before deciding on the component. If valid widths are correct and missing events fall in the unarmed window, address the acquisition mechanism. Save one passing long-gap trace and one failing short-gap trace for repeatability.
