PDA

View Full Version : encode/decode manchester



a_critchlow
- 2nd February 2006, 21:51
could anyone explain this to me in more detail please?



Encode:
For i = 0 to 7 ' loop for 8-bits
outword.0[(i*2)] = ~inbyte.0[i]
outword.0[(i*2)+1] = inbyte.0[i]
Next i '
Return

Decode::
For i = 0 to 7
outbyte.0[i] = ~inword.0[i<<1]
Next i
Return





The main line i dont understand is: outword.0[(i*2)] = ~inbyte.0[i]




thank you all for your time

Ioannis
- 3rd February 2006, 14:24
The main line i dont understand is: outword.0[(i*2)] = ~inbyte.0[i]


That means bit i*2 of outword be the NOT (the inverse of) inbyte bit i

Ioannis

Michael
- 3rd February 2006, 14:43
I don't get any of it.

Please, someone, a manchester encoding for dummies tutorial.

Melanie
- 3rd February 2006, 16:54
Do a SEARCH on 'manchester' on this forum and all will be revealed.

a_critchlow
- 4th February 2006, 13:01
ive figured out the encoded part but i cant get the decoded part into my head:


outbyte.0[i] = ~inword.0[i<<1]


if the counter is at 0, it should put the first bit of the encoded data inversed into the decoded data var. but because of the <<1 it puts the second bit inversed into the first decoded var.




thanks.

Ioannis
- 4th February 2006, 19:22
ive figured out the encoded part but i cant get the decoded part into my head:


Don't bother. If you do not understand this code, there are many other codes doing the same thing. Or better, create your own.

The idea is this: if you have to send 0 then in manchester you will send 01 pair. If you have to send 1 then in manchester you will send 10 pair.

So, for the byte

1 0 0 1 1 0 0 1

the result would be:

10 01 01 10 10 01 01 10

Is it clear now? You can simply do an if-then-else sub routine for the encoder and also the same for the decoder (in reverse of course).

As Melanie stated, a search will reveal much more. This case is trivial by now...

Ioannis

Michael
- 4th February 2006, 22:39
Nicely stated and thanks for spelling it out....at least for me.

Now that's Manchester for dummies without the gobble dee gook.

I felt it must have been a 2x code for 1x code or something when I saw it come up in discussions about wireless.

The opposite of compression? More bits for the same thing?

I still have some problems with a bit of code that works fine wired but not wireless.

I would think 2 or 3 qualifiers in a serout string would be good enough for wireless and do the same thing.

?

a_critchlow
- 5th February 2006, 14:58
yeah i understand how it works, i just dont see how the decoded part of the code works. you need to first decode index at zero before you start moving through the rest of the decoding process. the code says start at counter=0 and move left 1, this does not invert the correct bit.

Bruce
- 5th February 2006, 16:08
Maybe this will help.


Encode:
For Index = 0 to 7 ' loop 8-bits
Manch.0[(Index<<1)] = ~ByteIn.0[Index] ' Encode bits 0,2,4,6,8,10,12,14 in Manch
Manch.0[(Index<<1)+1] = ByteIn.0[Index]' Encode bits 1,3,5,7,9,11,13,15 in Manch
Next Index
Return
I'll skip to the decode routine since you already know how the encode routine works.

Option #1 that you think is wrong.


Decode:
For Index = 0 to 7 ' loop for 8 bits
ByteOut.0[Index] = ~Manch.0[Index<<1]' ByteOut=NOT Manch bits 0,2,4,6,8,10,12,14
Next Index
Return

you need to first decode index at zero before you start moving
through the rest of the decoding process
It is starting at 0.

On the 1st pass through the above loop, when Index = 0, what is the result of Index<<1..?

Index<<1 is the same as Index*2, and 0 shifted left by 1 or 0*2 is still 0.

So on the 1st pass through the loop, when Index = 0, ByteOut.0[Index] = ~Manch.0[Index<<1] is working on Manch.bit0.

Option #2 will also work, but it requires a 2nd bit index pointer.

Option #2:


Decode2:
Index2 = 1 ' Bit index pointer for Manch starts at 1 here
For Index = 0 to 7 ' loop counter & bit index pointer for ByteOut
ByteOut.0[Index] = Manch.0[Index2] ' ByteOut = ~Manch bits 1,3,5,7,9,11,13,15
Index2 = Index2 + 2 ' Increment Manch bit index pointer by 2 on each pass
Next Index ' I.E. point to bits 1,3,5,7,9,11,13,15 in Manch
Return
Decode2 works on the 'true' bits that were encoded. Not the inverted bits.

a_critchlow
- 6th February 2006, 08:50
brilliant! thank you very much Bruce, thats the exact answer i was looking for. i see that moving bits left is the same as multiplying.



thanks again




andrew.