Introduction and Motivation
In my work, I have concentrated on the design and implementation of a single-phase photovoltaic off-grid solar inverter based on the STM32 microcontroller. The motivation for this research comes from the rapid growth of energy demand, the progressive depletion of conventional fossil fuels, and the severe environmental problems caused by excessive use of non-renewable resources, such as acid rain, the greenhouse effect, and smog. Among the available renewable energy sources, solar energy is one of the most promising because it is clean, abundant, widely distributed, and free from geographical constraints. A solar inverter is therefore a critical component in any photovoltaic power generation system, especially in off-grid applications where direct current from photovoltaic panels must be converted into stable alternating current for residential, commercial, and remote-area loads.
I have observed that a typical off-grid photovoltaic system consists of photovoltaic panels, a storage battery, a controller, a boost converter, and a solar inverter. The solar inverter converts the low-voltage direct current from the battery or photovoltaic array into 220 V, 50 Hz alternating current. Because low-voltage direct current is inconvenient for transmission and distribution, the solar inverter plays an indispensable role in making solar energy usable. In my design, I selected a high-frequency isolated topology because it provides safety isolation, reduces volume and weight, and improves conversion efficiency compared with low-frequency isolation. The main objective of my work is to design a small-power single-phase solar inverter that can deliver a reliable sinusoidal output voltage with high waveform quality.
I structured my research into several parts: photovoltaic cell modeling, inverter topology and control strategy analysis, hardware circuit design, software program development, and experimental verification. Throughout this article, I use the term solar inverter repeatedly because it is the central device in my study. I also emphasize the role of the STM32F103 series processor, which I used as the main controller for generating SPWM signals, sampling voltages and currents, and implementing protection functions.
Photovoltaic Cell Modeling and Simulation
I began my design by studying the fundamental principle of photovoltaic power generation. A photovoltaic cell converts light energy into electrical energy through the photovoltaic effect of a semiconductor PN junction. When sunlight strikes the surface of a photovoltaic cell, electron-hole pairs are generated near the PN junction. The electric field in the depletion region separates these carriers: electrons move toward the N region, and holes move toward the P region. This charge separation creates a photogenerated electric field and a potential difference between the two terminals of the cell. When a load is connected, current flows through the external circuit. This process does not require any mechanical moving parts, and the output voltage and current depend on the irradiance, temperature, and load condition.
To analyze the electrical behavior of a photovoltaic cell, I used the single-diode equivalent circuit model. The model includes a photocurrent source, a diode, a series resistance, and a shunt resistance. The output current can be expressed as:
$$I_L = I_{ph} – I_D – I_{sh}$$
where $I_L$ is the load current, $I_{ph}$ is the photogenerated current, $I_D$ is the diode current, and $I_{sh}$ is the shunt leakage current. The diode current is given by:
$$I_D = I_o \left[ \exp\left( \frac{q(U_{oc} + R_s I_L)}{nKT} \right) – 1 \right]$$
and the shunt current is:
$$I_{sh} = \frac{U_{oc} + R_s I_L}{R_{sh}}$$
In these equations, $I_o$ is the reverse saturation current of the diode, $q$ is the electron charge, $U_{oc}$ is the open-circuit voltage, $R_s$ is the series resistance, $R_{sh}$ is the shunt resistance, $n$ is the diode ideality factor, $K$ is the Boltzmann constant, and $T$ is the absolute temperature in Kelvin. By combining these relationships, I obtained the complete output current equation:
$$I_L = I_{ph} – I_o \left[ \exp\left( \frac{q(U_{oc} + R_s I_L)}{nKT} \right) – 1 \right] – \frac{U_{oc} + R_s I_L}{R_{sh}}$$
In many practical cases, the series resistance is very small and the shunt resistance is very large. Therefore, I simplified the model by neglecting $R_s$ and $R_{sh}$, which yields:
$$I_L = I_{ph} – I_o \left[ \exp\left( \frac{q U_{oc}}{nKT} \right) – 1 \right]$$
The output power of the photovoltaic cell is the product of output voltage and output current:
$$P = U_{oc} I_L = U_{oc} \left\{ I_{ph} – I_o \left[ \exp\left( \frac{q U_{oc}}{nKT} \right) – 1 \right] \right\}$$
To evaluate the performance of a photovoltaic cell, I used several key parameters. The fill factor is defined as:
$$FF = \frac{P_{max}}{V_{oc} I_{sc}}$$
and the conversion efficiency is:
$$\eta_s = \frac{P_{max}}{P_{in}} \times 100\%$$
where $P_{max}$ is the maximum output power, $V_{oc}$ is the open-circuit voltage, $I_{sc}$ is the short-circuit current, and $P_{in}$ is the incident solar power. I also considered the short-circuit current, open-circuit voltage, maximum power point, and temperature coefficients. The main parameters I used in my simulation are summarized in the following table.
| Parameter | Symbol | Value |
|---|---|---|
| Open-circuit voltage | $V_{oc}$ | As specified by the panel model |
| Short-circuit current | $I_{sc}$ | As specified by the panel model |
| Maximum power voltage | $V_{m}$ | As specified by the panel model |
| Maximum power current | $I_{m}$ | As specified by the panel model |
| Reference temperature | $T_{ref}$ | 25 °C |
| Reference irradiance | $S_{ref}$ | 1000 W/m² |
| Short-circuit current temperature coefficient | $a$ | Defined in the model |
| Open-circuit voltage temperature coefficient | $b$ | Defined in the model |
I built the photovoltaic cell model in MATLAB/Simulink using the mathematical relationships described above. The simulation environment allowed me to observe the current-voltage and power-voltage characteristics under different irradiance and temperature conditions. I used the ode23tb solver because it is effective for stiff and moderately stiff differential equations. The reference temperature was set to 25 °C and the reference irradiance was set to 1000 W/m². The simulation results showed that the output characteristics of the photovoltaic cell are strongly nonlinear.
From the current-voltage curves, I found that when the temperature is held constant at 25 °C, an increase in irradiance causes the short-circuit current to increase significantly, while the open-circuit voltage increases only slightly. As a result, the maximum output power increases approximately in proportion to the irradiance. From the power-voltage curves, I observed that there is a unique maximum power point for each irradiance and temperature condition. When the irradiance is constant at 1000 W/m², an increase in temperature causes a small change in short-circuit current, but the open-circuit voltage decreases, and the maximum power point also decreases. These observations confirmed that both irradiance and temperature must be considered in maximum power point tracking and in the overall design of a solar inverter.
Inverter Topologies and Control Strategies
I then moved to the study of inverter topologies and control strategies for the solar inverter. An inverter is a power electronic device that converts direct current into alternating current using semiconductor switches. In photovoltaic off-grid systems, the solar inverter must provide a sinusoidal output voltage with low harmonic distortion and good dynamic response. I reviewed three common topologies: the low-frequency isolated inverter, the high-frequency isolated inverter, and the non-isolated inverter.
| Topology | Main Features | Advantages | Disadvantages |
|---|---|---|---|
| Low-frequency isolated inverter | Inverter stage followed by a line-frequency transformer | Simple design, good isolation | Large size, heavy weight, high losses |
| High-frequency isolated inverter | Boost stage, high-frequency transformer, and inverter stage | Small size, light weight, high efficiency, safety isolation | Possible magnetic bias, more complex control |
| Non-isolated inverter | Boost stage and inverter stage without transformer | Small size, low cost, high efficiency | No galvanic isolation, common-mode noise |
I selected the high-frequency isolated topology for my solar inverter because it offers a good balance between safety, size, weight, and efficiency. The topology includes a boost converter, a high-frequency transformer, a rectifier, and a full-bridge inverter. The boost converter raises the low DC voltage from the battery or photovoltaic array to a higher DC-link voltage. The high-frequency transformer provides isolation and further voltage matching. The full-bridge inverter converts the DC-link voltage into a sinusoidal AC voltage using SPWM modulation.
For the modulation strategy, I studied single-polarity SPWM, double-polarity SPWM, and frequency-doubling SPWM. Single-polarity SPWM is attractive because it reduces switching losses and improves efficiency. In single-polarity SPWM, during the positive half-cycle, one switch in each leg is kept on or off according to the modulation, and the output voltage alternates between a positive value and zero. During the negative half-cycle, the output voltage alternates between a negative value and zero. This results in lower harmonic content and smaller filter requirements. I therefore chose single-polarity SPWM for my solar inverter.
The relationship between the modulation index and the output voltage is important. The modulation index is defined as:
$$m = \frac{U_{sm}}{U_{cm}}$$
where $U_{sm}$ is the amplitude of the sinusoidal modulation wave and $U_{cm}$ is the amplitude of the triangular carrier wave. The carrier ratio is:
$$N = \frac{f_c}{f_s}$$
where $f_c$ is the carrier frequency and $f_s$ is the modulation frequency. For single-polarity SPWM, when the carrier frequency is much higher than the modulation frequency, the average output voltage over one switching period can be approximated as:
$$u_o = \frac{U_d}{U_{cm}} u_s(t) = m U_d \sin \omega t$$
where $U_d$ is the DC-link voltage and $u_s(t)$ is the sinusoidal modulation signal. The fundamental output voltage is:
$$u_{o1} = m U_d \sin \omega t$$
Thus, by adjusting the modulation index, I can control the amplitude of the output voltage of the solar inverter. I also analyzed the dead-time effect. Dead time is necessary to prevent shoot-through in the same bridge leg, but it introduces voltage distortion and current waveform distortion. I used the STM32 advanced timer to set the dead time in software, which simplifies the circuit and improves reliability.
For the control strategy, I adopted a double closed-loop PI control scheme. The outer loop regulates the output voltage, and the inner loop regulates the inductor current. This structure improves stability, dynamic response, and load regulation. The control law for a continuous-time PI controller is:
$$u(t) = K_p e(t) + \frac{K_p}{T_i} \int_0^t e(t) dt$$
where $e(t)$ is the error between the reference and the actual value, $K_p$ is the proportional gain, and $T_i$ is the integral time. For digital implementation, I used the incremental PI algorithm:
$$\Delta u_k = u_k – u_{k-1} = A e_k – B e_{k-1} + C e_{k-2}$$
where the coefficients are:
$$A = K_p \left( 1 + \frac{T}{T_i} \right), \quad B = K_p \left( 1 + \frac{2T}{T_i} \right), \quad C = K_p \frac{T}{T_i}$$
and $T$ is the sampling period. I built the double closed-loop control model in MATLAB/Simulink. The simulation parameters I used are listed in the following table.
| Parameter | Value |
|---|---|
| DC-link voltage | 360 V |
| Filter inductance | 1 mH |
| Filter capacitance | 6 μF |
| Load resistance | 4 Ω |
| Outer-loop proportional gain | 0.01 |
| Outer-loop integral gain | 3 |
| Inner-loop proportional gain | 0.03 |
| Inner-loop integral gain | 6 |
The simulation results showed that the output voltage reached a peak value of approximately 311 V at 50 Hz, and the output current was in phase with the output voltage. The steady-state error was small, and the dynamic response was satisfactory. These results confirmed that the double closed-loop PI control strategy is feasible for the single-phase solar inverter.
Hardware Design of the Solar Inverter
After completing the modeling and control analysis, I designed the hardware for the solar inverter. The hardware includes the main power circuit, the control circuit, the driver circuit, the power supply circuit, the sampling circuit, and the protection circuit. The overall block diagram of my solar inverter is shown in the figure below.

