Case Study: 750W Grid-Tied Full-Bridge Inverter on STM32F103 — Unipolar SPWM with Plug-in Repetitive Control

A production-derived 750W single-phase grid-tied inverter on STM32F103C8T6 featuring unipolar SPWM at 32kHz, DQ-frame current control, software PLL, and 4-channel plug-in repetitive control for harmonic suppression.

Case Study: 750W Grid-Tied Full-Bridge Inverter on STM32F103

A production-derived single-phase grid-tied inverter featuring unipolar SPWM at 32 kHz, software PLL grid synchronization, DQ-frame current control, and plug-in repetitive control for harmonic suppression — all on a single 72 MHz Cortex-M3 MCU without an FPU. | Published August 2026 | innovchip.net

1. Project Overview

This 750W single-phase grid-tied full-bridge inverter is built on the STM32F103C8T6 — a 72 MHz Cortex-M3 microcontroller with 64 KB Flash, 20 KB SRAM, and notably no hardware floating-point unit. Despite this constraint, the firmware implements a complete grid-tied inverter stack: unipolar sinusoidal PWM, software phase-locked loop (PLL) for grid synchronization, DQ-rotating-frame current control with cross-axis decoupling, and a multi-channel plug-in repetitive controller for harmonic suppression. The design is clearly derived from an earlier TI C2000 DSP codebase, ported to the ultra-low-cost STM32 platform through careful fixed-point mathematics and resource-aware scheduling.

Key System Specifications:

Rated Power: 750 W | Grid Voltage: 220VAC ±15% | Grid Frequency: 50 Hz | DC Bus: ~390 VDC (from PFC Boost) | PWM Carrier: 32 kHz (INV), 16 kHz (PFC) | MCU: STM32F103C8T6 @ 72 MHz | ADC: 12-bit, 1 Msps | Switching Devices: 600V IGBTs (full-bridge), MOSFETs (PFC)

2. Hardware Topology: Two-Stage Architecture

The inverter employs a two-stage cascaded topology: a front-end boost PFC converter that rectifies and regulates the AC input to a stable 390V DC bus, followed by a single-phase H-bridge inverter that synthesizes the sinusoidal output current using unipolar SPWM. Both stages are controlled by the same STM32F103C8T6, which drives all power switches through two independent timer peripherals.

Stage Topology Timer/Pins Frequency Modulation
DC-DC PFC Boost Single-switch boost with input bridge rectifier TIM8 CH1/CH1N (complementary) 16 kHz Center-aligned, current-mode control
DC-AC Full-Bridge Inverter H-bridge (4 IGBTs) with LC output filter TIM1 CH1-CH4 full remap (PE8-PE11) 32 kHz Unipolar SPWM with bus-voltage feedforward
Auxiliary TIM4 (base timer, 1 kHz) General-purpose timing, state machine tick

PWM Pin Remapping: The design uses TIM1’s full remap mode to route all four complementary PWM outputs to GPIOE pins 8–11 (PE8=N-PWM1, PE9=N-PWM2, PE10=N-PWM3, PE11=N-PWM4), keeping GPIOA/B free for ADC inputs and communication peripherals. Dead-time is configured via TIM1_BDTR: DTG[7:0]=0x45 → tdead = (32+5) × 16 × 1/72MHz = 1.16 µs for the inverter stage. The PFC stage uses a lighter dead-time of 0.58 µs on TIM8.

The H-bridge uses 600V-rated IGBTs in a TO-220 package, operating with unipolar PWM — only two transistors switch at high frequency at any instant while the complementary pair holds steady-state, halving effective switching losses compared to bipolar modulation. The output filter is a single-stage LC low-pass with an inductor in the range of 2–5 mH, sized to attenuate the 32 kHz carrier ripple to below 1% THD at rated load.

3. PWM Strategy: Unipolar SPWM with Bus-Voltage Feedforward

The inverter PWM implements unipolar sinusoidal modulation in SINGLE_MODE. Compared to bipolar SPWM, unipolar modulation doubles the effective switching frequency seen by the output filter (the inductor ripple frequency is 64 kHz at a 32 kHz carrier), significantly reducing filter size while maintaining low switching losses. The modulation index is updated every PWM cycle via the IPRG_Spwm_DEAL function, which computes the duty cycle as:

SPWM Duty Cycle Computation:

DA = 0.5 + m × sin(θ) / 2   |   DB = 0.5 – m × sin(θ) / 2

Where m = Vref / Vbus × Vbus,nom / Vref,nom — a bus-voltage feedforward term that compensates for DC-link ripple, ensuring the actual output voltage tracks the sinusoidal reference independent of bus voltage fluctuations.

The sinusoidal reference is drawn from a pre-computed 1024-entry sine table stored in Flash memory, indexed by the phase accumulator. This eliminates runtime trigonometric computation — critical on an MCU without an FPU. The sine values are stored in Q12 fixed-point format (1.0 = 4096), and the duty-cycle registers are loaded in Q10 format after scaling by the modulation index.

4. Control Architecture

4.1 Off-Grid Mode: Cascaded Voltage-Current Loop

In islanded operation, the inverter runs a cascaded dual-loop PI control: the outer voltage loop regulates the AC output voltage amplitude (220V RMS) and generates the inner current reference. The inner current loop tracks this reference with a bandwidth of approximately 1 kHz. Both loops execute at the 32 kHz PWM rate (every 31.25 µs).

4.2 Grid-Tied Mode: DQ-Rotating-Frame Current Control

For grid-connected operation, the control transitions to synchronous-frame (DQ) current control. The grid voltage and inverter current are transformed from the stationary αβ-frame to the rotating DQ-frame using the grid phase angle from the software PLL. The D-axis current (id) controls active power, and the Q-axis current (iq) controls reactive power. Cross-axis decoupling terms compensate for the Lω coupling between the D and Q axes, enabling independent control of active and reactive power.

All DQ-transformation coefficients and PI gains are pre-computed in Q28 fixed-point format for the coordinate transforms and Q10 format for the PI controller, carefully scaled to avoid overflow at maximum modulation index while preserving sub-1% steady-state resolution.

4.3 Software Phase-Locked Loop (PLL)

The PLL locks to the grid voltage zero-crossing using a second-order generalized integrator (SOGI) structure, sampled at 16 kHz. The frequency tracking rate is limited to 0.64 Hz/s to reject transient frequency disturbances. The code includes a zero-crossing jump anticipation feature: if the expected zero-crossing point differs from the actual by more than a configurable threshold, the PLL performs a soft angle correction rather than an abrupt reset, preventing current transients.

4.4 Plug-in Repetitive Control (RC) for Harmonic Suppression

A 4-channel plug-in repetitive controller runs in parallel with the PI current loop to suppress periodic harmonic distortion. Each channel targets a specific harmonic order (3rd, 5th, 7th, and 9th), using a delay-line memory buffer equal to one fundamental period (20 ms for 50 Hz). The RC transfer function includes:

  • Damping coefficient (Q < 1): a slight low-pass characteristic to prevent instability at high frequencies
  • Dead-zone: disables the RC output when the error is below a configurable threshold, preventing integrator windup from noise
  • Output limiting: clamps the RC correction term to ±10% of the PI output, ensuring the RC improves but never destabilizes the current loop

This hybrid PI+RC structure achieves <3% THD on the output current under nonlinear and distorted grid conditions, a significant improvement over standalone PI control.

5. Protection and Fault Handling

Protection Threshold Response Time Action
Overcurrent (hardware) +15 A / -15 A <10 µs (cycle-by-cycle via comparator) PWM duty cycle 3% retraction per cycle until current subsides
Overcurrent (software) +12 A / -12 A 100 µs (ADC sampling interval) Fault latch, PWM shutdown
Bus Overvoltage 450 VDC 100 µs Immediate PWM disable
Bus Undervoltage 280 VDC 100 µs Warning → shutdown after 100 ms persistence
Grid Overvoltage 253 VAC (115%) 200 ms Disconnect and retry after 5 minutes
Grid Undervoltage 187 VAC (85%) 200 ms Disconnect and retry after 5 minutes
Overfrequency / Underfrequency 50.5 Hz / 49.5 Hz 200 ms Disconnect, retry on return to nominal
DC Injection +500 mA 1 second averaging window Fault latch, requires power-cycle reset
Overtemperature 85°C (heatsink NTC) 1 second Power derating → shutdown at 95°C

Cycle-by-Cycle Current Limiting: A hardware comparator on the current-sense shunt triggers TIM1’s break input (BRK), which immediately truncates the active PWM pulse. The ISR then reduces the duty cycle by 3% per subsequent cycle until the current falls below the threshold — a soft current-limiting scheme that avoids hard shutdowns during momentary overloads.

6. Software Architecture

The firmware executes from a 16 kHz timer interrupt (TIM4), completing one full control cycle every 62.5 µs. The ISR executes a 9-step sequential chain:

  1. Read ADC results (grid voltage, inverter current, DC bus voltage, PFC inductor current)
  2. Apply Q10/Q12/Q28 fixed-point scaling to all samples
  3. Run PLL phase update and zero-crossing detection
  4. Execute DQ-frame transformation (Park/Clarke transforms in Q28)
  5. Compute PI current controller output (Q10 → Q12 for PWM mapping)
  6. Add repetitive controller correction term
  7. Apply cross-axis decoupling and bus-voltage feedforward
  8. Update TIM1 compare registers for SPWM duty cycles
  9. Check fault status, update state machine, and return

The sine table (1024 × 2 bytes = 2 KB) and all control parameters are stored in Flash. The RAM budget is tight: the repetitive controller’s 4-channel delay buffers alone consume approximately 2.5 KB, leaving about 17 KB for stack, heap, and working variables on the 20 KB SRAM.

7. Key Design Takeaways

  1. DSP-to-STM32 Porting Masterclass: The codebase carries clear DNA from a Texas Instruments C2000 DSP design (evident in the naming conventions and control structure), yet it’s been painstakingly ported to a $1.50 Cortex-M3 MCU. The fixed-point mathematics (Q10/Q12/Q28 scale factors), pre-computed sine LUT, and resource-aware ISR scheduling demonstrate how to ship DSP-grade control on a cost-optimized general-purpose MCU.
  2. Repetitive Control as a Harmonic Safety Net: Rather than relying on high-bandwidth PI alone, the 4-channel plug-in RC provides targeted harmonic cancellation without destabilizing the main control loop. This is especially valuable for grid-tied inverters operating on weak or distorted grids.
  3. Production-Ready Protection: The 9-tier fault hierarchy with hardware cycle-by-cycle limiting, software overcurrent latching, and DC injection detection meets utility-interconnection requirements for distributed generation systems.
  4. Single-MCU Integration: Running PFC, inverter PWM, PLL, DQ control, repetitive control, and fault management on a single 72 MHz MCU is an impressive engineering feat. The 16 kHz ISR leaves approximately 40 µs of headroom per cycle for background tasks (communication, EEPROM writes, state machine updates).

8. FAQ

Q1: Why was this design ported from a TI C2000 DSP to an STM32F103?

The STM32F103C8T6 is approximately 5–8× cheaper than an equivalent TMS320F280x DSP while offering comparable PWM peripherals (TIM1 with complementary outputs, dead-time insertion, and break input). For a 750W consumer-grade inverter where BOM cost is the dominant design constraint, the trade-off — giving up the FPU and hardware C28x math accelerators in exchange for a sub-$2 MCU — is commercially compelling.

Q2: Why was 32 kHz chosen as the PWM carrier frequency?

32 kHz is a deliberate sweet spot: it’s above the audible range (eliminating acoustic noise from the magnetics), doubles the effective ripple frequency to 64 kHz under unipolar modulation (enabling a smaller output filter inductor), and keeps the switching losses manageable at 600V. At 72 MHz core clock, each 32 kHz PWM period allows 2,250 CPU cycles — enough for the full 9-step ISR with approximately 40% headroom.

Q3: How does the repetitive controller stay stable when the grid frequency drifts?

The RC uses a variable-length delay buffer. The delay-line length (N) is dynamically adjusted based on the PLL’s measured grid period: N = round(fs / fgrid), where fs = 16 kHz. If fgrid shifts from 50.00 Hz to 49.95 Hz, N changes from 320 to 321 samples, keeping the delay line synchronized to the actual fundamental period rather than assuming a fixed 50 Hz.

Q4: What are the ADC scaling coefficients for current and voltage measurements?

The current-sense scaling uses a 0.01Ω shunt with a gain-50 differential amplifier, yielding 0.5 V/A. With the ADC’s 3.3V reference and 12-bit resolution (4096 counts), the conversion is: Iactual (A) = ADC_value × 3.3 / 4096 / 0.5 = ADC_value × 0.00161. In the fixed-point code this is implemented as a Q10 multiplication with a pre-computed scale factor. Voltage sensing uses a resistive divider (1000:1 ratio) followed by a 1.65V offset stage to center the AC waveform at mid-ADC range.

Q5: Can this design be scaled to higher power levels?

The control architecture (DQ current control + repetitive control + PLL) is power-agnostic and scales directly. The limitations are the STM32F103’s pin count and Flash size — a 3kW version would require an STM32F407 (Cortex-M4 with FPU) for additional ADC channels, CAN communication, and Ethernet for monitoring. The IGBT power stage would also need upgrading to 1200V devices with isolated gate drivers for the higher DC bus voltage (typically 400–800V for 3kW designs).

Leave a Reply

Your email address will not be published. Required fields are marked *