0% found this document useful (0 votes)
154 views9 pages

Tugas SKPE: Nama Davin Oktavian (1106068106) Membuat CMEX Untuk PMSM Diagram Simulink Yang Digunakan

Davin Oktavian created an S-Function in Simulink to model a PMSM motor. The S-Function contains the mathematical equations to model the motor dynamics and outputs various signals like phase currents, angular velocity, position, and generated torque. The S-Function takes in a 3-phase voltage source at 220V and 50Hz as input. With no load torque, the phase currents, velocity, and position graphs are obtained. With a 100N load torque, the changed phase currents, velocity, and torque graphs are shown.

Uploaded by

ibnumaulanah
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)
154 views9 pages

Tugas SKPE: Nama Davin Oktavian (1106068106) Membuat CMEX Untuk PMSM Diagram Simulink Yang Digunakan

Davin Oktavian created an S-Function in Simulink to model a PMSM motor. The S-Function contains the mathematical equations to model the motor dynamics and outputs various signals like phase currents, angular velocity, position, and generated torque. The S-Function takes in a 3-phase voltage source at 220V and 50Hz as input. With no load torque, the phase currents, velocity, and position graphs are obtained. With a 100N load torque, the changed phase currents, velocity, and torque graphs are shown.

Uploaded by

ibnumaulanah
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/ 9

Tugas SKPE

Nama = Davin Oktavian (1106068106)


Membuat CMEX untuk PMSM
Diagram Simulink yang digunakan :

Pada S-Function sinyalinput dibuat program sebagai berikut :


#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME sinyalinput
#include "simstruc.h"
#include <math.h>
#define U(element) (*uPtrs[element]) /*Pointer to Input Port0*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumDiscStates(S, 3);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0,2);
ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetInputPortOverWritable(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);
ssSetNumSampleTimes(S, 1);
ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE
| SS_OPTION_DISCRETE_VALUED_OUTPUT));

}
static void mdlInitializeSampleTimes(SimStruct *S){
ssSetSampleTime(S, 0, 0.001);
ssSetOffsetTime(S, 0, 0.0);}
#define MDL_INITIALIZE_CONDITIONS
static void mdlInitializeConditions(SimStruct *S){
real_T *x = ssGetRealDiscStates(S);
int_T nXStates = ssGetNumDiscStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);

/* initialize the states to 0.0 */


x[0] = 0;
x[1] = 0;
x[2] = 0;
x[3] = 0;
}
static void mdlOutputs(SimStruct *S, int_T tid){
real_T *y = ssGetOutputPortRealSignal(S,0);
real_T *x = ssGetRealDiscStates(S);
y[0] = x[0];
y[1] = x[1];
y[2] = x[2];
}
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int_T tid)
{
real_T *x = ssGetRealDiscStates(S);
real_T t = ssGetT(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T amplitudo,f ;
f=U(1);
amplitudo=U(0);
x[0]= amplitudo*sin(2*3.14*f*t);
x[1]= amplitudo*sin((2*3.14*f*t)-(2*3.14/3));
x[2]= amplitudo*sin((2*3.14*f*t)+(2*3.14/3));
}
static void mdlTerminate(SimStruct *S)
{ } /*Keep this function empty since no memory is allocated*/
#ifdef MATLAB_MEX_FILE
/* Is this file being compiled as a MEX-file? */
#include "simulink.c" /*MEX-file interface mechanism*/
#else
#include "cg_sfun.h" /*Code generation registration function*/
#endif

Pada s-Function PMSM1 digunakan program berikut :


#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME PMSM1
#include <math.h>
#include "simstruc.h"
#define U(element) (*uPtrs[element])

//pointer to input port 0

static void mdlInitializeSizes(SimStruct *S)


{
ssSetNumContStates(S, 8);
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 4);
ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetInputPortOverWritable(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 6);
ssSetNumSampleTimes(S, 1);
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS
static void mdlInitializeConditions(SimStruct *S)
{
real_T
*x
= ssGetContStates(S);
InputRealPtrsType
uPtrs
= ssGetInputPortRealSignalPtrs(S,0);
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
x[6]
x[7]

=
=
=
=
=
=
=
=

0;
0;
0;
0;
0;
0;
0;
0;

}
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T
*y
= ssGetOutputPortRealSignal(S,0);
real_T
*x
= ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
y[0] = x[5]; //ia
y[1] = x[6]; //ib
y[2] = x[7]; //ic
y[3] = x[2]; //wm

y[4] = x[3]; //teta_e


y[5] = x[4]; //te
}

