Buck Converter: DCM
The periodic current (with a period of $100\,\mu$s) through the inductor of a buck converter is given below. The capacitor $C$ is large so that $V_o$ can be treated as constant. If the load resistance is $R=10\,\Omega$, find the input voltage $V_s$ and inductance $L$.from IPython.display import Image
Image(filename =r'buck_dcm_1_fig_1.png', width=700)
# run this cell to view the circuit file.
%pycat buck_dcm_1_orig.in
We now replace the strings \$Vin, \$L, \$C, \$R, \$D, \$f_hz with the values of our choice by running the python script given below. It takes an existing circuit file buck_dcm_1_orig.in and produces a new circuit file buck_dcm_1.in, after replacing \$L, \$C, \$R, \$D, \$f_hz with the values of our choice.
import gseim_calc as calc
s_Vin = '60' # to be changed by user
s_L = '200e-6' # to be changed by user
s_C = '50e-6'
s_R = '10'
s_D = '0.5'
s_f_hz = '10e3'
l = [
('$Vin', s_Vin),
('$L', s_L),
('$C', s_C),
('$R', s_R),
('$D', s_D),
('$f_hz', s_f_hz)
]
calc.replace_strings_1("buck_dcm_1_orig.in", "buck_dcm_1.in", l)
print('buck_dcm_1.in is ready for execution')
buck_dcm_1.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("buck_dcm_1.in")
os.system('run_gseim buck_dcm_1.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = buck_dcm_1.in Circuit: n_xbeu_vr = 1 Circuit: n_ebeu_nd = 4 main: i_solve = 0 ssw_allocate_1 (2): n_statevar=3 main: calling solve_trns mat_ssw_1_ex: n_statevar: 3 mat_ssw_1_e0: cct.n_ebeu: 6 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=0, rhs_ssw_norm=5.8854e+00 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=1, rhs_ssw_norm=4.7930e-01 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=2, rhs_ssw_norm=1.8537e-06 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=3, rhs_ssw_norm=1.0869e-09 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=4, rhs_ssw_norm=5.3115e-19 solve_ssw_ex: calling solve_ssw_1_ex for one more trns step Transient simulation starts... i=0 i=1000 solve_ssw_1_ex over (after trns step for output) solve_ssw_ex ends, slv.ssw_iter_newton=4 GSEIM: Program completed.
0
The circuit file (buck_dcm_1.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on buck_dcm_1.in) creates a data file buck_dcm_1.dat in the same directory. We can now use the python code below to view the inductor current as a function of time.
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("buck_dcm_1.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
col_IL = slv.get_index(i_slv,i_out,"IL")
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")
col_IR = slv.get_index(i_slv,i_out,"IR")
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_clock = slv.get_index(i_slv,i_out,"clock")
# 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_IL = calc.avg_rms_2(t, u[:,col_IL], 0.0, 2.0*T, 1.0e-3*T)
l_IS = calc.avg_rms_2(t, u[:,col_IS], 0.0, 2.0*T, 1.0e-3*T)
l_ID = calc.avg_rms_2(t, u[:,col_ID], 0.0, 2.0*T, 1.0e-3*T)
l_IC = calc.avg_rms_2(t, u[:,col_IC], 0.0, 2.0*T, 1.0e-3*T)
l_IR = calc.avg_rms_2(t, u[:,col_IR], 0.0, 2.0*T, 1.0e-3*T)
l_v_out = calc.avg_rms_2(t, u[:,col_v_out], 0.0, 2.0*T, 1.0e-3*T)
t_IL = np.array(l_IL[0])
t_IS = np.array(l_IS[0])
t_ID = np.array(l_ID[0])
t_IC = np.array(l_IC[0])
t_IR = np.array(l_IR[0])
t_v_out = np.array(l_v_out[0])
print('average output voltage:' , "%11.4E"%l_v_out[1][0])
print('average switch current:' , "%11.4E"%l_IS[1][0])
print('average diode current:' , "%11.4E"%l_ID[1][0])
print('average load current:' , "%11.4E"%l_IR[1][0])
print('average inductor current:', "%11.4E"%l_IL[1][0])
print('rms inductor current:' , "%11.4E"%l_IL[2][0])
l1 = calc.min_max_1(t, u[:,col_IL], 0.0, 2.0*T)
IL_ptop = l1[1] - l1[0]
print('IL_ptop:', "%11.4E"%IL_ptop)
fig, ax = plt.subplots(7, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(6.5, 10, ax[0])
for i in range(7):
ax[i].set_xlim(left=0.0, right=2.0*T*1e6)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
for i in range(6):
ax[i].tick_params(labelbottom=False)
ax[0].set_ylabel(r'clock', fontsize=12)
ax[1].set_ylabel(r'$i_L$', fontsize=12)
ax[2].set_ylabel(r'$i_C$', fontsize=12)
ax[3].set_ylabel(r'$i_D$', fontsize=12)
ax[4].set_ylabel(r'$i_S$', fontsize=12)
ax[5].set_ylabel(r'$i_R$', fontsize=12)
ax[6].set_ylabel(r'$v_o$', fontsize=12)
ax[0].set_ylim(bottom=-0.2, top=1.2)
ax[0].set_yticks([0.0, 1.0])
color1 = "blue"
color2 = "tomato"
color3 = "dodgerblue"
color4 = "olive"
color5 = "green"
color6 = "red"
color7 = "darkcyan"
ax[0].plot(t*1e6, u[:,col_clock], color=color1, linewidth=1.0, label="clock")
ax[1].plot(t*1e6, u[:,col_IL], color=color2, linewidth=1.0, label="$i_L$")
ax[1].plot(t_IL*1e6, l_IL[1] , color=color2, linewidth=1.0, label="$i_L^{avg}$", linestyle='--', dashes=(5,3))
ax[2].plot(t*1e6, u[:,col_IC], color=color3, linewidth=1.0, label="$i_C$")
ax[2].plot(t_IC*1e6, l_IC[1] , color=color3, linewidth=1.0, label="$i_C^{avg}$", linestyle='--', dashes=(5,3))
ax[3].plot(t*1e6, u[:,col_ID], color=color4, linewidth=1.0, label="$i_D$")
ax[3].plot(t_ID*1e6, l_ID[1] , color=color4, linewidth=1.0, label="$i_D^{avg}$", linestyle='--', dashes=(5,3))
ax[4].plot(t*1e6, u[:,col_IS], color=color5, linewidth=1.0, label="$i_S$")
ax[4].plot(t_IS*1e6, l_IS[1] , color=color5, linewidth=1.0, label="$i_S^{avg}$", linestyle='--', dashes=(5,3))
ax[5].plot(t*1e6, u[:,col_IR], color=color6, linewidth=1.0, label="$i_R$")
ax[5].plot(t_IR*1e6, l_IR[1] , color=color6, linewidth=1.0, label="$i_R^{avg}$", linestyle='--', dashes=(5,3))
ax[6].plot(t*1e6, u[:,col_v_out] , color=color7, linewidth=1.0, label="$v_o$")
ax[6].plot(t_v_out*1e6, l_v_out[1], color=color7, linewidth=1.0, label="$v_o^{avg}$", linestyle='--', dashes=(5,3))
ax[6].set_xlabel('time ($\mu$sec)', fontsize=12)
for i in range(1,7):
ax[i].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12})
#plt.tight_layout()
plt.show()
filename: buck_ccm_7.dat average output voltage: 3.2496E+01 average switch current: 1.7615E+00 average diode current: 1.4881E+00 average load current: 3.2496E+00 average inductor current: 3.2496E+00 rms inductor current: 3.9073E+00 IL_ptop: 7.0295E+00
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.