Dallas CRC8 Routines


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    found 2 more typos for total of 3...

    line with 35,125,159,193,66,28,"154", Dallas has 254
    line with 101,59,217,135,4,90,184,230,167,249,"29", Dallas has 27
    line with 50,108,142,208,83,13,239,177,"140", but Dallas example is 240 (as noted above)

  2. #2
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    Has anyone ever converted Scott Dattalo's method (1-Wire Polynomial) to PBP?

    Code:
    ;
    ;  Scott Dattalo's version (20 words, 23 cycles per byte)
    ;
    crc_8
            xorwf   CRC,F           ;
            clrw                    ;
            btfsc   CRC,0           ;
            xorlw   0x5E            ; 
            btfsc   CRC,1           ; 
            xorlw   0xBC            ; 
            btfsc   CRC,2           ; 
            xorlw   0x61            ; 
            btfsc   CRC,3           ; 
            xorlw   0xC2            ; 
            btfsc   CRC,4           ; 
            xorlw   0x9D            ; 
            btfsc   CRC,5           ;
            xorlw   0x23            ; 
            btfsc   CRC,6           ; 
            xorlw   0x46            ; 
            btfsc   CRC,7           ; 
            xorlw   0x8C            ; 
            movwf   CRC             ; 
            return                  ;
    It seems like a pretty good compromise between size and performance.

    Regards, Mike
    Last edited by Mike, K8LH; - 23rd May 2012 at 04:05.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    If your concern is size and speed, why not use it as is with he addition of _ before CRC variable (_CRC)?

    I think it will work just fine.

    Ioannis

  4. #4
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    Quote Originally Posted by Ioannis View Post
    If your concern is size and speed, why not use it as is with he addition of _ before CRC variable (_CRC)?

    I think it will work just fine.
    Hi Ioannis:

    Since the Dattalo method wasn't mentioned in the thread, I simply wanted to pass it along, hoping it might be useful or helpful to PBP users. I'm afraid I don't know how you would implement it in PBP.

    While I've tried all of the methods discussed in this thread in the past, now days in my C programs I use bit level cumulative CRC built into my low level 1-Wire read/write bit driver. Total cost for doing it this way is 8 words of program memory, 1 byte of RAM, and 0 cycles processing overhead since the CRC code executes during a portion of the delay required to fill out the 60 usec read slot timing.

    Cheerful regards, Mike

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    Hmm, yes I see what you mean. In Basic this does not seem an easy job to do.

    I will try it and see if it works.

    Ioannis

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    My main concern is how to save the W register and then restore it.

    I tried

    MOVW _wsave

    but did not compile.

    Ioannis

  7. #7
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Dallas CRC8 Routines

    Quote Originally Posted by Ioannis View Post
    My main concern is how to save the W register and then restore it.

    I tried

    MOVW _wsave

    but did not compile.

    Ioannis
    The command would be: movwf

    Here is a quick attempt at converting the asm to PBP. Note that this is not the most efficeint/elegant conversion, but it should be a bit clearer was to what's happening.

    Code:
    crc VAR BYTE
    i_w VAR BYTE
    
    goto start                  
    
    crc_8:
       crc = i_w ^ crc        ;xorwf crc,f
       i_w = 0                   ;clrw
    
       IF crc.0 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $5E    ;xorlw 0x5e
          END IF
       IF crc.1 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $BC    ;xorlw 0xbc
          END IF
       IF crc.2 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $61    ;xorlw 0x61
          END IF
       IF crc.3 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $C2    ;xorlw 0xc2
          END IF
       IF crc.4 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $9D    ;xorlw 0x9d
          END IF
       IF crc.5 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $23    ;xorlw 0x23
          END IF
       IF crc.6 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $46    ;xorlw 0x46
          END IF
       IF crc.7 = 1 THEN     ;btfsc crc,0
          i_w = i_w ^ $8C    ;xorlw 0x8c
          END IF
    
       crc = i_w             ;movwf crc
    RETURN
    
    start:
     crc = 0                    ;clrf crc
     i_w = 1                    ;movlw 1
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                    ;clrf crc
     i_w = 2                    ;movlw 2
     GOSUB crc_8            ;call  crc_8
     
     crc = 0                    ;clrf crc
     i_w = 4                    ;movlw 4
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                   ;clrf crc
     i_w = 8                   ;movlw 8
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                   ;clrf crc
     i_w = $10                ;movlw 0x10
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                   ;clrf crc
     i_w = $20                ;movlw 0x20
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                   ;clrf crc
     i_w = $40                ;movlw 0x40
     GOSUB crc_8            ;call  crc_8
    
     crc = 0                   ;clrf crc
     i_w = $80                ;movlw 0x80
     GOSUB crc_8            ;call  crc_8
    END

Similar Threads

  1. Problems with CRC8 Calc in 1Wire
    By JohnB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2007, 23:01
  2. dallas ibutton to pics
    By CBUK in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 25th October 2006, 13:55
  3. Dallas 1-wire search Routine
    By jimbab in forum Code Examples
    Replies: 0
    Last Post: - 7th April 2006, 17:14
  4. Dallas Semiconductor Components Serial Numbers
    By ideaman234 in forum General
    Replies: 2
    Last Post: - 27th February 2006, 23:17
  5. Dallas CRC16 Routines
    By Tom Estes in forum Code Examples
    Replies: 0
    Last Post: - 16th May 2005, 16:29

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