1/*
2 * File: Shunt_Three_Sample_Point.c
3 *
4 * Code generated for Simulink model 'PMSM_Controller'.
5 *
6 * Model version : 1.1228
7 * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
8 * C/C++ source code generated on : Tue Apr 5 20:46:52 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
18#include "Shunt_Three_Sample_Point.h"
19
20/* Include model header file for global data */
21#include "PMSM_Controller.h"
22#include "PMSM_Controller_private.h"
23
24/* Output and update for atomic system: '<S68>/Shunt_Three_Sample_Point' */
25void Shunt_Three_Sample_Point(uint16_T rtu_low, uint16_T rtu_midle, uint8_T
26 rtu_i_sector, uint16_T rtu_half_pwm_count, uint16_T rtu_t_adc, uint16_T
27 rtu_t_dead, uint16_T rtu_t_samp_before, uint16_T *rty_o_samp_p1, uint16_T
28 *rty_o_samp_p2, uint8_T *rty_o_sector)
29{
30 uint32_T qY;
31 uint32_T qY_0;
32 uint32_T tmp;
33 uint32_T tmp_0;
34 uint16_T qY_1;
35 *rty_o_sector = rtu_i_sector;
36 tmp_0 = rtu_half_pwm_count + 1U;
37 if (rtu_half_pwm_count + 1U > 65535U) {
38 tmp_0 = 65535U;
39 }
40
41 *rty_o_samp_p1 = (uint16_T)tmp_0;
42 tmp_0 = rtu_half_pwm_count + 1U;
43 if (rtu_half_pwm_count + 1U > 65535U) {
44 tmp_0 = 65535U;
45 }
46
47 *rty_o_samp_p2 = (uint16_T)tmp_0;
48 tmp_0 = (uint32_T)rtu_t_adc + rtu_t_dead;
49 tmp = tmp_0;
50 if (tmp_0 > 65535U) {
51 tmp = 65535U;
52 }
53
54 tmp += rtu_t_samp_before;
55 if (tmp > 65535U) {
56 tmp = 65535U;
57 }
58
59 qY_0 = (uint32_T)rtu_half_pwm_count - /*MW:OvSatOk*/ rtu_low;
60 if (qY_0 > rtu_half_pwm_count) {
61 qY_0 = 0U;
62 }
63
64 qY = (uint32_T)rtu_half_pwm_count - /*MW:OvSatOk*/ rtu_midle;
65 if (qY > rtu_half_pwm_count) {
66 qY = 0U;
67 }
68
69 if ((uint16_T)qY_0 > 32767) {
70 qY_1 = MAX_uint16_T;
71 } else {
72 qY_1 = (uint16_T)((uint16_T)qY_0 << 1);
73 }
74
75 if (qY_1 >= (uint16_T)tmp) {
76 if (tmp_0 > 65535U) {
77 tmp_0 = 65535U;
78 }
79
80 if ((uint16_T)qY_0 >= (int32_T)tmp_0) {
81 qY_0 = rtu_half_pwm_count - /*MW:OvSatOk*/ 1U;
82 if (rtu_half_pwm_count - 1U > rtu_half_pwm_count) {
83 qY_0 = 0U;
84 }
85
86 *rty_o_samp_p1 = (uint16_T)qY_0;
87 *rty_o_sector = 1U;
88 } else {
89 tmp_0 = (uint32_T)rtu_low + rtu_t_samp_before;
90 if (tmp_0 > 65535U) {
91 tmp_0 = 65535U;
92 }
93
94 if ((uint16_T)tmp_0 >= rtu_half_pwm_count) {
95 if (rtu_half_pwm_count > 32767) {
96 qY_1 = MAX_uint16_T;
97 } else {
98 qY_1 = (uint16_T)(rtu_half_pwm_count << 1);
99 }
100
101 qY_0 = (uint32_T)qY_1 - /*MW:OvSatOk*/ (uint16_T)tmp_0;
102 if (qY_0 > qY_1) {
103 qY_0 = 0U;
104 }
105
106 qY = qY_0 - /*MW:OvSatOk*/ 1U;
107 if (qY_0 - 1U > qY_0) {
108 qY = 0U;
109 }
110
111 *rty_o_samp_p2 = (uint16_T)qY;
112 } else {
113 *rty_o_samp_p1 = (uint16_T)tmp_0;
114 }
115 }
116 } else {
117 if ((uint16_T)qY > 32767) {
118 qY_1 = MAX_uint16_T;
119 } else {
120 qY_1 = (uint16_T)((uint16_T)qY << 1);
121 }
122
123 if (qY_1 >= (uint16_T)tmp) {
124 if (tmp_0 > 65535U) {
125 tmp_0 = 65535U;
126 }
127
128 if ((uint16_T)qY >= (int32_T)tmp_0) {
129 qY_0 = rtu_half_pwm_count - /*MW:OvSatOk*/ 1U;
130 if (rtu_half_pwm_count - 1U > rtu_half_pwm_count) {
131 qY_0 = 0U;
132 }
133
134 *rty_o_samp_p1 = (uint16_T)qY_0;
135 } else {
136 tmp_0 = (uint32_T)rtu_midle + rtu_t_samp_before;
137 if (tmp_0 > 65535U) {
138 tmp_0 = 65535U;
139 }
140
141 if ((uint16_T)tmp_0 >= rtu_half_pwm_count) {
142 if (rtu_half_pwm_count > 32767) {
143 qY_1 = MAX_uint16_T;
144 } else {
145 qY_1 = (uint16_T)(rtu_half_pwm_count << 1);
146 }
147
148 qY_0 = (uint32_T)qY_1 - /*MW:OvSatOk*/ (uint16_T)tmp_0;
149 if (qY_0 > qY_1) {
150 qY_0 = 0U;
151 }
152
153 qY = qY_0 - /*MW:OvSatOk*/ 1U;
154 if (qY_0 - 1U > qY_0) {
155 qY = 0U;
156 }
157
158 *rty_o_samp_p2 = (uint16_T)qY;
159 } else {
160 *rty_o_samp_p1 = (uint16_T)tmp_0;
161 }
162 }
163 }
164 }
165}
166
167/*
168 * File trailer for generated code.
169 *
170 * [EOF]
171 */
172