Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Simulink Formation

Version 0.1 – by MARTIN Cezar


Confidential C
Contents
Block timer conversion................................................................................................................................3
Block Conv_BoolToEvent and Conv_BoolToEvent_RisingEdge....................................................................3
Modelling....................................................................................................................................................4
RSA Timer....................................................................................................................................................5
RSA FlipFlop.................................................................................................................................................7
RSA TurnOnDelay........................................................................................................................................8
RSA TurnOffDelay........................................................................................................................................9
Detect Decrease:.......................................................................................................................................10
Detect Increase:.........................................................................................................................................10
Summary of model inputs/outputs types:.................................................................................................11
Naming Rules for Matlab Modeling...........................................................................................................12
Declaring a constant in InitFcn:.................................................................................................................16
Enum types:...............................................................................................................................................17
Delay block:...............................................................................................................................................20
Switch:.......................................................................................................................................................21
Multiport Switch:.......................................................................................................................................22
Counters, algebraic loops..........................................................................................................................23
MXAM:......................................................................................................................................................24

Version 0.1 – by MARTIN Cezar


Confidential C
Block timer conversion
This block is used for Timers (calibration and configuration of time) for a Stateflow/Simulink model .A
constant has to be declared ( NameOfModel_SAMPLE_TIME_CST ) in the file
NameOfModel_Constants.m and change the name from MASK of the block to Timer_Conversion.

Click on the block and change the name of the constant to the one declared in the .m file.

At the top of the model, use these blocks to change calibrations or configurations of time.

Block Conv_BoolToEvent and Conv_BoolToEvent_RisingEdge


These blocks are used to convert a boolean into a TYP_EVENT

These blocks shall be used at the TOP of model

Version 0.1 – by MARTIN Cezar


Confidential C
The usage of these blocks is as follows:

-Conv_BoolToEvent is used when we have a boolean that does NOT need to take into account the
change from 0 to 1 of the input.

-Conv_Bool ToEvent_RisingEdge is used when we have a boolean that NEEDS to take into account the
change from 0 to 1 of the input.

Modelling

Here we have an example of a modelling configuration that is commonly found in functions. The
purpose of this structure is to allow the user to have a simple structure that is easy to read. In our
example, the first switch has a particular structure used for the signal port:

Version 0.1 – by MARTIN Cezar


Confidential C
This is used for the initialization of the structure.

RSA Timer

This block detects the rising of the INIT port to 1. Afterwards, the following will happen :

1.The output “Timer” will be set with “Duration” value and start Decrementing by SampleTime.

Version 0.1 – by MARTIN Cezar


Confidential C
2.The output “Timeout will be Rising to 1 (TRUE) after a delay (Duration/SampleTime).

When INIT falls back to 0, the block will be reset to Initial State(delay_out= 0 , Timer= 0). This can be
observed in the previous screenshots. One thing to note here is the fact that the block parameters can
be modified to change the Initial State.In the following example, we have configured the block to have
the output TIMEOUT=1 and INIT= 1.

Version 0.1 – by MARTIN Cezar


Confidential C
RSA FlipFlop
Also known as S-R flip-flop/set-reset flip-flop. Is an implementation using a specific truth table:

S=0 R=0 and Initial Condition= True

S=1 R=1 and Output if Indeterminate Condition= False

When we have a true value applied to both SET and RESET, the output is set to either true or false:

Ideally this state is undefined and is usually avoided.


The initial value for the output is given by the mask parameter Initial Condition.

Version 0.1 – by MARTIN Cezar


Confidential C
RSA TurnOnDelay
When the input Signal is Rising to 1 :

1. The output Out will be rising to 1 (TRUE) after a Delay ( Delaytime/Timestep)

When the input Timestep is falling to 0, the following will happen:


1. The block will be reset to Initial State.(Out= 0)
Initialization:
-Output initialization = beginning state of Output signal.
-Input initialization = Used to determine rising or falling edge at the first simulation step:
For 0 – Block will detect Edge Rising at the first simulation step itself.
For 1 – Block will detect Edge Rising at the first simulation step.
To note:
1. Negative Values are not allowed as an inputs (Delaytime,Timestep) to the block
2. The Block's inputs (Delaytime,Timestep) must have Same Datatype
3. The Block's inputs (Delaytime,Timestep) should not be Zero value when there is a Rising Edge of input
(Signal)

