Scott Dattalo wrote: >The code looks good (your latest post - 19 bits of dynamic range). > >Probably the easiest way to test the code is with the stopwatch. >Make IOPORT a ram register, single step to the first sample, >clear the stopwatch, and press F9 (run). After it runs for a while, >force a break. Then go modify the ram register to where IOPORT >points. Single step and note the value of the stop watch when >you break out of the loop. This value should be 3 times the value >get in the counters. > >Repeat this process a few times - perhaps even attempt the timeout. > >Scott Hi again, Scott. Looking not too bad right now. I found a couple errors: testing the wrong register for overflow in 1 spot and I wasn't fixing up 'count_high' at the end of the normalisation routine. I've been simulating for the past couple hours - no probelms so far, with no more than 1 count error between calculated and actual count. I'm about to stick the code into a 12c508 driving some LED displays (my standard serial stuff that I have on the shelf) and I'm going to see if it actually works when I feed the output of a pulse generator to it. This is neat stuff, Scott. I can't even begin to thank you for all your help. dwayne Here is the code for those interested. ;up to 19 bit counter with 3 cycle resolution ;original concept by Scott Dattalo; this version by Dwayne Reid CLRF count_low CLRF count_mid CLRF count_high ;used as known zero for main loop loop BTFSC PULSE goto went_high_1st MOVLW 1 BTFSC PULSE goto went_high_2nd ADDWF count_low,F BTFSC PULSE goto went_high_3rd RLF count_high,W ;get C into W lsb (adding 0 or 1) BTFSC PULSE goto went_high_4th ADDWF count_mid,F BTFSC PULSE goto went_high_5th ;use either of the following lines (not both) ; btfss count_mid,5 ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpc = 19 skpc ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpc = 19 BTFSC PULSE goto went_high_6th nop BTFSC PULSE goto went_high_7th CLRWDT BTFSS PULSE goto loop went_high_8th INCF count_high,F ;count_high now used to accumulate LSBs went_high_7th INCF count_high,F went_high_6th INCF count_high,F went_high_5th ;use either of the following lines (not both) ; btfsc count_mid,5 ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpnc =19 skpnc ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpnc =19 goto overflow ; SUBWF count_mid,F ;undo increment, if any INCF count_high,F went_high_4th INCF count_high,F went_high_3rd DECF count_low,F ;undo increment INCF count_high,F went_high_2nd INCF count_high,F went_high_1st CLRC RLF count_low,F ;make room for lower 3 LSBs RLF count_mid,F RLF count_high,F ;LSB count gets shifted safely out of the way RLF count_low,F RLF count_mid,F RLF count_high,F RLF count_low,F RLF count_mid,F RLF count_high,F RLF count_high,F ;get LSB count into w swapf count_high,w andlw b'00000111' RRF count_high,F iorwf count_low,F ;put LSBs into low byte movlw b'00000111' ;toss extraneous bits - we're done with them andwf count_high,F goto done overflow ;do whatever we want here movlw 0xff movwf count_low movwf count_mid movwf count_high done dwayne Dwayne Reid Trinity Electronics Systems Ltd Edmonton, Alberta, CANADA (403) 489-3199 voice (403) 487-6397 fax