Decoding a Manchester Encoded Signal

The Logic Analyzer instrument in WaveForms can be used to easily decode Manchester encoded signals. The following guide presents what Manchester encoding is, what are its advantages over unencoded digital signals and how to decode such a signal using the Logic Analyzer instrument in WaveForms and a Test & Measurement device in a simple loop-back configuration.


Prerequisites

Manchester Code

A Manchester code is a self-clocking binary code achieved by encoding every data bit with a transition from high to low, or from low to high. This type of encoding is used mainly in applications where galvanic isolation is needed, or where the number of lines available for communication is limited.

There are two accepted standards of Manchester encoding: one in which HIGH values are represented by falling edges of the signal and LOW values by rising edges, and the inverse.


Advantages of Manchester Encoding

One of the most important advantages of this code is the lack of a separate clock signal. By encoding the clock in the data signal, the number of channels needed for communication is reduced to one, making this code optimal in applications where galvanic isolation is needed between the transmitter and the receiver, or in wireless communication, like IR, RFID and NFC applications.

Another advantage is, that this encoding scheme ensures that the resulting signal won't remain at a logic HIGH or LOW level for a longer period of time, so the signal can be AC coupled, which means that the DC component of the signal can be eliminated. This type of filtering is not available in the case of unencoded digital signals, as a long, uninterrupted sequence of ones or zeros would result in the same voltage level after the decoupling capacitor. AC coupling offers some sort of protection against fault currents circulating in the circuit and can resolve common-mode range incompatibility in some cases.

A simulation of AC coupling an unencoded digital signal is presented below. The ambiguous voltage level (0V) can be observed every time, when a longer series of HIGH or LOW bits appear.


Disadvantages of Manchester Encoding

The most important disadvantage of this encoding scheme is that data rate is only half of the bandwidth. In other words, to send one information bit, two logic states have to be sent, thus the frequency of the outgoing signal must be twice as large as the number of incoming information bits per second. If we consider the signal frequency constant (limited by the clock frequency of our device), the data rate is only half than in the case of the unencoded data signal.


Generating a Signal to be Decoded

To demonstrate the usage of the Manchester decoder in the Logic Analyzer, we will need a signal to decode. For this we will use the Pattern Generator instrument from WaveForms and a digital I/O line of the selected Test & Measurement device in simple loop-back configuration (the same digital line is used both as input and output - no external connections are needed). As the Pattern Generator instrument can't generate a Manchester code by default, a Python script will be used to create the binary data and to save it to a csv file, which can be imported later in WaveForms. You can download the script from here: code_generator.zip, or you can follow the steps below to write your own script.

First, define the parameters of the signal: which standard to use (HIGH = falling edge, or HIGH = rising edge), endianness and the number of data bits. Then import the necessary packages: in this script we will use NumPy to generate arrays and Pandas to export the result to a csv file.

Get the input string.

# define parameters
falling_one = True
LSB_first = True
nr_bits = 8
 
# import necessary modules
import numpy
import pandas
 
# get the input data
input_data = input("Enter the message: ")

Convert the input string to binary, then, if necessary, invert the order of the octets.

Double every bit (this way you make the data signal two times “slower”), then generate a clock signal: an array which contains alternating “1”-s and “0”-s and has the same length as the data signal.

# convert the string to binary
binary_format = "0{}b".format(nr_bits)
raw_binary = "".join(format(ord(index), binary_format)
                     for index in input_data)
 
# invert string if necessary
if LSB_first:
    temporal = raw_binary
    raw_binary = ""
    for index in range(0, len(input_data)):
        current_byte = temporal[index * 8 : (index + 1) * 8]
        raw_binary = raw_binary + current_byte[::-1]
 
# double every bit
binary_data = "".join(index + index for index in raw_binary)
 
# create array for clock
binary_clock = "".join("1" + "0" for index in raw_binary)

Convert the strings to arrays of integers, then get the Manchester code from the two arrays by applying a bitwise XOR (exclusive or) operator to the two arrays (element-by-element). Change “1”-s to “0” and “0”-s to one if you want to change the standard.

# get numbers from characters
data = []
for index in binary_data:
    data = numpy.concatenate((data, ord(index) - 48), axis = None)
data = data.astype("int")
 
clock = []
for index in binary_clock:
    clock = numpy.concatenate((clock, ord(index) - 48), axis = None)
clock = clock.astype("int")
 
# generate code
manchester = data ^ clock
if falling_one:
    manchester = 1 - manchester

Finally, create a data frame from the generated code and export it as a csv file.

# export code
manchester = { "Data": manchester}
code_data = pandas.DataFrame(manchester)
code_data.to_csv("manchester_code.csv", index = False)

Open WaveForms, connect it to your device, then open the Pattern Generator instrument. Add a new Signal and select DIO 0. Set the Output to PP (Push-Pull), the Type to Custom, then import the csv file, leaving every other setting on default.

Set the Wait time to 10ms and the Run mode to auto by checking the respective box. Start the Pattern Generator.

Note: For more information check: Using the Pattern Generator


Decoding with the Logic Analyzer

To decode the Manchester encoded signal, open the Logic Analyzer instrument in WaveForms and add Manchester at adding channels. Set the frequency to half of the frequency of the generated signal (500 Hz in this case). With the help of the respective drop-down lists, set the parameters of the encoding to the same as in the Python code. Set the Format to ASCII, to make the message readable.

At Trigger settings, set up a protocol trigger to the first value of your message: in this guide the message “Hello!” is encoded, so the trigger will be set to the value 48[H], where 48 is the hexadecimal code of the ASCII character “H”.

Start the instrument. Set the time base and the position in a way, to make the message visible.


Next Steps

For more guides on how to use the Digilent Test & Measurement Device, return to the device's Resource Center, linked from the Test and Measurement page of this wiki.

For more information on WaveForms visit the WaveForms Reference Manual.

For technical support, please visit the Test and Measurement section of the Digilent Forums.