Can we use pulse generator as input to Embedded Matlab Function
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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.
Accepted Answer
Arnaud Miege
on 19 Apr 2011
1 vote
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
vishnu p
on 20 Apr 2011
Thank you Mr. Arnaud. Is it ok if I send you my state flow chart to verify if I am going in the correct approach.
Arnaud Miege
on 20 Apr 2011
Yes, or even better, upload it to a filesharing site so that it's available to other members of the community.
vishnu p
on 20 Apr 2011
Hi Mr. Arnaud. I uploaded it in mega upload. The download link is
http://www.megaupload.com/?d=5I5DYSR7. Can you please verify it and tell me if I am doing the right approach or should I take a different one. I am also confused how to use the delay in the state flow. Appreciate your time and suggestions.
Arnaud Miege
on 21 Apr 2011
Well, your state chart is such a mess that it's unreadable... I had to recreate it based on the word document you supplied. You can see a snapshot at:
https://picasaweb.google.com/lh/photo/zMvjoLinf3b8xGCz20EM2g?feat=directlink
I'd make the following suggestions:
- Use entry rather than exit to set the outputs
- Use ; rather than ,
I don't know VHDL but you can use the after construct for delays:
http://www.mathworks.com/help/releases/R2011a/toolbox/stateflow/ug/f0-34084.html
vishnu p
on 21 Apr 2011
Thank you very much Mr. Arnaud. I will build a new state chart as per your suggestions and see if it works with my circuit. I will let you know about the result.
vishnu p
on 21 Apr 2011
Hi Mr. Arnaud,
I have completed the new state chart with the necessary modifications. The only question for me is how to use the timeout. If 'timeout=1', the inputs should not leave state0. If you have any suggestions please let me know. I have uploaded the state chart in mega upload. The download link is http://www.megaupload.com/?d=D3HL4F7Z . Please have a look at my state chart. Thank you very much for your help and guiding me through the right path.
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)
Categories
Find more on Stateflow in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)