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.

Missing first edge with eCAP module

Other Parts Discussed in Thread: TMS320F28069

I am using the eCAP Module with a TMS320F28069 and I seem to be missing the first edge sometimes, I do not get an interrupt for the first event.

 

When we reset our system, our system will send out a couple of resets back to back and the CPU will end up getting reinitialized a couple of times within a second or two. On the first initialization, if the input to the eCAP is low, the eCAP is setup to look for a rising edge for the first event. Then a second or two later our system will send out a second reset event and at this point the input to the eCAP will be high, so the eCAP is setup now to look for a falling edge first. When this sequence happens, I do not get an interrupt for the first edge. If the input to the eCAP is always high for the first and second initializations, and the eCAP is setup to look for a falling edge both times, this seems to always work.

 

Before I initialize the eCAP, I set the input to a GPIO first and read what state the line is at, high or low. This way I know what event to look for first, a falling or rising edge. When it does not work, the first eCAP event that gets triggered by the interrupt is event 2, not event 1. So it looks like event 1 did occur, I just did not get an interrupt for it. After it starts to work, it is fine thereafter, I just don’t get an interrupt for every edge.

 

Any ideas what can be happening?

 

Below is how the eCAP is being setup -

 

// GPIO24 AC SIGNAL

GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1; // eCAP1

 

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

 

// Capture Control Reg 1

if (eCAP_Input == High)

   ECap1Regs.ECCTL1.bit.CAP1POL = 1;     // 0   Capture Event 1 Polarity select - Falling Edge

else

 ECap1Regs.ECCTL1.bit.CAP1POL = 0;     // 0   Capture Event 1 Polarity select - Rising Edge

 

ECap1Regs.ECCTL1.bit.CTRRST1 = 0;     // 1   Counter Reset on Capture Event 1 - No Reset

 

if (eCAP_input== High)

   ECap1Regs.ECCTL1.bit.CAP2POL = 0;     // 2   Capture Event 2 Polarity select - Rising Edge

else

   ECap1Regs.ECCTL1.bit.CAP2POL = 1;     // 2   Capture Event 2 Polarity select - Falling Edge

 

 

ECap1Regs.ECCTL1.bit.CTRRST2 = 1;     // 3   Counter Reset on Capture Event 2 - Reset

ECap1Regs.ECCTL1.bit.CAP3POL = 0;     // 4   Capture Event 3 Polarity select

ECap1Regs.ECCTL1.bit.CTRRST3 = 0;     // 5   Counter Reset on Capture Event 3

ECap1Regs.ECCTL1.bit.CAP4POL = 0;     // 6   Capture Event 4 Polarity select

ECap1Regs.ECCTL1.bit.CTRRST4 = 0;     // 7   Counter Reset on Capture Event 4

ECap1Regs.ECCTL1.bit.CAPLDEN = 0;     // 8   Enable Loading CAP1-4 regs on a Cap Event - Disbled

ECap1Regs.ECCTL1.bit.PRESCALE = 0;   // 13:9 Event Filter prescale select - Divide by 1

ECap1Regs.ECCTL1.bit.FREE_SOFT = 10; // 15:14   Emulation mode - Run Free

 

// Capture Control Reg 2

ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;     // 0   Continuous or one-shot - Continuous

ECap1Regs.ECCTL2.bit.STOP_WRAP = 1;       // 2:1 "Stop value for one-shot, Wrap for continuous", Wrap after Capture Event 2

ECap1Regs.ECCTL2.bit.REARM = 0;           // 3   One-shot re-arm

ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;       // 4   TSCNT counter stop

ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;       // 5   Counter sync-in select

ECap1Regs.ECCTL2.bit.SYNCO_SEL = 3;       // 7:6 Sync-out mode

ECap1Regs.ECCTL2.bit.SWSYNC = 0;         // 8   SW forced counter sync

ECap1Regs.ECCTL2.bit.CAP_APWM = 0;       // 9   CAP/APWM operating mode select

