September
2004, Issue 170
Multilab
Build
a Z8 Encore!-Based Multipurpose Test Instrument
IrDA
and RS-232 LINKS
The
design of the IrDA link to the Palm Pilot is simple,
thanks to Zilog. The Z8 Encore! contains two UARTs,
each of which includes a complete IrDA encoder-decoder,
or ENDEC. The IrDA physical layer encoding/decoding
isn’t a complicated process. The data format is basically
the same asynchronous format used for RS-232 serial
communications, except that instead of using two different
voltage levels to represent ones and zeros, the IrDA
format uses a short pulse within the bit cell time to
indicate a zero and the lack of a pulse to indicate
a one.
In
asynchronous data protocol, all characters start with
a 0 start bit; therefore, all IrDA characters start
with a short pulse representing this start bit. This
forms the timing reference needed to recover the following
8 data bits, as well as the stop bit at the end, which
is a one.
The
pulse width used by IrDA is defined as one-sixteenth
of the bit cell time (the reciprocal of the data rate).
It’s the timing of this pulse width that creates a bit
of a problem. In an MCU that contains just a standard
UART function, adding the ENDEC function outside the
MCU can be done using specialty chips designed for this
purpose, like the Texas Instruments TIR1000 and Unitrode
UCC5343. However, these devices require a timing reference
at 16 times the data rate used by the MCU’s UART.
This
timing signal, although definitely present within the
MCU’s UART block, is generally not brought out to any
of the MCU’s port pins. Therefore, it has to be provided
for in some other way. That’s why the ENDECs contained
within the Z8 Encore! are so handy.
I
used the Z8 Encore!’s UART1 for the IrDA port. To switch
from normal asynchronous data protocol to the IrDA protocol,
all you need to do is set the U1CTL1 register’s bit
0 to 1. The only hardware needed is the IrDA transceiver
module, which contains both the IR LED/driver and detector/amplifier.
During early tests, I was impressed with the operation
of the Zilog IrDA transceiver module contained on the
evaluation board, so I used a similar ZHX1820 transceiver
module for this project.
The
circuitry only handles the physical layer of the communications
link. There is an extremely sophisticated (meaning lots
of code!) protocol called irCOMM that PDAs, laptops,
and printers use to communicate with each other in a
wireless fashion. It handles all of the nitty-gritty
details of networking these devices together in an error-free
way.
The
Palm Pilot includes all of the drivers for the protocol
in its operating system. I did not come across an irCOMM
protocol stack for the Z8 in the C libraries I had.
When I looked at the protocol’s details, I decided it
was much too complex for my application.
IR
communication has some parallels in RF communication.
Stray noise found in RF is replaced with stray light.
In both cases the distance between the transmitter and
receiver may cause the received signal strength to vary
over a wide range. The IrDA transceiver modules do all
they can to combat this. The IR LED is pulsed fairly
hard to produce a strong IR light signal, and an AGC-controlled
amplifier follows the photodector to even out the differences
in received signal strength.
In
my experiments with a Palm Pilot and the Z8 Encore!
development board, I found only a few things that you
need to worry about when trying to achieve error-free
data transfers between the two devices. First, note
that you have to keep the two devices pointed at each
other at a distance of less than one yard. Second, allow
a fraction of a second of dead time between transmitting
and receiving data because the IrDA link is only a half-duplex
link. Third, send a short preamble before the actual
message because the IrDA receiver operates using AGC.
The preamble gives the receiver time to adjust from
a state in which it looks (in a sensitive way) at stray
light to a state in which its gain has been adjusted
to match the level of the incoming IR signal. I chose
a 10-character preamble of 0xFF bytes before the actual
message. As a result, the byte pattern sends one short
start pulse per character (the start bit) with which
the receiving UART easily synchronizes.
Finally,
frame the message to start with a start-of-text control
character and end with an end-of-text control character.
This allows the receiving end to easily identify the
actual message. Using this simple scheme, it’s easy
to transmit data back and forth between this design
and the Palm Pilot that controls it.
I
used UART0, along with a MAX232 for level shifting,
for the RS-232 link to the PC. Although the preamble
and message protocol used for the IrDA link isn’t necessary
for this direct-wired link, I used it here as well to
simplify the program.
Fortunately,
the MobileVB software I used to write the Palm Pilot
application supports both RS-232 and IrDA communications
links. It also provides for both raw, which I used,
and irCOMM protocols for the IrDA link.