Datasheet

Table Of Contents
the TCNTn value can be accessed by the CPU, independent of whether clk
Tn
is present or not. A CPU
write overrides (has priority over) all counter clear or count operations.
The counting sequence is determined by the setting of the Waveform Generation mode bits (WGMn3:0)
located in the Timer/Counter Control Registers A and B (TCCRnA and TCCRnB). There are close
connections between how the counter behaves (counts) and how waveforms are generated on the Output
Compare Outputs OCnx. For more details about advanced counting sequences and waveform
generation, see Modes of Operation.
The Timer/Counter Overflow (TOVn) flag is set according to the mode of operation selected by the
WGMn3:0 bits. TOVn can be used for generating a CPU interrupt.
19.6. Input Capture Unit
The Timer/Counter incorporates an Input Capture unit that can capture external events and give them a
timestamp indicating time of occurrence. The external signal indicating an event, or multiple events, can
be applied via the ICPn pin or alternatively, via the Analog Comparator unit. The time-stamps can then be
used to calculate frequency, duty-cycle, and other features of the signal applied. Alternatively the time-
stamps can be used for creating a log of the events.
The Input Capture unit is illustrated by the block diagram below. The elements of the block diagram that
are not directly a part of the Input Capture unit are gray shaded. The small “n” in register and bit names
indicates the Timer/Counter number.
Figure 19-3. Input Capture Unit Block Diagram
ICFn (Int.Req.)
Analog
Comparator
WRITE
ICRn (16-bit Register)
ICRnH (8-bit)
Noise
Canceler
ICPn
Edge
Detector
TEMP (8-bit)
DATA BUS (8-bit)
ICRnL (8-bit)
TCNTn (16-bit Counter)
TCNTnH (8-bit) TCNTnL (8-bit)
ACIC* ICNC ICES
ACO*
When a change of the logic level (an event) occurs on the Input Capture Pin (ICPn), alternatively on the
Analog Comparator Output (ACO), and this change confirms to the setting of the edge detector, a capture
will be triggered. When a capture is triggered, the 16-bit value of the counter (TCNTn) is written to the
Input Capture Register (ICRn). The Input Capture Flag (ICFn) is set at the same system clock as the
TCNTn value is copied into ICRn Register. If enabled (TICIEn = 1), the Input Capture Flag generates an
Atmel ATmega32A [DATASHEET]
Atmel-8155I-ATmega32A_Datasheet_Complete-08/2016
111