...painful experience has taught me that if you are going to reverse the motor in software, first, limit the pwm from 1 to 254. Then subtract that value from 255.
so in c...
/*
** Max the PWM ...see p 51. in Kernighan and Richie :"the c programming
** language"
*/
pwm02 = (pwm02 <= 254) ? pwm02 : 254 ;
/* Min the PWM*/
pwm02 = (pwm02 >= 1 ) ? pwm02 : 1 ;
/* reverse it in software */
pwm02 = 255 - pwm02 ;
...or with if's
if ( pwm02 > 254)
{
pwm02 = 254 ;
}
else if (pwm02 < 1)
{
pwm02 = 1 ;
}
pwm02 = 255 - pwm02 ;
Or, we've also reversed the wiring on the motor
But, we prefer to reverse it in software.
Really though, since Anthony and echos code hardwires the values, you know that you don't have to protect for a rollover and can get away with
pwm02 = 254 - pwm02.
Thanks,
Eric