PDA

View Full Version : Need CRC for RF PIC2PIC Bit arrayed interface



mrx23
- 22nd August 2006, 16:25
Hi!

I want to build a RC model encoder/decoder (PIC to PIC@4Mhz) interface.
On the transmitter side I've Frame[99] Bit array set of 10bit ADC datas to transmit.
And I need a simple but reliable CRC for it.
I dont want to waste bandwidth with like manchester coding.
I prefer to do the job with more processtime like XOR-ing.

How do i treat the Bit array like a long Bin number? (or I've to XOR-ed by one by one?)
How do i add the CRC checksum to the array? (add-it, or append it)?
The calc must be loop driven not table driven.
If it is possible no shifting.
How can i send/rec this array via Serin2/Serout2?

an idea:
Data in: Frame[99]+Checksum
CONST onboardpolynomial = ....(bin array)

x= (Frame[99]+Checksum) XOR onboardpolynomial
if x =1 then goto error

Thank you!

DynamoBen
- 22nd August 2006, 16:42
A while back I did a wired project that just used a byte add error checking method.

Add each byte to the last and store the sum in a byte sized variable:

RX var byte[10]
CHKSUMCALC var byte

For Cnt=0 to 8
HSerin 2,No_Data,[RX[CNT]] ' Buffer bytes to RX
CHKSUMCALC = CHKSUMCALC + RX[CNT] ' Calculate the checksum
Next Cnt

mrx23
- 22nd August 2006, 17:03
Thx for your reply.

But I read this:
http://www.repairfaq.org/filipg/LINK/F_crc_v31.html#CRCV_002

And i realised that summing is not so reliable like dividing.
Does anyone know an easy Modulo-2 PICbasic arithmetic algorytm?

SteveB
- 22nd August 2006, 21:50
Here is a ECC idea based on hamming code used for flash memory. It may be something you can apply to your situation. It has the advantage of being able to correct a single bit error, in addition to detecting multiple bit errors.
1029

I have some ideas about how to implement this if you think it would be useful in your situation. The bigger the data packet, the more efficient the technique, but the more likely, in a noisy environment, that you will have more than one single bit error, and then be required to retransmit. Here is an example of one way you could use this: Send 6 * 10 bit ADC values + 12 bits of ECC for a total of 72 bits (9 bytes) of data. Since you are using only 60 of the first 64 bits, the top 4 ECC bits could be loaded into the 4 bits not used by the ADC values. When calculating the ECC, those 4 bits could always be 0, then filled with the ECC values before transmission. At the receiving end, the ECC values are replaced with 0s again before the ECC recalculation.

I have played with this a little bit on 256 Byte (2048 bit) data packets, so I might have some code you could use as a starting place.

HTH,
Steve

mrx23
- 23rd August 2006, 01:20
I think its much more simple to use CRC rather than ECC.
If a frame falls the CRC test, and its ignored, its loose just a ~12mS time.
Then it will automatical sendout the previous good data to the servo.

Here is a way to complex packet oriented Futaba transmision with 1bit error
tolerance. http://graphics.tudelft.nl/~wouter/publications/pasman03k.pdf

more ECC: http://en.wikipedia.org/wiki/Error_detection

Is the Serin2/Serout2 reliable on 628A@internal 4Mhz?
Or I must choose the pulseout/pause on TX and RX: Pulsin 1/Pulsin 0?
The transfer rate is 5kbit/sec->5Khz, period time: 0,2mS

The ADC is MAX148 10bit 8ch internal (or ext) clock (max 2Mhz),
SPI interface.
After I send the control Byte to its input.
It starts the conv, then it sends out(shifts out by its clk) the selected
channel value. Can I catch this data with something else than pulsin 1?

I want to apply this in PICbasicPro
http://ww1.microchip.com/downloads/en/AppNotes/00730a.pdf
anyone done this before (not the table driven code)?
Thx

arniepj
- 23rd August 2006, 02:10
The manual for the SNAP protocol describes a simple CRC method on this site. http://www.hth.com/snap/

SteveB
- 23rd August 2006, 02:53
Is the Serin2/Serout2 reliable on 628A@internal 4Mhz?

Haven't used that chip, but see this post (http://www.picbasic.co.uk/forum/showpost.php?p=9471&postcount=6) by Melanie on just that issue. YMMV.


The ADC is MAX148 10bit 8ch internal (or ext) clock (max 2Mhz),
SPI interface.
After I send the control Byte to its input.
It starts the conv, then it sends out(shifts out by its clk) the selected
channel value. Can I catch this data with something else than pulsin 1?
You should use PBP's SHIFTIN/SHIFTOUT with a SPI interface. No experiance with that particular ADC, but lots of folks (myself included) use SHIFTIN/SHIFTOUT with great success. You have to choose the correct "mode", but then it works a treat.

Also, unless there is some unkown reason, why not select a PIC with ADC on board? Its surely going to be cheaper than the seperate MAX ADC, and no comm hassle. Lots of options to choose from: A quick search yielded (http://www.microchip.com/ParamChartSearch/params.aspx?branchID=1005&mid=10&lang=en&pageId=74) 134 with 8 or more 10 bit ADC Channels.

Steve

mrx23
- 23rd August 2006, 11:43
Thx, I will try the shifting.
I choosed the Max 148 ADC becouse its free:)
You can order sample www.maxim-ic.com
The other reason:
I want minimal pin usage for SPI, so the rest of the PIC pins
can be used for Switches.

Can I tied the CS pin (on ADC,chipselect,activ low) to directly to the ground?
I just use one ADC chip.

Thanks for this link: http://www.hth.com/snap
I'll read it.

Is this code correct? Do I have to care about stop bits?
Or its just automatic (and hidden)?


' -----------------------[ Transmitter ]--------------------

MultipleBites var Bit[60]

MultipleBites[0]=0
MultipleBites[1]=1
MultipleBites[2]=0
MultipleBites[3]=0
MultipleBites[4]=1
...

Serout2 pin,Baud,[str MultipleBites]



' ------------------------[ Receiver ]-----------------------

MultipleBites var Bit[60]

Serin2 Serpin,Baud,[str multiplebytes\60]

SteveB
- 23rd August 2006, 16:13
Can I tied the CS pin (on ADC,chipselect,activ low) to directly to the ground?
I just use one ADC chip.


You'll have to check the datasheet for the MAX chip. The limited SPI devices (2) I've used have the CS pin as a sort of like a command reset, and required you to toggle the CS line to end one command and start another.

SteveB
- 23rd August 2006, 16:44
Thx, I will try the shifting.
I choosed the Max 148 ADC becouse its free:)
You can order sample www.maxim-ic.com
The other reason:
I want minimal pin usage for SPI, so the rest of the PIC pins
can be used for Switches.


