Confused about PIC CCP Module

Discussion in 'Embedded Systems and Microcontrollers' started by Barnaby Walters, Mar 28, 2011.

  1. Barnaby Walters

    Thread Starter Member

    Mar 2, 2011
    103
    4
    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
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  3. Barnaby Walters

    Thread Starter Member

    Mar 2, 2011
    103
    4
    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
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    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.
     
    Barnaby Walters likes this.
  5. Barnaby Walters

    Thread Starter Member

    Mar 2, 2011
    103
    4
    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
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    Yeah. That's the ticket!
     
  7. Barnaby Walters

    Thread Starter Member

    Mar 2, 2011
    103
    4
    Excellent. Hopefully I'll be able to put these to use sometime soon.

    Thanks again,
    Barnaby
     
Loading...