Im just getting started on programming Vex with mplab. I have already worked with simple limit switches to control actions but now I would like to branch out into the more difficult realm of encoders.
I wrote a program that today that works but isnt correct.
Code:
void StartRightEncoder(void)
{
oldstate = rc_dig_in05;
state = rc_dig_in05;
if(oldstate != state)
{
rtick++;
}
oldstate = state;
}
It works to the extent that rtick increases, but I have a feeling that due to condition of incrementing rtick, I am missing many ticks from the encoder because it simply doesnt get the ticks quick enough. My emperical evidence is that when I set my motors to go when rtick is less than 270 (3 complete revolutions and with a wheel diam of approximately 3 inches, the code should make the bot go 9 inches give or take for round off error), the bot went more like 3 feet.
How does everyone else actually detect all the ticks? I checked the sample code on vexlabs but the encoder code isnt ready yet in the sample code download.