(programmed). This pin is then denoted CCP1 and devoted
exclusively as the input to the CCP module from then on.
Observe that this is established by the configuration bits of
the chip (what some people call fuses) and doesn’t change
once the chip has been Flashed.
Jump ahead a little in the figure and notice the edge
select switch. Your program can decide whether to sense
either rising edges or falling edges. Additionally, in the case
of the former choice, you may also have the chip react to
every rising edge, every fourth, or every 16th. Think of this
as a prescaler to slow things down.
Remember, that timer we left a
moment ago is still counting away.
Whenever an edge event occurs
(whichever you selected in the previous
step), the current value of the timer is
latched into the capture register made up
of the two bytes CCPR1H and CCPR1L.
Thus, you have a record of how many
increments Timer 1 has made since the
last edge event. Because the timer runs at
a predicable frequency, we then know
exactly how much time has been
consumed. If you’d like, think of this as
one of the those elapsed-time
stopwatches used in sporting events.
With the principles of operation out
of the way, we can now get serious
about the nuts and bolts of actually
setting things up. Unlike the PIC
datasheet which throws you into the
deep end of the pool, I’ve broken things
up into logical units to be easily
assimilated. Tackling the details becomes so much more
straightforward. Setting Up Capture Mode
As a basic road map, here’s what needs to be done in
order to get the capture module up and running:
• Establish which pin is CCP1 and make it an input.
• Set the rate at which the timer operates.
• Start the timer counting.
• Set which type of edge
event is desired — rising or
• Set the prescaler for rising
edges, if needed.
• Monitor the results directly
or use interrupts.
Let’s get a bit more specific.
As mentioned, you have a choice
of which pin (B.0 or B. 3) you
would like to connect up to the
capture module. Clearly, there is
an internal multiplexer handling
this business. The CCPMX bit in
configuration register CONFIG1
takes care of it. Refer to
Figure 2 which gives the
particulars. The setting is burned
into CONFIG1 when you Flash
Figure 2: The CCP1 pin is established when the PIC is Flashed.
52 SERVO 07.2014
Figure 3: This register
determines how Timer
1 will operate.