This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28377S: ePWM SETUP

Part Number: TMS320F28377S

Tool/software: Code Composer Studio

We use TMS320F28377S to control the three phase synchronous motor of elevator and ePWM1A/B-ePWM3A/B to generate three-phase SVPWM output. EPWM6A is used to output pulse signal to control elevator brake. SYSCLKOUT=120MHz. Call the following function to configure the ePWM module:

void SetPWM123(void) // setup ePWM1/2/3 modules for SVPWM

{ EPwm1Regs.TBCTL.bit.SYNCOSEL =0; /* Pass through*/

  EPwm2Regs.TBCTL.bit.SYNCOSEL =0; /* Pass through*/

  EPwm3Regs.TBCTL.bit.SYNCOSEL =0; /* Pass through*/

  EPwm1Regs.TBCTL.bit.PHSEN =1; /* Allow each timer to be sync'ed*/

  EPwm2Regs.TBCTL.bit.PHSEN =1; /* Allow each timer to be sync'ed*/

  EPwm3Regs.TBCTL.bit.PHSEN =1; /* Allow each timer to be sync'ed*/

  EPwm1Regs.TBPRD =2000; // set timer period,

  EPwm2Regs.TBPRD =2000; // set timer period

  EPwm3Regs.TBPRD =2000; // set timer period

  EPwm1Regs.TBPHS.bit.TBPHS =0; // Phase is 0

  EPwm2Regs.TBPHS.bit.TBPHS =0; // Phase is 0

  EPwm3Regs.TBPHS.bit.TBPHS =0; // Phase is 0

  EPwm1Regs.TBCTL.all =0xA08A; //0x2092;free run, count up when sync, TBCLK 30M,

  EPwm2Regs.TBCTL.all =0xA08A; //0x2086;free run, count up when sync, TBCLK 30M

  EPwm3Regs.TBCTL.all =0xA08A; //0x2086;free run, count up when sync, TBCLK 30M,

  EPwm1Regs.CMPCTL.all =0; // load CMPA/B when CTR=0, shadow mode

  EPwm2Regs.CMPCTL.all =0; // load CMPA/B when CTR=0, shadow mode

  EPwm3Regs.CMPCTL.all =0; // load CMPA/B when CTR=0, shadow mode

  EPwm1Regs.CMPA.bit.CMPA =200; // CMPA

  EPwm2Regs.CMPA.bit.CMPA =200; // CMPA

  EPwm3Regs.CMPA.bit.CMPA =200; // CMPA

  EPwm1Regs.AQCTLA.all =0x61; // set wehn CAU, clear when CAD or CTR=0

  EPwm2Regs.AQCTLA.all =0x61; // set wehn CAU, clear when CAD or CTR=0

  EPwm3Regs.AQCTLA.all =0x61; // set wehn CAU, clear when CAD or CTR=0

  EPwm1Regs.DBCTL.all =11; // enable deadband, active high complementary

  EPwm2Regs.DBCTL.all =11; // enable deadband, active high complementary

  EPwm3Regs.DBCTL.all =11; // enable deadband, active high complementary

  EPwm1Regs.DBRED.all =60; // PWM rising-edge delay

  EPwm1Regs.DBFED.all =60; // PWM falling-edge delay

  EPwm2Regs.DBRED.all =60; // PWM rising-edge delay

  EPwm2Regs.DBFED.all =60; // PWM falling-edge delay

  EPwm3Regs.DBRED.all =60; // PWM rising-edge delay

  EPwm3Regs.DBFED.all =60; // PWM falling-edge delay

  EALLOW;

  EPwm1Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm2Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm3Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm1Regs.TZFRC.bit.OST =1; // force ePWM1A and ePWM1B pin output low

  EPwm2Regs.TZFRC.bit.OST =1; // force ePWM2A and ePWM2B pin output low

  EPwm3Regs.TZFRC.bit.OST =1; // force ePWM1A and ePWM3B pin output low

  EDIS;

  EPwm1Regs.TBCTR =0; // Clear counter

  EPwm2Regs.TBCTR =0; // Clear counter

  EPwm3Regs.TBCTR =0; // Clear counter

  EPwm6Regs.TBCTL.all =0xA08A; // free run, count up when sync, TBCLK 30M

  EPwm6Regs.TBPRD =12500; // Set timer period, 1.2k Hz

  EPwm6Regs.AQCTLA.all =0x61;

  EPwm6Regs.DBCTL.all =8; // disable deadband, active high complementary

  EPwm6Regs.CMPA.bit.CMPA =10000; // CMPA

  EPwm6Regs.TBCTR =0; // Clear counter

  EALLOW;

  CpuSysRegs.PCLKCR0.bit.TBCLKSYNC =1;

  EPwm6Regs.TZCTL.all =2; // set trip zone signal will clear ePWM6A pin out low

  EPwm4Regs.TZFRC.bit.OST =1; // force EPWM4A pin output low, not brake

  EPwm6Regs.TZFRC.bit.OST =1; // force ePWM6A pin output low, not open lock

  EDIS;

}

