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.

TMS320F280025C: phase shift ePWM problem

Part Number: TMS320F280025C

Hi everyone,

Excuse me but I have exchanged on this subject with S, but the topic has closed and I have others questions.

You can see a screen shot. Why when I set phase = 120° ePWM2 is OK with correct phase shift with ePWM1 and ePWM3 isn't OK ? Can you explain me more please ? If I understand correctly we must reverse the direction by TBPHSDIR on UP and DOWN count but I can't do it.

Thanks

My code : 

void set_phase(uint32_t base, uint16_t phi)
{
    uint16_t phase;

    if(base == myEPWM2_BASE)
    {
        //EPWM_setCountModeAfterSync(base, EPWM_COUNT_MODE_UP_AFTER_SYNC);
        phase = ((float)phi * HWREGH(base + EPWM_O_TBPRD) * 2 / 360); // *2 to adapt scale on UP and DOWN Count mode
    }

    if(base == myEPWM3_BASE)
    {
        //EPWM_setCountModeAfterSync(base, EPWM_COUNT_MODE_UP_AFTER_SYNC);
        phase = ((float)phi * 2 * HWREGH(base + EPWM_O_TBPRD) * 2 / 360);
    }

    EPWM_enableSyncOutPulseSource(base, EPWM_SYNC_OUT_PULSE_ON_SOFTWARE);
    EPWM_forceSyncPulse(base);

    EPWM_setPhaseShift(base, phase);
    EPWM_setTimeBaseCounter(base, phase);
    EPWM_enablePhaseShiftLoad(base);
}
float PWM_Freq_TBCLK = (float) SYSCLK / (PWM_HIGHSPEED_PRESCALER * PWM_PRESCALER);

*TBCLK = 1. / PWM_Freq_TBCLK;

PWM_period = 1. / PWM_FREQ;

time_FED_RED = (FED + RED) * 0.000001;

PWM_period += time_FED_RED;

*TBPRD_boost_3 = PWM_Freq_TBCLK / (PWM_FREQ * 2);
*CMPA_boost_3 = ((float) (100 - duty_boost_3) / 100) * (*TBPRD_boost_3);
void epwm_init(uint32_t base)
{
    float PWM_TBPRD_1;
    float PWM_TBPRD_2;
    float PWM_TBPRD_3;
    float PWM_CMPA_1;
    float PWM_CMPA_2;
    float PWM_CMPA_3;
    EPWM_ClockDivider PWM_PARAM_PRESCALER;
    EPWM_HSClockDivider PWM_PARAM_HIGHSPEEDPRESCALER;
    float TBCLK;

    if(base == myEPWM1_BASE)
    {
        get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);

        // Parameters
        EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_1);
        EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_B, (uint16_t)PWM_CMPA_1);
        EPWM_setPhaseShift(base, 0U);
        EPWM_disablePhaseShiftLoad(base);
        EPWM_setTimeBaseCounter(base, 0U);
        EPWM_enableSyncOutPulseSource(myEPWM1_BASE, EPWM_SYNC_OUT_PULSE_ON_CNTR_ZERO);
    }

    else if (base == myEPWM2_BASE)
    {
        get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);

        // Parameters
        EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_2);
        EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_A, (uint16_t)PWM_CMPA_2);
        EPWM_setPhaseShift(base, 0U);
        EPWM_disablePhaseShiftLoad(base);
        EPWM_setTimeBaseCounter(base, 0U);
        EPWM_setSyncInPulseSource(base, EPWM_SYNC_IN_PULSE_SRC_SYNCOUT_EPWM1);

        set_phase(base, PHI);

    }

    else if(base == myEPWM3_BASE)
    {
        get_pwm_clock_from_freq(base , &PWM_TBPRD_1 , &PWM_TBPRD_2 , &PWM_TBPRD_3 , &PWM_CMPA_1 , &PWM_CMPA_2 , &PWM_CMPA_3 , &PWM_PARAM_PRESCALER , &PWM_PARAM_HIGHSPEEDPRESCALER, &TBCLK);

        // Parameters
        EPWM_setTimeBasePeriod(base, (uint16_t)PWM_TBPRD_3);
        EPWM_setCounterCompareValue(base, EPWM_COUNTER_COMPARE_A, (uint16_t)PWM_CMPA_3);

        EPWM_setPhaseShift(base, 0U);
        EPWM_disablePhaseShiftLoad(base);
        EPWM_setTimeBaseCounter(base, 0U);

        EPWM_setSyncInPulseSource(base, EPWM_SYNC_IN_PULSE_SRC_SYNCOUT_EPWM1);

        set_phase(base, PHI);

    }

    //EPWM_setTimeBaseCounter(base, 0U);
    EPWM_setTimeBaseCounterMode(base, EPWM_COUNTER_MODE_UP_DOWN);

    EPWM_setClockPrescaler(base, PWM_PARAM_PRESCALER, PWM_PARAM_HIGHSPEEDPRESCALER);

    // Set up shadowing
    EPWM_setCounterCompareShadowLoadMode(base, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);

    // Set actions
    EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(base, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);

    // Trip zone
    // Configure ePWM1x to output low on TZx TRIP
    EPWM_setTripZoneAction(base, EPWM_TZ_ACTION_EVENT_TZA, EPWM_TZ_ACTION_LOW);
    EPWM_setTripZoneAction(base, EPWM_TZ_ACTION_EVENT_TZB, EPWM_TZ_ACTION_LOW);
    // Trigger event when DCBH is high
    EPWM_setTripZoneDigitalCompareEventCondition(base, EPWM_TZ_DC_OUTPUT_B1, EPWM_TZ_EVENT_DCXH_HIGH);
    // Configure DCBH to use TRIP4 as an input
    EPWM_enableDigitalCompareTripCombinationInput(base, EPWM_DC_COMBINATIONAL_TRIPIN4, EPWM_DC_TYPE_DCBH);
    // Enable DCB as OST
    EPWM_enableTripZoneSignals(base, EPWM_TZ_SIGNAL_DCBEVT1);
    // Configure the DCB path to be unfiltered and asynchronous
    EPWM_setDigitalCompareEventSource(base, EPWM_DC_MODULE_B, EPWM_DC_EVENT_1, EPWM_DC_EVENT_SOURCE_ORIG_SIGNAL);

    // Clear trip flags
    EPWM_clearTripZoneFlag(base, EPWM_TZ_INTERRUPT | EPWM_TZ_FLAG_OST);

    // Calculate delays
    get_delays_FED_RED(myEPWM1_BASE, &TBCLK);
    get_delays_FED_RED(myEPWM2_BASE, &TBCLK);
    get_delays_FED_RED(myEPWM3_BASE, &TBCLK);
}