move pwm logic to motor.js as module