Target Language Compiler    

Explore Variable Names and Loop Rolling

Objective: This example shows how you can influence the generated code from the Simulink GUI.

Example directory: tlctutorial/mygain

Preparing the Example

Performing the Tasks

  1. Change the Sine Wave block to be a Constant block and add labels to the new simple_mimo model as shown in this diagram.
  2. Save your changes in simple_mimo.mdl.
  3. This is a vectorized model. Generate C code for the model and view the MdlOutputs( ) section, paying close attention to variables and for loops. This section appears right below the statement

    Notice that:

  1. Real-Time Workshop provides some ability for users to control RollThreshold. You can manually alter the loop rolling threshold by setting your own value for RollThreshold for the entire model. Do this for your model by selecting General code generation options from the Category pulldown on the Real-Time Workshop page.

    Set Loop rolling threshold to 12.

    This results in loop rolling only when the number of signals passing through a block exceeds 12.

  1. Generate code for your model (Generate code only) and view the output C file. Note the significant difference in the model code compared to the system that did not use such a high RollThreshold.
  2. Change the RollThreshold back to the value 10 in the General code generation options dialog. Modify the simple_mimo model to have a vectored gain as shown below.
  3. Once again, generate code and note the difference between this code and the code from the model that simply included a scalar gain of 1. In this case, the 10 gains are placed in a parameter array.

As you look at the TLC file, matlabroot/rtw/c/tlc/gain.tlc, notice three "rollVars" for U, Y, and P. This tells TLC that inputs (U), parameters (P), and outputs (Y) can all be rolled when the number of signals operated on by this block exceeds the RollThreshold.

Loop rolling is an important but very advanced capability of Real-Time Workshop and TLC. It takes a fair amount of time to fully understand loop rolling before you can apply it. This brief introduction to loop rolling demonstrates that it exists and provides some insight and illustration as to how it works.


 Building a Model Using the TLC Debugger Code Coverage for Debugging TLC Files