New topic: 

Ticks/Microseconds and overflows/rollovers

<http://forums.realsoftware.com/viewtopic.php?t=47085>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        lordfrito          Post subject: Ticks/Microseconds and 
overflows/rolloversPosted: Tue Feb 26, 2013 11:22 am                         
Joined: Tue Feb 26, 2013 11:04 am
Posts: 1                Having some problems understanding how to do accurate 
high resolution time measurement using Microseconds

First let me start off by saying that I understand how to use integer timers to 
perform high resolution time-span measurement.  I see that Real Studio provides 
a Ticks function in integer form.  Typical time measurement works as
dim start_ticks as uint32
dim delta as uint32
delta = (uint32)(Ticks - start_ticks)

This always works, even in the case of Ticks overflow, as 0x0 - 0xFFFFFFFF = 1 
tick

So I *could* use Ticks, except that I need higher precision time measurement 
than Ticks provides (only 1/60th of a second)

So I move to the Microseconds function.  However the value it returns in in 
double form.  Using floating point makes no sense to me for timespan 
measurement, as eventually a double will FREEZE counting once the value gets so 
large that it's precision is larger than 1 microsecond.  As...
   THIS WORKS -->  1.000000 + 0.000001 = 1.000001
   THIS DOESNT --> 2^52 + 0.000001 = 2^52

Compounding things is knowing that the "real" value underlying this double is 
probably some hardware timer in integer form.  Meaning the "real" timer counts 
properly, and causes microseconds to overflow at some unknown (to me) amount.  
My guess is that Microseconds works like this
 dim hw_timer as UInt32
dim hw_timer_frequency as UInt32
hw_timer = GetHardwareTimer()
hw_timer_frequency = GetHardwareTimerFrequency()
dim result_in_microseconds as double
result_in_microseconds = 0.000001 * hw_timer / hw_timer_frequency


This implies that the double value returned DOES in fact overflow.  However I 
need to know EXACTLY when this overflows, so I can handle time measurement 
during the rollover.  For example
   // assuming it overflows at 1500 counts
current timer = 10
prev timer = 1490
delta = (current timer - prev timer) + 1500
= (10 - 1490) + 1500
= -1480 + 1500
= 20 counts!


For this scheme to work it requires that I now exactly when the timer 
overflows.  So I'm totally confused as how to use Microseconds to perform these 
kinds of calculations.  And for the life of me I can't understand why there 
isn't some sort of integer timer with better resolution than Ticks.

Am I missing something here?  Can someone point me in the right direction?

Thanks
John   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to