Quote:
|
Originally Posted by Xufer
Sorry wasnt paying attention when i posted that it was off the backup file. heres the working version.
Code:
pwm01 = p1_y;
if (p1_y >= 120 && p1_y <= 133)
{pwm01 = 127;}
else if (p1_y < 120 && p1_y > 133)
{pwm01 = (1/1635.6 * (p1_y * p1_y) - 0.16149181 * (p1_y * p1_y) + 9.10002);}
/******************/
pwm02 = p2_y;
if (p2_y >= 120 && p2_y <= 133)
{pwm02 = 127;}
else if (p2_y < 120 && p2_y > 133)
{pwm02 = (1/1635.6 * (p2_y * p2_y) - 0.16149181 * (p2_y * p2_y) + 9.10002);}
Sometimes suqre numbers are fun... not today.
|
A warning about this code. You use floating points in the equations. The way C works, temporary results in an equation are subject to the same limitations that the final result will be. (I.E. if you are going to ended storing the result in an unsigned char, then none of the stuff that occurs in the equation should pass 0 or 255 either, because it will wrap around.) So, your results will probably be fairly inaccurate.
Also, it may be right, but just in case, the equation is complex, make sure that it is being evaluated the way you think it is.
Somebody correct me if I'm wrong.
--EDIT--
Well, not all compilers work this way. I don't konow about this compiler.
