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

How do I count pulse width ?

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



Joined: 14 Dec 2009
Posts: 33
Location: Wales

View user's profile Send private message

How do I count pulse width ?
PostPosted: Mon Dec 14, 2009 10:39 am     Reply with quote

I am reading an encoder for velocity and I would like to calculate the speed using the encoder pulse width.

I have tried doing this using an External Interrupt INT_EXT to start timer 1
but couldn't work out how to stop the timer on the falling edge so that the count relating to pulse width (and hence velocity) could be read.

Of course if the shaft isn't moving it will also need to cater for this and time out within 1 second for example.

Any help would be appreciated -

Rob
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 14, 2009 11:18 am     Reply with quote

The CCP (in capture mode) is designed to do this.
CCS has an example file which uses both CCP modules to do it:
Quote:
c:\program files\picc\examples\ex_ccpmp.c


This thread has sample code to do it with one CCP module:
http://www.ccsinfo.com/forum/viewtopic.php?t=31470
ac34856



Joined: 14 Dec 2009
Posts: 33
Location: Wales

View user's profile Send private message

Thanks ... but ...
PostPosted: Tue Dec 15, 2009 6:04 am     Reply with quote

Yes that routine was tested yesterday and works mostly ok above
500Hz.

If I wanted to count very slow pulses say down to 10Hz it
would need to wrap around which obviously means more bits
counting resolution.

In its present form it works ok down to above 100Hz after which
the counter gets into trouble.

Ideally I would need to increase the counter resolution to 32 bits
is there a quick way to do this ?

Rob
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