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)
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)
Has anyone ever converted Scott Dattalo's method (1-Wire Polynomial) to PBP?
It seems like a pretty good compromise between size and performance.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 ;
Regards, Mike
Last edited by Mike, K8LH; - 23rd May 2012 at 04:05.
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
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
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
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
Bookmarks