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.

TMS320F28377S: ECAP TIME STAMP capture values are varying

Part Number: TMS320F28377S

Tool/software:

Hi 

I configured ECAP1 to measure period values of EPWM9, here in the modified version of example code that i made to work for my application.

void initEPWM()
{
//
// Disable sync(Freeze clock to PWM as well)
//
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

//
// Configure ePWM
// Counter runs in up-count mode.
// Action qualifier will toggle output on period match
//
EPWM_setTimeBaseCounterMode(EPWM9_BASE, EPWM_COUNTER_MODE_UP);
EPWM_setTimeBasePeriod(EPWM9_BASE, 1000);
EPWM_setPhaseShift(EPWM9_BASE, 0U);
/**
* Set up shadowing
*/
EPWM_setCounterCompareShadowLoadMode(EPWM9_BASE,
EPWM_COUNTER_COMPARE_A,
EPWM_COMP_LOAD_ON_CNTR_ZERO);
/**
* Set Compare values
*/
// 1.667us Clock pulse width
EPWM_setCounterCompareValue(EPWM9_BASE,
EPWM_COUNTER_COMPARE_A,
400);
EPWM_setActionQualifierAction(EPWM9_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_HIGH,
EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
EPWM_setActionQualifierAction(EPWM9_BASE,
EPWM_AQ_OUTPUT_A,
EPWM_AQ_OUTPUT_LOW,
EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO );
EPWM_setClockPrescaler(EPWM9_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);

//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_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);

XBAR_setInputPin(XBAR_INPUT7, 74);

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);
}

//
// eCAP 1 ISR
//
__interrupt void ecap1ISR(void)
{
//
// Get the capture counts. Each capture should be 4x the ePWM count
// because of the ePWM clock dividers.
//
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);

//
// Compare the period value with the captured count
//
epwm3PeriodCount = EPWM_getTimeBasePeriod(EPWM9_BASE);

if(cap2Count > ((epwm3PeriodCount * 4) + 4) ||
cap2Count < ((epwm3PeriodCount * 4) - 4))
{
error();
}

else if(cap3Count > ((epwm3PeriodCount * 4) + 4) ||
cap3Count < ((epwm3PeriodCount * 4) - 4))
{
error();
}

else if(cap4Count > ((epwm3PeriodCount * 4) + 4) ||
cap4Count < ((epwm3PeriodCount * 4) - 4))
{
error();
}
else
{
flag = 0;
}

ecap1IntCount++;

The timestamp capture values are reading fine.

I am getting an Issue when implementing, ECAP1 with my actual code, where there are other epwm configurations (epwm1, 2, 3) and 

I am using syncout sel mode to keep these in sync as they need to have some phase shift.

The time stamp  values are varying.

I want to know does syncout sel effect ecap TSCTR which is clocked from sysclk.

only when i disable the syncout sel configuration from epwm1 then only i get proper timestamp value.

i found this in Reference manual, my understanding is ecap synchronization is only for other ecap modules then why the syncout sel is effecting the ecap

Thanks & regards

Rupa

  • Hi Rupa,

    SYNCOUT select does not affect eCAP's TSCTR since eCAP is in capture mode. 

    Best,

    Ryan Ma

  • Hi Ryan,

    Yes it should not affect TSCTR of ECAP, But my observations are:

    Since I am using epwm 1 that is interfering with the eCAP time stamp capture values and thus it is not able to give the exact capture value.

    When I am disabling the EPWM1 configurations, the ecap time stamp capture value is reading fine.
    What could be the issue in this case?

  • Hi Rupa, 

    Can you double check your eCAPs configuration for ECCTL2.SYNCI_EN register value? Is it 0? This should disable the sync-in option for that eCAP. Let me rephrease what I had mentioned earlier. SYNCOUT select should not affect eCAP TSCTR if you have disabled sync in option.  If you still see the same behavior can you try setting the SYNCSELECT.ECAP1SYNCIN to be sourced from a PWM that does not generate any SYNCOUT?

    Best,

    Ryan Ma

  • since i am configuring using driverlib functions i didnt find the SYNCI_EN , then do I need to use the ECCTL2.SYNCI_EN register only. 

    I had tried using SYNCSELECT.ECAP1SYNCIN to be sourced from a different. PWM But at that time i did not check ECCTL2.SYNCI_EN register configuration.

  • To ensure that the eCAP TSCTR is not affected by the ePWM's syncout I would verify to see if the register ECCT2.SYNCI_EN is set or not. If it is 0, then the EPWM's syncout should not affect it. But please do verify this.

    Best,

    Ryan Ma