How do I use Simulink “Custom Code” blocks to measure code execution time on TI C2000?

조회 수: 50 (최근 30일)
How do I use Simulink “Custom Code” blocks to measure code execution time on TI C2000?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 12월 2일
편집: MathWorks Support Team 님. 2020년 12월 2일
Simulink Coder’s Custom Code blocks are a key method to call custom code. Custom code blocks can be found under the Simulink Coder library. Start by navigating 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 we want to measure the time taken to execute a block of code on F2837x device. We can configure and use the CPU timer to get the timing information. We 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. 
We are assuming the algorithm whose execution time is to be computed is inside an atomic subsystem. 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. 
1. 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 HW support package)
Add the block to the model and double-click on the block to open the block mask, as shown in the screenshot below. The ConfigCpuTimer() function is used to configure CPU timers. 200MHz is the frequency at which CPUTimer counts and 10000 is the timer period in uSeconds. 
2. Add Model Header block 
Use Model Header block to specify extern variables in model header file. 
3. Add Model Source block 
Use Model Source block to define variables needed to store timer values. 
4. Add Subsystem block containing the algorithm 
As noted before, mark the subsystem as atomic. 
5. Add System Outputs block 
Add this block inside the atomic subsystem containing the algorithm to read the timer value before code execution. 
We also can read the timer value after code execution from the same block in the exit code and compute the difference. 
The computed difference can be sent over a serial link to host using the memory copy block.  

추가 답변 (0개)


Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by