Design of a Single-Phase Grid-Connected Inverter Based on STM32

In the context of rapidly advancing renewable energy technologies, the role of inverters has become increasingly critical. We developed a low-power single-phase inverter for residential use, centered around the STM32H7B0VBT6 control core. This single-phase inverter supports both off-grid programmable voltage output and grid-connected programmable current output, delivering high-quality AC waveforms with stable operation. The design emphasizes efficiency, low total harmonic distortion (THD), and user-friendly interfaces, making it suitable for home photovoltaic systems. Throughout this project, we focused on optimizing the hardware and software integration to achieve reliable performance in various operating conditions.

The overall system architecture of the single-phase inverter includes several key modules: the STM32 main controller, inverter circuit, filter circuit, sampling circuit, transformer, auxiliary power supply, encoders, and an LCD screen. These components work together to enable dual output modes—off-grid and grid-connected. In off-grid mode, the STM32 generates a 50 Hz sine wave and produces a sinusoidal pulse width modulation (SPWM) signal with a duty cycle that varies sinusoidally. This signal drives the inverter circuit, which, after passing through the filter circuit, outputs a smooth AC voltage waveform. The transformer then steps up the low-voltage AC to high-voltage AC for loads, while the sampling circuit feeds back voltage and current signals to the STM32. Based on the voltage feedback, the STM32 adjusts the modulation index of the SPWM signal to achieve programmable voltage output. In grid-connected mode, the inverter connects to the grid, and the STM32 uses phase-locking based on voltage feedback to generate a synchronized sine wave. Similarly, current feedback adjusts the SPWM modulation index for programmable current injection into the grid. This flexible design ensures that the single-phase inverter can adapt to different energy scenarios, providing efficient power conversion.

For the hardware design, we selected the STM32H7B0VBT6 as the main controller due to its high-performance ARM Cortex-M7 core, operating at up to 280 MHz, with 1.4 MB of RAM and a 16-bit ADC. This capability ensures stable and rapid processing for the single-phase inverter. The inverter circuit consists of four NMOS transistors arranged in a full-bridge configuration, driven by IR2101 chips powered by 12 V. These drivers amplify the control signals to 12 V, reducing conduction losses and enhancing efficiency. The filter circuit employs an LCL low-pass filter to attenuate high-frequency components from the inverter output, resulting in a clean AC waveform. The sampling circuit measures AC voltage and current using transformers and operational amplifiers, producing signals in the 0 V to 3 V range for STM32 ADC sampling. Voltage sampling involves a voltage transformer that steps down the AC voltage, followed by a two-stage op-amp circuit with adjustable gain via a potentiometer. Similarly, current sampling uses a current transformer to generate a proportional voltage signal, processed through op-amps with a 1.6 V bias from a MAX6018 reference. This circuit is powered by a 5 V supply, with a -5 V module for the LM358 op-amps. The transformer is designed with a theoretical ratio of 9.167:1 (220 V high-side to 24 V low-side), but we calibrated it empirically to minimize errors. The auxiliary power supply uses two MP4560DN modules to provide 5 V and 12 V from the DC input, which must be below 55 V. Encoders and a 1.8-inch RGB LCD with SPI communication enable user interaction, allowing parameter adjustments and real-time monitoring.

Hardware Components of the Single-Phase Inverter
Component Description Key Parameters
STM32 Main Controller STM32H7B0VBT6 microcontroller 280 MHz, 1.4 MB RAM, 16-bit ADC
Inverter Circuit Full-bridge with NMOS transistors and IR2101 drivers 12 V drive, high efficiency
Filter Circuit LCL low-pass filter Attenuates high-frequency noise
Sampling Circuit Voltage and current transformers with op-amps 0-3 V output range, adjustable gain
Transformer Step-up transformer 220 V/24 V ratio, calibrated empirically
Auxiliary Power MP4560DN modules 5 V and 12 V outputs, input <55 V
User Interface Encoders and LCD screen SPI communication, real-time display

In the software design, we used STM32CubeMX for initialization and Keil μVision5 for C programming. The configuration set the system clock to 280 MHz and allocated peripherals: GPIO pins for encoder inputs (PE0-PE5) and LCD control (PD8-PD10), ADC1 and ADC2 at 16-bit resolution for voltage and current sampling (PA6 and PC4), SPI2 in half-duplex master mode for LCD communication (PB13, PB15), TIM6 as a general-purpose timer at 1 kHz for encoder scanning and PID computations, and TIM1 as an advanced timer at 20 kHz for PWM generation with dead time. TIM1 outputs complementary PWM signals on PA7, PE9, PE10, and PE11 to control the inverter circuit. The main program initializes peripherals, variables for SOGI-PLL, Kalman filtering, and PID control, and the LCD. It then enters a loop that processes encoder inputs to select variables, adjust values, toggle output modes, and update the display. For instance, encoder rotations increment or decrement parameters, while button presses switch modes or enable output. The single-phase inverter’s software ensures responsive control and accurate feedback handling.

