0% found this document useful (0 votes)
76 views10 pages

Skip

The document describes an incomplete code for a 3-level NPC inverter PSIM simulation that implements space vector pulse width modulation (SVPWM), a phase locked loop (PLL), and is written in C programming. It includes the basic circuit, PSIM circuit diagram, simulation results, and an incomplete C code with function declarations for the transformation, current control, switching, and PLL algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views10 pages

Skip

The document describes an incomplete code for a 3-level NPC inverter PSIM simulation that implements space vector pulse width modulation (SVPWM), a phase locked loop (PLL), and is written in C programming. It includes the basic circuit, PSIM circuit diagram, simulation results, and an incomplete C code with function declarations for the transformation, current control, switching, and PLL algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

(Need code) PSIM simulation : 3-level NPC inverter(SVPWM, PLL, C programming)

I need code to get that result. and There is an incomplete code.

Could you complete the code?

1. Basic Circuit

2.PSIM circuit
3. Result
4. incomplete code

void transform();
void current_control();
void in_transform();
void sw();
double V_grid_ab = 0., V_grid_bc = 0., V_grid_ca = 0.;
double V_grid_a = 0., V_grid_b = 0., V_grid_c = 0.;
double wc = 0., zeta = 0.7, wn = 200;
double V_grid_ds = 0., V_grid_qs = 0.;
double V_grid_de = 0., V_grid_qe = 0.;
double V_grid_m = 0.;
double V_grid_de_err = 0., V_grid_de_err_int = 0.;
double kp_PLL = 0., ki_PLL = 0.;
double wrate = 0., we = 0.;

__declspec(dllexport) void simuser(double t, double dt, double *in, double *out)


{
T_cnt += dt;

car = in[0];
i_a_in = in[1];
i_b_in = in[2];
i_c_in = in[3];
dc_link = in[4];
car_u = in[5];
car_d = in[6];

V_grid_ab = in[7];
V_grid_bc = in[8];
V_grid_ca = in[9];

if (t < 0.2) { i_de_in_ref = 0., i_qe_in_ref = 10.; }


else if (t < 0.3) { i_de_in_ref = 0., i_qe_in_ref = 20.; }
else { i_de_in_ref = 0., i_qe_in_ref = 10.; }

if (T_cnt >= T_amp)


{

V_grid_a = (V_grid_ab - V_grid_ca) * 0.333333333;


V_grid_b = (V_grid_bc - V_grid_ab) * 0.333333333;
V_grid_c = -(V_grid_a + V_grid_b);

wc = 1. + 2. * zeta*wn;

V_grid_ds = (2.*V_grid_a - V_grid_b - V_grid_c) / 3.;


V_grid_qs = (V_grid_b - V_grid_c) / sqrt(3.);

V_grid_de = V_grid_ds*cos(theta) + V_grid_qs*sin(theta);


V_grid_qe = -V_grid_ds*sin(theta) + V_grid_qs*cos(theta);

V_grid_m = sqrt(V_grid_de*V_grid_de + V_grid_qe*V_grid_qe);

V_grid_de_err = 0. - V_grid_de;
V_grid_de_err_int += V_grid_de_err*T_samp;
kp_PLL = 2. * zeta*wn / (V_grid_m + 0.0000001);
ki_PLL = (wn*wn) / ((V_grid_m + 0.00000001)*wc);

wrate = 2. * pi*f;

we = kp_PLL*V_grid_de_err + ki_PLL*V_grid_de_err_int + wrate;

f = 60.;

theta += we*T_samp;
if (theta < 0.) { theta += 2.*pi; }
if (theta > 2.*pi) { theta -= 2.*pi; }

i_ds_in = (2.*i_a_in - i_b_in - i_c_in) / 3.;


i_qs_in = (1. / sqrt(3.))*(i_b_in - i_c_in);

L_f = 0.002;
R_f = 0.1;
wc_i = 1000.;

p_gain_i = L_f * wc_i;


i_gain_i _ R_f * wc_i;

i_de_in_err = i_de_in_ref - T_de_in;


i_qe_in_err = i_qe_in_ref - i_qe_in;

i_de_err_int += i_de_in_err * T_samp;


i_qe_err_int += i_qe_in_err * T_samp;

v_de_ref = p_gain_i * i_de_in_err + i_gain_i * i_de_err_int;


v_qe_ref = p_gain_i * i_qe_in_err + i_gain_i * i_qe_err_int;

v_ds_ref = v_de_ref * cos(theta) - v_qe_ref * sin(theta);


v_qs_ref = v_de_ref * sin(theta) + v_qe_ref * cos(theta);

v_a_ref = v_ds_ref;
v_b_ref = (-1.*v_ds_ref + sqrt(3.)*v_qs_ref) / 2.;
v_c_ref = (-1.*v_ds_ref - sqrt(3.)*v_qs_ref) / 2.;

v_a_ref_scale = (v_a_ref / dc_link) + 0.5;


v_b_ref_scale = (v_b_ref / dc_link) + 0.5;
v_c_ref_scale = (v_c_ref / dc_link) + 0.5;

T_cnt -= T_samp;
}
if (v_a_ref_scale > car) { sa1 = 1, sa2 = 1, sa3 = 0, sa4 = 0; }
else { sa1 = 0, sa2 = 0, sa3 = 1, sa4 = 1; }

if (v_b_ref_scale > car) { sa1 = 1, sa2 = 1, sa3 = 0, sa4 = 0; }


else { sa1 = 0, sa2 = 0, sa3 = 1, sa4 = 1; }

if (v_c_ref_scale > car) { sa1 = 1, sa2 = 1, sa3 = 0, sa4 = 0; }


else { sa1 = 0, sa2 = 0, sa3 = 1, sa4 = 1; }

out[0] = V_grid_a;
out[1] = V_grid_b;
out[2] = V_grid_c;
out[3] = V_grid_ds;
out[4] = V_grid_qs;
out[5] = V_grid_de;
out[6] = V_grid_qe;
out[7] = i_de_in;
out[8] = theta;
out[9] = i_de_in;
out[10] = i_de_in_ref;
out[11] = i_qe_in;
out[12] = i_qe_in_ref;

out[13] = sa1;
out[14] = sa2;
out[15] = sa3;
out[16] = sa4;
out[17] = sb1;
out[18] = sb2;
out[19] = sb3;
out[20] = sb4;
out[21] = sc1;
out[22] = sc2;
out[23] = sc3;
out[24] = sc4;
}

