Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
timer-problems   Message List  
Reply | Forward Message #12615 of 15019 |
RE: [gbadev] timer-problems

Normally there is no need to check the timer yourself..

The normal timer usage is this:

Set the correct period to use.. (every 1, 64, 256 or 1024 clocks)
Set the start value by writing to TMxCNT_L, this is the value at which
the timer will start every time it overflows or gets started.. Standard
this is 0
Set the interrupt and enable it
Start the timer..

Now the timer will start at the start value, get increased every period
of clocks, and on overflow the interrupt will get called, in which you
do the handling..

http://www.suddenpresence.com/sgade/ has a nice implementation, you
might wanna look for sourcecode there


Now to your problem:

while(REG_TM3D < 263)

Depending on the period you chose, this situation will occur fast to
VERY fast. That's why you probably don't even notice it waiting..

With a period of 1 it takes 0.000015676021575927734375 seconds to make
the timer reach 263
With a period of 64 it takes 0.001003265380859375 seconds to make the
timer reach 263
With a period of 256 it takes 0.0040130615234375 seconds to make the
timer reach 263
With a period of 1024 it takes 0.01605224609375 seconds to make the
timer reach 263

So in the best case, it will only be a wait of 1/100ths of a second,
hardly noticable most of the times..


If you put in a WaitVblank(), after each check it waits an entire frame
before it checks again, obviously this will lead to incorrect results..


One other point you should check, is wheter that define use a volatile
pointer, else the compiler will optimise it away
But I think that's not the problem


Hope that helps,
Willem





> -----Original Message-----
> From: Roman Schaub [mailto:roman@...]
> Sent: Thursday, September 05, 2002 16:19 PM
> To: gbadev@yahoogroups.com
> Subject: [gbadev] timer-problems
>
>
> hello there..
>
> since i need a timer in my game, i tried to create a function
> which uses one of the internal timer registers (obviously).
> the problem i encountered was:
>
> if i create a while-loop and check the value of the counter,
> it never stops! (means: the cpu doesn't check the value of
> the counter, but if i insert something like
> "WaitforVBlank()" into the while-loop, the counter works
> correctly (but significantly slower...).
>
> while(REG_TM3D < 263){} //doesn't work
>
> while(REG_TM3D < 263){WaitVblank();} //works....
>
> i also tried to enable the interrupt-on-overflow...didn't
> work either...
>
> it just seems that counting occupies the cpu to 100% so he
> doesn't have the time anymore to check if the
> abort-conditions have already reached... i really don't have
> a clue how to fix that.
>
> cheers
>
> roman




Thu Sep 5, 2002 4:42 pm

thezensunni
Online Now Online Now
Send Email Send Email

Forward
Message #12615 of 15019 |
Expand Messages Author Sort by Date

hello there.. since i need a timer in my game, i tried to create a function which uses one of the internal timer registers (obviously). the problem i...
Roman Schaub
schoebey
Offline Send Email
Sep 5, 2002
4:20 pm

You're sure you have declared REG_TM3D to be volatile right? Otherwise the value will likely be cached, thus changes in it will be unnoticed? Just something...
Wogan
wogan_gwb
Offline Send Email
Sep 5, 2002
4:59 pm

... How is 'REG_TMD3D' defined? Is it volatile? Waiting for Vblank within the while loop puts the CPU on halt until a Vblank interrupt fires, so that happens...
Jan-Lieuwe Koopmans
jan-lieuwe@...
Send Email
Sep 5, 2002
5:02 pm

Normally there is no need to check the timer yourself.. The normal timer usage is this: Set the correct period to use.. (every 1, 64, 256 or 1024 clocks) Set...
Willem Kokke
thezensunni
Online Now Send Email
Sep 5, 2002
5:03 pm

... the ... well, that is exactly the plan. i wanted to implement a timer that is accurate to 1/1000 s... ... volatile ... it was indeed the problem that the...
schoebey
Offline Send Email
Sep 5, 2002
9:05 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help