This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
您好!
我正在使用 TMS320F28379D。 基本上、我在 MATLAB/Simulink 中实现了一种算法、在 该算法中、我在仿真模型中使用了传输延迟块。 我正在尝试实现相同的算法、在该算法中、我可以为信号提供延时时间、而不是传输延迟块。 因此、我想知道我是否可以在 Code Composer Studio 中实现相同的算法、其中它与传输延迟块的工作方式相同。
请告诉我。
此致
Rachana
您好、Gautam、
感谢您花时间回复我。
我在 Simulink 模型中使用多个 TDB 块、我给出的时间延迟为(1/240;1/720;1/1200;1/1680;1/2160; 这些 TDB 块的1/2640。
如果您能够在 Code Composer Studio 中给出有关如何执行相同操作的想法、这将会非常有帮助。
此致
Rachana
您好、Elizabeth、
我无法找出问题。 我认为最好能截屏我的 Simulink 模型并要求您提供示例代码。 我已附加 Simulink 文件,输入信号被视为 y=170*cos(u)-10 *sin (u)-14*cos(3*u)-40 *sin (3*u)+1.8*cos(5*u);对于传输延迟块,我将提供1/120的延迟;1/360;1/600,初始大小为1024。
请帮我了解如何在 Code Composer Studio 中实现相同功能。 如果可能、您可以提供一个示例吗? 请查看随附的文件、并告诉我您是否需要任何信息!
谢谢、此致
Rachana
您好、Rachana、
Elizabeth 说得不错- MathWorks Embedded Coder 将为您的 Simulink 模型生成所需的 C 代码、包括传输延迟、您可以获取该 C 代码并将其导入到您的 CCS 项目中。
我们还提供了一些特定于 C2000的特殊支持->您可以在以下位置了解相关信息: https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/484814
谢谢、
-Brian
您好、Brian 和 Elizabeth、
感谢您耐心地回复我。
正如您所说、我尝试从 Simulink 生成代码、并将代码导入到 Code Composer Studio 中。 但它会弹出一些错误、我认为从 Simulink 生成的代码不合适。
我正在附加从 Simulink 生成的代码。 请看一下、让我知道这是不是我的算法适用的代码。
/*
2 * simple.c
3 *
4 *学术许可-用于教学、学术研究和会议
5 *仅在授予学位机构的课程要求。 不适用于
6 *政府、商业或其他组织用途。
7 *
8 *为"简单"模型生成代码。
9 *
10 *型号版本:1.1
11 * Simulink Coder 版本:8.12 (R2017a) 2017年2月16日
12 * C 源代码生成时间:2018年4月02日星期一13:25:52
13 *
14 *目标选择:grt.tlc
15 *注意:grt 包括用于原型设计的额外基础设施和仪器
16 *嵌入式硬件选择:英特尔->x86-64 (Windows64)
17 *代码生成目标:未指定
18 *验证结果:未运行
19 */
20.
21 #include "simple.h"
22 #include "simple_prive.h"
23
24 /*阻止信号(自动存储)*/
25 B_simple_T simple_B;
26
27 //块状态(自动存储)*/
28 DW_SIMPLE_T SIMPLE_DW;
29.
30 /*外部输出(由带自动存储的信号馈送的根输出端口)*/
31 ExtY_simple_T simple_Y;
32
33 /*实时模型*/
34 RT_MODEL SIMPLE_T SIMPLE_M_;
35 RT_MODE_SIMPLE_T *常量 simple_M =&simple_M_;
36.
37 /*
38 *延时内插例程
39 *
40 *使用以下公式执行线性插值:
41 *
42 *(t2- tMinusDelay)(tMinusDelay - t1)
43 * u (t)=--- * U1 +--- * U2
44 *(T2 - T1)(T2 - T1)
45 */
46 REAL_T RT_TDelayInterpolate (
47 Real_T tMinusDelay、/* tMinusDelay = currentSimTime - Delay *
48 REAL_T tStart、
49 Real_T * tBuf、
50 Real_T *μ Buf、
51 int_T bufSz、
52 int_T * lastIdx、
53 int_T olddestIdx、
54 int_T newIdx、
55 REAL_T initOutput、
56布尔值_T 离散、
57布尔值_T minorStepAndTastMajorOutput)
58{
59 INT_T I;
60 Real_T 弹出、T1、T2、U1、U2;
61.
62 /*
63 *如果缓冲区中只有一个数据点、则该数据点必须是
64 * t= 0和 tMinusDelay > t0时、它会询问未知的内容。 最好的
65 *假设初始输出也是如此
66 */
67 if ((newIdx =0)&&(olddestIdx =0)&&(tMinusDelay > tStart)
68返回 initOutput;
69
70 /*
71 *如果 tMinusDelay 小于零、则应输出初始值
72 */
73 IF (tMinusDelay <= tStart)
74返回 initOutput;
75
76 /*对于固定缓冲器外推:
77 *如果 tMinusDelay 小于 oldestIdx 的时间、则为离散输出
78 * tailptr 值、否则使用 tailptr 和 tailptr +1值进行推断
79 *它也适用于固定缓冲器。 注意:传输延迟块也可能发生同样的情况、其中
80 *使用 tStart 和 t[tail]、而不是使用 t[tail]和 t[tail+1]。
81 *见下文
82 */
83 if ((tMinusDelay <= tBuf[oldestIdx]){
84 if (分立式){
85返回(uBuf[olddestIdx]);
86}否则{
87 int_T tempIdx= olddestIdx + 1;
88 IF (olddestIdx =bufSz-1)
89 tempIdx = 0;
90 t1= tBuf[olddestIdx];
91 t2= tBuf[tempIdx];
92 U1= uBuf[olddestIdx];
93 U2= uBuf[tempIdx];
94 if (T2 == T1){
95 if (tMinusDelay >= T2){
96次执行= U2;
97}否则{
98弹出= U1;
99}
100}否则{
101 REAL_T F1 =(t2-tMinusDelay)/(t2-T1);
102 REAL_T f2 = 1.0 - f1;
103.
104/*
105 *使用 Lagrange 的内插公式。 T1、T2的精确输出。
106 */
107执行=f1*U1 +f2*U2;
108}
109.
110回款;
111}
112}
113
114/*
115 *当块没有直接馈通时、我们使用的表
116 *值、用于在表末尾外推较短的延迟
117 *小于0 (小于步长)。 这不完全准确。 。
118 *对于给定的时间 t、事件链如下所示。主要输出-查看
表中为119 *。 更新-向表添加条目。 现在、如果我们调用的输出为
120 *再说一次、表中有一个新条目。 对于非常短的延迟、
121 *这意味着我们将有一个与之前呼叫不同的答案
122 *同时 t 连接到输出 fcn。以下代码可防止这种情况
123 *不会发生。
124 */
125 IF (minorStepAndtLastMajorOutput){
126 /*假设新条目尚未添加到表*/中
127 if (newIdx!= 0){
128 if (* lastIdx == newIdx){
129 (* lastIdx)--;
130}
131.
132 newIdx--;
133}否则{
134如果(* lastIdx = newIdx){
135 * lastIdx = bufSz-1;
136}
137.
138 newIdx = bufSz - 1;
139}
140}
141.
142 i =* lastIdx;
143 if (tBuf[i]< tMinusDelay){
144 /*从最后一个索引开始展望*/
145 while (tBuf[i]< tMinusDelay){
146 /*如果延迟小于步长、则可能会发生-推断*/
147 if (i =newIdx)
148次休息;
149 i =( i <(bufSz-1))? (i+1):0;/*通过缓冲区移动*/
150}
151}否则{
152 /*
153 *从可能在时发生的最后一个索引开始向后看
154 *延迟时间增加。
155 */
156 while (tBuf[i]>= tMinusDelay){
157/*
158 *由于函数顶部的进入条件、我们
159 *永远不会结束
160 */
161 i =(i > 0)? I-1:(bufSz-1);/*移动到缓冲区*/
162}
163.
164 i =( i <(bufSz-1))? (i+1):0;
165}
166.
167 * lastIdx = i;
168 if (分立式){
169/*
170 * tempEps = 128 * eps;
171 * localEps = max (tempEps、tempEps*fabs (tBuf[i]))/2;
172 */
173 double tempEps =(DBL_Epsilon)* 128.0;
174 double localEps = tempEps * fabs (tBuf[i]);
175 if (tempEps > localEps){
176 localEps = tempEps;
177}
178.
179 localEps = localEps/2.0;
180 if (tMinusDelay >=(tBuf[i]- localEps)){
181弹出= uBuf[i];
182}否则{
183如果(I =0){
184支付= uBuf[bufSz-1];
185}否则{
186次执行= uBuf[I-1];
187}
188}
189}否则{
190 if (i =0){
191 t1 = tBuf[bufSz-1];
192 U1 = uBuf[bufSz-1];
193}否则{
194 T1 = tBuf[I-1];
195 U1 = uBuf[I-1];
196}
197
198 t2 = tBuf[i];
199 U2 = uBuf[i];
200 IF (T2 == T1){
201 IF (tMinusDelay >= T2){
202支付= U2;
203}否则{
204支付= U1;
205}
206}否则{
207 REAL_T F1 =(t2-tMinusDelay)/(t2-T1);
208 REAL_T f2 = 1.0 - f1;
209.
210/*
211 *使用 Lagrange 的内插公式。 T1、T2的精确输出。
212 */
213弹出= f1*U1 + f2*U2;
214}
215}
216
217个退货(支付);
218}
219.
220 /*型号步进函数*/
221 void simple_step (void)
222{
223 /*本地块 I/O 变量*/
224 REAL_T RTB_sum1;
225 REAL_T RTB_Sum2;
226 REAL_T RTB_TransportDelay2;
227 REAL_T RTB_TransportDelay1;
228 REAL_T RTB_TransportDelay;
229 REAL_T RTB_Gain9;
230
231/*传输延迟:' /运输 Delay2'*
232{
233 REAL_T **uBuffer =(REAL_T**)&simple_dw.TransportDelay2_PWORK/TubbuerPts[0];
234 REAL_T **tBuffer =(REAL_T**)&simple_Dw.TransportDelay2_PWORK/TbufferPts[1];
235 Real_T simTime = simple_M->Timing.t[0];
236 REAL_T tMinusDelay = simTime -(simple_P.TransportDelay2_delay);
237 RTB_TransportDelay2 = RT_TDelayInterpolate (
238 tMinusDelay、
239 0.0、
240 * tBuffer,
241 *缓冲区,
242 simple_dw.TransportDelay2_IWORK.CircularBufSize、
243&simple_dw.TransportDelay2_IWORK.Last、
244 simple_dw.TransportDelay2_IWORK.Tail、
245 simple_dw.TransportDelay2_IWORK.Head、
246 simple_P.TransportDelay2_InitOutput、
247 0、
248 0);
249}
250
251/*移植延迟:' /运输 Delay1'*/
252{
253 REAL_T ** uBuffer =(REAL_T**)&simple_dw.TransportDelay1_PWORK/TubbufferPts[0];
254 Real_T **tBuffer =(Real_T**)&simple_Dw.TransportDelay1_PWORK.TbufferPts[1];
255 REAL_T simTime = simple_M->Timing.t[0];
256 REAL_T tMinusDelay = simTime -(simple_P.TransportDelay1_delay);
257 RTB_TransportDelay1 = RT_TDelayInterpolate (
258个用户、
2590.0、
260 * tBuffer,
261 *缓冲区,
262 simple_dw.TransportDelay1_IWORK.CircularBufSize、
263 &simple_dw.TransportDelay1_IWORK.Last、
264 simple_dw.TransportDelay1_IWORK.Tail、
265 simple_dw.TransportDelay1_IWORK.Head、
266 simple_P.TransportDelay1_InitOutput、
267.0、
268 0);
269}
270
271/* TransportDelay:' /运输延迟'*/
272{
273 REAL_T ** uBuffer =(REAL_T**)&simple_Dw.TransportDelay_PWORK.TubbufferPts[0];
274 REAL_T **tBuffer =(REAL_T**)&simple_Dw.TransportDelay_PWORK/TbufferPts[1];
275 Real_T simTime = simple_M->Timing.t[0];
276 Real_T tMinusDelay = simTime -(simple_P.TransportDelay_delay);
277 RTB_TransportDelay = RT_TDelayInterpolate (
278 tMinusDelay、
279 0.0、
280 *tBuffer,
281 *缓冲区,
282 simple_dw.TransportDelay_IWORK.CircularBufSize、
283 &simple_dw.TransportDelay_IWORK.Last、
284 simple_dw.TransportDelay_IWORK.Tail、
285 simple_dw.TransportDelay_IWORK.Head、
286 simple_P.TransportDelay_InitOutput、
287 0、
288 0);
289}
290
291 /*增益:' /Gain9'包含:
292 *时钟:' /时钟'
293 */
294 RTB_Gain9 = simple_P.Gain9_gain * simple_M->Timing.t[0];
295.
296 /* MATLAB 函数:' /MATLAB 函数'*/
297 /* MATLAB 函数'MATLAB 函数':' :1'*/
298/*' :1:4'*/
299 simple_B.y =(((170.0 * cos (RTB_Gain9)- 10.0 * sin (RTB_Gain9))- cos (3.0 *
300 RTB_Gain9)* 14.0)- sin (3.0 * RTB_Gain9)* 40.0)+ cos (5.0 * RTB_Gain9)*
301 1.8;
302.
303 /*总和:' /sum1'*
304 RTB_sum1 = simple_B.y - RTB_TransportDelay;
305.
306 /*总和:' /Sum2'*
307 RTB_Sum2 = RTB_TransportDelay1 + RTB_Sum1;
308
309 /*输出:' /Out1'包含:
310 *总和:' /摘要5'
311 */
312 simple_Y.Out1 = RTB_TransportDelay2 + RTB_Sum2;
313.
314 /* Matfile 日志记录*/
315 RT_UpdateXYLogVars(simple_M->rtwLogInfo,(simple_M->Timing.t));
316
317 /* TransportDelay 更新:' /运输 Delay2'*
318{
319 REAL_T **uBuffer =(REAL_T**)&simple_Dw.TransportDelay2_PWORK/TubbuerPtrs[0];
320 REAL_T **tBuffer =(REAL_T**)&simple_dw.TransportDelay2_PWORK.TbufferPts[1];
321 Real_T simTime = simple_M->Timing.t[0];
322 simple_dw.TransportDelay2_IWORK.Head =
323 (((simple_dw.TransportDelay2_IWORK.Head <
324 (simple_dw.TransportDelay2_IWORK.CircularBufSize-1))?
325 (simple_dw.TransportDelay2_IWORK.Head+1):0);
326 IF (simple_dw.TransportDelay2_IWORK.Head =
327 simple_dw.TransportDelay2_IWORK.Tail){
328 simple_dw.TransportDelay2_IWORK.Tail =
329 (((simple_dw.TransportDelay2_IWORK.Tail <
330 (simple_dw.TransportDelay2_IWORK.CircularBufSize-1))?
331 (simple_dw.TransportDelay2_IWORK.Tail+1):0);
332}
333.
334 (* tBuffer)[simple_dw.TransportDelay2_IWORK.Head]= simTime;
335 (* uBuffer)[simple_dw.TransportDelay2_IWORK.Head]= RTB_Sum2;
336}
337.
338 /* TransportDelay 更新:' /运输 Delay1'*/
339{
340 REAL_T **uBuffer =(REAL_T**)&simple_dw.TransportDelay1_PWORK/TubbufferPts[0];
341 REAL_T **tBuffer =(REAL_T**)&simple_dw.TransportDelay1_PWORK/TbufferPts[1];
342 Real_T simTime = simple_M->Timing.t[0];
343 simple_dw.TransportDelay1_IWORK.Head =
344 (((simple_dw.TransportDelay1_IWORK.Head <
345 (simple_dw.TransportDelay1_IWORK.CircularBufSize-1))?
346 (simple_dw.TransportDelay1_IWORK.Head+1):0);
347 IF (simple_dw.TransportDelay1_IWORK.Head =
348 simple_dw.TransportDelay1_IWORK.Tail){
349 simple_dw.TransportDelay1_IWORK.Tail =
350 (((simple_dw.TransportDelay1_IWORK.Tail <
351 (simple_dw.TransportDelay1_IWORK.CircularBufSize-1))?
352 (simple_dw.TransportDelay1_IWORK.Tail+1):0);
353}
354.
355 (* tBuffer)[simple_dw.TransportDelay1_IWORK.Head]= simTime;
356 (* uBuffer)[simple_dw.TransportDelay1_IWORK.Head]= RTB_sum1;
357}
358.
359/* TransportDelay 更新:' /运输延迟'*/
360{
361 REAL_T **uBuffer =(REAL_T**)&simple_Dw.TransportDelay_PWORK/TubbuerPts[0];
362 REAL_T **tBuffer =(REAL_T**)&simple_dw.TransportDelay_PWORK/TbufferPts[1];
363 Real_T simTime = simple_M->Timing.t[0];
364 simple_dw.TransportDelay_IWORK.Head =(simple_Dw.TransportDelay_IWORK.Head <
365 (simple_dw.TransportDelay_IWORK.CircularBufSize-1))?
366 (simple_dw.TransportDelay_IWORK.Head+1):0);
367 IF (simple_dw.TransportDelay_IWORK.Head =
368 simple_dw.TransportDelay_IWORK.Tail){
369 simple_dw.TransportDelay_IWORK.Tail =
370 (((simple_dw.TransportDelay_IWORK.Tail <
371 (simple_dw.TransportDelay_IWORK.CircularBufSize-1))?
372 (simple_dw.TransportDelay_IWORK.Tail+1):0);
373}
374.
375 (* tBuffer)[simple_Dw.TransportDelay_IWORK.Head]= simTime;
376 (* uBuffer)[simple_dw.TransportDelay_IWORK.Head]= simple_B.y;
377}
378.
379 /*信号 main 停止模拟*/
380{/*采样时间:[0、0 ]*/
381 if ((rtmGetTFinal (simple_M)!=-1)&&
382!((rtmGetTFinal (simple_M)-simple_M->Timing.t[0])> simple_M->Timing.t[0]
383 *(DBL_Epsilon)){
384 rtmSetErrorStatus (simple_M、"Simulation Finished");
385}
386}
387.
388 /*更新基本速率的绝对时间*/
389 /*"clockTick0"计算此任务代码的次数
390 *已执行。 绝对时间是"clockTick0"的乘法
391 *和"Timing.StepSize0"。 "clockTick0"的大小可确保计时器不会
392 *在选定的应用程序生命周期内溢出。
393 *此任务的计时器由两个32位无符号整数组成。
394 *这两个整数代表低位 Timing.clockTick0和高位
395 * Timing.clockTickH0。 当低位溢出到0时、高位递增。
396 */
397 if (!(++simple_M->Timing.clockTick0)){
398 ++simple_M->Timing.clockTickH0;
399}
400
401 simple_M->Timing.t[0]= simple_M->Timing.clockTick0 *
402 simple_M->Timing.StepSize0 + simple_M->Timing.clockTickH0 *
403 simple_m->Timing.StepSize0 * 4294967296.0;
404}
405.
406 //模型初始化函数*/
407 void simple_initialize (void)
408{
409 /*注册码*/
410
411 /*初始化非 finites */
412 RT_InitInfAndNaN (sizeof (REAL_T));
413
414 /*初始化实时模型*/
415 (void) memset (((void *) simple_M、0、
416 sizeof (rt_model_simple_T);
417
418{
419 //设置解算器对象*/
420 rtsiSetSimTimeStepPtr (&simple_M->solverInfo、&simple_M->Timing.simTimeStep);
421 rtsiSetTPtr (&simple_M->solverInfo、&rtmGetTPtr (simple_M));
422 rtsiSetStepSizePtr (&simple_M->solverInfo、&simple_M->Timing.StepSize0);
423 rtsiSetErrorStatusPtr (&simple_M->solverInfo (&rtmGetErrorStatus (simple_M)));
424 rtsiSetRTModelPtr (&simple_M->solverInfo、simple_M);
425}
426
427 rtsiSetSimTimeStep (&simple_M->solverInfo、main_time_step);
428 rtsiSetSolverName (&simple_M->solverInfo、"FixedStepDiscrete);
429 rtmSetTPtr (simple_M、&simple_M->Timing.tArray[0]);
430 rtmSetTFinal (simple_M、10.0);
431 simple_M->Timing.StepSize0 = 0.2;
432
433 /*数据记录设置*/
434{
435静态 RTWLogInfo RT_DataLoggingInfo;
436 RT_DataLoggingInfo.logingInterval =空;
437 simple_M->rtwLogInfo =&RT_DataLoggingInfo;
438}
439.
440 //数据记录设置*/
441{
442 rtliSetLogXSignalInfo (simple_M->rtwLogInfo,(NULL));
443 rtliSetLogXSignalPtrs (simple_M->rtwLogInfo (NULL));
444 rtliSetLogT (simple_M->rtwLogInfo、"TOUT");
445 rtliSetLogX (simple_M->rtwLogInfo、"");
446 rtliSetLogXFinal (simple_M->rtwLogInfo、"");
447 rtliSetLogVarNameModifier (simple_M->rtwLogInfo、"RT_");
448 rtliSetLogFormat (simple_M->rtwLogInfo,4);
449 rtliSetLogMaxRows (simple_M->rtwLogInfo、0);
450 rtliSetLogDecimation (simple_M->rtwLogInfo,1);
451 rtliSetLogY (simple_M->rtwLogInfo、"");
452 rtliSetLogYSignalInfo (simple_M->rtwLogInfo (NULL));
453 rtliSetLogYSignalPts (simple_M->rtwLogInfo (NULL));
454}
455
456 /*块 I/O */
457 (void) memset (((void *)&simple_B)、0、
458 sizeof (B_simple_T));
459.
460 /*状态(dwork)*/
461 (void) memset ((void *)&simple_DW、0、
462 sizeof (DW_SIMPLE_T));
463)
464/*外部输出*/
465 simple_Y.Out1 = 0.0;
466
467 /* Matfile 日志记录*/
468 RT_StartDataLoggingWithStartTime (simple_M->rtwLogInfo、0.0、rtmGetTFinal
469 (simple_M)、simple_M->Timing.StepSize0 (&rtmGetErrorStatus (simple_M)));
470
471 /*开始传输延迟:' /运输 Delay2'*
472{
473 REAL_T *缓冲区=&simple_dw.TransportDelay2_RWORK.TuperArea[0];
474 simple_dw.TransportDelay2_IWORK.Tail = 0;
475 simple_dw.TransportDelay2_IWORK.Head = 0;
476 simple_dw.TransportDelay2_IWORK.Last = 0;
477 simple_dw.TransportDelay2_IWORK.CircularBufSize = 1024;
478 pbuffer[0]= simple_P.TransportDelay2_InitOutput;
479pbuffer[1024]= simple_M->Timing.t[0];
480 simple_dw.TransportDelay2_PWORK.TupbufferPts[0]=(void *)&pbuffer[0];
481 simple_dw.TransportDelay2_PWORK.TupbufferPtr[1]=(void *)&pbuffer[1024];
482}
483
484 /*开始传输延迟:' /运输 Delay1'*/
485{
486 Real_T *pbuffer =&simple_dw.TransportDelay1_RWORK.TupbufferArea[0];
487 simple_dw.TransportDelay1_IWORK.Tail = 0;
488 simple_dw.TransportDelay1_IWORK.Head = 0;
489 simple_dw.TransportDelay1_IWORK.Last = 0;
490 simple_dw.TransportDelay1_IWORK.CircularBufSize = 1024;
491 pbuffer[0]= simple_P.TransportDelay1_InitOutput;
492pbuffer[1024]= simple_M->Timing.t[0];
493 simple_dw.TransportDelay1_PWORK.TupbufferPts[0]=(void *)&pbuffer[0];
494 simple_dw.TransportDelay1_PWORK.TupbufferPts[1]=(void *)&pbuffer[1024];
495}
496.
497 /*开始传输延迟:' /运输延迟'*/
498{
499 REAL_T *缓冲区=&simple_dw.TransportDelay_RWORK.TuperArea[0];
500 simple_dw.TransportDelay_IWORK.Tail = 0;
501 simple_dw.TransportDelay_IWORK.Head = 0;
502 simple_dw.TransportDelay_IWORK.Last = 0;
503 simple_dw.TransportDelay_IWORK.CircularBufSize = 1024;
504 pbuffer[0]= simple_P.TransportDelay_InitOutput;
505 pbuffer[1024]= simple_M->Timing.t[0];
506 simple_dw.TransportDelay_PWORK.TupbufferPts[0]=(void *)&pbuffer[0];
507 simple_dw.TransportDelay_PWORK/TupbufferPts[1]=(void *)&pbuffer[1024];
508}
509}
510
511 /*型号终止功能*/
512 void simple_terminate (void)
513{
514 /*(无需终止代码)*/
515}
Rachana、
我不在 技术支持部门、因此我无法浏览您的代码。 如果 需要、您可以联系 MathWorks 技术支持以获得更详细的帮助。
问题:您使用的是 MathWorks C2000支持包、还是仅使用 Embedded Coder 的正常 C 代码?
--
如果您使用 的是 C2000支持包, 它将创建一个 CCS 项目文件 ,您可以使用它来调试 CCS 内部的代码。
我的项目文件夹位置是:... model-name_ERT_RTW\ccs_Project。 以下是几周前我运行的 F28377S 模型的示例:
--
谢谢、
-Brian
您好 Brian、
我能够使用 C2000支持包解决我的问题。
/*
*学术许可-用于教学、学术研究和会议
*仅在授予学位机构的课程要求。 不适用于
*政府、商业或其他组织用途。
*
*文件:ERT_main.c
*
*为 Simulink 模型'pllex'生成的代码。
*
*型号版本:1.41
* Simulink Coder 版本:8.14 (R2018a) 2018年2月6日
*在2018年4月10日16:33:12日星期二生成的 C/C++源代码
*
*目标选择:ERT.tlc
*嵌入式硬件选择:Texas Instruments->C2000
*代码生成目标:
* 1. 执行效率
* 2. RAM 效率
*验证结果:未运行
*
#include "pllex.h"
#include "rtwtypes.h"
volatile int IsrOverf溢= 0;
Boolean _T isRateRunning[2]={0、0};
BOOLEOLED_T INTEC2runFlags[2]={0、0};
void RT_OneStep (void)
{
布尔_T 事件标志[2];
/*检查超限的基本速率*/
if (isRateRunning[0]++){
IsrOverf溢= 1;
isRateRunning[0]-;/*允许将来的迭代成功*/
返回;
}
/*
*对于裸板目标(即、无操作系统)、速率
*执行此基本步骤的本地缓冲以允许
*重叠占先。 生成的代码包括函数
* writeCodeInfoFcn(),用于设置速率
*需要运行此时间步骤的代码。 返回值为1和0
*分别为 true 和 false。
*
pllex_SetEventsForThisBaseStep (eventFlags);
enableTimer0Interrupt();
pllex_Step0();
/*在此处获取模型输出*/
disableTimer0Interrupt();
isRateRunning[0]-;
if (eventFlag[1]){
if (need2runFlags[1]++){
IsrOverf溢= 1;
need2runFlags[1]-;/*允许将来的迭代成功*/
返回;
}
}
if (need2runFlags[1]){
if (isRateRunning[1]){
/*提高优先级*/
返回;
}
isRateRunning[1]++;
enableTimer0Interrupt();
/*步进子速率"1"的模型*/
开关(1)
{
案例1:
pllex_step1();
/*在此处获取模型输出*/
中断;
默认值:
中断;
}
disableTimer0Interrupt();
need2runFlags[1]-;
isRateRunning[1]-;
}
}
volatile boole_T stopored Requested = false;
int main (空)
{
volatile boole_T runModel = true;
浮点 modelBaseRate = 1.0E-6;
浮点系统时钟= 200;
c2000_flash_init ();
init_board();
#ifdef MW_EXEC_Profiler_ON
CONFIG_profilerTimer();
#endif
;
rtmSetErrorStatus (RTM、0);
pllex_initialize();
configureTimer0 (modelBaseRate、systemClock);
runModel =
rtmGetErrorStatus (RTM)=(空);
enableTimer0Interrupt();
globalInterruptEnable();
while (runModel){
已停止请求=!(
rtmGetErrorStatus (RTM)=(NULL));
runModel =!(已停止请求);
}
/*在此禁用 RT_OneStep()*/
globalInterruptDisable();
返回0;
}
您好、Rachana、
我真的无法查看您的代码(我不在技术支持部门)。 通常、您需要的代码将位于其中 .c 和 .. 大多数客户都有一个现有的 CCS 项目、其中包含他们的算法/控制代码(例如 .c)。 您可以剪切和粘贴的内核 将.c 转换为 C. 我无法告诉您如何准确地执行此操作、因为它取决于您的软件架构和 C. 我们提供了一个基本项目、您可以根据我之前提供的文档链接导入和使用该项目。
如果您仍然卡滞、请联系 MathWorks 技术支持以获取帮助。
谢谢、
-Brian
您好 Brian、
我要附加主代码( .c)。 请看一下、让我知道我在哪里放置看门狗变量并检查输出。
*
*学术许可-用于教学、学术研究和会议
*仅在授予学位机构的课程要求。 不适用于
*政府、商业或其他组织用途。
*
*文件:pllex.c
*
*为 Simulink 模型'pllex'生成的代码。
*
*型号版本:1.43
* Simulink Coder 版本:8.14 (R2018a) 2018年2月6日
*生成的 C/C++源代码:2018年4月11日星期三12:04:34
*
*目标选择:ERT.tlc
*嵌入式硬件选择:Texas Instruments->C2000
*代码生成目标:
* 1. 执行效率
* 2. RAM 效率
*验证结果:未运行
*
#include "pllex.h"
#ifndef UCHAR_MAX
#include
#endif
#if (UCHAR_MAX!=(0xFFFFFFU))||(SCHA_MAX!=(0x7FFF))
为具有不同大小的 uchar/char 的编译器生成了#ERROR 代码。 \
考虑调整\上的测试硬件字大小设置
硬件实现窗格、以匹配您的编译器字大小为\
在编译器的 limits.h 中定义。 或者、您也可以\
选择 Test hardware is the same as production hardware 选项和\
选择代码生成>>\上的启用可移植字大小选项
基于 ERT 的目标的验证窗格、将禁用\
预处理器字大小检查。
#endif
#if (USHRT_MAX!=(0xFFFFU))||(lcl_dwnld_shrt_dsc> MAX!=(0x7FFF))
为具有不同大小的 ushort/short 的编译器生成了#ERROR 代码。 \
考虑调整\上的测试硬件字大小设置
硬件实现窗格、以匹配您的编译器字大小为\
在编译器的 limits.h 中定义。 或者、您也可以\
选择 Test hardware is the same as production hardware 选项和\
选择代码生成>>\上的启用可移植字大小选项
基于 ERT 的目标的验证窗格、将禁用\
预处理器字大小检查。
#endif
#if (UINT_MAX!=(0xFFFFFFU))||(INT_MAX!=(0x7FFF))
为具有不同大小 uint/int 的编译器生成了#ERROR 代码。 \
考虑调整\上的测试硬件字大小设置
硬件实现窗格、以匹配您的编译器字大小为\
在编译器的 limits.h 中定义。 或者、您也可以\
选择 Test hardware is the same as production hardware 选项和\
选择代码生成>>\上的启用可移植字大小选项
基于 ERT 的目标的验证窗格、将禁用\
预处理器字大小检查。
#endif
#if (Ulong_MAX!=(0xFFFFFFFFUL))||(Long_MAX!=(0x7FFFFFFFL))
为具有不同大小 ulong/long 的编译器生成了#ERROR 代码。 \
考虑调整\上的测试硬件字大小设置
硬件实现窗格、以匹配您的编译器字大小为\
在编译器的 limits.h 中定义。 或者、您也可以\
选择 Test hardware is the same as production hardware 选项和\
选择代码生成>>\上的启用可移植字大小选项
基于 ERT 的目标的验证窗格、将禁用\
预处理器字大小检查。
#endif
/*跳过 ulong_long/long_long 检查:预处理器整数范围不足。 *
void InitAdcA (void);
void CONFIG_ADCA_SOC0 (void);
/*阻止信号和状态(默认存储)*/
DW rtDW;
/*实时模型*/
rt_model RTM_;
rt_model * const RTM =&RTM_;
静态 void rate _monotonic_scheduler (void);
静态 uint16_T adcAInitFlag = 0;
/*
*设置运行此基本步骤所需的子速率(基本速率始终运行)。
*必须在调用模型步骤函数之前调用此函数
*为了"记住"运行此基本步骤所需的速率。 。
*事件缓冲允许重叠抢占。
*
void pllex_SetEventsForThisBaseStep (布尔值_T *事件标志)
{
/*任务在计数器为零时运行、通过 rtmStepTask 宏计算*/
eventFlag[1]=((boole_T) rtmStepTask (RTM、1));
}
/*
*此函数更新每个子速率的活动任务标志
*和为交换数据的任务的转换标志。
*该函数假定速率单调多任务调度程序。
*必须以模型基准速率调用该函数、以便这样做
*生成的代码会自行管理其所有子速率和速率
*转换标志。
*
静态空比率_monotonic_scheduler (空)
{
/*计算在下一个基准时步骤中运行的子速率。 子酸盐
*是基速率计数器的整数倍。 因此、子任务
*计数器在达到其限值时复位(零表示运行)。
*
(RTM->Timing.taskCounter.TID[1])++;
如果((RTM->Timing.taskCounter.TID[1])> 82){/*采样时间:[8.3E-5s、0.0S]*/
RTM->Timing.taskCounter.tID[1]= 0;
}
}
TID0的/*模型步进函数*/
void pllex_Step0 (void)/*采样时间:[1.0E-6s、0.0S]*/
{
{/*采样时间:[1.0E-6s、0.0S]*/
RATE_MONotonic_scheduler();
}
}
TID1的/*模型步进函数*/
void pllex_Step1 (void)/*采样时间:[8.3E-5s、0.0S]*/
{
/* S-function (c2802xadc):' /adc '*/
{
/*内部基准电压:0至3.3V 的固定刻度范围。 *
/*外部基准电压:VREFHI (ADCINA0)= 3.3和 VREFLO (接地)= 0 */的允许范围
AdcaRegs.ADCSOCFRC1.bit.SOC0 = 1;
//等待采样窗口的周期和 EOC 结果在触发后被锁存*/
asm (" RPT #75 || NOP");
rtDw.adc =(AdcaResultRegs.ADCRESULT0);
}
}
/*型号初始化函数*/
void pllex_initialize (void)
{
/*注册码*/
/*初始化实时模型*/
(void) memset ((void *) RTM、0、
sizeof (rt_model));
/*状态(dwork)*/
(void) memset ((void *)&rtDW、0、
sizeof (DW));
/* S 函数开始(c2802xadc):' /adc '*/
if (adcAInitFlag = 0){
InitAdcA();
adcAInitFlag = 1;
}
CONFIG_ADCA_SOC0 ();
}
/*
*生成的代码的文件尾部。
*
*[EOF]
*
提前感谢!!
此致
Rachana Dasari
我无法查看您的代码。 请联系 MathWorks 技术支持以获得直接帮助。
-b.