当前位置:   article > 正文

《基于模型的设计-MCU篇》第5.3.2小节缺失的ert_main.c文件修改_rtw 基于模型的设计

rtw 基于模型的设计

最近在学的一本书,学到第5章直流电机控制的时候,发现少了一节内容,主要是关于main函数修改的,自己尝试修改了一下,可以正常运行。
其他部分都比较明朗,关键是trigger产生阶跃信号的处理,新手,没找到太好的办法,用了最笨的一种。。。贴出来,如果有高手能指点一下就更好了。

/*
 * File: ert_main.c
 *
 * Code generated for Simulink model 'DC_motor'.
 *
 * Model version                  : 1.5
 * Simulink Coder version         : 8.7 (R2014b) 08-Sep-2014
 * C/C++ source code generated on : Thu Jun 21 09:01:07 2018
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: 32-bit Generic
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include <stddef.h>
//#include <stdio.h>                     /* This ert_main.c example uses printf/fflush */
#include <REGX51.H>
#include "DC_motor.h"                  /* Model's header file */
#include "rtwtypes.h"


/*
 * Associating rt_OneStep with a real-time clock or interrupt service routine
 * is what makes the generated code "real-time".  The function rt_OneStep is
 * always associated with the base rate of the model.  Subrates are managed
 * by the base rate from inside the generated code.  Enabling/disabling
 * interrupts and floating point context switches are target specific.  This
 * example code indicates where these should take place relative to executing
 * the generated code step function.  Overrun behavior should be tailored to
 * your application needs.  This example simply sets an error status in the
 * real-time model and returns from rt_OneStep.
 */
void rt_OneStep(void);
void rt_OneStep(void)
{
  static boolean_T OverrunFlag = 0;

  /* Disable interrupts here */

  /* Check for overrun */
  if (OverrunFlag) {
    rtmSetErrorStatus(DC_motor_M, "Overrun");
    return;
  }

  OverrunFlag = true;

  /* Save FPU context here (if necessary) */
  /* Re-enable timer or interrupt here */
  /* Set model inputs here */
  DC_motor_U.forward=P1_1;
  DC_motor_U.backward=P1_4;
  DC_motor_U.faststop=P1_7;   



  /* Step the model */
  DC_motor_step();

  /* Get model outputs here */
  P2_0=DC_motor_Y.forward_led;
  P2_1=DC_motor_Y.backward_led;
  P2_2=DC_motor_Y.stop_led;
  P3_7=DC_motor_Y.Input1;
  P3_6=DC_motor_Y.Input2;

  /* Indicate task complete */
  OverrunFlag = false;

  /* Disable interrupts here */
  /* Restore FPU context here (if necessary) */
  /* Enable interrupts here */
}

/*
 * The example "main" function illustrates what is required by your
 * application code to initialize, execute, and terminate the generated code.
 * Attaching rt_OneStep to a real-time clock is target specific.  This example
 * illustates how you do this relative to initializing the model.
 */
int_T main()
{
  /* Unused arguments */
  //(void)(argc);
  //(void)(argv);

  /* Initialize model */
  DC_motor_initialize();
  P3_3=1;                    /*L298使能*/
  DC_motor_U.trigger=0;      /*以下三行人工产生一个阶跃信号*/
  DC_motor_step();
  DC_motor_U.trigger=1;





  while (rtmGetErrorStatus(DC_motor_M) == (NULL)) {
    /*  Perform other application tasks here */
        rt_OneStep();

  }

  /* Disable rt_OneStep() here */

  /* Terminate model */
  DC_motor_terminate();
  return 0;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号