例程1:
void svgendq_calc(SVGENDQ *v)
{
_iq Va,Vb,Vc,t1,t2;
Uint32 Sector = 0; // Sector is treated as Q0 – independently with global Q
// Inverse clarke transformation
Va = v->Ubeta;
Vb = _IQmpy(_IQ(-0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
Vc = _IQmpy(_IQ(-0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
// 60 degree Sector determination
if (Va>_IQ(0))
Sector = 1;
if (Vb>_IQ(0))
Sector = Sector + 2;
if (Vc>_IQ(0))
Sector = Sector + 4;
// X,Y,Z (Va,Vb,Vc) calculations
Va = v->Ubeta; // X = Va
Vb = _IQmpy(_IQ(0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // Y = Vb
Vc = _IQmpy(_IQ(0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // Z = Vc
if (Sector==0) // Sector 0: this is special case for (Ualpha,Ubeta) = (0,0)
{
v->Ta = _IQ(0.5);
v->Tb = _IQ(0.5);
v->Tc = _IQ(0.5);
}
if (Sector==1) // Sector 1: t1=Z and t2=Y (abc —> Tb,Ta,Tc)
{
t1 = Vc;
t2 = Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Ta = v->Tb+t1; // taon = tbon+t1
v->Tc = v->Ta+t2; // tcon = taon+t2
}
else if (Sector==2) // Sector 2: t1=Y and t2=-X (abc —> Ta,Tc,Tb)
{
t1 = Vb;
t2 = -Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tc = v->Ta+t1; // tcon = taon+t1
v->Tb = v->Tc+t2; // tbon = tcon+t2
}
else if (Sector==3) // Sector 3: t1=-Z and t2=X (abc —> Ta,Tb,Tc)
{
t1 = -Vc;
t2 = Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tb = v->Ta+t1; // tbon = taon+t1
v->Tc = v->Tb+t2; // tcon = tbon+t2
}
else if (Sector==4) // Sector 4: t1=-X and t2=Z (abc —> Tc,Tb,Ta)
{
t1 = -Va;
t2 = Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Tb = v->Tc+t1; // tbon = tcon+t1
v->Ta = v->Tb+t2; // taon = tbon+t2
}
else if (Sector==5) // Sector 5: t1=X and t2=-Y (abc —> Tb,Tc,Ta)
{
t1 = Va;
t2 = -Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Tc = v->Tb+t1; // tcon = tbon+t1
v->Ta = v->Tc+t2; // taon = tcon+t2
}
else if (Sector==6) // Sector 6: t1=-Y and t2=-Z (abc —> Tc,Ta,Tb)
{
t1 = -Vb;
t2 = -Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Ta = v->Tc+t1; // taon = tcon+t1
v->Tb = v->Ta+t2; // tbon = taon+t2
}
// Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1))
v->Ta = _IQmpy(_IQ(2.0),(v->Ta-_IQ(0.5)));
v->Tb = _IQmpy(_IQ(2.0),(v->Tb-_IQ(0.5)));
v->Tc = _IQmpy(_IQ(2.0),(v->Tc-_IQ(0.5)));
}
例程2:
#define SVGENDQ_MACRO(v)
v.tmp1= v.Ubeta;
v.tmp2= _IQdiv2(v.Ubeta) + (_IQmpy(_IQ(0.8660254),v.Ualpha));
v.tmp3= v.tmp2 – v.tmp1;
v.VecSector = 3;
v.VecSector=(v.tmp2> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp3> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp1< 0)?(7-v.VecSector) :v.VecSector;
if (v.VecSector==1 || v.VecSector==4)
{ v.Ta= v.tmp2;
v.Tb= v.tmp1-v.tmp3;
v.Tc=-v.tmp2;
}
else if(v.VecSector==2 || v.VecSector==5)
{ v.Ta= v.tmp3+v.tmp2;
v.Tb= v.tmp1;
v.Tc=-v.tmp1;
}
else
{ v.Ta= v.tmp3;
v.Tb=-v.tmp3;
v.Tc=-(v.tmp1+v.tmp2);
}
经过推导,例程1算出来的Ta,Tb,Tc,与例程2中的Ta,Tb,Tc都差个负号,即
例程1.Ta = – 例程2.Ta
例程1.Tb = – 例程2.Tb
例程1.Tc = – 例程2.Tc
例程1得出的结果范围是(-1,1);例程2得出的结果范围是(1,-1)
这两结果经过处理赋值给PWM寄存器时有什么区别?
希望TI大神不吝赐教
wentao zhang:请问你解决了吗
例程1:
void svgendq_calc(SVGENDQ *v)
{
_iq Va,Vb,Vc,t1,t2;
Uint32 Sector = 0; // Sector is treated as Q0 – independently with global Q
// Inverse clarke transformation
Va = v->Ubeta;
Vb = _IQmpy(_IQ(-0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
Vc = _IQmpy(_IQ(-0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
// 60 degree Sector determination
if (Va>_IQ(0))
Sector = 1;
if (Vb>_IQ(0))
Sector = Sector + 2;
if (Vc>_IQ(0))
Sector = Sector + 4;
// X,Y,Z (Va,Vb,Vc) calculations
Va = v->Ubeta; // X = Va
Vb = _IQmpy(_IQ(0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // Y = Vb
Vc = _IQmpy(_IQ(0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // Z = Vc
if (Sector==0) // Sector 0: this is special case for (Ualpha,Ubeta) = (0,0)
{
v->Ta = _IQ(0.5);
v->Tb = _IQ(0.5);
v->Tc = _IQ(0.5);
}
if (Sector==1) // Sector 1: t1=Z and t2=Y (abc —> Tb,Ta,Tc)
{
t1 = Vc;
t2 = Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Ta = v->Tb+t1; // taon = tbon+t1
v->Tc = v->Ta+t2; // tcon = taon+t2
}
else if (Sector==2) // Sector 2: t1=Y and t2=-X (abc —> Ta,Tc,Tb)
{
t1 = Vb;
t2 = -Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tc = v->Ta+t1; // tcon = taon+t1
v->Tb = v->Tc+t2; // tbon = tcon+t2
}
else if (Sector==3) // Sector 3: t1=-Z and t2=X (abc —> Ta,Tb,Tc)
{
t1 = -Vc;
t2 = Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tb = v->Ta+t1; // tbon = taon+t1
v->Tc = v->Tb+t2; // tcon = tbon+t2
}
else if (Sector==4) // Sector 4: t1=-X and t2=Z (abc —> Tc,Tb,Ta)
{
t1 = -Va;
t2 = Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Tb = v->Tc+t1; // tbon = tcon+t1
v->Ta = v->Tb+t2; // taon = tbon+t2
}
else if (Sector==5) // Sector 5: t1=X and t2=-Y (abc —> Tb,Tc,Ta)
{
t1 = Va;
t2 = -Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Tc = v->Tb+t1; // tcon = tbon+t1
v->Ta = v->Tc+t2; // taon = tcon+t2
}
else if (Sector==6) // Sector 6: t1=-Y and t2=-Z (abc —> Tc,Ta,Tb)
{
t1 = -Vb;
t2 = -Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Ta = v->Tc+t1; // taon = tcon+t1
v->Tb = v->Ta+t2; // tbon = taon+t2
}
// Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1))
v->Ta = _IQmpy(_IQ(2.0),(v->Ta-_IQ(0.5)));
v->Tb = _IQmpy(_IQ(2.0),(v->Tb-_IQ(0.5)));
v->Tc = _IQmpy(_IQ(2.0),(v->Tc-_IQ(0.5)));
}
例程2:
#define SVGENDQ_MACRO(v)
v.tmp1= v.Ubeta;
v.tmp2= _IQdiv2(v.Ubeta) + (_IQmpy(_IQ(0.8660254),v.Ualpha));
v.tmp3= v.tmp2 – v.tmp1;
v.VecSector = 3;
v.VecSector=(v.tmp2> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp3> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp1< 0)?(7-v.VecSector) :v.VecSector;
if (v.VecSector==1 || v.VecSector==4)
{ v.Ta= v.tmp2;
v.Tb= v.tmp1-v.tmp3;
v.Tc=-v.tmp2;
}
else if(v.VecSector==2 || v.VecSector==5)
{ v.Ta= v.tmp3+v.tmp2;
v.Tb= v.tmp1;
v.Tc=-v.tmp1;
}
else
{ v.Ta= v.tmp3;
v.Tb=-v.tmp3;
v.Tc=-(v.tmp1+v.tmp2);
}
经过推导,例程1算出来的Ta,Tb,Tc,与例程2中的Ta,Tb,Tc都差个负号,即
例程1.Ta = – 例程2.Ta
例程1.Tb = – 例程2.Tb
例程1.Tc = – 例程2.Tc
例程1得出的结果范围是(-1,1);例程2得出的结果范围是(1,-1)
这两结果经过处理赋值给PWM寄存器时有什么区别?
希望TI大神不吝赐教
Ziqiang Ye:
同问,TI在simulink中模块和Control Suit 中关于SVGENDQ 也是一样的情况。
CCS 库中定义
#define SVGENDQ_MACRO(v)
v.tmp1= v.Ubeta;v.tmp2= _IQdiv2(v.Ubeta) + (_IQmpy(_IQ(0.8660254),v.Ualpha));v.tmp3= v.tmp2 – v.tmp1;
v.VecSector = 3;v.VecSector=(v.tmp2> 0)?( v.VecSector-1):v.VecSector;v.VecSector=(v.tmp3> 0)?( v.VecSector-1):v.VecSector;v.VecSector=(v.tmp1< 0)?(7-v.VecSector) :v.VecSector;
if (v.VecSector==1 || v.VecSector==4){ v.Ta= v.tmp2;v.Tb= v.tmp1-v.tmp3;v.Tc=-v.tmp2;}
else if(v.VecSector==2 || v.VecSector==5){ v.Ta= v.tmp3+v.tmp2;v.Tb= v.tmp1;v.Tc=-v.tmp1;}
else{ v.Ta= v.tmp3;v.Tb=-v.tmp3;v.Tc=-(v.tmp1+v.tmp2);}
与
也是出现一样的情况,输出多了个正负号。请问何解!谢谢
例程1:
void svgendq_calc(SVGENDQ *v)
{
_iq Va,Vb,Vc,t1,t2;
Uint32 Sector = 0; // Sector is treated as Q0 – independently with global Q
// Inverse clarke transformation
Va = v->Ubeta;
Vb = _IQmpy(_IQ(-0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
Vc = _IQmpy(_IQ(-0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // 0.8660254 = sqrt(3)/2
// 60 degree Sector determination
if (Va>_IQ(0))
Sector = 1;
if (Vb>_IQ(0))
Sector = Sector + 2;
if (Vc>_IQ(0))
Sector = Sector + 4;
// X,Y,Z (Va,Vb,Vc) calculations
Va = v->Ubeta; // X = Va
Vb = _IQmpy(_IQ(0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // Y = Vb
Vc = _IQmpy(_IQ(0.5),v->Ubeta) – _IQmpy(_IQ(0.8660254),v->Ualpha); // Z = Vc
if (Sector==0) // Sector 0: this is special case for (Ualpha,Ubeta) = (0,0)
{
v->Ta = _IQ(0.5);
v->Tb = _IQ(0.5);
v->Tc = _IQ(0.5);
}
if (Sector==1) // Sector 1: t1=Z and t2=Y (abc —> Tb,Ta,Tc)
{
t1 = Vc;
t2 = Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Ta = v->Tb+t1; // taon = tbon+t1
v->Tc = v->Ta+t2; // tcon = taon+t2
}
else if (Sector==2) // Sector 2: t1=Y and t2=-X (abc —> Ta,Tc,Tb)
{
t1 = Vb;
t2 = -Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tc = v->Ta+t1; // tcon = taon+t1
v->Tb = v->Tc+t2; // tbon = tcon+t2
}
else if (Sector==3) // Sector 3: t1=-Z and t2=X (abc —> Ta,Tb,Tc)
{
t1 = -Vc;
t2 = Va;
v->Ta = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2
v->Tb = v->Ta+t1; // tbon = taon+t1
v->Tc = v->Tb+t2; // tcon = tbon+t2
}
else if (Sector==4) // Sector 4: t1=-X and t2=Z (abc —> Tc,Tb,Ta)
{
t1 = -Va;
t2 = Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Tb = v->Tc+t1; // tbon = tcon+t1
v->Ta = v->Tb+t2; // taon = tbon+t2
}
else if (Sector==5) // Sector 5: t1=X and t2=-Y (abc —> Tb,Tc,Ta)
{
t1 = Va;
t2 = -Vb;
v->Tb = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2
v->Tc = v->Tb+t1; // tcon = tbon+t1
v->Ta = v->Tc+t2; // taon = tcon+t2
}
else if (Sector==6) // Sector 6: t1=-Y and t2=-Z (abc —> Tc,Ta,Tb)
{
t1 = -Vb;
t2 = -Vc;
v->Tc = _IQmpy(_IQ(0.5),(_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2
v->Ta = v->Tc+t1; // taon = tcon+t1
v->Tb = v->Ta+t2; // tbon = taon+t2
}
// Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1))
v->Ta = _IQmpy(_IQ(2.0),(v->Ta-_IQ(0.5)));
v->Tb = _IQmpy(_IQ(2.0),(v->Tb-_IQ(0.5)));
v->Tc = _IQmpy(_IQ(2.0),(v->Tc-_IQ(0.5)));
}
例程2:
#define SVGENDQ_MACRO(v)
v.tmp1= v.Ubeta;
v.tmp2= _IQdiv2(v.Ubeta) + (_IQmpy(_IQ(0.8660254),v.Ualpha));
v.tmp3= v.tmp2 – v.tmp1;
v.VecSector = 3;
v.VecSector=(v.tmp2> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp3> 0)?( v.VecSector-1):v.VecSector;
v.VecSector=(v.tmp1< 0)?(7-v.VecSector) :v.VecSector;
if (v.VecSector==1 || v.VecSector==4)
{ v.Ta= v.tmp2;
v.Tb= v.tmp1-v.tmp3;
v.Tc=-v.tmp2;
}
else if(v.VecSector==2 || v.VecSector==5)
{ v.Ta= v.tmp3+v.tmp2;
v.Tb= v.tmp1;
v.Tc=-v.tmp1;
}
else
{ v.Ta= v.tmp3;
v.Tb=-v.tmp3;
v.Tc=-(v.tmp1+v.tmp2);
}
经过推导,例程1算出来的Ta,Tb,Tc,与例程2中的Ta,Tb,Tc都差个负号,即
例程1.Ta = – 例程2.Ta
例程1.Tb = – 例程2.Tb
例程1.Tc = – 例程2.Tc
例程1得出的结果范围是(-1,1);例程2得出的结果范围是(1,-1)
这两结果经过处理赋值给PWM寄存器时有什么区别?
希望TI大神不吝赐教
zhenhua ren:我也是看到这个问题了,我也搞不懂,为啥整2个,有大神知道为啥吗?什么时候有SVGEN,什么时候用SEGEN_DQ?