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.

RM46 eTPWM HALCoGen 04.03.00 example_etpwmPulseGeneration.c compilation fails

Other Parts Discussed in Thread: HALCOGEN

I followed the HALCoGen 04.03.00 exampe  example_etpwmPulseGeneration.c for the RM46x.

The compilation in CCS 6.0.1 failed, seemingly for differences between the source example file and the etPWM API (as generated by HALCoGen into file etpwm.h.

Here are the changes I had to make to the code to make it compile (haven't checked that it runs fine yet) :

replaced 
ETPWM_HspClkDiv_t etpwmHspClkDiv_t
ETPWM_HspClkDiv_by_1 HspClkDiv_by_1
ETPWM_ClkDiv_t etpwmClkDiv_t
ETPWM_ClkDiv_by_1 ClkDiv_by_1
ETPWM_ActionQual_t  etpwmActionQual_t
ETPWM_ActionQual_Set ActionQual_Set
ETPWM_ActionQual_Clear ActionQual_Clear
ETPWM_CounterMode_t etpwmCounterMode_t
ETPWM_CounterMode_Up CounterMode_Up

ETPWM_setHighSpeedClkDiv() and ETPWM_setClkDiv() needed to be combined both to etpwmSetClkDiv()
ETPWM_setPeriod() etpwmSetTimebasePeriod()
ETPWM_setCounterMode() etpwmSetCounterMode()
ETPWM_write_CmpA() etpwmSetCmpA()
ETPWM_write_CmpB() etpwmSetCmpB()
ETPWM_setActionQual_Zero_PwmA() etpwmSetActionQualPwmA()
ETPWM_setActionQual_Zero_PwmB() etpwmSetActionQualPwmA()
ETPWM_setActionQual_CntUp_CmpA_PwmA() etpwmSetActionQualPwmA()
ETPWM_setActionQual_CntUp_CmpB_PwmB() etpwmSetActionQualPwmB()
ETPWM_setCount() etpwmSetCount()

Here is the list of compilation/link errors I had with the original code.

"../source/sys_main.c", line 62: error #20: identifier "ETPWM_HspClkDiv_t" is undefined
"../source/sys_main.c", line 62: error #20: identifier "ETPWM_HspClkDiv_by_1" is undefined
"../source/sys_main.c", line 63: error #20: identifier "ETPWM_ClkDiv_t" is undefined
"../source/sys_main.c", line 63: error #20: identifier "ETPWM_ClkDiv_by_1" is undefined
"../source/sys_main.c", line 67: error #20: identifier "ETPWM_ActionQual_t" is undefined
"../source/sys_main.c", line 67: error #20: identifier "ETPWM_ActionQual_Set" is undefined
"../source/sys_main.c", line 68: error #20: identifier "ETPWM_ActionQual_t" is undefined
"../source/sys_main.c", line 69: error #20: identifier "ETPWM_ActionQual_t" is undefined
"../source/sys_main.c", line 69: error #20: identifier "ETPWM_ActionQual_Clear" is undefined
"../source/sys_main.c", line 70: error #20: identifier "ETPWM_ActionQual_t" is undefined
"../source/sys_main.c", line 71: error #20: identifier "ETPWM_CounterMode_t" is undefined
"../source/sys_main.c", line 71: error #20: identifier "ETPWM_CounterMode_Up" is undefined
"../source/sys_main.c", line 75: warning #225-D: function "ETPWM_setHighSpeedClkDiv" declared implicitly
"../source/sys_main.c", line 78: warning #225-D: function "ETPWM_setClkDiv" declared implicitly
"../source/sys_main.c", line 81: warning #225-D: function "ETPWM_setPeriod" declared implicitly
"../source/sys_main.c", line 84: warning #225-D: function "ETPWM_setCounterMode" declared implicitly
"../source/sys_main.c", line 87: warning #225-D: function "ETPWM_write_CmpA" declared implicitly
"../source/sys_main.c", line 90: warning #225-D: function "ETPWM_write_CmpB" declared implicitly
"../source/sys_main.c", line 93: warning #225-D: function "ETPWM_setActionQual_Zero_PwmA" declared implicitly
"../source/sys_main.c", line 96: warning #225-D: function "ETPWM_setActionQual_Zero_PwmB" declared implicitly
"../source/sys_main.c", line 99: warning #225-D: function "ETPWM_setActionQual_CntUp_CmpA_PwmA" declared implicitly
"../source/sys_main.c", line 102: warning #225-D: function "ETPWM_setActionQual_CntUp_CmpB_PwmB" declared implicitly
"../source/sys_main.c", line 105: warning #225-D: function "ETPWM_setCount" declared implicitly
12 errors detected in the compilation of "../source/sys_main.c".

 undefined                           first referenced     
  symbol                                 in file          
 ---------                           ----------------     
 ETPWM_setActionQual_CntUp_CmpA_PwmA ./source/sys_main.obj
 ETPWM_setActionQual_CntUp_CmpB_PwmB ./source/sys_main.obj
 ETPWM_setActionQual_Zero_PwmA       ./source/sys_main.obj
 ETPWM_setActionQual_Zero_PwmB       ./source/sys_main.obj
 ETPWM_setClkDiv                     ./source/sys_main.obj
 ETPWM_setCount                      ./source/sys_main.obj
 ETPWM_setCounterMode                ./source/sys_main.obj
 ETPWM_setHighSpeedClkDiv            ./source/sys_main.obj
 ETPWM_setPeriod                     ./source/sys_main.obj
 ETPWM_write_CmpA                    ./source/sys_main.obj
 ETPWM_write_CmpB                    ./source/sys_main.obj

Here is the resulting source file:

void main(void)
{
/* USER CODE BEGIN (3) */



	// ETPWM_HspClkDiv_t hsClkDiv=ETPWM_HspClkDiv_by_1;
    etpwmHspClkDiv_t hsClkDiv=HspClkDiv_by_1;
	// ETPWM_ClkDiv_t clkDiv=ETPWM_ClkDiv_by_1;
    etpwmClkDiv_t clkDiv=ClkDiv_by_1;
    uint16 period=0x24;
    uint16 pwmData1=period/2;
    uint16 pwmData2=period/4;
    // ETPWM_ActionQual_t actionQual1= ETPWM_ActionQual_Set;
    etpwmActionQual_t actionQual1= ActionQual_Set;
    // ETPWM_ActionQual_t actionQual2= ETPWM_ActionQual_Set;
    etpwmActionQual_t actionQual2= ActionQual_Set;
    // ETPWM_ActionQual_t actionQual3= ETPWM_ActionQual_Clear;
    etpwmActionQual_t actionQual3= ActionQual_Clear;
    // ETPWM_ActionQual_t actionQual4= ETPWM_ActionQual_Clear;
    etpwmActionQual_t actionQual4= ActionQual_Clear;
    // ETPWM_CounterMode_t counterMode=ETPWM_CounterMode_Up;
	etpwmCounterMode_t counterMode=CounterMode_Up;
    uint16 count=0;

    /* set the high speed clock divider   */
    // ETPWM_setHighSpeedClkDiv(etpwmREG1,hsClkDiv);

    /* set the normal clock divider   */
    // ETPWM_setClkDiv(etpwmREG1,clkDiv);
    /* needed to combine previous two calls into one call */
    etpwmSetClkDiv(etpwmREG1, clkDiv, hsClkDiv);

    /* set the period of pwm   */
    // ETPWM_setPeriod(etpwmREG1,period);
    etpwmSetTimebasePeriod(etpwmREG1,period);

    /* set the counter direction-up,down or updown   */
    // ETPWM_setCounterMode(etpwmREG1,counterMode);
    etpwmSetCounterMode(etpwmREG1,counterMode);

    /* set the compare register CMPA to adjust the duty cycle for ETPWM1A pin    */
    // ETPWM_write_CmpA(etpwmREG1,pwmData1);
    etpwmSetCmpA(etpwmREG1,pwmData1);

    /* set the compare register CMPB to adjust the duty cycle for ETPWM2A pin    */
    // ETPWM_write_CmpB(etpwmREG1,pwmData2);
    etpwmSetCmpB(etpwmREG1,pwmData2);

    /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1A    */
    // ETPWM_setActionQual_Zero_PwmA(etpwmREG1,actionQual1);
    etpwmSetActionQualPwmA(etpwmREG1,actionQual1);

    /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1B    */
    // ETPWM_setActionQual_Zero_PwmB(etpwmREG1, actionQual2);
    etpwmSetActionQualPwmA(etpwmREG1, actionQual2);

    /* set the action qualifier for the generation of events at counter equals compare value of A for ETPWM1A    */
    // ETPWM_setActionQual_CntUp_CmpA_PwmA(etpwmREG1, actionQual3);
    etpwmSetActionQualPwmA(etpwmREG1, actionQual3);

    /* set the action qualifier for the generation of events at counter equals compare value of B for ETPWM1B    */
    // ETPWM_setActionQual_CntUp_CmpB_PwmB(etpwmREG1, actionQual4);
    etpwmSetActionQualPwmA(etpwmREG1, actionQual4);

    /* set and initialize the counter   */
    // ETPWM_setCount(etpwmREG1,count);
    etpwmSetCount(etpwmREG1,count);

    /*  ... run forever  */
    while(1);

/* USER CODE END */
}

  • Hi Jan,

    Thank you for the valuable feedback! I have forwarded the information to our Halcogen Lead so they can investigate and make the corrections to improve the example and Halcogen code generation process.

    Please let me know if there is any additional findings or if there is anything we can help with.
  • I am not confident that I made the right conversion decision in this particular part. I'm still trying to understand the differences:

        /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1A    */
        // ETPWM_setActionQual_Zero_PwmA(etpwmREG1,actionQual1);
        etpwmSetActionQualPwmA(etpwmREG1,actionQual1);
    
        /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1B    */
        // ETPWM_setActionQual_Zero_PwmB(etpwmREG1, actionQual2);
        etpwmSetActionQualPwmA(etpwmREG1, actionQual2);
    
        /* set the action qualifier for the generation of events at counter equals compare value of A for ETPWM1A    */
        // ETPWM_setActionQual_CntUp_CmpA_PwmA(etpwmREG1, actionQual3);
        etpwmSetActionQualPwmA(etpwmREG1, actionQual3);
    
        /* set the action qualifier for the generation of events at counter equals compare value of B for ETPWM1B    */
        // ETPWM_setActionQual_CntUp_CmpB_PwmB(etpwmREG1, actionQual4);
        etpwmSetActionQualPwmA(etpwmREG1, actionQual4);

  • Jan,

    The etpwmSetActionQualPwmA function now expects a combined value passed as an argument for the action qualifier.

    /** @fn void etpwmSetActionQualPwmA(etpwmBASE_t *etpwm, etpwmActionQualConfig_t actionqualconfig)
    * @brief Configure Action Qualifier submodule to generate PWMA
    *
    * @param etpwm The pulse width modulation (ETPWM) object handle (etpwmREG1..7)
    * @param actionqualconfig Action Qualifier configuration
    *
    * Example usage (Removing semicolons to avoid MISRA warnings):
    * etpwmActionQualConfig_t configA
    * configA.CtrEqZero_Action = ActionQual_Set
    * configA.CtrEqPeriod_Action = ActionQual_Disabled
    * configA.CtrEqCmpAUp_Action = ActionQual_Clear
    * configA.CtrEqCmpADown_Action = ActionQual_Disabled
    * configA.CtrEqCmpBUp_Action = ActionQual_Disabled
    * configA.CtrEqCmpBDown_Action = ActionQual_Disabled
    * void etpwmSetActionQualPwmA(etpwmREG1, configA)
    *
    * This function configures Action Qualifier submodule to generate PWMA
    */
    /* SourceId : ETPWM_SourceId_021 */
    /* DesignId : ETPWM_DesignId_021 */
    /* Requirements : HL_EPWM_SR13 */
    void etpwmSetActionQualPwmA(etpwmBASE_t *etpwm, etpwmActionQualConfig_t actionqualconfig)
    {
    etpwm->AQCTLA = ((uint16)((uint16)actionqualconfig.CtrEqZero_Action << 0U) |
    (uint16)((uint16)actionqualconfig.CtrEqPeriod_Action << 2U) |
    (uint16)((uint16)actionqualconfig.CtrEqCmpAUp_Action << 4U) |
    (uint16)((uint16)actionqualconfig.CtrEqCmpADown_Action << 6U) |
    (uint16)((uint16)actionqualconfig.CtrEqCmpBUp_Action << 8U) |
    (uint16)((uint16)actionqualconfig.CtrEqCmpBDown_Action << 10U));

    }

    This means that you need just one function call to set up the action qualifier behavior for all counter match conditions for PWMA. There is a similar function for PWMB.

    I will let the HALCoGen team comment on when this change was introduced, and if/when the examples are going to be updated to match the API.

    Regards,
    Sunil

  • This was very helpful.

    The only thing I had to add is an etpwmInit() call.

    Working code:

    void main(void)
    {
    /* USER CODE BEGIN (3) */
    
        etpwmHspClkDiv_t hsClkDiv=HspClkDiv_by_1;
        etpwmClkDiv_t clkDiv=ClkDiv_by_1;
        uint16 period=0x24;
        uint16 pwmData1=period/2;
        uint16 pwmData2=period/4;
    
        etpwmActionQualConfig_t  actionQualConfig;
    
        actionQualConfig.CtrEqZero_Action = ActionQual_Set;
        actionQualConfig.CtrEqPeriod_Action = ActionQual_Disabled;
        actionQualConfig.CtrEqCmpAUp_Action = ActionQual_Clear;
        actionQualConfig.CtrEqCmpADown_Action = ActionQual_Disabled;
        actionQualConfig.CtrEqCmpBUp_Action = ActionQual_Disabled;
        actionQualConfig.CtrEqCmpBDown_Action = ActionQual_Disabled;
    
    
        etpwmCounterMode_t counterMode=CounterMode_Up;
    
        uint16 count=0;
    
        etpwmInit();
    
        /* set the high speed clock divider   */
        /* set the normal clock divider   */
        etpwmSetClkDiv(etpwmREG1, clkDiv, hsClkDiv);
    
        /* set the period of pwm   */
        etpwmSetTimebasePeriod(etpwmREG1,period);
    
        /* set the counter direction-up,down or updown   */
        etpwmSetCounterMode(etpwmREG1,counterMode);
    
        /* set the compare register CMPA to adjust the duty cycle for ETPWM1A pin    */
        etpwmSetCmpA(etpwmREG1,pwmData1);
    
        /* set the compare register CMPB to adjust the duty cycle for ETPWM2A pin    */
        etpwmSetCmpB(etpwmREG1,pwmData2);
    
        /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1A    */
        /* set the action qualifier for the generation of events at counter equals 0 for ETPWM1B    */
        /* set the action qualifier for the generation of events at counter equals compare value of A for ETPWM1A    */
        /* set the action qualifier for the generation of events at counter equals compare value of B for ETPWM1B    */
        etpwmSetActionQualPwmA(etpwmREG1, actionQualConfig);
        etpwmSetActionQualPwmB(etpwmREG1, actionQualConfig);
    
        /* set and initialize the counter   */
        etpwmSetCount(etpwmREG1,count);
    
        /*  ... run forever  */
        while(1);
    
    /* USER CODE END */
    }