当前位置:网站首页>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 .

边栏推荐
- Discussion on improving development quality and reducing test bug rate
- kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
- Record personal understanding and experience of game console configuration
- Idempotent design of Internet API interface
- cmake的命令-官方文档
- QT signal slot summary -connect function incorrect usage
- Share a blog (water blog)
- Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
- Learn combinelatest through a practical example
- C语言之分草莓
猜你喜欢

How to use pyqt5 to make a sensitive word detection tool

Vs+qt set application icon

图像识别-数据增广

Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue

自定义Redis连接池

Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)

Image recognition - data augmentation

Enterprise level SaaS CRM implementation

Required request body is missing: (cross domain problem)

MySQL事务
随机推荐
What is the function of laravel facade
BugkuCTF-web16(备份是个好习惯)
Tinyxml2 reading and modifying files
Mysql默认事务隔离级别及行锁
JDBC review
TD conducts functional simulation with Modelsim
Methods of classfile
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
The road is blocked and long, and the line is coming
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
Bugkuctf-web21 (detailed problem solving ideas and steps)
College Students' CET-4 and CET-6 composition template (self created version, successfully crossed CET-6)
Off grid control of three-phase inverter - PR control
2837xd Code Generation - stateflow (4)
Inverter Simulink model -- processor in the loop test (PIL)
三相逆变器离网控制——PR控制
Matplotlib swordsman - a stylist who can draw without tools and code
Operation and application of stack and queue
Bold prediction: it will become the core player of 5g
Record the interesting process of using Xray for the first time