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.

TMS320F28379D: Integrating Simulink Embedded Coder generated code into existing CCS project.

Part Number: TMS320F28379D
Other Parts Discussed in Thread: TMS320F280025, SYSCONFIG, C2000WARE

We are doing model based design for digital control of power converter. The modelling and simulations are done in Simulink and then code is generated using the Simulink Embedded Coder. The frame work code is generated mostly using the SysConfig tool. All the control peripherals such as ADCs, EPWMs etc as well as  communication interfaces have been setup using the latest version of the  SysConfig tool. Earlier we have been using the TMS320F280025 controller without CLA. The integration of embedded coder generated files was very simple in that case. We only copied three generated files i.e model_name.C, model_name.h & rtwtypes.h files in our existing CCS project. We achieved the desired control loop execution just by calling the model step function at the precise timing. 

We are just migrating to the Delfino series to take benefit of the increased processing power and the CLA. Again we have setup all the peripherals using the SysConfig tool. The CLA tasks and interrupts have also been setup with the SysConfig tool. I have done some basic testing to verify that CLA is setup correctly to execute the code. CLA Deep Dive submodule in the C2000Academy was helpful. I am facing difficulty in identifying the proper procedure/steps for incorporating the embedded coder generated CLA code into our CCS project. I have already gone through the Mathworks documentation "Using the Control Law Accelerator (CLA)"but the process of combining the generated files into the existing CCS project is not clear to me. It will be nice is some one can guide on the below points:

1- Is it right approach to configure all the peripherals in CCS project and then integrated the embedder coder files into it or otherwise i.e. generate project from embedded coder and then add peripheral configurations and custom code to it?. We are familiar and comfortable with the former approach i.e. integrating the generated files into our existing project.

2- Please provide guidelines for both approaches. If the first approach can work then kindly guide which generated files must be added to the project and the ones that can be ignored for e.g. there are lot of peripheral configuration files that are already generated by the SysConfig tool. 

3- Any other technical literature on the subject that will be helpful in the CLA code configurations in the Simulink Embedded Coder and interfacing with the C28x code.

  • Asad,

    SysConfig feature is new in C2000Ware SDK release, so far we have not worked on integration of SysConfig generated code and Simulink generated code. Let me discuss with our team locally and let back to you in a day or two.

    Thanks & Regards,

    Santosh

  • Even if it was a driverlib based project then there should be a way to export only the control algorithm code from Simulink into the existing CCS project. Looking forward to your guidance.

  • Asad,

    We have not done anything similar. We are checking with MathWorks engineers on their preferred methodology. I will update you when we hear back from them.

    Thanks & Regards,

    Santosh

  • Hi Asad,

    1- Is it right approach to configure all the peripherals in CCS project and then integrated the embedder coder files into it or otherwise i.e. generate project from embedded coder and then add peripheral configurations and custom code to it?. We are familiar and comfortable with the former approach i.e. integrating the generated files into our existing project.

    2- Please provide guidelines for both approaches. If the first approach can work then kindly guide which generated files must be added to the project and the ones that can be ignored for e.g. there are lot of peripheral configuration files that are already generated by the SysConfig tool.

    Yes, you can follow the approach of peripheral configuration using CCS project and then integrating the algorithm code generated from model to get the full application. Since you are comfortable doing this , you can continue doing the same.

    For the first approach, you should pick the files generated with modelName.c and modelName.h for integration and any other separate algorithm specific files generated from the subsystem or reference models. these files are enough if you have all the peripheral configuration done and you have a scheduler up and running to call the functions from the file.

    If you want to do second approach, then it would be better to use the peripheral blocks supported from the Simulink and use custom code only for the peripherals features not supported by Simulink to integrate with custom code workflow directly in Simulink. How do I use Simulink “Custom Code” blocks to measure code execution time on TI C2000? - (mathworks.com).

    3- Any other technical literature on the subject that will be helpful in the CLA code configurations in the Simulink Embedded Coder and interfacing with the C28x code.

    For CLA, use the following doc pages as reference which explains all the details you have to consider using the same

    https://in.mathworks.com/help/supportpkg/texasinstrumentsc2000/ug/CLA-Task-Subsystem.html 

    https://in.mathworks.com/help/supportpkg/texasinstrumentsc2000/ug/using-the-control-law-accelerator-cla.html 

    Hope this answers your question.

    Thanks,

    Aditya

  • I have already gone through the reference documentation. Let me try implementing the first approach. I would request to answer the following points in this regard:

    Is there an option to suppress the generation of the peripheral files so that only the control algorithm code files are generated?.

    Kindly confirm if below understanding is correct:

    I understand that CLA code interface is similar to non CLA code. I will need to call modelName_initialize() once  & modelName_step() function through scheduler. I think the difference lies in the CLA function inputs and outputs. For non CLA code there are input and output structures rtU and rtY for updating the model inputs and reading the inputs. However for CLA function the inputs and outputs need to be accessed using CPU to CLA message RAMs and CLA to CPU Message RAMS (assigned using data store memory blocks in Simulink). So I will need to write and  read these variables instead?.

    I have also noticed that the CLA initialization code from embedded coder is setting up the CLA message RAMs and data RAMs. I configured the CLA in the CCS project. I think I will need to remove that code to avoid duplications.

    Thanks alot for your support.

  • Hi Asad,

    option to suppress the generation of the peripheral files

    If you do not use any driver blocks, you will not see any driver specific files included as part of modelName.c file though there will be other files with names starting from MW_c28x_ generated specific to scheduler and peripheral clock init configuration. You just have to use the functions in modelName.c and .h files.

    CLA code interface

    Yes, for CLA, you need to get integrate the source and header files generated by CLS subsystem. This will have the definition of variables specific to CLA message RAMs along with the CLA function. You can integrate this with your CCS project to continue further.

    Thanks,

    Aditya

  • Hi Aditya,

       There is one more related question. We are maintaining two separate Simulink projects for code generation. All the generated model files have name relating to the model except for the "cla_task.cla" file. The generated code from both models have the same file name. The question is:

    1-How to resolve this same name conflict. Is there any setting in the embedded code generation to give a custom name to this file or do we need to handle this conflict manually after the code generation.

    2- Kindly advise what is the recommended approach?. Is it Okay to do code generation from two separate Simulink projects (different people working on different control subsystems) or we should go for a single project?. I have not tried combining two models into a single project but I think that this will need two task triggers and two CLA subsystems. Two separate CLA tasks are required to have independent execution of both tasks.

  • Hi Asad,

    1. There is no provision to change the name of the generated "cla_task.cla" file. You will have to change it and integrate this manually after code generation.
    2. That depends upon the logic (CLA trigger source, content of CLA subsystem and data shared between CPU and CLAs) that multiple people working on. Ultimately you may have to establish your own process of code generation and integration as you may be working over multiple iterations to get final algorithm. 

    Thanks,

    Aditya

  • Hi Aditya,

       Thank you for answering last queries. I have a couple more questions. 

    1- The first one is regarding the __TMS320C28XX_CLA__ definition. I think I need to define this at some point in the code as the cla subsystem function is not building/defined with my current project setup.

    Please guide how to define it properly. If I define it globally then the compiler throws a lot of errors.

    2- The second question is related to compile time error. This error is coming in my project (in which the model related files have been imported manually in the existing project)  as well as the Embedded Coder Generated project. This is shown in the screenshot below:

    Please guide on the above two points.

  • Hi Aditya,

      I found the answer to first query in the following post: https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1055510/tms320f280049c-question-about-__tms320c28xx_cla__?tisearch=e2e-sitesearch&keymatch=__TMS320C28XX_CLA__# . 

    I have some clue to the second issue: Actually we are trying to migrate existing model developed for C28x processor to the CLA task. I think we will need to change some fucntions as CLA does not support standard maths library. I have also noticed that the generated project is including math.h library for the CLA code. Should it be adding CLAmath.h instead?. Please refer if there is some documentation for guiding in migrating code from C28x to CLA.

    /*
     * Trial License - for use to evaluate programs for possible purchase as
     * an end-user only.
     *
     * File: aux_grid_cla.c
     *
     * Code generated for Simulink model 'Aux_Grid'.
     *
     * Model version                  : 4.34
     * Simulink Coder version         : 9.7 (R2022a) 13-Nov-2021
     * C/C++ source code generated on : Mon May  9 14:51:42 2022
     *
     * Target selection: ert.tlc
     * Embedded hardware selection: Texas Instruments->C2000
     * Code generation objectives:
     *    1. Execution efficiency
     *    2. RAM efficiency
     * Validation result: Not run
     */
    
    #include "aux_grid_cla.h"
    #include "IQmathLib.h"
    #include <math.h>
    #include "rtwtypes.h"
    #include "multiword_types.h"
    #include "Aux_Grid_private.h"
    #include "cla_header.h"
    

  • Hi Asad,

    CLAMath.h is added as part of cla_task.cla file. In order to use CLA specific math functions you need to use MATLAB function block. Please see the example c28035pmsmfoc_cla.

    The following block uses CLA trigonometric functions.

    c28035pmsmfoc_cla/FOC Algorithm/Torque Control Algorithm/Generating Space Vectors/Generating Raw Space Vectors/Park Transformation

    In order to migrate code from C28x to CLA, you need to ensure that CLA MAth functions are used instead of standard maths library function. 

    Thanks,

    Mukul

  • Hi Mukul,

    Thank you very much for you reply.

    It appears that the code generation doesn't incorporates any check to ensure that CLA subsystem contains CLA supported functions only. The CLA subsystem does include the math.h library whenever any standard math library function is there. The issue comes during project compilation phase when CLA C compiler comes across standard math library function calls.

    Your proposed solution is correct and we have learnt and used this approach yesterday to resolve compilation issues in one of the model. 

    If my understanding is correct then it is only a suggestion to Mathworks to incorporate some checks in the CLA subsystem block so that code generation is successful only if there are no incompatibilities.

    I think we can close this thread.

  • Thanks to Mukul, Aditya and Asad for helping in resolving the issue. I will close the thread now.