Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C code for Manchester encoding and decoding a byte of data

Status
Not open for further replies.

Munib

Advanced Member level 4
Joined
Jun 11, 2004
Messages
114
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
1,129
manchester coding

Can some body give me C code to Manchester encode and decode a byte of data .
I am using PIC18F452 mcu and C18 compiler.

I need a function like

Encode(byte in)
{
return (byte [2] manchester);
}

Decode(byte [2] manchester)
{
return(byte out);
}
 

mcu manchester coding

Thats really simple:

Encode your logic 1s as a 01 and your logic 0s as a 10 (or vice versa ... logic 1 = 10 and logic 0 = 01).

Example:

encoding a byte "11010001" results into MSB:"01011001" + LSB:"10101001"

simple enough?
 

manchester coding sample

Yes its really very simple to manchester encode and decode the data manually by ourself or by using a lookup table in a mcu
But what i want is some function to encode/decode the data in a mcu
 

mcu manchester decode

Maybe this website can be helpfull to you.

**broken link removed**

Note: I haven't used manchester coding myself but the implemetation looks fairly straightforward.
 

Re: Manchester coding

Hi, just thought I'd add my $0.02 :)

I've used manchester (similar to biphase) coding in a PIC16F818 to test the BER of an RF link. I did it by splitting my input byte into two 4-bit nibbles, and used a LUT of 16 entries (1 for every possible 4-bit combination). I think its only used a total of 10 lines of code, plus the LUT.

Pseudocode:
Move inbyte to temp register
Move to W
And with 00001111 ; gets rid of the four MSB's
Call look-up table
Move result to outbyte1
Swap nibbles in temp (swapf temp,W)
And with 00001111
Call look-up table
Move result to outbyte2

Note: outbyte2 is the 4-MSB, outbyte1 the 4-LSB.

And there it is, the LUT is simple as well: ie: 00000000 -> 10101010
with the last entry being: 00001111 -> 01010101
If you're unsure what to put in the LUT, theres plenty of info on the net about manchester encoding.

I think thats right, but I'm rusty. I did it ages ago, and maganged to get 1.5MB/s out of the PIC (with the aid of a shift register).

As for decoding, bit more tricky. A clever use of interupts could be used, since a '1' is an upward transistion, and a '0' a downward one. You'll need to add a preamble in your packet to train your decoder so it knows where to sample. (check for rising edge and transmit all 1's).

Hope this helps,

BuriedCode
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top