Clear Filters
Clear Filters

How to set Unconditional Transition State for Else Statement in HDL Coder with a Counter?

3 views (last 30 days)
Hi,
in the HDL Coder Guideline, it is recommended to insert an unconditional Else transition: "Insert Unconditional Transition State for Else Statement in HDL Code"
How to do this, if the after(..., tick) transition is used?
Consider the following modification to the example: the transition between the 2 states shall happen every 2 clock cycles.
With the unconditional "else" transition, the transition will never happen, because the timer (which evaluates the "after(2,tick)" event) is always reset to 0 by the unconditional "else" transition → counter value of 2 is never reached. So the unconditional transition breaks the whole functionality.
I do not see any solution how to follow the guideline with after(n,E) events used: https://de.mathworks.com/help/stateflow/ref/after.html.
The only workaround would be to re-invent the wheel and implement a custom counter in the stateflow, and use "if(counter == 2)" instead of the after(n,E) event - which is obviously a bad workaround.
In my opinion, an transition type that does not reset the counters for the after(n,E) events is missing for stateflow.
What do you think about this, or am I missing something?

Accepted Answer

Tom Richter
Tom Richter on 3 Apr 2024
Hello Michael,
This is a good catch. Have you tried to use the “after” temporal logic operator on a smaller design? Did the Synthesis tool do some strange things or added latches? The guideline says you should have an unconditional transition to prevent having latches later. If this is not the case, I would just say the after operator is fine and can be justified. If you see latches then yes, the workaround you mentioned is a possible solution. Instead of a conditional transition you would switch to an “about to switch” state where you count up to N-1 (in your case it would just be an empty state).
If you think MathWorks should offer a better solution I suggest contacting Technical Support to help you with this issue/question. If you go to
, you can submit a support request and add example or reproduction files. The page also displays phone contact information based on your location.
Best regards,
Tom
  1 Comment
Michael Felger
Michael Felger on 4 Apr 2024
Edited: Michael Felger on 4 Apr 2024
Hello Tom,
thanks for your answer!
I did not have any propblems with latches yet, so for the moment I'm fine for my designs.
I just wanted to follow the guideline, but then found that for the after(n,E) events the default transition is breaking the stateflow logic...... and wanted to know if I'm missing something.
Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!