OK - here it is in Assembler - disappointingly not that much faster!
Code:
'**** mPULSIN defines ***
Period var word[7]
mPort var PortB
Mask con %00000011 'Mask of port pins to check
i var byte
j var byte
k var byte
pCount var word
sample var byte
CALL mPULSIN
END
asm
_mPULSIN: CLRF _Period ;Period[0] = 0
CLRF _Period + 1
CLRF _Period + 2 ;Period[1] = 0
CLRF _Period + 3
CLRF _Period + 4 ;Period[2] = 0
CLRF _Period + 5
CLRF _Period + 6 ;Period[3] = 0
CLRF _Period + 7
CLRF _Period + 8 ;Period[4] = 0
CLRF _Period + 9
CLRF _Period + 10 ;Period[5] = 0
CLRF _Period + 11
CLRF _Period + 12 ;Period[6] = 0
CLRF _Period + 13
CLRF _Period + 14 ;Period[7] = 0
CLRF _Period + 15
MOVLW 0xFF
MOVWF _pCount
MOVLW 0x0F
MOVWF _pCount + 1 ;pCount = $FFF = 4095
MOVLW _Mask
MOVWF _k ;k = Mask
CLRF _sample ;clear sample flag
cycle: MOVF _mPort, W ;Sample the Port
ANDWF _k, W
MOVWF _j ;j = Port AND Mask
B0: BTFSS _j,0 ;Bit set? Pulse high
GOTO B0Clear
BSF _sample,0 ;flag that now sampling
INCFSZ _Period ;Period[0] = Period[0] + 1
GOTO B1
INCF _Period + 1
GOTO B1
B0Clear: BTFSS _sample,0 ;Pulse low - already sampling?
GOTO B1
BCF _k,0 ;Clear Bit in Mask
B1: BTFSS _j,1 ;Bit set? Pulse high
GOTO B1Clear
BSF _sample,1 ;flag that now sampling
INCFSZ _Period + 2 ;Period[1] = Period[1] + 1
GOTO B2
INCF _Period + 3
GOTO B2
B1Clear: BTFSS _sample,1 ;Pulse low - already sampling?
GOTO B2
BCF _k,1 ;Clear Bit in Mask
B2: BTFSS _j,2 ;Bit set? Pulse high
GOTO B2Clear
BSF _sample,2 ;flag that now sampling
INCFSZ _Period + 4 ;Period[2] = Period[2] + 1
GOTO B3
INCF _Period + 5
GOTO B3
B2Clear: BTFSS _sample,2 ;Pulse low - already sampling?
GOTO B3
BCF _k,2 ;Clear Bit in Mask
B3: BTFSS _j,3 ;Bit set? Pulse high
GOTO B3Clear
BSF _sample,3 ;flag that now sampling
INCFSZ _Period + 6 ;Period[3] = Period[3] + 1
GOTO B4
INCF _Period + 7
GOTO B4
B3Clear: BTFSS _sample,3 ;Pulse low - already sampling?
GOTO B4
BCF _k,3 ;Clear Bit in Mask
B4: BTFSS _j,4 ;Bit set? Pulse high
GOTO B4Clear
BSF _sample,4 ;flag that now sampling
INCFSZ _Period + 8 ;Period[4] = Period[4] + 1
GOTO B5
INCF _Period + 9
GOTO B5
B4Clear: BTFSS _sample,4 ;Pulse low - already sampling?
GOTO B5
BCF _k,4 ;Clear Bit in Mask
B5: BTFSS _j,5 ;Bit set? Pulse high
GOTO B5Clear
BSF _sample,5 ;flag that now sampling
INCFSZ _Period + 10 ;Period[5] = Period[5] + 1
GOTO B6
INCF _Period + 11
GOTO B6
B5Clear: BTFSS _sample,5 ;Pulse low - already sampling?
GOTO B6
BCF _k,5 ;Clear Bit in Mask
B6: BTFSS _j,6 ;Bit set? Pulse high
GOTO B6Clear
BSF _sample,6 ;flag that now sampling
INCFSZ _Period + 12 ;Period[6] = Period[6] + 1
GOTO B7
INCF _Period + 13
GOTO B7
B6Clear: BTFSS _sample,6 ;Pulse low - already sampling?
GOTO B7
BCF _k,6 ;Clear Bit in Mask
B7: BTFSS _j,7 ;Bit set? Pulse high
GOTO B7Clear
BSF _sample,7 ;flag that now sampling
INCFSZ _Period + 14 ;Period[7] = Period[7] + 1
GOTO Next
INCF _Period + 15
GOTO Next
B7Clear: BTFSS _sample,7 ;Pulse low - already sampling?
GOTO Next
BCF _k,7 ;Clear Bit in Mask
Next: MOVF _k, F ;Is Mask = 0?
BTFSC STATUS,Z ;Branch on No Zero
RETURN ;Finished all samples
DECFSZ _pCount
GOTO cycle
DECFSZ _pCount + 1
GOTO cycle
RETURN ;pCount reached 0 - Timeout
ENDASM
Bookmarks