Manchester encoding

The encoding in Manchester technique is established when we add the correct transitions to the message signal in relation to the data that will be transmitted. Several steps are used. The first one is to fix the data rate, then the mid-bit time which correspond to ½ of the data rate period.
Below, we are going to use an example in order to clarify the principle of decoding in Manchester code.

We choose to use a data rate of 5 KHz. So, the bit period in this case is T = 1/f = 1/5000 = 200 micro second. Dividing by 2, we obtain the mid-bit value which is 100 Micro-second.
Once we do that, now we will encode a data which is 0XC5 (for example). This data correspond to 11000101.
So we use a timer to interrupt at each 100 micro second, we need also to track which ½ bit period are we sending.
Once we finish this, we can easier encode the data.

1. Begin with the output signal high.
2. Check if all bits have been sent, If yes, then go to step 7
3. Check the next logical bit to be coded
4. If the bit equals “1”, then call ManchesterOne(T)
5. Else call ManchesterZero(T)
6. Return to step 2
7. Set output signal high and return

Implementation of ManchesterOne(T)

1. Set the output signal low
2. Wait for mid-bit time (T)
3. Set the output signal high
4. Wait for mid-bit time (T)
5. Return

Implementation of ManchesterZero(T)

1. Set the output signal high
2. Wait for mid-bit time (T)
3. Set the output signal low
4. Wait for mid-bit time (T)
5. Return

By doing these steps, we encode the data into a Manchester message signal at the desired data rate. Otherwise, the accuracy of the data rate and the duty cycle will depend on the clock source and the method used to create the wait times.