Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MANCHESTER CODING in C language

Status
Not open for further replies.

Anniyan_x

Member
Does anyone have come across manchester encoding and decoding in C language, Transmits and receive. I wana do RF remote controller.i have the codes but it is in ASM,anyone have in C lang?? :)
 
Nigel Goodwin in his tutorials
This is the way the bits are actually sent, a bit 1 is a transition from 0 to 1, and a bit 0 is a transition from 1 to 0.

AND
Melanie in web (ericgibbs posted the link)
8 bit byte becomes 16 bits to transmit... zero's become "01" and ones become "10".
I think overall result will be the same... but i want to know which is the right way... Any Standered???
 
I follow the fisrt convention, that is standard (IEEE) now. But the second one was published first, as far as I know.
 
The result will be the same, because the two above explainations are essentially the same :D It just depends on how you deal with the data. With microcontrollers/CPU' you tend to deal with bytes, thus the '8-bit becomes 16-bit' part. I usually just use a lookup table, split a byte into nibbles, and encode each seperately, meaning a byte -> 2x 4-bit nibbles -> 2 'manchester' bytes.

However, if you're dealing with pure logic, CPLD's/FPGA's then generally these will work on a bit-by-bit basis, encoding each bit on its own, by reading it in, then switching to its compliment. But with that method, the datarate out is double the datarate in, because its purely serial, no storage of bytes anywhere.

As for 'standards', I've seen both 0->01, 1->10 AND 0->10, 1->01 used. As long as your tx and rx agree on the rules, it'll be fine. The whole point of manchester/biphase encoding is that each bit has a transistion in the middle of it, making it self-clocking, synchronous. Very reliable, easy to do, but you pay the price for doubling the bandwidth used, or halving the available datarate (because you're sending two 'chips' for every data bit).

There are other methods varying in complexity (4B/6B, 8B/10B, data whitening), but manchester is a great place to start for RF/DC-balanced comms.

I'm a complete newbie with C at the moment, so I can only suggest maybe a case statement, but deffinately working on a byte-byte basis. That is, a routine that takes in a byte, but outputs two bytes, essentially working in parallel. I've seen plenty of C-based routines whilst googling for channel coding methods, I'm sure you'll find something. Google has (almost) everything.

Blueteeth
 
As Nigel said though, anyone can do Manchester encoding, it's very simple. The decoding is the hard part because if you're off by a half of the baud rate you get garbage.
 
He is using C, download mikroC and have a look at the Manchester examples

Heres what it's like in mikroBasic;
Code:
program RRX

dim error, ErrorCount, temp as byte

main:
  ErrorCount = 0
  TRISB      = 0
  CMCON = 7
  ' VRCON = 0  ' Uncomment the line for PIC16
  Lcd_Init(PortB)                ' Initialize LCD on PORTB
  Lcd_Cmd(LCD_CLEAR)
  Man_Receive_Config(PORTA,3)    ' Configure and synchronize receiver

 
  while true

    Lcd_Cmd(LCD_FIRST_ROW)

    while true                   ' Wait for the start marker
      temp = Man_Receive(error)
      if temp = $0B then
        break
      end if                     ' We got the starting sequence
      if error then              ' Exit so we do not loop forever
        break
      end if
    wend

    do
      temp = Man_Receive(error)  ' Attempt byte receive
      if error = true then
        Lcd_Chr_Cp(63)           ' ASCII for "?"
        Inc(ErrorCount)
        if ErrorCount > 20 then
          Man_Receive_Init(PORTA)
          ' alternative:
          ' temp = Man_Synchro
          ErrorCount = 0
        end if

      else
        if temp <> $0E then      ' Don't write the end marker on LCD
          Lcd_Chr_Cp(temp)
        end if
      Delay_ms(20)
      end if
    loop until temp = $0E        ' Wait for the end marker

  wend
end.

The above example will receive Manchester encoded information, and check for errors. It will wait for the start marker (or header) of the information "$0B", and then display each byte on an lcd, and any errors will be displayed as a "?". This will keep going until the end marker (or footer) "$0E" is received.
 
Yes encoding is easy but decoding is tough...currenlty im just tryin to follow exactly the coding and decodind manchester tht i get frm nigel webpage and translating it in C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top