📄 svm.c
字号:
#include "MAIN.H"
#include "DEF.H"
#include "TableQ15.h"
unsigned int tk,tk1,to;
const int PulseMin_Div2 = 15;
//****************************************************************************
// @Function void SVM (TComplex *m, char *Sector)
//
//----------------------------------------------------------------------------
// @Description This Function calculate the compare values t0, tk and tk+1
// for the SVM. Then this values are written in the Shadow-
// Registers of CC6-Unit
//
// Execution time 4.2us @ 40MHz
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 15.10.2003
//
//****************************************************************************
void SVM(TComplex *m, char *Sector)
{
int x;
bit Abort=1;
// determiination of the sector
x=((long)m->imag*(long)SQRT3INV) >> 15;
if (m->imag>0)
{ // m.imag>0
if (m->real>0)
{ // Quadrant 1
if (x<m->real) {*Sector=0;} else {*Sector=1;}
}
else
{ // Quadrant 2
if (x< -m->real) {*Sector=2;} else {*Sector=1;}
}
}
else
{ // m.imag<0
if (m->real<0)
{ // Quadrant 3
if (x<m->real) {*Sector=4;} else {*Sector=3;}
}
else
{ // Quadrant 4
if (x< -m->real) {*Sector=4;} else {*Sector=5;}
}
}
// Sector contain the Sector number minus 1 (from 0 to 5)
// Calul of Tk and Tk+1
// Tk= sin(k)*m.Re - Cos(k)*m.Im k is the sector number
// Tk+1= Cos(k-1)*m.Im - Sin(k-1)*m.Re
tk1 = ((long)CosVectorQ1_15[*Sector]*(long)m->imag - (long)SinVectorQ1_15[*Sector]*(long)m->real) >> 15;
tk1 = ((long)tk1 * (long)TPWM) >> 15;
tk = ((long)SinVectorQ1_15[*Sector+1]*(long)m->real - (long)CosVectorQ1_15[*Sector+1]*(long)m->imag) >> 15;
tk = ((long)tk * (long)TPWM) >> 15;
// lengthen the states to measure the currents
/*
if (tk<PulseMin_Div2)
{
tk=PulseMin_Div2;
}
if (tk1<PulseMin_Div2)
{
tk1=PulseMin_Div2;
}
*/
to=1001-tk-tk1;
// Write t0, 1k and tk1 to the shadow registers of CC6
// Set Timer 13 Event Control, for ADC start
switch (*Sector)
{
case 0:
CCU6_TCTR2 = 0x006A;
CCU6_CC60SR=to>>2;
CCU6_CC61SR=500-(to>>2)-(tk1>>1);
CCU6_CC62SR=500-(to>>2);
break;
case 1:
CCU6_TCTR2 = 0x0066;
CCU6_CC60SR=(to>>2)+(tk1>>1);
CCU6_CC61SR=to>>2;
CCU6_CC62SR=500-(to>>2);
break;
case 2:
CCU6_TCTR2 = 0x006E;
CCU6_CC60SR=500-(to>>2);
CCU6_CC61SR=to>>2;
CCU6_CC62SR=500-(to>>2)-(tk1>>1);
break;
case 3:
CCU6_TCTR2 = 0x006A;
CCU6_CC60SR=500-(to>>2);
CCU6_CC61SR=(to>>2)+(tk1>>1);
CCU6_CC62SR=to>>2;
break;
case 4:
CCU6_TCTR2 = 0x0066;
CCU6_CC60SR=500-(to>>2)-(tk1>>1);
CCU6_CC61SR=500-(to>>2);
CCU6_CC62SR=to>>2;
break;
case 5:
CCU6_TCTR2 = 0x006E;
CCU6_CC60SR=(to>>2);
CCU6_CC61SR=500-(to>>2);
CCU6_CC62SR=(to>>2)+(tk1>>1);
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -