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.

TMS320F280049C: External synchronisation of EPWM via EXTSYNCINx

Part Number: TMS320F280049C
Other Parts Discussed in Thread: TMDSHSECDOCK, , C2000WARE, SYSCONFIG, LAUNCHXL-F280049C

Hi, 

I am trying to accomplish something similar to what is described here: Sync PWM with an External Signal - TI Hercules Microcontroller (please check the video of this link to understand the functionality).

The main idea behind the post is to synchronise a PWM with an external signal where, every time the controlling signal has a rising edge the PWM signal is reset. The implementation is done with another TI microcontroller, therefore I guess it can be implemented as well with F28004x C2000 microcontroller family. In my case, I am using the TMS320F280049C control card along with TMDSHSECDOCK.

The TMS320F28004x Real-Time Microcontrollers Technical Reference Manual explains that an ePWM can be synchronised with EXTSYNCINx, hence the external sync signal should be directly routed through INPUTXBAR5 and/or INPUTXBAR6 in order to provide the synchronisation to ePWM and eCAP Sync Chain. 

In order to test the concept I took the CCS reference example epwm_ex3_synchronization.projectspec (located at C2000Ware_5_00_00_00\driverlib\f28004x\examples\epwm) and did some modifications to make the test very simple. Thus, I considered the following simple scenario:

Input GPIO39* > INPUTXBAR5 > EXTSYNCIN1 > ePWM1 > GPIO0 (PWM1A) and GPIO1 (PWM1B) output 

*External square signal (2V amplitude, 50% duty cycle and 100Hz) is applied to GPIO39

The final .c code is shared here below where my only contribution is to comment the lines related to ePWM2, 3 and 4 that I am not going to use. Also small modifications are applied on .syscfg code below, where I changed the XBAR input 5 to GPIO39 and deleted the myINPUTXBARINPUT1 (XBAR_INPUT6), the following screenshot shows the final config. Moreover, I deleted the myEPWM2, 3 and 4, the following screenshot shows the final config.  No further changes are applied to the original example.

//#############################################################################
//
// FILE:   epwm_ex3_synchronization.c
//
// TITLE:  ePWM Using The Synch Chain and Phase Shift.
//
//! \addtogroup driver_example_list
//! <h1>ePWM Synchronization</h1>
//!
//! This example configures ePWM1, ePWM2, ePWM3 and ePWM4 as follows
//!  - ePWM1 without phase shift as sync source
//!  - ePWM2 with phase shift of 300 TBCLKs
//!  - ePWM3 with phase shift of 600 TBCLKs
//!  - ePWM4 with phase shift of 900 TBCLKs
//!
//! \b External \b Connections \n
//! - GPIO0 EPWM1A
//! - GPIO1 EPWM1B
//! - GPIO2 EPWM2A
//! - GPIO3 EPWM2B
//! - GPIO4 EPWM3A
//! - GPIO5 EPWM3B
//! - GPIO6 EPWM4A
//! - GPIO7 EPWM4B
//!
//! \b Watch \b Variables \n
//! - None.
//
//#############################################################################
//
//
// $Copyright:
// Copyright (C) 2023 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"
#include "board.h"


__interrupt void epwm1ISR(void);
__interrupt void epwm2ISR(void);
__interrupt void epwm3ISR(void);
__interrupt void epwm4ISR(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
    //
    Interrupt_register(INT_EPWM1, &epwm1ISR);
    //Interrupt_register(INT_EPWM2, &epwm2ISR);
    //Interrupt_register(INT_EPWM3, &epwm3ISR);
    //Interrupt_register(INT_EPWM4, &epwm4ISR);


    // Disable sync(Freeze clock to PWM as well). GTBCLKSYNC is applicable
    // only for multiple core devices. Uncomment the below statement if
    // applicable.
    //
    // SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_GTBCLKSYNC);
    SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

    //

    // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 and GPIO6/7 as
    // ePWM1A/1B, ePWM2A/2B, ePWM3A/3B, ePWM4A/4B pins respectively
    // Configure EPWM Modules
    // 
    Board_init();

    //
    // 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);
    //Interrupt_enable(INT_EPWM4);

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

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

    }
}

//
// epwm1ISR - ePWM 1 ISR
//
__interrupt void epwm1ISR(void)
{
    //
    // Clear INT flag for this timer
    //
    EPWM_clearEventTriggerInterruptFlag(myEPWM1_BASE);

    //
    // Acknowledge interrupt group
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
}

