gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > What is the effect of setting TimerX's reload value to 0?

#135537 - kiwi.ds - Tue Jul 24, 2007 8:54 am

For example, if I do this:

Code:

IME = 0
Set Timer0's Control Register = 0 (Disable Timer)
Set Timer0's Reload Register = 0
Set Timer0's Control Register = 0xc1 (Timer Enable, IRQ Enable, Prescalar Selection = F/64)
IME = 1


Does it mean that a Timer0 overflow will occur in the next 64/33MHz time?
_________________
http://kiwi.ds.googlepages.com/sdat.html
http://kiwi.ds.googlepages.com/nsbmd.html

#135541 - DekuTree64 - Tue Jul 24, 2007 9:49 am

The overflow will occur after 65536*64/33MHz time (about 1/8 of a second).

With no prescaler, the timer will increment at 33MHz. The count register is 16 bits, so it counts up to 65535, and then wraps back to 0 on the next increment (and triggers the overflow interrupt).

If you want it to overflow every 64/33MHz time, then keep everything the same, but set the reload register to 65535. Then it will overflow every time it increments.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#135558 - kiwi.ds - Tue Jul 24, 2007 4:19 pm

Thanks DekuTree. I thought it was decrement
_________________
http://kiwi.ds.googlepages.com/sdat.html
http://kiwi.ds.googlepages.com/nsbmd.html