There are 4 16 bit timers, which count up according to either a specified frequency or via a cascade. When a timer overflows (crosses from FFFF to 0000), other timers can be incremented (if the cascade bit in the following timer is set), and an interrupt can occur, if the interrupt request bit is set.
Timers are useful for implementing the passage of time in a game, to profile code, or when producing sound.
TIMERx_CR
)Offset | Name | Type | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
$102 | TIMER0_CR | Read Write |   | Enabled | Trigger IRQ |   | Cascade Mode | Frequency | ||||||||||
$106 | TIMER1_CR | Read Write |   | Enabled | Trigger IRQ |   | Cascade Mode | Frequency | ||||||||||
$10A | TIMER2_CR | Read Write |   | Enabled | Trigger IRQ |   | Cascade Mode | Frequency | ||||||||||
$10E | TIMER3_CR | Read Write |   | Enabled | Trigger IRQ |   | Cascade Mode | Frequency |
TIMER_CLK
)TIMER_CLK_DIV_64
)TIMER_CLK_DIV_256
)TIMER_CLK_DIV_1024
)TIMER_CASCADE
.
TIMER_IRQ_ENABLE
.
TIMER_ENABLED
.
TIMERx_DATA
)
Offset | Name | Type | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
$100 | TIMER0_DATA | Read Only | Current timer value | |||||||||||||||
$104 | TIMER1_DATA | Read Only | Current timer value | |||||||||||||||
$108 | TIMER2_DATA | Read Only | Current timer value | |||||||||||||||
$10C | TIMER3_DATA | Read Only | Current timer value |
Offset | Name | Type | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
$100 | TIMER0_DATA | Write Only | Timer latch value | |||||||||||||||
$104 | TIMER1_DATA | Write Only | Timer latch value | |||||||||||||||
$108 | TIMER2_DATA | Write Only | Timer latch value | |||||||||||||||
$10C | TIMER3_DATA | Write Only | Timer latch value |
Reading a timer data register returns the current value of the timer.
Any value written to a timer data register sets the latch for that timer. A write to a latch doesn't modify the value read from the register immediately, it is loaded into the timer whenever it overflows. For instance, writing FFFFh
would result in the timer overflowing every time it counts up. The default value in the latches is 0000h
.
Example: timer usage.
// fixme: insert code here
Copyright © 2001 to 2002, Bottled Light, Inc.