//
// epwm2ISR - ePWM 2 ISR
//
/*__interrupt void epwm2ISR(void)
{
    //
    // Clear INT flag for this timer
    //
    EPWM_clearEventTriggerInterruptFlag(myEPWM2_BASE);

    //
    // Acknowledge interrupt group
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
}

//
// epwm3ISR - ePWM 3 ISR
//
__interrupt void epwm3ISR(void)
{
    //
    // Clear INT flag for this timer
    //
    EPWM_clearEventTriggerInterruptFlag(myEPWM3_BASE);

    //
    // Acknowledge interrupt group
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
}

//
// epwm4ISR - ePWM 4 ISR
//
__interrupt void epwm4ISR(void)
{
    //
    // Clear INT flag for this timer
    //
    EPWM_clearEventTriggerInterruptFlag(myEPWM4_BASE);

    //
    // Acknowledge interrupt group
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
}*/

/**
 * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
 * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
 * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00"
 * @versions {"tool":"1.18.0+3266"}
 */

/**
 * Import the modules used in this configuration.
 */
const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
const epwm1            = epwm.addInstance();
const inputxbar        = scripting.addModule("/driverlib/inputxbar.js", {}, false);
const inputxbar1       = inputxbar.addInstance();
const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js");
const inputxbar_input1 = inputxbar_input.addInstance();
const sync             = scripting.addModule("/driverlib/sync.js");

/**
 * Write custom configuration values to the imported modules.
 */
epwm1.$name                                                    = "myEPWM1";
epwm1.epwmTimebase_period                                      = 2000;
epwm1.epwmCounterCompare_cmpA                                  = 1000;
epwm1.epwmCounterCompare_cmpB                                  = 500;
epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
epwm1.epwmTimebase_clockDiv                                    = "EPWM_CLOCK_DIVIDER_8";
epwm1.epwmTimebase_hsClockDiv                                  = "EPWM_HSCLOCK_DIVIDER_1";
epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW";
epwm1.epwmEventTrigger_enableInterrupt                         = true;
epwm1.epwmEventTrigger_interruptEventCount                     = "1";
epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO";
epwm1.epwm.$assign                                             = "EPWM1";
epwm1.epwm.epwm_aPin.$assign                                   = "GPIO0";
epwm1.epwm.epwm_bPin.$assign                                   = "GPIO1";

inputxbar1.$name = "myINPUTXBAR5";

inputxbar_input1.$name          = "myINPUTXBARINPUT0";
inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
inputxbar_input1.inputxbarGpio  = "GPIO39";

After loading the code I can not see any synchronisation at the rising edge of GPIO39 input. At the bottom of the post I attach a video in .ZIP format with the performed test, you can see the configuration and the result from the oscilloscope. In yellow is displayed the GPIO39 external control signal while in blue and pink the GPIO0 (PWM1A) and GPIO1 (PWM1B)

What may be missing on this example to make PWM synchronised? Why the PWM1A and PWM1B are not complementary?

Awaiting your answers. 

Best regards, 

Denys Ovsiyenko

