AngleObserver_discrete.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * File: AngleObserver_discrete.c
  3. *
  4. * Code generated for Simulink model 'AngleObserver_discrete'.
  5. *
  6. * Model version : 1.28
  7. * Simulink Coder version : 9.6 (R2021b) 14-May-2021
  8. * C/C++ source code generated on : Wed Apr 27 16:33:17 2022
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: Custom Processor->Custom Processor
  12. * Code generation objectives:
  13. * 1. Execution efficiency
  14. * 2. RAM efficiency
  15. * Validation result: Not run
  16. */
  17. #include "AngleObserver_discrete.h"
  18. #ifndef UCHAR_MAX
  19. #include <limits.h>
  20. #endif
  21. #if ( UCHAR_MAX != (0xFFU) ) || ( SCHAR_MAX != (0x7F) )
  22. #error Code was generated for compiler with different sized uchar/char. \
  23. Consider adjusting Test hardware word size settings on the \
  24. Hardware Implementation pane to match your compiler word sizes as \
  25. defined in limits.h of the compiler. Alternatively, you can \
  26. select the Test hardware is the same as production hardware option and \
  27. select the Enable portable word sizes option on the Code Generation > \
  28. Verification pane for ERT based targets, which will disable the \
  29. preprocessor word size checks.
  30. #endif
  31. #if ( USHRT_MAX != (0xFFFFU) ) || ( SHRT_MAX != (0x7FFF) )
  32. #error Code was generated for compiler with different sized ushort/short. \
  33. Consider adjusting Test hardware word size settings on the \
  34. Hardware Implementation pane to match your compiler word sizes as \
  35. defined in limits.h of the compiler. Alternatively, you can \
  36. select the Test hardware is the same as production hardware option and \
  37. select the Enable portable word sizes option on the Code Generation > \
  38. Verification pane for ERT based targets, which will disable the \
  39. preprocessor word size checks.
  40. #endif
  41. #if ( UINT_MAX != (0xFFFFFFFFU) ) || ( INT_MAX != (0x7FFFFFFF) )
  42. #error Code was generated for compiler with different sized uint/int. \
  43. Consider adjusting Test hardware word size settings on the \
  44. Hardware Implementation pane to match your compiler word sizes as \
  45. defined in limits.h of the compiler. Alternatively, you can \
  46. select the Test hardware is the same as production hardware option and \
  47. select the Enable portable word sizes option on the Code Generation > \
  48. Verification pane for ERT based targets, which will disable the \
  49. preprocessor word size checks.
  50. #endif
  51. #if ( ULONG_MAX != (0xFFFFFFFFU) ) || ( LONG_MAX != (0x7FFFFFFF) )
  52. #error Code was generated for compiler with different sized ulong/long. \
  53. Consider adjusting Test hardware word size settings on the \
  54. Hardware Implementation pane to match your compiler word sizes as \
  55. defined in limits.h of the compiler. Alternatively, you can \
  56. select the Test hardware is the same as production hardware option and \
  57. select the Enable portable word sizes option on the Code Generation > \
  58. Verification pane for ERT based targets, which will disable the \
  59. preprocessor word size checks.
  60. #endif
  61. /* Skipping ulong_long/long_long check: insufficient preprocessor integer range. */
  62. /* Block signals and states (default storage) */
  63. DW rtDW;
  64. /* External inputs (root inport signals with default storage) */
  65. ExtU rtU;
  66. /* External outputs (root outports fed by signals with default storage) */
  67. ExtY rtY;
  68. /* Real-time model */
  69. static RT_MODEL rtM_;
  70. RT_MODEL *const rtM = &rtM_;
  71. /* Model step function */
  72. void Trigger(void)
  73. {
  74. int64_T rtb_Saturation2;
  75. int32_T rtb_Add2;
  76. int32_T rtb_Add3_i;
  77. int32_T rtb_Add5;
  78. /* RootInportFunctionCallGenerator generated from: '<Root>/Trigger' incorporates:
  79. * SubSystem: '<Root>/AngleObserver_discrete'
  80. */
  81. /* ArithShift: '<S8>/Shift Arithmetic' incorporates:
  82. * ArithShift: '<S7>/Shift Arithmetic'
  83. * Constant: '<S1>/Constant4'
  84. * Inport: '<Root>/AngleIn'
  85. * Sum: '<S1>/Add2'
  86. * Sum: '<S1>/Add3'
  87. * UnitDelay: '<S1>/Unit Delay1'
  88. */
  89. rtb_Add2 = (((int16_T)(rtU.AngleIn - 16384) << 17) - rtDW.UnitDelay1_DSTATE) >>
  90. 17;
  91. /* Sum: '<S4>/Add3' incorporates:
  92. * Constant: '<S1>/Constant1'
  93. * DataTypeConversion: '<S8>/Data Type Conversion'
  94. * Product: '<S1>/Product1'
  95. * Saturate: '<S8>/Saturation'
  96. * UnitDelay: '<S4>/Unit Delay1'
  97. */
  98. rtb_Add3_i = (int16_T)rtb_Add2 * 84 + rtDW.UnitDelay1_DSTATE_k;
  99. /* Sum: '<S6>/Add5' incorporates:
  100. * ArithShift: '<S1>/Shift Arithmetic2'
  101. * Constant: '<S1>/Constant2'
  102. * DataTypeConversion: '<S8>/Data Type Conversion'
  103. * Product: '<S1>/Product2'
  104. * Saturate: '<S8>/Saturation'
  105. * Sum: '<S1>/Sum2'
  106. * UnitDelay: '<S6>/Unit Delay3'
  107. */
  108. rtb_Add5 = ((17765 * (int16_T)rtb_Add2 + rtb_Add3_i) >> 12) +
  109. rtDW.UnitDelay3_DSTATE;
  110. /* ArithShift: '<S1>/Shift Arithmetic1' incorporates:
  111. * Constant: '<S1>/Constant'
  112. * Product: '<S1>/Product'
  113. * Saturate: '<S1>/Saturation2'
  114. */
  115. rtb_Saturation2 = (rtb_Add5 * 10LL) >> 10;
  116. /* Saturate: '<S1>/Saturation2' */
  117. if (rtb_Saturation2 > 32167LL) {
  118. /* Outport: '<Root>/Speed' incorporates:
  119. * DataTypeConversion: '<S1>/Data Type Conversion3'
  120. */
  121. rtY.Speed = 32167;
  122. } else if (rtb_Saturation2 < -32768LL) {
  123. /* Outport: '<Root>/Speed' incorporates:
  124. * DataTypeConversion: '<S1>/Data Type Conversion3'
  125. */
  126. rtY.Speed = MIN_int16_T;
  127. } else {
  128. /* Outport: '<Root>/Speed' incorporates:
  129. * DataTypeConversion: '<S1>/Data Type Conversion3'
  130. */
  131. rtY.Speed = (int16_T)rtb_Saturation2;
  132. }
  133. /* End of Saturate: '<S1>/Saturation2' */
  134. /* Sum: '<S5>/Add2' incorporates:
  135. * ArithShift: '<S2>/Shift Arithmetic'
  136. * ArithShift: '<S2>/Shift Arithmetic1'
  137. * DataTypeConversion: '<S8>/Data Type Conversion'
  138. * Gain: '<S1>/Gain6'
  139. * Saturate: '<S8>/Saturation'
  140. * Sum: '<S1>/Sum3'
  141. * UnitDelay: '<S5>/Unit Delay'
  142. */
  143. rtb_Add2 = ((((24127 * (int16_T)rtb_Add2) >> 7) + rtb_Add5) << 5) +
  144. rtDW.UnitDelay_DSTATE;
  145. /* Outport: '<Root>/Angle_Filtered' incorporates:
  146. * ArithShift: '<S3>/Shift Arithmetic'
  147. * Constant: '<S1>/Constant5'
  148. * Sum: '<S1>/Add4'
  149. * Sum: '<S5>/Add2'
  150. */
  151. rtY.Angle_Filtered = (int16_T)((rtb_Add2 >> 17) + 16384);
  152. /* Update for UnitDelay: '<S1>/Unit Delay1' */
  153. rtDW.UnitDelay1_DSTATE = rtb_Add2;
  154. /* Update for UnitDelay: '<S4>/Unit Delay1' */
  155. rtDW.UnitDelay1_DSTATE_k = rtb_Add3_i;
  156. /* Update for UnitDelay: '<S6>/Unit Delay3' */
  157. rtDW.UnitDelay3_DSTATE = rtb_Add5;
  158. /* Update for UnitDelay: '<S5>/Unit Delay' */
  159. rtDW.UnitDelay_DSTATE = rtb_Add2;
  160. /* End of Outputs for RootInportFunctionCallGenerator generated from: '<Root>/Trigger' */
  161. }
  162. /* Model initialize function */
  163. void AngleObserver_discrete_initialize(void)
  164. {
  165. /* (no initialization code required) */
  166. }
  167. /*
  168. * File trailer for generated code.
  169. *
  170. * [EOF]
  171. */