ECap1Regs.ECCTL2.bit.APWMPOL = 0;         // 10   APWM output polarity select

 

// ECAP interrupt enable

ECap1Regs.ECEINT.bit.CEVT1 = 1;           // 1   Capture Event 1 Interrupt Enable

ECap1Regs.ECEINT.bit.CEVT2 = 1;           // 2   Capture Event 2 Interrupt Enable

ECap1Regs.ECEINT.bit.CEVT3 = 0;           // 3   Capture Event 3 Interrupt Enable

ECap1Regs.ECEINT.bit.CEVT4 = 0;           // 4   Capture Event 4 Interrupt Enable

ECap1Regs.ECEINT.bit.CTROVF = 0;         // 5   Counter Overflow Interrupt Enable

ECap1Regs.ECEINT.bit.CTR_EQ_PRD1 = 0;     // 6   Period Equal Interrupt Enable

ECap1Regs.ECEINT.bit.CTR_EQ_CMP = 0;     // 7   Compare Equal Interrupt Enable

 

// ECAP interrupt clear

ECap1Regs.ECCLR.bit.INT = 1;             // 0   Global Flag

ECap1Regs.ECCLR.bit.CEVT1 = 1;           // 1   Capture Event 1 Interrupt Flag

ECap1Regs.ECCLR.bit.CEVT2 = 1;           // 2   Capture Event 2 Interrupt Flag

ECap1Regs.ECCLR.bit.CEVT3 = 1;           // 3   Capture Event 3 Interrupt Flag

ECap1Regs.ECCLR.bit.CEVT4 = 1;           // 4   Capture Event 4 Interrupt Flag

ECap1Regs.ECCLR.bit.CTROVF = 1;           // 5   Counter Overflow Interrupt Flag

ECap1Regs.ECCLR.bit.CTR_EQ_PRD1 = 1;     // 6   Period Equal Interrupt Flag

 

 

 

 

  • Hi Stephen,

    What is the the variable eCAP_Input? When is the value updated?

    I see that you are choosing the GPIO24 to be ecap input.

    // GPIO24 AC SIGNAL

    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1; // eCAP1

    Also, you mention -

    Before I initialize the eCAP, I set the input to a GPIO first and read what state the line is at, high or low.

    Is this where you assign the eCAP_input variable?

    Is the variable always reflecting the correct value of the pin?


    -Bharathi.

  • The variable eCAP_input is a variable that is set reflecting the state of the input pin, GPIO24.  On startup, I set GPIO24 to an input and read what state this input is at, high or low.  After I find out what state the input is at, then I set the eCAP_input variable to reflect this and then setup the eCAP registers. 

    The state of GPIO24 input is always appears to be correct when I read it on startup.

  • Stephen,

    You mentioned earlier that 

     "When it does not work, the first eCAP event that gets triggered by the interrupt is event 2, not event 1. So it looks like event 1 did occur, I just did not get an interrupt for it."

    It seems like the edge occurred, and capture event is generated for the same. But interrupt is not enabled.
    Can you make sure interrupt for the capture event is enabled before this?
    From the code, it seems like the interrupt is enabled later.
    I'm wondering if it's just the timing of the edge occurrence and it's happening before the interrupt gets enabled in the system.

    What is the status of the ECFLG register? Does it reflect CEVT1?

    -Bharathi.

  • The interrupts are enabled.   I can wait for many minutes before triggering an event, the initialization should only take a few seconds.  When I do trigger the event, the CEVTx pins all stay at 0 when I don't get the first interrupt.  

    When I first power up the system, everything works OK.  But if I do a reset (without powering down), then the system might not generate the interrupt.  It is like the eCAP module remembers where it leaves off at.  Even though the input is high after the reset, if the last time the eCAP module ran and the input was low, then it is like the module starts off thinking the input is low.  When I reset the system I disabled the clock to the module in order to try to reset and put it in a state like on power up.   Is there a better way to reset the eCAP module.

  • Did you try writing 1 to ECap1Regs.ECCTL2.bit.REARM bit?

    -Bharathi.