Timer/counter prescaler, Special function io register – sfior, Atmega128(l) – Rainbow Electronics ATmega128L User Manual
Page 104

104
ATmega128(L)
2467B–09/01
Timer/Counter Prescaler
Figure 44. Prescaler for Timer/Counter0
The clock source for Timer/Counter0 is named clk
T0S
. clk
T0S
is by default connected to
the main system clock clk
OSC
. By setting the AS0 bit in ASSR, Timer/Counter0 is asyn-
chronously clocked from the TOSC1 pin. This enables use of Timer/Counter0 as a Real
Time Counter (RTC). When AS0 is set, pins TOSC1 and TOSC2 are disconnected from
Port C. A crystal can then be connected between the TOSC1 and TOSC2 pins to serve
as an independent clock source for Timer/Counter0. The oscillator is optimized for use
with a 32.768 kHz crystal. Applying an external clock source to TOSC1 is not
recommended.
For Timer/Counter0, the possible prescaled selections are: clk
T0S
/8, clk
T0S
/32, clk
T0S
/64,
clk
T0S
/128, clk
T0S
/256, and clk
T0S
/1024. Additionally, clk
T0S
as well as 0 (stop) may be
selected. Setting the PSR0 bit in SFIOR resets the prescaler. This allows the user to
operate with a predictable prescaler.
Special Function IO Register –
SFIOR
• Bit 7 - TSM: Timer/Counter Synchronization Mode
Writing TSM to one, PSR0 and PSR321 becomes registers that hold their value until
rewritten, or the TSM bit is written zero. This mode is useful for synchronizing
timer/counters. By setting both TSM and the appropriate PSR bit(s), the appropriate
timer/counters are halted, and can be configured to same value without the risk of one of
t h em a d v a n c i ng d u ri ng c o nf i g u ra t i o n . W h e n th e T SM b i t wr i tt e n z e ro , t h e
Timer/Counters start counting simultaneously.
10-BIT T/C PRESCALER
TIMER/COUNTER0 CLOCK SOURCE
clk
OSC
clk
T0S
TOSC1
AS0
CS00
CS01
CS02
clk
T0S
/8
clk
T0S
/64
clk
T0S
/128
clk
T0S
/1024
clk
T0S
/256
clk
T0S
/32
0
PSR0
Clear
clk
T0
Bit
7
6
5
4
3
2
1
0
TSM
–
–
ADHSM
ACME
PUD
PSR0
PSR321
SFIOR
Read/Write
R/W
R
R
R/W
R/W
R/W
R/W
R/W
Initial value
0
0
0
0
0
0
0
0