#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S)
{
real_T *dx = ssGetdX(S);
real_T *x = ssGetContStates(S);
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T Ld = 16.6 * 1e-3 ;
real_T Lq = 16.32 *1e-3 ;
real_T Rs = 0.55 ;
real_T J = 0.01;
real_T flux = 0.121;
real_T N = 2;
real_T va , vb , vc , Tl ,te, teta ,wm, valpha, vbeta, Vd , Vq ,
ialpha,ibeta,ia,ib,ic,id,iq, iddot, iqdot,wmdot,tetadot;
va=U(0);
vb=U(1);
vc=U(2);
Tl=U(3);
//valpha vbeta
valpha = 0.8165*va -(0.8165*0.5)*vb -(0.8165*0.5)*vc;
vbeta = 0.8660*0.8165*vb - 0.8660*0.8165*vc;
//vd vq
teta=x[3];
Vd = cos(teta)*valpha + sin(teta)*vbeta;
Vq = -sin(teta)*valpha + cos(teta)*vbeta;
//ia ib ic
wm=x[2];
iddot = (Vd/Ld) + N*x[2]*(Lq/Ld)*x[1] -(Rs/Ld)*x[0] ;
iqdot = (Vq/Lq) - N*x[2]*(Ld/Lq)*x[0] -(Rs/Lq)*x[1] - (N*x[2]*flux/Lq) ;
tetadot= N*x[2];
wmdot=(1/J)*x[4] - (1/J)*Tl;
dx[0] = iddot;
dx[1] = iqdot;
dx[2] = wmdot;
dx[3] = tetadot;
//ialpha ibeta
ialpha = cos(x[3])*x[0]-sin(x[3])*x[1];
ibeta = sin(x[3])*x[0]+cos(x[3])*x[1];
//ia ib ic
ia = 0.8165*ialpha;
ib = -0.4082*ialpha+0.7071*ibeta;
ic = -0.4082*ialpha-0.7071*ibeta;
x[5]= ia;
x[6]= ib;
x[7]= ic;
//te
x[4]= N*(flux+(Ld-Lq)*x[0])*x[1];

}
static void mdlTerminate(SimStruct *S)
{}
#ifdef MATLAB_MEX_FILE
/* Is this file being compiled as a MEX-file? */
#include "simulink.c"
/* MEX-file interface mechanism */
#else
#include "cg_sfun.h"
/* Code generation registration function */
#endif

Dengan menggunakan input sebagai berikut :

Amplitudo Tegangan = 220 V


Frekuensi sumber = 50 Hz
Besar Torsi Load = 0

Maka didapatkan hasil sinyal berikut :

Sinyal tersebut merupakan Va, Vb, dan Vc yang bersifat sinusoidal


Setelah dimasukkan ke PWM akan dikeluarkan variable ia, ib, ic, wm (kecepatan angular), teta
(posisi), dan torsi elektrik yang dihasilkan.
Didapatkan grafik untuk ia. ib, dan ic adalah sebagai berikut

Grafik untuk Wm vs Posisi adalah sebagai berikut :

Grafik untuk Torsi Elektrik yang dihasilkan adalah :

Jika Besarnya torsi Load diubah menjadi 100 maka output sinyal yang dihasilkan :

Besarnya ia, ib, dan ic

Besar Wm vs teta

Besar torsi elektrik yang dihasilkan

You might also like