we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.
Code:
//the encoder is at 50 resolution
//the arm motor is attatched to pwm_02
//the encoder is attatched to rc_dig_in06
static unsigned int encoder;
static unsigned int pressedornot;
if (p1_sw_trig == 1)
{
if (encoder <= 10)
{
pwm_02 = 150;
if (rc_dig_in06 == 1)
{
encoder = encoder + 1;
if (encoder > 10)
{
pwm_02 = 127;
}
}
}
}