
79
ATtiny40 [DATASHEET]
8263B–AVR–01/2013
The counter is incremented at each timer clock (clk
T1) until it passes its TOP value and then restarts from BOT-
TOM. The counting sequence is determined by the setting of the CTC1 bit located in the Timer/Counter Control
T1 can
be generated from an external or internal clock source, selected by the Clock Select bits (CS1[2:0]). When no clock
source is selected (CS1[2:0] = 0) the timer is stopped. However, the TCNT1 value can be accessed by the CPU,
regardless of whether clk
T1 is present or not. A CPU write overrides (has priority over) all counter clear or count
operations. The Timer/Counter Overflow Flag (TOV1) is set when the counter reaches the maximum value and it
can be used for generating a CPU interrupt.
12.5
Input Capture Unit
The Timer/Counter incorporates an Input Capture unit that can capture external events and give them a time-
stamp indicating time of occurrence. The external signal indicating an event, or multiple events, can be applied via
the ICP1 pin or alternatively, via the analog-comparator unit. The time-stamps can then be used to calculate fre-
quency, 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 shown in
Figure 12-2. The elements of the block diagram
that are not directly a part of the Input Capture unit are gray shaded.
Figure 12-2. Input Capture Unit Block Diagram
The Output Compare Register OCR1A is a dual-purpose register that is also used as an 8-bit Input Capture Regis-
ter ICR1. In 16-bit Input Capture mode the Output Compare Register OCR1B serves as the high byte of the Input
Capture Register ICR1. In 8-bit Input Capture mode the Output Compare Register OCR1B is free to be used as a
normal Output Compare Register, but in 16-bit Input Capture mode the Output Compare Unit cannot be used as
there are no free Output Compare Register(s). Even though the Input Capture register is called ICR1 in this sec-
tion, it is refering to the Output Compare Register(s).
When a change of the logic level (an event) occurs on the Input Capture pin (ICP1), and this change confirms to
the setting of the edge detector, a capture will be triggered. When a capture is triggered, the value of the counter
(TCNT1) is written to the Input Capture Register (ICR1). The Input Capture Flag (ICF1) is set at the same system
ICF0 (Int.Req.)
WRITE
ICR0 (16-bit Register)
OCR0B (8-bit)
Noise
Canceler
ICP0
Edge
Detector
TEMP (8-bit)
DATA BUS
(8-bit)
OCR0A (8-bit)
TCNT0 (16-bit Counter)
TCNT0H (8-bit)
TCNT0L (8-bit)
ICNC0
ICES0