📄 pmsm.c
字号:
float ualfa[200]={0.0},ubeta[200]={0.0};
float vref1,vref2,vref3,ualfa3;
float KP=0.7;
float INIA=3.1415926/180;
float DETA=2*3.1415926/200;
unsigned int sector[200]={0};
float TP = 1200.0;
float K=0.0,t=0.0;
void PMSM()
{
int i;
unsigned int a, b, c,n;
float x,y,z;
unsigned int cmp1,cmp2,cmp3;
float taon,tbon,tcon;
float t1,t2;
for(i=0;i<200;i++)
{
ualfa[i] = KP*cos(INIA + i*DETA);
ubeta[i] = KP*sin(INIA + i*DETA);
}
for(i=0;i<200;i++)
{
ualfa3 = ualfa[i]*1.732051;
vref1 = ubeta[i];
vref2 = (-ubeta[i] + ualfa3)*0.5;
vref3 = ubeta[i] + ualfa3;
vref3 = 0.0 - vref3*0.5;
if(vref1 > 0) { a = 1; }
else { a = 0; }
if(vref2 > 0) { b = 1; }
else { b = 0; }
if(vref3 > 0) { c = 1; }
else { c = 0; }
n = 4*c + 2*b + a;
switch(n)
{
case 1:
sector[i] = 1;
break;
case 2:
sector[i] = 5;
break;
case 3:
sector[i] = 0;
break;
case 4:
sector[i] = 3;
break;
case 5:
sector[i] = 2;
break;
case 6:
sector[i] = 4;
break;
default:
break;
}
}
for(i=0;i<200;i++)
{
x = ubeta[i];
y = (ubeta[i] + 1.732051*ualfa[i])*0.5;
z = (ubeta[i] - 1.732051*ualfa[i])*0.5;
switch(sector[i])
{
case 1:
t1 = 0.0 - z;
t2 = x;
break;
case 2:
t1 = z;
t2 = y;
break;
case 3:
t1 = x;
t2 = 0.0 - y;
break;
case 4:
t1 = 0.0 - x;
t2 = z;
break;
case 5:
t1 = 0.0 -y;
t2 = 0.0 - z;
break;
case 6:
t1 = y;
t2 = 0.0 - x;
break;
default:
break;
}
taon = (1 - t1*0.5 - t2*0.5)*0.5;
tbon = taon + t1*0.5;
tcon = tbon + t2*0.5;
cmp1 = (unsigned int)(taon*TP);
cmp2 = (unsigned int)(tbon*TP);
cmp3 = (unsigned int)(tcon*TP);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -