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.

Use SFO library SFO_TI_Build_V6b.lib without TI headerfiles?

Hi all,

I am just starting with HRPWM and would like to auto-update the HRMSTEP-register.

But I can't use the SFO_TI_Build_V6b.lib because we are using own peripheral headerfiles, not the TI provided ones.

So the linker requests EPwm1Regs, ePWM and MEP_ScaleFactor which are not known.

What can I do? Is there a workaround for use of SFO_TI_Build_V6b.lib  without the original TI headerfiles? Or is there a way to get and change the library source code?

  • Stephan -

    int MEP_ScaleFactor and volatile struct EPWM_REGS *ePWM are not specific to the header files - these are variables that you declare in your source code which is calling the SFO_TI_Build_V6b.lib functions. (see the HRPWM user guide appendix). The following was copied and pasted from the hrpwm_duty_sfo_v6 example.  The below needs to be defined at the beginning of your source file as global variables before you call the SFO function. Additionally, above this, #define PWM_CH must be defined equal to the # of ePWM modules + 1.

    //====================================================================
    // The following declarations are required in order to use the SFO
    // library functions:
    //
    int MEP_ScaleFactor; // Global variable used by teh SFO library
                         // Result can be used for all HRPWM channels
                         // This variable is also copied to HRMSTEP
                         // register by SFO() function.

    // Array of pointers to EPwm register structures:
    // *ePWM[0] is defined as dummy value not used in the example
    volatile struct EPWM_REGS *ePWM[PWM_CH] =
                 {  0, &EPwm1Regs, &EPwm2Regs, &EPwm3Regs, &EPwm4Regs};

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

    Because header files are linked when you build your project with the library, at the minimum, you will need to add the linker command file (DSP2802x_Headers_nonBIOS.cmd) and the DSP2802x_GlobalVariableDefs.c source file to your project.  The combination of these files basically links header file variables to their register address locations in the memory map so the library knows where to access them.

  • Okay, now I have seen that MEP_ScaleFactor and *ePWM are variables not specific to the header files.

    BUT they have to be declared as global variables - not really high recommended software practice. Why aren't they given to the SFO() function via calling parameters?

    And the use of *ePWM is not really clear - do I include all PWMs used, all PWMs using HRPWM, something else?

    What is the use of PWM_CH which has to be adapted in SFO_V6.h? Do I set it to all PWMs used, all PWMs using HRPWM, something else?

    Since HRMSTEP is only available on ePWM1 and valid for all PWMs, the number of used PWM channels should not matter!?

    What if I use ePWM1 for normal PWM and ePWM2 for HRPWM? How do I set PWM_CH and *ePWM then?

    Still, I would like to know how the SFO calibration routine works. What else is affected if not only HRMSTEP? What registers are accessed? How is calibration done?

    And still, my PWM registers are named different than the original TI names. How can I solve this other than being forced to use the original TI name?

    Having *EPwm1Regs as calling parameter would solve this, too.

     

  • Stephan -

    All of your questions are answered in the HRPWM Reference Guide Appendix - which shows how to use the MEP_ScaleFactor and *ePWM variables. you do not have to use *ePWM in your code - this is used by the library only and is available for you to use only if you wish to. - the reason you set it up as a global in your code is so that the library properly sets up the register locations at link time. You can still use your ePWM registers with your own header file format.

    These variables are global variables because they are used both in the library and outside of the library - and are used for compiler link time, again, to link library variables to the correct address locations. MEP_ScaleFactor should be used in your code.

    PWM_CH is set to the maximum numerical  HRPWM channel used PLUS 1. So if ePWM channel 2 is HRPWM  but ePWM channel 1 is not, you need to set PWM_CH to 3 (because PWM2 is the maximum numerical  HRPWM channel used).

    HRMSTEP REGISTER is only available in the ePWM1 register space. It is not tied to ePWM1 though. It is independent of all PWM's and shared across all PWM's. 

    The SFO library is proprietary TI information - we cannot tell you which registers are modified and what it is doing.  The reference guide explains exactly how it is used and what needs to be done to surround it. The documentation also explains how the SFO function calculates the # of MEP steps per SYSCLK cycle and returns it in MEP_ScaleFactor. The examples also explain this.

  • Okay, so I will have to live with the SFO library until there might be an updated version that does not use the global variables...:-(

    I finally found a way to use our own register definitions by using a UNION in the linker command file and defining EPwm1Regs as duplicate to our own register name.

    This is not nice, but it works.