BY JAMES MOBLEY
my PC in my projects. I looked
around at some other products and
software, but none of them really
seemed to fit my need. I needed
something that I could use over and
over again in a variety of different
applications; a single board that
could interface with several different
projects at once, but was also cost-effective enough to justify dedicating
it to a single project if that project
demanded it.
I finally began to develop my own
computer interface board, which
would transform a standard serial
port into something more like the old
parallel ports from the days of DOS.
What Does the Board
Do and How Does it
Work?
The Data Acquisition Board
(DAQ) converts standard serial I/O
from a PC into a 20 pin parallel
I/O bus. Each of the 20 I/O pins is
individually configurable as an input
or an output. You can read the state
of each pin, or change the state if it’s
configured as an output, about a
1,000 times per second.
There is also the potential, with
some additional firmware, to add up
to five analog inputs with 10 bits of
resolution. You can communicate
with the board using binary
commands or text commands. The
text commands are easy to use, and
can even be executed with Microsoft
Hyper Terminal. The binary commands
require a better understanding of
ones and zeros, but are much faster
than the text commands. The board
operates at bit rates up to 115.2K, and
down to 300.
Why Did I Go With a
Serial Port Interface
Instead of a Parallel
Port or USB?
Although many will disagree with
me, there are a few advantages to a
serial connection:
1. Serial cables are cheap — you can
make your own without too much
trouble, and if you’re not worried
about noise, you can sploog one
together with just three wires: TX, RX,
and GND.
2. At the lower bit rates, you can use
serial cables 50 ft or longer. This has
enabled me to connect some projects
to the computer that would not
otherwise have been practical without
a wireless setup.
3. A computer’s serial port is easy
to access; you can use virtually any
programming interface, and all you
need are the standard drivers already
installed on your PC.
Hardware Design
The DAQ is built around the
PIC16F873A microcontroller (see the
schematic in Figure 2). I used a 1.8432
MHz crystal oscillator for the clock
because it’s compatible with most of
the standard serial port bit rates. You
may notice that 300, 600, 1200, 2400,
4800, 9600, 19200, 38400, 57600, and
115200 all divide into 1.8432M evenly.
Because of this, the DAQ can operate
at all those bit rates with virtually
no error.
RC6 and RC7 (pins 17 and 18 on
the PIC) are the TX and RX lines for
the serial communications; you
can’t just connect those two pins
directly up to your PC however. The
PIC is powered by a single +5V
power supply, but a standard serial
interface requires a negative
voltage, as well as a positive voltage
— a logical high is negative and a
logical low is positive. Likewise, the
transmit line coming from your
computer swings positive and
negative — if it was connected
directly to the PIC, it would most
certainly damage the chip.
The TX signal from the PIC needs
to be inverted and swing positive and
negative, and the RX going to the PIC
needs to be inverted and go from 0V
to +5V. I decided to go with the
LT1181ACN RS232 driver IC to interface between the microcontroller and
the computer. This is a handy little IC!
When the TX pin on the PIC goes high,
the TX out pin on the LT1181 goes to
about -8V. Likewise, when the TX pin
on the PIC goes low, the LT1181 goes
to about +8V. No additional power
supply needed!
How do you get + and -8V out
when you only have a +5V power
supply? The LT1181 not only does the
inverting for you, it also has a charge
pump on the chip to generate a + and
- voltage supply. Capacitors C5-C8 are
filter caps for the switching network
on the IC.
The MCLR pin on the PIC (pin 1)
and its associated components (R5,
R6, and C4) don’t make a very
interesting circuit. The circuit simply
causes the MCLR pin to go high a
short time after power-up which, in
turn, causes the PIC to reset. I did
want to pass on, however, that I tried
a few different resistor and capacitor
values before going with the ones
I did.
A 10 µF cap for C4 intuitively
seems very large for this application,
however, smaller values for this cap
cause a very frustrating problem. The
DAQ would be operating just fine,
and then it would freeze up for no
apparent reason. I went over and
over my firmware trying to find the
never-ending loop I was sure was
causing the problem, but I never
found it. I checked and rechecked
every solder joint trying to find the
loose wire, but I never found that
either.
After hours of troubleshooting
and getting nowhere, it finally
occurred to me that the PIC may be
resetting intermittently. After a little
more investigation, I found this to be
the case. I then started experimenting
with different values for R5 and C4; 10
kohms and 10 µF is what I ended up
with. Again, a 10 µF electrolytic capacitor doesn’t seem like the right answer
to me, but I’ve used the DAQ board
March 2006 39