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.

TMS320F28377D: ePWM using CLB Tool

Part Number: TMS320F28377D
Other Parts Discussed in Thread: SYSCONFIG

Hi,

I want to use the CLB tool to generate a customised ePWM signal using ePWM internal peripherals of PWM1 and PWM2 and apply the following logic in a TIEL to produce PWM3A and PWM3B at pins GPIO4 and GPIO5 by using CLB overriding option.  

(PWM3A= PWM1A XOR PWM2A ), and (PWM3B =PWM1B  NXOR PWM2B )

I modified the clb_ex8_external_signal_AND_gate CLB example and inserted a few additional codes to generate PWM1 and PWM2 signals as global signals.

However, I don't get the signals I am looking for. So please advice me?

    
    
    #include "driverlib.h"
    #include "device.h"
    #include "clb_config.h"
    #include "clb.h"
    #include "board.h"
    #include "F28x_Project.h"
    
    
    void InitEPwm1(void);               // Init ePWM module 1
    void InitEPwm2(void);
    
    
    
    void main(void)
    {
    
        Device_init();
        Device_initGPIO();
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
    
            InitEPwm1();    //
            InitEPwm2();    //
    
    
            SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_EPWM3);
    
    
    
    
        Board_init();
    
        initTILE1(myCLB0_BASE);
        CLB_enableCLB(myCLB0_BASE);
    
    
        while(1)
        {
    
            asm(" NOP");
        }
    }
    void InitEPwm1(void)
    {
        EPwm1Regs.TBPRD = 450; // Period = 900 TBCLK counts
        EPwm1Regs.TBPHS.bit.TBPHS = 0; // Set Phase register to zero
        EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Symmetrical mode
        EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
        EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
        EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
        EPwm1Regs.CMPA.bit.CMPA= 285; // adjust duty for output EPWM1A
        EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
        EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
        EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // set actions for EPWM1A
        EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
        EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
        EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi complementary
        EPwm1Regs.DBRED.bit.DBRED = 20;    // Dead-Band Generator Rising Edge Delay Count Register
        EPwm1Regs.DBFED.bit.DBFED = 20;    // Dead-Band Generator Falling Edge Delay Count Register
    }
    
    //------------------------------------------------------------------------------------------
    void InitEPwm2(void)
    {
        EPwm2Regs.TBPRD = 450; // Period = 900 TBCLK counts
        EPwm2Regs.TBPHS.bit.TBPHS = 300; // Phase = 300/900 * 360 = 120 deg
        EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Symmetrical mode
        EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
        EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN; // Count DOWN on sync (=120 deg)
        EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
        EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // sync flow-through
        EPwm2Regs.CMPA.bit.CMPA = 285; // adjust duty for output EPWM2A
        EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
        EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
        EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
        EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
        EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; // set actions for EPWM2A
        EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
        EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
        EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi Complementary
        EPwm2Regs.DBRED.bit.DBRED = 20;    // Dead-Band Generator Rising Edge Delay Count Register
        EPwm2Regs.DBFED.bit.DBFED = 20;    // Dead-Band Generator Falling Edge Delay Count Register
    }
    
  • Send me your Syscfg file and your main.c file on here.

  • Hi Nima, 

    Thanks for your reply. Please find attached. The system doesn't allow me to attach the syscfg. file for some reason, so I am attaching the full folder.

    I have also included the full project as I have added the header files to the original example project. 

    FYI, I am using the F28377D microcontroller on a custom control board developed by my university, yet the GPIO pins are the same.  I am attaching the related documents. 

    F28377D controller software description v1_01.pdf

    CLBTool.zip 

    
        #include "driverlib.h"
        #include "device.h"
        #include "clb_config.h"
        #include "clb.h"
        #include "board.h"
        #include "F28x_Project.h"
    
    
        void InitEPwm1(void);               // Init ePWM module 1
        void InitEPwm2(void);
    
    
    
        void main(void)
        {
    
            Device_init();
            Device_initGPIO();
    
            Interrupt_initModule();
            Interrupt_initVectorTable();
    
    
            Board_init();
            SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_EPWM3);
            initTILE1(myCLB3_BASE);
            CLB_enableCLB(myCLB3_BASE);
    
    
            InitEPwm1();    //
            InitEPwm2();    //
    
            while(1)
            {
    
                asm(" NOP");
            }
        }
        void InitEPwm1(void)
        {
            EPwm1Regs.TBPRD = 450; // Period = 900 TBCLK counts
            EPwm1Regs.TBPHS.bit.TBPHS = 0; // Set Phase register to zero
            EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Symmetrical mode
            EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Master module
            EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
            EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // Sync down-stream module
            EPwm1Regs.CMPA.bit.CMPA= 285; // adjust duty for output EPWM1A
            EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
            EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
            EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
            EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
            EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // set actions for EPWM1A
            EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
            EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
            EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi complementary
            EPwm1Regs.DBRED.bit.DBRED = 20;    // Dead-Band Generator Rising Edge Delay Count Register
            EPwm1Regs.DBFED.bit.DBFED = 20;    // Dead-Band Generator Falling Edge Delay Count Register
        }
    
        //------------------------------------------------------------------------------------------
        void InitEPwm2(void)
        {
            EPwm2Regs.TBPRD = 450; // Period = 900 TBCLK counts
            EPwm2Regs.TBPHS.bit.TBPHS = 300; // Phase = 300/900 * 360 = 120 deg
            EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Symmetrical mode
            EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Slave module
            EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN; // Count DOWN on sync (=120 deg)
            EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
            EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // sync flow-through
            EPwm2Regs.CMPA.bit.CMPA = 285; // adjust duty for output EPWM2A
            EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
            EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
            EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
            EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
            EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; // set actions for EPWM2A
            EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
            EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
            EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi Complementary
            EPwm2Regs.DBRED.bit.DBRED = 20;    // Dead-Band Generator Rising Edge Delay Count Register
            EPwm2Regs.DBFED.bit.DBFED = 20;    // Dead-Band Generator Falling Edge Delay Count Register
        }
    
    

  • There is something wrong in your hardware your code seems correct. Here is my latest one with results.

    //#############################################################################
    //
    // FILE:   clb_ex8_external_signal_AND_gate.c
    //
    // TITLE:  CLB External Signal AND Gate.
    //
    //! \addtogroup driver_example_list
    //! <h1>CLB External Signal AND Gate</h1>
    //!
    //! For the detailed description of this example, please refer to: 
    //!  C2000Ware_PATH\utilities\clb_tool\clb_syscfg\doc\CLB Tool Users Guide.pdf
    //!
    //
    //
    //#############################################################################
    // $TI Release: F2837xD Support Library v3.12.00.00 $
    // $Release Date: Fri Feb  5 23:22:05 IST 2021 $
    // $Copyright:
    // Copyright (C) 2013-2021 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.
    // $
    //#############################################################################
    
    
    
    #include "driverlib.h"
    #include "device.h"
    #include "clb_config.h"
    #include "clb.h"
    #include "board.h"
    
    void initEPWM(uint32_t base);
    
    void main(void)
    {
    
        Device_init();
        Device_initGPIO();
    
        Interrupt_initModule();
        Interrupt_initVectorTable();
    
    
        Board_init();
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_EPWM3);
        initTILE1(myCLB3_BASE);
        CLB_enableCLB(myCLB3_BASE);
    
    
    
        //
        // Initialize PWM1 without phase shift as master
        //
        initEPWM(myEPWM1_BASE);
    
        //
        // Initialize PWM2 with phase shift of 300 TBCLKs
        //
        initEPWM(myEPWM2_BASE);
        EPWM_selectPeriodLoadEvent(myEPWM2_BASE, EPWM_SHADOW_LOAD_MODE_SYNC);
        EPWM_setPhaseShift(myEPWM2_BASE, 300);
        EPWM_setTimeBaseCounter(myEPWM2_BASE, 300);
    
        while(1)
        {
    
            asm(" NOP");
        }
    }
    
    void initEPWM(uint32_t base)
    {
        //
        // Set-up TBCLK
        //
        EPWM_setTimeBasePeriod(base, 450);
        EPWM_setPhaseShift(base, 0U);
        EPWM_setTimeBaseCounter(base, 0U);
    
        //
        // Set Compare values
        //
        EPWM_setCounterCompareValue(base,
                                    EPWM_COUNTER_COMPARE_A,
                                    450/2);
        EPWM_setCounterCompareValue(base,
                                    EPWM_COUNTER_COMPARE_B,
                                    450/4);
    
        //
        // Set up counter mode
        //
        EPWM_setTimeBaseCounterMode(base, EPWM_COUNTER_MODE_UP);
        EPWM_disablePhaseShiftLoad(base);
        EPWM_setClockPrescaler(base,
                               EPWM_CLOCK_DIVIDER_8,
                               EPWM_HSCLOCK_DIVIDER_1);
    
        //
        // Set up shadowing
        //
        EPWM_setCounterCompareShadowLoadMode(base,
                                             EPWM_COUNTER_COMPARE_A,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);
        EPWM_setCounterCompareShadowLoadMode(base,
                                             EPWM_COUNTER_COMPARE_B,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);
    
        //
        // Set actions
        //
        EPWM_setActionQualifierAction(base,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
        EPWM_setActionQualifierAction(base,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_HIGH,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
        EPWM_setActionQualifierAction(base,
                                      EPWM_AQ_OUTPUT_A,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
        EPWM_setActionQualifierAction(base,
                                      EPWM_AQ_OUTPUT_B,
                                      EPWM_AQ_OUTPUT_LOW,
                                      EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    
    
        //
        // Interrupt where we will change the Compare Values
        // Select INT on Time base counter zero event,
        // Enable INT, generate INT on 1rd event
        //
        EPWM_setInterruptSource(base, EPWM_INT_TBCTR_ZERO);
        EPWM_disableInterrupt(base);
        EPWM_setInterruptEventCount(base, 1U);
    }
    

    The sysconfig file:

    /**
     * Import the modules used in this configuration.
     */
    const clb                              = scripting.addModule("/driverlib/clb.js", {}, false);
    const clb1                             = clb.addInstance();
    const epwm                             = scripting.addModule("/driverlib/epwm.js", {}, false);
    const epwm1                            = epwm.addInstance();
    const epwm2                            = epwm.addInstance();
    const epwm3                            = epwm.addInstance();
    const TILE                             = scripting.addModule("/utilities/clb_tool/clb_syscfg/source/TILE");
    const TILE1                            = TILE.addInstance();
    const clb_run_dynamic_template_clb_c   = scripting.addModule("/utilities/clb_tool/clb_syscfg/source/clb_run_dynamic_template_clb_c.js");
    const clb_run_dynamic_template_clb_dot = scripting.addModule("/utilities/clb_tool/clb_syscfg/source/clb_run_dynamic_template_clb_dot.js");
    const clb_run_dynamic_template_clb_h   = scripting.addModule("/utilities/clb_tool/clb_syscfg/source/clb_run_dynamic_template_clb_h.js");
    const clb_run_dynamic_template_clb_sim = scripting.addModule("/utilities/clb_tool/clb_syscfg/source/clb_run_dynamic_template_clb_sim.js");
    
    /**
     * Write custom configuration values to the imported modules.
     */
    clb1.clbBase                     = "CLB3_BASE";
    clb1.outputsToOverridePeripheral = ["CLB_OUT0","CLB_OUT2"];
    clb1.inputsUsed                  = ["CLB_IN0","CLB_IN1","CLB_IN2","CLB_IN3"];
    clb1.inputTypeCLB_IN0            = "GLOBAL";
    clb1.synchronizeCLB_IN0          = true;
    clb1.inputTypeCLB_IN1            = "GLOBAL";
    clb1.globalConfigCLB_IN1         = "CLB_GLOBAL_IN_MUX_EPWM1B";
    clb1.synchronizeCLB_IN1          = true;
    clb1.inputTypeCLB_IN2            = "GLOBAL";
    clb1.globalConfigCLB_IN2         = "CLB_GLOBAL_IN_MUX_EPWM2A";
    clb1.synchronizeCLB_IN2          = true;
    clb1.inputTypeCLB_IN3            = "GLOBAL";
    clb1.globalConfigCLB_IN3         = "CLB_GLOBAL_IN_MUX_EPWM2B";
    clb1.synchronizeCLB_IN3          = true;
    clb1.$name                       = "myCLB3";
    clb1.enableCLB                   = true;
    
    epwm1.$name                 = "myEPWM1";
    epwm1.epwm.$assign          = "EPWM1";
    epwm1.epwm.epwmaPin.$assign = "GPIO0";
    epwm1.epwm.epwmbPin.$assign = "GPIO1";
    
    epwm2.$name                 = "myEPWM2";
    epwm2.epwm.$assign          = "EPWM2";
    epwm2.epwm.epwmaPin.$assign = "GPIO2";
    epwm2.epwm.epwmbPin.$assign = "GPIO3";
    
    epwm3.$name                 = "myEPWM3";
    epwm3.epwm.$assign          = "EPWM3";
    epwm3.epwm.epwmaPin.$assign = "GPIO4";
    epwm3.epwm.epwmbPin.$assign = "GPIO5";
    
    TILE1.$name              = "TILE1";
    TILE1.BOUNDARY.$name     = "BOUNDARY0";
    TILE1.LUT_0.$name        = "LUT_0";
    TILE1.LUT_0.i0           = "BOUNDARY.in0";
    TILE1.LUT_0.i1           = "BOUNDARY.in2";
    TILE1.LUT_0.eqn          = "i0^i1";
    TILE1.LUT_1.$name        = "LUT_1";
    TILE1.LUT_1.i0           = "BOUNDARY.in1";
    TILE1.LUT_1.i1           = "BOUNDARY.in3";
    TILE1.LUT_1.eqn          = "!(i0^i1)";
    TILE1.LUT_2.$name        = "LUT_2";
    TILE1.FSM_0.$name        = "FSM_0";
    TILE1.FSM_1.$name        = "FSM_1";
    TILE1.FSM_2.$name        = "FSM_2";
    TILE1.COUNTER_0.$name    = "COUNTER_0";
    TILE1.COUNTER_1.$name    = "COUNTER_1";
    TILE1.COUNTER_2.$name    = "COUNTER_2";
    TILE1.OUTLUT_0.$name     = "OUTLUT_0";
    TILE1.OUTLUT_0.eqn       = "i0";
    TILE1.OUTLUT_0.i0        = "LUT_0.OUT";
    TILE1.OUTLUT_1.$name     = "OUTLUT_1";
    TILE1.OUTLUT_2.$name     = "OUTLUT_2";
    TILE1.OUTLUT_2.i0        = "LUT_1.OUT";
    TILE1.OUTLUT_2.eqn       = "i0";
    TILE1.OUTLUT_3.$name     = "OUTLUT_3";
    TILE1.OUTLUT_4.$name     = "OUTLUT_4";
    TILE1.OUTLUT_5.$name     = "OUTLUT_5";
    TILE1.OUTLUT_6.$name     = "OUTLUT_6";
    TILE1.OUTLUT_7.$name     = "OUTLUT_7";
    TILE1.HLC.$name          = "HLC_0";
    TILE1.HLC.program0.$name = "HLCP_0";
    TILE1.HLC.program1.$name = "HLCP_1";
    TILE1.HLC.program2.$name = "HLCP_2";
    TILE1.HLC.program3.$name = "HLCP_3";
    

    And the results are XORed.

    When writing professional code its important that you do it in small sections. A good debugger should divide down their code and see which code snippets work independently before moving on to the next.

    The code above works and now I have tested it on my HW.

    Please, next time make sure to test the examples with minimal edits and build on top of it step by step. 

    Nima

  • Hi Nima, I really appreciate your support with this and the time you spent solving the issue. It’s properly as you said I have something wrong in my HW. would it be possible please to send me the full project file after your modification? I just want to make sure I have the same project properties as yours. Hopefully I won’t bother you again then :) Regards, Mohammed
  • clb_ex8_external_signal_AND_gate.zip

    Thank you please make sure to click the verify answer on the code and the attached zip + my earlier comments.

  • You are superb Niam. Thanks a lot.

    I really appreciate it!

    Best regards,

    Mohammed

  • Hi Niam,

    I think I have no hope to make the CLB working :( 

    I used the .c and .syscfg files you send me and built the code with no errors. Yet, when I debug it I get PWM3 signals active high continuously as it was before, it doesn't toggle to the correct signals. Although I can generate PWM3 signals at pins GOPI4 and GPIO5 with no issue without the CLB tool. so nothing is wrong with my control board.

    I made a new forum seeking help and this would be final try.

    https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/978055

    Thanks for everything!

  • It must be your Hardware...