TI中文支持网
TI专业的中文技术问题咨询交流网站

TMS320F280021: 使用ePWM触发ADC,使用ADCINT2中断,中断程序运行不正常

Part Number:TMS320F280021

Dear all:

在使用epwm触发ADC时,使用ADCA1配置为ADCINT1中断,程序可以正常运行,相关程序如下程序如下:

EALLOW;
PieVectTable.ADCA1_INT = &adcA1ISR; // Function for ADCA interrupt 1
EDIS;

IER |= M_INT1;//T0 ADCINT1

PieCtrlRegs.PIEIER1.bit.INTx1 = 1;// ADCINT1

EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 3; // Select SOC on up-count
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

EPwm1Regs.CMPA.bit.CMPA = 430; // Set compare A value to 2048 counts
EPwm1Regs.TBPRD = 862; // Set period to 4096 counts

EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter

AdcaRegs.ADCSOC0CTL.bit.CHSEL = 7; // SOC0 will convert pin A1
// 0:A0 1:A1 2:A2 3:A3
// 4:A4 5:A5 6:A6 7:A7
// 8:A8 9:A9 A:A10 B:A11
// C:A12 D:A13 E:A14 F:A15
AdcaRegs.ADCSOC0CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // Trigger on ePWM1 SOCA

AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 0; //不连续
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared

__interrupt void adcA1ISR(void)
{
LED_FLASH=1;

Current.Sum+=AdcaResultRegs.ADCRESULT0;
if(++Current.ConversionCount==80)
{
Current.ConversionCount=0;
Current.Data=(Current.Sum/80);
Current.Sum=0;

EALLOW;
EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Enable SOC on A group
EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Unfreeze, and enter up count mode
EDIS;
}
//
// Clear the interrupt flag
//
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;

//
// Check if overflow has occurred
//
if(1 == AdcaRegs.ADCINTOVF.bit.ADCINT1)
{
AdcaRegs.ADCINTOVFCLR.bit.ADCINT1 = 1; //clear INT1 overflow flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
}

//
// Acknowledge the interrupt
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

上面测试代码中在定时中使能ePWM 开启

EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Unfreeze, and enter up count mode

转换80个周期,每个周期时间是17.2us, 使用 LED_FLASH=1; 测试管脚来查看转换的周期和每个周期的个位。

上述程序运行正常。

但是ADCINT1已经被其他功能占用,配置到ADCINT2 中断上,使用发现就不能正常运行,相关程序如下:

EALLOW;
PieVectTable.ADCA2_INT  = &adcA2ISR;// Function for ADCA interrupt 2
EDIS;

IER |= M_INT10; //ADCINT2

PieCtrlRegs.PIEIER10.bit.INTx2 = 1;// ADCINT2

EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 3; // Select SOC on up-count
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

EPwm1Regs.CMPA.bit.CMPA = 430; // Set compare A value to 2048 counts
EPwm1Regs.TBPRD = 862; // Set period to 4096 counts

EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter

AdcaRegs.ADCSOC1CTL.bit.CHSEL = 7; // SOC1 will convert pin A1
// 0:A0 1:A1 2:A2 3:A3
// 4:A4 5:A5 6:A6 7:A7
// 8:A8 9:A9 A:A10 B:A11
// C:A12 D:A13 E:A14 F:A15
AdcaRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5; // Trigger on ePWM1 SOCA

AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 1; // End of SOC0 will set INT2 flag
AdcaRegs.ADCINTSEL1N2.bit.INT2E = 1; // Enable INT2 flag
AdcaRegs.ADCINTSEL1N2.bit.INT2CONT = 0; //不连续
AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1; // Make sure INT2 flag is cleared

__interrupt void adcA2ISR(void)
{
LED_FLASH=1;

Current.Sum+=AdcaResultRegs.ADCRESULT1;
if(++Current.ConversionCount==80)
{
Current.ConversionCount=0;
Current.Data=(Current.Sum/80);
Current.Sum=0;

EALLOW;
EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Enable SOC on A group
EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Unfreeze, and enter up count mode
EDIS;
}
//
// Clear the interrupt flag
//
AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1;

//
// Check if overflow has occurred
//
if(1 == AdcaRegs.ADCINTOVF.bit.ADCINT2)
{
AdcaRegs.ADCINTOVFCLR.bit.ADCINT2 = 1; //clear INT2 overflow flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1; //clear INT2 flag
}

//
// Acknowledge the interrupt
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

通过示波器测试LED_FLASH=1; 管脚上的电平转换时间是20ms,运行不正常

也没查找出是什么具体原因。

原来之前使用的是28065也是这么使用,可以正常工作,插入一段28065的程序

PieVectTable.ADCINT1= &adc_isr;// ADC SignalPieVectTable.ADCINT2= &adc_current_isr;// ADC currentIER |= M_INT1;// T0 ADCINT1PieCtrlRegs.PIEIER1.bit.INTx1 = 1;// ADCINT1P1.1PieCtrlRegs.PIEIER1.bit.INTx2 = 1;// ADCINT2	EALLOW;

	AdcRegs.ADCCTL1.bit.ADCREFSEL = 1;//外部电源参考
	AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;//结果存入寄存器才产生中断

	AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 1;//同时采样

	AdcRegs.ADCSOC0CTL.bit.CHSEL = 0;//soc通道选择
//	AdcRegs.ADCSOC1CTL.bit.CHSEL = 8;
	AdcRegs.ADCSOC0CTL.bit.ACQPS = 25;//采样时间  25
	AdcRegs.ADCSOC1CTL.bit.ACQPS = 25;
	AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1;//

	AdcRegs.ADCSAMPLEMODE.bit.SIMULEN2 = 1;//同时采样
	AdcRegs.ADCSOC2CTL.bit.CHSEL = 1;//soc通道选择
//	AdcRegs.ADCSOC3CTL.bit.CHSEL = 9;
	AdcRegs.ADCSOC2CTL.bit.ACQPS = 50;//采样时间  20
	AdcRegs.ADCSOC3CTL.bit.ACQPS = 50;
	AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 5;//set SOC2 start trigger on EPWM1A, due to round-robin SOC2 converts first then SOC3
//	AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 5;//set SOC3 start trigger on EPWM1A, due to round-robin SOC2 converts first then SOC3

	//EPwm1Regs.ETSEL.bit.SOCAEN	= 1;		// Enable SOC on A group
	EPwm1Regs.ETSEL.bit.SOCASEL	= 3;		// Enable event time-base counter equal to zero or period
	EPwm1Regs.ETPS.bit.SOCAPRD 	= 1;		// Generate pulse on 1st event

	AdcRegs.INTSEL1N2.bit.INT2SEL = 2;//中断线2选择soc3
	AdcRegs.INTSEL1N2.bit.INT2CONT = 0;//不连续
	AdcRegs.INTSEL1N2.bit.INT2E = 1;//中断使能

	AdcRegs.INTSEL1N2.bit.INT1SEL = 1;//中断线1选择soc1
	AdcRegs.INTSEL1N2.bit.INT1CONT = 0;//不连续
	AdcRegs.INTSEL1N2.bit.INT1E = 1;//中断使能
	EDIS;
	

28065 ADCINT1和ADCINT2都能正常运行。

请大家帮忙分析280021 上如何正常使用ADCINT2,(ADCINT1已经被占用),并且必须是在PWM触发上去ADC中断。

Green Deng:

你好,粗看了一下代码,有一句:

AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 1; // End of SOC0 will set INT2 flag

按照注释的说明,应该是:

AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 0; // End of SOC0 will set INT2 flag

你看看这么修改是否有效。

,

Huit Wu:

注释我忘记更改了,实际我配置到SOC1上

EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 3; // Select SOC on up-count EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

EPwm1Regs.CMPA.bit.CMPA = 430; // Set compare A value to 2048 counts EPwm1Regs.TBPRD = 862; // Set period to 4096 counts

EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter

AdcaRegs.ADCSOC1CTL.bit.CHSEL = 7; // SOC0 will convert pin A1 // 0:A0 1:A1 2:A2 3:A3 // 4:A4 5:A5 6:A6 7:A7 // 8:A8 9:A9 A:A10 B:A11 // C:A12 D:A13 E:A14 F:A15 AdcaRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5; // Trigger on ePWM1 SOCA

AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 1; // End of SOC1 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT2E = 1; // Enable INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT2CONT = 0; //不连续 AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1; // Make sure INT1 flag is cleared

实际可以进入ADCINT2中断,只是进入中断的时间不是EPWM的周期触发的,固定20ms

,

Green Deng:

看到你发布了新帖,后续将在新帖中回复:e2echina.ti.com/…/tms320f280021-2800x-adc-pie-adcint1-adcint2

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F280021: 使用ePWM触发ADC,使用ADCINT2中断,中断程序运行不正常
分享到: 更多 (0)