View Single Post
  #10   Spotlight this post!  
Unread 26-10-2007, 18:48
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: Problem using VEX shaft encoder

Quote:
Originally Posted by JamesBrown View Post
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
Could you help me with this. I'm new to programming, and am not very good at all. I was thinking that the cpu must be pretty fast to catch every loop perfectly. So where should I write this code and what should I write?
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364