Version 0.1 – by MARTIN Cezar


Confidential C
RSA TurnOffDelay
When the input "delay_flag" is falling to 0:
1. The output "Ctr" will be set with "Dly" Value and start Decrementing by SampleTime.

2. The output ("delay_out") will be falling to 0 (FALSE) after a Delay (Dly/SampleTime).

When the input "delay_flag" is rising to 1, the following will be happening


1. Block will be reset to Initial State (delay_out = 1 and Ctr =0)

NOTE:
1.When fixed data types is given for input ("dly"), the sample time's data type in the mask should be set
as "Uint8".
2.The input "dly" should be set such that it is a multiple of sample time "Ts". Eg. If "dly" is 1 then allowed
sample time (Ts) are 0.1,0.2,0.02, etc.,

Version 0.1 – by MARTIN Cezar


Confidential C
Detect Decrease:
If the input is strictly lesser than its previous value, then output TRUE, otherwise output FALSE. Initial
condition of the output is false.

Detect Increase:
If the input is strictly greater than its previous value, then output TRUE, otherwise output FALSE. Initial
condition of the output is false.

NOTE:
The check for the initial condidtion can be inhibited by unchecking the checkbox
"Compare the Input with Initial Value".
In the BCM library we also have access to the detectChange block that can display both the changes
from one state to another and vice-versa.

Version 0.1 – by MARTIN Cezar


Confidential C
Summary of model inputs/outputs types:
Code Signification Definition Type
TYP_* User Defined Type Predefined type (often used for enumerated type) Any type

*_CF Configuration Parameter Allows to activate/deactivate an Activity Chart (typ. in EEPORM) All

*_CST Constant Constant parameter Int / Real

*_TP Calibration Parameter Calibration parameter for tunning (typ. in Flash ROM) All

*_TM_TP Calibration Timeout Variable representing a time calibration parameter All

*_TM_CF Configuration Timeout Variable representing a time configuration parameter All

*_S Saved Variable for input Variable that needs to be saved (in EEPROM for example) All

*_S_OUT Saved Variable for output Variable that needs to be saved (in EEPROM for example) All

*_T_FAIL Diagnosis Trouble Code Defines failures and flaws Boolean

*_T_CONF

R_* Request Variable representing a Request (usually R_xxxx_BY_yyyy) All

*_TOP TOP SubSystem The highest level of the hierarchy of a project SubSystem

*_FNS Activity Activity that contains several sub-activities SubSystem

*_CTL Control Subsystem Allows activation/deactivation of Activity Charts SubSystem

*_FCT Function Subsystem Performs a given task or function SubSystem

TT_* Truth Table Gives the values of the outputs as a function of the inputs Truth Table
SubSystem

TB_* Test Bench Describes interactions between the model and the environment .mdl

Z_* Test Bench Variable Variable used in the Test Bench for simulation purposes. All

Version 0.1 – by MARTIN Cezar


Confidential C
Naming Rules for Matlab Modeling
All parameters should be define in capital letter (and only in capital letters)

 Lowercase letter is not permitted for the inputs, outputs, constants, enumerated types
parameters.
 The naming rules in capitals letters is due to Statemate naming rules which allow only capital
letters. It’s to have the same naming rules between Statemate and Matlab to avoid problem in
the data-dictionary.

All parameters name size are limited to 31 characters

 The maximum letters permitted for a parameters is 31 characters (It’s a model Based-Design
rules)

Choose the Right Words for a Parameter, Subsystem, Stateflow, State in StateFlow

 The name of a function must contain one or two action verbs and one or two objects
(complements). The label must represent the task performed by the underlying function. Thus
verbs like “manage”, “supervise” should be avoided because they are too vague.
This rule also forces the author to construct the specification by identifying the missions and
objectives of the function.

Respect Name Uniqueness for Each Parameter, SubSystem, StateFlow, State in Stateflow

In general, do not use names that are too similar for two different states, parameters, etc.

In particular …

 Do not define local variables with the same name in one model to avoid problem.
Similarly …
 Do not name two subsystem or state in StateFlow identically, especially if they perform two
different functions, even though Simulink allows it. This is to avoid interpretation errors.
Notably…
 Use different names for a parallel StateFlow State.

Use the Positive Form for all Parameters, SubSystems, StateFlow Names

 Use variable, state and chart names that satisfy positive logic. For instance use
“ALL_THE_DOORS_ARE_CLOSED” instead of “NO_DOOR_IS_NOT_OPEN”.

Remain Independent of the Target Project

 Avoid abbreviations. All the names should be as clear as possible, and should be meaningful to
the layman.
 All the names used inside the top of the model should be independent of any project. These
names should not include any physical or implementation information. They should be as

Version 0.1 – by MARTIN Cezar


Confidential C
explicit as possible as to the concept they represent. For Example:, do not use variables such as
“VEHICLE_SPEED_84” or “WIRED_INPUT_SENSOR_FAILED”, but simply use the names
“VEHICLE_SPEED” or “SENSOR_FAILED”.

Name External and Environment Activities Logically

 The names of the external activities should be representative of what they represent (either
physically, e.g., the CAN; or abstractly, e.g., an input produced by another Simulink model or a
Statemate Model or an output fed to another Simulink or Statemate model).

Put information insight the Name Variables

 Flow names should be as clear and explicit as possible and must not burden with useless
information, given that name sizes are limited to 31 characters.

 For Example: WAITING_CONFIRMATION_TM_TP does not describe what confirmation is


awaited. It’s describe that it’s time calibration parameters with the suffix *_TM_TP

 For names to hold maximum information it is recommended to follow the following scheme for
internal or CAN inputs: R_ACTION_BY_SOURCE (Example:: R_WIPING_BY_DRIVER). “R” stands
for “Request”.

R_action1_by_A1
R_action1_by_driver
A1
R_action3_by_A3
A3
R_action2_by_driver
A2
R_action2_by_A2

This prefix cannot always be applied.

For Example: Data such as vehicle or engine speed or the state of the engine, it is useless to add
any prefix or suffix.

 Variable names should not hold negative forms inside them. For example,
'DRIVER_DOOR_NOT_OPEN' should be replaced by 'DRIVER_DOOR_CLOSED'.

Certain types of flows must be recognized immediately by their suffix:

 Configuration parameters : _CF (that are configurable by diagnosis)


 Calibration parameters: _TP
 Constant parameters (these are not configurable by diagnosis): _CST
 Time Calibration parameters : _TM_TP
 Time Configuration parameters : _TM_CF (that are configurable by diagnosis)
 Variables to be saved in EEPROM: _S for input or _S_OUT for the output.

Version 0.1 – by MARTIN Cezar


Confidential C
Have uniqueness for constant parameters for each model

Naming rules and constant declaration in Simulink model

 NAMEOFTHEMODEL_NAMEOFTHECONSTANT_CST or
INITIALOFTHEMODEL_NAMEOFTHECONST_CST
 Declare constants of the model in the function InitFct for each model.
 In the file NameOfTheModel_Constant.m, you find only the constant
“NAMEOFTHEMODEL_SAMPLE_TIME_CST”  if in this model there is the use of timing calibration.

Click on the Model Explorer button

Version 0.1 – by MARTIN Cezar


Confidential C
1. Select the model
2. Click on the tab Callbacks
3. Click on InitFcn
4. Declare the constants parameters that you need in your model.

3
2
5
4

Transversality of models for some specificity about architecture

Some specifies about the architecture EE C1A (double APC and VehicleState C1A etc …) making diversity
with our transversal models.

To resolve this problem and keep our transversal models, an addition of an interface envelop is probably
needed.

Example: models Dongle/Tracker:

-          Before C1A: input IGNITION_ON


-          C1A: need to have ignition cabin (or VehicleState C1A to keep the transversally with BCM/HFM)

The modification is to take into account the diversity and manage the 2 inputs data for the same
information (In this case it’s alimentation) and switch on the correct data depend on the architecture EE.

Version 0.1 – by MARTIN Cezar


