With the gradual depletion of traditional fossil energy and the increasing demand for electricity, finding new energy sources has become the only way for sustainable development. Microgrid is becoming an important auxiliary power for some developed and developing countries to solve the supply problem of energy system, which can not only effectively improve the overall utilization rate of renewable energy, but also improve the power supply reliability of the main grid. In this paper, the hardware circuit and software control of microgrid simulation system based on STM32 are studied and designed. The main circuit design of microgrid simulation system is based on STM32 single chip microcomputer as the main control core, and the pulse modulation signal SPWM is output through the software program of STM32F103CBT6 single chip microcomputer. The MOS driving circuit provides driving voltage and control signal to drive the inverter bridge to invert DC into AC. The inverter bridge is modulated by SPWM control technology, and the high-frequency signal in AC is filtered by low-pass filtering circuit, and finally the stable AC with a fixed frequency of 50 Hz is the output. By calculating the device parameters of the main control circuit and the full-bridge inverter circuit in the hardware unit circuit, and making appropriate selection of components, the specific model is determined, and finally the circuit design of the whole circuit is completed. The hardware circuit is designed rationally by Altium designer, and the software circuit is programmed by Keil. The influence of SPWM signal output by the circuit on the resistance load and its output waveform is analyzed comprehensively, and the influence of working frequency on the output waveform of the circuit is studied.