Optimizing CRC16 routine.


Results 1 to 20 of 20

Threaded View

  1. #11
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Trying to get up to speed

    Hi Henrik,
    here is the snippit I am testing:
    Code:
    Main:      'DO WHATEVER YOU WANT HERE
    tmr1=0
    t1con = 1
        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
    t1con = 0
    stopnow:
    goto stopnow
    This takes 169 cycles according to TMR1 setup as you see here. I have tried with both $A001 and $1021. Both are the same. Does this fall in line with what you have?

    BTW, MPLAB stopwatch reports the same

    Next I think I will try out DT's snippet
    Last edited by cncmachineguy; - 16th January 2011 at 19:58. Reason: added
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts