This section explains how to generate sine waves using PWM control, which is used in inverters, etc.
■Sine wave generation circuit diagram
As shown below, it consists of a switch and an RL circuit that acts as a low-pass filter. By turning the switch on and off at the right time using PWM control, a sine wave can be generated in the RL circuit.
■PWM control method: Triangle wave comparison method
The triangular wave comparison method is a way to turn a switch on and off at the desired timing to generate a sine wave.
If the sine wave and triangular wave you want to generate are passed through a comparator as shown below, when the triangular wave value is smaller than the sine wave value, the voltage level will be ON.
Conversely, when the triangular wave value is greater, the voltage level will be OFF.
■Implementation example using python
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
f1 = 1 # Sine Wave Frequency
f2 = 50 # Triangle Wave Frequency
K = 0.015 # Low-pass filter time constant
v = 0.5 # Initial voltage value of the pseudo sine wave
v_t = [] # Voltage value storage space
x = np.arange(0,1,0.001) # time
sin = (np.sin(2 * np.pi * f1 * x) + 1)/2 # Target sine wave
tri = (signal.sawtooth(2 * np.pi * f2 * x, 0.5) + 1)/2 # Triangle wave
on = sin > tri # ON/OFF signal
for i in on: # Pseudo Sine Wave Generation
v = K * i + (1-K)* v # Low-pass Filter
v_t = np.append(v_t,v)
The results are as follows. We were able to generate a sine wave close to the desired sine wave. This sine wave has a delay because it passes through a low-pass filter.
Also, the frequency of the triangular wave needs to be appropriately changed depending on the time constant of the low-pass filter.