Can we use pulse generator as input to Embedded Matlab Function
2 views (last 30 days)
Show older comments
Hi Every one, I am trying build a stateflow chart in simulink. This stateflow has a code written in VHDL. As I am new to stateflow I am trying to convert the code in VHDL to Matlab code and use it in Matlab Embedded Function. The stateflow chart has inputs from a pulse generator. My question is can a Matlab Embedded function block have inputs from a pulse generator. If we can't can you suggest me any other options. Appreciate your time and help.
0 Comments
Accepted Answer
Arnaud Miege
on 19 Apr 2011
Yes, as far as I know, it's just a standard Simulink input. Just make sure the chart is updated with a fast enough sample time to capture the PWM switching.
HTH,
Arnaud
7 Comments
Arnaud Miege
on 26 Apr 2011
First, a comment: to make your chart more readable, I would use connective junctions so that you have a single path back to state0, see:
https://picasaweb.google.com/lh/photo/tUh3kDm_07OlIuX5EpYzLQ?feat=directlink
Second, with regards to your question about timeout. You have defined timeout, high and low as rising edge events, so the transition from state0 back onto itself will only happen when the input signal changes from 0 to 1. It it stays at 1, the transition will not occur. For what you want, I would define high, low and timeout as boolean (data) inputs from Simulink, not events. This means that they need to be enclosed in square brackets when annotating the transition, to create a valid condition (see snapshot above).
Third, you need to test your state chart to ensure it does what it's supposed to do. The only way to do that is to run the model with different inputs. You can use the Signal Builder block for that (from Simulink/Sources) or if you want more interactivity, you two constant blocks (1 and 0) and a manual switch, as I have done here (make sure to set the outputs of the constant blocks to boolean, otherwise you'll get an error):
https://picasaweb.google.com/lh/photo/y_mPmlwUcYmdiyou8Ew74Q?feat=directlink
When I did this, I found there was a design error in your chart. If timeout == 1 and high == 1, or timeout == 1 and low == 1 or all three inputs == 1, there are three valid transitions out of state0. Stateflow doesn't know which one to take. I have added an additional conditions to the two transitions to state01 ([high && !timeout]) and state02 ([low && !timeout]). I think this achieves what you want, i.e. stay in state0 while timeout == 1.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!