void transform()
{
i_ds_in = (2. *i_a_in - i_b_in - i_c_in) / 3.;
i_qs_in = (1. / sqrt(2.))*(i_b_in - i_i_c_in);

i_de_in = i_ds_in * cos(theta) + i_qs_in * sin(theta);


i_qe_in = -i_ds_in * sin(theta) + i_qs_in * cos(theta);
}
void current_control()
{

}
void in_transform()
{

}
void sw()
{

}
void PLL()
{
wc = 1. + 2. + zeta*wn; zeta = 0.7 wn = 200
Vds = (2. *Va - Vb - Vc) / 3.;
Vqs = (Vb - Vc) / sqrt(3.);

Vde = Vds*cos(thetae) + Vqs*sin(thetae);


Vqe = -Vds*sin(thetae) + Vqs*cos(thetae);

Vm = sqrt(Vde*Vde + Vqe*Vqe);

La = (2. - wc * Ts) / (2. + wc * Ts);


Lb = (wc * Ts) / (2. + wc * Ts);
Y = (La * Y_old) + Lb * (Vde + X_old);
Y_old + Y;
X_old = Vde;

Vde_err = Vde_ref - Vde;


Vde_err_int += Vde_err*Tsamp;

Kp = 2. * zeta*wn / (Vm + 0.0000001);


Kl = (wn*wn) / ((Vm + 0.00000001)*wc);

wrate = 2. * pi * f;

we = Vde_err*Kp + Vde_err_int*Kl + wrate;

thetae += we*T_samp;
theta += wrate *Ts;

If(thetae > pi) { theta -= 2.*pi; }


else if (thetae < -pi) { theta += 2.*pi; }

You might also like