当前位置:网站首页>2837xd code generation - stateflow (1)
2837xd code generation - stateflow (1)
2022-07-02 09:43:00 【Quikk】
2837xd Code generation ——StateFlow(1)
stay Command Window Type in sf Can enter the , It can also be done through Simulink In the library StateFlow Sub library entry .
StateFlow Finite state machine , Reuse matlab when , May feel : A simple if Statements or ++ The operation needs to be built too complex . But the introduction of state machine can greatly reduce this situation .
Entering the library function module, you can see that these three components are all state machine modules , Learn one by one : First look at Chart modular .

1 Chart modular
Create a new Chart modular , After opening , Right click to enter Properties Set it up .

On the left side of the interface are some Chart Components used in :

among , There is only mutual exclusion between each module ( Only one can execute ) And parallelism . There will be an execution order identifier in the upper right corner under the parallel relationship .

Which is divided into different levels by modules , The content under the same module is a level , If you need to set parallel and mutually exclusive relationships . Right click the blank space of the level to be set and select Decomposition Choose parallel and mutually exclusive relationships .

State Modules have some keywords that can be used to define the actions to be performed after entering these modules :


Using the above knowledge, we can build a simple model , Take a look at the concept of flow chart .

First, build a simple model as shown in the above figure ,s Is the condition ,light It's the result of action . This is a process that simulates the switching of lights , turn on the light (s=1) Obviously, we need to give ,light The program needs to run to produce relevant results . Now enter Model Explorer The relevant settings are made in .


And then in Simulink Add relevant external modules , Give and display input and output .

The simulation results are as follows . change s Value , Can be changed accordingly light Value .

Transform the above process , Join the event .Open_switch(Close_Switch),b And in Model Exporer Defined in . Here, pay attention to the defined input port and demux The input should be consistent .

Then build a circuit ,Input3 It is used to activate the module . You can know at this time , It's not just about s=1, And need the rising edge (Open_switch The rising edge of the trigger of the event setting ) To trigger light=1. Similar to the rising edge in digital electricity, the corresponding signal can be locked .

In order to better write the process ,StateFlow The concept of connection node is introduced . Click on Parretn The following structures can be set .

You can also add conditions for your connection , When the mouse is placed on the line between the two connection points, the following marks will automatically appear , By default, when one node has multiple branches , Will give priority to the conditional branch .:

Pictured , Set up the following branches , Equate to C Code :
if (x<0)
y=abs(x);
else
y=x;

stay Model Explorer Set relevant... In data Properties of , Given inputs and outputs . The given input here is 1Hz The sine wave of .


Now combine the state of the first switch lamp , If there are two states in the light on state (A、B) Represents different brightness . Then if we set the brightness for the first time , I certainly don't want to adjust the brightness again next time I turn on the light . Therefore, historical nodes are introduced here , That is, you can remember the last exit state , Even though A It's the default state . But the state at this time is determined by the state of the last exit :

2 Model instance construction
2.1 Car status judgment
Build the following logic circuit for judging the car state , Be able to define the events generated above , Run , It can simulate gear shifting and start stop status monitoring :

After the completion of construction , You can click run directly , At this time, because there is no definition of related data and event An automatically defined interface will pop up , Make relevant modifications above to quickly add :

Build peripheral circuits , Set the device runtime triggered by related events , Change the simulation duration to inf( Infinite length ), You can operate and observe experimental phenomena :

2.2 Media playback status detection
The media playing status can be observed through the flow chart , This example introduces historical nodes and state detection , Build as shown in the following figure chart, You can see in the power_on Some of the state transition flow charts in have no trigger conditions ( That means anything can trigger ). for example , If now in USB state , If sent Open_CD(Open_Radio) After that, state transition can be triggered .

Right click on the status to enter the attribute (Properties), Modify the status output , Then you can observe the status at the output port ( Boolean variable output , by 1 It means in secondary state ).

The history node is added , Represents the next entry power_on When the module , It will directly enter the state of the last exit .
Build the external circuit as shown in the figure below :

2.3 2837xd Running water lamp online debugging
First, build the following chart, here led1 and led2 It's all output . Direct connection GPIO Interface .

The picture below is led1 and led2 Output waveform of , Identified in the figure 1.2.3.4 Corresponding to the execution process in the above figure . That's the cycle 3 After that , Out of the loop , Then go out and wait , Enter the next cycle . Here the test found , It will last one step in the state , Act at the node (3、4) It will take another step .[ The step size is set to 0.5s], Setting of relevant parameters , Please refer to the previous blog article .

Program peripheral circuit diagram :

This is a debugging skill , The following figure SIMULATION and HARDWARE There is one in each RUN,SIMULINK Medium RUN Hardware can be disconnected , Run the software running results directly , That is, it can also be easily debugged chart Output module .HARDWARE Medium RUN Is to generate DSP Code burning into DSP And then run .

边栏推荐
- 攻防世界-Web进阶区-unserialize3
- 2837xd 代码生成——补充(3)
- Customize redis connection pool
- 分布式锁的这三种实现方式,如何在效率和正确性之间选择?
- Amq6126 problem solving ideas
- 三相并网逆变器PI控制——离网模式
- What are the waiting methods of selenium
- College Students' CET-4 and CET-6 composition template (self created version, successfully crossed CET-6)
- Methods of classfile
- Bugkuctf-web24 (problem solving ideas and steps)
猜你喜欢

Required request body is missing:(跨域问题)

JDBC review

TD conducts functional simulation with Modelsim

vs+qt 设置应用程序图标

Activity的创建和跳转

并网逆变器PI控制(并网模式)

Bugkuctf-web21 (detailed problem solving ideas and steps)

Share a blog (water blog)

Bold prediction: it will become the core player of 5g

Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
随机推荐
C语言之到底是不是太胖了
因上努力,果上随缘
Matplotlib swordsman - a stylist who can draw without tools and code
Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
Bugkuctf-web16 (backup is a good habit)
Idempotent design of Internet API interface
BugkuCTF-web16(备份是个好习惯)
MySQL multi column in operation
自定义Redis连接池
ZK configuration center -- configuration and use of config Toolkit
Break the cocoon | one article explains what is the real cloud primordial
Image recognition - Data Acquisition
Don't look for it. All the necessary plug-ins for Chrome browser are here
定时线程池实现请求合并
并网逆变器PI控制(并网模式)
JVM instruction mnemonic
C语言之判断直角三角形
VIM操作命令大全
BugkuCTF-web21(详细解题思路及步骤)