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.

TMS320F28379D: Regarding XBAR SYNCOUT signal

Part Number: TMS320F28379D


As per the specification, the SYNCOUT pulse which comes from XBAR OUTPUT to sync other MCU's PWM is 20nSec(Four Clock Cycle). But is it possible that the pulse with can be increased? 20nS is very short duration to sending the signal from one MCU to other MCU without a very precise hardware circuit. 

My Issue may be resolved if I can able to increase the pulse width of XBARSYNCOUT.

It is really appreciated if someone has a solution about this. If there are any references please give me the link.

Ashutosh

  • I will ask to see if this is possible.

    Nima Eskandari

  • By doing all these things my ultimate aim is to synchronize all MCU PWM.
    Thanks for the support,
    Please suggest any other solution, if there ...

    Ashutosh
  • Well the answer is no you cannot STRETCH the EXTSYNCOUT signal.

    But what you CAN do is instead of selecting EXTSYNCOUT on the PINMUX, select an OUTPUTXBAR which is sourced from EXTSYNCOUT.
    Then enable the LATCH on OUTPUTXBAR, and manually clear the latch whenever you feel like you have a long enough signal.

    Nima Eskandari
  • Let Me Try...

    Ashutosh
  • Here I already enable the latch, but do you mean I need to force the latch in it?

    XBAR_enableOutputMux(XBAR_OUTPUT1,XBAR_MUX14);
    XBAR_setOutputLatchMode(XBAR_OUTPUT1,true);
    XBAR_setOutputMuxConfig(XBAR_OUTPUT1,XBAR_OUT_MUX14_EXTSYNCOUT);

    I have done the above configuration and I got 20nSec pulse only.

    Ashutosh
  • The figure below shows what I shared. This should take care of your need. The latch is there keep the signal until you CLEAR it.

  • //#############################################################################
    //
    // FILE:   epwm_ex2_updown_aq.c
    //
    // TITLE:  ePWM Action Qualifier Module - Using up/down count.
    //
    //! \addtogroup driver_example_list
    //! <h1> ePWM Up Down Count Action Qualifier</h1>
    //!
    //! This example configures ePWM1, ePWM2, ePWM3 to produce a waveform with
    //! independent modulation on ePWMxA and ePWMxB.
    //!
    //! The compare values CMPA and CMPB are modified within the ePWM's ISR.
    //!
    //! The TB counter is in up/down count mode for this example.
    //!
    //! View the ePWM1A/B(GPIO0 & GPIO1), ePWM2A/B(GPIO2 &GPIO3)
    //! and ePWM3A/B(GPIO4 & GPIO5) waveforms on oscilloscope.
    //
    //#############################################################################
    // $TI Release: F2837xD Support Library v3.04.00.00 $
    // $Release Date: Sun Mar 25 13:26:04 CDT 2018 $
    // $Copyright:
    // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define EPWM1_TIMER_TBPRD  25000U
    #define EPWM1_MAX_CMPA     1950U
    #define EPWM1_MIN_CMPA       50U
    #define EPWM1_MAX_CMPB     1950U
    #define EPWM1_MIN_CMPB       50U
    
    #define EPWM2_TIMER_TBPRD  25000U
    #define EPWM2_MAX_CMPA     1950U
    #define EPWM2_MIN_CMPA       50U
    #define EPWM2_MAX_CMPB     1950U
    #define EPWM2_MIN_CMPB       50U
    
    #define EPWM3_TIMER_TBPRD  25000U
    #define EPWM3_MAX_CMPA      950U
    #define EPWM3_MIN_CMPA       50U
    #define EPWM3_MAX_CMPB     1950U
    #define EPWM3_MIN_CMPB     1050U
    
    #define EPWM_CMP_UP           1U
    #define EPWM_CMP_DOWN         0U
    
    //
    // Globals
    //
    typedef struct
    {
        uint32_t epwmModule;
        uint16_t epwmCompADirection;
        uint16_t epwmCompBDirection;
        uint16_t epwmTimerIntCount;
        uint16_t epwmMaxCompA;
        uint16_t epwmMinCompA;
        uint16_t epwmMaxCompB;
        uint16_t epwmMinCompB;
    }epwmInformation;
    
    //
    // Globals to hold the ePWM information used in this example
    //
    epwmInformation epwm1Info;
    epwmInformation epwm2Info;
    epwmInformation epwm3Info;
    
    //
    // Function Prototypes
    //
    void initEPWM1(void);
    void initEPWM2(void);
    void initEPWM3(void);
    __interrupt void epwm1ISR(void);
    __interrupt void epwm2ISR(void);
    __interrupt void epwm3ISR(void);
    void updateCompare(epwmInformation *epwmInfo);
    
    unsigned int Timer_latch=0;
    //
    // 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
        //
        Interrupt_register(INT_EPWM1, &epwm1ISR);
        Interrupt_register(INT_EPWM2, &epwm2ISR);
        Interrupt_register(INT_EPWM3, &epwm3ISR);
    
        //
        // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 as ePWM1A/1B, ePWM2A/2B and
        // ePWM3A/3B pins respectively
        //
        GPIO_setPadConfig(0, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_0_EPWM1A);
        GPIO_setPadConfig(1, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_1_EPWM1B);
    
        GPIO_setPadConfig(2, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_2_EPWM2A);
        GPIO_setPadConfig(3, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_3_EPWM2B);
    
        GPIO_setPadConfig(4, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_4_EPWM3A);
        GPIO_setPadConfig(5, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_5_EPWM3B);
    /*
     * Setup Output X bar EXTSYNC GPIO
     */
        GPIO_setPadConfig(6, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_6_EPWMSYNCO);
        GPIO_setPadConfig(7, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_7_GPIO7);
        GPIO_setDirectionMode(7, GPIO_DIR_MODE_OUT);
        GPIO_writePin(7, 0);
    /*
     * Setup Output X bar
     */
        XBAR_disableOutputMux(XBAR_OUTPUT1,XBAR_MUX14);
        XBAR_setOutputMuxConfig(XBAR_OUTPUT1, XBAR_OUT_MUX14_EXTSYNCOUT);
        XBAR_setOutputLatchMode(XBAR_OUTPUT1, true);
        XBAR_enableOutputMux(XBAR_OUTPUT1,XBAR_MUX14);
    
    
    //    XBAR_getOutputLatchStatus(XBAR_OUTPUT1);
    //
    //    XBAR_clearOutputLatch(XBAR_OUTPUT1);
        //
        // Disable sync(Freeze clock to PWM as well)
        //
        SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        initEPWM1();
        initEPWM2();
        initEPWM3();
    
        //
        // Enable sync and clock to PWM
        //
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        //
        // Enable ePWM interrupts
        //
        Interrupt_enable(INT_EPWM1);
        Interrupt_enable(INT_EPWM2);
        Interrupt_enable(INT_EPWM3);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // IDLE loop. Just sit and loop forever (optional):
        //
        for(;;)
        {
            NOP;
            if(XBAR_getOutputLatchStatus(XBAR_OUTPUT1)==true){
                GPIO_writePin(7, 1);
               if(++Timer_latch>=5){
                   XBAR_clearOutputLatch(XBAR_OUTPUT1);
                   GPIO_writePin(7, 0);
                  Timer_latch=0;
               }
    
            }
    
        }
    }
    
    //
    // epwm1ISR - ePWM 1 ISR
    //
    __interrupt void epwm1ISR(void)
    {
    
        //
        // Update the CMPA and CMPB values
        //
        updateCompare(&epwm1Info);
    
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(EPWM1_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // epwm2ISR - ePWM 2 ISR
    //
    __interrupt void epwm2ISR(void)
    {
        //
        // Update the CMPA and CMPB values
        //
        updateCompare(&epwm2Info);
    
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(EPWM2_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // epwm3ISR - ePWM 3 ISR
    //
    __interrupt void epwm3ISR(void)
    {
        //
        // Update the CMPA and CMPB values
        //
        updateCompare(&epwm3Info);
    
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(EPWM3_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // initEPWM1 - Configure ePWM1
    //
    void initEPWM1()
    {
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBasePeriod(EPWM1_BASE, EPWM1_TIMER_TBPRD);
        EPWM_setPhaseShift(EPWM1_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);
    
        //
        // Set Compare values
        //
        EPWM_setCounterCompareValue(EPWM1_BASE,
                                    EPWM_COUNTER_COMPARE_A,
                                    EPWM1_MIN_CMPA);
        EPWM_setCounterCompareValue(EPWM1_BASE,
                                    EPWM_COUNTER_COMPARE_B,
                                    EPWM1_MAX_CMPB);
    
        //
        // Set up counter mode
        //
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM1_BASE);
        EPWM_setClockPrescaler(EPWM1_BASE,
                               EPWM_CLOCK_DIVIDER_2,
                               EPWM_HSCLOCK_DIVIDER_4);
    
        //
        // 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_UP_CMPA);
        EPWM_setActionQualifierAction(EPWM1_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
        EPWM_setActionQualifierAction(EPWM1_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
        EPWM_setActionQualifierAction(EPWM1_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    
        //
        // Interrupt where we will change the Compare Values
        // Select INT on Time base counter zero event,
        // Enable INT, generate INT on 3rd event
        //
        EPWM_setInterruptSource(EPWM1_BASE, EPWM_INT_TBCTR_ZERO);
        EPWM_enableInterrupt(EPWM1_BASE);
        EPWM_setInterruptEventCount(EPWM1_BASE, 3U);
    
        //
        // Information this example uses to keep track of the direction the
        // CMPA/CMPB values are moving, the min and max allowed values and
        // a pointer to the correct ePWM registers
        //
        epwm1Info.epwmCompADirection = EPWM_CMP_UP;
        epwm1Info.epwmCompBDirection = EPWM_CMP_DOWN;
        epwm1Info.epwmTimerIntCount = 0U;
        epwm1Info.epwmModule = EPWM1_BASE;
        epwm1Info.epwmMaxCompA = EPWM1_MAX_CMPA;
        epwm1Info.epwmMinCompA = EPWM1_MIN_CMPA;
        epwm1Info.epwmMaxCompB = EPWM1_MAX_CMPB;
        epwm1Info.epwmMinCompB = EPWM1_MIN_CMPB;
    }
    
    //
    // initEPWM2 - Configure ePWM2
    //
    void initEPWM2()
    {
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBasePeriod(EPWM2_BASE, EPWM2_TIMER_TBPRD);
        EPWM_setPhaseShift(EPWM2_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM2_BASE, 0U);
    
        //
        // Set Compare values
        //
        EPWM_setCounterCompareValue(EPWM2_BASE,
                                    EPWM_COUNTER_COMPARE_A,
                                    EPWM2_MIN_CMPA);
        EPWM_setCounterCompareValue(EPWM2_BASE,
                                    EPWM_COUNTER_COMPARE_B,
                                    EPWM2_MIN_CMPB);
    
        //
        // Set-up counter mode
        //
        EPWM_setTimeBaseCounterMode(EPWM2_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_disablePhaseShiftLoad(EPWM2_BASE);
        EPWM_setClockPrescaler(EPWM2_BASE,
                               EPWM_CLOCK_DIVIDER_2,
                               EPWM_HSCLOCK_DIVIDER_4);
    
        //
        // 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 Action qualifier
        //
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
        EPWM_setActionQualifierAction(EPWM2_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    
        //
        // Interrupt where we will change the Compare Values
        // Select INT on Time base counter zero event,
        // Enable INT, generate INT on 3rd event
        //
        EPWM_setInterruptSource(EPWM2_BASE, EPWM_INT_TBCTR_ZERO);
        EPWM_enableInterrupt(EPWM2_BASE);
        EPWM_setInterruptEventCount(EPWM2_BASE, 3U);
    
        //
        // Information this example uses to keep track of the direction the
        // CMPA/CMPB values are moving, the min and max allowed values and
        // a pointer to the correct ePWM registers
        //
        epwm2Info.epwmCompADirection = EPWM_CMP_UP;
        epwm2Info.epwmCompBDirection = EPWM_CMP_UP;
        epwm2Info.epwmTimerIntCount = 0U;
        epwm2Info.epwmModule = EPWM2_BASE;
        epwm2Info.epwmMaxCompA = EPWM2_MAX_CMPA;
        epwm2Info.epwmMinCompA = EPWM2_MIN_CMPA;
        epwm2Info.epwmMaxCompB = EPWM2_MAX_CMPB;
        epwm2Info.epwmMinCompB = EPWM2_MIN_CMPB;
    }
    
    //
    // initEPWM3 - Configure ePWM3
    //
    void initEPWM3(void)
    {
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBaseCounterMode(EPWM3_BASE, EPWM_COUNTER_MODE_UP_DOWN);
        EPWM_setTimeBasePeriod(EPWM3_BASE, EPWM3_TIMER_TBPRD);
        EPWM_disablePhaseShiftLoad(EPWM3_BASE);
        EPWM_setPhaseShift(EPWM3_BASE, 0U);
        EPWM_setTimeBaseCounter(EPWM3_BASE, 0U);
        EPWM_setClockPrescaler(EPWM3_BASE,
                               EPWM_CLOCK_DIVIDER_2,
                               EPWM_HSCLOCK_DIVIDER_4);
    
        //
        // Set up shadowing
        //
        EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE,
                                             EPWM_COUNTER_COMPARE_A,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
        EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE,
                                             EPWM_COUNTER_COMPARE_B,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
        //
        // Set Compare values
        //
        EPWM_setCounterCompareValue(EPWM3_BASE,
                                    EPWM_COUNTER_COMPARE_A,
                                    EPWM3_MIN_CMPA);
    
        EPWM_setCounterCompareValue(EPWM3_BASE,
                                    EPWM_COUNTER_COMPARE_B,
                                    EPWM3_MAX_CMPB);
    
        //
        // Set actions
        //
        EPWM_setActionQualifierAction(EPWM3_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM3_BASE,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
        EPWM_setActionQualifierAction(EPWM3_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
        EPWM_setActionQualifierAction(EPWM3_BASE,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    
        //
        // Interrupt where we will change the Compare Values
        // Select INT on Time base counter zero event,
        // Enable INT, generate INT on 3rd event
        //
        EPWM_setInterruptSource(EPWM3_BASE, EPWM_INT_TBCTR_ZERO);
        EPWM_enableInterrupt(EPWM3_BASE);
        EPWM_setInterruptEventCount(EPWM3_BASE, 3U);
    
        //
        // Information this example uses to keep track of the direction the
        // CMPA/CMPB values are moving, the min and max allowed values and
        // a pointer to the correct ePWM registers
        //
        epwm3Info.epwmCompADirection = EPWM_CMP_UP;
        epwm3Info.epwmCompBDirection = EPWM_CMP_DOWN;
        epwm3Info.epwmTimerIntCount = 0U;
        epwm3Info.epwmModule = EPWM3_BASE;
        epwm3Info.epwmMaxCompA = EPWM3_MAX_CMPA;
        epwm3Info.epwmMinCompA = EPWM3_MIN_CMPA;
        epwm3Info.epwmMaxCompB = EPWM3_MAX_CMPB;
        epwm3Info.epwmMinCompB = EPWM3_MIN_CMPB;
    }
    
    //
    // updateCompare - Function to update the frequency
    //
    void updateCompare(epwmInformation *epwmInfo)
    {
        uint16_t compAValue;
        uint16_t compBValue;
    
        compAValue = EPWM_getCounterCompareValue(epwmInfo->epwmModule,
                                                 EPWM_COUNTER_COMPARE_A);
    
        compBValue = EPWM_getCounterCompareValue(epwmInfo->epwmModule,
                                                 EPWM_COUNTER_COMPARE_B);
    
        //
        //  Change the CMPA/CMPB values every 10th interrupt.
        //
        if(epwmInfo->epwmTimerIntCount == 10U)
        {
            epwmInfo->epwmTimerIntCount = 0U;
    
            //
            // If we were increasing CMPA, check to see if we reached the max
            // value. If not, increase CMPA else, change directions and decrease
            // CMPA
            //
            if(epwmInfo->epwmCompADirection == EPWM_CMP_UP)
            {
                if(compAValue < (epwmInfo->epwmMaxCompA))
                {
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_A,
                                                ++compAValue);
                }
                else
                {
                    epwmInfo->epwmCompADirection = EPWM_CMP_DOWN;
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_A,
                                                --compAValue);
                }
            }
            //
            // If we were decreasing CMPA, check to see if we reached the min
            // value. If not, decrease CMPA else, change directions and increase
            // CMPA
            //
            else
            {
                if( compAValue == (epwmInfo->epwmMinCompA))
                {
                    epwmInfo->epwmCompADirection = EPWM_CMP_UP;
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_A,
                                                ++compAValue);
                }
                else
                {
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_A,
                                                --compAValue);
                }
            }
    
            //
            // If we were increasing CMPB, check to see if we reached the max
            // value. If not, increase CMPB else, change directions and decrease
            // CMPB
            //
            if(epwmInfo->epwmCompBDirection == EPWM_CMP_UP)
            {
                if(compBValue < (epwmInfo->epwmMaxCompB))
                {
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_B,
                                                ++compBValue);
                }
                else
                {
                    epwmInfo->epwmCompBDirection = EPWM_CMP_DOWN;
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_B,
                                                --compBValue);
                }
            }
            //
            // If we were decreasing CMPB, check to see if we reached the min
            // value. If not, decrease CMPB else, change directions and increase
            // CMPB
            //
            else
            {
                if(compBValue == (epwmInfo->epwmMinCompB))
                {
                    epwmInfo->epwmCompBDirection = EPWM_CMP_UP;
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_B,
                                                ++compBValue);
                }
                else
                {
                    EPWM_setCounterCompareValue(epwmInfo->epwmModule,
                                                EPWM_COUNTER_COMPARE_B,
                                                --compBValue);
                }
            }
        }
        else
        {
            epwmInfo->epwmTimerIntCount++;
        }
    }
    
    
     Hi Nima,

    By using your suggestion as above, I have changed one of the codes given by TI C2000 ware. I am sharing you the wave form and the code What I changed.

    First I found the latch status and when I got the latch state high I make a GPIO high and as per my requirement I did the pulse down and clear the latch but here I got one issue which you can also figure out from the CRO waveform I sharing you. Both pulses have some delay around 500nS, is this acceptable for syncing the other MCU PWM?

    And still, my main issue is not resolved that I am unable to sync two MCU PWMs while stating the convert on power mode. Even if I send the signal through the optical wire.

  • I'll try this out.
  • sorry for the delay, still working on this.
  • Got it. Sending you the working code.
  • Using GPIO24 and GPIO0. GPIO24 is the EXTSYNCOUT.

    The variable "clearFlag" is set in the interrupt at CTR = ZRO. The main while loop clears the OUTPUTXBAR latch when needed. In my case I wanted the width to be approx 2us.

    // Nima Eskandari
    // Included Files
    //
    #include "F28x_Project.h"
    
    //
    // Defines
    //
    #define EPWM1_TIMER_TBPRD  1250  // Period register
    
    
    //
    // Function Prototypes
    //
    void InitEPwm1Example(void);
    __interrupt void epwm1_isr(void);
    uint16_t clearFlag = 0;
    
    //
    // Main
    //
    void main(void)
    {
    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xD_SysCtrl.c file.
    //
        InitSysCtrl();
    
    //
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xD_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    //    InitGpio();
    
    //
    // enable PWM1, PWM2 and PWM3
    //
        CpuSysRegs.PCLKCR2.bit.EPWM1=1;
    
    //
    // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
    // These functions are in the F2837xD_EPwm.c file
    //
        InitEPwm1Gpio();
        EALLOW;
        GpioCtrlRegs.GPAPUD.bit.GPIO24 = 1;    // Disable pull-up on GPIO24
        GpioCtrlRegs.GPAGMUX2.bit.GPIO24 = 0;   // Configure GPIO24 as OUTPUTXBAR1
        GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1;   // Configure GPIO24 as OUTPUTXBAR1
        EDIS;
    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
        DINT;
    
    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2837xD_PieCtrl.c file.
    //
        InitPieCtrl();
    
    //
    // Disable CPU interrupts and clear all CPU interrupt flags:
    //
        IER = 0x0000;
        IFR = 0x0000;
    
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2837xD_DefaultIsr.c.
    // This function is found in F2837xD_PieVect.c.
    //
        InitPieVectTable();
    
    //
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
    //
        EALLOW; // This is needed to write to EALLOW protected registers
        PieVectTable.EPWM1_INT = &epwm1_isr;
        EDIS;   // This is needed to disable write to EALLOW protected registers
    
    //
    // For this example, only initialize the ePWM
    //
        EALLOW;
        CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
        EDIS;
    
        InitEPwm1Example();
    
        EALLOW;
        CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
        EDIS;
    
        EALLOW;
        OutputXbarRegs.OUTPUT1MUX0TO15CFG.bit.MUX14 = 3;
        OutputXbarRegs.OUTPUT1MUXENABLE.bit.MUX14 = 1;
        OutputXbarRegs.OUTPUTLATCHENABLE.bit.OUTPUT1 = 1;
        EDIS;
    
    //
    // Step 4. User specific code, enable interrupts:
    //
    
    //
    // Enable CPU INT3 which is connected to EPWM1-3 INT:
    //
        IER |= M_INT3;
    
    //
    // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
    //
        PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
    
    //
    // Enable global Interrupts and higher priority real-time debug events:
    //
        EINT;  // Enable Global interrupt INTM
        ERTM;  // Enable Global realtime interrupt DBGM
    
    //
    // Step 5. IDLE loop. Just sit and loop forever (optional):
    //
        for(;;)
        {
            asm ("    NOP");
            if (clearFlag == 1)
            {
                DELAY_US(2);
                OutputXbarRegs.OUTPUTLATCHCLR.bit.OUTPUT1 = 1;
                clearFlag = 0;
            }
        }
    }
    
    //
    // epwm1_isr - EPWM1 ISR
    //
    __interrupt void epwm1_isr(void)
    {
    
        clearFlag = 1;
    
        //
        // Clear INT flag for this timer
        //
        EPwm1Regs.ETCLR.bit.INT = 1;
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 3
        //
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    
    
    }
    
    //
    // InitEPwm1Example - Initialize EPWM1 configuration
    //
    void InitEPwm1Example()
    {
        //
        // Setup TBCLK
        //
        EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD;       // Set timer period 801 TBCLKs
        EPwm1Regs.TBPHS.bit.TBPHS = 0x0000;        // Phase is 0
        EPwm1Regs.TBCTR = 0x0000;                  // Clear counter
    
        //
        // Set Compare values
        //
        EPwm1Regs.CMPA.bit.CMPA = EPWM1_TIMER_TBPRD/2;    // Set compare A value
        EPwm1Regs.CMPB.bit.CMPB = EPWM1_TIMER_TBPRD/2;    // Set Compare B value
    
        //
        // Setup counter mode
        //
        EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
        EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
        EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;       // Clock ratio to SYSCLKOUT
        EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
    
        //
        // Setup shadowing
        //
        EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
        EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
        //
        // Set actions
        //
        EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;            // Set PWM1A on event A, up
                                                      // count
        EPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR;          // Clear PWM1A on event A,
                                                      // down count
    
        EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;            // Set PWM1A on event A, up
                                                      // count
        EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;          // Clear PWM1A on event A,
                                                      // down count
    
        //
        // Interrupt where we will change the Compare Values
        //
        EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
        EPwm1Regs.ETSEL.bit.INTEN = 1;                // Enable INT
        EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;           // Generate INT on 3rd event
    
    }
    
    //
    // End of file
    //