01-26-2007, 04:10 AM
Ralph
The only way to use timer tick accurately is to get the interupt to update your variable each time the interupt happens. I use a scheme as below to accurately time events, without creating a lot of overhead.
The only way to use timer tick accurately is to get the interupt to update your variable each time the interupt happens. I use a scheme as below to accurately time events, without creating a lot of overhead.
Code:
'---------------------------------
TYPE TIMES
Clk AS INTEGER
Divider AS INTEGER
Speed AS INTEGER
Increment AS LONG
Msec AS LONG
NowTime AS LONG
KeyTime AS LONG
PassCount AS LONG
StartTime AS LONG
WaitState AS LONG
RunTime AS LONG
OldTime AS LONG
ShowTime AS LONG
Hours AS INTEGER
Minutes AS INTEGER
Seconds AS INTEGER
Tyd AS STRING * 7
END TYPE
COMMON SHARED TIMES AS TIMES
'---------------------------------
DECLARE FUNCTION TsrTime& (byval a&,byval B&)
'First Hook the Interupt so that everytime the clock tick increments,
'your variable increments.(If you want the asm routine that I can send it)
A& = TsrTime& (byval varptr(Times.NowTime),byval varseg(Times.NowTime))
'I write my programs so that I never hang around or wait for a delay.
'Then at the beginning there is a main loop
DO
TimeShow
'call whatever else here,
LOOP
'So if you need an accurate delay.
Times.StartTime = Times.Msec
'then in your loop
IF Times.Msec - Times.StartTime > 12 THEN ......
'You can also use it to see how long your loop takes
'by printing Times.Increment on the screen
SUB TimeShow
Times.PassCount = Times.PassCount + 1 'increment the program loops
Times.Msec = clng((Times.NowTime * 54.9254) + (Times.Increment \ 1000 )) '
'-----------------------------------------------
IF Times.NowTime > Times.OldTime THEN 'if a tick has happened ,recalculate
Times.Increment = (54.9254 / Times.PassCount) * 1000 '55 msec / Nr of Passes = msec per pass
Times.OldTime = Times.NowTime
Times.PassCount = 0
END IF
END SUB
t is the End result that matters, not the Tools used to get there.