THEDESIGNCYCLE
ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
■ BY FRED EADY
MANAGING THE REAL WORLD
NO MATTER HOW POWERFUL A MICROCONTROLLER may claim to be, a
microcontroller by itself cannot do everything in a real-world, I/O-oriented
embedded system. For instance, I don’t know of any microcontroller that can
directly drive a one ampere resistive or inductive load directly from one of its
I/O pins. That means if you’re working on putting together a microcontroller-based system that will interface to motors and relays, a great deal of your
design time will be expended on the I/O interface hardware.
The same holds true if your microcontroller has to switch
high currents. You’ll have to put some heavy duty
electronic hardware between the microcontroller’s multi-milliampere I/O pin and the amperage hungry I/O device
at the other end. Amperage is not the only worry you have.
You can’t reliably drive a 12-volt relay coil with a raw 3.3-
volt or 5-volt microcontroller I/O pin. And, 12 volts may be
a drop in the bucket if you’ve got an I/O device that wants
to see a 60 volt source. What about controlling a standard
household AC device? Can you imagine driving a micro-controller I/O pin with 120 VAC? Smoke on the water.
Okay, suppose you’ve figured out a way to get those
high voltages and currents under control. Now, in addition
to wrangling the voltages and currents, you have to accurately read temperatures! I’m not talking room temperatures
that you would normally take with a temperature sensor like
the LM35C. Your temperature data will originate at the
point of a thermocouple.
Fortunately, every obstacle I’ve thrown into your
Design Cycle can be easily circumvented without resorting
to exotic or expensive special-purpose electronic components. In fact, we can solve every problem I’ve thrown out
on the table with a simple order to Mouser or Jameco. If
you’re still reading, I’ll show you how to easily drive relays,
solenoids, high-current devices, high-voltage devices, and
high-voltage/high-current I/O devices with a simple PIC
microcontroller and everyday electronic parts. We’ll also
take a look at getting that thermocouple data.
I/O BASICS
Professional athletes are drilled on the fundamentals of
their respective sports. That’s why they excel at what they
do. Musicians practice, practice, and practice some more.
That’s why you buy their musical work in the form of a CD
or a live performance. For us that dabble with electricity by
82 January 2008
indirectly moving electrons about within silicon lattices, a
firm grasp on the basics of I/O interfacing is as good as a
LeBron James dunk on Sunday afternoon.
To understand how to drive that device on the other end
of your microcontroller’s I/O pin requires that you understand
just what that microcontroller I/O pin can really do. Let’s use a
typical Microchip PIC as an example case. The run-of-the-mill
PIC can sink or source up to a maximum of 25 mA on most of
its I/O pins. That’s a measly 0.025 amperes per pin. The truth
is, 25 mA of sink/source capability is a relatively high value as
many other microcontrollers can only handle 20 mA or better
and only on a portion of their pin complement. I’ve seen
microcontroller datasheets that claim 40 mA maximum values
but I personally have not put that maximum figure to the test.
If you read the fine print in those high-current I/O
datasheets, the 40 mA maximum is just that — a maximum
value you’re not supposed to approach in normal use.
Reading carefully reveals that according to the test
conditions, the 40 mA per pin microcontroller can really
handle 20 mA @ 5V safely. Nevertheless, I have abused my
share of PIC I/O pins. I have accidentally driven PIC I/O
pins above 25 mA many times. (That’s something you don’t
want to do for any length of time.) There’s nothing worse
than trying to troubleshoot a “dead” PIC port pin.
If you think you can drive a bunch of 25 mA devices
without any intermediate buffering, you’re almost right as
long as you don’t exceed a total of 200 mA across all of the
I/O pins you are using to drive the loads. The point I’m trying to make here is that realistically you can’t drive anything
much larger than an LED load on a single PIC
microcontroller I/O pin. If you think in terms of each LED
drawing 10 mA, you can only drive a maximum of 20 LEDs
simultaneously directly from the I/O pins of a single PIC
microcontroller. I’ve not been brave enough to try this and
say I did it, and I don’t recommend that you try this at home.
Most of the time, I design my I/O buffer hardware so that