PI control using PSIM dll

Control technique using PI is commonly use in power electronic. Here is a sample how to implement PI control in PSIM dll block. We will use it to control output current of Buck DC-DC conventer.

Actually PSIM has provided PI block itself. PI can write mathematically base on the picture below:

The controller output is given by
K_P \Delta + K_I \int \Delta\,dt

where Δ is the error or deviation of actual measured value (PV) from the set-point (SP).

Δ = SP - PV
Key point here is how generate the c code program as sum of error(Δ) times the proportional constant and integral constant times the integration of the error.

code program is shown below:
#include <

__declspec(dllexport) void simuser (t, delt, in, out)

// Note that all the variables must be defined as "double"
double t, delt;
double *in, *out;


static double Kp= 4.,T =2.28e-4, diff=0., integ = 0., erprev = 0., temp = 0;
static d
ouble iMax = 0., iMin = 0.0;
static double
oMax = 1., oMin = 0.;


iMax = T/Kp;
err = in[0];
integ = integ + (err*delt);

if(integ > iMax)
integ = iMax;
else if (iMin > integ)
integ = iMin;

temp = (Kp*err) + (Kp*integ/T) ;
if(temp > oMax)
temp = oMax;
else if (oMin > temp)
temp = oMin;

out[0] = temp ;
erprev = err;


Here is a sample circuit and
simulation result using PSIM. Dll block act as PI control to control output current of buck dc-dc conventer.

i. Buck Circuit

ii. output current

You can compare it with PSIM PI block with same parameters.

Bookmark and Share


Post a Comment