Motor control with pwm