A new inverter based on the electromechanical transient model of synchronous generator(which is referred to as virtual synchronous generator) is presented. A power controller and a voltage-frequency controller are designed to make the inverter with double function of controlling power and modulating frequency and voltage. Furthermore, when microgrid is faulty, uninterruptable electrical power can still be supplied to important loads of the microgrid. A pre-grid unit designed enables safe connection of the inverter and a microgrid. When the microgrid connecting with the main grid, frequency is decided by the main grid, so power control strategy is employed in each virtual synchronous generator to control its dispatchable output power. When the microgrid is islanding, voltage reference should be provided by one inverter using voltage-frequency controller. In addition, it is convenient to be modularized and standardized because virtual synchronous generator with the same capacity can be replaced freely in the microgrid. This scheme will increase the flexibility of microgrid and enhance the reliability of system control strategy, which has been verified by the MATLAB/Simulink.