您的当前位置:首页正文

SVPWM算法程序

2020-02-18 来源:布克知识网


第6章 空间矢量脉宽调制技术

例1、CLARK变换的DSP实现

图 CLARK变换实现波形图

/*----------------------------------------------------------------------------------------------------------------------------------------

CLARKE变换相关变量定义

----------------------------------------------------------------------------------------------------------------------------------------*/

typedef struct { float32 As; // 输入:A相定子电流

float32 Bs; // 输入:B相定子电流

float32 Alpha; // 输出:静止坐标系d轴定子电流

1

float32 Beta; // 输出:静止坐标系q轴定子电流

void (*calc)(); // 计算函数指针

} CLARKE;

typedef CLARKE *CLARKE_handle;

/*----------------------------------------------------------------------------------------------------------------------------------------

定义CLARKE变换初始化参数

----------------------------------------------------------------------------------------------------------------------------------------*/

#define CLARKE_DEFAULTS { 0, \\

0, \\

0, \\

0, \\

(void (*)(Uint32))clarke_calc }

2

/*----------------------------------------------------------------------------------------------------------------------------------------

CLARKE变换函数原型CLARKE.C

----------------------------------------------------------------------------------------------------------------------------------------*/

void clarke_calc(CLARKE_handle);

#include \"dmctype.h\"

#include \"clarke.h\"

void clarke_calc(CLARKE *v)

{

v->Alpha = v->As;

v->Beta = (v->As + 2*v->Bs)*0.57735026918963; // 1/sqrt(3) = 0.57735026918963

}

例2、PARK变换的DSP实现

3

图 PARK变换DSP实现坐标映射

/*----------------------------------------------------------------------------------------------------------------------------------------

PARK变换相关变量定义

----------------------------------------------------------------------------------------------------------------------------------------*/

typedef struct { float32 Alpha; // 输入:静止坐标系d轴定子变量

loat32 Beta; // 输入:静止坐标系q轴定子变量

float32 Angle; // 输入:转子角度(弧度)

float32 Ds; // 输出:旋转d轴定子变量(M轴)

4

float32 Qs; // 输出:旋转q轴定子变量(T轴)

void (*calc)(); // 函数指针

} PARK;

typedef PARK *PARK_handle;

/*----------------------------------------------------------------------------------------------------------------------------------------

PARK变换变量初始化参数

----------------------------------------------------------------------------------------------------------------------------------------*/#define PARK_DEFAULTS { 0, \\

0, \\

0, \\

0, \\

0, \\

(void (*)(Uint32))park_calc }

5

/*----------------------------------------------------------------------------------------------------------------------------------------

PARK函数原型

----------------------------------------------------------------------------------------------------------------------------------------*/

void park_calc(PARK_handle);

#include \"dmctype.h\"

#include \"park.h\"

extern float32 sin_tab[];

void park_calc(PARK *v)

{

float32 Cosine,Sine;

// 采用查表法

// (PI/2)/(2*PI) = 0.25

6

// ((PI/2)/(2*PI))*256 = 0.25*256 = 64

// ((PI/2)-2*PI)/(2*PI) = -0.75

// (((PI/2)-2*PI)/(2*PI))*256 = -0.75*256 = -192

// 查表发求解正弦

if (v->Angle+0.25 > 1.0)

{

Sine = sin_tab[(int16)(v->Angle*256)];

Cosine = sin_tab[(int16)(v->Angle*256) - 192]; }

else

{

Sine = sin_tab[(int16)(v->Angle*256)];

Cosine = sin_tab[(int16)(v->Angle*256) + 64];

7

}

v->Ds = v->Alpha*Cosine + v->Beta*Sine;

v->Qs = v->Beta*Cosine - v->Alpha*Sine;

}

图6.7 PARK变换坐标映射图

/*----------------------------------------------------------------------------------------------------------------------------------------

PARK逆变换参数定义

----------------------------------------------------------------------------------------------------------------------------------------*/

8

typedef struct { float ds; /* 输出:定子参考坐标系d-轴变量 */

float qs; /* 输出:定子参考坐标系q-轴变量 */

float ang; /* 输入:转子转动角度 (rad) */

float de; /* 输入:旋转d-轴定子变量 */

float qe; /* 输入:旋转q-轴定子变量 */

void (*calc)(); /* 计算函数指针 */

} IPARK;

typedef IPARK *IPARK_handle;

/*----------------------------------------------------------------------------------------------------------------------------------------

Default initalizer for the IPARK object.

----------------------------------------------------------------------------------------------------------------------------------------*/

#define IPARK_DEFAULTS { 0, \\

9

0, \\

0, \\

0, \\

0, \\

(void (*)(long))ipark_calc }

/*----------------------------------------------------------------------------------------------------------------------------------------

逆变换函数IPARK.C

----------------------------------------------------------------------------------------------------------------------------------------*/

void ipark_calc(IPARK_handle);

/*----------------------------------------------------------------------------------------------------------------------------------------

文件名称:: IPARK.C

-------------------------------------------------------------------------------------10

---------------------------------------------------*/

#include \"ipark.h\"

extern float sin_tab[];

void ipark_calc(IPARK *v)

{

float cos_ang,sin_ang;

/*采用查表法计算正弦角度 */

/* (PI/2)/(2*PI) = 0.25 */

/* ((PI/2)/(2*PI))*256 = 0.25*256 = 64 */

/* ((PI/2)-2*PI)/(2*PI) = -0.75 */

/* (((PI/2)-2*PI)/(2*PI))*256 = -0.75*256 = -192 */

if (v->ang+0.25 > 1)

{

11

sin_ang = sin_tab[(int)(v->ang*256)];

cos_ang = sin_tab[(int)(v->ang*256) - 192];

}

else

{

sin_ang = sin_tab[(int)(v->ang*256)];

cos_ang = sin_tab[(int)(v->ang*256) + 64];

}

v->ds = v->de*cos_ang - v->qe*sin_ang;

v->qs = v->qe*cos_ang + v->de*sin_ang;

}

例3、空间矢量的算法程序

/*----------------------------------------------------------------------------------------------------------------------------------------

12

空间矢量的产生: SVGEN_DQ.C (IQ version)

----------------------------------------------------------------------------------------------------------------------------------------*/

#include \"IQmathLib.h\" // Include header for IQmath library

// Don't forget to set a proper GLOBAL_Q in \"IQmathLib.h\" file

#include \"dmctype.h\"

#include \"svgen_dq.h\"

void svgendq_calc(SVGENDQ *v)

{

_iq Va,Vb,Vc,t1,t2;

Uint32 Sector = 0; // Sector is treated as Q0 - independently with global Q

// CLARKE逆变换

Va = v->Ubeta;

Vb = _IQmpy(_IQ(-0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha);

13

Vc = _IQmpy(_IQ(-0.5),v->Ubeta) - _IQmpy(_IQ(0.8660254),v->Ualpha);

// 0.8660254 = sqrt(3)/2

// 60o 扇区确定

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) 计算

Va = v->Ubeta; // X = Va

Vb = _IQmpy(_IQ(0.5),v->Ubeta) + _IQmpy(_IQ(0.8660254),v->Ualpha); // Y = Vb

14

Vc = _IQmpy(_IQ(0.5),v->Ubeta) - _IQmpy(_IQ(0.8660254),v->Ualpha); // Z = Vc

if (Sector==0) // Sector 0: 当(U,

U) = (0,0)

{

v->Ta = _IQ(0.5);

v->Tb = _IQ(0.5);

v->Tc = _IQ(0.5);

}

if (Sector==1) // Sector 1: t1=Z 和 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

15

v->Tc = v->Ta+t2; // tcon = taon+t2

}

else if (Sector==2) // Sector 2: t1=Y和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和t2=X (abc ---> Ta,Tb,Tc)

{

t1 = -Vc;

16

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和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

}

17

else if (Sector==5) // Sector 5: t1=X和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和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

18

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)));

}

19

因篇幅问题不能全部显示,请点此查看更多更全内容