Manchester Coding- Sending data by Radio.

Mauried
2010-04-14
2013-05-30
  • Mauried
    Mauried
    2010-04-14

    Many of the common techniques for Sending data by Radio is to use small ASK 433 Mhz radio modules to send data.
    These modules are cheap and low powered and can operate at up to 9600 bps.
    Due to the way the receivers in these modules work, they dont like data that has few data transitions in what is being sent, or data with a DC component ,and will incorrectly decode or not decode properly at all.
    A popular technique to overcome this problem is Manchester Coding, which converts byte variables into word variables
    with many more data transitions, and no DC component.
    This drastically reduces the error rate of the data being sent, and provides some basic error checking.

    Some simple GCbasic code to do this .

    Manchester Encoding converts byte data into word data with maximum data transitions and zero DC component.
    MC encoding routine , enter with data byte in Mydata.

    Encode Routine converts 1 byte into 2 bytes  with maximum data transitions and no DC component.

    Encode:
    Mword=0 ;Dim Mword as word variable
    For CounterA=0 to 7
    If MyData.0=0 then
    MWord.14=1
    else
    MWord.15=1
    end if
    If CounterA<7 then MWord=(MWord/4)
    MyData=(MyData/2)
    Next CounterA
    lobyte=MWord
    hibyte=MWord_H
    sersend 1, lobyte ;send the low byte
    sersend 1, hibyte ;send the high byte
    return

    MC receive routine.
    We take the 2 bytes transmitted above and convert them back into 1 byte.
    If the error flag is set on exit, the data is corrupted and should be discarded.
    Databyte returned as Mydata.

    Decode:
    Mword=Serdata         'receive lobyte
    Mword_H=Serdata 'receive hibyte, makes a single word variable.
    ErrorFlag=0
    For CounterA=0 to 7
    If MWord.1=0 then
    MyData.7=0
    If MWord.0=0 then ErrorFlag=1
    else
    MyData.7=1
    If MWord.0=1 then ErrorFlag=1
    end if
    MWord=MWord/4
    If CounterA<7 then MyData=MyData/2
    NEXT COUNTERA
    Return