System for controlling a motor