Guy on Simulink

Simulink & Model-Based Design

R2008b Simulink: Sample Time Colors

Simulink models present a schematic layout of your algorithm.  The diagram encodes information about the system in the form of block icons, data type annotations, and sample time colors.  In technical support, I have seen many questions like,

  • How can I print on a black and white printer and show sample time information?
  • What is the sample time of the green signal?
  • Why does Simulink have so few sample time colors?

In this post, I will to show you some new R2008b features that make it easier to understand what rates are in your model and make it easier to document your design.  I will also unravel the mystery of why Simulink has so few sample time colors.

Sample Time Annotations

For a long time Simulink has offered a Format menu option to turn on the sample time colors.  This labels blocks and signals with different colors based on their update rate.  Red for the fastest discrete rate, green for the second fastest, black for continuous, and many more.  The documentation has a table of sample time colors and their meaning.  After updating the diagram (Ctrl-D), these colors show you which blocks have the same rates in your model.  In Simulink R2008b, you can choose to show the sample time colors as well as sample time annotations.

Simulink R2008b sample time colors menu

The annotations add text  to the diagram that identifies rates as D1, D2, D3, Cont, Inf, etc.  This is a great reminder when your model has many rates in it.  Now you can print your model on a black and white printer and keep the rate information visible in the form of annotations.

Simulink diagram with R2008b sample time annotations

The Sample Time Legend

To help decode the meaning of these annotations and the colors, we have added the Sample Time Legend.  This opens when you first enable the Sample Time Display options, and is also found through the View->Sample Time Legend menu.

Simulink R2008b sample time legend

The annotation labels show you the meaning of the color and include the value of the sample time for that model.  In previous releases, you could only get a list of sample times in the model using debugger commands.  For example:

>> sim(bdroot,[],simset('Debug',{'stimes','stop'}))
%----------------------------------------------------------------%
[TM = 0 ] stcDemo.Simulate
(sldebug @0):
--- Sample times for 'stcDemo' [Number of sample times = 4]
1. [0 , 0 ] tid=0 (continuous sample time)
2. [0.05 , 0 ] tid=1
3. [0.1 , 0 ] tid=2
4. [0.2 , 0 ] tid=3

(sldebug @0):
%----------------------------------------------------------------%
% Simulation stopped

Why so few sample time colors?

Simulink graphics originally (circa 1992) had a minimum 16-color graphics environment, including X terminals and Windows 3.0. This meant that the lowest common denominator had to work. All the color stuff was hard-coded into the sample time code, so even when 32-bit core color support was added circa R12-R13, the sample time code was not updated. The addition of annotations and a sample time legend are part of a much larger project in recent releases to improve the use of color in Simulink.

Do you have sample time colors turned on in your models?  Leave a comment and tell me what you think about this new feature.

|

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.