|
|
View previous topic :: View next topic |
Author |
Message |
frierray
Joined: 11 Nov 2008 Posts: 29
|
CCP Question |
Posted: Sat May 09, 2009 5:31 am |
|
|
Hi All,
I need to count pulses from a motor encoder. The pulses are low frequency (about 1Khz) and the max count will be <5000. I am using a 18F2520 and compiler version 4.073. I could do this using one of the portB pins and interrupt on change. I was wondering if there is anyway to have the CCP count the pulses and I could just read the counter. But I don't see that option, it looks like the CCP only reports the time value of the pulses.
Is there something very basic I am missing here?
Thanks, Ray |
|
|
Ttelmah Guest
|
|
Posted: Sat May 09, 2009 7:20 am |
|
|
You don't need/want the CCP.
All you use is one of the timers.
Timers 0, 1, & 3, all support counting from external inputs, or from the internal clock.
All you do, is set the timer you decide to use (will depend what _else_ you want to do, with other timers, or with this one), to use it's external clock, clear it, and it'll start counting the pulses fed in on it's external pin.
What you can do wth the CCP, is (for example), if you used timer1, ot timer3, then you could set the CCP, to (say) 5000, and set it to use the timer you are feeding the clock into, and it'd then automatically trigger, it's output, and/or an interrupt, when the count on the timer 'reaches' 5000.
The CCP's are used to capture timer values,or compare timer values (or generate PWM's), the timers are what are actually used to do the counting.
From your description, you only need this latter ability, not the CCP abilities.
Best Wishes |
|
|
frierray
Joined: 11 Nov 2008 Posts: 29
|
|
Posted: Sun May 10, 2009 6:05 am |
|
|
Hi Ttelmah,
Thanks for the reply, just what I needed to know. It's working great now.
Thanks again, Ray |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|