Buck Converter: CCM
The buck converter given below is switched at $20\,$kHz and at a duty ratio of 0.5 with a load resistance of $1\,\Omega$. The input voltage to the buck converter is $10\,$V. The inductor is $100\,\mu$H with an ESR of $100\,$m$\Omega$, and the output capacitator is $1000\,\mu$F. The on-state resistance of the switch $S$ is $25\,$m$\Omega$, and the on-state drop across the diode is $0.8\,$V.Evaluate the following quantities:
- output voltage
- average input current
- output power
- efficiency
- average power dissipated in the switch, diode, and inductor
from IPython.display import Image
Image(filename =r'buck_ccm_2_fig_1.png', width=350)
# run this cell to view the circuit file.
%pycat buck_ccm_2_orig.in
We now replace the strings such as \$Vin, \$L, with the values of our choice by running the python script given below. It takes an existing circuit file buck_ccm_2_orig.in and produces a new circuit file buck_ccm_2.in, after replacing \$Vin, \$L, etc. with values of our choice.
import gseim_calc as calc
s_Vin = '10'
s_L = '100u'
s_ESR = '100m'
s_R_sw = '25m'
s_V_D = '0.8'
s_R_load = '1'
s_f_hz = '20k'
s_D = '0.5'
l = [
('$Vin', s_Vin),
('$L', s_L),
('$ESR', s_ESR),
('$R_load', s_R_load),
('$V_D', s_V_D),
('$R_sw', s_R_sw),
('$f_hz', s_f_hz),
('$D', s_D)
]
calc.replace_strings_1("buck_ccm_2_orig.in", "buck_ccm_2.in", l)
print('buck_ccm_2.in is ready for execution')
buck_ccm_2.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("buck_ccm_2.in")
os.system('run_gseim buck_ccm_2.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = buck_ccm_2.in Circuit: n_xbeu_vr = 1 Circuit: n_ebeu_nd = 5 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: 7 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=0, rhs_ssw_norm=2.4145e+00 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=1, rhs_ssw_norm=2.1024e-14 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=2, rhs_ssw_norm=1.1538e-14 Transient simulation starts... i=0 i=1000 solve_ssw_ex: ssw_iter_newton=3, rhs_ssw_norm=6.1535e-15 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=3 GSEIM: Program completed.
0
The circuit file (buck_ccm_2.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on buck_ccm_2.in) creates two data files buck_ccm_2.dat and buck_ccm_2_1.dat in the same directory. We can now use the python code below to 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("buck_ccm_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*1e6 # convert time to micro-seconds
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_v_in = slv.get_index(i_slv,i_out,"v_in")
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_v_out = calc.avg_rms_2(t, u[:,col_v_out], 0.0, 2.0*T, 1.0e-3*T)
print('average output voltage:', "%11.4E"%l_v_out[1][0])
print('average input current:', "%11.4E"%l_IS[1][0])
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(4, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
# comment out lines for variables which should not be shown
ax.plot(t, u[:,col_IL], color=color1, linewidth=1.0, label="$I_L$")
ax.plot(l_IL[0], l_IL[1], color=color1, linewidth=1.0, label="$I_L^{avg}$", linestyle='--', dashes=(5,3))
ax.plot(l_IL[0], l_IL[2], color=color1, linewidth=1.0, label="$I_L^{rms}$", linestyle='-.')
#ax.plot(t, x[col_IS-1], color=color2, linewidth=1.0, label="$I_S$")
#ax.plot(t, x[col_ID-1], color=color3, linewidth=1.0, label="$I_D$")
#ax.plot(t, x[col_IC-1], color=color4, linewidth=1.0, label="$I_C$")
plt.xlabel('time (' + r'$\mu$' + 'sec)', fontsize=11)
ax.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_2.dat average output voltage: 4.1320E+00 average input current: 2.0676E+00
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("buck_ccm_2.in")
i_slv = 0
i_out = 1
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t1 = u[:, 0]
t = t1*1e6 # convert time to micro-seconds
col_P_VS = slv.get_index(i_slv,i_out,"P_VS")
col_P_ESR = slv.get_index(i_slv,i_out,"P_ESR")
col_P_S = slv.get_index(i_slv,i_out,"P_S")
col_P_D = slv.get_index(i_slv,i_out,"P_D")
col_P_R = slv.get_index(i_slv,i_out,"P_R")
# 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_P_VS = calc.avg_rms_2(t, u[:,col_P_VS], 0.0, 2.0*T, 1.0e-3*T)
l_P_ESR = calc.avg_rms_2(t, u[:,col_P_ESR], 0.0, 2.0*T, 1.0e-3*T)
l_P_S = calc.avg_rms_2(t, u[:,col_P_S], 0.0, 2.0*T, 1.0e-3*T)
l_P_D = calc.avg_rms_2(t, u[:,col_P_D], 0.0, 2.0*T, 1.0e-3*T)
l_P_R = calc.avg_rms_2(t, u[:,col_P_R], 0.0, 2.0*T, 1.0e-3*T)
print('average power (VS):', "%11.4E"%l_P_VS[1][0])
print('average power (ESR):', "%11.4E"%l_P_ESR[1][0])
print('average power (switch):', "%11.4E"%l_P_S[1][0])
print('average power (diode):', "%11.4E"%l_P_D[1][0])
print('average power (load):', "%11.4E"%l_P_R[1][0])
print('efficiency:', "%11.4E"%(l_P_R[1][0]/l_P_VS[1][0]))
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(4, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax.plot(t, u[:,col_P_R], color=color1, linewidth=1.0, label="$P_{R}$")
ax.plot(l_P_R[0], l_P_R[1], color=color1, linewidth=1.0, label="$P_{R}^{avg}$", linestyle='--', dashes=(5,3))
plt.xlabel('time (' + r'$\mu$' + 'sec)', fontsize=11)
ax.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_2_1.dat average power (VS): 2.0676E+01 average power (ESR): 1.7223E+00 average power (switch): 2.1565E-01 average power (diode): 1.6601E+00 average power (load): 1.7074E+01 efficiency: 8.2576E-01
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.