I’m a student at VCU and near the shipping deadline I went out to a school in the Richmond area that my friend mentors to help them with their programming issues. Apparently the compiler is as wonderful as last year… and here’s a solution for a problem they had…
The original code went something to the tune of:
if(calib) {
offset01 = p1_y - 128;
calib=0;
}
if(p1_y - offset01 > 254)
pwm01 = 254;
else if(p1_y - offset01 < 0)
pwm01 = 0;
else
pwm01 = p1_y - offset01;
It would seem the compiler has issues with signed and unsigned variables and doing the math ‘right’ without you being very explicit. A bit of casting is all you need…
This should be the fix:
if(calib) {
offset01 = p1_y - 128;
calib=0;
}
if( ((signed int) p1_y) - offset01 > 254)
pwm01 = 254;
else if( ((signed int) p1_y) - offset01 < 0)
pwm01 = 0;
else
pwm01 = ((signed int) p1_y) - offset01;