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.

TMS320F28335 eCAP interrupt always occurs twice

I'm trying to use the eCAP function to create a rectified sine wave that is synchronized to a square wave that is applied to the eCAP input.  It works, however there is some unwanted jitter and I've found something that is strange to me.  To understand the situation, here's a little background:  I'm using the sine wave in the lookup table provided.  When the eCAP interrupt occurs, the period of the square wave is calculated and the lookup table is zeroed.  It seems to work, but when I trigger on the eCAP ISR, I notice that the ISR is executed twice and the sine wave lookup index is only zeroed on the second execution.  I'm a hardware guy, so I set a bit when the ISR is entered, clear it after same executions, set it again after some executions, and clear it upon exit.  I observe this bit on a scope.  

To make the double execution more evident I added a dummy delay in the ISR of about 600uS (see ISR code below).  When I enter the ISR, I set the trigger bit.  My intention is to next zero the lookup table index, but it doesn't happen.  The trigger bit stays set for 600uS, it is then cleared and held in that state for 600uS.  The trigger bit is then set, the interrupts are re-enabled, the trigger bit is cleared, and the trigger bit is set again as the ISR is executed again.  Why is it executed again?  

Anyway, the lookup table index is zeroed the second time as evidenced by the yellow trace below.  The slow decay of the yellow trace is due to an RC filter placed on the PWM representation of the rectified sine wave.  After the 2 600uS dummy delays, we finally exit the eCAP1_isr and the lookup table generates the rectified sine wave until the next eCAP interrupt.

void Setup_eCAP1(void)
{
//---------------------------------------------------------------------
//--- Configure eCAP1 unit for capture
//---------------------------------------------------------------------
ECap1Regs.ECEINT.all = 0;   // Disable all eCAP interrupts
ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disabled loading of capture results
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Stop the counter

ECap1Regs.TSCTR = 0; // Clear the counter
ECap1Regs.CTRPHS = 0; // Clear the counter phase register

ECap1Regs.ECCTL2.all = 0x0096; // ECAP control register 2

ECap1Regs.ECCTL1.all = 0x01C4; // ECAP control register 1

ECap1Regs.ECEINT.all = 0x0008; // Enable desired eCAP interrupts

}

interrupt void eCAP1_isr(void)

{
int i;
int k;

GpioDataRegs.GPBSET.bit.GPIO49 = 1; // Turn on LED4
linear_idx=0; // reset table index to syncronize to input
for (k = 0; k <10000; k++);
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1; // Turn off LED4
for (i = 0; i <10000; i++);
GpioDataRegs.GPBSET.bit.GPIO49 = 1; // Turn on LED4

ECap1Regs.ECCLR.bit.INT = 1; // Clear the ECAP1 interrupt flag
ECap1Regs.ECCLR.bit.CEVT3 = 1; // Clear the CEVT3 flag

// Calculate the input frequency period (rising edge to rising edge)
Freq_Period = (unsigned long)ECap1Regs.CAP3 - (unsigned long)ECap1Regs.CAP1;

//linear_idx=0; // reset table index to syncronize to input

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; // Must acknowledge the PIE group 4
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1; // Turn off LED4
}

The blue trace is the square wave that I'm trying to synchronize to.   The green trace is the trigger bit.  The second rising edge of the trigger bit is actually a rising edge after the second dummy delay, then a falling edge after the interrupts are re-enabled and then a rising edge as the interrupt is executed the second time.  This just looks like one edge on this time base setting since all of these edges occur in a couple of hundred nanaseconds.  The last narrow pulse of the trigger bit is the program exiting the ISR where it is free to generate the rectified sine wave.

I can set the qualification on the eCAP input for maximum filtering and it behaves identically to no filtering. 

Please help.

  • I think you may be getting two interrupts because of the order of these two instructions:

    ECap1Regs.ECCLR.bit.INT = 1; // Clear the ECAP1 interrupt flag
    ECap1Regs.ECCLR.bit.CEVT3 = 1; // Clear the CEVT3 flag

    The first clears the global eCAP interrupt and enables any pending interrupts to re-trigger, but since CEVT3 is still set the global flag immediately goes back to 1 and you get another interrupt.  See figure 8 in the user's guide.  The second time through it works because CEVT3 has already been cleared.

    Can you swap the order of these two instructions and see if it behaves?

    Regards,

    Richard 

  • That did it Richard.  Thank you very much.

    You may mark the question resolved.

    I'd appreciate a quick opinion, if you have the time.  

    We're pretty good analog engineers with our first foray into digital control being a single phase PFC unit.  Instead of adding the complication of a PLL to synchronize to the utility, we were going to synthesize a full wave rectified sine wave based on the sine wave lookup table provided by ti for our reference.  The eCAP interrupt will call an ISR to determine the frequency of the input and reset the counter for the lookup table.  It seems to be working pretty well without the power switches doing their thing.  I plan on filtering the input sine wave that we'll be generating our reference from pretty heavily with an external RC having a known phase shift.  I'll account for the phase shift due to the RC by phase shifting the lookup table.  I'd have turned on the power stage already, but I'm doing all of the development on a development kit from ti as I await our control board.

    Do you see pitfalls with this technique that I'm not accounting for?  I guess if one has a working PLL function they would use it, but if one doesn't have it, hopefully this will work.

  • Thanks for posting back.

    I think your approach should work fine. We have worked with several customers who generate the PFC current reference using a similar technique. You probably already know about the C2000 development kits for PFC so I won't list them here. None of the kits use a software reference so I regret there isn't any off-the-shelf reference code I can point you towards.

    Regards,

    Richard