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
Posted: Fri Apr 20, 2007 12:59 pm
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
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