Design Article
Back to the future: Manchester Encoding - Part 2
Robert Guastella, Tennant Company
2/17/2008 5:40 PM EST
Design Overview
Albert Einstein once said that everything in life should be as simple
as possible, but no simpler. One of the benefits of Manchester Encoding
is how simple it is to implement. All that is needed is a tiny
microcontroller, a couple resistors, a MOSFET, and a few lines of code.
The circuit in Figure 1 below is a simplified, yet highly functional design that can be used as a foundation for communicating via Manchester Encoding. At the heart of this design is a Microchip PIC microcontroller; however any microcontroller with similar functionality will work equally as well.
Figure 1

One of the fundamental ingredients for an efficient implementation of Manchester Encoding is an analog comparator feature found on many microcontrollers. Exploiting this feature will provide more efficiency while simplifying and reducing the software required to implement Manchester Encoding.
Analyzing the Details
Let us take a closer look at the circuitry in Figure 1. The microcontroller
chosen for this example is a Microchip PIC 12F683. This
versatile, low-cost microcontroller comes in an 8-pin SOIC and contains
enough on-board peripherals to support a variety of applications.
For Manchester Encoding only two general purpose I/O pins are required. One pin is configured as an output and provides the gate drive voltage for controlling the MOSFET Q1. The other pin is used as an input to receive incoming Manchester Encoded data from another device on the communication line.
A high voltage on the output pin GP0 will turn ON the MOSFET, resulting in a high voltage on the Manchester Encoded Communications Line. The pull-down resistor R2 will ensure a low voltage on the communication line when the MOSFET is turned OFF.
The input pin labeled GP1 will be configured with the analog comparator function. This pin will basically "listen" to the communications line and provide the timing requirements necessary to properly decode the Manchester Encoded bit stream.
Open-Drain Output
If the microcontroller supports an open-drain output, the circuit in Figure 1 can be simplified even more
(See Figure 2 below).
Figure 2

With an open-drain output, the pin from the microcontroller can be tied directly to the communication line. In doing this, the pull-down resistor in Figure 1 is changed to a pull-up, and the MOSFET can be removed completely from the circuit.
It is worth noting that care should be taken when using open-drain outputs. Setting and resetting outputs may not be as straight forward as it would seem. Many microcontrollers use "read-modified-write" instructions when setting or resetting bits on various output ports.
The problem is that the microcontroller will read the voltage level of the pin itself, rather than the output latch, when trying to determine the current state of an output. This voltage level on the pin is used when writing back to the output latches. Many developers have spent hours debugging designs because of this one crucial issue.
Analog Comparator
As mentioned earlier, the analog comparator feature is used to enhance
the efficiency of receiving Manchester Encoded data. Let's take a
closer look into why this feature is so important.
Recall that Manchester Encoding is unique to other forms of serial data transmission because it uses bit transitions rather than logic levels to identify a logic "1" or logic "0". In Figure 3 below the rising edge signal represents logic "0", while the trailing edge signal represents logic "1".
Figure 3

The analog comparator circuitry within the PIC microcontroller can be configured to generate an interrupt on any transition that occurs on its input signal line.
This means that a level transition for a logic "0", as well as logic "1" will trigger an interrupt to occur. This allows the microcontroller to decode the Manchester Encoded signal into the proper logic "1" or logic "0" value.
Figure 4