The main circuit consists of a boost converter, a high-frequency transformer, a rectifier, a full-bridge inverter, and an LC filter. I designed the solar inverter for an output power of 500 W, an output voltage of 220 V, and an output frequency of 50 Hz. The input is a 12 V DC source, which can be a battery or a photovoltaic array. The boost converter raises the voltage to an intermediate level, and the high-frequency transformer further increases the voltage before the inverter stage. The full-bridge inverter uses four MOSFETs to generate the SPWM waveform.
For the boost converter, I calculated the inductor value based on the continuous conduction mode requirement. The duty cycle is:
$$D = 1 – \frac{U_{in}}{U_d}$$
With an input voltage range of 10.5 V to 13.5 V and an intermediate DC voltage of 60 V, the duty cycle varies from approximately 0.775 to 0.825. The critical inductance for continuous conduction is:
$$L \ge \frac{U_o^2 D (1-D)^2 T_s}{2 P_o \eta}$$
Using a switching frequency of 15 kHz, an output power of 500 W, a ripple factor of 5%, and the calculated duty cycle, I selected an inductor of 12.7 mH. I chose a 6MBI20-060 insulated-gate bipolar transistor module for the boost switch, with a voltage rating of 600 V and a current rating of 60 A. For the boost diode, I selected an IDP18E120 fast-recovery diode.
For the DC-link capacitor, I used the following relationship:
$$C = \frac{P_d D T_s}{\eta_c U_d^2}$$
With a voltage ripple coefficient of 0.05 and the calculated duty cycle, I obtained a capacitance of approximately 72.6 μF. To provide sufficient margin, I selected a 470 μF electrolytic capacitor with a voltage rating of 400 V.
For the high-frequency transformer, I used an EE42 ferrite core. The core product requirement is given by:
$$A_c A_w = \frac{P_T \times 10^4}{K_f K_w f_s B_w K_j}$$
where $P_T$ is the apparent power, $K_f$ is the waveform coefficient, $K_w$ is the window utilization factor, $f_s$ is the switching frequency, $B_w$ is the working magnetic flux density, and $K_j$ is the current density coefficient. The primary turns are:
$$N_p = \frac{V_{in} D \times 10^4}{2 B_m f_s A_e}$$
and the turns ratio is:
$$\frac{N_p}{N_s} = \frac{V_{in} D}{V_o}$$
I selected a high-frequency transformer with a primary winding of 3+3 turns and a secondary winding of 73T+18T, suitable for a power level of 500 W and a frequency range of 15 kHz to 50 kHz.
For the inverter stage, I selected IRFP450A MOSFETs. These devices have a drain-source voltage rating of 500 V and a continuous drain current rating of 14 A. They are suitable for the full-bridge configuration of my solar inverter. For the output filter, I used an LC low-pass filter with a cutoff frequency much lower than the switching frequency. The cutoff frequency is:
$$f_c = \frac{1}{2\pi \sqrt{LC}}$$
I selected a filter inductance of 1 mH and a filter capacitance of 10 μF. This filter attenuates the high-frequency harmonics generated by the SPWM switching and helps produce a nearly sinusoidal output voltage.
The control circuit is based on the STM32F103C8T6 microcontroller. This device includes an ARM Cortex-M3 core, a maximum operating frequency of 72 MHz, multiple 16-bit timers, a 12-bit analog-to-digital converter with multiple channels, and advanced timers with dead-time control. I used the advanced timer to generate four SPWM signals with complementary outputs and programmable dead time. The minimum system includes an 8 MHz crystal oscillator, a reset circuit, and a serial wire debug interface. The boot mode can be selected using the BOOT0 and BOOT1 pins.
For the gate driver, I used the IR2110S high-voltage high-speed power MOSFET driver. This driver can drive two MOSFETs in the same bridge leg and provides level shifting, isolation, and fast switching. The driver circuit includes bootstrap capacitors and diodes. I used a 47 μF bootstrap capacitor and an FM1S bootstrap diode. The driver ensures that the power MOSFETs receive sufficient gate charge for reliable turn-on and turn-off. The pin functions of the IR2110S are summarized in the following table.
| Pin | Name | Function |
|---|---|---|
| 1 | LO | Low-side output |
| 2 | COM | Common ground |
| 3 | VCC | Low-side supply voltage |
| 6 | VS | High-voltage floating supply offset |
| 7 | VB | High-side floating supply |
| 8 | HO | High-side output |
| 11 | VDD | Logic supply voltage |
| 12 | HIN | Logic high-side input |
| 13 | SD | Shutdown |
| 14 | LIN | Logic low-side input |
| 15 | VSS | Logic ground |
For the power supply, I designed a 5 V regulator using the L7805CV and a 3.3 V regulator using the LM1117. The 3.3 V supply is used for the STM32 and the analog signal conditioning circuits. I separated the analog and digital grounds using a zero-ohm resistor to reduce noise. The power supply circuits include input and output filtering capacitors to ensure stable operation.
For the sampling circuits, I designed voltage and current sensing for both the DC input and the AC output. For the DC input, I used a resistor divider followed by a voltage follower and a clamping circuit to keep the signal within 0 to 3.3 V. I also used the HCNR201 linear optocoupler for isolation. For the AC output voltage, I used a CHV-50P voltage transducer. For the AC output current, I used a DT-50P current transducer. The signal conditioning circuits convert the transducer outputs into 0 to 3.3 V signals suitable for the STM32 ADC. The sampling circuits are essential for the double closed-loop control and for the protection functions of the solar inverter.
For the protection circuit, I implemented overcurrent, overvoltage, undervoltage, and overtemperature protection. The overcurrent protection uses a current transformer, a rectifier, a filter, and an LM339 comparator. When the output current exceeds a preset threshold, the comparator output changes state and triggers an interrupt in the STM32. The microcontroller then immediately stops generating SPWM signals, and the solar inverter shuts down. The overvoltage and undervoltage protection circuit uses two comparators to detect whether the input voltage is within the allowed range. If the voltage is too high or too low, the circuit generates a fault signal. I also included a buzzer alarm circuit with an active electromagnetic buzzer. These protection functions improve the reliability and safety of the solar inverter.
Software Design
I developed the software for the solar inverter in Keil uVision4 using the C programming language and the STM32 firmware library. The software is modular and includes the main program, the analog-to-digital conversion routine, the interrupt service routines, the PI control algorithm, and the SPWM generation routine. The main program initializes the system constants, variables, and peripherals. After initialization, it enables interrupts and timers and then enters a loop waiting for interrupts. This structure allows the solar inverter to respond quickly to real-time events.
The analog-to-digital conversion routine samples the input voltage, output voltage, and output current. To improve accuracy, I used an average filtering algorithm that takes multiple samples and computes the average value. This reduces the effect of random noise and improves the precision of the control loop. The sampling routine is called periodically from the timer interrupt.
The interrupt service routine handles the timer interrupt and the external fault interrupts. In the timer interrupt, I first save the context, then check whether any protection fault has occurred. If a fault is detected, I disable the PWM outputs and set a fault flag. If no fault is present, I perform the analog-to-digital conversion, update the duty cycle, and execute the PI control algorithm. The interrupt routine is critical for the real-time performance of the solar inverter.
I implemented the incremental PI algorithm as follows. First, I read the reference value and the sampled value. Then I computed the error. Then I calculated the incremental control output using the coefficients A, B, and C. I limited the output to the maximum and minimum values to prevent integral windup and to protect the power stage. Finally, I updated the previous errors. This algorithm is simple and requires less computation than the positional PI algorithm, which makes it suitable for the STM32 microcontroller.
For SPWM generation, I used a lookup table method. I precomputed the discrete values of a sinusoidal reference wave and stored them in an array. The number of points in the table corresponds to the carrier ratio. In each timer interrupt, the program reads the next value from the table and writes it to the compare register of the advanced timer. The timer is configured in center-aligned mode, which produces a triangular carrier. When the counter value matches the compare register value, the output pin toggles. By using two complementary output channels with dead time, I generated four SPWM signals for the full-bridge inverter. This method avoids real-time trigonometric calculations and reduces the computational burden on the microcontroller.
Experimental Results and Analysis
I built a prototype of the single-phase solar inverter and tested it in the laboratory. The DC input was provided by a valve-regulated sealed lead-acid battery with a nominal voltage of 12 V and a capacity of 100 Ah. I programmed the STM32 microcontroller using Keil uVision and downloaded the code through the serial wire debug interface. I measured the SPWM gate drive waveforms, the output voltage, and the output current under different load conditions.
The gate drive waveforms showed that the SPWM signals from the STM32 were correctly amplified and isolated by the IR2110S driver. There were some small spikes at the switching instants, but they were within acceptable limits for the power MOSFETs. The dead time was set to 3 μs, which prevented shoot-through in the bridge legs.
Under no-load conditions, the solar inverter produced an output voltage of approximately 219 V at 50 Hz. The output voltage waveform was smooth and stable, with low harmonic distortion. The heat sink temperature remained around 25 °C, and the solar inverter operated normally. The no-load current was zero, as expected.
I then tested the solar inverter with a load consisting of a 450 W hair dryer, a 5 W power bank charger, a 5 W mobile phone charger, and a 10 W LED lamp. The total load power was approximately 470 W, which is close to the rated power of 500 W. The output voltage remained stable, and the output current waveform was in phase with the voltage. The waveform quality was good, and the solar inverter maintained a stable output.
I also tested the dynamic response by suddenly adding a linear load. The output voltage dropped slightly at the instant of load application, but it recovered quickly. The double closed-loop control ensured that the output voltage remained within acceptable limits. The response time was short, and the waveform distortion was small.
To evaluate the efficiency of the solar inverter, I used a ZX1M AC/DC resistance box as the load. I measured the input power and output power at several power levels and calculated the efficiency. The results are shown in the following table.
| Input power (W) | Output power (W) | Load resistance (Ω) | Efficiency (%) |
|---|---|---|---|
| 50 | 45.42 | 1065.7 | 90.83 |
| 100 | 91.49 | 529.0 | 91.49 |
| 200 | 184.50 | 262.4 | 92.25 |
| 300 | 277.12 | 175.7 | 92.37 |
| 400 | 364.61 | 132.9 | 91.15 |
The efficiency of the solar inverter was above 90% over the tested power range. The highest efficiency was approximately 92.37% at 300 W. These results demonstrate that the high-frequency isolated topology and the double closed-loop PI control strategy are effective for a small-power solar inverter. The experimental results also confirmed that the STM32-based control system can generate accurate SPWM signals and maintain a stable output voltage.
Conclusion and Future Work
In this work, I designed and implemented a single-phase photovoltaic off-grid solar inverter based on the STM32F103C8T6 microcontroller. I modeled the photovoltaic cell in MATLAB/Simulink and analyzed its output characteristics under different irradiance and temperature conditions. I studied inverter topologies and selected a high-frequency isolated topology with a boost converter, a high-frequency transformer, and a full-bridge inverter. I adopted single-polarity SPWM modulation and a double closed-loop PI control strategy. I designed the hardware circuits, including the main power circuit, control circuit, driver circuit, power supply, sampling circuits, and protection circuits. I developed the software in Keil uVision4 using the C language and the STM32 firmware library. I built a prototype and tested it under no-load and loaded conditions. The experimental results showed that the solar inverter produced a stable 220 V, 50 Hz sinusoidal output voltage with an efficiency above 90%.
Despite the promising results, there are several areas for improvement. The dynamic response of the solar inverter under large load steps could be further improved by optimizing the PI parameters or by using more advanced control algorithms such as model predictive control or sliding mode control. The power rating of the prototype is 500 W, which limits its application to small loads. Increasing the power rating would require larger components, better thermal management, and more robust protection. The maximum power point tracking function was not fully implemented in this prototype, and future work could integrate a dedicated MPPT algorithm to improve the energy harvest from the photovoltaic panels. In addition, the electromagnetic interference and common-mode noise could be reduced by optimizing the printed circuit board layout and adding additional filtering.
Overall, my work demonstrates that a single-phase solar inverter based on the STM32 microcontroller is a practical and effective solution for off-grid photovoltaic power systems. The design methodology, including photovoltaic modeling, control strategy selection, hardware design, software development, and experimental verification, can serve as a reference for future research and development of solar inverter systems. I believe that continued improvements in power electronics, control algorithms, and digital signal processing will make solar inverters even more efficient, compact, and reliable in the future.
