John Payson wrote: > 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. Here's a solution that I suggested to Dwayne Reid a while back. It has 19 bits of dynamic range and is easily extendable to 27 bits. Furthermore, it doesn't depend on which I/O port is being tested. It's probably not what you had in mind, but it does have 3-cycle resolution. clrf lo clrf hi btfsc portb,7 goto high_in_3 nop loop btfsc portb,7 goto high0 movlw 1 btfsc portb,7 goto high1 addwf lo,f btfsc portb,7 goto high2 rlf kz,w btfsc portb,7 goto high3 addwf hi,f btfsc portb,7 goto high4 skpc btfsc portb,7 goto high5_maybe_overflow clrwdt btfsc portb,7 goto high6 nop btfss portb,7 goto loop ;fall through... Add 7 to the total count incf kz,f high6: incf kz,f high5: skpnc goto overflow incf kz,f high4: incf kz,f high3: incf kz,f high2: incf kz,f high1: incf kz,f high0: clrf upper clrc rlf lo,f rlf hi,f rlf upper,f rlf lo,f rlf hi,f rlf upper,f rlf lo,w rlf hi,f rlf upper,f iorwf kz,w movwf lo clrf kz > > [3] Try to design the loop to look for either port pin RB6 or RB7 to > go high, with a precision of 4 cycles. The two instruction test: btfsc portb,7 goto highx can be replaced with btfss portb,7 btfsc portb,6 goto highx There are a host of other tricks.... Scott