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.

TMS320F280039C: eCAP generating random value when ePWM1 is enabled

Part Number: TMS320F280039C
Other Parts Discussed in Thread: SYSCONFIG

Hi,

I am working on capturing the frequency of an external PWM signal while generating another PWM signal on Channel 1 (GPIO0 and 1). Without the PWM, the eCAP module is working perfectly. I get the time duration of the event in ISR and then on the main loop run some calculations on it. 

When I enable the PWM signal by sending a serial command, the value which I'm getting in eCAP ISR turns out to be wrong and random.  Can you help me out with what's happening over here and how to solve it? 

  • Hi Rishabh, just to clarify, is the serial command you're referring to being sent to your F280039C from your computer? When you enable your PWM on channel 1, are you getting the correct output from that ePWM on your oscilloscope?

    Could you share your code so that we can test your configuration?

  • Hi Luke,

    Yes, the serial command I'm referring to is being sent by computer to the F280039C. I'm getting the expected output on my PWM channel 1 on my oscilloscope. 

    Below if my ePWM code

                // configure pins as PWM
                // configure pins as GPIO
    
                if(complement_required){
                    GPIO_setPinConfig(GPIO_0_EPWM1_A);
                    GPIO_setPadConfig(GATE_HB1_HS, GPIO_PIN_TYPE_STD);
                    GPIO_setQualificationMode(GATE_HB1_HS, GPIO_QUAL_SYNC);
    
                    GPIO_setPinConfig(GPIO_1_EPWM1_B);
                    GPIO_setPadConfig(GATE_HB1_LS, GPIO_PIN_TYPE_STD);
                    GPIO_setQualificationMode(GATE_HB1_LS, GPIO_QUAL_SYNC);
                }
                else if(primary_pin == HS){
                    GPIO_setPinConfig(GPIO_1_GPIO1);
                    GPIO_setDirectionMode(GATE_HB1_LS, GPIO_DIR_MODE_OUT);
                    GPIO_setPadConfig(GATE_HB1_LS, GPIO_PIN_TYPE_STD);
                    GPIO_setMasterCore(GATE_HB1_LS, GPIO_CORE_CPU1);
                    GPIO_setQualificationMode(GATE_HB1_LS, GPIO_QUAL_SYNC);
                    GPIO_writePin(GATE_HB1_LS, 0);
    
                    GPIO_setPinConfig(GPIO_0_EPWM1_A);
                    GPIO_setPadConfig(GATE_HB1_HS, GPIO_PIN_TYPE_STD);
                    GPIO_setQualificationMode(GATE_HB1_HS, GPIO_QUAL_SYNC);
                }
                else{
                    GPIO_setPinConfig(GPIO_0_GPIO0);
                    GPIO_setDirectionMode(GATE_HB1_HS, GPIO_DIR_MODE_OUT);
                    GPIO_setPadConfig(GATE_HB1_HS, GPIO_PIN_TYPE_STD);
                    GPIO_setMasterCore(GATE_HB1_HS, GPIO_CORE_CPU1);
                    GPIO_setQualificationMode(GATE_HB1_HS, GPIO_QUAL_SYNC);
                    GPIO_writePin(GATE_HB1_HS, 0);
    
                    GPIO_setPinConfig(GPIO_1_EPWM1_B);
                    GPIO_setPadConfig(GATE_HB1_LS, GPIO_PIN_TYPE_STD);
                    GPIO_setQualificationMode(GATE_HB1_LS, GPIO_QUAL_SYNC);
                }
                
    
                EPWM_setClockPrescaler(GATE_HB1_BASE, EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_1);
    
                EPWM_setTimeBaseCounter(GATE_HB1_BASE, 0);
                EPWM_setTimeBaseCounterMode(GATE_HB1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
                EPWM_disablePhaseShiftLoad(GATE_HB1_BASE);
                EPWM_setPhaseShift(GATE_HB1_BASE, 0);
                EPWM_setSyncInPulseSource(GATE_HB1_BASE, EPWM_SYNC_IN_PULSE_SRC_DISABLE);
    
                EPWM_setCounterCompareShadowLoadMode(GATE_HB1_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);
                EPWM_setCounterCompareValue(GATE_HB1_BASE, EPWM_COUNTER_COMPARE_B, 0);
                EPWM_setCounterCompareShadowLoadMode(GATE_HB1_BASE, EPWM_COUNTER_COMPARE_B, EPWM_COMP_LOAD_ON_CNTR_ZERO);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    
    
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    
    
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
                EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    
                if(complement_required){
                    EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                    EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                    EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                    EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                    EPWM_setDeadBandDelayPolarity(GATE_HB1_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);
                    EPWM_setDeadBandDelayMode(GATE_HB1_BASE, EPWM_DB_RED, true);
                    EPWM_setDeadBandDelayMode(GATE_HB1_BASE, EPWM_DB_FED, true);
    
                    if(primary_pin == HS){	
                        EPWM_setDeadBandOutputSwapMode(GATE_HB1_BASE, EPWM_DB_OUTPUT_A, false);
                        EPWM_setDeadBandOutputSwapMode(GATE_HB1_BASE, EPWM_DB_OUTPUT_B, false);
                    }
                    else{	
                        EPWM_setDeadBandOutputSwapMode(GATE_HB1_BASE, EPWM_DB_OUTPUT_A, true);
                        EPWM_setDeadBandOutputSwapMode(GATE_HB1_BASE, EPWM_DB_OUTPUT_B, true);
                    }
    
                    EPWM_setRisingEdgeDelayCount(GATE_HB1_BASE, rising_edge_dead_time_register);
                    EPWM_setFallingEdgeDelayCount(GATE_HB1_BASE, falling_edge_dead_time_register);
                }
                else{
                    EPWM_setDeadBandDelayPolarity(GATE_HB1_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);
                    EPWM_setDeadBandDelayMode(GATE_HB1_BASE, EPWM_DB_RED, false);
                    EPWM_setDeadBandDelayMode(GATE_HB1_BASE, EPWM_DB_FED, false);
                    if(primary_pin == HS){
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                        	
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                        
                    }
                    else{
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                        	
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
                        EPWM_setActionQualifierAction(GATE_HB1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
                    }
                }
    
    
                EPWM_setTimeBasePeriod(GATE_HB1_BASE, period_register);
    //            EPWM_setCounterCompareValue(GATE_HB1_BASE, EPWM_COUNTER_COMPARE_A, period_register);
    //            if(soft_start > 0){
    //                start_soft_start(soft_start, 10, period_register, compare_register);
    //            }
    //            else{
                    EPWM_setCounterCompareValue(GATE_HB1_BASE, EPWM_COUNTER_COMPARE_A, compare_register);
    //            }
                break;

    Below is my ISR for eCAP

    extern volatile uint16_t temp1Count;
    
    __interrupt void INT_TEMP_MEAS_ISR(void){
        temp1Count = ECAP_getEventTimeStamp(TEMP_MEAS_BASE, ECAP_EVENT_4);
    
        ECAP_clearInterrupt(TEMP_MEAS_BASE,ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
        ECAP_clearGlobalInterrupt(TEMP_MEAS_BASE);
    
        //
        // Start eCAP
        //
        ECAP_reArm(TEMP_MEAS_BASE);
    
        //
        // Acknowledge the group interrupt for more interrupts.
        //
        Interrupt_clearACKGroup(INT_TEMP_MEAS_INTERRUPT_ACK_GROUP);
    }

    Following is my sysconfig for eCAP

    Below is my backend code which does frequency calculation

    extern uint16_t temp1Count;
    
    frequency = 60000/temp1Count;
    

    Let me know if you need anything else.

  • Hi Rishahb,

    What are you getting for your temp1Count?

    I have set up a similar configuration with an input pulse wave coming in at 500KHz with 50% duty cycle to inputxbar which goes to the ECAP, and then outputting an EPWM signal from EPWM3.

    This is what I am getting from CCS. The derivedDT variable is the duty cycle I am reading from the ECAP which is correct and aligns with my signal generator that is generating the pulse wave.

    Here is the attached code. Maybe try running this and see what you get?

    //#############################################################################
    //
    // FILE:    ecap_capture_pwm.c
    //
    // TITLE:   Capture ePWM3.
    //
    //! \addtogroup driver_example_list
    //! <h1>eCAP Capture PWM Example</h1>
    //!
    //! This example configures ePWM3A for:
    //! - Up count mode
    //! - Period starts at 500 and goes up to 8000
    //! - Toggle output on PRD
    //!
    //! eCAP1 is configured to capture the time between rising
    //! and falling edge of the ePWM3A output.
    //!
    //! \b External \b Connections \n
    //! - eCAP1 is on GPIO16
    //! - ePWM3A is on GPIO4
    //! - Connect GPIO4 to GPIO16.
    //!
    //! \b Watch \b Variables \n
    //! - \b ecap1PassCount - Successful captures.
    //! - \b ecap1IntCount - Interrupt counts.
    //
    //#############################################################################
    //
    //
    // $Copyright:
    // Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    
    //
    // Defines
    //
    #define PWM3_TIMER_MIN     600U
    #define PWM3_TIMER_MAX     8000U
    #define EPWM_TIMER_UP      1U
    #define EPWM_TIMER_DOWN    0U
    
    //
    // Globals
    //
    uint32_t ecap1IntCount;
    uint32_t ecap1PassCount;
    uint32_t epwm3TimerDirection;
    volatile uint16_t cap1Count;
    volatile uint16_t cap2Count;
    volatile uint16_t cap3Count;
    volatile uint16_t cap4Count;
    volatile uint16_t epwm3PeriodCount;
    float derivedDT;
    
    //
    // Function Prototypes
    //
    void error(void);
    void initECAP(void);
    void initEPWM(void);
    __interrupt void INT_myECAP0_ISR(void);
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Configure GPIO4/5 as ePWM3A/3B
        //
        GPIO_setPadConfig(4,GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_4_EPWM3_A);
        GPIO_setPadConfig(5,GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_5_EPWM3_B);
        //
        // Configure GPIO 16 as eCAP input
        //
        XBAR_setInputPin(INPUTXBAR_BASE, XBAR_INPUT7, 16);
        GPIO_setPinConfig(GPIO_16_GPIO16);
        GPIO_setDirectionMode(16, GPIO_DIR_MODE_IN);
        GPIO_setQualificationMode(16, GPIO_QUAL_ASYNC);
        Interrupt_register(INT_ECAP1, &INT_myECAP0_ISR);
    
        //
        // Board initialization
        // Configure GPIO 16 as eCAP input
        // Enable interrupts required for this example
        //
    //    Board_init();
    
        //
        // Configure ePWM
        //
        initEPWM();
        initECAP();
    
        //
        // Initialize counters:
        //
        cap2Count = 0U;
        cap3Count = 0U;
        cap4Count = 0U;
        ecap1IntCount = 0U;
        ecap1PassCount = 0U;
        epwm3PeriodCount = 0U;
        Interrupt_enable(INT_ECAP1);
    
        //
        // Enable Global Interrupt (INTM) and Real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop forever. Suspend or place breakpoints to observe the buffers.
        //
        for(;;)
        {
           NOP;
        }
    }
    
    //
    // initEPWM - Configure ePWM
    //
    void initEPWM()
    {
        //
         // Disable sync(Freeze clock to PWM as well)
         //
         SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
         //
         // Configure ePWM 3
         //       Counter runs in up-count mode.
         //       Action qualifier will toggle output on period match
         //
    
    
         EPWM_setTimeBaseCounterMode(EPWM3_BASE, EPWM_COUNTER_MODE_UP);
         EPWM_setTimeBasePeriod(EPWM3_BASE, PWM3_TIMER_MIN);
         EPWM_setPhaseShift(EPWM3_BASE, 0U);
         EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE,
                                              EPWM_COUNTER_COMPARE_A,
                                              EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
         EPWM_setCounterCompareValue(EPWM3_BASE, EPWM_COUNTER_COMPARE_A,
                                     PWM3_TIMER_MIN >> 1);
         EPWM_setActionQualifierAction(EPWM3_BASE,
                                       EPWM_AQ_OUTPUT_A,
                                       EPWM_AQ_OUTPUT_HIGH,
                                       EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
         EPWM_setActionQualifierAction(EPWM3_BASE,
                                       EPWM_AQ_OUTPUT_A,
                                       EPWM_AQ_OUTPUT_LOW,
                                       EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
         EPWM_setClockPrescaler(EPWM3_BASE,
                                EPWM_CLOCK_DIVIDER_1,
                                EPWM_HSCLOCK_DIVIDER_2);
    
         epwm3TimerDirection = EPWM_TIMER_UP;
    
         //
         // Enable sync and clock to PWM
         //
         SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
    }
    //
    // initECAP - Configure eCAP
    //
    void initECAP()
    {
        //
        // Disable ,clear all capture flags and interrupts
        //
        ECAP_disableInterrupt(ECAP1_BASE,
                              (ECAP_ISR_SOURCE_CAPTURE_EVENT_1  |
                               ECAP_ISR_SOURCE_CAPTURE_EVENT_2  |
                               ECAP_ISR_SOURCE_CAPTURE_EVENT_3  |
                               ECAP_ISR_SOURCE_CAPTURE_EVENT_4  |
                               ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
                               ECAP_ISR_SOURCE_COUNTER_PERIOD   |
                               ECAP_ISR_SOURCE_COUNTER_COMPARE));
        ECAP_clearInterrupt(ECAP1_BASE,
                            (ECAP_ISR_SOURCE_CAPTURE_EVENT_1  |
                             ECAP_ISR_SOURCE_CAPTURE_EVENT_2  |
                             ECAP_ISR_SOURCE_CAPTURE_EVENT_3  |
                             ECAP_ISR_SOURCE_CAPTURE_EVENT_4  |
                             ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
                             ECAP_ISR_SOURCE_COUNTER_PERIOD   |
                             ECAP_ISR_SOURCE_COUNTER_COMPARE));
    
        //
        // Disable CAP1-CAP4 register loads
        //
        ECAP_disableTimeStampCapture(ECAP1_BASE);
    
        //
        // Configure eCAP
        //    Enable capture mode.
        //    One shot mode, stop capture at event 4.
        //    Set polarity of the events to rising, falling, rising, falling edge.
        //    Set capture in time difference mode.
        //    Select input from XBAR7.
        //    Enable eCAP module.
        //    Enable interrupt.
        //
        ECAP_stopCounter(ECAP1_BASE);
        ECAP_enableCaptureMode(ECAP1_BASE);
    
        ECAP_setCaptureMode(ECAP1_BASE, ECAP_ONE_SHOT_CAPTURE_MODE, ECAP_EVENT_4);
    
        ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_1, ECAP_EVNT_RISING_EDGE);
        ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_2, ECAP_EVNT_FALLING_EDGE);
        ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_3, ECAP_EVNT_RISING_EDGE);
        ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_4, ECAP_EVNT_FALLING_EDGE);
    
        ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_4);
    
        XBAR_setInputPin(INPUTXBAR_BASE, XBAR_INPUT7, 16);
    
        ECAP_enableLoadCounter(ECAP1_BASE);
        ECAP_setSyncOutMode(ECAP1_BASE, ECAP_SYNC_OUT_SYNCI);
        ECAP_startCounter(ECAP1_BASE);
        ECAP_enableTimeStampCapture(ECAP1_BASE);
        ECAP_reArm(ECAP1_BASE);
    
        ECAP_enableInterrupt(ECAP1_BASE, ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
    }
    //
    // myECAP0 ISR
    //
    __interrupt void INT_myECAP0_ISR(void)
    {
        //
        // Get the capture counts. Each capture should be 2x the ePWM count
        // because of the ePWM clock divider.
        //
        cap1Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_1);
        cap2Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_2);
        cap3Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_3);
        cap4Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_4);
        derivedDT = (float)(cap2Count-cap1Count)/(cap3Count-cap1Count);
    
        //
        // Compare the period value with the captured count
        //
        epwm3PeriodCount = EPWM_getTimeBasePeriod(EPWM3_BASE);
    
    
        //
        // Count correct captures
        //
        ecap1PassCount++;
    
        //
        // Clear interrupt flags for more interrupts.
        //
        ECAP_clearInterrupt(ECAP1_BASE,ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
        ECAP_clearGlobalInterrupt(ECAP1_BASE);
    
        //
        // Start eCAP
        //
        ECAP_reArm(ECAP1_BASE);
    
        //
        // Acknowledge the group interrupt for more interrupts.
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP4);
    }
    
    //
    // error - Error function
    //
    void error()
    {
        ESTOP0;
    }
    

  • Hi ,

    I took a look into this and this I believe is actually the example code that I got most of my inspiration from. I'll try it out again tomorrow. Meanwhile, my temp1Cap value is exactly what it is supposed to be when no PWM is running. When a PWM1 is running with dead band, trip zone and other stuff, my temp1Count value is getting f** up. 

    My current suspect is one of the other interrupt (probably PWM or UART or Timer) might be taking a higher priority and messing this up. Note, for my application, it is also fine to have a one-shot capture as long as the PWM is running in the background. 

    Kindl suggest my next steps. Meanwhile I'll try the example tomorrow and let you know the result. 

  • Hi Rishabh,

    I would kindly suggest to try and see if you can get the same output as I have or something similar. That way we might find that this problem could be having other interrupts taking a higher priority.

    Another thing to note is that within your Sysconfig I noticed you enabled counter reset on each Event 1, 2, 3, 4. With this in mind, when you are reading from temp1Count on event 4, it will be a count value that is not the total count from event 1 to event 4. The counter will have some counter value that is between event 3 and event 4.

    Try and only enable counter reset on event 4 and see if that is of any help?