
Manchester encoding explained
Manchester encoding combines the clock and data of (typically) synchronous
data into one serial data stream. The combination is simply an exclusive - NOR:
manchester data = NRZ data ^ (NRZ clock)'
where
NRZ data == Non-Return to Zero data. A fancy way of saying there is no
encoding i.e. a logic 1 is +5 volts and a logic 0 is 0 volts.
NRZ clock == A clock whose rising edge occurs in the middle of each NRZ data bit
^ == exclusive or operator
( )' == The boolean complement operator
Here's an example comparing NRZ to Manchester:
-+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+
NRZ | | | | | | | | | | | | | | | | |
clock +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--+ +--
+-----+ +-----+ +-----------------+
NRZ | | | | | |
data -+ +-----+ +-----------+ +---
1 0 1 0 0 1 1 1
Manchester +-----+ +-----+ +--+ +--+ +--+ +--+
Encoded | | | | | | | | | | | |
Data ----+ +-----+ +--+ +-----+ +--+ +--+ +--
Click here
for this and other encoding schemes.
If you wish to "bit-bang" the serial data stream and decode the Manchester data,
typically, a bit-banging algorithm goes as follows.
1) Synchronize to the input data stream by hunting for an edge. For NRZ
data, you would hunt for the falling edge of the start bit. For Manchester
data, you will continuously have edges. This could be either good or bad
(see below).
2) Wait for one half bit time. Presumably, the data is "cleanest" in the
middle of a bit.
3) Wait for one whole bit time.
4) Sample the input data. Note that this sample will occur in the middle of a bit.
5) Decode the data bit, i.e. convert from Manchester to NRZ.
6) go to step 3.
The "continuous edges" of Manchester-encoded data dilemmma/panacea depends
on your computing resources. If you have to use the PIC16C54 with a 32kHz
crystal, your capabilities are extremely limited. Instruction cycles are
around 125 usec. However, you need at least two cycles to acquire one sample.
Yet a moderate data rate of 9600 baud (NRZ) has a bit time of about 100 usec.
I think you see the picture.
On the other hand, if you can increase the frequency, then it is possible to
continuously re-synchronize to the data. This will allow you to accurately
sample the middle of the data bits, and perhaps saving you the burden of
having to filter the data.
Thanks to Scott Dattalo for this.