Input capture functions like output compare in reverse. Instead of generating an edge on the TCMP pin at a specific time, input capture saves the time at which a specific edge occurs on the TCAP pin.
The IEDG bit in the timer control register (TCR) specifies whether rising or falling edges are recognized by the input capture hardware. When a capture occurs, the input capture flag (ICF) bit in the timer status register (TSR) is set, and an interrupt will be generated if the input capture interrupt enable (ICIE) bit in TCR is set.
To clear ICF, read the input capture register high (ICRH) byte. This prevents further captures and latches the low byte of the result until ICRL is read.
In the wheel speed sensor shown above, each rotation of the bicycle's front tire closes the magnetic switch. This generates a falling edge that is detected by the input capture hardware. The number of wheel rotations that occurs during a given period of time is directly proportional to the distance traveled.
When the MC68HC705P6A is clocked with a 4.194 MHz crystal, the 16-bit counter overflows eight times per second. This allows the cycling monitor to accurately update and display the speed and distance traveled every one and ten seconds, respectively.