Quote:
|
Originally Posted by Joe Ross
Code:
if(currentPWM >= goalPWM + sensitivity)
return currentPWM - sensitivity;
if(currentPWM <= goalPWM - sensitivity)
return currentPWM + sensitivity;
Since everything is an unsigned char, then this code is a problem.
If goalPWM is 254 and sensitivity is 10 and CurrentPWM is 127, the result of (goalPWM + sensitivity) is 8 and so CurrentPWM is greater then 8 and you return 117 not 137 like you hope.
|
Yep, that will be the problem I'm sure. I'll just add a few extra tests for the extreme cases. (wanting to be at 0 and 254)
And the funny thing is, I had already paritially taken looping around into acount in the code.