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.

TMS320F28P659DK-Q1: ePWM unexpected behavior when TBCTR is counting down

Part Number: TMS320F28P659DK-Q1
Other Parts Discussed in Thread: C2000WARE

Hello support,
I'm reporting you an unexpected behavior of ePWM.

Setup:
SYSCLK = 200MHz
EPWMCLK = 200MHz (PERCLKDIVSEL.EPWMCLKDIV = 0)

setup pf ePWM1 and ePWM3
both configured in UP-DOWN mode
both configured with CLKDIV = 0 and HSPCLKDIV = 1 (total prescaler = 2) so that TBCLK = 100MHz
ePWM1 (AQCTLA) is configured to generate output A: HIGH on CMPA when counting UP, LOW on CMPB when counting UP
ePWM3 (AQCTLA) is configured to generate output A: HIGH on CMPA when counting DOWN, LOW on CMPB when counting DOWN
ePWMs are synced (ePWM1 provides the sync to ePWM3) and ePWM3 PRD reload is linked to ePWM1 (through EPWMXLINK.TBPRDLINK)

Here the issue:
ePWM1_A is generated as expected
on ePWM3_A is not generated, even if TBCTR is running and CMPA/CMPB/TBPRD hold the right values.

If I change (even in runtime during debug session) the value of ePWM3 HSPCLKDIV to ZERO, the ePWM3_A is generated (of course
with a frequency double as desired).

On the other hand, keeping CLKDIV = 0 and HSPCLKDIV = 1, if I change the AQCTLA configuration of ePWM3 as follows
HIGH on CMPA when counting UP, LOW on CMPB when counting UP
the signal ePWM3_A is generated.

Finally, if I set
- EPWMCLK = 100MHz (PERCLKDIVSEL.EPWMCLKDIV = 1),
- ePWM1/ePWM3 with CLKDIV = 0 and HSPCLKDIV = 0 (total prescaler = 1) so that TBCLK = 100MHz,
- ePWM1 (AQCTLA) configured to generate output A: HIGH on CMPA when counting UP, LOW on CMPB when counting UP
- ePWM3 (AQCTLA) configured to generate output A: HIGH on CMPA when counting DOWN, LOW on CMPB when counting DOWN
everithing works fine --> ePWM3_A is generated properly

It seems that there is a sort of incompatibility between
- setting of TBCLK different than EPWMCLK, and
- the behavior of ePWM when it is counting down.