Invoke the following function to start the ePWM output:

void EPinPWM123(void) // enable ePWM1/2/3 pin output

{ EALLOW;

  Cla1Regs.MICLR.all =0xFF; // clear all cla interrupt flag

  Cla1Regs.MICLROVF.all =0xFF; // clear all cla interrupt overflow flag

  Cla1Regs.MIER.all =0x81; // enable CLA interrupt 1,8, disable 7

  EDIS;

  AdcaRegs.ADCINTFLGCLR.all=15; // clear ADCAINT1-4

  AdcaRegs.ADCINTOVFCLR.all=15; // clear ADCAINTOVFCLR1-4

  EPwm1Regs.ETCLR.all =5; // // Clear EPWM1 INT, ADCA

  EALLOW;

  PieVectTable.EPWM1_INT =&epwm1_timer_isr;

  EPwm1Regs.TZCLR.bit.OST =1; // enable ePWM1A and ePWM1B pin output

  EPwm2Regs.TZCLR.bit.OST =1; // enable ePWM2A and ePWM2B pin output

  EPwm3Regs.TZCLR.bit.OST =1; // enable ePWM1A and ePWM3B pin output

  EPwm6Regs.TZCLR.bit.OST =1; // enable ePWM6A

  EDIS;

  EPwm1Regs.ETSEL.all =0x909; // SOCA when TBCTR =TBPRD, enable underflow

}

The values of EPwm1Regs.CMPA.bit.CMPA, EPwm2Regs.CMPA.bit.CMPA, and EPwm3Regs.CMPA.bit.CMPA are calculated and set in Cla1Task1 (void), and the SVPWM wave is output in ePWMxA/B.(x=1/2/3).

Call the following function to stop the PWM output:

void LPinPWM123(void) // force ePWM1/2/3 output low

{ EALLOW;

  EPwm1Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm2Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm3Regs.TZCTL.all =10; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm6Regs.TZCTL.all =2; // set trip zone signal will clear ePWM1A/B pin out low

  EPwm1Regs.TZFRC.bit.OST =1; // force ePWM1A and ePWM1B pin output low

  EPwm2Regs.TZFRC.bit.OST =1; // force ePWM2A and ePWM2B pin output low

  EPwm3Regs.TZFRC.bit.OST =1; // force ePWM1A and ePWM3B pin output low

  EPwm3Regs.TZFRC.bit.OST =1; // force ePWM6A output low

  EDIS;

}

Call the above function to start and stop PWM output for about 3~7 times (PWM module runs normally), and then start PWM output, regardless of the value of EPwmxRegs.CMPA.bit.CMPA, ePWMxA/B (x=1/2/3) output high resistance at the same time, or at the same time output high level, ePWM6A is always high resistance or high level. What's the reason?

