Decoding a Manchester Encoded Signal

波形中的逻辑分析仪仪器可用于轻松解码曼彻斯特编码的信号。以下指南介绍了曼彻斯特的编码是什么,其优点比未编码的数字信号以及如何使用波形中的逻辑分析仪仪器和简单的回路配置中的测试和测量设备对此信号进行解码。


Prerequisites

Note:WaveForms can be installed by following theWaveForms Getting Started Guide


曼彻斯特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高的值由信号的下降边缘表示低的values by rising edges, and the inverse.


曼彻斯特编码的优势

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高的或者低的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.

下面介绍了AC耦合的模拟未编码的数字信号。每次都可以观察到模棱两可的电压水平(0V),当高的或者低的bits appear.


曼彻斯特编码的缺点

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.


生成要解码的信号

为了在逻辑分析仪中演示曼彻斯特解码器的使用情况,我们将需要一个信号来解码。为此,我们将在简单的回路配置中使用波形的模式生成器仪器,以及所选测试和测量设备的数字I/O线(同一数字线被用作输入和输出 - 不需要外部连接)。由于模式生成器仪器默认情况下无法生成曼彻斯特代码,因此将使用Python脚本来创建二进制数据并将其保存到CSV文件中,该文件可以在稍后在波形中导入。您可以从这里下载脚本:code_generator.zip, or you can follow the steps below to write your own script.

首先,定义信号的参数:使用哪个标准(高的= falling edge, or高的= 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 parametersfalling_one=真的LSB_first=真的nr_bits=8# import necessary modulesimportnumpyimport熊猫# get the input data在put_data=在put("Enter the message: ")

然后,将输入字符串转换为二进制,然后,如有必要,将八位钟的顺序倒置。

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.

#将字符串转换为二进制binary_format="0{}b"格式(nr_bits)raw_binary=""join(格式(或者d(指数),binary_format)for指数在put_data)#如有必要iflsb_first:时间=raw_binary raw_binary=""for指数范围(0,len(在put_data)): current_byte=temporal[指数 *8:(索引 +1)*8]raw_binary=raw_binary + current_byte[::-1]#每一点加倍binary_data=""join(索引 +指数for指数raw_binary)#为时钟创建数组binary_clock=""join(“ 1”+“ 0”for指数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.

#从字符中获取数字数据=[]for指数binary_data: data=numpy。连接((数据,或者d(指数)-48),=没有任何)数据=数据。astype(“ int”)=[]for指数binary_clock: clock=numpy。连接((,或者d(指数)-48),=没有任何)=钟。astype(“ int”)#生成代码manchester=数据 ^时钟iffalling_one: manchester=1- 曼彻斯特

最后,从生成的代码创建数据框架,并将其导出为CSV文件。

#导出代码manchester={“数据”:曼彻斯特}code_data=熊猫。数据框架(manchester)code_data.to_csv("manchester_code.csv",指数=False)

打开波形,将其连接到您的设备,然后打开模式发生器仪器。添加新信号,然后选择DIO0。设置Outputto(Push-Pull), the类型to风俗,然后导入CSV文件,将其他所有设置留在默认情况下。

Set the等待time to 10ms and theRun通过检查相应的框来进行自动模式。启动模式生成器。

Note:有关更多信息检查:Using the Pattern Generator


Decoding with the Logic Analyzer

要解码曼彻斯特编码的信号,请在波形中打开逻辑分析仪仪器并添加曼彻斯特at adding channels. Set the frequency to half of the frequency of the generated signal (500赫兹在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 toASCII,使消息可读。

在触发设置处,设置了消息的第一个值的协议触发器:在本指南中,消息“ Hello!”。已编码,因此触发器将设置为值48 [h],其中48是该值的十六进制代码ASCIIcharacter “H”.

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


Next Steps

为more guides on how to use the Digilent Test & Measurement Device, return to the device's Resource Center, linked from the测试和测量page of this wiki.

为more information on WaveForms visit the波形参考手册

要获得技术支持,请访问测试和测量Digilent论坛的部分。