Rubberbands andBAILING WIRE
by Jack Buffington
Transmitting data between devices is a
common task for electronic projects.
When the devices are near each other and
directly connected with a cable or circuit
board trace, you can often ignore the possibility of data errors. If, on the other hand,
the devices are separated by a long stretch
of wire or — even worse — by a radio link,
then you need to start thinking about ways
to detect when data errors have occurred
and how to correct them, if necessary.
Data errors can be caused by any
number of things, but common sources are
electromagnetic interference from outside
sources, such as motors that are electrically
noisy, other radio transmitters nearby, or by
the shape of your data bits changing as they travel down a
wire or are being distorted by your radio equipment.
For the purposes of this article, it will be assumed that
all of the data we are referring to is in serial format. This
article will discuss a few different strategies to help detect
errors when they are received and then move on to strategies
to recover data that is determined to be bad. Finally, it will
detail how to avoid errors in the first place.
The first and simplest method that you could use to
detect if there has been an error would be to simply send
each byte twice. At the receiving
end, you can just subtract one byte
from the other. If the result is zero,
then the data is likely to be good.
A slightly better method would
be to send your first byte normally
and the second byte with all of the bits
inverted. By performing an XOR operation
on the data, you will be able to detect if
the data is good, as the result would be all
ones. Inverting the second byte is slightly
better because, if the bytes are sent one
after the other and the error is caused by
an intermittent short in a wire, it will tend
to drive all of the bits either high or low.
XORing the data will detect this sort of
situation. XOR stands for eXclusive OR. The
truth table for XOR looks like Figure 1.
Figure 1. Exclusive OR
Figure 2. An
example of XOR.
Another simple way to assist in the
detection of errors is to encode your data using Manchester
encoding. Like the previous strategy, this method doubles the
amount of bits that need to be sent. Manchester encoding is
a method of encoding your serial data so that both the clock
signal and the data are sent simultaneously.
This type of encoding gives you the flexibility to change
your data rate dynamically because the receiver will be able
to sync itself to the sender’s clock. This can be useful in
situations where you are experiencing a lot of noise.
To encode data using Manchester encoding, you will
replace each bit that you are trying to send with two bits. If
the data bit that you want to send is a 0, then you would
send the two bits “01.” If the data bit that you want to send
is a 1, then you would send the two bits “ 10.” The end result
of this sort of encoding is that the signal that is sent will
never stay high or low for more than the time needed for two
bits. If the signal stays high or low for longer, then you will
know that you are receiving an error.
Figure 3. Manchester encoded data.
A third and very common way to detect errors in your
data is to use something called parity. If you are using parity,
you will add an additional bit to each byte that you send.
Parity can be either even or odd. The value of the parity bit
40 SERVO 07.2004