We think the possible reason is that there is an out of range pointer writing operation in the program, and the EPwmxRegs.TZCTL or EPwmxRegs.TBCTL registers are erroneously modified. We checked all the codes carefully and found no such cases.

  • Hi '7385,

    This is my understanding of the issue:
    *The ePWM modules start up and run as expected
    *If the modules are stopped and then started using the above function, after a random amount of times (3 to 7 times), the ePWM modules fail to start

    This seems like an issue where the ePWM is getting into an inconsistent state (not a rouge pointer write). Can you check the values of the key ePWM registers and see if there is any difference between the cases that start back up again correctly vs. the cases that fail to start?
  • [Ramesh] Devin, Here is the query from the user on another thread that I closed.

    Hello, Cottier

    Thank you for your guidance.

    We tested some registers of the ePWM module, including EPwmxRegs.TZFLG.all, EPwmxRges.TZCTL.all, EPwmxRges.DBCTL.all, EPwmxRges.AQCTL.all, EPwmxRges.AQCTLA.all, EPwmxRges.TBCTL.all, (x=1/2/3).The values of these registers are all expected. During the test, we found that when the ePWM module is not working properly, some function calls are not executed, especially the FLASH program calls the function running in RAM, or the RAM program calls the function running in FLASH. Is it a CMD file error? The following is the CMD file. Please help to see if there is any error or inappropriateness.


    // The user must define CLA_C in the project linker settings if using the


    // CLA C compiler


    // Project Properties -> C2000 Linker -> Advanced Options -> Command File


    // Preprocessing -> --define


    #ifndef CLA_C


    #define CLA_C


    #endif //CLA_C


    #ifdef CLA_C


    // Define a size for the CLA scratchpad area that will be used


    // by the CLA compiler for local symbols and temps


    // Also force references to the special symbols that mark the


    // scratchpad are.


    CLA_SCRATCHPAD_SIZE = 0x100;


    --undef_sym=__cla_scratchpad_end


    --undef_sym=__cla_scratchpad_start


    #endif //CLA_C


    MEMORY


    {


    PAGE 0 :


    /* BEGIN is used for the "boot to SARAM" bootloader mode */





    BEGIN : origin = 0x080000, length = 0x000002


    RAMM0 : origin = 0x000122, length = 0x0002DE


    RAMD0 : origin = 0x00B000, length = 0x000800


    RAMLS0_1 : origin = 0x008000, length = 0x001000


    RAMLS3_5 : origin = 0x009800, length = 0x001800


    //RAMLS3 : origin = 0x009800, length = 0x000800


    //RAMLS4 : origin = 0x00A000, length = 0x000800


    //RAMLS5 : origin = 0x00A800, length = 0x000800


    RAMGS14 : origin = 0x01A000, length = 0x001000


    RAMGS15 : origin = 0x01B000, length = 0x001000


    RESET : origin = 0x3FFFC0, length = 0x000002


    /* Flash sectors */


    FLASHA : origin = 0x080002, length = 0x001FFE /* on-chip Flash */


    FLASHB : origin = 0x082000, length = 0x002000 /* on-chip Flash */


    FLASHC : origin = 0x084000, length = 0x002000 /* on-chip Flash */


    FLASHD : origin = 0x086000, length = 0x002000 /* on-chip Flash */


    FLASHE : origin = 0x088000, length = 0x008000 /* on-chip Flash */


    FLASHF : origin = 0x090000, length = 0x008000 /* on-chip Flash */


    FLASHG : origin = 0x098000, length = 0x008000 /* on-chip Flash */


    FLASHH : origin = 0x0A0000, length = 0x008000 /* on-chip Flash */


    FLASHI : origin = 0x0A8000, length = 0x008000 /* on-chip Flash */


    FLASHJ : origin = 0x0B0000, length = 0x008000 /* on-chip Flash */


    FLASHK : origin = 0x0B8000, length = 0x002000 /* on-chip Flash */


    FLASHL : origin = 0x0BA000, length = 0x002000 /* on-chip Flash */


    FLASHM : origin = 0x0BC000, length = 0x002000 /* on-chip Flash */


    FLASHN : origin = 0x0BE000, length = 0x002000 /* on-chip Flash */





    PAGE 1 :


    BOOT_RSVD : origin = 0x000002, length = 0x000120 /* Part of M0, BOOT rom will use this for stack */


    RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */


    //RAMLS0 : origin = 0x008000, length = 0x000800


    //RAMLS1 : origin = 0x008800, length = 0x000800


    RAMLS2 : origin = 0x009000, length = 0x000800


    //RAMLS3 : origin = 0x009800, length = 0x000800


    RAMGS0 : origin = 0x00C000, length = 0x001000


    RAMGS1 : origin = 0x00D000, length = 0x001000


    RAMGS2 : origin = 0x00E000, length = 0x001000


    RAMGS3 : origin = 0x00F000, length = 0x001000


    RAMGS4 : origin = 0x010000, length = 0x001000


    RAMGS5 : origin = 0x011000, length = 0x001000


    RAMGS6 : origin = 0x012000, length = 0x001000


    RAMGS7 : origin = 0x013000, length = 0x001000


    RAMGS8 : origin = 0x014000, length = 0x001000


    RAMGS9 : origin = 0x015000, length = 0x001000


    RAMGS10 : origin = 0x016000, length = 0x001000


    RAMGS11 : origin = 0x017000, length = 0x001000


    RAMGS12 : origin = 0x018000, length = 0x001000


    RAMGS13 : origin = 0x019000, length = 0x001000


    CPU2TOCPU1RAM : origin = 0x03F800, length = 0x000400


    CPU1TOCPU2RAM : origin = 0x03FC00, length = 0x000400


    CLA1_MSGRAMLOW : origin = 0x001480, length = 0x000080


    CLA1_MSGRAMHIGH : origin = 0x001500, length = 0x000080


    }





    SECTIONS


    {


    /* Allocate program areas: */


    .cinit : > FLASHE PAGE = 0, ALIGN(4)


    .pinit : > FLASHE, PAGE = 0, ALIGN(4)


    .text : >> FLASHF PAGE = 0, ALIGN(4)


    codestart : > BEGIN PAGE = 0, ALIGN(4)


    ramfuncs : LOAD = FLASHD,


    RUN = RAMLS0_1,


    LOAD_START(_RamfuncsLoadStart),


    LOAD_SIZE(_RamfuncsLoadSize),


    LOAD_END(_RamfuncsLoadEnd),


    RUN_START(_RamfuncsRunStart),


    RUN_SIZE(_RamfuncsRunSize),


    RUN_END(_RamfuncsRunEnd),


    PAGE = 0, ALIGN(4)


    /* Allocate uninitalized data sections: */


    .stack : > RAMM1 PAGE = 1


    .ebss : > RAMGS5 PAGE = 1


    .esysmem : > RAMGS6 PAGE = 1


    /* Initalized sections go in Flash */


    .econst : > FLASHB PAGE = 0, ALIGN(4)


    .switch : > FLASHB PAGE = 0, ALIGN(4)


    .reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */


    Filter_RegsFile : > RAMGS0, PAGE = 1


    .sysmem : > RAMGS7, PAGE = 1


    .cio : > RAMGS8, PAGE = 1


    /* CLA specific sections */


    Cla1Prog : LOAD = FLASHC,


    RUN = RAMLS3_5,


    LOAD_START(_Cla1funcsLoadStart),


    LOAD_END(_Cla1funcsLoadEnd),


    RUN_START(_Cla1funcsRunStart),


    LOAD_SIZE(_Cla1funcsLoadSize),


    PAGE = 0, ALIGN(4)


    CLADataLS0 : > RAMLS2, PAGE=1


    Cla1ToCpuMsgRAM : > CLA1_MSGRAMLOW, PAGE = 1


    CpuToCla1MsgRAM : > CLA1_MSGRAMHIGH, PAGE = 1


    #ifdef __TI_COMPILER_VERSION


    #if __TI_COMPILER_VERSION >= 15009000


    .TI.ramfunc : {} LOAD = FLASHD,


    RUN = RAMLS0_1,


    LOAD_START(_RamfuncsLoadStart),


    LOAD_SIZE(_RamfuncsLoadSize),


    LOAD_END(_RamfuncsLoadEnd),


    RUN_START(_RamfuncsRunStart),


    RUN_SIZE(_RamfuncsRunSize),


    RUN_END(_RamfuncsRunEnd),


    PAGE = 0, ALIGN(4)


    #endif


    #endif


    /* The following section definition are for SDFM examples */


    Filter1_RegsFile : > RAMGS1, PAGE = 1, fill=0x1111


    Filter2_RegsFile : > RAMGS2, PAGE = 1, fill=0x2222


    Filter3_RegsFile : > RAMGS3, PAGE = 1, fill=0x3333


    Filter4_RegsFile : > RAMGS4, PAGE = 1, fill=0x4444


    #ifdef CLA_C


    /* CLA C compiler sections */


    //


    // Must be allocated to memory the CLA has write access to


    //


    CLAscratch :


    { *.obj(CLAscratch)


    . += CLA_SCRATCHPAD_SIZE;


    *.obj(CLAscratch_end) } > RAMLS2, PAGE = 1


    .scratchpad : > RAMLS2, PAGE = 1


    .bss_cla : > RAMLS2, PAGE = 1


    .const_cla : LOAD = FLASHC,


    RUN = RAMLS2,


    RUN_START(_Cla1ConstRunStart),


    LOAD_START(_Cla1ConstLoadStart),


    LOAD_SIZE(_Cla1ConstLoadSize),


    PAGE = 1


    #endif //CLA_C


    /* The following section definitions are required when using the IPC API Drivers */


    GROUP : > CPU1TOCPU2RAM, PAGE = 1


    {


    PUTBUFFER


    PUTWRITEIDX


    GETREADIDX


    }





    GROUP : > CPU2TOCPU1RAM, PAGE = 1


    {


    GETBUFFER : TYPE = DSECT


    GETWRITEIDX : TYPE = DSECT


    PUTREADIDX : TYPE = DSECT


    }


    }


    /*


    //===========================================================================


    // End of file.


    //===========================================================================


    */




    The following is PAGE 0 of the.MAP file:

    name origin length used unused attr fill

    ---------------------- -------- --------- -------- -------- ---- --------

    PAGE 0:

    RAMM0 00000122 000002de 00000000 000002de RWIX

    RAMLS0_1 00008000 00001000 00000870 00000790 RWIX

    RAMLS3_5 00009800 00001800 00001598 00000268 RWIX

    RAMD0 0000b000 00000800 00000000 00000800 RWIX

    RAMGS14 0001a000 00001000 00000000 00001000 RWIX

    RAMGS15 0001b000 00001000 00000000 00001000 RWIX

    DCSM_OTP_Z1_LINKPOINT 00078000 0000000c 00000000 0000000c RWIX

    DCSM_OTP_Z1_PSWDLOCK 00078010 00000004 00000000 00000004 RWIX

    DCSM_OTP_Z1_CRCLOCK 00078014 00000004 00000000 00000004 RWIX

    DCSM_OTP_Z1_BOOTCTRL 0007801c 00000004 00000000 00000004 RWIX

    DCSM_ZSEL_Z1_P0 00078020 00000010 00000000 00000010 RWIX

    DCSM_OTP_Z2_LINKPOINT 00078200 0000000c 00000000 0000000c RWIX

    DCSM_OTP_Z2_GPREG 0007820c 00000004 00000000 00000004 RWIX

    DCSM_OTP_Z2_PSWDLOCK 00078210 00000004 00000000 00000004 RWIX

    DCSM_OTP_Z2_CRCLOCK 00078214 00000004 00000000 00000004 RWIX

    DCSM_OTP_Z2_BOOTCTRL 0007821c 00000004 00000000 00000004 RWIX

    DCSM_ZSEL_Z2_P0 00078220 00000010 00000000 00000010 RWIX

    BEGIN 00080000 00000002 00000002 00000000 RWIX

    FLASHA 00080002 00001ffe 00000000 00001ffe RWIX

    FLASHB 00082000 00002000 0000025d 00001da3 RWIX

    FLASHC 00084000 00002000 00001598 00000a68 RWIX

    FLASHD 00086000 00002000 00000870 00001790 RWIX

    FLASHE 00088000 00008000 0000001a 00007fe6 RWIX
  • Hello, Cottier

    We set different EPwmxRegs.CMPA.bit.CMPA values and fixed EPwmxRegs.TBPRD values to generate PWM waves. We set EPwmxRegs.TZCTL.all=10 and EPwmxRegs.TZFRC.bit.OST=1 to stop EPWMA and EPWMB output. We set EPwmxRegs.TZCLR.bit.OST =1 to start EPWMA and EPWMB output. We set EPwmxRegs.TZCTL.bit.TZA=3 to start EPWMA output. We set EPwmxRegs.TZCTL.bit.TZB=3 to start EPWMB output. Before EPWMA or EPWMB starts the output, the EPwmxRegs.CMPA.bit.CMPA active register has been updated as expected value. The The time base counter(TBCTR) always count up-down. The output of the DB submodule is always valid. My questions are as follows:

    TZ submodule registers such as EPwmxRegs.TZCTL, EPwmxRegs.TZFRC, EPwmxRegs.TZCLR can be set up only when EPwmxRegs.TBCTR, EPwmxRegs.CMPA.bit.CMPA and EPwmxRegs.CMPB.bit.CMPB are specific values, or these TZ submodule registers can be set up at any time?

    The function of EPwmxRegs.CMPA.bit.CMPA or EPwmxRegs.CMPB.bit.CMPB is only compared with EPwmxRegs.TBCTR, and produces corresponding events without any other functions. Is it this?

  • The conditions are as follows: TBCLK=30M, up-down counting mode. EPwmxRegs.TBPRD=1500(The switching frequency is 10k). EPwmxRegs.DBCTL.all=11(x=1/2/3). The time delay 2us of the rising and falling edge of the DB submodule. EPwmxRegs.AQCTLA.all=0x61.

    Using ePWM1/2/3's A and B outputs to control three-phase IGBT(100A) bridge. A controls the up half bridge, B controls the down half bridge. A and B output to buffer. Buffer output to control optocoupler. Optocoupler control IGBT. The SVPWM voltage vector amplitude is fixed to 200V, and the DC bus voltage is about 560V. SVPWM voltage vector action time 1ms, stop time 80ms to make the permanent magnet synchronous motor stator winding fully release current. Each voltage vector angle test 20000 times. The voltage vector angles were 348.7, 337.5, 270, 202.5, 180, 157.5, 112, 101.2, 92.8, 90, 88.5, and 0 respectively. Different angles will make the CMPA value different. At CMPB=0, when the voltage vector angle is 88.5 degrees, when each test is about 40 times, the A and B output of ePWM1/2/3 will output high level. This will lead to short circuit of IGBT and optocoupler output protection. Other angles do not have this problem. Set the value of CMPB to 1498 (CMPA does not use this value). These abnormalities occur at 92.8 degrees when each test is about 3000 times. These abnormalities occur at 157.5 degrees when each test is about 3000 times. after change the location of the interrupt service program(The project has 5.C files. We move ISR to other.C files.). The value of CMPB is still 1498. 

    What is the reason?