Shunt_Three_Sample_Point.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * File: Shunt_Three_Sample_Point.c
  3. *
  4. * Code generated for Simulink model 'PMSM_Controller'.
  5. *
  6. * Model version : 1.885
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Sat Jan 8 15:44:11 2022
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex-M
  12. * Code generation objectives:
  13. * 1. Execution efficiency
  14. * 2. RAM efficiency
  15. * Validation result: Not run
  16. */
  17. #include "Shunt_Three_Sample_Point.h"
  18. /* Include model header file for global data */
  19. #include "PMSM_Controller.h"
  20. #include "PMSM_Controller_private.h"
  21. /* Output and update for atomic system: '<S178>/Shunt_Three_Sample_Point' */
  22. void Shunt_Three_Sample_Point(uint16_T rtu_low, uint16_T rtu_midle, uint8_T
  23. rtu_i_sector, uint16_T rtu_half_pwm_count, uint16_T rtu_t_adc, uint16_T
  24. rtu_t_dead, uint16_T rtu_t_samp_before, uint16_T *rty_o_samp_p1, uint16_T
  25. *rty_o_samp_p2, uint8_T *rty_o_sector)
  26. {
  27. uint32_T qY;
  28. uint32_T qY_0;
  29. uint32_T tmp;
  30. uint32_T tmp_0;
  31. uint16_T qY_1;
  32. *rty_o_sector = rtu_i_sector;
  33. tmp_0 = rtu_half_pwm_count + 1U;
  34. if (rtu_half_pwm_count + 1U > 65535U) {
  35. tmp_0 = 65535U;
  36. }
  37. *rty_o_samp_p1 = (uint16_T)tmp_0;
  38. tmp_0 = rtu_half_pwm_count + 1U;
  39. if (rtu_half_pwm_count + 1U > 65535U) {
  40. tmp_0 = 65535U;
  41. }
  42. *rty_o_samp_p2 = (uint16_T)tmp_0;
  43. tmp_0 = (uint32_T)rtu_t_adc + rtu_t_dead;
  44. tmp = tmp_0;
  45. if (tmp_0 > 65535U) {
  46. tmp = 65535U;
  47. }
  48. tmp += rtu_t_samp_before;
  49. if (tmp > 65535U) {
  50. tmp = 65535U;
  51. }
  52. qY_0 = (uint32_T)rtu_half_pwm_count - /*MW:OvSatOk*/ rtu_low;
  53. if (qY_0 > rtu_half_pwm_count) {
  54. qY_0 = 0U;
  55. }
  56. qY = (uint32_T)rtu_half_pwm_count - /*MW:OvSatOk*/ rtu_midle;
  57. if (qY > rtu_half_pwm_count) {
  58. qY = 0U;
  59. }
  60. if ((uint16_T)qY_0 > 32767) {
  61. qY_1 = MAX_uint16_T;
  62. } else {
  63. qY_1 = (uint16_T)((uint16_T)qY_0 << 1);
  64. }
  65. if (qY_1 >= (uint16_T)tmp) {
  66. if (tmp_0 > 65535U) {
  67. tmp_0 = 65535U;
  68. }
  69. if ((uint16_T)qY_0 >= (int32_T)tmp_0) {
  70. qY_0 = rtu_half_pwm_count - /*MW:OvSatOk*/ 1U;
  71. if (rtu_half_pwm_count - 1U > rtu_half_pwm_count) {
  72. qY_0 = 0U;
  73. }
  74. *rty_o_samp_p1 = (uint16_T)qY_0;
  75. *rty_o_sector = 1U;
  76. } else {
  77. tmp_0 = (uint32_T)rtu_low + rtu_t_samp_before;
  78. if (tmp_0 > 65535U) {
  79. tmp_0 = 65535U;
  80. }
  81. if ((uint16_T)tmp_0 >= rtu_half_pwm_count) {
  82. if (rtu_half_pwm_count > 32767) {
  83. qY_1 = MAX_uint16_T;
  84. } else {
  85. qY_1 = (uint16_T)(rtu_half_pwm_count << 1);
  86. }
  87. qY_0 = (uint32_T)qY_1 - /*MW:OvSatOk*/ (uint16_T)tmp_0;
  88. if (qY_0 > qY_1) {
  89. qY_0 = 0U;
  90. }
  91. qY = qY_0 - /*MW:OvSatOk*/ 1U;
  92. if (qY_0 - 1U > qY_0) {
  93. qY = 0U;
  94. }
  95. *rty_o_samp_p2 = (uint16_T)qY;
  96. } else {
  97. *rty_o_samp_p1 = (uint16_T)tmp_0;
  98. }
  99. }
  100. } else {
  101. if ((uint16_T)qY > 32767) {
  102. qY_1 = MAX_uint16_T;
  103. } else {
  104. qY_1 = (uint16_T)((uint16_T)qY << 1);
  105. }
  106. if (qY_1 >= (uint16_T)tmp) {
  107. if (tmp_0 > 65535U) {
  108. tmp_0 = 65535U;
  109. }
  110. if ((uint16_T)qY >= (int32_T)tmp_0) {
  111. qY_0 = rtu_half_pwm_count - /*MW:OvSatOk*/ 1U;
  112. if (rtu_half_pwm_count - 1U > rtu_half_pwm_count) {
  113. qY_0 = 0U;
  114. }
  115. *rty_o_samp_p1 = (uint16_T)qY_0;
  116. } else {
  117. tmp_0 = (uint32_T)rtu_midle + rtu_t_samp_before;
  118. if (tmp_0 > 65535U) {
  119. tmp_0 = 65535U;
  120. }
  121. if ((uint16_T)tmp_0 >= rtu_half_pwm_count) {
  122. if (rtu_half_pwm_count > 32767) {
  123. qY_1 = MAX_uint16_T;
  124. } else {
  125. qY_1 = (uint16_T)(rtu_half_pwm_count << 1);
  126. }
  127. qY_0 = (uint32_T)qY_1 - /*MW:OvSatOk*/ (uint16_T)tmp_0;
  128. if (qY_0 > qY_1) {
  129. qY_0 = 0U;
  130. }
  131. qY = qY_0 - /*MW:OvSatOk*/ 1U;
  132. if (qY_0 - 1U > qY_0) {
  133. qY = 0U;
  134. }
  135. *rty_o_samp_p2 = (uint16_T)qY;
  136. } else {
  137. *rty_o_samp_p1 = (uint16_T)tmp_0;
  138. }
  139. }
  140. }
  141. }
  142. }
  143. /*
  144. * File trailer for generated code.
  145. *
  146. * [EOF]
  147. */