What is Input capture?

A timer function in which hardware records the counter value at the instant an input signal changes, allowing precise measurement of pulse width or frequency.

Field: Embedded Systems & Firmware

Japanese name: インプットキャプチャ

How it works

The timer counter runs continuously from a fixed clock. When the input pin sees the selected edge, rising, falling or both, hardware copies the counter value at that instant into a capture register and sets a flag, optionally notifying software with an interrupt or a DMA request. Because hardware takes the value, a slow interrupt response does not shift the recorded time. Many microcontrollers also offer an input filter that ignores short glitches and a prescaler that captures only every few events.

Measuring pulse width and frequency

The difference between two captures on the same edge is the period, and the difference between a rising-edge and a falling-edge capture is the pulse width. Multiplying by the timer clock period converts counts to time; at 1 MHz, for example, the resolution is 1 µs. If the counter runs through its full range, unsigned subtraction handles one wrap-around between captures correctly, but longer intervals require counting overflows too. For high-frequency signals, counting pulses over a fixed time gives better accuracy.

Input capture vs. output compare

Input capture records when something happened outside the chip. Its counterpart, output compare, works on the output side: when the counter reaches a set value, it changes an output pin or raises an interrupt, and it is also used to generate PWM. Typical uses of input capture include measuring the pulse period from a speed sensor, timing the echo of an ultrasonic range finder, decoding infrared remote-control signals and measuring the duty cycle of PWM produced by another device.

Try it: questions about Input capture

What is the input capture function of a microcontroller timer used for?

  1. ATo capture and save a screen image
  2. BTo record the counter value at the instant an input signal changes, precisely measuring pulse width or frequency
  3. CTo output a PWM signal from a pin
Show answer and explanation

Answer: B. To record the counter value at the instant an input signal changes, precisely measuring pulse width or frequency

With input capture, hardware copies the timer counter into a register at the instant the input signal rises or falls. The difference between two captured values gives the pulse width or period. Reading the time in software after an interrupt adds error from processing delays, but this method measures precisely regardless of them. It is used with rotation sensors, ultrasonic rangefinders and the like.

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary