This technical note presents a possible current control implementation for power converters.

First, the note introduces the general operating principles of a simple Proportional-Integral controller. Then, an example of current control for a boost converter is provided.

Finally, a practical control implementation is introduced, targeting the B-Box RCP or B-Board PRO with both C/C++ and automated code generation approaches.

Software resources

  File Modified
File Boost_PlecsViewer_2015a.slx Simulink file, Matlab 2015a with Plecs Viewer Apr 07, 2020 by Gabriel Fernandez
File Boost.slx Original Simulink file, Matlab 2017a and Plecs blockset are required. Apr 07, 2020 by Gabriel Fernandez
Text File parameters.m Matlab file containing all the parameters of the system. Apr 07, 2020 by Gabriel Fernandez

General principles

PI controllers are widely used in power electronics, thanks to their simple structure and implementation. They are very frequently used to control constant or slowly-varying quantities, e.g. in direct current (DC) applications, as well as in AC applications together with coordinate transformations.

When implemented in a parallel form, a PI controller can be represented as shown below: 

In practice, Pi controllers constitute rather a family that can be extended to alternative configurations, e.g. :

DC current control example

The simplest and most obvious example of PI-base control is certainly given by the control of the inductor current within a boost-type converter.

In this system, basic circuit equations show that the inductor current is given by:

\begin{array}{l}\displaystyle R_b I_b + L_b \displaystyle\frac{d I_b}{dt} = V_L = V_b - V_c\end{array}

In the Laplace domain, this translates into:

\begin{array}{l}\displaystyle I_b = \displaystyle\frac{1}{R_b + s L_b} \cdot V_L\end{array}

System-level modeling

A widely-accepted model for the proposed system is shown below. Four distinct parts can be clearly identified.


The inductor is modeled as:

\begin{array}{l}P_1(s) = \displaystyle\frac{K_1}{1+s T_1} \qquad &\text{with} \qquad &\begin{cases}K_1 = 1/R_b \\ T_1 = L_b/R_b \end{cases}\end{array}


The measurements of the current \begin{array}{l}I_b\end{array}and the voltages \begin{array}{l}V_b\end{array}and \begin{array}{l}V_{dc}\end{array}are generally modeled using a low-pass filter approximation, or they are neglected. The sampling corresponds to a zero-order hold (ZOH) which introduces a lag, which is the sampling delay.


The control algorithm consists of a digital PI controller followed by some basic mathematic operations to compute the duty cycle. The whole algorithm requires a certain amount of computation time, which is represented as a delay.


The Pulse-Width Modulation (PWM) is also generally modeled as a simple delay.

Digital implementation

The three most common implementations [2] of the PI controller are the following:

\begin{aligned} C(z) &= K_p + K_i T_s \frac{1}{z-1} & \text{Forward Euler} \\ &= K_p + K_i T_s \frac{z}{z-1} & \text{Backward Euler} \\ &= K_p + K_i \frac{T_s}{2} \frac{z+1}{z-1} & \text{Tustin /Trapezoidal} \\ \end{aligned}

The parameter \begin{array}{l}T_s\end{array} correspond to the period of the interruption. The advantages/disadvantages of these different discretizations are well discussed in [1]. The Forward Euler will be used in this note, and the corresponding difference equation is given below.

\begin{aligned} y(k) &= P(k) + I(k) \\ P(k) &= K_p \cdot e(k) \\ I(k) &= I(k-1) + K_i \cdot T_s \cdot e(k-1) \end{aligned}

These equations can be easily used for generating run-time code.

Tuning and performance evaluation

Different methods are used in the literature to determine the parameters of a PI controller. Those methods are well detailed and explained in [1]. In this note, the Magnitude Optimum (MO) will be used.

The goal of the MO is to make the frequency response from reference to the plant output as close to one as possible for low frequencies. The controller parameters are defined as:

\begin{aligned} &T_n = T_1 \\ &T_i = 2 K_1 T_d\\ & \text{and}\\ &K_p = T_n /T_i \\ &K_i = 1 / T_i \end{aligned}

The parameter \begin{array}{l}T_d\end{array} represents the sum of all the small delays in the system, such as the sampling delay or the modulation delay mentioned above. The product note PN142: Time delay determination for closed-loop control explains how to determine the total delay of the system.

Academic references

[1] Karl J. Åström and Tore Hägglund; “Advanced PID Control”; 1995
[2] Dew Toochinda; "Discrete-time PID Controller Implementation";; 2015

B-Box / B-Board implementation

C/C++ code

The imperix IDE provides numerous pre-written and pre-optimized functions. Controllers such as P, PI, PID and PR are already available and can be found in the controllers.h/.cpp files.

As for all controllers, PI controllers are based on:

  • A pseudo-object PIDcontroller, which contains pre-computed parameters as well as state variables.

  • A configuration function, meant to be called during UserInit(), named ConfigPIDController().

  • A run-time function, meant to be called during the user-level ISR, such as UserInterrupt(), named RunPIController().

Implementation example

#include "../API/controllers.h"
PIDController mycontroller;

float Kp = 13.64;
float Ki = 120.00;
float limup = 500;
float limlow = -500;

tUserSafe UserInit(void)
  	//... some code
	ConfigPIDController(&mycontroller, Kp, Ki, 0, limup, limlow, SAMPLING_PERIOD, 0);
	//... some code
	return SAFE;
tUserSafe UserInterrupt(void)
	//... some code
	UL_ref = RunPIController(&mycontroller, Ib_ref - Ib);
	//... some code
	return SAFE;

Simulink implementation

The enclosed file provides an implementation example of the whole control loop, including a PI controller. Of course, the standard "Discrete PID Controller" block can also be used.

Implementation using Simulink. The plant model can be modeled using PLECS blockset or Simscape Power Systems.

PLECS implementation

The included file for PLECS also provides a PI block. The default PI block of the PLECS library can also be used.

Implementation using PLECS standalone. The plant model can be launched into the RT-Box.


The PI current control was tested in the case of a boost converter connected to a resistive load.

A current reference step was performed in both simulation (with Simulink) and experimental modes. The following graph shows a comparison between both results: