TMS320F28379D: Help with ECAP not correctly capturing PWM input

Part Number: TMS320F28379D

Tool/software:

I am trying to configure eCap to continuously measure Period and Duty of a PWM input.  I am testing with a 50% duty 10kHz PWM.  ePWM0 generates the PWM, and I connect EPWM0A on the LaunchPad to the appropriate input also on the LaunchPad, GPIO104, with Xbar configured appropriately.

With a Logic Analyzer I confirmed the 50% duty cycle on GPIO104.

I see the CAP1 register as 0x26FB, CAP2=0x1C, CAP3=0x26FB,CAP4=0x1C, which of course does not match the 50% duty cycle.  

Below are configuration details, based mainly on ecap_ex2_capture_pwm.c.  Any suggestion on why I'm not capturing the PWM correctly?

Thanks!

GPIO configuration:

GPIO_setPinConfig(GPIO_104_GPIO104);
GPIO_setDirectionMode(104, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(104, GPIO_PIN_TYPE_STD);

XBAR_setInputPin(XBAR_INPUT7, 104);

ECAP Config:

ECAP_setCaptureMode(ECAP1_BASE, ECAP_CONTINUOUS_CAPTURE_MODE, ECAP_EVENT_4);

ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_1, ECAP_EVNT_FALLING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_2, ECAP_EVNT_RISING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_3, ECAP_EVNT_FALLING_EDGE);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_4, ECAP_EVNT_RISING_EDGE);

ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_1);
ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_2);
ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_3);
ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_4);

ECAP_enableLoadCounter(ECAP1_BASE);
ECAP_startCounter(ECAP1_BASE);
ECAP_enableTimeStampCapture(ECAP1_BASE);
ECAP_reArm(ECAP1_BASE);

ECAP_enableInterrupt(ECAP1_BASE, ECAP_ISR_SOURCE_CAPTURE_EVENT_4);

  • Some further comment:

    The Falling Edge captures seem to be correct.  The values there are ~50us, which matches.  It is the rising edge that is off.

    If I switch which edges are rising and falling, the issue follows the rising edge:

    ECAP_setEventPolarity(ecap_bases[i], ECAP_EVENT_1, ECAP_EVNT_RISING_EDGE);
    ECAP_setEventPolarity(ecap_bases[i], ECAP_EVENT_2, ECAP_EVNT_FALLING_EDGE);
    ECAP_setEventPolarity(ecap_bases[i], ECAP_EVENT_3, ECAP_EVNT_RISING_EDGE);
    ECAP_setEventPolarity(ecap_bases[i], ECAP_EVENT_4, ECAP_EVNT_FALLING_EDGE);


    If I set all edges to rising edge, I get 0x1C for all CAP registers.

    So it seems the rising edge capture is the issue.

    I have also tried all different settings for input qualification, with no change in behavior.

  • Hi Mark Feller,

    First can you confirm if the example 2 of the eCAP works as expected? I am able to correctly run this example.

    I also switched the example over to sample from pin 104. I see no issues.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    //#############################################################################
    //
    // 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.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Best,

    Ryan Ma

  • Hi Ryan,

    The example2  works.  I changed to pin 104, and also changed to EPWM1, and the example2  still works. 

    I switched to one-shot mode in my project, in order to match the example, and there is still the issue with rising edge capture.  If I look at the register contents for ECAP1, these all look as expected.

  • I provided code snippet for your configuration for pin 104. I didn't see any issues with using epwm1.

    Can you confirm?

    Best,

    Ryan Ma

  • Hi Ryan,

    The issue is related to the call to ECAP_enableLoadCounter(ECAP1_BASE);

    This is setting ECCTL2.SYNCI_EN.  If I disable this in my project, the issue goes away, and ECAP behaves normally.  

    I am configuring XBARINPUT5 for other purposes, but have the GPIO floating/disconnected.  XBARINPUT5 is connected to EXTSYNC1

  • Hi Mark, 

    Got it, sync in was being set causing TSCTR to change.

    Good catch!

    Best regards,

    Ryan Ma