Invertor as a virtual synchronous generator (VSG) to provide virtual inertia and damping can improve the stability of a microgrid, in which the damping is one of the fundamental problems in dynamics. From the view of the Hamiltonian dynamics, this paper researches the damping formation mechanism and damping injection control of VSG. First, based on the energy composition and dynamic characteristics of VSG, the differential equations system of VSG is established and is transformed into the generalized Hamiltonian system. Second, the effects of the three parameters of VSG, the damping coefficient D, active power droop coefficient, and time constant of excitation TE on damping characteristics are researched from a dynamic perspective, and simulation research is carried out with an isolated microgrid. Lastly, the control design method of Hamiltonian structure corrections used to add the damping factor and design the equivalent control inject damping to improve the stability of the isolated microgrid. Research shows that the voltage and frequency stability of the isolated microgrid can be effectively improved by selecting three key parameters of VSG and damping injection control. The innovations of this paper are 1. The Hamiltonian model of the inverter is deduced and established by taking the inverter as a virtual generator. 2. Based on the Hamiltonian model, damping characteristics of inverter in the microgrid are studied. 3. Hamiltonian structure correction method is applied to the inverter, and equivalent damping injection is designed to improve the stability of the microgrid.