matlabsimulinkstateflow

Simulink/StateFlow error with my Clock


I created this state machine chart in Simulink using the StateFlow :

There are two states (S1,S2), one of which (S1) has 3 nested parallel FSM , each one has 4 states (SS1, SS2, SS2, SS4) , I put a default state in all of the 3 FSMs (SS1), and in the main two states (default S2).

To test the main FSM (S1,S2) , I used signal builder for all my inputs/events. One of the inputs is a square wave which is a clock event for my main FSM (1 Hz) and the duration of the simulation is 50 sec.

The problem i have is that i can see in the signal builder that i have a square wave, however when i put scope to that clock i see one square wave (extending from 0 to 49.5 second then drops to 0) .

enter image description here

Where is my clock ? what isn't it feeding my FSM properly ?

Here is the FSM:

enter image description here

The orthogonal sub-states are :

enter image description here

in details:

enter image description here

in in between S1 and S2

enter image description here

One of the signal builder , which has the Clock signal is:

enter image description here

The other has the following signals:

enter image description here


Solution

  • The problem is that you are using the default step size with ode3. When using a fixed-step solver the auto step size is calculated as (StopTime-StartTime)/50. In your case this gives a step size of 1.

    Since at t = 0,1,2,3,...49 the Clock has a value of 2, that's what you see in the scope. At t =50 the Clock has a value of 0, and that's what you're seeing in the scope.

    You need to go to the Solver Panel of the Simulaton->Model Configuration Parameters pull-down menu. Then open up the Additional Options option and change the step size to something smaller, such as 0.01.

    Alternatively (depending on your other requirements) you could use a variable step solver.