# Using Python for the Simulation of a Closed-Loop PI Controller for a Buck Converter

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Simulation of the Open-Loop Operation

#### 2.1. Stage I—Conduction State

#### 2.2. Stage II—Non-Conduction State

_{in}, R

_{L}, L, R

_{S}, V

_{d}, R

_{d}, C, ESR, R

_{Load}, i

_{L}, i

_{C}, i

_{O}, v

_{O}and v

_{C}, represent the input voltage, inductor resistance, inductor inductance, drain-source resistance, diode forward voltage drop, diode internal resistance, capacitor capacitance, capacitor internal resistance, load resistance, inductor current, capacitor current, load current, output voltage and output voltage component due exclusively to C, respectively.

#### 2.3. Open-Loop Simulation

_{L}, i

_{C}, v

_{C}and v

_{O}values during the conduction state (Figure 4) and during the non-conducting state (Figure 5).

_{0}, the sampling period, PA, the characteristics of the converter (V

_{in}, R

_{S}, L, ESR, C and R

_{Load}) and the initial conditions (the inductor current, i

_{L0}, and capacitor voltage, v

_{C0}, at the initial time).

_{L}, v

_{C}, i

_{C}and v

_{O}represent the vectors referring to the following quantities: time, inductor current, output voltage component due exclusively to C, capacitor current and output voltage, respectively.

## 3. Power-Stage Design Process

- Converter is operating in steady-state regime (V
_{in}> V_{O}); - Average voltage across inductor is zero (〈v
_{L}〉 = 0); - Average current through capacitor is zero (〈i
_{C}〉 = 0); - All components are considered ideal;
- Capacitor capacitance is large enough.

_{in}, V

_{O}, v

_{LON}, Δi

_{L}, D, T, f, v

_{M}, i

_{M}, i

_{D}and v

_{D}represent the input voltage, mean value of output voltage, voltage across the inductor during the conduction state, inductor current ripple, duty cycle, switching period, switching frequency, MOSFET voltage, MOSFET current, diode current and diode voltage, respectively.

- Maximum voltage value across both Di and M is equal to V
_{in}(minimum voltage rating). - Peak current through Di and M is equal to maximum inductor peak current (minimum current rating).

_{Load}), it is possible to conclude that the AC component of the inductor current is equal to the capacitor current. In this way, it is possible to write:

_{critical}) as:

_{L}(ΔiL

_{Max}). In this case, Equation (5) can be used.

## 4. Simulation of the Closed-Loop Operation

## 5. Comparison—Proposed Technique versus LTspice

_{O}, i

_{L}, i

_{C}, and v

_{ctrl}obtained in LTspice (left plots) and also with the proposed simulation technique (right plots).

_{O}), inductor current (i

_{L}), capacitor current (i

_{C}) and control voltage (v

_{ctrl}) obtained with the proposed technique and in LTspice. v

_{ctrl}shows a slight difference between both simulations, which is essentially due to the time taken by the MOSFET to switch. This time period is not taken into account in Python simulation.

## 6. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## References

