simulink用Sfunction builder写的SVPWM出来COMP1的调制波咋会有突变
代码是照着一个模块改的
/* Includes_BEGIN */
#include <math.h>
/* Includes_END */
/* Externs_BEGIN */
/* extern double func(double a); */
#define Tc 0.00002
#define Udc 311
float A=0,B=0,C=0;
int section=0;
float Tx=0,Ty=0;
float X=0,Y=0,Z=0;
float T0 = 0;
float T1=0,T2=0,T3=0;
/* Externs_END */
void svpwm_Start_wrapper(void)
{
/* Start_BEGIN */
/*
* Custom Start code goes here.
*/
/* Start_END */
}
void svpwm_Outputs_wrapper(const real_T *u_alpha,
const real_T *u_beta,
real_T *comp1,
real_T *comp2,
real_T *comp3)
{
/* Output_BEGIN */
A = u_beta[0];
B = -0.5*u_beta[0] + 0.866*u_alpha[0];//(sqrt(3)/2)
C = -0.5*u_beta[0] - 0.866*u_alpha[0];
if(A > 0)
section = 1;
if(B > 0)
section += 2;
if(C > 0)
section += 4;
X = (1.732*u_beta[0]*Tc)/Udc;
Y = (0.866*u_beta[0] + 1.5*u_alpha[0])*Tc/Udc;
Z = (0.866*u_beta[0] - 1.5*u_alpha[0])*Tc/Udc;
switch(section)
{
case 1:Tx = Z;Ty = Y;break;
case 2:Tx = Y;Ty = -X;break;
case 3:Tx = -Z;Ty = X;break;
case 4:Tx = -X;Ty = Z;break;
case 5:Tx = X;Ty = -Y;break;
default:Tx = -Y;Ty = -Z;
}
if(Tx+Ty>Tc)
{
Tx = Tx*Tc/(Tx+Ty);
Ty = Ty*Tc/(Tx+Ty);
}
T0 = (Tc-Tx-Ty)/4;
T1 = T0;
T2 = T1 + Tx/2;
T3 = T2 + Ty/2;
switch(section)
{
case 1:comp1[0] = T2;comp2[0] = T1;comp3[0] = T3;break;
case 2:comp1[0] = T1;comp2[0] = T3;comp3[0] = T2;break;
case 3:comp1[0] = T1;comp2[0] = T2;comp3[0] = T3;break;
case 4:comp1[0] = T3;comp2[0] = T2;comp3[0] = T1;break;
case 5:comp1[0] = T3;comp2[0] = T1;comp3[0] = T2;break;
default:comp1[0] = T2;comp2[0] = T3;comp3[0] = T1;
}
if(comp1[0]>1e-5)
comp1[0] = 1e-5;
else if(comp1[0]<0)
comp1[0] = 0;
if(comp2[0]>1e-5)
comp2[0] = 1e-5;
else if(comp2[0]<0)
comp2[0] = 0;
if(comp3[0]>1e-5)
comp3[0] = 1e-5;
else if(comp3[0]<0)
comp3[0] = 0;
/* Output_END */
}
void svpwm_Terminate_wrapper(void)
{
/* Terminate_BEGIN */
/*
* Custom Terminate code goes here.
*/
/* Terminate_END */
}
模块的COMP1
代码的COMP1