Confused about PIC CCP Module

Thread Starter

Barnaby Walters

Joined Mar 2, 2011
102
Hi there,

I am a little confused about the CCP modules on Microchip's PIC MCUs. I get that the capture records the state of a timer on an event such as a rising/falling edge — and can therefore be used to measure frequency? PWM I know about too.

But the 'Compare' function is confusing me. I can't find a simple explanation of what it does. I thought it might be a comparator, but it uses timers, so I'm doubting that now… Can someone explain it please, or give an example of how it's used?

Thanks a lot,
Barnaby
 

Thread Starter

Barnaby Walters

Joined Mar 2, 2011
102
Thanks, that's a great resource. So, have I got this right:

The Compare in CCP measures the period of a signal
Some PICs have an on-board analog comparator (which is different to the Compare function above)
The Analog Comparator output can be fed into the CCP Compare function in order to measure the period of an analog signal.

Sounds about right? If it is, that's cleared up a lot of confusion!

Thanks,
Barnaby
 

Papabravo

Joined Feb 24, 2006
21,225
No you still have it wrong. Here it is in a nutshell

  1. You have a free running timer that increments at some rate
  2. You have a compare register with a single value
  3. When the TIMER == COMPARE_REGISTER something happens
The something could be:

  1. A COMPARE_MATCH Interrupt
  2. An output pin gets SET, or CLEARED, or TOGGLED
  3. The counter changes direction, and so forth.
You can use this to schedule future events, do PWM, generate other kinds of waveforms.

To measure frequency or period you want INPUT CAPTURE. In this case the value of the free running timer is recorded when a certain event happens. When you have two values for the same type of event you can compute the period.
 

Thread Starter

Barnaby Walters

Joined Mar 2, 2011
102
Ok, so capture is period measurement, and timer allows you to generate an interrupt/action when the value in a timer matches the value you've put in the compare register? So for a 14 bit timer, the compare number would have to be spread across several registers?

Thanks, that's cleared up a lot. The PIC Tips and Tricks document is great, but it doesn't always explain everything.

Barnaby
 
Top