Path: utzoo!dciem!dretor!bpd From: bpd@dretor.dciem.dnd.ca (Brian P. Dickson) Newsgroups: comp.sys.amiga.tech Subject: Re: ciatimer.c ... Message-ID: <1366@dretor.dciem.dnd.ca> Date: 13 Jan 89 15:35:29 GMT Article-I.D.: dretor.1366 References: <3236@sugar.uu.net> Reply-To: bpd@dretor.dciem.dnd.ca (Brian P. Dickson) Organization: NTT Systems, Inc., Toronto, Canada Lines: 47 In article <3236@sugar.uu.net> karl@sugar.uu.net (Karl Lehenbauer) writes: [most of souce code to very handy routines deleted] >/* TIMER - Amiga CIA Timer Control Software > > The routine ElapsedTime gets the time by getting the number of > 65536 microsecond ticks that the handler has seen and retrieving > the 0-46911 number of 1.397 microsecond ticks from the CIA timer > registers, scaling them to 1.000 microsecond ticks and returning > the shifted-and-ored result. >*/ After checking the hardware manual, I calculate the actual ticks to be 1.396825 microseconds (clock interval is 279.365 nanoseconds). While the difference is small, it WILL cause clock drift, if you use these routines as a realtime clock as opposed to just a timer. To get a much more accurate clock, the following changes to the code should be made: > >/* timeslice is 46911 intervals. Each interval is 1.397 microseconds, > * this should correspond to a timing interval of 65536 microseconds */ >#define CIA_TIME_SLICE ((unsigned short) 46911) /* timeslice is 40000 intervals. Each interval is 1.396825 microseconds, * this should correspond to a timing interval of 55833 microseconds, * almost exactly */ #define CIA_TIME_SLICE ((unsigned short) 40000) #define CIA_TIME_QUANTITY ((unsigned short) 55833) /* and now replace all occurrences of 65536 with CIA_TIME_QUANTITY */ > >VOID CIAInterrupt() > CIA_Microseconds += 65536; CIA_Microseconds += CIA_TIME_QUANTITY; /* the approximation for the scaling in ElapsedTime is acceptable, since * it will not affect the clock itself */ >-- >-- uunet!sugar!karl | "We've been following your progress with considerable >-- karl@sugar.uu.net | interest, not to say contempt." -- Zaphod Beeblebrox >-- Usenet BBS (713) 438-5018 -- Brian Dickson bpd@dretor.dciem.dnd.ca