Do you have any idea?
Maybe something could be missing is my configuration ?

  • ePWM1_A is generated as expected
    on ePWM3_A is not generated, even if TBCTR is running and CMPA/CMPB/TBPRD hold the right values.

    What are the CMPA CMPB values and when EPWM1 TBPRD is loaded what value is written to it ? Are both modules in same mode (up-down count )?

    On the other hand, keeping CLKDIV = 0 and HSPCLKDIV = 1, if I change the AQCTLA configuration of ePWM3 as follows
    HIGH on CMPA when counting UP, LOW on CMPB when counting UP
    the signal ePWM3_A is generated

    The fact that it works on LOW on CMPB counting up and HIGH on CMPA counting up, I suspect its missing action qualifier event on PRD load.

    Can you share waveform of the same depicting and if possible share the code so I can try to replicate ?

    Thanks.

  • Hello,
    here my answers

    "What are the CMPA CMPB values and when EPWM1 TBPRD is loaded what value is written to it ? Are both modules in same mode (up-down count )?"

    ePWM1.CMPA = 0x000A0000
    ePWM1.CMPB = 0x009C0000

    ePWM3.CMPA = 0x009C0000
    ePWM3.CMPB = 0x000A0000

    ePWM1.TBPRD = ePWM3.TBPRD = 0x00A6
    ePWM1.TBPRDHR = ePWM3.TBPRDHR = 0x0000

    Both module are configured in UP-DOWN count mode.



    "The fact that it works on LOW on CMPB counting up and HIGH on CMPA counting up, I suspect its missing action qualifier event on PRD load."
    What do you mean ? In which register can I comfigure an action qualifier event on PRD load ?


    "Can you share waveform of the same depicting and if possible share the code so I can try to replicate ?"
    Following file LLC_Extract.c contains the function used to configure both PWM.
    Function is called twice, each time with different arguments

    To configure ePWM1 you can call the function with PeriodCountReload = 0xA6, Position = FB_H1L2_BRIDGE
    To configure ePWM3 you can call the function with PeriodCountReload = 0xA6, Position = FB_H2L1_BRIDGE

    No matter about the value of FB_H1L2_BRIDGE and FB_H2L1_BRIDGE, anyway in my project are:
    FB_H1L2_BRIDGE = 1
    FB_H2L1_BRIDGE = 2

    Pay attention that, in order to have my setup, you must set
    SYSCLK = 200MHz
    EPWMCLK = 200MHz (PERCLKDIVSEL.EPWMCLKDIV = 0)

    LLC_Extract.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    static void ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet(uint32_t BaseAddress, uint16_t PeriodCountReload, LLCBRIDGE_Position_t Position)
    {
    uint32_t pwmPeriod_ticks;
    /*
    * compute PERIOD reload value to be loaded in HR registers
    */
    pwmPeriod_ticks = (uint32_t)((float32_t)PeriodCountReload * 65536.0f);/* polyspace MISRA2012:10.8 [Justified:Low] "cast needed by application" */
    /*
    * Direct access to HR PERIOD register
    * should be faster than using drivers
    */
    HRPWM_setTimeBasePeriod(BaseAddress, pwmPeriod_ticks);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    In attachment you also find 2 pictures: yellow line is ePWM1_A, green line is ePWM3_A
    1701888899381.jpg: taken with CLKDIV = 0 and HSPCLKDIV = 1 for both ePWM
    1701888899371.jpg: taken with CLKDIV = 0 and HSPCLKDIV = 1 for both ePWM1, CLKDIV = 0 and HSPCLKDIV = 0 for ePWM3

  • For simplicity and finding the root cause to the issue can you remove/comment out all code pertaining to HRPWM and syncronizations just configure action qualifiers and see if the epwm outputs work as expected ?

    Can you send me all the epwm only configurations in file, the function you shared above only has hrpwm configurations can you share the pwm initializations also ?

     Also have you tried examples for f28p65x that come in c2000ware maybe try those and change the values as mentioned in the code there is something off in the configurations.

  • For simplicity and finding the root cause to the issue can you remove/comment out all code pertaining to HRPWM and syncronizations just configure action qualifiers and see if the epwm outputs work as expected ?
    Ok, I will do it but since my project is already at advanced development stage, this will take quite long time.


    Can you send me all the epwm only configurations in file, the function you shared above only has hrpwm configurations can you share the pwm initializations also ?
    I'm not sure I fully understood your question, anyway I try to answer:
    in my project I'm using 6 ePWM to drive a PFC stage and 8 HRPWM to drive a CLLC full bridge stage.
    In attached file "PFC_Config.c" you can find the configuration of ePWM used for PFC function.
    each PWM peripherals used for CLLC functions is configured only by the function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet that I already shared: there is not any other configuration as ePWM, just as HRPWM.
    I add in attachment the file "LLC_Config.c" where I have added the function ABS_LLC_Enable_ePWM_Peripherals() - called before any other -
    and the initialization function ABS_LLC_ConfigPWMs_LLCBridges(), that calls the configuration function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet() and configures sync, phaseshift and reload links.

    PFC_Config.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    static void ABS_PFC_ConfigSinglePfcPwm_DBDriven(const uint32_t base, const uint32_t period, const uint32_t CMPA, const uint32_t red, const uint32_t fed)
    {
    //
    // =============================================== //
    // === Configure Time Base Submodule Registers === //
    // =============================================== //
    //
    // Enable TBPRD shadow load (Default is load on CTR=0)
    // PWM frequency = 1 / period
    // No phase shift
    // Initialize counter to 0
    // Configure counter for up-down count mode
    // Set prescalers: clock divider = 1, HS clock divider = 1
    // ---TBCLK = EPWMCLK/(HSPCLKDIV * CLKDIV)
    //
    EPWM_setPeriodLoadMode(base, EPWM_PERIOD_SHADOW_LOAD);
    EPWM_setTimeBasePeriod(base, (uint16_t)period);
    EPWM_setPhaseShift(base, 0);
    EPWM_setTimeBaseCounter(base, 0);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     
    LLC_Config.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    static void ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet(uint32_t BaseAddress, uint16_t PeriodCountReload, LLCBRIDGE_Position_t Position)
    {
    uint32_t pwmPeriod_ticks;
    /*
    * compute PERIOD reload value to be loaded in HR registers
    */
    pwmPeriod_ticks = (uint32_t)((float32_t)PeriodCountReload * 65536.0f);/* polyspace MISRA2012:10.8 [Justified:Low] "cast needed by application" */
    /*
    * Direct access to HR PERIOD register
    * should be faster than using drivers
    */
    HRPWM_setTimeBasePeriod(BaseAddress, pwmPeriod_ticks);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



    Also have you tried examples for f28p65x that come in c2000ware maybe try those and change the values as mentioned in the code there is something off in the configurations
    Honestly I still did not. I will check if I can find some example fitting my needs.

    I add some more details about my project for your better understanding:
    HRPWMs peripherals are: PWM1,PWM2,PWM3,PWM7,PWM9,PWM12,PWM13,PWM18, all configured using the function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet()
    PWM1,PWM9,PWM12 and PWM13 are configured with Position = FB_H1L2_BRIDGE, therefore the action qualifier is "HIGH on CMPA when counting UP, LOW on CMPB when counting UP"
    They all work properly.

    PWM2,PWM3,PWM7 and PWM18 are configured with Position = FB_H2L1_BRIDGE, therefore the action qualifier is "HIGH on CMPA when counting DOWN, LOW on CMPB when counting DOWN"
    They ALL don't work: no PWM signal.
    That's why I was focusing on some issue linked to the down counting.
    And remind what I have previously written: if I change the AQCTLA configuration of PWM2,PWM3,PWM7 and PWM18 to "HIGH on CMPA when counting UP, LOW on CMPB when counting UP", the PWM is generated.



    Some questions from my side:
    had you the chance to test my configuration? I think using only PWM2 and PWM3 is enough to feel the different behavior.
    Same behavior was seen on both EVA board (Docking + ControlCard) and the final board.

  • Thank you for the details.

    As I am going through the code you set compare values using variable LLC_PWM_HR_TRANSFORM(LLC_OFF_Duty_StartPoint) so just to make sure you have verified that CMPA and CMPB values match your expectations as below.
    Because if CMPA is not greater than CMPB there wont be any pulse output can you also send me a snapshot or register view dump when there is no pwm output for these pwms.

    "HIGH on CMPA when counting DOWN, LOW on CMPB when counting DOWN
    ePWM3.CMPA = 0x009C0000
    ePWM3.CMPB = 0x000A0000

    I have tried with basic epwm configuration like just setting action qualifiers and cmpa, cmpb values on up-down count mode and I see pwm output both on A and B.

    Thanks

  • Hello
    "As I am going through the code you set compare values using variable LLC_PWM_HR_TRANSFORM(LLC_OFF_Duty_StartPoint) so just to make sure you have verified that CMPA and CMPB values match your expectations as below.
    Because if CMPA is not greater than CMPB there wont be any pulse output can you also send me a snapshot or register view dump when there is no pwm output for these pwms."

    I did not explain that function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet just make the initial configuration with the aim to configure everithing but keeping outputs OFF.

    In runtime CMPA and CMPB take different values (variable frequency).
    Pair
    ePWM3.CMPA = 0x009C0000
    ePWM3.CMPB = 0x000A0000
    is one configuration that is supposed to work and it does not.


    "I have tried with basic epwm configuration like just setting action qualifiers and cmpa, cmpb values on up-down count mode and I see pwm output both on A and B."
    Could you please try with HRPWM ? Maybe you can do this test faster than me.
    Please, remind to set
    SYSCLK = 200MHz, and
    EPWMCLK = 200MHz (PERCLKDIVSEL.EPWMCLKDIV = 0)

    Best regards

  • Hello
    I have tested my project using ePWM instead of HRPWM and the issue is not present.

    In details:
    I have deleted from function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet() all the final part after the
    comment "High Resolution registers activation",
    and I have replaced
    HRPWM_setTimeBasePeriod
    HRPWM_setPhaseShift
    HRPWM_setCounterCompareValue
    with corresponding epwm functions.

    Many other hrpwm functions are merely a redefinition of epmw and didn't need to be replaced.
    Of course, also the follwing have been deleted
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_HRCAL0);
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_HRCAL1);
    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_HRCAL2);


    Now the question remains:
    what is the link between the following 3 features:
    - PWM output qualified in down count
    - PWM set in High Resolution
    - PWM TBCLK (100MHz) different than EPWMCLK (200MHz)

    If I change one of the three settings above, the PWM works.

  • Hello Davide,

    Lets dig into your High resolution settings since I do not expect anything wrong with TBCLK being 200Mhz or 100Mhz both should work :

    Are you initializing the SFO() function for the MEP scale factor to be acquired using the SFO() function ?
    Also refer to steps highlighted in section 22.18.1.5.4.1 High-Resolution Period Configuration to see if you are missing any ?

    Also because you are using HRPE high resolution period making sure you are aware of the below limitation pertaining to min and max duty cycles ?
    Please refer to section 22.18.1.5.3 Duty Cycle Range Limitation

    Thanks

  • Hello,
    you wrote: "Are you initializing the SFO() function for the MEP scale factor to be acquired using the SFO() function ?"  Yes


    you wrote: "Also refer to steps highlighted in section 22.18.1.5.4.1 High-Resolution Period Configuration to see if you are missing any ?"
    Referring to the par. "22.18.1.5.4.1 High-Resolution Period Configuration", this is the initialization sequence in my project:
    - EPWMClockDivider clock divider setting (field SYSCTL_O_PERCLKDIVSEL)
    - Enable ePWMx clock
    - Enable HRPWMx clock
    - Disable TBCLKSYNC
    - Launch of function SFO() to initiate the MEP module
    - Configuration of ePWMx registers: this is done by the function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet() already shared
      and includes:
        - CMPCTL[LOADAMODE] = EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD (2), through function HRPWM_setCounterCompareShadowLoadMode()
        - HRCNFG[HRLOAD] = HRPWM_LOAD_ON_CNTR_ZERO_PERIOD (2), through function HRPWM_setCounterCompareShadowLoadEvent()
        - HRCNFG[AUTOCONV] = 1, through function HRPWM_enableAutoConversion()
        - HRCNFG[EDGMODE] = HRPWM_MEP_CTRL_RISING_EDGE (1), through function HRPWM_setMEPEdgeSelect() --> setting value is different than the one suggested by TRM (3), and the function is called not respecting the same order as in TRM (is the order so important ?)
        - Enable high-resolution period control (HRPCTL[HRPE] = 1), through function HRPWM_enablePeriodControl --> function is called not respecting the same order as in TRM
        - Setting of and TBCTL[PHSEN] = 1 through EPWM_enablePhaseShiftLoad --> function is called not respecting the same order as in TRM
    - Enable TBCLKSYNC
    - TBCTL[SWFSYNC] = 1
    - Periodic acquiring of MEP scale factor using SFO function()


    I have also made a test modifying the sequence above as follows:
    - HRCNFG[EDGMODE], called with the proper argument (3) and respecting the same order as TRM
    - Enabling high-resolution period control (HRPCTL[HRPE] = 1), called respecting the same order as TRM
    - Setting of and TBCTL[PHSEN] = 1 through EPWM_enablePhaseShiftLoad, called respecting the same order as TRM
    - Adding setup of HRPCTL[TBPSHRLOADE] = 1, this setting was missing

    Result is the same as before: this does not surprise me because, as I wrote previously, I can see PWM in output if I change on the fly into debugger the value of HSPCLKDIV from 1 to 0.
    This suggests to me that the PWm configuration, even is not exactly the same as in TRM, is not the root cause of this issue.




    You wrote
    "Also because you are using HRPE high resolution period making sure you are aware of the below limitation pertaining to min and max duty cycles cycles ? Please refer to section 22.18.1.5.3 Duty Cycle Range Limitation"

    I previously wrote you the values of CMPA/CMPB and PRD during the issue:
    ePWM1.CMPA = 0x000A0000
    ePWM1.CMPB = 0x009C0000

    ePWM3.CMPA = 0x009C0000
    ePWM3.CMPB = 0x000A0000

    ePWM1.TBPRD = ePWM3.TBPRD = 0x00A6
    ePWM1.TBPRDHR = ePWM3.TBPRDHR = 0x0000
    I think those values are not violating the limitations of section 22.18.1.5.3.

    Have you tried my configuration ?

  • Based on the CMPA and CMPB values of A000 and 9C0000 the upper 8 bits of CMPAHR and CMPBHR would be zero as shown below

    But according to definition If the AUTOCONV bit (HRCNFG.6) is set and the MEP_ScaleFactor is in the HRMSTEP register, then CMPAHR / CMPBHR register value = frac (PWMDuty*PWMperiod<<8)

    Can you set the CMPAHR and CMPBHR accordingly ? You can refer to the ex4 for hrpwm where the duty cycle is steeped up from minduty cycle and  CMPAHR is calculated in loop as shown in snapshot below

    I will try to prepare the code files as per your configuration it would be faster if you could just send me cut down version of your code settings just for one pwm which leads to the issue which I can just copy paste in empty project and run.

    Thanks

  • Also I checked with the internal team on the clocking for HRPWM, there is a requirement for the TBCLK to be the same as HRPWM CLK. That's why its imperative to have HSPCLKDIV and CLKDIV to be 1 so that TBCLK and HRPWM CLK equal.

  • Hello,
    thank you for your last suggestions.

    You wrote
    "I will try to prepare the code files as per your configuration it would be faster if you could just send me cut down version of your code settings just for one pwm which leads to the issue which I can just copy paste in empty project and run."
    The function ABS_LLC_ConfigSingleLLC_DrivingAndSyncMosfet() that I already shared is the most representative of my setting for 1 pwm.
    I attach here a version with all the necessary definition and data types.
    You should first set
    SYSCLK = 200MHz
    EPWMCLK = 200MHz (PERCLKDIVSEL.EPWMCLKDIV = 0)

    then call the function ABS_LLC_Enable_ePWM_Peripherals() to provide the clock to PWMs
    and as last call ABS_LLC_ConfigPWMs_LLCBridges(), that configures all PWMs, but for you test you can focus on just PWM1 and PWM3 (easiest to catch on EVA board)

    LLC_Config_1.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    #define LLC_BUS_FREQUENCY (100e6)
    #define LLC_MAX_FREQUENCY ((float32_t)350000.0)
    #define LLC_PERIOD_RELOAD_RATIO (2u)
    #define LLC_MIN_PRD_UD_MODE_COUNT (uint32_t)((LLC_BUS_FREQUENCY / (float32_t)(LLC_MAX_FREQUENCY * LLC_PERIOD_RELOAD_RATIO)))
    #define LLC_PWM_HR_TRANSFORM(Count) (uint32_t)((uint32_t)Count << 16u)
    #define NOF_PWMs_PRIMARY_STAGE (4u)
    #define NOF_PWMs_SECONDARY_STAGE (4u)
    #define NOF_LLC_PWMs (NOF_PWMs_PRIMARY_STAGE + NOF_PWMs_SECONDARY_STAGE)
    #define LLC_PRI_LEG1_HS_PWM_MODULE (EPWM1_BASE)
    #define LLC_PRI_LEG1_LS_PWM_MODULE (EPWM18_BASE)
    #define LLC_PRI_LEG2_HS_PWM_MODULE (EPWM3_BASE)
    #define LLC_PRI_LEG2_LS_PWM_MODULE (EPWM12_BASE)
    #define LLC_SEC_LEG1_HS_PWM_MODULE (EPWM13_BASE)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


    You wrote
    "Also I checked with the internal team on the clocking for HRPWM, there is a requirement for the TBCLK to be the same as HRPWM CLK. That's why its imperative to have HSPCLKDIV and CLKDIV to be 1 so that TBCLK and HRPWM CLK equal."
    Independent on my PWWs setting or the management of MEP, I think this sentence is quite definitive.
    Could you also tell me at which par. of TRM this is written ? Have I missed it ?

  • Independent on my PWWs setting or the management of MEP, I think this sentence is quite definitive.
    Could you also tell me at which par. of TRM this is written ? Have I missed it ?

    Its not documented in TRM will be included in the next revision of TRM. I confirmed with internal team that it is applicable to F28P65x