>Date: Fri, 31 May 2002 22:18:15 -0400
>To: Daniel Shima <daniel.shima@...>
>From: Denis Pelli <denis.pelli@...>
>Subject: Re: new GetChar: when.secs still inaccurate?
>Cc:
>Bcc:
>X-Attachments:
>
>>Dear Denis,
>>
>>Hello again. I am noticing some inaccuracy with the when.secs return
>>element of the new GetChar function. I have attached a small M-file called
>>newGetChartest.m which demonstrates the problem (on my Mac at least.)
>>
>>By the way, I am definitely running the more recent copy of the new
>>GetChar downloaded from the forum for which you already made a
>>when.secs fix.
>>
>>Please run the attached M-file when you have a chance and let me know if
>>you see the same inaccurate when.secs value I see. Thanks very much!
>>
>>- Dan
>dear dan
>
>i just ran your test program. i confirm your observations. (a copy
>of the output appears below.)
>
>GetChar is working more or less as documented. the keypress timing
>info provided by the Mac OS is in ticks, i.e. when.ticks. The value
>of when.secs is derived from when.ticks. it's nice to have a value
>in secs since it's a more natural unit, but simply converting the
>scale does not make it more precise. thus, when you use getsecs to
>acquire the time after getchar has returned, you are getting the
>time with much higher precision. one has to expect that the
>quantized time of the tick counter would differ from the continuous
>time of getsecs by a fraction of a tick.
>
>i wouldn't have expected the time difference to be negative. it
>would seem that my algorithm to do the conversion from ticks to secs
>could be enhanced. if you can suggest an improved formula for
>conversion i'd be happy to use it to enhance GetChar.mex.
>
>best
>
>denis
>
>p.s.
>% here's the code (translated from C to MATLAB) that does the conversion:
>% global tick0Secs % value of GetSecs when GetTicks was zero
>% if tick0Secs==0
>% WaitTicks(1);
>% tick0Secs=GetSecs-GetTicks/60.15;
>% end
>% secs=ticks/60.15+tick0Secs;
>%
>
>
>>Press a character key.
>>Now press another character key.
>>
>>startticks 449136
>>when.ticks 449197
>>finishticks 449197
>>
>>(when.ticks - startticks)/60.15 = 1.014
>>(finishticks - startticks)/60.15 = 1.014
>>
>>startsecs 7501.817
>>when.secs 7502.888
>>finishsecs 7502.831
>>
>>when.secs - startsecs = 1.071 (???)
>>finishsecs - startsecs = 1.013
>>
>>finishsecs - when.secs = -0.057 (???)
>>
>>I see that when.ticks and finishticks have the same value
>>and that they are an appropriate number of ticks greater than
>>startticks for the time between the two key presses,
>>assuming 60.15 ticks/second.
>>
>>The value of finishsecs is appropriately larger than startsecs,
>>but the value of when.secs always seems to be significantly
>>less than finishsecs instead of being equal to it and often less
>>than startsecs.