Advertisement

Back to the future: Manchester Encoding - Part 2

Robert Guastella, Tennant Company

February 17, 2008

Robert Guastella, Tennant CompanyFebruary 17, 2008

In Part 1 of this series, I introduced the use of Manchester Encoding as a novel approach to designing a low-cost serial wired or wireless communications interface. In this second part, I will leverage upon this concept and provide a realistic example that will illustrate the simplicity of implementing Manchester Encoding into a real-world embedded design.

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

View the full-size image

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

View the full-size image

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

View the full-size image

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.

< Previous
Page 1 of 2
Next >

Loading comments...