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.

Coding > Changing A Timer Base In The IRQ Handler

#14672 - Krakken - Sat Jan 10, 2004 6:22 pm

Hi,

Just a little question. I'm trying to set "REG_TMxD" (aka "REG_TMxCNT_L") during my IRQ handler function. I can set all the "REG_TMxCNT" registers, no problem, but I cannot set the offset for the timers. I have tried disabling "REG_TMxCNT" setting the value of "REG_TMxD" then restoring the old values of "REG_TMxCNT" but unfortunately that doesn't seem to work either.

If anyone knows of a solution?

Thanks,
Nat.

#14675 - jma - Sat Jan 10, 2004 6:48 pm

A long time ago (about 8 months) I had this problem, too. The trick is disabling the timer settings in the correct order before writing. Sorry, I don't remember exactly what needed to be done.

Also, I wasn't doing it inside the ISR, so I can't say whether or not that will affect you. My guess is that it wouldn't, though.

Jeff
_________________
massung@gmail.com
http://www.retrobyte.org

#14681 - Krakken - Sun Jan 11, 2004 2:49 am

Hey thanks, it worked!

I changed my code to the following:

Code:
           
REG_TM1CNT ^= TME_OVERFLOW;
REG_TM1CNT ^= TME_ENABLE;
           
REG_TM1D = 0xFFFF - iRemain;
           
REG_TM1CNT ^= TME_ENABLE | TME_OVERFLOW;


And now it works just fine. Can anyone explain why it needs to be done this way?