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.

CCS/TMS320F28027: ECAP interrupt and EPWM interrupt do not work at same time.

Part Number: TMS320F28027


Tool/software: Code Composer Studio

Dear all,

I wish to use ECAP interrupt to capture several pulse, and then change the duty cycle of PWM signal from EPWM ports. The PWM function is same as the example "Example_2802xEPwmUpDownAQ" which has about 3 interrupt already. I can use a external interrupt from keys to change the duty cycle of the PWM signal very well. However, after I add the ECAP interrupt into my program, the interrupt has never happened. I still can use the keys to change the PWM signal, but the ECAP function did not work. I learned the ECAP function from example "Example_2802xECap_Capture_Pwm". The example has only 1 interrupt, but my program has 4. The program is used to change the period of the PWM signal, but my program is used for duty cycle.

I tried to change the priority of the interrupts as the example "Example_2802xSWPrioritizedInterrupts". The problems have not really gone away.

Can some one help me please.

#define ISRS_GROUP3  (M_INT1|M_INT2|M_INT3|M_INT4)
#define ISRS_GROUP4  (M_INT1|M_INT3|M_INT4)  

   IER = 0x0000;
   IFR &= 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in f2802x_DefaultIsr.c.
// This function is found in f2802x_PieVect.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.EPWM1_INT = &epwm1_isr;
   PieVectTable.EPWM2_INT = &epwm2_isr;
   PieVectTable.EPWM3_INT = &epwm3_isr;
   PieVectTable.ECAP1_INT = &ecap1_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers



// Step 4. Initialize all the Device Peripherals:
// This function is found in f2802x_InitPeripherals.c
// InitPeripherals();  // Not required for this example

// For this example, only initialize the ePWM

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
   EDIS;

   InitEPwm1Example();
   InitEPwm2Example();
   InitEPwm3Example();
   InitECapture();
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
   EDIS;

// Step 5. User specific code, enable interrupts:


// Copy time critical code and Flash setup code to RAM
// This includes the following ISR functions: EPwm1_timer_isr(), EPwm2_timer_isr()
// EPwm3_timer_isr and and InitFlash();
// The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker.
   memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
   InitFlash();


// Enable CPU INT3 which is connected to EPWM1-3 INT:


   ECap1IntCount = 0;
   ECap1PassCount = 0;

   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;

   PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
   PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
   PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
   PieCtrlRegs.PIEIER4.bit.INTx1 = 1;

//   PieCtrlRegs.PIEIER3.all = 0x00FF;
//   PieCtrlRegs.PIEIER4.all = 0x00FF;

   PieCtrlRegs.PIEACK.all = (M_INT3|M_INT4);

   IER |= (M_INT3|M_INT4);

//   PieCtrlRegs.PIEIFR3.all = ISRS_GROUP3;
//   PieCtrlRegs.PIEIFR4.all = ISRS_GROUP4;

// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM

ECAP function:

void InitECapture()
{
   ECap1Regs.ECEINT.all = 0x0000;             // Disable all capture interrupts
   ECap1Regs.ECCLR.all = 0xFFFF;              // Clear all CAP interrupt flags
   ECap1Regs.ECCTL1.bit.CAPLDEN = 0;          // Disable CAP1-CAP4 register loads
   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0;        // Make sure the counter is stopped

   // Configure peripheral registers
   ECap1Regs.ECCTL2.bit.CONT_ONESHT = 1;      // One-shot
   ECap1Regs.ECCTL2.bit.STOP_WRAP = 3;        // Stop at 4 events
   ECap1Regs.ECCTL1.bit.CAP1POL = 1;          // Falling edge
   ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge
   ECap1Regs.ECCTL1.bit.CAP3POL = 1;          // Falling edge
   ECap1Regs.ECCTL1.bit.CAP4POL = 0;          // Rising edge
   ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation
   ECap1Regs.ECCTL1.bit.CTRRST2 = 1;          // Difference operation
   ECap1Regs.ECCTL1.bit.CTRRST3 = 1;          // Difference operation
   ECap1Regs.ECCTL1.bit.CTRRST4 = 1;          // Difference operation
   ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;         // Enable sync in
   ECap1Regs.ECCTL2.bit.SYNCO_SEL = 0;        // Pass through
   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units

   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter
   ECap1Regs.ECCTL2.bit.REARM = 1;            // arm one-shot
   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable CAP1-CAP4 register loads
   ECap1Regs.ECEINT.bit.CEVT4 = 1;            // 4 events = interrupt
}

Four interrupt:

__interrupt void epwm1_isr(void){my code}

__interrupt void epwm2_isr(void){my code}

__interrupt void epwm3_isr(void){my code}

__interrupt void ecap1_isr(void){my code}

  • Hello,

    Just to clarify, which of the 4 interrupts are not generated? If you place a breakpoint in each of the ISRs, which breakpoints are not hit? To help with debugging, I recommend looking at the register values for PIE, EPWM and ECAP in the CCS registers window.

    Regards,
    Elizabeth
  • Hi Elizabeth,

    Only the ECAP interrupt doesn't work. All the EPWM interrupts work well. I use both breakpoints and register to chekc the interrupts. The breakpoint in ECAP interrupts has never been hitted.

    The PIE registor show the INT3 for PWM and INT4 for ECAP are enable. The CMPA and CMPB value also changed when EPWM interrupts happened. However, the CAP1-4 value always be zero.

    In the example "Example_2802xECap_Capture_Pwm", the CAP 1-4 value changed when the interrupt happend everytime. The process also could stop at the breakpoint in ISR.

    I thought the problom come from the priority of hte interrupts, but i don't konw how to fix it in the right way. I tried to change the priority, but it doesn't work.

    Thanks,
    Shu

  • Hi Shu,

    Have you tried debugging with other settings for ECAP? For example, generating an interrupt at every capture event by modifying ECEINT and triggering on both falling and rising edges by modifying ECCTL1 if that is the configured PWM waveform.

    It may be an issue with interrupt priority, but it could also be the timing of events that cause the ECAP interrupt to not be triggered.

    Regards,
    Elizabeth