#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "DSP2833x_GlobalConst.h"
#include "DSP2833x_Globalpara.h"
#include ".\source\app\AdcProcess.c"
#include ".\source\app\Timer.c"
#include ".\source\app\MotorCtrl.c"
#include "485.c"
#include "ECana.c"
#include "dmctype.h"
#include "rmp_cntl.h"
//#include "AD.h"
//#include "DA.h"
#include "Resolver.h"
CLARKE clarkeu=CLARKE_DEFAULTS;
CLARKE clarkei=CLARKE_DEFAULTS;
PARK parku=PARK_DEFAULTS;
PARK parki=PARK_DEFAULTS;
PIDREG3 pid1_PLL =PIDREG3_DEFAULTS;
PIDREG3 pid1_Speed =PIDREG3_DEFAULTS;
PIDREG3 pid1_idloop=PIDREG3_DEFAULTS;
PIDREG3 pid1_iqloop=PIDREG3_DEFAULTS;
IPARK iparku=IPARK_DEFAULTS;
PIDREG3 pid1_vdc =PIDREG3_DEFAULTS;
SPEED_ESTIMATION speed1=SPEED_ESTIMATION_DEFAULTS;
RMPCNTL rc1=RMPCNTL_DEFAULTS;
//AD Adv=AD_DEFAULTS;
//DA DAv=DA_DEFAULTS;
RESOLVER resolver=RESOLVER_DEFAULTS;
interrupt void MainIsr();
interrupt void adc_isr();
//interrupt void CpuTimer0Isr(void);
//interrupt void CpuTimer1Isr(void);
//interrupt void ISRExint(void);
//interrupt void ECanaISR(void);
//void InitMboxa(void);
//void ClrStatup(void);
float32 Ualpha1=0,Ubeta1=0,Ref_theta=0;
float Freq1=0;
int kk;
float32 minus=0,oldElecTheta=0;
Uint16 ledcont=0;
Uint16 INT3Count=0;
float32 Cosine1,Sine1;
float theta1=0,vdc1flt=0;
Uint32 iqcount=0;
Uint32 ao1=0;
int key=0,key1count=0,key2count=0;
//int kji=0,kreset=0,nreset=0;
/**************************************************************采样中断*********************************************************************/
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Current1[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Uint16 CURRENT1 = 0;
Uint16 iLo = 0;
Uint16 ILO_REF = 41800;
Uint16 ILo = 0;
Uint16 ILo_ref = 0;
Uint16 ILo_error = 0;
Uint16 ILo_Inter = 0;
Uint16 ILo_out = 0;
Uint16 Uzaibo = 0;
Uint16 Uzaibo_out = 0;
Uint16 ILo_P = 0;
Uint16 ILo_I = 0;
/***************************************************************主函数*********************************************************************/
#pragma CODE_SECTION(main,"ramfuncs")
void main(void)
{
DSP28x_usDelay(5000);
// Initialize System Control registers, PLL, WatchDog, Clocks to default state
// This function is found in the DSP280x_SysCtrl.c file
InitSysCtrl();
InitGpio();
InitSci();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitCpuTimers();
InitAdc();
// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
// EDIS;
InitEPwm();
// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
// EDIS;
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
EDIS;
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
PieVectTable.EPWM1_INT = &MainIsr;
EDIS; // This is needed to disable write to EALLOW protected registers
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitAdc(); // For this example, init the ADC
InitEPwm();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |=M_INT1; //开放CPUTimer0/AD/ePWM
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
IER |=M_INT3; //开放CPUTimer0/AD/ePWM
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
EALLOW;
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable EPWM1INT generation
EPwm1Regs.ETSEL.bit.INTSEL = 1; // Enable interrupt CNT_zero event
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate interrupt on the 1st event
EPwm1Regs.ETCLR.bit.INT = 1; // Enable more interrupts
EDIS;
EALLOW;
// Configure ADC
AdcRegs.ADCTRL3.bit.SMODE_SEL= 0x0; //同步采样模式
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf; //ADC采样时间选择
AdcRegs.ADCTRL3.bit.ADCCLKPS = OSCCLOCK; //ADC内核分频
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联工作方式
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联工作方式
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 1 conv's on SEQ1
//AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续采样
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1; //设置CONV0 为第一个通道
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1; //Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; //Enable SEQ1 interrupt (every EOS)
//AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续运行模式
//AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; //完成排序后,排序器指针回到最初状态
EDIS;
for(;;)
{
}
}
/**********************************************************EPWM中断程序*******************************************************************/
#pragma CODE_SECTION(MainIsr,"ramfuncs")
interrupt void MainIsr(void)
{
// float32 vdcMaxPU;
// float32 iMaxPU;
// float Kiu,Kiv;
ILo = iLo;
ILo_ref = ILO_REF;
ILo_error = ILo_ref-ILo;
ILo_Inter += ILo_error*ILo_I;
if(ILo_Inter > 400)
ILo_Inter = 400;
else if(ILo_Inter < -400)
ILo_Inter = -400;
ILo_out = ILo_Inter+ILo_P*ILo_error;
if(ILo_out > 500)
ILo_out = 500;
else if(ILo_out < -500)
ILo_out = -500;
Uzaibo = ILo_out/500.0;
// Uzaibo_out = -Uzaibo*30000/2+30000/2;
EPwm2Regs.TBPHS.half.TBPHS = 0.0*30000;//1.06*30000;
EPwm3Regs.TBPHS.half.TBPHS = 1.0*30000;//1.1538*30000;
EPwm4Regs.TBPHS.half.TBPHS = (1.1+0.5*Uzaibo)*30000;//0.1438*30000;
EPwm5Regs.TBPHS.half.TBPHS = (0.1+0.5*Uzaibo)*30000;//0.1438*30000;
EPwm2Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm3Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm4Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
EPwm5Regs.CMPA.half.CMPA = (0.4+Uzaibo)*30000;
//EPwm1Regs.CMPA.half.CMPA=30000/2;
//EPwm2Regs.CMPA.half.CMPA=30000/2;
EPwm1Regs.ETCLR.bit.INT =1;
DINT;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; //响应本次接收中断;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //开CPUTimer0中断
}
/********************************************************************采样中断*************************************************************/
#pragma CODE_SECTION(adc_isr,"ramfuncs")
interrupt void adc_isr(void)
{
Current1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
CURRENT1 +=Current1[ConversionCount];
// If 40 conversions have been logged, start over
if(ConversionCount == 19)
{
iLo = CURRENT1;
ConversionCount = 0;
CURRENT1= 0;
}
else
{
ConversionCount++;
}
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
/**************************************************************************************************************************************/
void ClrStatup(void)
{
Freq1=0;
pid1_vdc.Out=0;
pid1_vdc.Ref=0;
pid1_vdc.Fdb=0;
pid1_vdc.Ui=0;
pid1_iqloop.Out=0;
pid1_iqloop.Fdb=0;
pid1_iqloop.Ref=0;
pid1_iqloop.Ui=0;
pid1_idloop.Out=0;
pid1_idloop.Ref=0;
pid1_idloop.Fdb=0;
pid1_idloop.Ui=0;
iparku.Ds=0;
iparku.Qs=0;
}
请问:这个程序的两个中断都能进去,但是最终没有波形输出,这是为什么,错误在哪里? |