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.

How to use ePWM module of the TMS570ls1224 with variable duty cylce?

Other Parts Discussed in Thread: HALCOGEN

Hi

Im trying to use HALcogen to generate the code for the ePWM, among other stuff, but when I generated the code, I could not find any clue to where the duty cycle of every pin is located, or the EPWMXA and EPMXB are configured....

I read on some post that the information is like codified or something....

do any of you guys have any clue?? :S

Best regards!! and thanks for the help

  • Did you look on the ETPWM tab ?

  • In  HALCoGen version 4.5.2 the etpwmSetCmpA and etpwmSetCmpB functions start on line 1007 of the file etpwm.c.

    /** @fn void etpwmSetCmpA(etpwmBASE_t *etpwm, uint16 value)
    *   @brief Set the Compare A value
    *
    *   @param etpwm     The pulse width modulation (ETPWM) object handle (etpwmREG1..7)
    *   @param value     16-bit Compare A value
    *
    *   This function sets the compare A value
    */
    /* SourceId : ETPWM_SourceId_015 */
    /* DesignId : ETPWM_DesignId_015 */
    /* Requirements : HL_EPWM_SR11 */
    void etpwmSetCmpA(etpwmBASE_t *etpwm, uint16 value)
    {
        etpwm->CMPA = value;
    }
    
    /** @fn void etpwmSetCmpB(etpwmBASE_t *etpwm, uint16 value)
    *   @brief Set the Compare B value
    *
    *   @param etpwm     The pulse width modulation (ETPWM) object handle (etpwmREG1..7)
    *   @param value     16-bit Compare B value
    *
    *   This function sets the compare B register
    */
    /* SourceId : ETPWM_SourceId_016 */
    /* DesignId : ETPWM_DesignId_016 */
    /* Requirements : HL_EPWM_SR11 */
    void etpwmSetCmpB(etpwmBASE_t *etpwm, uint16 value)
    {
        etpwm->CMPB = value;
    }
    

  • Yes, I saw that tab. But I need to generate a different PWM every time, and there is a fixed value, so I need to put a variable there

    Thanks!!
  • So... I could just put a variable there and then make the file a function, dependant on those variables so it can work with the main.c?
    Another question... I checked the file and I found something I dont really understand... what is the meaning of an U after the numeric value?? 47U for example

    Best regards!!
  • If you use HALCoGen, then the functions are already part of your code. In the example above it starts as 50% duty cycle. (1000 for the period and 500 for the phase). In main(), after you call etpwmInit() and etpwmStartTBCLK(), you call etpwmSetCmpA() with a new value to change the duty cycle.

    The "U" just means treat the number as "unsigned".
  • So I just need to put a value from 0 to 1000 inside the etpwmSetCmpA(), just like etpwmSetCmpA(750) and it should work with a duty cycle of 75%?
    And on the Init() and the TBCLK() just put the values?

    thanks and best regards!!!! =D
  • Hi Bob

    I was looking the EPWM-ECAP example and there is a part I dont understand... 

    You told me to just do the etpwmInit and the Start TBCLK and then call the SETCmpA with the duty cycle. But there are some lines I don't understand..

    #if 1
    /* Initialise EPWM and ECAP with GUI configuration */
    etpwmInit();
    ecapInit();


    #else
    /* Alternate code for configuring ETPWM and ECAP */
    /* Configure ETPWM1 */
    /* Set the TBCLK frequency = VCLK4 frequency = 90MHz */
    etpwmSetClkDiv(etpwmREG1, ClkDiv_by_1, HspClkDiv_by_1);

    /* Set the time period as 1000 ns (Divider value = (1000ns * 90MHz) - 1 = 89)*/
    etpwmSetTimebasePeriod(etpwmREG1, 89);

    /* Configure Compare A value as half the time period */
    etpwmSetCmpA(etpwmREG1, 45);

    /* Configure the module to set PWMA value as 1 when CTR=0 and as 0 when CTR=CmpA */
    etpwmActionQualConfig_t configPWMA;
    configPWMA.CtrEqZero_Action = ActionQual_Set;
    configPWMA.CtrEqCmpAUp_Action = ActionQual_Clear;
    configPWMA.CtrEqPeriod_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpADown_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBUp_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBDown_Action = ActionQual_Disabled;
    etpwmSetActionQualPwmA(etpwmREG1, configPWMA);

    /* Start counter in CountUp mode */
    etpwmSetCount(etpwmREG1, 0);
    etpwmSetCounterMode(etpwmREG1, CounterMode_Up);
    etpwmStartTBCLK();

    /* Configure ECAP1 */
    /* Configure Event 1 to Capture the rising edge */
    ecapSetCaptureEvent1(ecapREG1, RISING_EDGE, RESET_DISABLE);

    /* Configure Event 2 to Capture the falling edge */
    ecapSetCaptureEvent2(ecapREG1, FALLING_EDGE, RESET_DISABLE);

    /* Configure Event 3 to Capture the rising edge with reset counter enable */
    ecapSetCaptureEvent3(ecapREG1, RISING_EDGE, RESET_ENABLE);

    /* Set Capure mode as Continuous and Wrap event as CAP3 */
    ecapSetCaptureMode(ecapREG1, CONTINUOUS, CAPTURE_EVENT3);

    /* Start counter */
    ecapStartCounter(ecapREG1);

    /* Enable Loading on Capture */
    ecapEnableCapture(ecapREG1);

    /* Enable Interrupt for CAP3 event */
    ecapEnableInterrupt(ecapREG1, ecapInt_CEVT3);

    The lines in green. Those are like the configuration registers for the PWM module... but I don't understand the reason of those lines if I already configured the PWM on HALcogen...

    Also... the lines

    etpwmSetCount(etpwmREG1, 0);
    etpwmSetCounterMode(etpwmREG1, CounterMode_Up);

    Are they not included on the initialization of the module?? Or shall I write those for every module I'm using in order to define the counter mode??

    What are the TB clock and the VCLK figures for? in HALcogen. What do those values do?? Should I use a delay or is not necessary?? Im using the Channel A and B independently...

    Best regards

  • Your green lines come after:

    #if 1
    /* Initialise EPWM and ECAP with GUI configuration */
    etpwmInit();
    ecapInit();


    #else


    So it looks like they are 'disabled' by the compiler preprocessor...

    This conditional is also basically saying

    #if 1
    // use the halcogen gui's init functions
    #else
    // configure it myself...
    #endif

    So if you take the #else path you have to do what isn't done anymore because of etpwmInit() no longer being called...

    If it's any more deep than this probably needs to answer.
  • so... If I get it right... the #else is disabling the PWM init?? and then the etpwminit() is not working anymore?
    And... the lines

    etpwmSetCount(etpwmREG1, 0);
    etpwmSetCounterMode(etpwmREG1, CounterMode_Up);

    Are they not included on the initialization of the module?? Or shall I write those for every module I'm using in order to define the counter mode??

    What are the TB clock and the VCLK figures for? in HALcogen. What do those values do?? Should I use a delay or is not necessary?? Im using the Channel A and B independently...

    Best regards
  • Miguel,

    I don't have the code .. except for what you posted above.

    You posted:

    #if 1
    /* Initialise EPWM and ECAP with GUI configuration */
    etpwmInit();
    ecapInit();

    #else
    ...

    Which means 'etpwmInit()' and 'ecapInit()' calls will be generated, and everything else between #else and #endif will be discarded.


    TBCLK is the time base clock, it is divided down from VCLK. It is the clock that the timer counters run off of. It is 80MHz in the screen capture above.

    VCLK is the device peripheral clock. Look at the GCM tab in HalCoGen and or read the 'Clocks' section of the technical reference manual (in the "Architecture" chapter) to get a better idea of the different clock domains on the device.

    You do not delay these clocks, one is simply divided down from the other.

    If you increase the divider (Make TBCLK slower) this does two things:
    a) resolution of the timer is reduced
    b) the maximum period of the counter is increased by the same proportion..

    You need to decide how much resolution & range you need in your design and pick a setting that works for you. if not sure just start w. the smallest divider as this will give the best resolution.