E.Klinke Heliman Location: 71088 Holzgerlingen, Germany
| Hi Angelos, Frederic and Wouter (alphabetic order)
I am wondering if y'all are still interested in the subject. I definitely am.
I came across this thread only yesterday while looking for info on JR SPCM encoding/decoding. I had finished a micro controller program to decode Futaba PCM1024 and thought it might be a good idea to also enable JR SPCM. I was really electrified and read the whole thread from beginning to the end. You can imagine I have a few remarks on subjects you were discussing - like the following:
Delta codes: I do not agree that delta code 0 is omitted. I have seen and recorded all possible delta codes including 0. I saw them when the difference between successive absolute values for that channel were above x'F0' .
Btw., my delta table is off by 4 as compared to Wouter's suggestion.
it looks the following:
F E D C B A 9 8 7 6 5 4 3 2 2 0
-92 -68 -48 -32 -20 -12 -8 0 8 12 20 32 48 68 92 120
I derived it the following way:
I generated stimulus by using 'Servo Test' in the TX and iterated the servo speed.
I recorded with my micro the differences between successive absolutes for one channel together with the delta code for that channel transmitted in the frame between. From these data I derived the upper and lower limits of differences for all delta codes. Now, since the delta is applied midway between the two absolute values they were derived from, it will statistically create the least error if the receiver applies half of the mean difference.
I reallized that Futaba had chosen to make the range of differences for each delta code 8 bigger than the previous one as you move away from delta code 8. This would result in a formula like
Table[ D] = (8-D)x4.
This results in Wouter's table. But since Futaba choose to create a 'calm zone' where they do not apply any delta if the difference between consecutive absolute transmissions is not greater then 7, it is necessary to 'make up' for it when being outside this zone.
That made me come to the formula
Table[D] = (8-D)x4 + C
where C = 0 if D=8; C=+4 if D is less than 8; and C = -4 if D is greater than 8.
Subject CRC: My implementation is the following:
CRC = CRCTable[CRCTable[Byte1] xor Byte2]
this is one line in C and the following 4 lines in 8051 assembler if the 256 byte table is in code space.
mov DPTR,#CCF0CRCTab1 ;
mov a,RxInData ;
movc a,@a+DPTR
xrl a,RxInData+1
This is the table:
;
CCF0CRCTab1:
DB 000h,06bh,0d6h,0bdh,0c7h,0ach,011h,07ah ;00
DB 0e5h,08eh,033h,058h,022h,049h,0f4h,09fh ;08
DB 0a1h,0cah,077h,01ch,066h,00dh,0b0h,0dbh ;10
DB 044h,02fh,092h,0f9h,083h,0e8h,055h,03eh ;18
DB 029h,042h,0ffh,094h,0eeh,085h,038h,053h ;20
DB 0cch,0a7h,01ah,071h,00bh,060h,0ddh,0b6h ;28
DB 088h,0e3h,05eh,035h,04fh,024h,099h,0f2h ;30
DB 06dh,006h,0bbh,0d0h,0aah,0c1h,07ch,017h ;38
DB 052h,039h,084h,0efh,095h,0feh,043h,028h ;40
DB 0b7h,0dch,061h,00ah,070h,01bh,0a6h,0cdh ;48
DB 0f3h,098h,025h,04eh,034h,05fh,0e2h,089h ;50
DB 016h,07dh,0c0h,0abh,0d1h,0bah,007h,06ch ;58
DB 07bh,010h,0adh,0c6h,0bch,0d7h,06ah,001h ;60
DB 09eh,0f5h,048h,023h,059h,032h,08fh,0e4h ;68
DB 0dah,0b1h,00ch,067h,01dh,076h,0cbh,0a0h ;70
DB 03fh,054h,0e9h,082h,0f8h,093h,02eh,045h ;78
DB 0a4h,0cfh,072h,019h,063h,008h,0b5h,0deh ;80
DB 041h,02ah,097h,0fch,086h,0edh,050h,03bh ;88
DB 005h,06eh,0d3h,0b8h,0c2h,0a9h,014h,07fh ;90
DB 0e0h,08bh,036h,05dh,027h,04ch,0f1h,09ah ;98
DB 08dh,0e6h,05bh,030h,04ah,021h,09ch,0f7h ;A0
DB 068h,003h,0beh,0d5h,0afh,0c4h,079h,012h ;A8
DB 02ch,047h,0fah,091h,0ebh,080h,03dh,056h ;B0
DB 0c9h,0a2h,01fh,074h,00eh,065h,0d8h,0b3h ;B8
DB 0f6h,09dh,020h,04bh,031h,05ah,0e7h,08ch ;C0
DB 013h,078h,0c5h,0aeh,0d4h,0bfh,002h,069h ;C8
DB 057h,03ch,081h,0eah,090h,0fbh,046h,02dh ;D0
DB 0b2h,0d9h,064h,00fh,075h,01eh,0a3h,0c8h ;D8
DB 0dfh,0b4h,009h,062h,018h,073h,0ceh,0a5h ;E0
DB 03ah,051h,0ech,087h,0fdh,096h,02bh,040h ;E8
DB 07eh,015h,0a8h,0c3h,0b9h,0d2h,06fh,004h ;F0
DB 09bh,0f0h,04dh,026h,05ch,037h,08ah,0e1h ;F8
I also have a version where the table resides in external ram. In this case I generate the table using the following code fragment:
;-----------------------------------------------------------------
; Generate CRC Table to allow fast calculation of PCM1024 CRC by SLIH
;-----------------------------------------------------------------
;
GenCRCTable: mov DPTR,#HIGH(CCF0CRCTab) ; load DPTR to start of CRC table to be built
mov r3,#000h ; Table Index
mov r4,#000h ; Loop Counter for 0100h table entries
; To calculate the table entry at offset i, it is necessarry to shift i eight times and if
; a b'1' was shifted out, do an additional xor with the polynom (in our case #06bh).
GenCRCTable0: mov r2,#008h ; 8 bits in a byte
mov a,r3
GenCRCTable1: clr c
rlc a
jnc GenCRCTable2 ; Skip xor if bit 7 was a b'0'
xrl a,#06bh
GenCRCTable2: djnz r2,GenCRCTable1 ; Next Bit
movx @DPTR,a
inc DPTR
inc r3 ; Next Index
djnz r4,GenCRCTable0 ; loop if not done
;
;-----------------------------------------------------------------
Sorry I can not get the formatting right but I hope you can read the code anyways.
I have also implemented a 'Multiswitch/Multiprop' decoding functionality and it works well. I want to use it to influence the parameters like P,I and D of the automatic flight control I am developing for my glider.
Enough for today - it is late and I need to catch some sleep.  |