Flyback converter
For the two-switch flyback converter shown in the figure, the input voltage is $40\,$V, and the output voltage is $10\,$V. The rated power of the converter is $10\,$W. The switching frequency is $50\,$kHz, and the turns ratio of the transformer is 2:1. The converter operates under DCM, and the secondary conduction time is one half of the off duration of the primary switches $S_1$ and $S_2$ (which are turned on or off simultaneously).- What is the on time of switches $S_1$ and $S_2$?
- What is the magnetizing inductance of the flyback transformer as seen from the source side?
- Plot the current through the primary and secondary winding, and determine the peak values.
- Find the capacitance $C$ required to keep the output voltage ripple less than $2\,\%$.
In [1]:
from IPython.display import Image
Image(filename =r'flyback_3_fig_1.png', width=360)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat flyback_3_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_3_orig.in and produces a new circuit file flyback_3.in, after replacing \$Vdc, \$L, etc. with values of our choice.
In [3]:
import gseim_calc as calc
P = 10.0
Vo = 10.0
R = Vo*Vo/P
s_R = ("%11.4E"%(R)).strip()
s_D = "0.25" # to be changed by user
s_Vdc = "40"
s_Lm = "40e-6" # to be changed by user
s_C = "40e-6" # to be changed by user
s_N1 = "2"
s_N2 = "1"
s_f_hz = "50e3"
T = 1/float(s_f_hz)
s_Tend = "5e-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),
('$Lm', s_Lm),
('$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_3_orig.in", "flyback_3.in", l)
print('flyback_3.in is ready for execution')
flyback_3.in is ready for execution
Execute the following cell to run GSEIM on flyback_3.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("flyback_3.in")
os.system('run_gseim flyback_3.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = flyback_3.in main: i_solve = 0 main: calling solve_trns Transient simulation starts... i=0 i=10000 i=20000 GSEIM: Program completed.
Out[4]:
0
The circuit file (flyback_3.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on flyback_3.in) creates a data file called flyback_3.dat in the same directory. We can now use the python code below to compute/plot the various quantities of interest.
In [5]:
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("flyback_3.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_ILm = slv.get_index(i_slv,i_out,"ILm" )
col_ip = slv.get_index(i_slv,i_out,"ip" )
col_is = slv.get_index(i_slv,i_out,"is" )
col_ID1 = slv.get_index(i_slv,i_out,"ID1" )
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
ip_net = u[:,col_ILm] + u[:,col_ip]
ip_net_max = max(ip_net)
print('peak primary current (including ILm:',
"%11.4E"%(ip_net_max), 'A')
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, "V")
ndiv = 5000
n_ID1 = 0
delt_ID1, ID1p = calc.interp_linear_1(t, u[:,col_ID1], ndiv)
for k in range(ndiv):
if (ID1p[k] > 0): n_ID1 += 1
print('duration of conduction for D1 in one cycle:',
"%11.4E"%(1.0e6*float(n_ID1)*delt_ID1/(2.0)), 'micro seconds.')
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
color5='cornflowerblue'
color6='red'
fig, ax = plt.subplots(6, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(7, 9, ax[0])
for i in range(6):
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_ip ], color=color1, linewidth=1.0, label="$i_p$")
ax[1].plot(t*1e6, u[:,col_ILm ], color=color2, linewidth=1.0, label="$i_{Lm}$")
ax[2].plot(t*1e6, ip_net, color=color3, linewidth=1.0, label="$i_p^{net}$")
ax[3].plot(t*1e6, u[:,col_is ], color=color4, linewidth=1.0, label="$i_s$")
ax[4].plot(t*1e6, u[:,col_v_out], color=color5, linewidth=1.0, label="$V_o$")
ax[5].plot(t*1e6, u[:,col_ID1 ], color=color6, linewidth=1.0, label="$i_{D1}$")
ax[0].set_ylabel(r'$i_p$' , fontsize=14)
ax[1].set_ylabel(r'$i_{Lm}$' , fontsize=14)
ax[2].set_ylabel(r'$i_p^{net}$', fontsize=14)
ax[3].set_ylabel(r'$i_s$' , fontsize=14)
ax[4].set_ylabel(r'$V_o$' , fontsize=14)
ax[5].set_ylabel(r'$i_{D1}$' , fontsize=14)
ax[5].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(5):
ax[i].tick_params(labelbottom=False)
#plt.tight_layout()
plt.show()
filename: flyback_3.dat peak primary current (including ILm: 4.9898E+00 A peak-to-peak ripple in Vo: 5.6039E-01 V duration of conduction for D1 in one cycle: 6.4211E+00 micro seconds.
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: