当前位置:网站首页>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 .
边栏推荐
- Save video opencv:: videowriter
- 每天睡觉前30分钟阅读_day3_Files
- Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
- Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
- Mysql默认事务隔离级别及行锁
- What is the function of laravel facade
- idea查看字节码配置
- 上班第一天的报错(Nessus安装winpcap报错)
- YOLO物体识别,生成数据用到的工具
- Alibaba /热门json解析开源项目 fastjson2
猜你喜欢
Web security and defense
Typora installation package sharing
Save video opencv:: videowriter
攻防世界-Web进阶区-unserialize3
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
Image recognition - data annotation
Tools used for Yolo object recognition and data generation
MySQL multi column in operation
C language programming problems
随机推荐
Matplotlib swordsman line - first acquaintance with Matplotlib
zk配置中心---Config Toolkit配置与使用
Bugkuctf-web16 (backup is a good habit)
Don't look for it. All the necessary plug-ins for Chrome browser are here
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
Thinkphp5 how to determine whether a table exists
Image recognition - data annotation
Solutions to Chinese garbled code in CMD window
在SQL注入中,为什么union联合查询,id必须等于0
ClassFile - Attributes - Code
Error reporting on the first day of work (error reporting when Nessus installs WinPcap)
Memories of a chat
C语言之数据插入
Chrome video download Plug-in – video downloader for Chrome
What is the function of laravel facade
TD联合Modelsim进行功能仿真
Fragmenttabhost implements the interface of housing loan calculator
Learn combinelatest through a practical example
Int to string, int to qstring
C语言之判断直角三角形