A charging system and a method of operating the same are provided. The charging system includes an electric machine which may be a wound or un-wound rotor type or a doubly fed induction motor (DFIM). A control system is coupled to the electric machine and a battery system. In the case of a wound rotor, the control system is coupled to stator windings and a rotor winding for controlling excitation of the stator windings and the rotor winding. The charging system is AC and DC compatible. In the case of an AC power source, the control system injects excitation into a rotor winding to induce a desired voltage in the stator, if the power supply voltage of the power supply is greater or smaller than the voltage of the battery system. Other modes of operation allowing for safe charging and discharging of a battery system are also described herein.