The TIM1 interrupt service routine (ISR), triggered at 20 kHz, processes several key functions. First, it converts ADC samples to real voltage values using the formula: $$real_{adc} = \frac{sample_{adc} \times 3.3}{65535}$$ where \(sample_{adc}\) is the digital ADC value (0-65535). This scales the input to a 0-3.3 V range. Next, it computes the RMS values of voltage and current by tracking the maximum and minimum values over a 50 Hz cycle (400 samples). The RMS calculation is: $$VI_{rms} = \frac{adc_{max} – adc_{min}}{2\sqrt{2}}$$ To obtain actual RMS values, we fitted calibration curves using MATLAB’s cftool with a quadratic polynomial: $$f(x) = p_1 \cdot x^2 + p_2 \cdot x + p_3$$ where \(x\) is the software-calculated RMS, and \(p_1\), \(p_2\), \(p_3\) are coefficients derived from experimental data. Depending on the mode, the ISR either runs a second-order generalized integrator phase-locked loop (SOGI-PLL) for grid synchronization in grid-connected mode or generates a sine wave via arm_math functions in off-grid mode. The SPWM signals are computed as: $$SPWM_1 = pmw_{med} + pmw_p \cdot \sin(\theta) \cdot ratio$$ $$SPWM_2 = pmw_{med} – pmw_p \cdot \sin(\theta) \cdot ratio$$ where \(pmw_{med}\) is half the timer period (ARR), \(pmw_p\) accounts for dead time, \(\sin(\theta)\) is the sine wave value, and \(ratio\) is the modulation index. These values update TIM1’s compare registers (CCR1 and CCR2) to produce single-polarity SPWM waveforms, crucial for the single-phase inverter’s output quality.

Software Configuration for the Single-Phase Inverter
Component Setting Purpose
System Clock 280 MHz High-speed processing
GPIO PE0-PE5 (encoders), PD8-PD10 (LCD) User input and display control
ADC 16-bit, PA6 (voltage), PC4 (current) Precision sampling
SPI Half-duplex, PB13, PB15 LCD communication
TIM6 1 kHz frequency, interrupt enabled Encoder scanning, PID computation
TIM1 20 kHz, center-aligned, dead time 200 ns PWM generation for inverter control

The TIM6 ISR, operating at 1 kHz, handles encoder scanning and PID control. It polls the encoders at 200 Hz to detect rotations and button presses, returning values that the main loop uses to adjust parameters. For example, a clockwise rotation on encoder 1 returns 1, triggering a variable selection change. At 50 Hz, it performs PID computations: in grid-connected mode, it adjusts the current based on the error between setpoint and measured value, while in off-grid mode, it does the same for voltage. The PID output is calculated as: $$PID_{out} = K_p \cdot err_k + K_i \cdot \int err_k \, dt + K_d \cdot (err_k – err_{k-1})$$ where \(K_p\), \(K_i\), and \(K_d\) are proportional, integral, and derivative gains, and \(err_k\) is the current error. The output is clamped between 0.01 and 0.99 and assigned to the SPWM modulation ratio \(ratio\), enabling precise control of the single-phase inverter’s output. This approach ensures stability and rapid response to load or grid changes.

During testing, we powered the single-phase inverter with a 50 V DC input. In off-grid mode, setting the voltage RMS to 25.2 V resulted in a transformer output of 220.04 V AC, as measured by a multimeter. In grid-connected mode, a current setpoint of 1.6 A yielded an actual output of 1.611 A. These results demonstrate the inverter’s accuracy and reliability. The LCD interface displays real-time parameters, such as voltage, current, and mode, enhancing usability. For instance, the off-grid screen shows voltage setpoints and measurements, while the grid-connected screen focuses on current values. The single-phase inverter maintains low THD and high efficiency across operations, validated by oscilloscope waveforms that indicate clean sine outputs.

In summary, we successfully designed and implemented a single-phase grid-connected inverter using the STM32H7B0VBT6 microcontroller. This single-phase inverter offers versatile off-grid and grid-connected functionalities with programmable voltage and current output, supported by robust hardware and software. Key strengths include stable performance, high waveform quality, and an intuitive user interface. However, we identified areas for improvement, such as reducing the physical size and weight for portability and minimizing transformer-related power losses. Future work could focus on integrating maximum power point tracking (MPPT) for photovoltaic applications and enhancing efficiency with advanced semiconductor materials. Overall, this single-phase inverter represents a scalable solution for residential renewable energy systems, contributing to the broader adoption of sustainable power technologies.

Scroll to Top