CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

CCP Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
frierray



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

CCP Question
PostPosted: Sat May 09, 2009 5:31 am     Reply with quote

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







PostPosted: Sat May 09, 2009 7:20 am     Reply with quote

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. Smile
From your description, you only need this latter ability, not the CCP abilities.

Best Wishes
frierray



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

PostPosted: Sun May 10, 2009 6:05 am     Reply with quote

Hi Ttelmah,

Thanks for the reply, just what I needed to know. It's working great now.

Thanks again, Ray
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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