Hi John/Scott, Here is my version, somewhat similar to Scott's but the correction and the end is more simpler: (untested) cnt16bit: clrf kz clrf lo clrf hi movlw 2 ;preset 2 counts loop btfsc PORTB,7 goto quit1 ;1 addwf lo,f ;inc lo cnt btfsc PORTB,7 goto quit2 ;2 rlf kz,w ;get carry btfsc PORTB,7 goto quit3 ;3-2 addwf hi,f ;hi incremented depends on carry btfsc PORTB,7 goto quit4 ;4-2 skpc ;check if already finished btfsc PORTB,7 goto quit5 ;5-2 movlw 7 ;add 7 uncounted tests btfsc PORTB,7 goto loop6 ;6-2 btfss PORTB,7 goto loop ;7-2 quit7 incf kz,f ;add uncounted tests quit6 incf kz,f quit5 incf kz,f quit4 incf kz,f quit3 addwf hi,f ;inc hi byte first ; bec. not incr in the loop quit1 incf kz,w addwf lo,f skpnc incf hi,f return quit2 addwf hi,f return regards, Reggie -- e-mail: rberdin@bigfoot.com ICQ#: 31651436 URL: http://www.bigfoot.com/~rberdin John Payson wrote: > > |Create a delay loop that can loop for up to 2^16 times while mininmizing > |the number of cycles per iteration. > > More fun variant: write a routine which, when called, will time how long > it takes for pin RB7 to go high [assuming it isn't already]. Time should > be kept in 16 bits, and the routine should exit if RB7 does not go high. > within 65,536 counts. > > To make things a bit more interesting... > > [1] Consider approaches with and without RTCC > > [2] Try for a measurement precision of 3 cycles. > > [3] Try to design the loop to look for either port pin RB6 or RB7 to > go high, with a precision of 4 cycles. > > Those sound like fun little additions? I will offer a couple little hints: > > [A] The code need not LOOP 65536 times; if you have, e.g., two tests within > a 6-cycle loop you could run the loop 32768 times and at the end check > which test kicked you out of it. > > [B] You need not exit the loop immediately upon detecting the event, prov- > ided the count values are correct. > > Have at it...