interrupt void ISRTimer0(void)
{
IQ_Ref=2.2;//在电流环下给负电流电机反转
IQ_Fdb=iq;
IQ_Error=IQ_Ref-IQ_Fdb;
IQ_Up=IQ_Kp*IQ_Error;
IQ_Ui=IQ_Ui + IQ_Ki*IQ_Up + IQ_Kc*IQ_SatError;
IQ_OutPreSat=IQ_Up+IQ_Ui;
if(IQ_OutPreSat>IQ_OutMax)
IQ_Out=IQ_OutMax;
else if(IQ_OutPreSat<IQ_OutMin)
IQ_Out=IQ_OutMin;
else
IQ_Out=IQ_OutPreSat;
IQ_SatError=IQ_Out-IQ_OutPreSat;
Uq=IQ_Out;
ID_Ref=0;
ID_Fdb=id;
ID_Error=ID_Ref-ID_Fdb;
ID_Up=ID_Kp*ID_Error;
ID_Ui=ID_Ui+ID_Ki*ID_Up+ID_Kc*ID_SatError;
ID_OutPreSat=ID_Up+ID_Ui;
if(ID_OutPreSat>ID_OutMax)
ID_Out=ID_OutMax;
else if(ID_OutPreSat<ID_OutMin)
ID_Out=ID_OutMin;
else
ID_Out=ID_OutPreSat;
ID_SatError=ID_Out-ID_OutPreSat;
Ud=ID_Out;
Ualfa = Ud*Cosine - Uq*Sine;
Ubeta = Uq*Cosine + Ud*Sine;
B0=Ubeta;
B1=0.8660254*Ualfa - 0.5*Ubeta;
B2=-0.8660254*Ualfa- 0.5*Ubeta;
Sector=0;
if(B0>0) Sector =1;
if(B1>0) Sector =Sector +2;
if(B2>0) Sector =Sector +4;
X=Ubeta;
Y=0.8660254*Ualfa + 0.5*Ubeta;
Z=-0.8660254*Ualfa+ 0.5*Ubeta;
if (Sector==0)
{
Ta = 0.5;
Tb = 0.5;
Tc = 0.5;
}
if (Sector==1)
{
t1 = Z;
t2 = Y;
Tb = 0.5*(1-t1-t2);
if(Tb<0)
{
Tb=0;
}
Ta = Tb+t1;
Tc = Ta+t2;
}
else if (Sector==2)
{
t1 = Y;
t2 = -X;
Ta = 0.5*(1-t1-t2);
if(Ta<0)
{
Ta=0;
}
Tc = Ta+t1;
Tb = Tc+t2;
}
else if (Sector==3)
{
t1 = -Z;
t2 = X;
Ta = 0.5*(1-t1-t2);
if(Ta<0)
{
Ta=0;
}
Tb = Ta+t1;
Tc = Tb+t2;
}
else if (Sector==4)
{
t1 = -X;
t2 = Z;
Tc = 0.5*(1-t1-t2);
if(Tc<0)
{
Tc=0;
}
Tb = Tc+t1;
Ta = Tb+t2;
}
else if (Sector==5)
{
t1 = X;
t2 = -Y;
Tb = 0.5*(1-t1-t2);
if(Tb<0)
{
Tb=0;
}
Tc = Tb+t1;
Ta = Tc+t2;
}
else if (Sector==6)
{
t1 = -Y;
t2 = -Z;
Tc = 0.5*(1-t1-t2);
if(Tc<0)
{
Tc=0;
}
Ta = Tc+t1;
Tb = Ta+t2;
}
EPwm1Regs.CMPA.half.CMPA=Ta*3750;
EPwm2Regs.CMPA.half.CMPA=Tb*3750;
EPwm3Regs.CMPA.half.CMPA=Tc*3750;
EPwm1Regs.CMPB=Ta*3750;
EPwm2Regs.CMPB=Tb*3750;
EPwm3Regs.CMPB=Tc*3750;
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
CpuTimer0Regs.TCR.bit.TIF = 1;
CpuTimer0Regs.TCR.bit.TRB = 1;
}