• ## Flag Counter

### 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.

c
code program is shown below:
------------------------------------------------------------------------------------------------
#include <
math.h>

__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.;

double
err;

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.

### How to use PSIM dll

This time we will learn how to use dll block in PSIM. Other software we need is C/C++ Compiler such as Borland, Dev, MinGW, etc.. You can get it free by searching on Google. In this tutorial we'll use free distributed MinGW C Compiler.

On MinGW window, click Project and select New Project as shown in the picture below!

After the following window appear, select Win32 Dynamic Link Library. Choose your Project name for example 'test' and store it on D:\test\. Test is our folder on drive D:\ which will contain PSIM file, *.dll, and c code.

Run PSIM program and open 'custom dll' folder in the PSIM example. Select dll-rms.sch and save as on folder D:\test\.. You can save it as test.sch or another. Copy msvc_dll.c from custom dll file to D:\test\.

On MinGW window, right click Source File and click Add Source files to project as shown below.

Open D:\test\ and click msvc_dll.c.

After that, click Source File and double click msvc_dll.c. C code will appear on your MinGW screen like the picture below. Now build or compile it. If use MinGW you can prees F7 button on your keyboard as a shortcut to build it.

Now let us back to PSIM and double click DLL block to change its name. Type test.dll.

If you succeed to compile your c code, there will be debug folder. Open it and copy paste test.dll file to test folder as shown picture below.

Finally, run PSIM you'll get simulation result as shown below. You can create your own dll block for example PI control in dll or another.
Good Luck!

### Introduction to the PSIM Software

The first article of my blog is the introduction of PSIM software. PSIM is a simulation software developed by PSIM is designed for power electronics, motor control, and simulation of dynamic systems. The following add-on Modules are provided for PSIM:

 - Motor Drive Module: For electric motor drive - Digital Control Module: For analysis of digital control systems in z-domain - SimCoupler Module: For co-simulation with Matlab/Simulink - Thermal Module: For loss calculation and thermal analysis of switching devices - MagCoupler Module: For dynamic link with finite element analysis software JMAG - MagCoupler-RT Module: For link with JMAG-RT data files - SimCoder Module: For automatic code generation for specific DSP hardware

In addition, PSIM supports links to third-party software through custom DLL blocks.

The overall PSIM environment is shown as follows:

Some add-on modules doesn't exist in previous versions.

-
The Index is added to both the PSIM and SimCoder User Manuals, network licenses can have the license manager run either as an application or a service, and in metafile images, the quality of text in schematic files is greatly improved.
-
A key new feature of Version 8 is the SimCoder Module. With SimCoder, one can simulate a system in PSIM first, then generate C code automatically for specific DSP hardware.