Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site uwai.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!uwvax!uwai!neves From: neves@uwai.UUCP Newsgroups: net.micro.apple Subject: software timing Message-ID: <207@uwai.UUCP> Date: Fri, 31-May-85 00:09:29 EDT Article-I.D.: uwai.207 Posted: Fri May 31 00:09:29 1985 Date-Received: Sat, 1-Jun-85 12:09:01 EDT References: <117@nvuxf.UUCP> Organization: U of Wisconsin CS Dept Lines: 89 I have a question/problem. I'm writing several timing routines in software but they are a bit off and I can't figure out why. On a 1.023 MhZ Apple II there should be 1023 6502 cycles in a millisecond. Below I have a routine that waits a number of milliseconds. Each loop traversal takes up 1023 cycles (or one millisecond). I have compared the time on a //e and II+ and against two Mountain Hardware clocks and the clocks say that the wait routine is about 2.5 clock cycles too slow (error rate of .25%). Why? Are the Mountain Hardware clocks off by this much (has anyone testing them)? Is the Apple crystal (or whatever sets the frequency) really 1.0205 MhZ? Am I doing something really stupid in my software routine below? -Thanks, david neves Usenet: {allegra,heurikon,ihnp4,seismo,uwm-evax}!uwvax!neves Arpanet: neves@uwvax ---------------------------------------------------------------- ;; assm routine for Pascal that waits a number of milliseconds return .equ 0 stopmsec .equ 2 ;timeout location ;; Wait for a specified number of Msecs ;; wait(msec); ;; ;; 1023 clock cycles in 1 msec ;; 24 + 5n - 1 = 1023, n = 200 .proc wait,1 ;; Note: pull and push are the standard pla, sta or lda, pha macros ;; defined elsewhere. pull return pull stopmsec lda bfirst+1 cmp blast+1 bne bloop2 ;make sure one of the loops is in a page bloop1 nop ;2 clock cycles nop ;2 ldx #200. ;2 bl1 dex ; bne bl1 ;200 * 5 -1 (-1 for bne dropthough) dec stopmsec ;5 beq lzero1 ;2 nop ;2 ;same # as lzero1 (11 clock cycles) nop ;2 nop ;2 clc ;2 bcc bloop1 ;3 lzero1 dec stopmsec+1 ;5 + 1 (+1 for sucessful beq jump to lzero1) bmi ret ;2 bpl bloop1 ;3 - nops above take same time as lzero1 eloop1 ;---------------- ret push return rts bfirst .word bloop1 blast .word eloop1 bloop2 nop ;2 nop ;2 ldx #200. ;2 bl2 dex ; bne bl2 ;200 * 5 -1 (-1 for bne dropthough) dec stopmsec ;5 beq lzero2 ;2 nop ;2 nop ;2 nop ;2 clc ;2 bcc bloop2 ;3 lzero2 dec stopmsec+1 ;5 + 1 (+1 for sucessful beq jump) bmi ret ;2 bpl bloop2 ;3 - .end -- David Neves Computer Sciences Department University of Wisconsin-Madison Usenet: {allegra,heurikon,ihnp4,seismo,uwm-evax}!uwvax!neves Arpanet: neves@uwvax