Datasheet

Table Of Contents
19.4. Timer/Counter Clock Sources
The Timer/Counter can be clocked by an internal or an external clock source. The clock source is
selected by the clock select logic which is controlled by the clock select (CSn2:0) bits located in the
Timer/Counter Control Register B (TCCRnB). For details on clock sources and prescaler, see Timer/
Counte1 and Timer/Counter0 Prescalers.
Related Links
Timer/Counter0 and Timer/Counter1 Prescalers on page 102
19.5. Counter Unit
The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. The
figure below shows a block diagram of the counter and its surroundings.
Figure 19-2. Counter Unit Block Diagram
TEMP (8-bit)
DATA BUS (8-bit)
TCNTn (16-bit Counter)
TCNTnH (8-bit) TCNTnL (8-bit)
Control Logic
Count
Clear
Direction
TOVn
(Int.Req.)
Clock Select
TOP BOTTOM
Tn
Edge
Detector
( From Prescaler )
clk
Tn
Signal description (internal signals):
count Increment or decrement TCNTn by 1.
direction Select between increment and decrement.
clear Clear TCNTn (set all bits to zero).
clk
Tn
Timer/Counter clock.
TOP Signalize that TCNTn has reached maximum value.
BOTTOM Signalize that TCNTn has reached minimum value (zero).
The 16-bit counter is mapped into two 8-bit I/O memory locations: counter high (TCNTnH) containing the
upper eight bits of the counter, and Counter Low (TCNTnL) containing the lower eight bits. The TCNTnH
Register can only be indirectly accessed by the CPU. When the CPU does an access to the TCNTnH I/O
location, the CPU accesses the High byte temporary register (TEMP). The temporary register is updated
with the TCNTnH value when the TCNTnL is read, and TCNTnH is updated with the temporary register
value when TCNTnL is written. This allows the CPU to read or write the entire 16-bit counter value within
one clock cycle via the 8-bit data bus. It is important to notice that there are special cases of writing to the
TCNTn Register when the counter is counting that will give unpredictable results. The special cases are
described in the sections where they are of importance.
Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each
timer clock (clk
Tn
). The clk
Tn
can be generated from an external or internal clock source, selected by the
clock select bits (CSn2:0). When no clock source is selected (CSn2:0 = 0) the timer is stopped. However,
Atmel ATmega32A [DATASHEET]
Atmel-8155I-ATmega32A_Datasheet_Complete-08/2016
110