当前位置:网站首页>2837xd code generation - Supplement (1)
2837xd code generation - Supplement (1)
2022-07-02 09:43:00 【Quikk】
2837xd Code generation —— Add (1)
1 Code generation supplement
GPIODATA Read , Need to use Memory Copy modular :
stay TI In the official manual ,GPIO Divided into A-F Six groups , The corresponding relationships of each group are as follows :
port | Pin | remarks |
---|---|---|
PortA | GPIO0 ---- GPIO31 | |
PortB | GPIO32---- GPIO63 | |
PortC | GPIO64 ---- GPIO95 | |
PortD | GPIO96 ---- GPIO127 | |
PortE | GPIO128 ---- GPIO159 | |
PortF | GPIO160 ---- GPIO168 |
Because in Simulink The official does not provide reading pins DATA Interface , There is no TI Official structure operation mode . Therefore, you can only read by accessing registers , For example, to visit GPIO23 The data of , To look at first GPIO23 Belong to PortA, So you should visit GpioDataRegs.GPADAT.all register . So use Memory Copy The module accesses the corresponding address :
For judging data, you can use Bitwise The module performs operations . For example, the following figure implements detection GPIO23 The data is 0 when , Trigger sub module .Bitwise The mask of represents which bit to check , Here's the picture , On behalf of care 23 position (GPIO23). Ruodi 23 If the bit is zero, output 0, if 1 The output 0x800000.
2 Matlab-Coder Code generation
First, write a m_functiong Code for :
Then enter Matlab Coder APP:
Then choose the one just written m Script files :
Just click Next:
Then define the input port ( data type ):
Select script for test generation MEX Files can be easily used to verify the effect of code generation :
Enter more settings :
Set to TIc2000 Series of codes :
Then generate the code :
Next, add the generated code to the project for application :
In the above code generation , You can see that there is mian file . That is matlab Given usage examples . It can be used according to the above . Enter the generated code directory , It's important here h The file contains , If you can't, join first my_func Of c Document and h file . After the compilation , Prompt to add whatever is missing .
Here are some file containment relationships , In the code I generated ,my_func.h Need header file my_func_types.h And rtwtypes.h.rtwtypes.h There are some macro definition files stored . So I can copy four files into the project in the code generation directory :
Use here CodeBlocks Verify that it can run :
The result is in line with m Code functions :
3 Simulink Function Code generation
Because computer systems are discrete control systems , Therefore, discrete modules must be used for code generation , Here is a simple example to describe :
Create the following PI Discrete model of , Input and output are replaced by ports ( In the generated code, parameters are passed in ):
Set simulation step size and solver method :
Set the hardware accordingly , There are different processors , The number of operations that may be supported is different :
Yes Code Generation Tab for related settings , Any version is installed in the system VS Unchecked Generate code only. If there is no installation, you must check :
That generation tlc The principle of the document is not well understood , Similar to scripting language , Call resources to compile . So for the time being, use the official , Write it yourself when you have the ability .
Report tab :
Comments Tabs are all related to comments , Setting can increase the readability of the program ( The default settings are used here ):
Code Placement Tab selection Compact( Compact type ):
Then after application , Exit to Simulink Interface (2019 The following version is in Interface There was a Configure Model Function Make relevant settings ),2019 The above versions separate this function ( Here is 2019 Version setting process ):
1) Get into Embeded Coder Set it up
2) Click the lower left corner to generate the editing function , Here are three function initializations 、 Step operation 、 Terminate function , Main setup step function ( The other two are set by themselves ):
3)step Function settings ( Click verify after setting , After successful verification ,Ctrl+B Generate code ):
4) In the generated code , You can see step function :
Its name , The formal parameters are all in Simulink Parameters set in . But here is only function generation , It also needs to be 0.01 It can be used once every second . Add the corresponding header file and source file into the project to call the function :
4 Quick test of the model
Simulink Workspace and Workspace Connect with each other , So when testing the model quickly , Can pass m Script to simulate . The main process is as follows :
clear;
clc;
step_size=0.01; // Simulation step setting
time=0.5; // Simulation time setting
t=[0:step_size:time]';
u(:,1)=[ones(2,1);zeros(length(t)-2,1)]; // Given array ,t by Simulink Simulation time point ,u For input
simout=sim(gcs,'SolverType','Fixed-step','Solver','ode3',...
'FixedStep',num2str(step_size),'Stoptime',num2str(time),...
'LoadExternalInput','on'); // Yes Simulik Of Configuration Parameters Set it up
stairs(simout.tout,simout.yout{
1}.Values.Data); // Draw the result graph
It can be seen that the script actually realizes , The command to open the external input function and set the step length, running time and other related parameters :
But the biggest difference between script testing and actual testing is : He will not change any settings of the model . It can also quickly give different inputs and operations and draw results .
Of course, this is just a simple application , Specifically simout Function parameters and other usages need to refer to the help document .
边栏推荐
猜你喜欢
自定义Redis连接池
Kinect DK obtains color RGB images in cv:: mat format (used in openpose)
三相并网逆变器PI控制——离网模式
Insight into cloud native | microservices and microservice architecture
c语言编程题
How to use PHP spoole to implement millisecond scheduled tasks
Solutions to Chinese garbled code in CMD window
并网逆变器PI控制(并网模式)
Share a blog (water blog)
Microservice practice | Eureka registration center and cluster construction
随机推荐
Mysql 多列IN操作
In depth analysis of how the JVM executes Hello World
Kinect DK obtains color RGB images in cv:: mat format (used in openpose)
Customize redis connection pool
个人经历&&博客现状
上班第一天的报错(Nessus安装winpcap报错)
Methods of classfile
TD conducts functional simulation with Modelsim
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
How to use pyqt5 to make a sensitive word detection tool
Bugkuctf-web21 (detailed problem solving ideas and steps)
图像识别-数据采集
2837xd Code Generation - stateflow (4)
大学生四六级作文模板(自创版,成功跨过六级)
What are the waiting methods of selenium
Chrome browser plug-in fatkun installation and introduction
web安全与防御
Web security and defense
Demand delineation executive summary