In view of the traditional instantaneous reactive power detection has low anti-harmonic interference ability, poor real-time performance, and insufficient accuracy when the power grid frequency fluctuates, this paper improved the detection link. The working principle of single-phase harmonic detection is analyzed, and the improved second-order generalized integrator is added to make the phase-locked loop detect the voltage phase accurately and efficiently. Based on the comparison and compensation simulation results of the active compensation device, the quality of grid-connected current of the inverter is improved effectively, and the precision of phase locking is increased.