TMS320F2800137: Event trigger prescaling isn't correct at 1st interrupt

Part Number: TMS320F2800137
Other Parts Discussed in Thread: SYSCONFIG, C2000WARE

Hi expert,

I am using LP-F2800137 for EPWM event trigger usage, I use event trigger prescaling logic to make every 4th event to trigger EPWM interrupt. Event counter also initializate by 0.

image.png

However after power up, we can see that 1st interrupt are happened after 3 events, not 4th event. The second and following interrupt are happened at 4 events as we expected.

I also change the event count setting from 4 to 8, the result shows the interrupt happens at 7th event. See below waveform for more details. 

May I know why 1st interrupt are happened at (event count - 1)? 

image.png

IO change code:

image.png

Wiky

  • One remedy is to remove initialize the counter as 0. So unchecking the following will resolve your issue.

    Following explain the root cause and the remedy.

    When ETCNTINITCTL[INTINITEN] = 1 is enabled with ETCNTINIT[INTINIT] = 0 (refer TRM SPRUIX1B, Table 13-89 & Table 13-90), the counter initialization is triggered on the first SYNC event (CTR = 0). Since the interrupt source is also configured as CTR = 0, the SYNC event that loads INTCNT2 = 0 simultaneously increments it by 1 in the same cycle, making INTCNT2 effectively start at 1 before any real user events are counted (refer TRM SPRUIX1B, Section 13.10.1 — Counter Reset and Initialization). As a result, only N−1 additional events are needed to reach INTPRD2 = N, causing the first interrupt to fire one event early, which is consistent with your observation of first interrupt at 3rd event (count = 4) and 7th event (count = 8). There are two ways to fix this in SysConfig — either set "Interrupt Event Count Initial Value" to 1 instead of 0 to compensate for the initialization increment, or simply uncheck "Interrupt Event Count Initial Value Load Enable" if counter pre-initialization is not required for your application, which allows the counter to start cleanly from 0 without the unintended early trigger.

    Regards,

    Sumit

  • Hi Sumit,

    Thanks for your explanation, I understand the mechanism, but following your workaround I have different questions:

    Method 1: Set "Interrupt Event Count Initial Value" to 1 instead of 0: The result shows interrupt happens at N-2, key reason should be event count is count-up counter. But if I set "Interrupt Event Count Initial Value" to N instead of 0, that makes interrupt ahead of event counter. See waveform below.

    Interrupt Event Count Initial Value = 1, Interrupt Event Sources happens at CTR=0: Interrupt happens at N-2

    Interrupt Event Count Initial Value = N-1, Interrupt Event Sources happens at CTR=0: Interrupt happens at 1st event.

    As you mentioned "Since the interrupt source is also configured as CTR = 0", I change the Interrupt Event Sources happens at CTR=0, the interrupt still happens at N-1. That make me confused because it is conflicted with your description. 

    The EPWM2_B(channel 2 waveform) AQ already config to set high when CTP=Period for monitoring.

    The method 2 seems useless, even uncheck "Interrupt Event Count Initial Value Load Enable" , we get the same result. Interrupt happens at N-1 event. 

    Wiky

  • Wiky,

    With unchecking the interrupt initializing counter in sysconfig, You can try initializing manually in main function after board_init() to rule if there is sysconfig issue as follows:

    /* main.c */

    #include "driverlib.h"
    #include "device.h"
    #include "board.h" // This is the file generated by SysConfig

    // ... other includes ...

    void main(void)
    {
    // 1. Standard Device/System Initialization
    Device_init();
    Device_initGPIO();
    Interrupt_init();

    // 2. SysConfig Initialization
    // This is where SysConfig sets up your EPWM, but it might
    // inadvertently leave the ET counter at "1" due to the hardware bump.
    Board_init();

    // ==========================================================================
    // INSERT THE FIX HERE
    // ==========================================================================
    // This clears the "phantom" count that occurred during the Board_init() phase.
    // Replace 'myEPWM' with the actual name you gave the EPWM in SysConfig.

    // Step A: Clear the ET Interrupt flag
    EPWM_clearETInterruptFlag(myEPWM_BASE, EPWM_ET_INT_NUMBER_1);

    // Step B: (Optional but recommended) If your C2000Ware version supports it,
    // you can also clear the ETSEL/ETPS registers to ensure a clean state,
    // but clearing the INT flag is usually sufficient to reset the event sequence.
    // ==========================================================================

    // 3. Enable Global Interrupts
    Interrupt_enable(myEPWM_INT_1); // Replace with your SysConfig interrupt name
    EINT;
    ERTM;

    while(1)
    {
    // Application Logic
    }
    }

    Regards,

    Sumit

  • Hi Sumit,

    I follow the steps however it still have the same result, see my code and waveform below. Could you setup bench test at your side and provide a workable solution? We need to fix the issue in short time to secure prototype workable to meet project schedule, thanks.

    Wiky

  • Wiky, 

    can you try turn on gpio at the begin and turn off at the end and recheck?

    Also can you provide this project here?

    Regards,

    Sumit

  • Hi Sumit,

    Set pin at the beginning and clear at the end have the same result, check my project here. 

    epwm_ex2_updown_aq.zip

    Wiky

  • Thanks for providing the project. I will check this one and will get back to you by tomorrow.

    Regards,

    Sumit