Maybe this will help.
Code:
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.
Code:
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:
Code:
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.
Bookmarks