Control and protection of electric motors