Hi,
I'm struggling with this as well. I have the follwing CRC routine working properly:
Code:
MB_CRC = 65535                             ' Initialize CRC value
MB_k = MB_Buffer_Ptr - 3                   ' Find out where in the array to stop.
 
T1CON = 1
 
FOR MB_i = 0 to MB_k                       ' Iterate thru the frame, stop before the last two bytes which are the actual CRC.
    MB_CRC = MB_CRC ^ MB_Buffer[MB_i]      ' Bitwise EXOR the current low byte of the CRC "value" with the byte in the buffer
 
    FOR MB_j = 0 to 7                      ' Cycle thru the low byte of the CRC value                      
        If MB_CRC.Bit0 THEN                ' If the LSB is set
            MB_CRC = MB_CRC >> 1           ' We shift CRC on bit to the right....
            MB_CRC = $A001 ^ MB_CRC        ' and EXOR it with out polynomial for MODBUS CRC-16 ($A001)
        ELSE
            MB_CRC = MB_CRC >> 1           ' If the LSB is not set we simply shift CRC one bit to the right.
        ENDIF
    NEXT                                   ' Next bit in the byte
 
NEXT                                       ' Next byte in the frame
 
T1CON = 0
 
RETURN
This works properly for what I'm doing (MODBUS) but is painfully slow. Darrel said he got 825us for 9 bytes @4Mhz. This thing takes 2837 cycles for 9 bytes....

Giving it 67 bytes and it it takes ~14000 cycles to return the 16 bit CRC value.

To my naked eye this looks fairly close to the Darrels routine but this uses another polynomial (which I can't see making any difference time wise) and it's "reversed".

I've rearanged a couple of things, splitting statements in two etc which has gained me a bit of performance but now I seem to be stuck. Again, it works properly which is the most important thing but can anyone tells me what the h..l is taking so long ;-)

Thanks!
/Henrik.