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.

CCS/LAUNCHXL-F280049C: EPWM Phase shift

Part Number: LAUNCHXL-F280049C

Tool/software: Code Composer Studio

Hello, 

I have a problem with the EPWM library regarding the phase shifting... I set the PWM and it´s working fine but when I try to set a phase shift, it doesn´t work, I need to set a new counterbase so it works... 

//Here I have my PWM initialization, setting the period, etc.

    //
    // configure PWM 1 as master and Phase 2, 3 as slaves and let it pass the sync in pulse from PWM1
    //
    EPWM_disablePhaseShiftLoad(VIENNA1_DRV_EPWM_BASE);
    EPWM_setSyncOutPulseMode(VIENNA1_DRV_EPWM_BASE, EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO);

    EPWM_enablePhaseShiftLoad(VIENNA2_DRV_EPWM_BASE);
    EPWM_setSyncOutPulseMode(VIENNA2_DRV_EPWM_BASE, EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN);

    EPWM_setPhaseShift(VIENNA2_DRV_EPWM_BASE, 0);
    EPWM_setCountModeAfterSync(VIENNA2_DRV_EPWM_BASE, EPWM_COUNT_MODE_UP_AFTER_SYNC);
    EPWM_setTimeBaseCounter(VIENNA2_DRV_EPWM_BASE, 2000);                                                                                        //Although PhaseShift is set to 0, because of base counter I have a phase shift.

    EPWM_setSyncOutPulseMode(VIENNA3_DRV_EPWM_BASE, EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN);
    EPWM_setCountModeAfterSync(VIENNA3_DRV_EPWM_BASE, EPWM_COUNT_MODE_UP_AFTER_SYNC);
    EPWM_enablePhaseShiftLoad(VIENNA3_DRV_EPWM_BASE);
    EPWM_setPhaseShift(VIENNA3_DRV_EPWM_BASE, 2000);                                                                                                   // I set the PhaseShift but it´s not working at all...

Could you help me, please?

Thank you very much.

BR,

Luis

  • Hi,

    Can you confirm the PWM instances used in the code above? Is it PWM1 as master and PWM 2 and 3 as slaves ? Also can you share other PWM configurations like period, duty, action qualifier as well?

    Thanks

    Vasudha

  • Hi Vasudha,

    Thanks for your support.

    Yes, the PWM1 is master and PWM2 and PWM3 are slaves.

    The configuration of the PWM is done as follows:

        EPWM_setClockPrescaler(PWMbase,VIENNA_EPWM_EPWMCLK_DIV, VIENNA_EPWM_HSCLK_DIV);
        EPWM_setEmulationMode(PWMbase, EPWM_EMULATION_FREE_RUN);
        //
        // Configure ePWM for count-up operation
        //
        EPWM_setTimeBaseCounter(PWMbase, 0);
        EPWM_setTimeBasePeriod(PWMbase, VIENNA_EPWM_TBPRD);
        EPWM_setPeriodLoadMode(PWMbase, EPWM_PERIOD_SHADOW_LOAD);
        EPWM_setTimeBaseCounterMode(PWMbase, EPWM_COUNTER_MODE_UP);
        EPWM_setPhaseShift(PWMbase,0);

        //
        // Use shadow mode to update CMPA on TBPRD
        //
        EPWM_setCounterCompareValue(PWMbase, EPWM_COUNTER_COMPARE_A, 0);
        EPWM_setCounterCompareShadowLoadMode(PWMbase, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_PERIOD);

        // Configure Action Qualifier SubModule to:

        //     Output A Low when TBCTR=0

        EPWM_setActionQualifierShadowLoadMode(PWMbase, EPWM_ACTION_QUALIFIER_A, EPWM_AQ_LOAD_ON_CNTR_ZERO);
        EPWM_setActionQualifierAction(PWMbase, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        //     Output A High when TBCTR=CMPA
        EPWM_setActionQualifierAction(PWMbase, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);

        //     Output B High when TBCTR=0
        EPWM_setActionQualifierAction(PWMbase, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        //     Output B Low when TBCTR=CMPA
        EPWM_setActionQualifierAction(PWMbase, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);

        //
        // Configure Dead Band Generator for active high complementary PWMs
        //
        EPWM_setDeadBandDelayMode(PWMbase, EPWM_DB_RED, true);
        EPWM_setDeadBandDelayMode(PWMbase, EPWM_DB_FED, true);

        EPWM_setRisingEdgeDeadBandDelayInput(PWMbase, EPWM_DB_INPUT_EPWMA);
        EPWM_setFallingEdgeDeadBandDelayInput(PWMbase, EPWM_DB_INPUT_EPWMA);

        EPWM_setDeadBandDelayPolarity(PWMbase, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);
        EPWM_setDeadBandDelayPolarity(PWMbase, EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);

        EPWM_setFallingEdgeDelayCount(PWMbase, VIENNA_EPWM_DEADBAND_FED);
        EPWM_setRisingEdgeDelayCount(PWMbase, VIENNA_EPWM_DEADBAND_RED);

    Thanks again!

    Luis

  • Dear Vasudha,

    I´ve found the problem but I don´t know how to solve it... This picture gives a good description of my problem:

    When I use PWM1 and PWM2, the shift is working fine. The problem that I have using other PWM and synchronising them to PWM1 is that I need to select the input sync event.

    How do I do this with the epwm.h library? How is the function called to select the SYNCIN event? I cannot find a function to do this... could you help me, please?

    Best regards,

    Luis

  • I´ve found how to solve it:

        SysCtl_setSyncInputConfig(SYSCTL_SYNC_IN_EPWM4, SYSCTL_SYNC_IN_SRC_EXTSYNCIN1);
        SysCtl_setSyncInputConfig(SYSCTL_SYNC_IN_EPWM7, SYSCTL_SYNC_IN_SRC_EXTSYNCIN1);

    Adding this lines to sync the input clocks ;) 

    Thanks!