MATLAB Code For Synchronous Machine in Per Units U
MATLAB Code For Synchronous Machine in Per Units U
%START%
%------------------------------------------------------------------------%
% This program models a Synchronus Machine using Runge-Kutta 4th order Method %
%------------------------------------------------------------------------%
clear all;
clc;
close all;
%------------------------------------------------------------------------%
% Machine Constants %
%------------------------------------------------------------------------%
J=0.089; %Machine Moment of Inertia in Kg.m^2
B=0; %Co-efficient of Vicious Friction in S.I.
P=4; %Number of Poles
%------------------------------------------------------------------------%
%------------------------------------------------------------------------%
% Machine Dependent System Constants %
%------------------------------------------------------------------------%
Tm1=125; %Constant Load Torque or Prime Mover Torque in N.m
%(Use when mechanical torque is constant)
Vms=311.127; %Peak Line-Neutral Stator Voltage in V
V_f=0; % Field Voltage in V
fs=50; %Stator side Electrical Supply Frequency in Hz
Ws=2*pi*fs; %Stator Angular Velocity in rads/sec
%------------------------------------------------------------------------%
%% Number of turns:
%------------------------------------------------------------------------%
Ns =[];
Nkq1 =[];
Nkq2 =[];
Nfd =[];
Nkd =[];
Xmq = [];
Xmd = [];
%% List of resistances:
%------------------------------------------------------------------------%
Rs =
Rkq1 =
Rkq2 =
Rfd =
Rkd =
%------------------------------------------------------------------------%
%% Initializations %
%------------------------------------------------------------------------%
%------------------------------------------------------------------------%
% Electrical Torque(Te) in N.m,
% Mechanical Load/Input Torque(Tm) in N.m,
% Rotor Speed (wr-Electrical,wm-Mechanical)in rads/sec
% Rotor Angle (ThetaR) in radians
Te(1,1)=0;
Tm(1,1)=0;% Use when Mechanical torque is varying
wr(1,1)=0;
wm(1,1)=0;
ThetaR(1,1)=0;
%------------------------------------------------------------------------%
% Loop Counter (i), Time (t) in secs, Time Step (h) in secs %
%------------------------------------------------------------------------%
i=0;
t(1,1)=0;
h= 0.001;
%------------------------------------------------------------------------%
%------------------------------------------------------------------------%
% Starting with Machine Simulation 'For Loop' %
%------------------------------------------------------------------------%
for j=0:h:10
k1(1,i) = Wb * (Vqsr(1,i)+(Rs*Iqsr(1,i))-(wr(1,i)*Sidsr(1,i)));
m1(1,i) = Wb * (Vdsr(1,i)+(Rs*Idsr(1,i))+(wr(1,i)*Siqsr(1,i)));
n1(1,i) = Wb * (Vos(1,i)+(Rs*Ios(1,i)));
k2(1,i) = Wb * (Vqsr(1,i)+(Rs*Iqsr(1,i))-(wr(1,i)*Sidsr2(1,i)));
m2(1,i) = Wb * (Vdsr(1,i)+(Rs*Idsr(1,i))+(wr(1,i)*Siqsr2(1,i)));
n2(1,i) = Wb * (Vos(1,i)+(Rs*Ios(1,i)));
k3(1,i) = Wb * (Vqsr(1,i)+(Rs*Iqsr(1,i))-(wr(1,i)*Sidsr3(1,i)));
m3(1,i) = Wb * (Vdsr(1,i)+(Rs*Idsr(1,i))+(wr(1,i)*Siqsr3(1,i)));
n3(1,i) = Wb * (Vos(1,i)+(Rs*Ios(1,i)));
k4(1,i) = Wb * (Vqsr(1,i)+(Rs*Iqsr(1,i))-(wr(1,i)*Sidsr3(1,i)));
m4(1,i) = Wb * (Vdsr(1,i)+(Rs*Idsr(1,i))+(wr(1,i)*Siqsr3(1,i)));
n4(1,i) = Wb * (Vos(1,i)+(Rs*Ios(1,i)));
u2(1,i) = (1/J)*(Te(1,i)-Tm(1,i));
u3(1,i) = (1/J)*(Te(1,i)-Tm(1,i));
u4(1,i) = (1/J)*(Te(1,i)-Tm(1,i));
%--------------------------------------------------------------------%
%-----------------------------------------------------------------------%
% Calculation of Angles for dqo Transformation Matrix %
%--------------------------------------------------------------------%
Theta3 = Theta1 + (wr(1,i+1) * h); % For Stator Transformation
end
%------------------------------------------------------------------------%
% New Time Vector For Calculated Quantities (one element incremented) %
%------------------------------------------------------------------------%
t1=t;
t1(1,i+1)=t1(1,i)+h;
%------------------------------------------------------------------------%
% New Tm Vector For making elements equal to calculated quantities (one element
incremented) %
%------------------------------------------------------------------------%
Tm2=Tm;
Tm2(1,i+1)=Tm2(1,i);
%------------------------------------------------------------------------%
% Plotting Stator abc Voltages %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t,Vas)
title('Stator abc Voltages');
ylabel('Vas (V)');
subplot(3,1,2)
plot(t,Vbs)
ylabel('Vbs (V)');
subplot(3,1,3)
plot(t,Vcs)
ylabel('Vcs (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor abc Voltages %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t,Var)
title('Rotor abc Voltages');
ylabel('Var (V)');
subplot(3,1,2)
plot(t,Vbr)
ylabel('Vbr (V)');
subplot(3,1,3)
plot(t,Vcr)
ylabel('Vcr (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Stator qdo Voltages %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t,Vqs)
title('Stator qdo Voltages');
ylabel('Vqs (V)');
subplot(3,1,2)
plot(t,Vds)
ylabel('Vds (V)');
subplot(3,1,3)
plot(t,Vos)
ylabel('Vos (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor qdo Voltages %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t,Vqr)
title('Rotor dqo Voltages');
ylabel('Vqr (V)');
subplot(3,1,2)
plot(t,Vdr)
ylabel('Vdr (V)');
subplot(3,1,3)
plot(t,Vor)
ylabel('Vor (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Stator qdo Fluxes %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Lamqs)
title('Stator qdo Fluxes');
ylabel('Lamqs');
subplot(3,1,2)
plot(t1,Lamds)
ylabel('Lamds');
subplot(3,1,3)
plot(t1,Lamos)
ylabel('Lamos (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor qdo Fluxes %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Lamqr)
title('Rotor qdo Fluxes');
ylabel('Lamqr');
subplot(3,1,2)
plot(t1,Lamdr)
ylabel('Lamdr');
subplot(3,1,3)
plot(t1,Lamor)
ylabel('Lamor (V)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Stator qdo Currents %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Iqs)
title('Stator qdo Currents');
ylabel('Iqs (A)');
subplot(3,1,2)
plot(t1,Ids)
ylabel('Ids (A)');
subplot(3,1,3)
plot(t1,Ios)
ylabel('Ios (A)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor dqo Currents %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Iqr)
title('Rotor dqo Currents');
ylabel('Iqr (A)');
subplot(3,1,2)
plot(t1,Idr)
ylabel('Idr (A)');
subplot(3,1,3)
plot(t1,Ior)
ylabel('Ior (A)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Stator abc Currents %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Ias)
title('Stator abc Currents');
ylabel('Ias (A)');
subplot(3,1,2)
plot(t1,Ibs)
ylabel('Ibs (A)');
subplot(3,1,3)
plot(t1,Ics)
ylabel('Ics (A)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor abc Currents %
%------------------------------------------------------------------------%
figure
subplot(3,1,1)
plot(t1,Iar)
title('Rotor abc Currents');
ylabel('Iar (A)');
subplot(3,1,2)
plot(t1,Ibr)
ylabel('Ibr (A)');
subplot(3,1,3)
plot(t1,Icr)
ylabel('Icr (A)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Rotor Speed in Radian/sec and Revs/min %
%------------------------------------------------------------------------%
wm1= (30/pi)*(wm) ; % Calculating Rotor Speed in Rev/min
figure
subplot(2,1,1)
plot(t1,wm)
title('Rotor Speed');
ylabel('wm (Rads/sec)');
subplot(2,1,2)
plot(t1,wm1)
ylabel('wm (Revs/min)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Mechanical and Electrical Torque %
%------------------------------------------------------------------------%
figure
subplot(2,1,1)
plot(t1,Te)
title('Elcetrical and Mechanical Torques');
ylabel('Te(N.m)');
subplot(2,1,2)
plot(t,Tm)
ylabel('Tm (N.m)');
xlabel('Time (sec)');
%------------------------------------------------------------------------%
% Plotting Mechanical and Electrical Torque vs Rotor Speed (rpm) %
%------------------------------------------------------------------------%
figure
subplot(2,1,1)
plot(wm1,Te)
title('Electrical and Mechanical Torques vs Rotor Speed');
ylabel('Te(N.m)');
subplot(2,1,2)
plot(wm1,Tm2)
ylabel('Tm (N.m)');
xlabel('Rotor Speed (rpm)');
%------------------------------------------------------------------------%
% END %
%------------------------------------------------------------------------%*