Quote:
Originally Posted by Nathans
We're testing the new gyro code, but it overrides all of our commands and sets our pwm outs to 0. Once we put anything referencing the pwm outs we're using, it messes them up. We searched through the code, but we can't find anything that might be causing this. Has anyone else come across this problem?
|
I had a look at your code and it looks like the problem is your limit() function, which is returning a 16-bit integer when it should return an unsigned 8-bit byte. You also had semicolons immediatly after your if statments:
Code:
int limit(int value)
{
if(value >255);
value =255;
if(value <0);
value =0; <== because of the added semicolon above, this statement will always execute and will always set the return value to zero.
return value;
}
Your code should probably look like this:
Code:
unsigned char limit(int value)
{
if(value >255);
value =255;
else if(value <0);
value =0;
return (unsigned char)value;
}
-Kevin