Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
test-and-measurement:guides:manchester-encoding [2022/09/12 19:01] – changed forum.digilentinc.com to forum.digilent.com Jeffrey | test-and-measurement:guides:manchester-encoding [2023/04/18 15:53] (current) – Martha | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Decoding a Manchester Encoded Signal ====== | ||
+ | ~~TechArticle~~ | ||
+ | {{ reference: | ||
+ | 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 ===== | ||
+ | <WRAP group> | ||
+ | == Hardware == | ||
+ | * A Digilent [[https:// | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | * [[test-and-measurement: | ||
+ | |||
+ | == Software == | ||
+ | * [[software: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | </ | ||
+ | |||
+ | **Note:** //WaveForms can be installed by following the [[software: | ||
+ | ---- | ||
+ | |||
+ | ===== Manchester Code ===== | ||
+ | <WRAP group>< | ||
+ | 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. | ||
+ | </ | ||
+ | {{ : | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | 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 ==== | ||
+ | <WRAP group> | ||
+ | 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, | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | 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 ==== | ||
+ | <WRAP group> | ||
+ | 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 ===== | ||
+ | <WRAP group> | ||
+ | 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: {{ reference: | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | 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(" | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | 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 " | ||
+ | </ | ||
+ | # convert the string to binary | ||
+ | binary_format = " | ||
+ | raw_binary = "" | ||
+ | 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[:: | ||
+ | |||
+ | # double every bit | ||
+ | binary_data = "" | ||
+ | |||
+ | # create array for clock | ||
+ | binary_clock = "" | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | 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 " | ||
+ | </ | ||
+ | # get numbers from characters | ||
+ | data = [] | ||
+ | for index in binary_data: | ||
+ | data = numpy.concatenate((data, | ||
+ | data = data.astype(" | ||
+ | |||
+ | clock = [] | ||
+ | for index in binary_clock: | ||
+ | clock = numpy.concatenate((clock, | ||
+ | clock = clock.astype(" | ||
+ | |||
+ | # generate code | ||
+ | manchester = data ^ clock | ||
+ | if falling_one: | ||
+ | manchester = 1 - manchester | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | Finally, create a data frame from the generated code and export it as a csv file. | ||
+ | </ | ||
+ | # export code | ||
+ | manchester = { " | ||
+ | code_data = pandas.DataFrame(manchester) | ||
+ | code_data.to_csv(" | ||
+ | </ | ||
+ | |||
+ | <WRAP group>< | ||
+ | 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), | ||
+ | |||
+ | 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: [[test-and-measurement: | ||
+ | </ | ||
+ | {{ reference: | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | ===== Decoding with the Logic Analyzer ===== | ||
+ | <WRAP group>< | ||
+ | To decode the Manchester encoded signal, open the Logic Analyzer instrument in WaveForms and add // | ||
+ | </ | ||
+ | {{ reference: | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | At Trigger settings, set up a protocol trigger to the first value of your message: in this guide the message " | ||
+ | |||
+ | {{ reference: | ||
+ | </ | ||
+ | |||
+ | <WRAP group> | ||
+ | Start the instrument. Set the time base and the position in a way, to make the message visible. | ||
+ | |||
+ | {{ reference: | ||
+ | </ | ||
+ | ---- | ||
+ | |||
+ | ===== Next Steps ===== | ||
+ | <WRAP group> | ||
+ | For more guides on how to use the Digilent Test & Measurement Device, return to the device' | ||
+ | |||
+ | For more information on WaveForms visit the [[software: | ||
+ | |||
+ | For technical support, please visit the [[https:// | ||
+ | </ | ||
+ | |||
+ | {{tag> |