Flyback converter
The flyback converter shown in the figure operates under CCM at a frequency of $40\,$kHz. The input voltage of $20\,$V and the output voltage is $5\,$V. The converter delivers $25\,$W of power to the load. The magnetizing inductance of the flyback transformer is $10\,\mu$H as seen from the secondary side, and the transformer has a turns ratio of 1:0.125.- What is the duty cycle of the converter?
- Find the capacitance $C$ required to keep the output voltage ripple less than $1\,\%$.
- Plot the current through $L_m$, and determine the peak and average values.
- Evaluate the magnetizing inductance seen from the source side.
from IPython.display import Image
Image(filename =r'flyback_2_fig_1.png', width=360)
# run this cell to view the circuit file.
%pycat flyback_2_orig.in
We now replace the strings such as \$Vdc, \$L, with the values of our choice by running the python script given below. It takes an existing circuit file flyback_2_orig.in and produces a new circuit file flyback_2.in, after replacing \$Vdc, \$L, etc. with values of our choice.
import gseim_calc as calc
P = 25.0
Vo = 5.0
R = Vo*Vo/P
s_R = ("%11.4E"%(R)).strip()
s_D = "0.5" # to be changed by user
s_Vdc = "20"
s_L1 = "1" # Lm on the source side: make the impedance large
s_L2 = "10e-6"
s_C = "1200e-6" # to be changed by user
s_N1 = "1"
s_N2 = "0.125"
s_f_hz = "40e3"
T = 1/float(s_f_hz)
s_Tend = "20e-3"
delt1 = 2.0*T
Tend = float(s_Tend)
T1 = Tend - delt1
s_T1 = ("%11.4E"%(T1)).strip()
l = [
('$D', s_D),
('$Vdc', s_Vdc),
('$L1', s_L1),
('$L2', s_L2),
('$R', s_R),
('$C', s_C),
('$N1', s_N1),
('$N2', s_N2),
('$f_hz', s_f_hz),
('$T1', s_T1),
('$Tend', s_Tend),
]
calc.replace_strings_1("flyback_2_orig.in", "flyback_2.in", l)
print('flyback_2.in is ready for execution')
flyback_2.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("flyback_2.in")
os.system('run_gseim flyback_2.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = flyback_2.in main: i_solve = 0 main: calling solve_trns Transient simulation starts... i=0 i=10000 i=20000 i=30000 i=40000 GSEIM: Program completed.
0
The circuit file (flyback_2.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on flyback_2.in) creates a data file called flyback_2.dat in the same directory. We can now use the python code below to compute/plot the various quantities of interest.
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("flyback_2.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t1 = u[:, 0]
t = t1 - t1[0]
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_IL2 = slv.get_index(i_slv,i_out,"IL2" )
col_IS = slv.get_index(i_slv,i_out,"IS" )
col_ID = slv.get_index(i_slv,i_out,"ID" )
col_IC = slv.get_index(i_slv,i_out,"IC" )
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
l_IL2 = calc.avg_rms_2(t, u[:,col_IL2], T, 2.0*T, 1.0e-4*T)
l_IL2_1 = calc.min_max_1(t, u[:,col_IL2], 0.0, 2.0*T)
print('rms L2 current:', "%11.4E"%l_IL2[2][0])
print('average L2 current:', "%11.4E"%l_IL2[1][0])
print('peak L2 current:', "%11.4E"%l_IL2_1[1])
l_v_out_1 = calc.min_max_1(t, u[:,col_v_out], 0.0, 2.0*T)
v_out_ptop = l_v_out_1[1] - l_v_out_1[0]
print('peak-to-peak ripple in Vo:', "%11.4E"%v_out_ptop)
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
color5='cornflowerblue'
fig, ax = plt.subplots(5, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(7, 7, ax[0])
for i in range(5):
ax[i].set_xlim(left=0, right=2.0*T*1e6)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].plot(t*1e6, u[:,col_IL2 ], color=color1, linewidth=1.0, label="$i_{L2}$")
ax[1].plot(t*1e6, u[:,col_IC ], color=color2, linewidth=1.0, label="$i_C$")
ax[2].plot(t*1e6, u[:,col_IS ], color=color3, linewidth=1.0, label="$i_S$")
ax[3].plot(t*1e6, u[:,col_ID ], color=color4, linewidth=1.0, label="$i_D$")
ax[4].plot(t*1e6, u[:,col_v_out], color=color5, linewidth=1.0, label="$V_o$")
ax[0].set_ylabel(r'$i_{L2}$', fontsize=14)
ax[1].set_ylabel(r'$i_C$' , fontsize=14)
ax[2].set_ylabel(r'$i_S$' , fontsize=14)
ax[3].set_ylabel(r'$i_D$' , fontsize=14)
ax[4].set_ylabel(r'$V_o$' , fontsize=14)
ax[4].set_xlabel('time (' + r'$\mu$' + 'sec)', fontsize=14)
#ax[0].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
# markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
# prop = {'size' : 12},)
for i in range(4):
ax[i].tick_params(labelbottom=False)
#plt.tight_layout()
plt.show()
filename: flyback_2.dat rms L2 current: 5.0648E+00 average L2 current: -4.9836E+00 peak L2 current: -3.4205E+00 peak-to-peak ripple in Vo: 2.5944E-02
Next, we will make $L_2$ large (it will behave like an open circuit). In that case, $L_1$ would serve as the magnetizing inductance as seen from the primary.
import gseim_calc as calc
P = 25.0
Vo = 5.0
R = Vo*Vo/P
s_R = ("%11.4E"%(R)).strip()
s_D = "0.5" # to be changed by user
s_Vdc = "20"
s_L1 = "800e-6" # to be changed by user
s_L2 = "1" # Lm on the load side: make the impedance large
s_C = "1200e-6" # to be changed by user
s_N1 = "1"
s_N2 = "0.125"
s_f_hz = "40e3"
T = 1/float(s_f_hz)
s_Tend = "20e-3"
delt1 = 2.0*T
Tend = float(s_Tend)
T1 = Tend - delt1
s_T1 = ("%11.4E"%(T1)).strip()
l = [
('$D', s_D),
('$Vdc', s_Vdc),
('$L1', s_L1),
('$L2', s_L2),
('$R', s_R),
('$C', s_C),
('$N1', s_N1),
('$N2', s_N2),
('$f_hz', s_f_hz),
('$T1', s_T1),
('$Tend', s_Tend),
]
calc.replace_strings_1("flyback_2_orig.in", "flyback_2.in", l)
print('flyback_2.in is ready for execution')
flyback_2.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("flyback_2.in")
os.system('run_gseim flyback_2.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = flyback_2.in main: i_solve = 0 main: calling solve_trns Transient simulation starts... i=0 i=10000 i=20000 i=30000 i=40000 GSEIM: Program completed.
0
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("flyback_2.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t1 = u[:, 0]
t = t1 - t1[0]
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_IL1 = slv.get_index(i_slv,i_out,"IL1" )
col_IS = slv.get_index(i_slv,i_out,"IS" )
col_ID = slv.get_index(i_slv,i_out,"ID" )
col_IC = slv.get_index(i_slv,i_out,"IC" )
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
l_IL1 = calc.avg_rms_2(t, u[:,col_IL1], T, 2.0*T, 1.0e-4*T)
l_IL1_1 = calc.min_max_1(t, u[:,col_IL1], 0.0, 2.0*T)
print('rms L1 current:', "%11.4E"%l_IL1[2][0])
print('average L1 current:', "%11.4E"%l_IL1[1][0])
print('peak L1 current:', "%11.4E"%l_IL1_1[1])
l_v_out_1 = calc.min_max_1(t, u[:,col_v_out], 0.0, 2.0*T)
v_out_ptop = l_v_out_1[1] - l_v_out_1[0]
print('peak-to-peak ripple in Vo:', "%11.4E"%v_out_ptop)
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
color5='cornflowerblue'
fig, ax = plt.subplots(5, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(7, 7, ax[0])
for i in range(5):
ax[i].set_xlim(left=0, right=2.0*T*1e6)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].plot(t*1e6, u[:,col_IL1 ], color=color1, linewidth=1.0, label="$i_{L1}$")
ax[1].plot(t*1e6, u[:,col_IC ], color=color2, linewidth=1.0, label="$i_C$")
ax[2].plot(t*1e6, u[:,col_IS ], color=color3, linewidth=1.0, label="$i_S$")
ax[3].plot(t*1e6, u[:,col_ID ], color=color4, linewidth=1.0, label="$i_D$")
ax[4].plot(t*1e6, u[:,col_v_out], color=color5, linewidth=1.0, label="$V_o$")
ax[0].set_ylabel(r'$i_{L1}$', fontsize=14)
ax[1].set_ylabel(r'$i_C$' , fontsize=14)
ax[2].set_ylabel(r'$i_S$' , fontsize=14)
ax[3].set_ylabel(r'$i_D$' , fontsize=14)
ax[4].set_ylabel(r'$V_o$' , fontsize=14)
ax[4].set_xlabel('time (' + r'$\mu$' + 'sec)', fontsize=14)
#ax[0].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
# markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
# prop = {'size' : 12},)
for i in range(4):
ax[i].tick_params(labelbottom=False)
#plt.tight_layout()
plt.show()
filename: flyback_2.dat rms L1 current: 6.2983E-01 average L1 current: 6.2332E-01 peak L1 current: 7.7913E-01 peak-to-peak ripple in Vo: 2.5960E-02
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.