- Jung, G.; Hosani, K.; Song, B.; Seo, D.; Kim, J.; Cho, D. Semi-Dynamic Wireless Power Charging System for Autonomous Electric Vehicle. In Proceedings of the 2021 IEEE Wireless Power Transfer Conference, San Diego, CA, USA, 1–4 June 2021. [Google Scholar]
- Mohammad, K.; Rashid, M.F.; Rahat, H.; Khan, F.; Rahman, K. Detailed Analysis of DC-DC Converters Fed with Solar-PV System with MPPT. In Proceedings of the 2022 International Conference for Advancement in Technology, Goa, India, 21–22 January 2022. [Google Scholar]
- Dias, N.; Naik, A.J. Design, Modeling and Simulation of Bidirectional Buck and Boost Converter for Electric Vehicles. In Proceedings of the 2022 International Conference for Advancement in Technology, Goa, India, 21–22 January 2022. [Google Scholar]
- Jeelani, N.; Bhat, A.H.; Mir, T.N. Comparative Analysis of Voltage Control Techniques for Single Phase AC-AC Buck Converter. In Proceedings of the 2022 IEEE International Conference on Power Electronics, Smart Grid, and Renewable Energy, Trivandrum, India, 2–5 January 2022. [Google Scholar]
- Chapparya, V.; Singh, S.P.; Dey, A. Novel Non-isolated Boost-Zeta Interleaved DC-DC Converter for Low Voltage Bipolar DC Micro-grid Application. In Proceedings of the 2022 IEEE International Conference on Power Electronics, Smart Grid, and Renewable Energy, Trivandrum, India, 2–5 January 2022. [Google Scholar]
- Stala, R.; Waradzyn, Z.; Folmer, S. Input Current Ripple Reduction in a Step-Up DC–DC Switched-Capacitor Switched-Inductor Converter. IEEE Access
**2022**, 10, 19890–19904. [Google Scholar] [CrossRef] - Andries, V.; Goras, L.; Buzo, A.; Pelz, G. Automatic tuning for a DC-DC Buck Converter with adaptive controller. In Proceedings of the 2017 International Symposium on Signals, Circuits and Systems, Iasi, Romania, 13–14 July 2017. [Google Scholar]
- Prag, K.; Woolway, M.; Celik, T. Data-Driven Model Predictive Control of DC-to-DC Buck-Boost Converter. IEEE Access
**2021**, 9, 101902–101915. [Google Scholar] [CrossRef] - Andino, J.; Ayala, P.; Llanos-Proaño, J.; Naunay, D.; Martinez, W.; Arcos-Aviles, D. Constrained Modulated Model Predictive Control for a Three-Phase Three-Level Voltage Source Inverter. IEEE Access
**2022**, 10, 10673–10687. [Google Scholar] [CrossRef] - Nupur, N.; Nath, S. Effect of Coupling on Discontinuous Conduction Mode of Coupled Inductor SIDO Boost Converter. IEEE Trans. Power Electron.
**2022**, 37, 4991–5002. [Google Scholar] [CrossRef] - Navamani, J.D.; Geetha, A.; Almakhles, D.; Lavanya, A.; Ali, J.S. Modified LUO High Gain DC-DC Converter With Minimal Capacitor Stress for Electric Vehicle Application. IEEE Access
**2021**, 9, 122335–122350. [Google Scholar] [CrossRef] - Castiglia, V.; Campagna, N.; Tommaso, A.; Miceli, R.; Nevoloso, C.; Pellitteri, F.; Puccio, C.; Viola, F. Modeling, Simulation, and Characterization of a Supercapacitor in Automotive Applications. IEEE Trans. Ind. Appl.
**2022**, 58, 2421–2429. [Google Scholar] [CrossRef] - Khader, S.; Hadad, A.; Abu-aisheh, A.A. The application of PSIM & Matlab/Simulink in power electronics courses. In Proceedings of the 2011 IEEE Global Engineering Education Conference, Amman, Jordan, 4–6 April 2011. [Google Scholar]
- Showers, O.; Raji, A. Modelling and Simulation of Fuel Cell Hybrid Electric Vehicle Powertrain. In Proceedings of the 30th Southern African Universities Power Engineering Conference, Durban, South Africa, 25–27 January 2022. [Google Scholar]
- Ranjani, J.; Sheela, A.; Meena, K.P. Combination of NumPy, SciPy and Matplotlib/Pylab-a good alternative methodology to MATLAB-A Comparative analysis. In Proceedings of the 1st International Conference on Innovations in Information and Communication Technology, Chennai, India, 25–26 April 2019. [Google Scholar]
- Janarthanam, K.; Kamalesk, P.; Basil, V.; Judeson, J. Electrical Faults-Detection and Classification using Machine Learning. In Proceedings of the International Conference on Electronics and Renewable Systems, Tuticorin, India, 16–18 March 2022. [Google Scholar]
- Khond, S.; Kale, V.; Ballal, M. A combined Data Mining and Machine Learning approach for High Impedance Fault Detection in Microgrids. In Proceedings of the IEEE International Conference on Power Electronics, Smart Grid, and Renewable Energy, Trivandrum, India, 2–5 January 2022. [Google Scholar]
- Sun, Q.; Wang, Y.; Jiang, Y. A Novel Fault Diagnostic Approach for DC-DC Converters Based on CSA-DBN. IEEE Access
**2018**, 6, 6273–6285. [Google Scholar] [CrossRef] - Amaral, A.; Sahraqui, M. Capacitors. In Diagnosis and Fault Tolerance of Electrical Machines Power Electronics and Drives; Chapter 5; Cardoso, A.J.M., Ed.; IET-The Institution of Engineering and Technology: London, UK, 2018; pp. 195–286. [Google Scholar]
- Xia, Y.; Xu, Y. A Transferrable Data-Driven Method for IGBT Open-Circuit Fault Diagnosis in Three-Phase Inverters. IEEE Trans. Power Electron.
**2021**, 36, 13478–13488. [Google Scholar] [CrossRef] - Li, Z.; Gao, Y.; Zhang, X.; Wang, B.; Ma, H. A Model-Data-Hybrid-Driven Diagnosis Method for Open-Switch Faults in Power Converters. IEEE Trans. Power Electron.
**2021**, 36, 4965–4970. [Google Scholar] [CrossRef] - Zhao, M.; Li, M.; Song, S.; Hu, Y.; Yao, Y.; Bai, X.; Hu, R.; Wu, X.; Tan, Z. An Ultra-Low Quiescent Current Tri-Mode DC-DC Buck Converter With 92.1% Peak Efficiency for IoT Application. IEEE Trans. Circuits Syst.
**2022**, 69, 428–439. [Google Scholar] [CrossRef] - Malik, M.S.; Khan, H.A.; Zaffar, N.A. Evaluation of a Single Inductor based Single-Input Dual-Output Buck Converter for DC Microgrid Applications. In Proceedings of the IEEE 7th World Conference on Photovoltaic Energy Conversion, Waikoloa, HI, USA, 10–15 June 2018. [Google Scholar]
- Garg, A.; Das, M. High Efficiency Three Phase Interleaved Buck Converter for Fast Charging of EV. In Proceedings of the 1st International Conference on Power Electronics and Energy, Bhubaneswar, India, 2–3 January 2021. [Google Scholar]
- Venkatramanan, D.; John, V. Dynamic Modeling and Analysis of Buck Converter Based Solar PV Charge Controller for Improved MPPT Performance. IEEE Trans. Ind. Appl.
**2019**, 55, 6234–6246. [Google Scholar] [CrossRef] - Amaral, A.M.R.; Cardoso, A.J.M. A Simple Offline Technique for Evaluating the Condition of Aluminum–Electrolytic–Capacitors. IEEE Trans. Ind. Electron.
**2009**, 56, 3230–3237. [Google Scholar] [CrossRef]

