Apparatus and method for controlling speed of motor