Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Division by zero in /usr/share/web/joat/webshare/ds/index.php on line 1101

Warning: Cannot modify header information - headers already sent by (output started at /usr/share/web/joat/webshare/ds/index.php:1101) in /usr/share/web/joat/webshare/ds/index.php on line 885
NDSTech Wiki : Timers browse
System /
Timers

Menu

Getting Started

System Information

Misc

 Note: Stub article.

Timers in a nutshell

A timer is simply a special kind of counter. There is a master clock of 33.4 MHz, and an enabled counter normally goes up by one on each beat of this clock. There is a piece of hardware called a prescaler associated with each timer, which allows it to count up every 64, 256, or 1024 clocks instead of after every one. Timers can also be cascaded together, so that one will count up when the timer below it overflows, instead of being based directly on the clock.

The timers are 16 bit unsigned numbers, i.e. they can count up to 65536, after which they will overflow. When a timer overflows, it reloads the counter with a latched value and will trigger an interrupt if you have requested it.

The latch is set whenever you write to the timer data register, and cannot be read. This latched value is only loaded into a timer when it is re-enabled, or when it overflows (a write just sets the latch, and does not directly affect the counter).

To make a timer overflow at a particular frequency, you set the latch accordingly. A timer with a latched value of 0 counting at 33.4 MHz / 1024 will overflow every 65536*1024 clocks, or about once every two seconds. To make the same timer overflow with a period of X seconds, the calculation looks like:

 latch = 65536 - X*33400000/1024

For an arbitrary timer, change the 1024 depending on the prescaler.

Register Details

LocationRegisterType15..8765..321..0
0x04000102:16TIMER_CR(0)R/W0EnableIRQ00Prescaler
0x04000106:16TIMER_CR(1)R/W0EnableIRQ0CascadePrescaler
0x0400010A:16TIMER_CR(2)R/W0EnableIRQ0CascadePrescaler
0x0400010E:16TIMER_CR(3)R/W0EnableIRQ0CascadePrescaler
  • Prescaler setting (controls counting frequency) (bits 0-1)
    • 00: Every clock
    • 01: Every 64 clocks
    • 10: Every 256 clocks
    • 11: Every 1024 clocks
  • Cascade (bit 2):
    • When set, the timer is part of a cascade chain timer, in which the lower timer's overflow is the update frequency, and the frequency bits are ignored. This bit is ignored for timer 0, since it does not have a lower timer to cascade from.
  • IRQ (bit 6)
    • When set, an interrupt request is generated each time the timer overflows.
  • Enabled (bit 7)
    • When set, the timer proceeds as normal, otherwise the timer is halted.
LocationRegisterTypeDescription
0x04000100:16TIMER_DATA(0)RGet count
0x04000100:16TIMER_DATA(0)WSet latch
0x04000104:16TIMER_DATA(1)RGet count
0x04000104:16TIMER_DATA(1)WSet latch
0x04000108:16TIMER_DATA(2)RGet count
0x04000108:16TIMER_DATA(2)WSet latch
0x0400010A:16TIMER_DATA(3)RGet count
0x0400010A:16TIMER_DATA(3)WSet latch

Note:

  • Latch writes do not take effect immediately. The latch is only transferred into the counter on an overflow, or when the enable bit in the corresponding control register is set.
  • Timers (and almost all other hardware) runs off of a 33.4 MHz clock
Recent Changes (All) | Edit SideBar

Page last modified on February 04, 2006, at 12:10 AM
Edit Page | Page History
Everything done on this project is for the sole purpose of writing interoperable software under Sect. 1201 (f) Reverse Engineering exception of the DMCA.
This site is not affiliated with Nintendo in any manner. Nintendo DS © 2004 Nintendo. TM and ® are trademarks of Nintendo.
Powered by PmWiki