Author Topic: Better understanding CCP module of PIC MCU, looking for real world examples  (Read 1519 times)

0 Members and 1 Guest are viewing this topic.

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Hi, I'm an electronics hobbyist, to learn CCP module i gone through data sheet by microship for 18f46k22 mcu i also read application notes for CCP modules by microchip,
I wrote some program for PWM and was able to control brightness of LED, speed of DC motor and generate square wave on oscilloscope, but unfortunatly i did not find enough about Capture and Compare of CCP module.

As I have been read about CCP I understand how to setup but for better understanding of Capture and Compare modules I want to know real examples like i did for PWM so that i can understand it better.

I want to know what kind of advatages we can get from these modules in what kind of applications

Thanks.
 

Offline kony

  • Regular Contributor
  • *
  • Posts: 242
  • Country: cz
What is there not to understand? It takes binded timer value snapshot and saves it to its register at choosen event. Can invoke interrupt if you enable it.
Measuring pulse period is real world example, timestamping some external event occurence another (with obvious implications for selected timer prescaler - if your event needs longer span than what the timer provides and/or periodic one, you have to add SW postscaler diven by the timer interrupt service routine).
 

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Quote
Measuring pulse period is real world example

I need this kind of guidance, as i described in my question i know how to setup CCP but i need help regarding what i can develop from it, for exaple with pwm i was able to set brightness of LED and speed of DC motor.

I want to know in what kind of applications I can use Capture and Compare.  Thanks.
 

Offline kony

  • Regular Contributor
  • *
  • Posts: 242
  • Country: cz
Say you have a fans with tacho signal attached to your board. You want to know its speed. How will you do that with minimum impact on the rest of the firmware execution? For sake of example let's say gated timers are already used for something else, you have four fans and you have only CCP modules left. Another example would be recieving of standardised hobby model PWM signal and using the duty cycle as command variable for whatever purpose - how do you recover that information without inefficient SW polling?
 
The following users thanked this post: sairfan1

Offline hli

  • Frequent Contributor
  • **
  • Posts: 255
  • Country: de
I want to know in what kind of applications I can use Capture and Compare.  Thanks.
E.g. a frequency counter: the counter counts your input signal, and the capture event is created from your gate counter (e.g. a 1Hz signal).
 
The following users thanked this post: sairfan1

Offline kony

  • Regular Contributor
  • *
  • Posts: 242
  • Country: cz
Frequency counter is exactly the case where you want to use gated timer module bundled together with second timer for a timebase. CCPs are fine for the less demanding usecases as I mentioned earlier.
 

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Thanks, these examples looks good.

what i understand these are more related to Capture? or compare will be equally used in these examples,
 

Offline kony

  • Regular Contributor
  • *
  • Posts: 242
  • Country: cz
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1613
  • Country: gb
I'm still unsure exactly what you are asking, and I'm sure others have provided explanations in their own language.

Capture - "captures" (copies) the value of a free running timer for a given event. This event is usually a rising or falling edge on an IO.  This means you can detect when the edge occurred because it stores a snapshot of the timer value, and gives your software time to read it, and perhaps use it to measure the period of an input (measuring speed, period, timed events).  For repetitive signals (where the period doesn't change often) it has an input divider of 4 or 16.  This means you can time (using the timer) how long it takes for the input to have a rising/falling edge 16 times - essentially averaging the result, but also increasing resolution.

Compare - constantly "compares" the value of the timer to a fixed value you provide.  Once the values match you can choose what happens - usually a pin is driven high, low, or toggles (changes state). I believe PIC's also have an event system, where the compare match drives a special event trigger - this resets the timer, and can also start and ADC reading.   This is very handy for generating arbitrary frequencies, generating a "tick", triggering an ADC reading for precise ADC sampling periods.  The fact the special even trigger resets the timer means you are essentially counting up to a specific value, then resetting, meaning you can quite accurately set this period.  Essentially a programmable timer that, combined with the prescalers can generate timing signals accurate to 4/Fosc seconds. (for a 10MHz clock, thats a resolution of 400ns).

Both the above can be done just with software and a timer, but you would have to poll the inputs, or poll the timer constantly, meaning the MCU can't do anything else.  Like all peripherals, they are designed to off-load repetitive simple tasks to hardware, freeing up the CPU (or rather give it time to service interrupts without missing inputs).  This is because MCU's are mostly single core, and can only do one thing at a time.  Peripherals help it multitask by performing time-sensitive functions in separate hardware to be serviced later.
 

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Thanks for nicly describe, what kind of hobby projects you can suggest to build with CCP, i have already done some with PWM so you please advise some projects/or applications that can be done with the help CCP as @Kony and @hli described

thanks again.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf