SPRADI0A July   2024  – November 2024

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
    1. 1.1 Getting Started
  5. 2Model-Based Design of eCompressor
    1. 2.1 General Texas Instruments High Voltage Evaluation (TI HV EVM) User Safety Guidelines
    2. 2.2 Block Diagram
    3. 2.3 Hardware, Software and Testing Requirements
      1. 2.3.1 Hardware setup
      2. 2.3.2 Software setup
      3. 2.3.3 Test Procedure
  6. 3 Simulink Configuration Settings
    1. 3.1 Simulink Tool Optimization
      1. 3.1.1 Optimum Code Generation
    2. 3.2 C2000 Specific Optimization
      1. 3.2.1 Using TMU Through Simulink
      2. 3.2.2 Using Software Libraries Through Simulink
      3. 3.2.3 Running Code From RAM
    3. 3.3 Performance Comparison
  7. 4 Profiling Using Simulink
    1. 4.1 Processor-in-Loop (PIL) Method
    2. 4.2 C2000 Timer-Based Profiling
    3. 4.3 Code Composer Studio tools
  8. 5Summary
  9. 6Revision History

Simulink Tool Optimization

The C2000 Microcontroller Blockset along with Embedded Coder is responsible to generate the code for C2000 devices. To ensure that the code generated is optimized for C2000, the configurations in the tool are to be specifically chosen. All configurations corresponding to model-based code generation are available in the model configuration tab in Simulink.
TIDM-02012 Hardware Settings Figure 3-1 Hardware Settings

Open model configuration parameters by selecting the Hardware settings option under the Hardware tab of Simulink window. Code optimization configurations are available in the Optimization tab available in the Code Generation drop down as shown in Figure 3-2.

TIDM-02012 Configuration
                    Parameters Figure 3-2 Configuration Parameters

Configurations to be made to ensure optimal code generation for C2000 are as shown in Table 3-1.

Table 3-1 MATLAB Optimization Settings
Simulink Tab Specific Setting Default Configuration Optimized Configuration
Code Generation Build configuration Faster Builds Faster Runs
Prioritized objectives Unspecified Execution efficiency
Optimization Priority Balance RAM and speed Speed
Specify custom optimization On Off
Default parameter behavior Tunable Inlined
Efficient Map of Float to Int Off On
Interface Support absolute time On Off
Support complex On Off
Support non finite On Off
Math and Data Types Life span auto 1

All the mentioned configurations can be configured manually by selecting appropriate options in the Model configuration section as shown in Figure 3-2. Alternatively, a MATLAB .m script containing the above configuration can be integrated with the application example to ensure that the optimized configurations are invoked.

The script to integrate with the application is available with the TIDM_2012_F280039_MBD example with the name - TIDM_02012_F280039C_MBD_optimconfigs.m.

Note: The script provided with the example TIDM_02012_F380039C_MBD_optimconfigs can be used as-is for other application examples by changing just the model name and running before generating the code to ensure all the optimal settings are configured in the Simulink tool.

Code Generation:

  1. Build Configuration: Faster runs

    The build configuration of faster runs ensures the C2000 tool chain configuration is updated to use compiler optimization -O2 in place of default -O0.

  2. Objective priorities: Execution efficiency

    Keeping execution efficiency as the highest priority in the objective priority ensures the code generation from MATLAB is focused on the execution speed. Other parameters such as RAM, ROM efficiency are also available as a part of objective priorities that can be invoked based on the requirement, but may impact the performance. Default configuration is none.

Optimization:

  1. Optimization priority: Maximize speed

    User is allowed to configure the optimization priority to either maximize the speed, minimize the memory (RAM) or to balance between minimizing RAM and maximizing speed. To generate code focused on better performance in terms of execution speed, the optimization priority is to be set to maximize the speed. The default behavior is to optimize keeping a balance between RAM and speed.

    Change Configuration Parameters > Code Generation > Optimization > Optimization levels > Priority to Maximize Execution Speed. This applies code generation settings to maximize execution speed.

  2. Optimization customization: Off

    If the optimization customization is unchecked, the default configurations under the Details tab is auto-populated with the block operation optimized for improving code execution speed.

    Uncheck the Specify custom optimizations in Configuration Parameters > Code Generation > Optimization > Optimization levels. This disables the parameters in the Details section, so that you cannot individually select or clear these parameters.

  3. Default parameter behavior: Inlined

    Boost performance by changing Configuration Parameters > Code Generation > Optimization > Default parameter behavior to Inlined, optimizing default parameter behavior.

    Also, check the Inline invariant signals checkbox in Configuration Parameters > Code Generation > Optimization > Advanced parameters. This uses the numerical values of model parameters, instead of their symbolic names, in generated code.

  4. Efficient Map of Float to Int: On

    Datatype mapping from float to int is to be enabled. This configuration removes code that handles floating-point to integer conversion results for NaN values.

    Check the Remove code from floating-point to integer conversions with saturation that maps NaN to zero checkbox in Configuration Parameters > Code Generation > Optimization > Advanced parameters. This removes code that handles floating-point to integer conversion results for NaN values.

Interface:

Under the interface tab, the support for all the data type configurations that are noto going to be in use can be disabled. For generating efficient code, the configuration support for absolute time, non-finite numbers and complex numbers can be removed. Additional checks for the selected configurations in the Support tab is enabled, which may add additional number of cycles in run time application code.

Uncheck the Support: absolute time, non-finite numbers and complex numbers checkbox in Configuration Parameters > Interface > Software environment. This causes the support for blocks that depend on absolute time, non-finite numbers and complex numbers. Deselecting unused configurations under the Support tab ensures better run-time code efficiency.

Application lifetime:

Set the Application lifespan (days) field in Configuration Parameters > Math and Data Types > Advanced parameters. This specifies how long, in days, an application that depends on elapsed time can execute before timer overflow occurs.