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: PHASE SHIFT VARYING IN EPWM BLOCKSET OF C280039C

Part Number: TMS320F280039C

// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"
#include"pwm.h"

//
// Defines
//
#define EPWM1_TIMER_TBPRD 5000U
#define EPWM2_TIMER_TBPRD 5000U

//
// Function Prototypes
//
void initEPWM1(void);
void initEPWM2(void);


//
// Main
//
void main(void)
{
    //
    // Initialize device clock and peripherals
    //
    Device_init();

    //
    // Disable pin locks and enable internal pull ups.
    //
    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();

    //
    // Assign the interrupt service routines to ePWM interrupts
    //


        GPIO_setPinConfig(GPIO_6_EPWM4_A);
        GPIO_setPinConfig(GPIO_7_EPWM4_B);

        GPIO_setPinConfig(GPIO_8_EPWM5_A);
        GPIO_setPinConfig(GPIO_9_EPWM5_B);

        GPIO_setPinConfig(GPIO_0_EPWM1_A);
        GPIO_setPinConfig(GPIO_1_EPWM1_B);

        GPIO_setPinConfig(GPIO_2_EPWM2_A);
        GPIO_setPinConfig(GPIO_3_EPWM2_B);

    //
    // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 as ePWM1A/1B, ePWM2A/2B and
    // ePWM3A/3B pins respectively
    //
    Board_init();
    initEPWM4();
    initEPWM5();
    initEPWM2();
    initEPWM1();

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

    initEPWM1();
    initEPWM2();
    initEPWM4();
    initEPWM5();


    //
    // Enable sync and clock to PWM
    //
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);


    //
    // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
    //
    EINT;
    ERTM;

    //
    // IDLE loop. Just sit and loop forever (optional):
    //
    for(;;)
    {
        NOP;
    }
}


//
// initEPWM1 - Configure ePWM1
//
void initEPWM1()
{
         // Set-up TBCLK

        EPWM_setTimeBasePeriod(EPWM1_BASE, EPWM1_TIMER_TBPRD);

        // SYNC OUT EVENT

       EPWM_setSyncOutPulseMode(EPWM1_BASE,EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO);
        //EPWM_setPhaseShift(EPWM4_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);


        // SYNC EVENT
        //EPWM_setCountModeAfterSync(EPWM4_BASE, EPWM_COUNT_MODE_DOWN_AFTER_SYNC);

            // Set Compare values
            EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_A,2500);
            EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_B,2500);

        // Set up counter mode

        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM1_BASE);
        EPWM_setClockPrescaler(EPWM1_BASE,EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_1);

            // Set up shadowing

        EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE, EPWM_COUNTER_COMPARE_A,EPWM_COMP_LOAD_ON_CNTR_ZERO);
        EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE, EPWM_COUNTER_COMPARE_B, EPWM_COMP_LOAD_ON_CNTR_ZERO);

           // Set actions

        EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        // Use EPWMA as the input for both RED and FED
                 //
                 EPWM_setRisingEdgeDeadBandDelayInput(EPWM1_BASE, EPWM_DB_INPUT_EPWMA);
                 EPWM_setFallingEdgeDeadBandDelayInput(EPWM1_BASE, EPWM_DB_INPUT_EPWMA);

                 //
                 // Set the RED and FED values
                 //
                 EPWM_setFallingEdgeDelayCount(EPWM1_BASE, 500);
                 EPWM_setRisingEdgeDelayCount(EPWM1_BASE, 500);


                 // Invert only the Falling Edge delayed output (AHC)
                     //
                     EPWM_setDeadBandDelayPolarity(EPWM1_BASE, EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);
                     EPWM_setDeadBandDelayPolarity(EPWM1_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);

                     //
                         // Use the delayed signals instead of the original signals
                         //
                         EPWM_setDeadBandDelayMode(EPWM1_BASE, EPWM_DB_RED, true);
                         EPWM_setDeadBandDelayMode(EPWM1_BASE, EPWM_DB_FED, true);

                 // Use EPWMB as the input for both RED and FED
                 //
                 EPWM_setRisingEdgeDeadBandDelayInput(EPWM1_BASE, EPWM_DB_INPUT_EPWMB);
                 EPWM_setFallingEdgeDeadBandDelayInput(EPWM1_BASE, EPWM_DB_INPUT_EPWMB);

                 //
                // Set the RED and FED values
                //
                 EPWM_setFallingEdgeDelayCount(EPWM1_BASE, 500);
                 EPWM_setRisingEdgeDelayCount(EPWM1_BASE, 500);

                 // Invert only the Falling Edge delayed output (AHC)
                              //
                              EPWM_setDeadBandDelayPolarity(EPWM1_BASE, EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);
                              EPWM_setDeadBandDelayPolarity(EPWM1_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);

                              //
                                  // Use the delayed signals instead of the original signals
                                  //
                                  EPWM_setDeadBandDelayMode(EPWM1_BASE, EPWM_DB_RED, true);
                                  EPWM_setDeadBandDelayMode(EPWM1_BASE, EPWM_DB_FED, true);

    }