Free is a GOOD PRICE. Here is another way to look at it:

MAX 148 = 20 pin
PIC16F168A = 18 Pins
16 IO pins (-2 if using an Ext OSC)
(-4 for SPI Interface)
= 38 Pins for 12 usable IO Pins (or 10 with ext OSC)

Pic18F2620 = 28 Pins
24 IO pins (-2 if using an Ext OSC)
10 ADC (leaves 14 IO PINS remaining)
= 28 Pins for 14 usable IO Pins (or 12 with ext OSC)

Just my 2 cents,
Steve

mrx23
- 24th August 2006, 12:35
I'll choose one of these:
PIC16F685
PIC16F689
PIC16F785
they are very cheap, about $2 of each
12 number of 10bit ADC onboard.
4096 words code sp (does the newest PicBasicPro support above 2k codespace?)
18 I/o lines (-used ADC)

Shiftin/out for SPI are VERY slow: 50KHz clk out
the Max148 supports 2Mhz clk

Here is a very good CRC8 describe with easy example
http://pdfserv.maxim-ic.com/en/an/AN3749.pdf#search=%22an3749%22
Both loop and table driven CRC's, its easy to convert to CRC16.

About supply:
My plean is to use a zener based (and shunt transistor) regulator, like here:
http://www.satcure-focus.com/tutor/page5.htm

itt'll cut higher voltages than 5V from battery, and the PIC's BODEN will
restart continuously when the battery is to low.
The supply will ONLY power the PIC (very max ~1W), from 7.2V battery.

The same'll be on the receiver side, but it will ha low volt detect
that will shut down the motor signal.
(an internal comparator feeded by an internal reference ~1V,
and voltage divided battery input 1:4)
That will stop the motor when battery is under 4V.

Is my plean correct?