VIDEO HERE - VideoTest.zip

  • Hi Dennis,

    Did you enable phase shift load in sysconfig? I don't see this in your.syscfg file. This is required for the sync in pulse to take effect, even if you use a phase shift value of 0.

    Thank you,

    Luke

  • Hi Luke, 

    Thanks for you answer!

    Is this fact stated anywhere in the TMS320F28004x Real-Time Microcontrollers Technical Reference Manual? I have found that the EPWM1SYNCIN register is set to EXTSYNCIN1 by default (see picture below), therefore I assume nothing more should be configured.

    I have tried what you suggest. I have checked the Enable Phase Shift Load option on EPWM Time Base section and I have tried the same test described on the post. There are the screenshot of the configuration and the new .syscfg code.

    /**
     * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
     * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
     * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00"
     * @versions {"tool":"1.18.0+3266"}
     */
    
    /**
     * Import the modules used in this configuration.
     */
    const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1            = epwm.addInstance();
    const inputxbar        = scripting.addModule("/driverlib/inputxbar.js", {}, false);
    const inputxbar1       = inputxbar.addInstance();
    const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js");
    const inputxbar_input1 = inputxbar_input.addInstance();
    const sync             = scripting.addModule("/driverlib/sync.js");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    const mux1       = system.clockTree["CANABCLKSEL"];
    mux1.inputSelect = "XTAL";
    
    const mux2       = system.clockTree["OSCCLKSRCSEL"];
    mux2.inputSelect = "INTOSC1";
    
    epwm1.$name                                                    = "myEPWM1";
    epwm1.epwmTimebase_period                                      = 2000;
    epwm1.epwmCounterCompare_cmpA                                  = 1000;
    epwm1.epwmCounterCompare_cmpB                                  = 500;
    epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
    epwm1.epwmTimebase_clockDiv                                    = "EPWM_CLOCK_DIVIDER_8";
    epwm1.epwmTimebase_hsClockDiv                                  = "EPWM_HSCLOCK_DIVIDER_1";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmEventTrigger_enableInterrupt                         = true;
    epwm1.epwmEventTrigger_interruptEventCount                     = "1";
    epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO";
    epwm1.epwmTimebase_phaseEnable                                 = true;
    epwm1.epwm.$assign                                             = "EPWM1";
    epwm1.epwm.epwm_aPin.$assign                                   = "GPIO0";
    epwm1.epwm.epwm_bPin.$assign                                   = "GPIO1";
    scripting.suppress("Clearing the phase shift value will cause the EPWM module to ignore the synchronization input pulse, if any\\.", epwm1, "epwmTimebase_phaseShift");
    
    inputxbar1.$name = "myINPUTXBAR5";
    
    inputxbar_input1.$name          = "myINPUTXBARINPUT0";
    inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
    inputxbar_input1.inputxbarGpio  = "GPIO39";

    However, nothing has changes, the PWM output still not sync to my GPIO39 input signal! The result is the same as the one I show in the video.

  • Hi Denys,

    Could you also try configuring GPIO39 as an input in SysConfig? I have modified the .syscfg file to add this, attached below:

    /**
     * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
     * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
     * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00"
     * @versions {"tool":"1.0.0+dev"}
     */
    
    /**
     * Import the modules used in this configuration.
     */
    const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1            = epwm.addInstance();
    const gpio             = scripting.addModule("/driverlib/gpio.js", {}, false);
    const gpio1            = gpio.addInstance();
    const inputxbar        = scripting.addModule("/driverlib/inputxbar.js", {}, false);
    const inputxbar1       = inputxbar.addInstance();
    const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js");
    const inputxbar_input1 = inputxbar_input.addInstance();
    const sync             = scripting.addModule("/driverlib/sync.js");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    epwm1.$name                                                    = "myEPWM1";
    epwm1.epwmTimebase_period                                      = 2000;
    epwm1.epwmCounterCompare_cmpA                                  = 1000;
    epwm1.epwmCounterCompare_cmpB                                  = 500;
    epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
    epwm1.epwmTimebase_clockDiv                                    = "EPWM_CLOCK_DIVIDER_8";
    epwm1.epwmTimebase_hsClockDiv                                  = "EPWM_HSCLOCK_DIVIDER_1";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmEventTrigger_enableInterrupt                         = true;
    epwm1.epwmEventTrigger_interruptEventCount                     = "1";
    epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO";
    epwm1.epwm.$assign                                             = "EPWM1";
    epwm1.epwm.epwm_aPin.$assign                                   = "GPIO0";
    epwm1.epwm.epwm_bPin.$assign                                   = "GPIO1";
    
    gpio1.$name           = "myGPIO0";
    gpio1.gpioPin.$assign = "GPIO39";
    
    inputxbar1.$name = "myINPUTXBAR5";
    
    inputxbar_input1.$name          = "myINPUTXBARINPUT0";
    inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
    inputxbar_input1.inputxbarGpio  = "GPIO39";
    

  • Hi Luke, 

    I have updated the .syscfg code with the GPIO39 input initialization. I still don't getting sync between GPIO39 and PWM.

    As a extra, I have tried changing the GPIO Qualification Mode from Synchronisation to SYSCLK to No synchronisation (picture below), however nothing changes.

  • Hi Denys,

    My apologies, I seem to have accidentally modified the previous .syscfg file I sent you and disabled phase shift load.

    I create a new test case for F2837xD launchpad which has the same sync scheme as F28004x. I used GPIO3 as the sync input and monitored INPUTXBAR5 using an outputxbar on GPIO2 to see the sync signal and PWM output on the same logic analyzer.

    //#############################################################################
    //
    // FILE:   epwm_ex3_synchronization.c
    //
    // TITLE:  ePWM Using The Synch Chain and Phase Shift.
    //
    //! \addtogroup driver_example_list
    //! <h1>ePWM Synchronization</h1>
    //!
    //! This example configures ePWM1, ePWM2, ePWM3 and ePWM4 as follows
    //!  - ePWM1 without phase shift as sync source
    //!  - ePWM2 with phase shift of 300 TBCLKs
    //!  - ePWM3 with phase shift of 600 TBCLKs
    //!  - ePWM4 with phase shift of 900 TBCLKs
    //!
    //! \b External \b Connections \n
    //! - GPIO0 EPWM1A
    //! - GPIO1 EPWM1B
    //! - GPIO2 EPWM2A
    //! - GPIO3 EPWM2B
    //! - GPIO4 EPWM3A
    //! - GPIO5 EPWM3B
    //! - GPIO6 EPWM4A
    //! - GPIO7 EPWM4B
    //!
    //! \b Watch \b Variables \n
    //! - None.
    //
    //#############################################################################
    //
    //
    // $Copyright:
    // Copyright (C) 2023 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"
    #include "board.h"
    
    
    __interrupt void epwm1ISR(void);
    __interrupt void epwm2ISR(void);
    __interrupt void epwm3ISR(void);
    __interrupt void epwm4ISR(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
        //
        Interrupt_register(INT_EPWM1, &epwm1ISR);
        //Interrupt_register(INT_EPWM2, &epwm2ISR);
        //Interrupt_register(INT_EPWM3, &epwm3ISR);
        //Interrupt_register(INT_EPWM4, &epwm4ISR);
    
    
        // Disable sync(Freeze clock to PWM as well). GTBCLKSYNC is applicable
        // only for multiple core devices. Uncomment the below statement if
        // applicable.
        //
        // SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_GTBCLKSYNC);
        SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    
        //
    
        // Configure GPIO0/1 , GPIO2/3 and GPIO4/5 and GPIO6/7 as
        // ePWM1A/1B, ePWM2A/2B, ePWM3A/3B, ePWM4A/4B pins respectively
        // Configure EPWM Modules
        //
        Board_init();
    
        //
        // 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);
        //Interrupt_enable(INT_EPWM4);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // IDLE loop. Just sit and loop forever (optional):
        //
        for(;;)
        {
    
        }
    }
    
    //
    // epwm1ISR - ePWM 1 ISR
    //
    __interrupt void epwm1ISR(void)
    {
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(myEPWM1_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // epwm2ISR - ePWM 2 ISR
    //
    /*__interrupt void epwm2ISR(void)
    {
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(myEPWM2_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // epwm3ISR - ePWM 3 ISR
    //
    __interrupt void epwm3ISR(void)
    {
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(myEPWM3_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }
    
    //
    // epwm4ISR - ePWM 4 ISR
    //
    __interrupt void epwm4ISR(void)
    {
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(myEPWM4_BASE);
    
        //
        // Acknowledge interrupt group
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
    }*/
    
    /**
     * Import the modules used in this configuration.
     */
    const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1            = epwm.addInstance();
    const gpio             = scripting.addModule("/driverlib/gpio.js", {}, false);
    const gpio1            = gpio.addInstance();
    const inputxbar        = scripting.addModule("/driverlib/inputxbar.js", {}, false);
    const inputxbar1       = inputxbar.addInstance();
    const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js");
    const inputxbar_input1 = inputxbar_input.addInstance();
    const outputxbar       = scripting.addModule("/driverlib/outputxbar.js", {}, false);
    const outputxbar1      = outputxbar.addInstance();
    const sync             = scripting.addModule("/driverlib/sync.js");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    epwm1.$name                                                    = "myEPWM1";
    epwm1.epwmTimebase_period                                      = 2000;
    epwm1.epwmCounterCompare_cmpA                                  = 1000;
    epwm1.epwmCounterCompare_cmpB                                  = 500;
    epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
    epwm1.epwmTimebase_clockDiv                                    = "EPWM_CLOCK_DIVIDER_8";
    epwm1.epwmTimebase_hsClockDiv                                  = "EPWM_HSCLOCK_DIVIDER_1";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPB = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmEventTrigger_enableInterrupt                         = true;
    epwm1.epwmEventTrigger_interruptEventCount                     = "1";
    epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO";
    epwm1.epwmTimebase_phaseEnable                                 = true;
    epwm1.epwm.$assign                                             = "EPWM1";
    epwm1.epwm.epwm_aPin.$assign                                   = "GPIO0";
    epwm1.epwm.epwm_bPin.$assign                                   = "GPIO1";
    
    gpio1.$name           = "myGPIO0";
    gpio1.gpioPin.$assign = "GPIO3";
    
    inputxbar1.$name = "myINPUTXBAR5";
    
    inputxbar_input1.$name          = "myINPUTXBARINPUT0";
    inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
    inputxbar_input1.inputxbarGpio  = "GPIO3";
    
    outputxbar1.$name           = "myOUTPUTXBAR0";
    outputxbar1.useSourceSelect = true;
    outputxbar1.sourceSignals   = ["INPUTXBAR5"];
    
    /**
     * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
     * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
     * re-solve from scratch.
     */
    outputxbar1.outputxbar.$suggestSolution               = "OUTPUTXBAR1";
    outputxbar1.outputxbar.outputxbarPin.$suggestSolution = "GPIO2";
    

    Let me know if you're able to recreate this on F28004x.

    Thank you,

    Luke

  • Hi Luke,

    I have tried your suggested code on the TMS320F280049C control card along with TMDSHSECDOCK, and also on LAUNCHXL-F280049C to double check. However, does not work on either of them. 

    I attach here another video of the test result where you can see that the sync to the external signal is not happening. The video shows the oscilloscope where yellow is related to GPIO3 (ext. signal input), pink relates to GPIO2 (OUTPUTXBAR), light and dark blue are referred to GPIO0 and GPIIO1 (PWM1A and PWM1B) accordingly.

    What else may be wrong if phase shift load is enabled? Do you have the capability to test your code on F28004x?

    Awaiting your answer!

    Regards, 

    Denys

    VIDEO HERE -VideoTest2.zip

  • Hi Denys,

    You're trying to synchronize ePWM1 only correct? Are you setting a TBPHS non zero? Can you set a single capture for the trigger on the rising edge of your EXTSYNCOUT and view the waveform changing when EXTSYNCOUT is applied?

    What should happen when you set a non zero TBPHS value, the waveform should change at that instant and set the TBCTR = TBPHS. If you hold the signal high, syncing will not continuously occur since it's rising edge activated.

    PWM1A and PWM1B cannot be synchronized since you can only synchronize between submodules like ePWM1 to ePWM2. ePWM1 module has one counter that is being used for both ePWM1A and EPWM1B output.

    If your TBPHS = 0. there will be no phase shift. TBPHS should be non zero value in order to see the phase shift. Please note there is a 2 EPWM clk cycle delay when running at TBCLK = EPWMCLK when syncing from control module to target modules. 

    Best,

    Ryan Ma

  • Hi Ryan, 

    I appreciate your reply! Here below I provide my answers to your questions:

    You're trying to synchronize ePWM1 only correct?

    Yes, I want ePWM1 to by synchronised to rising edge of external signal coming through INPUTXBAR5. 

    Are you setting a TBPHS non zero?

    I believe that the following SysConfig ePWM configuration (see picture below) sets TBCTL[PHSEN] = 1 in order to allow synchronisation. Moreover, I don't need phase shift between sync input and ePWM1, thus TBPHS=0.

    Can you set a single capture for the trigger on the rising edge of your EXTSYNCOUT and view the waveform changing when EXTSYNCOUT is applied?

    I am not looking for EXTSYNCOUT here. I want ePWM1 to by sync to EXTSYNCIN1 which is inputted through INPUTXBAR5. This input signal is square wave (2V amplitude, 50% duty cycle and 100Hz)  Please check the two figures in main question. 

    Just to highlight again the purpose of this post: Synchronise a PWM with an external signal where, every time the controlling signal (INPUTXBAR5) has a rising edge the PWM (ePWM1) signal is reset. I am not interested in phase shift between ePWMs, what I need is 50% duty ePWM1A and complementary ePWM1B output, but sync to input signal rising edges. 

    I would appreciate if you can share a working code with the aforementioned feature for F28004x. Your colleague Luke shared the .c and .syscfg implemented and tested in F2837xD however it doesn't work in mine. 

    Best, 

    Denys 

  • Hi Denys,

    The root cause of this issue is a bug within SysConfig. I have went ahead and filed a ticket to get this fixed. Thank you for bringing this to our attention!

    After your intialization of PWM from Board_init(); SysConfig should have generated code to set the SYNCIN for ePWM1 to be EXTSYNCIN1 however it did not seem to generate this code and thus your PWM never used SYNCIN. The default for the SyncSocRegs.EPWM1SYNCIN is 7h. So the SYNCIN for ePWM1 was never being properly set thus seeing no phase shift.

    Here is a test case for you to try it on F28004x device. Along with the scope shot. Please verify this works on your end, apologize for any confusion!

    Also want to clarify, setting TBPHS = 0 does not cause SYNCIN to be ignored. Here is the test case. You can change Phase shift to be whatever you like Slight smile

    //#############################################################################
    //
    // FILE:   main.c
    //
    // TITLE:  Universal Empty Project
    //
    // Universal Empty Project Example
    //
    // This example is an empty project setup for Driverlib development.
    //
    //#############################################################################
    //
    //
    // $Copyright: $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    #include "c2000ware_libraries.h"
    void INT_myEPWM0_ISR(void);
    
    void INT_myEPWM0_ISR(void){
        GPIO_writePin(myGPIO0, 1);
    
        //
        // Clear INT flag for this timer
        //
        EPWM_clearEventTriggerInterruptFlag(myEPWM0_BASE);
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 3
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP3);
        GPIO_writePin(myGPIO0, 0);
        return;
    }
    //
    // 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();
    
        //
        // PinMux and Peripheral Initialization
        //
        Board_init();
        SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
        EPWM_setTimeBaseCounter(myEPWM0_BASE, 0);
        SysCtl_setSyncInputConfig(SYSCTL_SYNC_IN_EPWM1, SYSCTL_SYNC_IN_SRC_EXTSYNCIN1);
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
        //
        // C2000Ware Library initialization
        //
        C2000Ware_libraries_init();
    
        //
        // Enable Global Interrupt (INTM) and real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        while(1)
        {
            
        }
    }
    
    //
    // End of File
    //
    
    

    /**
     * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
     * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
     * @cliArgs --board "/boards/LAUNCHXL_F280049C" --context "system" --product "C2000WARE@5.02.00.00"
     * @versions {"tool":"1.17.0+3128"}
     */
    
    /**
     * Import the modules used in this configuration.
     */
    const device_support   = scripting.addModule("/driverlib/device_support.js");
    const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1            = epwm.addInstance();
    const gpio             = scripting.addModule("/driverlib/gpio.js", {}, false);
    const gpio1            = gpio.addInstance();
    const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js", {}, false);
    const inputxbar_input1 = inputxbar_input.addInstance();
    const memcfg           = scripting.addModule("/driverlib/memcfg.js");
    const outputxbar       = scripting.addModule("/driverlib/outputxbar.js", {}, false);
    const outputxbar1      = outputxbar.addInstance();
    const sync             = scripting.addModule("/driverlib/sync.js");
    const sysctl           = scripting.addModule("/driverlib/sysctl.js");
    const CMD              = scripting.addModule("/utilities/cmd_tool/cmd_syscfg/source/CMD");
    const CMD1             = CMD.addInstance();
    const CMD2             = CMD.addInstance();
    
    /**
     * Write custom configuration values to the imported modules.
     */
    epwm1.$name                                                    = "myEPWM0";
    epwm1.epwmTimebase_phaseEnable                                 = true;
    epwm1.$hardware                                                = system.deviceData.board.components.BP_SITE_2.subComponents.PWM_LOC1;
    epwm1.epwmTimebase_period                                      = 1000;
    epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmCounterCompare_cmpA                                  = 500;
    epwm1.epwmCounterCompare_cmpB                                  = 500;
    epwm1.epwmCounterCompare_cmpC                                  = 700;
    epwm1.epwmEventTrigger_enableInterrupt                         = true;
    epwm1.epwmEventTrigger_interruptSource                         = "EPWM_INT_TBCTR_U_CMPC";
    epwm1.epwmEventTrigger_registerInterrupts                      = true;
    epwm1.epwmEventTrigger_interruptEventCount                     = "2";
    epwm1.epwmTimebase_phaseShift                                  = 499;
    epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN";
    epwm1.epwmInt.enableInterrupt                                  = true;
    
    gpio1.$name             = "myGPIO0";
    gpio1.direction         = "GPIO_DIR_MODE_OUT";
    gpio1.writeInitialValue = true;
    gpio1.gpioPin.$assign   = "boosterpack1.13";
    
    inputxbar_input1.$name          = "myINPUTXBARINPUT0";
    inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
    inputxbar_input1.inputxbarGpio  = "GPIO39";
    
    outputxbar1.$name                            = "myOUTPUTXBAR0";
    outputxbar1.useSourceSelect                  = true;
    outputxbar1.sourceSignals                    = ["EXTSYNCOUT"];
    outputxbar1.outputxbar.outputxbarPin.$assign = "boosterpack2.75";
    scripting.suppress("Connected to hardware,@@@.+?@@@ is connected to EPWM2 BP on the LaunchPad F280049C\\. Consider selecting it in 'use hardware' above\\. @@@.+?@@@", outputxbar1.outputxbar, "outputxbarPin");
    
    CMD1.$name                    = "generic_ram_lnk";
    CMD1.sectionMemory_bss        = ["RAMLS5"];
    CMD1.sectionMemory_data       = ["RAMLS5"];
    CMD1.sectionMemory_ramfunc    = ["RAMM0"];
    CMD1.sectionMemory_cinit      = ["RAMM0"];
    CMD1.sectionMemory_stack      = ["RAMM1"];
    CMD1.sectionMemory_init_array = ["RAMM0"];
    CMD1.sectionMemory_switch     = ["RAMM0"];
    CMD1.sectionMemory_const      = ["RAMLS5"];
    CMD1.sectionMemory_sysmem     = ["RAMLS5"];
    CMD1.sectionMemory_text       = ["RAMGS0","RAMGS1","RAMLS0","RAMLS1","RAMLS2","RAMLS3","RAMLS4","RAMLS5","RAMLS6","RAMLS7","RAMM0","RAMM1"];
    
    CMD2.$name                               = "generic_flash_lnk";
    CMD2.sectionAlignEnable_ramfunc          = true;
    CMD2.sectionAlignEnable_text             = true;
    CMD2.sectionAlignEnable_binit            = true;
    CMD2.sectionAlignEnable_cinit            = true;
    CMD2.sectionAlignEnable_switch           = true;
    CMD2.sectionAlignEnable_init_array       = true;
    CMD2.sectionAlignEnable_const            = true;
    CMD2.sectionAlignEnable_ovly             = true;
    CMD2.sectionMemory_codestart             = "0x080000";
    CMD2.sectionMemory_stack                 = ["RAMM1"];
    CMD2.sectionMemory_bss                   = ["RAMLS5"];
    CMD2.sectionMemory_data                  = ["RAMLS5"];
    CMD2.sectionMemory_sysmem                = ["RAMLS5"];
    CMD2.sectionRunFromDifferentAddr_ramfunc = true;
    CMD2.sectionRun_ramfunc                  = ["RAMLS0"];
    CMD2.sectionBinit_ramfunc                = false;
    CMD2.sectionMemory_ramfunc               = ["FLASH_BANK0_SEC1"];
    CMD2.sectionMemory_text                  = ["FLASH_BANK0_SEC2","FLASH_BANK0_SEC3","FLASH_BANK0_SEC5"];
    CMD2.sectionMemory_binit                 = ["FLASH_BANK0_SEC1"];
    CMD2.sectionMemory_cinit                 = ["FLASH_BANK0_SEC1"];
    CMD2.sectionMemory_switch                = ["FLASH_BANK0_SEC1"];
    CMD2.sectionMemory_init_array            = ["FLASH_BANK0_SEC1"];
    CMD2.sectionMemory_const                 = ["FLASH_BANK0_SEC4"];
    CMD2.sectionMemory_ovly                  = ["FLASH_BANK0_SEC1"];
    
    /**
     * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
     * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
     * re-solve from scratch.
     */
    epwm1.epwm.$suggestSolution             = "EPWM1";
    epwm1.epwm.epwm_aPin.$suggestSolution   = "boosterpack2.80";
    epwm1.epwm.epwm_bPin.$suggestSolution   = "boosterpack2.79";
    outputxbar1.outputxbar.$suggestSolution = "OUTPUTXBAR2";
    

    Yellow: PWM1A

    Blue: PWM1B

    Pink: GPIO39

    Green: EXTSYNCOUT (passes through ePWM1)

    Tested this using our F28004x launchpad. ISR is generated after 2nd event using the event trigger submodule in which I toggle the GPIO to send out a SYNC Pulse.

  • Hi Ryan, 

    Thanks for your answer.

    I am trying to test your code but, while building the project, I get errors I am not sure what they are (see picture below)

    My procedure was the following:

    1.Take the example epwm_ex3_synchronization.projectspec (located at C2000Ware_5_00_00_00\driverlib\f28004x\examples\epwm)

    2. Modify epwm_ex3_synchronization.c code by yours

    3. Modify epwm_ex3_synchronization.syscfg code by yours.

    Please give me a hand on this so that I can perform the test.

    Regards, 

    Denys

  • Hi Denys,

    Can you open syscfg within CCS after copying the contents over from the .syscfg I provided?

    Best,

    Ryan Ma

  • Hi Ryan, 

    No, I can not. The following error appears at the screen:

    Regards, 

    Denys Ovsiyenko

  • Hi Denys, can you try copying this over instead?

    /**
     * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
     * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
     * @cliArgs --device "F28004x" --package "F28004x_100PZ" --part "F28004x_100PZ" --context "system" --product "C2000WARE@5.00.00.00"
     * @versions {"tool":"1.18.0+3267"}
     */
    
    /**
     * Import the modules used in this configuration.
     */
    const epwm             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1            = epwm.addInstance();
    const gpio             = scripting.addModule("/driverlib/gpio.js", {}, false);
    const gpio1            = gpio.addInstance();
    const inputxbar_input  = scripting.addModule("/driverlib/inputxbar_input.js", {}, false);
    const inputxbar_input1 = inputxbar_input.addInstance();
    const memcfg           = scripting.addModule("/driverlib/memcfg.js");
    const outputxbar       = scripting.addModule("/driverlib/outputxbar.js", {}, false);
    const outputxbar1      = outputxbar.addInstance();
    const sync             = scripting.addModule("/driverlib/sync.js");
    const sysctl           = scripting.addModule("/driverlib/sysctl.js");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    epwm1.$name                                                    = "myEPWM0";
    epwm1.epwmTimebase_phaseEnable                                 = true;
    epwm1.epwmTimebase_period                                      = 1000;
    epwm1.epwmTimebase_counterMode                                 = "EPWM_COUNTER_MODE_UP";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_A_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_ZERO    = "EPWM_AQ_OUTPUT_LOW";
    epwm1.epwmActionQualifier_EPWM_AQ_OUTPUT_B_ON_TIMEBASE_UP_CMPA = "EPWM_AQ_OUTPUT_HIGH";
    epwm1.epwmCounterCompare_cmpA                                  = 500;
    epwm1.epwmCounterCompare_cmpB                                  = 500;
    epwm1.epwmCounterCompare_cmpC                                  = 700;
    epwm1.epwmEventTrigger_enableInterrupt                         = true;
    epwm1.epwmEventTrigger_interruptSource                         = "EPWM_INT_TBCTR_U_CMPC";
    epwm1.epwmEventTrigger_registerInterrupts                      = true;
    epwm1.epwmEventTrigger_interruptEventCount                     = "2";
    epwm1.epwmTimebase_phaseShift                                  = 499;
    epwm1.epwmTimebase_syncOutPulseMode                            = "EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN";
    epwm1.epwm.$assign                                             = "EPWM1";
    epwm1.epwmInt.enableInterrupt                                  = true;
    
    gpio1.$name             = "myGPIO0";
    gpio1.direction         = "GPIO_DIR_MODE_OUT";
    gpio1.writeInitialValue = true;
    gpio1.gpioPin.$assign   = "GPIO39";
    
    inputxbar_input1.$name          = "myINPUTXBARINPUT0";
    inputxbar_input1.inputxbarInput = "XBAR_INPUT5";
    inputxbar_input1.inputxbarGpio  = "GPIO39";
    
    outputxbar1.$name                            = "myOUTPUTXBAR0";
    outputxbar1.useSourceSelect                  = true;
    outputxbar1.sourceSignals                    = ["EXTSYNCOUT"];
    outputxbar1.outputxbar.outputxbarPin.$assign = "GPIO3";
    
    /**
     * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
     * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
     * re-solve from scratch.
     */
    epwm1.epwm.epwm_aPin.$suggestSolution   = "GPIO0";
    epwm1.epwm.epwm_bPin.$suggestSolution   = "GPIO1";
    outputxbar1.outputxbar.$suggestSolution = "OUTPUTXBAR2";
    

    Best,

    Ryan Ma

  • Hello Ryan, 

    It works fine with the last .syscfg you shared. However it is still not what I expect.

    Your implementation generates kind of interrupt but doesn't synchronise to any external signal. Please check again the video on this site (I have posted earlier) to fully understand what I expect.  VIDEO HERE -  Sync PWM with an External Signal - TI Hercules Microcontroller

    The idea is simple. GPIO39 (INPUTXBAR5) should receive a square signal provided by an external circuitry (e.g. function generator), to which ePWM1 should be synchronised. The synchronisation must happen on the rising edges of the GPIO39 input signal.

    I hope that this time I explained well myself.

    Awaiting your answer. 

    Regards, 

    Denys

  • Hi Denys,

    Please take a look at the code and scope shot. I am synchronizing to a GPIO signal acting like the function generator. I am routing the GPIO39 signal through the input x-bar5 where the PWM1 module has phase shift enabled. To verify that the SYNC signal is going to ePWM1, I route ePWMSYNCOUT to another gpio so I know the SYNC signal has reached the PWM module. 

    You can also verify that when the synchronization comes to the ePWM, the duty width is longer because the counter is set to whatever TBPHS is equal to.

    In the test case above, you can change GPIO to instead be an input where you connect your external circuity to and the behavior will be the same.

    Best,

    Ryan Ma