Software Design
1) Initialization. Before
the PIC microcontroller can begin receiving Manchester Encoded data it
needs to be properly configured. The microcontroller initialization
process comprises setting up the on-board analog comparator circuitry,
the two free-running timers, and the two pins as an output and an
input.
2) Analog Comparator. For the analog comparator circuitry this design will use the "Multiplexed with Internal Reference" configuration (see PIC datasheet for details). This is accomplished by writing 0x0E to the CMCON0 register. Within this configuration register the CIS bit is set to logic "1", which will channel the input signal through the CIN+ pin.
The next register to setup is VRCON, which is responsible for establishing the internal voltage reference to the input of the comparator. For this design a reference voltage will be set to half of the supply voltage. This is accomplished by writing 0xAC to the VRCON register.
Next, the Peripheral Interrupt Register (PIE1) is configured, which will enable the Comparator interrupts to function. This is accomplished by writing a 0x40 to the PIE1 register.
Lastly, the Comparator Interrupt Flag bit needs to be cleared in order to allow further interrupts to occur. This is done by setting the CMIF bit to zero.
3) Free-Running Timers. Two free-running timers will be used to assist in constructing and decoding Manchester Encoded data. Timer 0 will be used in the construction (encoding) of the data stream.
The configuration register TMR0 is setup to generate an interrupt period equal to twice the desired Manchester Encoded bit rate. So for example, if you desire a bit rate of 5 KHz (200us), the interrupt rate should be set to 100us.
Timer 1 is used as part of the decoding procedure. This timer will be used by the analog comparator interrupt service routine to determine whether the signal transition received is a SETUP or DECODE transition.




Therm82
2/14/2008 9:55 AM EST
This is a well written article by Mr. Gustella. Also, thanks Embedded.com for allowing the entire article to be printed in one print job and without many large ads!
Sign in to Reply
mitME
2/15/2008 3:56 PM EST
This article is LESS THAN USELESS.....
With phrases as "Figure 6 below shows..." and others referring to figures containing code that is UNREADABLE, either on-screen or in hard copy. Many EMBEDDED.com articles have the ability to click on the image and make it larger and therefore READABLE.
I am so upset because I was able to follow PART 1 but NOT PART 2, thereby making the entire effort useless and a a big waste of time. The author should have reviewed other articles in EMBEDDED.com to be aware of this potential problem and its remedy.
Who is checking these articles BEFORE they get published? ARE YOU LISTERNING EDITOR?????
Sign in to Reply
mitME
2/15/2008 4:00 PM EST
#
mitME
CTO
commented on Feb 15, 2008 3:56:39 PM
This article is LESS THAN USELESS.....
With phrases as "Figure 6 below shows..." and others referring to figures containing code that is UNREADABLE, either on-screen or in hard copy. Many EMBEDDED.com articles have the ability to click on the image and make it larger and therefore READABLE.
I am so upset because I was able to follow PART 1 but NOT PART 2, thereby making the entire effort useless and a a big waste of time. The author should have reviewed other articles in EMBEDDED.com to be aware of this potential problem and its remedy.
Who is checking these articles BEFORE they get published? ARE YOU LISTENING EDITOR?????
Sign in to Reply
ESD editorial staff: SRambo
2/22/2008 3:13 PM EST
Thanks for pointing out the problems with the figures and code. You can now view a larger image by clicking on the link below each Figure and Listing.
Sign in to Reply
EEH
3/6/2008 9:50 PM EST
I just read parts 1 and 2 of this article and found it helpful. Having code samples that are not readable must have been like climbing to the top of a mountain and discovering there is a road up the back side ... but this is not exactly a beginner topic.
I am in the middle of a new design using the MSP430 to decode some Manchester RF data and I have spent alot of time carefully researching this topic by reading TI's app notes and sample source code. These articles are good indicators about the theory and some basic block level design points. I found them very useful, and easy to read (for me). If you are that easily frustrated by some of this material maybe you should look into hiring a consultant (like myself) to help you get the design nailed down.
Sign in to Reply
Erko
4/14/2008 3:41 AM EDT
We have used Manchester encoding to control the steering of a phased array antenna. I have published this in an article called: "A low cost transceiver for single wire sensor control" available via:
http://www.stw.nl/Programmas/Prorisc/Proceedings+2007.htm
In the article I explain why we could not use an existing communication standard and how we implemented the Manchester encoding/decoding on a microcontroller.
Sign in to Reply