Confidential C
Declaring a constant in InitFcn:
When working on a function, we are unable to directly declare the constant value inside a block
parameter as it would give us a fail when running MXAM. As such, we will need to declare the constant
together with it’s value in InitFcn.

In this example :

VOL_ALARM_ZERO_CST means that we have both the Timeout output and the Init Input = 0.

To declare the constant we shall go to :

1. Model explorer :
2. In the window that pops up, at the highest level of our function ( here VolumetricAlarm )

Version 0.1 – by MARTIN Cezar


Confidential C
3. Inside the model properties tab -> Callbacks -> InitFcn :

Enum types:
When working inside a function , one variable might hold more than 2 values, as such we will need
to use a ENUM type class to define the values/functionality of the variable. In the following
example , we will see how this works for the variable RES_STATUS_S.

As we can see, the input is defined as a type Enum: TYP_RES_STATUS.

Version 0.1 – by MARTIN Cezar


Confidential C
For the model to know what values each state is attributed with, we will need to have a
corresponding .m file declared inside our workspace (as to make the model compliable).

In this case, we have TYP_RES_STATUS.m with it’s values for RES :

When using one of the enum values, we will need to declare the constant as
TYP_”variablename”.”value”. In this example, the model checks to see if RES_STATUS_S is in the
Remote engine start value.

Version 0.1 – by MARTIN Cezar


Confidential C
It is important to note that inside the signal attributes, the output data type must also be Enum
type, together with the specific class.

Step size: the size of which the solver takes samples for.

Version 0.1 – by MARTIN Cezar


Confidential C
Fundamental step size should be set to fixed step, 0.01.

Event signal : Specifies an event that causes the transition to be taken, provided the condition. If
used without a convert block, it is used for stateflow . If a converter block is used, used for Simulink
type checks.

Delay block: Sample and hold with one sample period delay. (This block applies a delay to the
signal)
In the example we can see that the added delay to the signal is = to 0.01.

Version 0.1 – by MARTIN Cezar


Confidential C
Switch:

Pass through input 1 when input 2 satisfies the selected criterion; otherwise, pass through input 3.
The inputs are numbered top to bottom (or left to right). The first and third input ports are data
ports, and the second input port is the control port.

This example illustrates the case in which input 2 satisfies the criteria and therefore input 1 passes
to the output.

Similarly, the same case goes for when input 2 does not satisfy the criteria and input 3 will pass to
the output.

Version 0.1 – by MARTIN Cezar


Confidential C
Multiport Switch:

Pass through the input signals corresponding to the value of the first input. The inputs are
numbered top to bottom (or left to right). The first input port is the control port. The other input
ports are data ports. The number of data ports are customizable.

In the example, because the control port is set to 1, the output will have the value set at the input
port 1.

Version 0.1 – by MARTIN Cezar


Confidential C
When the control port receives a signal different from 1, 2 or 3, we will have an error. We can
change the behavior of the port by changing the block property,, Diagnostic for default case,, to
,,none,, . If we do this, whenever the switch receives a signal different from x ( where x is the
number of ports ) , the output will automatically choose the value that is specified in the port with
the * symbol.

Counters, algebraic loops


By using a counter we can count the amount of time a signal stays in a specific timeframe at a
specific value. In the following example, we only want the output to display the value 1 only after
our signal has been in the true state for at least 60ms.

For this, we have to use a counter that counts how much time our signal has stayed in the true state.
To do this we have to plan out the logic by using the signal output and adding 1 to it every time-step
in which the signal is true. After 60ms the output will display the value 1.

Version 0.1 – by MARTIN Cezar


Confidential C
One point to note is that if we use the output signal without adding a unit delay, we will encounter
an algebraic loop error. This is due to the fact that by acquiring the signal from the output, the
system is stuck in a loop.

MXAM:
The MES Model examiner(MXAM) automatically checks the model using guideline checks of
MATLAB Simulink/ Stateflow compliant to ISO 26262(functional safety standard for the automotive
industry). To use this tool for our model (and use the correct guidelines/rules ) we have to right click
our model at the topmost level-> Body functions-> Start MXAM drive.

Version 0.1 – by MARTIN Cezar


Confidential C

You might also like