{"id":28166,"date":"2021-06-01T05:02:59","date_gmt":"2021-06-01T12:02:59","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=28166"},"modified":"2021-04-01T15:37:58","modified_gmt":"2021-04-01T22:37:58","slug":"decoding-a-manchester-encoding-signal","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/decoding-a-manchester-encoding-signal\/","title":{"rendered":"Decoding a Manchester Encoding Signal"},"content":{"rendered":"<p>The Logic Analyzer instrument in <a href=\"https:\/\/store.digilentinc.com\/digilent-waveforms\/\">WaveForms<\/a> can be used to easily decode <a href=\"https:\/\/www.allaboutcircuits.com\/technical-articles\/manchester-encoding-what-is-it-and-why-use-it\/\">Manchester encoding<\/a> 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 &amp; Measurement device in a simple loop-back configuration.<\/p>\n<h5>What is Manchester Encoding?<\/h5>\n<p>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\u00a0<em>HIGH<\/em>\u00a0values are represented by falling edges of the signal and\u00a0<em>LOW<\/em>\u00a0values by rising edges, and the inverse.<\/p>\n<h5>Why Use Manchester Coding? What is the Advantage?<\/h5>\n<div class=\"group plugin_wrap\">\n<p>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.<\/p>\n<\/div>\n<div class=\"group plugin_wrap\">\n<p>Another advantage is that this encoding scheme ensures that the resulting signal won&#8217;t remain at a logic <em>HIGH<\/em>\u00a0or\u00a0<em>LOW<\/em>\u00a0level 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.<\/p>\n<h5>What are the Disadvantages of Manchester Encoding?<\/h5>\n<p>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.<\/p>\n<h5>Generating a Signal to Be Decoded<\/h5>\n<div class=\"group plugin_wrap\">\n<p>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 &amp; Measurement device in simple loop-back configuration (the same digital line is used both as input and output &#8211; no external connections are needed). As the Pattern Generator instrument can&#8217;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 follow the steps below to write your own script.<\/p>\n<\/div>\n<div class=\"group plugin_wrap\">\n<div class=\"wrap_half wrap_column plugin_wrap\">\n<ol>\n<li>First, define the parameters of the signal: which standard to use (<em>HIGH<\/em>\u00a0= falling edge, or\u00a0<em>HIGH<\/em>\u00a0= 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.<\/li>\n<li>Get the input string, then convert it to binary. If necessary, you can invert the order of the octets.<\/li>\n<li>Double every bit (this way you make the data signal two times \u201cslower\u201d), then generate a clock signal: an array which contains alternating \u201c1\u201d-s and \u201c0\u201d-s and has the same length as the data signal.<\/li>\n<li>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 \u201c1\u201d-s to \u201c0\u201d and \u201c0\u201d-s to one if you want to change the standard.<\/li>\n<li>Create a data frame from the generated code and export it as a csv file.<\/li>\n<li>Open WaveForms, connect it to your device, then open the Pattern Generator instrument. Add a new Signal and select DIO 0. Set the\u00a0<em>Output<\/em>\u00a0to\u00a0<em>PP<\/em>\u00a0(Push-Pull), the\u00a0<em>Type<\/em>\u00a0to\u00a0<em>Custom<\/em>, then import the csv file, leaving every other setting on default.<\/li>\n<li>Set the\u00a0<em>Wait<\/em>\u00a0time to 10ms and the\u00a0<em>Run<\/em>\u00a0mode to auto by checking the respective box. Start the Pattern Generator.<\/li>\n<\/ol>\n<h5>Decoding a Manchester Code with the Logic Analyzer<\/h5>\n<p>One you&#8217;ve generated it, your Manchester code is easy to decode using WaveForm&#8217;s Logic Analyzer instrument. Just open Logic Analyzer, and go to &#8220;<em>Add Manchester&#8221;<\/em> under Adding Channels. Set the frequency to half of the frequency of the generated signal (500\u00a0<abbr title=\"\" data-original-title=\"Hertz (times per second)\">Hz<\/abbr>\u00a0in 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\u00a0<abbr title=\"\" data-original-title=\"American Standard Code for Information Interchange\">ASCII<\/abbr>, to make the message readable.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-28168\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2021\/04\/manchester_settings.png\" alt=\"Adding Manchester Setting in WaveForms\" width=\"282\" height=\"257\" data-wp-pid=\"28168\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>At Trigger settings, set up a protocol trigger to the first value of your message: in this guide the message \u201cHello!\u201d is encoded, so the trigger will be set to the value 48[H], where 48 is the hexadecimal code of the\u00a0<abbr title=\"\" data-original-title=\"American Standard Code for Information Interchange\">ASCII<\/abbr>\u00a0character \u201cH\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-28169\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2021\/04\/manchester_trigger-600x94.png\" alt=\"\" width=\"600\" height=\"94\" data-wp-pid=\"28169\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2021\/04\/manchester_trigger-600x94.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2021\/04\/manchester_trigger.png 900w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The last thing to do is simply to start the instrument. Set the time base and the position in a way, to make the message visible. Voila! You&#8217;ve just decoded a Manchester Code.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-28166 jlk' data-task='like' data-post_id='28166' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-28166 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-28166 jlk' data-task='unlike' data-post_id='28166' data-nonce='ee750c7abc' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-28166 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-28166 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>The Logic Analyzer instrument in WaveForms can be used to easily decode Manchester encoding signals. The following guide presents what Manchester encoding is, what are its advantages over unencoded digital &hellip; <\/p>\n","protected":false},"author":50,"featured_media":28167,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4325,4323,1563],"tags":[452],"ppma_author":[4502],"class_list":["post-28166","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debug-validation-test","category-software","category-guide","tag-waveforms"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2021\/04\/manchester_standards.png","authors":[{"term_id":4502,"user_id":50,"is_guest":0,"slug":"davidh","display_name":"David Horn","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/44030532fc8d2bc9aa1d05f87c27d6f9?s=96&d=mm&r=g","author_category":"","user_url":"","last_name":"Horn","last_name_2":"","first_name":"David","first_name_2":"","job_title":"","description":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/28166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=28166"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/28166\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/28167"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=28166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=28166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=28166"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=28166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}