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

best way to measure time between interrupts?

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



Joined: 20 Apr 2007
Posts: 2

View user's profile Send private message

best way to measure time between interrupts?
PostPosted: Fri Apr 20, 2007 11:53 am     Reply with quote

Hey guys, i'm working on a project where I will have a platform spinning at about 2000rpm. I'm using a pic18f4550 i have a IR sensor which is going to be connected to pin RB7. I'm going to be using the INT_RB interrupt to do something for everytime the circuit is triggered. right now the pic is running at 32Mhz Internal, but I have a 40Mhz oscillator coming in.

the questions i have is what is the best way to go about measuring the time between the triggering of the interrupts. I ask this becasue all my time delays are going to be dependent on the time between cycles. here is kind of what i was thinking

when RB_isr is triggered
stop timer1
get timer 1 reading
reset timer 1
start timer1

do any small math neccessary

x=......

and then use that in
delay_cycles(x);

this is so that if the motor speed varies at all, the pic can compensate

there is probably a better way to do this.

i appreciate any help
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 20, 2007 12:59 pm     Reply with quote

You could setup Timer1 to count at an appropriate rate and read it
when an interrupt occurs, and then subtract off the previous reading
to get the time delta between interrupts. There will be some latency
time before Timer1 can be read. This might vary from one reading
to the next, because another interrupt might be in progress (from another
module). That's why it's better to use the CCP in Capture mode to
measure the time between two repetitive events. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=29963&highlight=tachometer
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