Main Content

Enhance Code Execution Speed in TI C2000 Simulink Applications

In this topic, you will learn various optimization techniques to enhance the execution speed of Simulink® applications on Texas Instruments® C2000™ devices. You will explore configuration parameter adjustments in the code generation settings, such as selecting Faster Runs in the build configuration and enabling the TI C28x™ Code Replacement Library (CRL) for hardware-optimized functions.

Additionally, the topic covers efficient code and data loading strategies, the selection of data types for precision and performance, and considerations for devices with or without Floating Point Units (FPU). Advanced optimization options and additional resources are also provided.

The following techniques are designed to improve the execution speed of Simulink applications on TI C2000 devices.

Compiler Specific Optimization

Updating Build Configuration

Navigate to Configuration Parameters > Code Generation > Build Configuration and select Faster Builds to compile your code with higher optimization, effectively reducing run-time.

Note

When you configure Build configuration to Faster Builds, the build adds -O2 flags. For better performance, can change the build configuration to Specify and add different levels of flags like O3, O4.

Toolchain Selection

The Texas Instruments C2000 processors are supported by various toolchain options, enabling the users to generate executable files in different formats. The supported toolchains for c28x core include:

  1. Texas Instruments Code Composer Studio (C2000) - This generates an executable in Common Object File Application Binary Interface (COFF ABI) format. COFF ABI format will interpret double datatype in Simulink as 32-bit floating point.

  2. Texas Instruments Code Composer Studio - EABI (C2000) - This generates an executable in ELF Application Binary Interface (EABI) format. ELF ABI format will interpret double datatype in Simulink as 64-bit floating point.

Based on the processor selection, multiple toolchain options are supported. Choosing the appropriate toolchain can also impact performance. For more information, see Exploring TI C2000 Toolchain Options.

Data Type Optimization.  Select the appropriate data type, single or double, based on the precision required by your FPU type processor. Additionally, examine the signal data types and use the minimum required precision whenever possible. For example, if the variable Counter can range from 0 to 130, a 16-bit integer data type would be sufficient instead of using double or single. For more information, see Exploring TI C2000 Toolchain Options.

Target Specific Optimization

Enable Code Replacement Library (CRL)

Ensure optimal hardware functions by selecting TI C28x in Configuration Parameters > Code Generation > Interface > Code replacement library. This replaces functions like multiplication, additions, IQMath operations, Fast integer division, CLA math operations and more for EABI toolchain with efficient hardware-optimized counterparts.

Optimize Code/Data Loading

Improve processing speed by loading code/data in runtime from flash to RAM. For more information, see https://in.mathworks.com/matlabcentral/answers/673963-how-do-i-load-data-code-to-flash-and-run-from-ram-on-a-ti-c2000-device.

Inlined Parameter Behavior

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

Fixed-Point Math Optimization

On devices without Floating Point Unit (FPU) support, avoid using floating-point operations and opt for fixed-point math to reduce computational overhead. You can use the IQMath blocks available in the C2000 library, which can be manually added during modeling.

CRL replacement happens when you select the correct datatype. Choosing datatypes for math and trigonometric operations imposes restrictions on using IQMath library functions.

Block Name Datatype Approximation MethodExecution time (us)
IQNtrig (IQsinPU) Fixed point   0.88
SinFixed point  Lookup(Linear Point Slope – Revolution)11.51

Utilize CRL for Fixed-Point Models

For models using Fixed-Point math, the CRL replaces the operations with highly optimized TI IQ Math routines. Ensure no CRL misses due to rounding or saturation options. For more information, see

Leverage FastRTS Library

On devices with FPU support, use optimized floating-point math functions from the FastRTS library. For devices with FPU but no Trigonometric Math Unit (TMU), consider enabling FastRTS support.

Enable TMU with FPU

On devices supporting both TMU and FPU, select Enable TMU for more optimized floating-point math routines. This option offers even better performance compared to FastRTS and covers most of the routines found in FastRTS.

The table describes the execution time for Sin Cos Quick Math block on F280049C LaunchPad.

Block Name Datatype Approximation Method TMU Execution time (us)
Sin Cos Quick Math     Floating point     None  On 0.82 
None Off 2.51

Unlock Advanced Optimization Options

Explore advanced optimization options under Configuration Parameters > Code Generation > Optimization > Advanced parameters.

See Also

| | | | | | | |

Related Topics