Overvoltage and surge protection in variable frequency drives