I was thinking people could post some useful code for using the RTC or some other timer on the prizm to measure time sleep or something else. Here is some code I worked out for starting a timer

these are the defines I use at the beginning of the file with these functions

Code:
Uint32 start = 0;



Code:
void StartTimeCount(void)
{
    start=RTC_GetTicks();
}


It should measure time in milliseconds with an accuracy of ~8 milliseconds.

this was the function I wrote to then find the time since StartTimer was called


Code:
Uint32 GetTimePassed(void)
{
    return 7.8125*(RTC_GetTicks()-start);
}


I have not been able to test this yet as a friend of mine has my prizm but I think it should work. Please add anything that could improve it

Thank You to AHelper whose clock program helped understand how to get the time from the RTC. and from whom most of these defines and value retrieval functions come from

EDIT: Updated to use RTC_GetTicks() thanks to KermM for telling me about it.
Because I'm unfamiliar with how it's all set up, do you know if overclocking will change how this functions?
It shouldn't. I'm making some assumptions here, but the CPU PLL is independent of the clock driving the RTC unit. They should both be sourced from the hardware oscillator (whatever that is), then the CPU clock runs through a few clock dividers and a PLL, while the RTC clock comes through nothing more than a set of (independent) dividers.
That's very nice code, but stupendously over-engineered. All you need to do is use the RTC_GetTicks() call, which gets a number that increases by 128 every realtime second. For example, I use it like this in Tetrizm:


Code:
      int timethistick = RTC_GetTicks();
      int timeoffsettick = timethistick;
[...]
      while(falling) {
         if (!harddrop) {
            RenderTetromino(curpiece,curpiecex,curpiecey,curpiece,rotation);
            Bdisp_PutDisp_DD();
            timethistick = RTC_GetTicks();
            timeoffsettick = (KEYTIMESCALE*(100-((level+HSMODE_OFFSET*(mode==1))>100?100:
                                                                                      (level+HSMODE_OFFSET*(mode==1)))));
         }
         while(harddrop == 0 &&
               timethistick + timeoffsettick >= RTC_GetTicks())
         {
[...etc...]
The CPU is driven by the RTC unit. The RTC has a 32KHz oscillator that drives the FLL. Overclocking simply changes the multipliers and dividers, not the base freq. of the oscillator.
Kerm how long does it take for RTC_GetTicks() to overflow?
one second, hence 64Hz. Read the documentation here: http://prizm.cemetech.net/index.php?title=RTC_Unit

(Unless that function is doing something else, I never care for it as the hardware is exposed)
AHelper you sure about the GetTicks? because I'd think that if it overflowed every second then Kerm's code for tetrizm would have problems if comparing much over that.
ruler501 wrote:
Kerm how long does it take for RTC_GetTicks() to overflow?
It takes (2^32)/128 = (2^32)/(2^7) = 2^25 seconds to overflow. Wink
that should be just fine for my purposes then Razz

thanks a lot to everyone who helped me
No problem. Be sure to let us know how well it works for you, and if you have any further suggestions for other Prizm programmers looking to use the same set of features once you've used it a bit.
This is a quick sleep function I worked out though I'm sure theres probably a more efficient way to do it


Code:
void sleep(Uint32 ms)
{
   int times = ms/1000, i;
   OS_InnerWait_ms(ms%1000);
   for( i=0; i<times; i++)
   {
      OS_InnerWait_ms(990);//reduce it a little for possible call delay
   }
}


I did it this way because I saw that Ashbad said here that OS_InnerWait_ms stops working at values ~1000

I can't wait to get my calc back so I can test all of this stuff
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement