SPWM Lookup Table Generator

SPWM Lookup Table Generator

Value typically between 0 and 1. (0.8 = 80%)

Number of data points for the selected wave cycle.

Phase offset for the sine wave (0-360 degrees).

Understanding SPWM Lookup Tables

Sine Pulse Width Modulation (SPWM) is a widely used technique to generate an AC output voltage from a DC input by varying the width of square pulses. It’s fundamental in inverters (DC to AC converters), motor drives, and active power filters.

The core idea is to create a series of PWM pulses whose duty cycles are proportional to the amplitude of a sinusoidal reference wave at various points in a cycle. A lookup table stores these pre-calculated duty cycle values, allowing microcontrollers or FPGAs to quickly generate the required PWM signals without complex real-time calculations.

Key Parameters:

  • Modulation Index (Ma): This value, typically between 0 and 1 (or 0% to 100%), determines the amplitude of the output AC voltage. An Ma of 1 (100%) represents the maximum possible sinusoidal output voltage without overmodulation. Higher Ma values generally lead to higher output voltage but can introduce more harmonics if pushed too far.
  • Number of Samples: This specifies how many discrete duty cycle values are generated for the selected wave cycle. A higher number of samples results in a smoother approximation of the sine wave and potentially lower harmonic distortion but requires a larger lookup table.
  • Start Angle (Degrees): This defines the phase offset for the sine wave. A value of 0 degrees means the sine wave starts at its zero-crossing point with a positive slope. Changing this value will shift the entire waveform, affecting the starting point of the duty cycle values in your lookup table.
  • PWM Resolution (Bits): This defines the number of discrete steps available for the duty cycle values. For example, 8-bit resolution means duty cycles can take 2^8 = 256 distinct values (from 0 to 255). Higher resolution allows for finer control over the PWM signal and a more accurate representation of the sine wave, reducing quantization error and harmonic content, but requires more memory for the lookup table.
  • Output Range:
    • Unipolar (0 to MaxVal): The generated values range from 0 (minimum duty cycle) to the maximum value based on the PWM resolution (e.g., 255 for 8-bit). This is suitable for common PWM generators where duty cycle is a positive value.
    • Bipolar (-MaxVal/2 to +MaxVal/2): The generated values are centered around zero, ranging from approximately half the maximum negative value to half the maximum positive value of the resolution. For example, with 8-bit resolution (max 255), values would range from -128 to +127. This is useful for systems where a signed representation of the sine wave amplitude is preferred.
  • Wave Cycle: This determines the portion of the sine wave cycle for which the lookup table is generated.
    • Full Cycle (0-360°): Generates values for one complete sine wave period.
    • Half Cycle (0-180°): Generates values for the first half of a sine wave period (e.g., for symmetric PWM, where the second half is a mirrored version). This can save memory in some applications.

Calculation Principle:

The duty cycle for each sample point ($D_n$) is calculated based on a sinusoidal reference, scaled by the modulation index, and then quantized to the chosen PWM resolution.
For **Unipolar (0 to MaxVal)** output: $$D_n = \text{round}\left( \frac{\text{M_a} \cdot \sin\left(\frac{2\pi n}{\text{Samples_FullCycle}} + \text{StartAngle_rad}\right) + 1}{2} \cdot (\text{2}^{\text{Resolution}} – 1) \right)$$
For **Bipolar (-MaxVal/2 to +MaxVal/2)** output: $$D_n = \text{round}\left( \text{M_a} \cdot \sin\left(\frac{2\pi n}{\text{Samples_FullCycle}} + \text{StartAngle_rad}\right) \cdot \frac{(\text{2}^{\text{Resolution}} – 1)}{2} \right)$$
Where:

  • $n$ is the current sample index (from 0 to Samples – 1)
  • $\text{M_a}$ is the Modulation Index
  • $\text{Samples_FullCycle}$ is the number of samples that would constitute a full 360-degree cycle. If “Half Cycle” is selected for generation, this value is effectively twice the “Number of Samples” entered.
  • $\text{StartAngle_rad}$ is the Start Angle converted to radians ($ \text{Start Angle in Degrees} \times \frac{\pi}{180} $)
  • $\text{Resolution}$ is the PWM Resolution in bits

Note: This tool provides ideal values. Practical implementations may require adjustments for dead-time compensation, control loop dynamics, and hardware limitations.