changed PWM calculations to prevent integer overflow under certain conditions (e.g. clock rate too high)