Thx for replying i finally understand the formulas given. My other problem will be the overshoot compensate configuration:
while(countAB < (limit-countover+3)) //while counter is in the (limit-previous overshoot +3)
{ //for the 1st time, the motor will overshoot because PIC
initA = A; //get current A value //has not get the overshoot value to compensate
initB = B; //get current B value
do
{
run_cw(speed); //run motor in clockwise direction with user defined speed
}while(initA ==A && initB ==B); //continue run until state change
countAB++; //increment counter for each state change
stopA=A; //stopA store A value right after state change
stopB=B; //stopB store B value right after state change
}
//once program exit the previous while loop
//meaning that the motor has reached the desired angle
i dont understand why "while(countAB < (limit-countover+3))" but i understand the content of the while loop for example the countAB++. I have no idea on the second half of the overshoot code that shown below.
countover=0; //reset overshoot counter
end=0; //reset end function flag
while(end==0) //while the flag is not set
{
do
{
if(countstop>10000) end=1; //set end flag if stop counter >10000
else
stop(0); //brake the motor
countstop++; //stop counter increment by 1
}while(stopA==A && stopB==B && end==0); //loop if states do not change
//if states change,meaning overshoot occur
countover++; //increment overshoot counter
countstop=0; //clear stop counter
stopA=A; //stopA store the current A value
stopB=B; //stopB store the current B value
}
}
THX.