terms of period (time, measured in seconds) rather
than the more useful notion of frequency. Lastly,
beginners sometimes trip over the algebra (elementary
as it may seem) needed for putting the various formulas
to good use.
So, in this article, I’ve rearranged the ideas to be
much more approachable, reworked everything naturally
in terms of frequency, and have taken care of all the
necessary mathematical finagling. By the time you
conclude with the lab demonstrations at the end, you
should be all set to start using pulse width modulation
in your own robotic designs.
To keep things concrete, I’ve focused specifically on
the common and inexpensive PIC16F88, but the ideas are
similar for other PICs. Let’s get some language down first.
Refer to Figure 1 which shows a representation of a
rectangular waveform. The total time required for one
complete cycle is called the period, typically measured in
The on-time is referred to as the duty — again a
measurement of time. It’s handier to
express this as a duty cycle (DC) in
percentage, as the figure indicates.
Within the PIC is a device called
the CCP module, which stands for
Capture/Compare/PWM. It can be
pressed into service in several
different ways, but for now all we
need to know is that it forms the
heart of the PWM machinery. Also
within the PIC is Timer2, which is
really nothing more than a counter
chugging away independently of the
remaining microcontroller innards.
Looking back at Figure 1, Timer2
counts away and when a certain
number is hit, the output pulse drops
low completing the duty portion. The
timer keeps incrementing and
eventually hits a second number
signaling that the output port pin
should go high again, thus concluding
the period. And so it goes forever, or
at least until Timer2 is shut off.
So, what about that port pin?
Well, here’s the first thing you need
to know. Thanks to the magic of
multiplexing, the PIC16F88 allows you
to select which of two pins (B.0 or
B. 3) should actually output the pulses.
Whichever is chosen, it will then be known as CCP1. This
is determined by the CONFIG1 configuration word
established when the microcontroller is programmed.
You’ll see how to set this in the software demonstrations
coming up shortly.
SERVO 05.2014 53