TI中文支持网
TI专业的中文技术问题搜集分享网站

DS9 28377中 ADC中断和TIMER0中断冲突 关闭TIMER0中断程序正常 开启后进入interrupt void ADCA1_ISR(void)

main.c

#include "F28x_Project.h"
__interrupt void adca1_isr(void);
__interrupt void epwm1_isr(void);
__interrupt void cpu_timer0_isr(void);
#include "adc.h"
#include "epwm.h"
#include "pid.h"
#include "timer.h"

#define RESULTS_BUFFER_SIZE 256
Uint16 AdcaResults;
Uint16 resultsIndex;
float V=0;
volatile Uint16 bufferFull;
Uint16 sum=0,ave=0;
extern int PwmValue;


void main(void)
{InitSysCtrl();InitGpio();EPWM1_Init(2000);DINT;InitPieCtrl();IER = 0x0000;IFR = 0x0000;InitPieVectTable();EALLOW;PieVectTable.ADCA1_INT = &adca1_isr;//中断向量表指向中断EDIS;EALLOW;PieVectTable.EPWM1_INT=&epwm1_isr;EDIS;PieCtrlRegs.PIEIER1.bit.INTx1 = 1;//ADCPieCtrlRegs.PIEIER3.bit.INTx1=1;//EPWMConfigureADC();ConfigureEPWM();SetupADCEpwm(0);Time0_Init(60,500000);PID_M1_Init();IER |= M_INT1;  //使能CPU的INT1IER|=M_INT3;EINT;ERTM;PieCtrlRegs.PIECTRL.bit.ENPIE = 1;EALLOW;CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;EDIS;do{EPwm1Regs.ETSEL.bit.SOCAEN = 1;//使能EPWMXSOCA启动ADCEPwm1Regs.TBCTL.bit.CTRMODE = 0;//上升计数EPwm1Regs.ETSEL.bit.SOCAEN = 0;//关闭转换EPwm1Regs.TBCTL.bit.CTRMODE = 3;//停止计数}while(1);
}




__interrupt void adca1_isr(void)
{

	AdcaResults= AdcaResultRegs.ADCRESULT0;
	V=(float)3.3*AdcaResults/4096;
	AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}



__interrupt void epwm1_isr(void)
{EPwm1Regs.CMPB.bit.CMPB= PwmValue;// EPwm1Regs.CMPA.bit.CMPA=0;EPwm1Regs.ETCLR.bit.INT=1;PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}


timer.c

/*
 * timer.c
 *
 *  Created on: 2020年7月22日
 *Author: 汪
 */



#include "timer.h"
#include "F2837xD_cputimer.h"
#include "pid.h"

Uint16 i=0;
__interrupt void cpu_timer0_isr(void);
extern PIDTypdDef M1PID;
extern PIDTypdDef M2PID;
int PwmValue=0;
extern float V;
void Time0_Init(float Freq,double time)
{InitSysCtrl();DINT;IER = 0x0000;IFR = 0x0000;InitPieVectTable();EALLOW;PieVectTable.TIMER0_INT = &cpu_timer0_isr;EDIS;InitCpuTimers();ConfigCpuTimer(&CpuTimer0, 60, 500000);CpuTimer0Regs.TCR.all = 0x4001;InitGpio();EALLOW;GpioCtrlRegs.GPEMUX1.bit.GPIO133 = 0;GpioCtrlRegs.GPEDIR.bit.GPIO133 = 1;EDIS;IER |= M_INT1;PieCtrlRegs.PIEIER1.bit.INTx7 = 1;EINT;ERTM;


}


__interrupt void cpu_timer0_isr(void)
{PID_M1_SetPoint(5);PID_M1_SetKp(200);PID_M1_SetKi(0.1);PID_M1_SetKd(0);PwmValue = PID_M1_PosLocCalc(V);if(PwmValue > 2000)  PwmValue=  2000;if(PwmValue < -2000) PwmValue = -2000;PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //清除中断应答位

}
在开启TIMEO中断后 程序进入

interrupt void ADCA1_ISR(void)
{
// Insert ISR Code here

// To receive more interrupts from this PIE group,
// acknowledge this interrupt.
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code

asm (" ESTOP0");
for(;;);
}

Susan Yang:

请您私信一下您的程序,我们会在开发板测试后给您回复。

另外您现在使用的自己的板子?

Susan Yang:

回复 user6394136:

很高兴能帮到您

赞(0)
未经允许不得转载:TI中文支持网 » DS9 28377中 ADC中断和TIMER0中断冲突 关闭TIMER0中断程序正常 开启后进入interrupt void ADCA1_ISR(void)
分享到: 更多 (0)