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.

EPWM Interrupt not firing

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

Hello all,

I am trying to fire ePWM1 interrupt when the PWM timer reaches zero or the PRD value. I found that the interrupt doesnot fire and morever halts the PWM waveforms when initialized with the interript settings. When I do not initialize the interrupts, the waveforms show up as expected. 

/**********************************************************************
* Function: InitEPwm()
*wy
* Description: Initializes the Enhanced PWM modules on the F28x7x
**********************************************************************/
void InitEPwm(void)
{
asm(" EALLOW");						// Enable EALLOW protected register access

	// Configure the prescaler to the ePWM modules.  Max ePWM input clock is 100 MHz.
	ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 1;		// EPWMCLK divider from PLLSYSCLK.  0=/1, 1=/2

	// Must disable the clock to the ePWM modules if you want all ePWM modules synchronized.
	CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;

	asm(" EDIS");						// Disable EALLOW protected register access
	//=====================================================================
	// Config
	// Initialization Time
	//========================
	// EPWM Module 1 config
	EPwm1Regs.TBPRD = 500;
	// Period = 900 TBCLK counts
	EPwm1Regs.TBPHS.bit.TBPHS = 0;

	//EPwm1Regs.TBCTL.bit.PHSDIR = 0; //count down after sync
	// Set Phase register to zero
	EPwm1Regs.TBCTL.bit.CTRMODE = 3; //stop timer
	// Symmetrical mode
	EPwm1Regs.TBCTL.bit.PHSEN = 0; //enable phase loading

	EPwm1Regs.TBCTL.bit.PHSDIR = 0; //count down after sync
	// Master module
	EPwm1Regs.TBCTL.bit.PRDLD = 0; //load on CTR = 0
	EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; //CTR = 0
	EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; //using 100MHz clock

	// Sync down-stream module
	EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0; //shadow updates
	EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0; //shadow updates
	EPwm1Regs.CMPCTL.bit.LOADAMODE = 2; //load on CTR = PRD or CTR = 0
	// load on CTR=Zero
	EPwm1Regs.CMPCTL.bit.LOADBMODE = 2; //load on CTR = PRD or CTR = 0
	// load on CTR=Zero
	EPwm1Regs.AQCTLA.bit.CAU = 1;  //clear on compare
	// set actions for EPWM1A
	EPwm1Regs.AQCTLA.bit.PRD = 2; //set on ctr = PRD

	EPwm1Regs.AQCTLB.bit.CAU = 2;  //clear on compare
	// set actions for EPWM1A
	EPwm1Regs.AQCTLB.bit.PRD = 1; //set on ctr = PRD
  EPwm1Regs.ETSEL.bit.INTSEL = 011; // Enable event time-base counter equal to zero or period
    EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
    EPwm1Regs.ETPS.bit.INTPRD = 01; // Generate INT on 1st event

    //EALLOW;
          //PieVectTable.EPWM1_INT = &epwm1_isr;
          //PieVectTable.EPWM2_INT = &epwm2_isr;
          IER |= 0x0004; //Enable INT3
          PieCtrlRegs.PIEIER3.bit.INTx1 = 1; //Enable PIE Group 3's Channel 1 (Which happens to be the ePWM1 )
            //PieCtrlRegs.PIEIFR3.bit.INTx1 = 0; //Interrupt flag is cleared. Ready to be set by the interrupt peripheral
}

/**********************************************************************
* Function: InitPieCtrl()
*
* Description: Initializes and enables the PIE interrupts on the F28x7x
**********************************************************************/
void InitPieCtrl(void)
{
//--- Disable interrupts
	asm(" SETC INTM, DBGM");			// Disable global interrupts

//--- Initialize the PIE_RAM.  There are:
//    32 base vectors + (12 PIE groups * 16 vectors/group) = 224 PIE vectors (448 words).
	PieCtrlRegs.PIECTRL.bit.ENPIE = 0;	// Disable the PIE
	asm(" EALLOW");						// Enable EALLOW protected register access

	// Step around the first three 32-bit locations (six 16-bit locations).
	// These locations are used by the ROM bootloader during debug.
	memcpy((Uint16 *)&PieVectTable+6, (Uint16 *)&PieVectTableInit+6, 448-6);

	asm(" EDIS");						// Disable EALLOW protected register access

//--- Disable all PIE interrupts
	PieCtrlRegs.PIEIER1.all =  0x0000;
	PieCtrlRegs.PIEIER2.all =  0x0000;
	PieCtrlRegs.PIEIER3.all =  0x0000;
	PieCtrlRegs.PIEIER4.all =  0x0000;
	PieCtrlRegs.PIEIER5.all =  0x0000;
	PieCtrlRegs.PIEIER6.all =  0x0000;
	PieCtrlRegs.PIEIER7.all =  0x0000;
	PieCtrlRegs.PIEIER8.all =  0x0000;
	PieCtrlRegs.PIEIER9.all =  0x0000;
	PieCtrlRegs.PIEIER10.all = 0x0000;
	PieCtrlRegs.PIEIER11.all = 0x0000;
	PieCtrlRegs.PIEIER12.all = 0x0000;

//--- Clear any potentially pending PIEIFR flags
	PieCtrlRegs.PIEIFR1.all  = 0x0000;
	PieCtrlRegs.PIEIFR2.all  = 0x0000;
	PieCtrlRegs.PIEIFR3.all  = 0x0000;	
	PieCtrlRegs.PIEIFR4.all  = 0x0000;
	PieCtrlRegs.PIEIFR5.all  = 0x0000;
	PieCtrlRegs.PIEIFR6.all  = 0x0000;
	PieCtrlRegs.PIEIFR7.all  = 0x0000;
	PieCtrlRegs.PIEIFR8.all  = 0x0000;
	PieCtrlRegs.PIEIFR9.all  = 0x0000;
	PieCtrlRegs.PIEIFR10.all = 0x0000;
	PieCtrlRegs.PIEIFR11.all = 0x0000;
	PieCtrlRegs.PIEIFR12.all = 0x0000;

//--- Acknowlege all PIE interrupt groups
	PieCtrlRegs.PIEACK.all = 0xFFFF;

//--- Enable the PIE
	PieCtrlRegs.PIECTRL.bit.ENPIE = 1;		// Enable the PIE


} // end of InitPieCtrl()

/**********************************************************************
* Function: main()
*
* Description: Main function for C28x workshop labs
**********************************************************************/
void main(void)
{
//--- CPU Initialization
	InitSysCtrl();						// Initialize the CPU (FILE: SysCtrl.c)
	InitGpio();							// Initialize the shared GPIO pins (FILE: Gpio.c)
	InitXbar();							// Initialize the input, output & ePWM X-Bar (FILE: Xbar.c)
	InitPieCtrl();						// Initialize and enable the PIE (FILE: PieCtrl.c)
	InitWatchdog();						// Initialize the Watchdog Timer (FILE: WatchDog.c)

//--- Peripheral Initialization
	//InitAdca();							// Initialize the ADC-A (FILE: Adc.c)
	//InitDacb();                         // Initialize the DAC-B (File: Dac.c)
    //Interrupt settings

	InitEPwm();							// Initialize the EPwm (FILE: EPwm.c) 



//--- Enable global interrupts
	asm(" CLRC INTM, DBGM");			// Enable global interrupts and realtime debug

//--- Main Loop
	while(1)							// endless loop - wait for an interrupt
	{
		asm(" NOP");
	}


} //end of main()

interrupt void EPWM1_ISR(void)						// PIE3.1 @ 0x000D60  ePWM1 interrupt
{
    static volatile Uint16 GPIO34_count = 0;            // Counter for pin toggle

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;			// Must acknowledge the PIE group

    EPwm1Regs.ETCLR.bit.INT = 1; //clear the EPWM interrupt flag

	if(GPIO34_count++ > 25000)                  // Toggle slowly to see the LED blink
	    {
	        GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;  // Toggle the pin
	        GPIO34_count = 0;                       // Reset the counter
	    }
// Next two lines for debug only - remove after inserting your ISR
	asm (" ESTOP0");								// Emulator Halt instruction
	while(1);
}