Measuring Code Execution Time on TI C2000 using Custom Code Blocks
Simulink®
Coder™ Custom Code blocks provide capability to call custom code. You can view the
custom code blocks under the Simulink
Coder library. Navigate to the Simulink library browser by pressing the button, or by typing the command
slLibraryBrowser
at the MATLAB® command prompt. Locate the blocks as shown below:
Suppose if you need to measure the time taken to execute a block of code on F2837x device, configure and use the CPU timer to get the timing information. Read the free running timer value before code execution and read back timer value at the end. The difference of the timer values gives code execution time. Assume the algorithm whose execution time is to be computed is inside an atomic subsystem.
Note
When using custom code block with subsystems, it is important to note that the custom code blocks honor the boundary of a subsystem only if it is atomic.
Add System Initialize Block
Begin with System Initialize block to Initialize, configure and start the CPU timer 2.
Note
Timer0 is used for scheduling and Timer1 is used for profiling in C2000 Microcontroller Blockset.
Add the System Initialize block to the model and double-click on
the block to open the block mask, as shown in the screenshot. The
ConfigCpuTimer()
function is used to configure CPU timers.
200MHz
is the frequency at which CPUTimer
counts and
10000 is the timer period in micro seconds.
Add Model Header Block
Use Model Header block to specify extern variables in model header file.
Double click on the block to specify the extern variables.
Add Model Source Block
Use the Model Source block to define variables required to store timer values.
Double click on the block and specify the variables required to store timer values.
Add Subsystem block containing the algorithm
When using custom code block with subsystems, it is important to note that the custom code blocks honor the boundary of a subsystem only if it is atomic.
Add System Outputs block
Add System Outputs block inside the atomic subsystem containing the algorithm to read the timer value before code execution.
You can also read the timer value after code execution from the same block in the exit code and compute the difference. The computed difference is sent over a serial link to host using the memory copy block.
See Also
Overview of Creating a Model and Generating Executable for C2000 Processors | Enhance Code Execution Speed in TI C2000 Simulink Applications
See Also
Overview of CLA Configuration for C2000 Processors Using Subsystem | Overview of Creating a Model and Generating Executable for C2000 Processors | Enhance Code Execution Speed in TI C2000 Simulink Applications