[NXC]TachoCount problem
Posted: 21 Feb 2013, 17:50
I'm just trying to wirte a function for fast motor-movements.
I have a problem with "GetOutput( OUT_A, TachoCount);"
After resetting the TachoCount, GetOutput returning not 0.
I have a problem with "GetOutput( OUT_A, TachoCount);"
After resetting the TachoCount, GetOutput returning not 0.
Code: Select all
inline void RunMotor ( byte out, char pwr, long angle)
{
long tacho;
long pre_tacho;
unsigned int stady_state;
int i;
ResetTachoCount(OUT_A);
SetMotorRegulationTime (10);
if (angle < 0)
{
pwr = -pwr;
}
OnFwd (out, pwr);
do
{
i++;
tacho = GetOutput( out, TachoCount);
if (tacho == pre_tacho) {stady_state++;}
if ( i%50 == 0) {pre_tacho = tacho;} // lower the resolution
} while (tacho < angle && !(stady_state > (angle *100 / pwr) ) );
OffEx (out, RESET_ALL); // i think off causes the problem
Yield();
}
task main ()
{
long tacho;
RunMotor (OUT_A, 100, 90);
Wait (1000);
// Lets reset TachoCount so it should be 0
ResetTachoCount(OUT_A);
tacho = GetOutput( OUT_A, TachoCount);
// tacho != 0 , tacho = 50!!! << whats wrong?
NumOut(5, LCD_LINE1, tacho);
Wait(5000);
}