Both, rtick and ltick (for the StartLeftEncoder function) are unsigned ints.
If I use GetRightTick() (which returns rtick), the function works fine. However, if I use GetLeftTick(), I get the odd pulsing again. I cant see any differences in my code between the two functions besides the names and the variable returned.
Code:
void StartRightEncoder(void)
{
state = rc_dig_in05;
if(oldstate != state)
{
rtick ++;
}
oldstate = state;
}
unsigned int GetRightTick(void)
{
return rtick;
}
void ClearRightTick(void)
{
rtick = 0;
}
void ClearLeftTick(void)
{
ltick = 0;
}
unsigned int GetLeftTick(void)
{
return ltick;
}
void StartLeftEncoder(void)
{
state1 = rc_dig_in06;
if(oldstate1 != state)
{
ltick++;
}
oldstate1 = state1;
}
void Process_Data_From_Local_IO(void)
{
StartRightEncoder();
StartLeftEncoder();
/* Add code here that you want to be executed every program loop. */
}
Those are all my functions and are all placed in User_Routines_Fast
Code:
if(GetRightTick() <= 300)
{
pwm04 = 255;
pwm03 = 0;
}
And that is the code that uses those functions in User_Routines. If I use the code posted directly above, it works fine (and by that i mean the wheel spins and stops at logical points). But if I change the If statement to ahve GetLeftTick <= 300, the motors pulse again. I had that problem with GetRightTick(), but that problem was resolved for some reason unknown to me.
And then when I use GetRightTick(), if i want my wheel to spin twice (which should be 180 ticks), I have to set the tick number to 308 to get close to two spins.
Its times like these that I wish someone had a vex encoder function posted on the internet.