View Single Post
  #9   Spotlight this post!  
Unread 25-10-2007, 22:08
JamesBrown JamesBrown is offline
Back after 4 years off
FRC #5279
Team Role: Engineer
 
Join Date: Nov 2004
Rookie Year: 2005
Location: Lynchburg VA
Posts: 1,276
JamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond reputeJamesBrown has a reputation beyond repute
Re: Problem using VEX shaft encoder

I would definitely rewrite the code using an interrupt routine, you are only checking the state of the encoder once every loop, for the regular FRC controller this is i believe once every 26ms I am not that familiar with the vex platform but I doubt that it is much faster.

If the math posted earlier in the thread is correct ( I believe it is) then running at full speed you might catch one out of every 4 or 5 pulses. You can't adjust for this in software since the motor does not always run at the same speed.

What you need to do is write an interrupt service routine, this is just like a regular function but it is called immediately when an event occurs. For example when the system clock overflows or when a switch is pushed or in your case when the encoder goes high. the ISR would be very simple you would just increment the counter variable. You can then use the count any where in the code you want. As a warning never make your ISR code complicated for example do not include loops, since it may be called very ofter you want to make sure it executes quickly.

James
__________________
I'm Back


5279 (2015-Present)
3594 (2011)
3280 (2010)
1665 (2009)
1350 (2008-2009)
1493 (2007-2008)
1568 (2005-2007)