Closed-loop flux-weakening for permanent magnet synchronous motors