As the full name implies, the CCP module has been designed to handle three different but vaguely related applications. This article focuses exclusively on the capture aspect. Its primary purpose is to
accurately measure the period or duty cycle of an incoming
pulse wave — a capability that's invaluable in reading a wide
variety of digital sensors. You could also build your own
PWM communications system, or debounce microswitches
in a wall sensor. These are all possible with the CCP module
operating in capture mode.
In general, any time you are sensing events that convey
meaning according to how long or how fast they occur, the
capture module is the helper to call upon.
Let's see how it works. Overview of the Capture Process
Most PICs contain at least one CCP unit. To keep this
article specific, I’ll focus on the common and inexpensive
PIC16F88, but bear in mind that the module works similarly
in other chips. Let’s consider how it’s been implemented in
broad strokes first. Refer to Figure 1 which depicts the
functional arrangement of the capture module.
Running in the background is a timer; it’s really just a
16-bit binary counter that keeps chugging away from 0 on
up to 65535, rolling over to 0, and continuing likewise in
perpetuity. This is denoted as Timer 1 by the PIC
manufacturer. It may be clocked in several different ways,
but for now just assume that the system clock of the
microcontroller is stepping it along. At any given moment,
the two bytes TMR1H and TMR1L (concatenated to form a
word) indicate the current value of Timer 1. Let it keep
running for the moment, and turn your attention to the left
side of Figure 1.
An external signal is applied to either port line B.0 or
B. 3. This may be a single pulse if you’re simply measuring
the on-time of a switch or a sensor, or could be an ongoing
pulse train if you’re wanting to determine frequency (which
is nothing more than the reciprocal of the period). Which
port line to be used is determined when the PIC is Flashed
By Thomas Henry
SERVO 07.2014 51
PICmicrocontrollers sport a number of useful peripheral devices, but some appear to lurk in the background not getting the attention they deserve. Or, maybe it's just they seem so complicated that the newcomer shies away, not knowing how to begin. The Capture/Compare/Pulse Width Modulation unit (called CCP from now on) is just such a module. It's so handy that it's a shame not to learn how to use it early on.
Post comments on this article and find any associated files and/or downloads at
Figure 1. Block diagram of the capture process.