An ATmega328P is recording tachometer edges. A scope shows a short high pulse at the pin, but the program never registers another capture. Increasing the Timer1 count rate gives finer timestamps on other pulses without recovering this particular event. On a board with a 16 MHz passive crystal, follow two timing paths. Input edges pass through synchronization and optional digital filtering. A qualified edge then latches the current timer count into ICR1. The paths share a reference but are prescaled at different points.
The filter and counter use different clock points
The ATmega328P data sheet calls the input capture filter enable ICNC1. The filter changes its output after four consecutive equal samples. It uses the system clock regardless of the Timer1 prescaler. Enabling it adds four system clock periods between an input change and the ICR1 update. Input synchronization and interrupt service contribute their own timing.
Assume that the system clock is actually 16 MHz with no additional system divider. Each system clock period is 62.5 nanoseconds, so the filter adds 250 nanoseconds. With Timer1 divided by eight, the count advances every 0.5 microseconds. Set Timer1 to divide by 64 and it advances every four microseconds, while the filter still takes four system clocks. If the system itself slows to 8 MHz and Timer1 still divides by eight, the timer advances every microsecond and the filter adds 500 nanoseconds.
The same 16 MHz passive crystal remains on the board in these examples. CLKPR settings or the divider selected at reset can give the processor a different clock. Read both divider settings and exercise the timer with a known, steady signal. Compare two successive timestamps for edges of the same polarity and account for any counter wrap. Keep the generator's measured period alongside the speed reported by the application.
Separate input qualification from software delay
Apply a logic-compatible signal directly to the board input and measure against the board's ground. Start with well-spaced two-microsecond high pulses and confirm that capture works with the filter both enabled and disabled. Then try an ideal 100-nanosecond high pulse with valid input levels. At a 16 MHz system clock it cannot span four consecutive samples, so the filter should reject it. Whether the unfiltered path sees it depends on synchronization and its phase relative to the sampling clock. The specified 250 nanoseconds is the added latency in this setup. Qualification near the boundary depends on edge shape and sampling phase.
Log the raw ICR1 count and capture flag. An output toggled in the interrupt handler includes interrupt entry and instruction latency. It helps measure firmware response while ICR1 reports when the counter was captured. If new events arrive before the handler reads ICR1, a subsequent event can overwrite the earlier timestamp. Begin with isolated pulses and increase their arrival rate while comparing transmitted and captured event counts.
For period measurement, capture a single edge polarity. For pulse width on one capture unit, the data sheet calls for reading ICR1 promptly, changing the ICES1 edge selection, and clearing the flag after the change as specified. The illustrative two-microsecond pulse tests capture in one direction. Capturing both edges on that same pulse requires a separate check of the time to change edge selection. A common fixed delay can cancel in a timestamp difference, while system-clock sampling, counter quantization, and the software's edge switching can still affect the result.
Define the minimum valid sensor pulse
Find out whether the narrow input is interference to reject or a legitimate pulse from the sensor at its highest speed and lowest duty cycle. Use the longest cable and the real logic levels at the intended temperature and supply corners. Exercise widths around the minimum and vary phase with respect to system sampling. Measure at the MCU input. With a slow edge, the width determined at the pin's input thresholds can differ from a generator's nominal pulse width.
Record the count of valid captures, the number of captures caused by disturbances, and timestamp resolution. Changing the Timer1 prescaler can affect the resolution column without recovering a filtered edge. When testing another 16 MHz passive crystal of the same specification, keep the system divider, capture settings, and input trace in the test record and repeat the same pulse sequence.
If a valid two-microsecond pulse also goes missing, check that the selected timer mode supports input capture. The data sheet identifies waveform modes that use ICR1 as the counter's top value. In those modes the application cannot use ICR1 as an ordinary capture register. Check that the analog comparator has not been selected in place of the pin and that a library write has not changed edge selection. Restore the long-pulse baseline before comparing narrow pulses or crystal samples.