**Figure 4.**Function that models the behavior of the converter during the on state: (

**a**) Algorithm and (

**b**) Python code.

**Figure 5.**Function that models the behavior of the converter during the off state: (

**a**) Algorithm and (

**b**) Python code.

**Figure 11.**Waveforms of v

_{O}, i

_{L}, i

_{C}and v

_{ctrl}obtained in steady-state regime, with LTspice (

**left plots**) and with the proposed simulation technique (

**right plots**).

**Figure 12.**Waveforms of v

_{O}, i

_{L}, i

_{C}and v

_{ctrl}obtained during the converter start up, with LTspice (

**left plots**) and with the proposed simulation technique (

**right plots**).

**Figure 13.**Waveforms of v

_{O}, i

_{L}, i

_{C}and v

_{ctrl}obtained during a load variation (from 5 A to 10 A) at 35 ms, with LTspice (

**left plots**) and with the proposed simulation technique (

**right plots**).

**Figure 14.**Waveforms of v

_{O}, i

_{L}, i

_{C}and v

_{ctrl}obtained during an input voltage variation (from 19 V to 9 V) at 35 ms, with LTspice (

**left plots**) and with the proposed simulation technique (

**right plots**).

Input Voltage | Output Voltage | Load Range | Output Voltage Ripple (Δv _{O}) | Inductor Ripple Current (Δi _{L}) | Operating Frequency |
---|---|---|---|---|---|

19 V | 5 V | 5 W to 50 W | 5 mV | 40% of I_{O} | 100 kHz |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Amaral, A.M.R.; Cardoso, A.J.M.
Using Python for the Simulation of a Closed-Loop PI Controller for a Buck Converter. *Signals* **2022**, *3*, 313-325.
https://doi.org/10.3390/signals3020020

**AMA Style**

Amaral AMR, Cardoso AJM.
Using Python for the Simulation of a Closed-Loop PI Controller for a Buck Converter. *Signals*. 2022; 3(2):313-325.
https://doi.org/10.3390/signals3020020

**Chicago/Turabian Style**

Amaral, Acacio M. R., and Antonio J. Marques Cardoso.
2022. "Using Python for the Simulation of a Closed-Loop PI Controller for a Buck Converter" *Signals* 3, no. 2: 313-325.
https://doi.org/10.3390/signals3020020