小弟最近在试着编写SVPWM程序,奈何TI给的例程有些NB,不太适合我所以我就自己整理了一个头文件和一个源文件。但是编译的时候总是出现这样的错误,如下:
undefined first referenced
symbol in file
--------- ----------------
_SVREG ./SRC/SVPWM.obj
error: unresolved symbols remain
error: errors encountered during linking; "SVPWM_CONTROL.out" not build
我也看了论坛上的解决方法可是仍旧解决不了。所以请教各位大师帮忙。
下面是我的代码首先是头文件
- #ifndef SVPWM_CAL_H_
- #define SVPWM_CAL_H_
- //#include "DSP2833x_Project.h"
- #define PI 3.14159
- struct SVPWM_REG{
- float32 Ta;
- float32 Tb;
- float32 Tc;
- Uint16 N;
- };
- void SVPWM_cal(Uint16 ang);
- void Init_STR(void);
- extern volatile struct SVPWM_REG SVREG;
- #endif
复制代码
然后是源文件
- #include "DSP2833x_Project.h"
- #include "math.h"
- float32 Ua,Ub,X,Y,Z,t1,t2,t0,U1,U2,U3;
- Uint16 A,B,C;
- void Init_STR(void)
- {
- SVREG.Ta = 0;
- SVREG.Tb = 0;
- SVREG.Tc = 0;
- SVREG.N = 0;
- }
- void SVPWM_cal(Uint16 ang)
- {
- Ua=cos(ang/100*PI);
- Ub=sin(ang/100*PI);
- X=0.866*Ub;
- Y=0.433*Ub+0.75*Ua;
- Z=0.433*Ub-0.75*Ua;
- U1=Ub;
- U2=0.866*Ua-Ub;
- U3=-0.866*Ua-Ub;
- if(U1>0)
- A=1;
- else
- A=0;
- if(U2>0)
- B=1;
- else
- B=0;
- if(U3>0)
- C=1;
- else
- C=0;
- SVREG.N=A+2*B+4*C;
- switch(SVREG.N)
- {
- case 1:t1=Z;t2=Y;break;
- case 2:t1=Y;t2=-X;break;
- case 3:t1=-Z;t2=X;break;
- case 4:t1=-X;t2=Z;break;
- case 5:t1=X;t2=Y;break;
- case 6:t1=-Y;t2=-Z;break;
- }
- SVREG.Ta=(1-t1-t2)/4*7500;
- SVREG.Tb=SVREG.Ta+t1/2*7500;
- SVREG.Tc=SVREG.Tb+t2/2*7500;
- }
复制代码
我将头文件包含在了库函数中DSP2833x_DEVICE_H这个头文件中
- #include "DSP2833x_SysCtrl.h" // System Control/Power Modes
- #include "DSP2833x_XIntrupt.h" // External Interrupts
- #include "DSP2833x_Xintf.h" // XINTF External Interface
- [b]#include "SVPWM.H"
- #include "Config_PWM.h"[/b]
- #if DSP28_28335
- #define DSP28_EPWM1 1
复制代码
最后是主程序
- #include "DSP2833x_Project.h"
- Uint16 i,flag,sector;
- interrupt void epwm1_timer_isr(void);
- interrupt void epwm2_timer_isr(void);
- interrupt void epwm3_timer_isr(void);
- void main(void)
- {
- InitSysCtrl();
- DINT;
- InitPieCtrl();
- IER = 0x0000;
- IFR = 0x0000;
- InitPieVectTable();
-
- EALLOW;
- PieVectTable.EPWM1_INT = &epwm1_timer_isr;
- PieVectTable.EPWM2_INT = &epwm2_timer_isr;
- PieVectTable.EPWM3_INT = &epwm3_timer_isr;
- EDIS;
-
- EALLOW;
- SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
- EDIS;
-
-
-
- InitEPWMALL();
-
-
- EALLOW;
- SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
- EDIS;
-
- IER |= M_INT3;
-
- PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
- PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
- PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
- EINT;
- ERTM;
-
-
- Init_STR();
-
- for(;;)
- {
- if(flag==1)
- {
- flag=0;
- i++;
- if(i>200)
- i=0;
- SVPWM_cal(i);
- sector = SVREG.N;
- }
- else
- asm(" NOP");
- }
- }
- interrupt void epwm1_timer_isr(void)
- {
- flag=1;
- switch(sector)
- {
- case 1:EPwm1Regs.CMPA.half.CMPA =SVREG.Tb ;
- EPwm1Regs.CMPB =SVREG.Tb;
- break;
-
- case 2:EPwm1Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm1Regs.CMPB =SVREG.Ta;
- break;
-
- case 3:EPwm1Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm1Regs.CMPB = SVREG.Ta;
- break;
-
- case 4:EPwm1Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm1Regs.CMPB = SVREG.Tc;
- break;
-
- case 5:EPwm1Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm1Regs.CMPB =SVREG.Tc;
- break;
-
- case 6:EPwm1Regs.CMPA.half.CMPA = SVREG.Tb;
- EPwm1Regs.CMPB =SVREG.Tb;
- break;
- }
- EPwm1Regs.ETCLR.bit.INT = 1;
- PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
- }
- interrupt void epwm2_timer_isr(void)
- {
- switch(sector)
- {
- case 1:EPwm2Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm2Regs.CMPB = SVREG.Ta;
- break;
- case 2:EPwm2Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm2Regs.CMPB =SVREG.Tc;
- break;
- case 3:EPwm2Regs.CMPA.half.CMPA = SVREG.Tb;
- EPwm2Regs.CMPB = SVREG.Tb;
- break;
-
- case 4:EPwm2Regs.CMPA.half.CMPA = SVREG.Tb;
- EPwm2Regs.CMPB = SVREG.Tb;
- break;
-
- case 5:EPwm2Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm2Regs.CMPB = SVREG.Ta;
- break;
-
- case 6:EPwm2Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm2Regs.CMPB =SVREG.Tc;
- break;
- }
-
- EPwm2Regs.ETCLR.bit.INT = 1;
- PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
- }
- interrupt void epwm3_timer_isr(void)
- {
- switch(sector)
- {
- case 1:EPwm3Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm3Regs.CMPB = SVREG.Tc;
- break;
- case 2:EPwm3Regs.CMPA.half.CMPA = SVREG.Tb;
- EPwm3Regs.CMPB = SVREG.Tb;
- break;
- case 3:EPwm3Regs.CMPA.half.CMPA = SVREG.Tc;
- EPwm3Regs.CMPB = SVREG.Tc;
- break;
-
- case 4:EPwm3Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm3Regs.CMPB = SVREG.Ta;
- break;
-
- case 5:EPwm3Regs.CMPA.half.CMPA = SVREG.Tb;
- EPwm3Regs.CMPB = SVREG.Tb;
- break;
-
- case 6:EPwm3Regs.CMPA.half.CMPA = SVREG.Ta;
- EPwm3Regs.CMPB = SVREG.Ta;
- break;
- }
-
-
- EPwm3Regs.ETCLR.bit.INT = 1;
- PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
- }
复制代码
最后还有关于配置EPWM模块的C文件和头文件,我就不粘了属于常规配置。
最后重申我的问题,就是编译时出现undefined first referenced
symbol in file
--------- ----------------
_SVREG ./SRC/SVPWM.obj
error: unresolved symbols remain
error: errors encountered during linking; "SVPWM_CONTROL.out" not built
导致编译不过。小弟急求!
一周热门 更多>