This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
/****************************************************************************************************/
/*作 者:DSP28335开发人员 */
/*日 期:2013-11-8 */
/****************************************************************************************************/
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "DSP2833x_Delay.h"
#include "math.h"
interrupt void cpu_timer0_isr(void);
interrupt void epwm1_isr(void);
void EPwm1Setup();
void EPwm2Setup();
void EPwm3Setup();
//Uint16 Voltage1[10];
//Uint16 Voltage2[10];
/************************ SVPWM Parameter Set*********************************/
float PI = 3.141592;
float Theta;
int Uin=300;
int Uout=100; // changed
float M;
float Ualpha, Ubeta;
float A, B, C;
int Sector;
float X, Y, Z;
float Ta, Tb, Tc;
int PreFre=0, On_OffFre=201; // changed
float t1, t2, t11, t21;
/*********************************************主函数**************************************************/
void main(void)
{
// float v;
DINT;
InitSysCtrl(); // 初始化系统寄存器
// InitFlash(); // 初始化Flash
InitPieCtrl(); // 初始化中断控制寄存器
IER=0X0000;
IFR=0X0000;
InitPieVectTable(); // 初始化中断向量表
// 初始化通用IO寄存器
EPwm1Setup();
EPwm2Setup();
EPwm3Setup();
//Config_ADC_A();
//InitCpuTimers(); // 初始化定时器
ConfigCpuTimer(&CpuTimer0, 150, 1000000); // 配置定时器(定时器标号、频率、周期)
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.EPWM1_INT = &epwm1_isr;
EDIS;
CpuTimer0Regs.TCR.all = 0x4001; // CPU定时器中断使能
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // CPUTimer0
PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // epwm1
IER = 0X0181;
IER |= 0x1000;
IER |= 0X2000;
IER |= 0X0020;
IER |= M_INT3;
EINT;
ERTM; //开实时中断
while(1)
{
}
}
/***************************************中断服务程序***************************************************/
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all |= 0x0001;
}
interrupt void epwm1_isr(void) // the interrupt can write the SVPWM algorithm
{
// Update the CMPA and CMPB values
DINT;
Sector = 0;
Theta = 2*PI*PreFre/(On_OffFre*1.0); // angle obtain
PreFre++;
if(PreFre >= On_OffFre)
PreFre = 0;
if(PreFre <= 0)
PreFre = 0;
M = ((float)(Uout*1.0))/ Uin; // modulation obtain
Ualpha = M*sin(Theta); // get alpha
Ubeta = M*cos(Theta); // get beta
A = Ubeta; // 2/3 conversion
B = -0.5*Ubeta + 0.866*Ualpha;
C = -0.5*Ubeta - 0.866*Ualpha;
if(A>0) Sector = 1; // sector judge
if(B>0) Sector += 2;
if(C>0) Sector += 4;
X = Ubeta; // timer obtain
Y = 0.5*Ubeta + 0.866*Ualpha;
Z = 0.5*Ubeta - 0.866*Ualpha;
if(Sector == 1)
{
t1 = Z;
t2 = Y;
t11 = t1;
t21 = t2;
//if(t11+t21>1)
//{
//t1 = t11/(t11+t21);
//t2 = t21/(t11+t21);
//}
Tb = 0.5*(1-t1-t2); // six on_off tube on_off time obtain
Ta = Tb + t1;
Tc = Ta + t2;
}
else if(Sector == 2)
{
t1 = Y;
t2 = -X;
t11 = t1;
t21 = t2;
// if(t11+t21>1)
//{
// t1 = t11/(t11+t21);
// t2 = t21/(t11+t21);
//}
Ta = 0.5*(1-t1-t2);
Tc = Ta + t1;
Tb = Tc + t2;
}
else if(Sector == 3)
{
t1 = -Z;
t2 = X;
t11 = t1;
t21 = t2;
//if(t11+t21>1)
//{
//t1 = t11/(t11+t21);
// t2 = t21/(t11+t21);
//}
Ta = 0.5*(1-t1-t2);
Tb = Ta + t1;
Tc = Tb + t2;
}
else if(Sector == 4)
{
t1 = -X;
t2 = Z;
t11 = t1;
t21 = t2;
//if(t11+t21>1)
//{
// t1 = t11/(t11+t21);
// t2 = t21/(t11+t21);
//}
Tc = 0.5*(1-t1-t2);
Tb = Tc + t1;
Ta = Tb + t2;
}
else if(Sector == 5)
{
t1 = X;
t2 = -Y;
t11 = t1;
t21 = t2;
//if(t11+t21>1)
//{
// t1 = t11/(t11+t21);
//t2 = t21/(t11+t21);
//}
Tb = 0.5*(1-t1-t2);
Tc = Tb + t1;
Ta = Tc + t2;
}
else if(Sector == 6)
{
t1 = -Y;
t2 = -Z;
t11 = t1;
t21 = t2;
//if(t11+t21>1)
//{
// t1 = t11/(t11+t21);
//t2 = t21/(t11+t21);
//}
Tc = 0.5*(1-t1-t2);
Ta = Tc + t1;
Tb = Ta + t2;
}
EPwm1Regs.CMPA.half.CMPA=(int16)(7500*Ta); // on_off time go to DSP PWM
EPwm2Regs.CMPA.half.CMPA=(int16)(7500*Tb);
EPwm3Regs.CMPA.half.CMPA=(int16)(7500*Tc);
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
EINT; //开全局中断
}
/****************************************Interrupt Function End*********************************************/
/************************************中断服务程序结束***************************************************/
大神帮我看看什么原因