Need CRC for RF PIC2PIC Bit arrayed interface


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2005
    Posts
    19

    Question Need CRC for RF PIC2PIC Bit arrayed interface

    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!

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Thx for your reply.

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

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

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


    Did you find this post helpful? Yes | No

    Default Another approach...

    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.
    Hamming Codes for NAND Flash Memories.pdf

    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
    Last edited by SteveB; - 23rd August 2006 at 00:45.

  5. #5
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    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/p.../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/e...tes/00730a.pdf
    anyone done this before (not the table driven code)?
    Thx

  6. #6
    Join Date
    Aug 2005
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    The manual for the SNAP protocol describes a simple CRC method on this site. http://www.hth.com/snap/

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mrx23
    Is the Serin2/Serout2 reliable on 628A@internal 4Mhz?
    Haven't used that chip, but see this post by Melanie on just that issue. YMMV.

    Quote Originally Posted by mrx23
    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 134 with 8 or more 10 bit ADC Channels.

    Steve
    Last edited by SteveB; - 23rd August 2006 at 03:00.

  8. #8
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    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]

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mrx23
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mrx23
    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

  11. #11
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    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/AN...h=%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?

Similar Threads

  1. Dallas CRC8 Routines
    By Tom Estes in forum Code Examples
    Replies: 23
    Last Post: - 8th May 2018, 18:07
  2. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  3. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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