state flow chart properties action language
Mostra commenti meno recenti
Action Language selected as Matlab, Cnt(counter) is updating and working fine.

when, Action Language selected as C, and if else ststement is replaced with flowchart (pattern) Cnt is not updating
if Any one faced this kind of issue before please help me
Risposta accettata
Più risposte (1)
Aravind
il 13 Feb 2025
0 voti
When you incorporate a flowchart within a state in Stateflow, the if-condition flowchart is executed only when that state is first entered. This means it runs the code in the “en” section of the state, followed by the if-condition flowchart. In subsequent time steps, when the chart remains in the same state, the during section (marked as “du”) is executed instead, bypassing the if-condition flowchart. Consequently, the if condition is not re-evaluated, preventing the counter “Cnt” from updating. This issue occurs regardless of the action language, affecting both C and MATLAB.
Since if-conditions as code are not supported in Stateflow when using C as the action language, a workaround is to restructure the Stateflow chart using substates. Substates allow you to execute a flowchart within a specific state, enabling multi-level state complexity. More information on substates can be found here: https://www.mathworks.com/help/releases/R2022a/stateflow/ug/state-hierarchy.html
With substates, your counter implementation might look like this:

In this setup, “State1” is similar to what you have shared, containing the entry code for initializing variables “Cnt” and “Y.” After executing the “en” section, Stateflow proceeds to “SubState1,” where the if-condition is implemented as a flowchart. There are two transitions: a self-transition that remains within the same state until “Y” becomes true, and an exit transition that moves from “SubState1” to “State1” once “Y” is true and the counter has completed counting.
This approach can be used with C as the action language to address the issue of the “Cnt” variable not updating.
For more insights into using substates and their transition semantics, you can explore this example: https://www.mathworks.com/help/releases/R2022a/stateflow/ug/modeling-a-dc-motor-in-stateflow.html
I hope this helps resolve your question.
1 Commento
VINAY
il 13 Feb 2025
Categorie
Scopri di più su Simulink Functions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



