当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
C语言之做木桶
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
Error reporting on the first day of work (incomplete awvs unloading)
互联网API接口幂等设计
图像识别-数据清洗
Required request body is missing: (cross domain problem)
Bugkuctf-web21 (detailed problem solving ideas and steps)
zk配置中心---Config Toolkit配置与使用
How to install PHP in CentOS
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
Cmake command - Official Document
Thinkphp5 how to determine whether a table exists
Don't look for it. All the necessary plug-ins for Chrome browser are here
vs+qt 设置应用程序图标
Alibaba / popular JSON parsing open source project fastjson2
Required request body is missing:(跨域问题)
JVM instruction mnemonic
Say goodbye to 996. What are the necessary plug-ins in idea?