//
// initEPWM2 - Configure ePWM2
//
void initEPWM2()
{
        EPWM_setTimeBasePeriod(EPWM2_BASE, EPWM5_TIMER_TBPRD);
        EPWM_setTimeBaseCounter(EPWM2_BASE, 0U);

        // SYNC EVENT
        EPWM_setCountModeAfterSync(EPWM2_BASE, EPWM_COUNT_MODE_DOWN_AFTER_SYNC);

        // PHASE SHIFT VALUE

        EPWM_setPhaseShift(EPWM2_BASE, 2000U);
        EPWM_enablePhaseShiftLoad(EPWM2_BASE);

        //
      //  EPWM_setSyncOutPulseMode(EPWM5_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN);

         // Set Compare values

        EPWM_setCounterCompareValue(EPWM2_BASE,EPWM_COUNTER_COMPARE_A,2500U);
        EPWM_setCounterCompareValue(EPWM2_BASE, EPWM_COUNTER_COMPARE_B,2500U);

        // Set up counter mode

        EPWM_setTimeBaseCounterMode(EPWM2_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_setClockPrescaler(EPWM2_BASE,EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_1);

       // Set up shadowing

        EPWM_setCounterCompareShadowLoadMode(EPWM2_BASE, EPWM_COUNTER_COMPARE_A,EPWM_COMP_LOAD_ON_CNTR_ZERO);
        EPWM_setCounterCompareShadowLoadMode(EPWM2_BASE, EPWM_COUNTER_COMPARE_B, EPWM_COMP_LOAD_ON_CNTR_ZERO);

       // Set actions

        EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);

        // Use EPWMA as the input for both RED and FED
                 //
                 EPWM_setRisingEdgeDeadBandDelayInput(EPWM2_BASE, EPWM_DB_INPUT_EPWMA);
                 EPWM_setFallingEdgeDeadBandDelayInput(EPWM2_BASE, EPWM_DB_INPUT_EPWMA);

                 //
                 // Set the RED and FED values
                 //
                 EPWM_setFallingEdgeDelayCount(EPWM2_BASE, 500);
                 EPWM_setRisingEdgeDelayCount(EPWM2_BASE, 400);


                 // Invert only the Falling Edge delayed output (AHC)
                     //
                     EPWM_setDeadBandDelayPolarity(EPWM2_BASE, EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);
                     EPWM_setDeadBandDelayPolarity(EPWM2_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);

                     //
                         // Use the delayed signals instead of the original signals
                         //
                         EPWM_setDeadBandDelayMode(EPWM2_BASE, EPWM_DB_RED, true);
                         EPWM_setDeadBandDelayMode(EPWM2_BASE, EPWM_DB_FED, true);

                 // Use EPWMB as the input for both RED and FED
                 //
                 EPWM_setRisingEdgeDeadBandDelayInput(EPWM2_BASE, EPWM_DB_INPUT_EPWMB);
                 EPWM_setFallingEdgeDeadBandDelayInput(EPWM2_BASE, EPWM_DB_INPUT_EPWMB);

                 //
                // Set the RED and FED values
                //
                 EPWM_setFallingEdgeDelayCount(EPWM2_BASE, 500);
                 EPWM_setRisingEdgeDelayCount(EPWM2_BASE, 500);

                 // Invert only the Falling Edge delayed output (AHC)
                              //
                              EPWM_setDeadBandDelayPolarity(EPWM2_BASE, EPWM_DB_RED, EPWM_DB_POLARITY_ACTIVE_HIGH);
                              EPWM_setDeadBandDelayPolarity(EPWM2_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);

                              //
                                  // Use the delayed signals instead of the original signals
                                  //
                                  EPWM_setDeadBandDelayMode(EPWM2_BASE, EPWM_DB_RED, true);
                                  EPWM_setDeadBandDelayMode(EPWM2_BASE, EPWM_DB_FED, true);
}


the code generated is for TMS 280049C for a 10Khz pulse with 50% duty ratio and a phase shift of 72 deg.  I was able to get the result in 280049C. Now i am trying to implement the same code  in 280039C with TBPRD and TBPHS value different based on the system clock frequency. But am not able to get the output in 280039C.

Kindly let me know any changes to made in coding?