/* * Academic License - for use in teaching, academic research, and meeting * course requirements at degree granting institutions only. Not for * government, commercial, or other organizational use. * * File: Open0.c * * Code generated for Simulink model 'Open0'. * * Model version : 2.23 * Simulink Coder version : 25.1 (R2025a) 21-Nov-2024 * C/C++ source code generated on : Sat Jun 14 14:25:03 2025 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex-M * Code generation objectives: * 1. Execution efficiency * 2. RAM efficiency * Validation result: Not run */ #include "include/Open0.h" #include #include "include/rtwtypes.h" /* External inputs (root inport signals with default storage) */ ExtU rtU; /* External outputs (root outports fed by signals with default storage) */ ExtY rtY; /* Real-time model */ static RT_MODEL rtM_; RT_MODEL *const rtM = &rtM_; /* Model step function */ void Open0_step(void) { real_T rtb_Switch_idx_0; real_T rtb_convert_pu; real_T rtb_sum_beta; real32_T T_idx_0; real32_T T_idx_1; real32_T T_idx_3; real32_T T_idx_4; real32_T d_Temp; uint16_T rtb_Get_Integer; /* Gain: '/convert_pu' incorporates: * Inport: '/theta' */ rtb_convert_pu = 0.15915494309189535 * rtU.theta; /* If: '/If' incorporates: * Constant: '/Constant' * DataTypeConversion: '/Convert_back' * DataTypeConversion: '/Convert_uint16' * DataTypeConversion: '/Convert_back' * DataTypeConversion: '/Convert_uint16' * Gain: '/indexing' * RelationalOperator: '/Compare' * Sum: '/Sum' * Sum: '/Sum' */ if (rtb_convert_pu < 0.0) { /* Outputs for IfAction SubSystem: '/If Action Subsystem' incorporates: * ActionPort: '/Action Port' */ rtb_Switch_idx_0 = rtb_convert_pu - (real_T)(int16_T)floor(rtb_convert_pu); /* End of Outputs for SubSystem: '/If Action Subsystem' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem1' incorporates: * ActionPort: '/Action Port' */ rtb_Switch_idx_0 = rtb_convert_pu - (real_T)(int16_T)rtb_convert_pu; /* End of Outputs for SubSystem: '/If Action Subsystem1' */ } rtb_convert_pu = 800.0 * rtb_Switch_idx_0; /* End of If: '/If' */ /* DataTypeConversion: '/Get_Integer' */ rtb_Get_Integer = (uint16_T)rtb_convert_pu; /* Sum: '/Sum2' incorporates: * DataTypeConversion: '/Data Type Conversion1' * DataTypeConversion: '/Get_Integer' */ rtb_sum_beta = rtb_convert_pu - (real_T)(uint16_T)rtb_convert_pu; /* Selector: '/Lookup' incorporates: * Constant: '/sine_table_values' * DataTypeConversion: '/Get_Integer' */ rtb_Switch_idx_0 = rtConstP.sine_table_values_Value[(uint16_T)rtb_convert_pu]; /* Sum: '/Sum4' incorporates: * Constant: '/offset' * Constant: '/sine_table_values' * DataTypeConversion: '/Get_Integer' * Product: '/Product' * Selector: '/Lookup' * Sum: '/Sum3' * Sum: '/Sum' */ rtb_convert_pu = (rtConstP.sine_table_values_Value[(int32_T)((uint16_T) rtb_convert_pu + 1U)] - rtb_Switch_idx_0) * rtb_sum_beta + rtb_Switch_idx_0; /* Selector: '/Lookup' incorporates: * Constant: '/offset' * Constant: '/sine_table_values' * Sum: '/Sum5' * Sum: '/Sum' */ rtb_Switch_idx_0 = rtConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer + 200U)]; /* Sum: '/Sum6' incorporates: * Constant: '/offset' * Constant: '/sine_table_values' * Product: '/Product1' * Selector: '/Lookup' * Sum: '/Sum5' * Sum: '/Sum' */ rtb_sum_beta = (rtConstP.sine_table_values_Value[(int32_T)(rtb_Get_Integer + 201U)] - rtb_Switch_idx_0) * rtb_sum_beta + rtb_Switch_idx_0; /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ /* Switch: '/Switch' incorporates: * Inport: '/Ud' * Inport: '/Uq' * Product: '/dcos' * Product: '/dsin' * Product: '/qcos' * Product: '/qsin' * Sum: '/sum_alpha' * Sum: '/sum_beta' */ rtb_Switch_idx_0 = rtU.Ud * rtb_sum_beta - rtU.Uq * rtb_convert_pu; rtb_convert_pu = rtU.Uq * rtb_sum_beta + rtU.Ud * rtb_convert_pu; /* MATLAB Function: '/MATLAB Function2' incorporates: * AlgorithmDescriptorDelegate generated from: '/a16' */ switch (((((real32_T)rtb_convert_pu - (real32_T)rtb_Switch_idx_0 * 1.73205078F > 0.0F) << 2) + (((real32_T)rtb_Switch_idx_0 * 1.73205078F + (real32_T)rtb_convert_pu > 0.0F) << 1)) + ((real32_T)rtb_convert_pu <= 0.0F)) { case 1: T_idx_0 = 5.0F; break; case 2: T_idx_0 = 1.0F; break; case 3: T_idx_0 = 6.0F; break; case 4: T_idx_0 = 3.0F; break; case 5: T_idx_0 = 4.0F; break; case 6: T_idx_0 = 2.0F; break; default: T_idx_0 = -1.0F; break; } /* End of MATLAB Function: '/MATLAB Function2' */ /* End of Outputs for SubSystem: '/Two inputs CRL' */ /* MATLAB Function: '/MATLAB Function1' incorporates: * AlgorithmDescriptorDelegate generated from: '/a16' * Constant: '/Constant' * Constant: '/Constant1' */ switch ((int32_T)T_idx_0) { case 1: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ T_idx_4 = (real32_T)(2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F; T_idx_3 = (real32_T)(rtb_Switch_idx_0 - rtb_convert_pu / 1.7320508075688772) * 1800.0F / 8.0F; /* End of Outputs for SubSystem: '/Two inputs CRL' */ T_idx_1 = T_idx_4; d_Temp = T_idx_3 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_3 *= d_Temp; T_idx_1 = T_idx_4 * d_Temp; } d_Temp = ((1800.0F - T_idx_3) - T_idx_1) / 2.0F; T_idx_3 = (T_idx_3 + T_idx_1) + d_Temp; T_idx_1 += d_Temp; break; case 2: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ rtb_convert_pu /= 1.7320508075688772; T_idx_1 = (real32_T)(rtb_convert_pu - rtb_Switch_idx_0) * 1800.0F / 8.0F; T_idx_4 = (real32_T)(rtb_convert_pu + rtb_Switch_idx_0) * 1800.0F / 8.0F; /* End of Outputs for SubSystem: '/Two inputs CRL' */ d_Temp = T_idx_1 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_1 *= d_Temp; T_idx_4 *= d_Temp; } d_Temp = ((1800.0F - T_idx_1) - T_idx_4) / 2.0F; T_idx_3 = T_idx_4 + d_Temp; T_idx_1 = (T_idx_1 + T_idx_4) + d_Temp; break; case 3: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ T_idx_1 = (real32_T)(1.7320508075688772 * rtb_convert_pu) * 1800.0F / 12.0F; T_idx_4 = -((real32_T)(1.5 * rtb_Switch_idx_0 + 0.8660254037844386 * rtb_convert_pu) * 150.0F); /* End of Outputs for SubSystem: '/Two inputs CRL' */ d_Temp = T_idx_1 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_1 *= d_Temp; T_idx_4 *= d_Temp; } d_Temp = ((1800.0F - T_idx_1) - T_idx_4) / 2.0F; T_idx_3 = d_Temp; T_idx_1 = (T_idx_1 + T_idx_4) + d_Temp; d_Temp += T_idx_4; break; case 4: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ T_idx_0 = (real32_T)(-2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F; T_idx_4 = (real32_T)(rtb_convert_pu / 1.7320508075688772 - rtb_Switch_idx_0) * 1800.0F / 8.0F; /* End of Outputs for SubSystem: '/Two inputs CRL' */ d_Temp = T_idx_0 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_0 *= d_Temp; T_idx_4 *= d_Temp; } d_Temp = ((1800.0F - T_idx_0) - T_idx_4) / 2.0F; T_idx_3 = d_Temp; T_idx_1 = T_idx_4 + d_Temp; d_Temp += T_idx_0 + T_idx_4; break; case 5: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ rtb_convert_pu = -rtb_convert_pu / 1.7320508075688772; T_idx_0 = (real32_T)(rtb_convert_pu - rtb_Switch_idx_0) * 1800.0F / 8.0F; T_idx_4 = (real32_T)(rtb_convert_pu + rtb_Switch_idx_0) * 1800.0F / 8.0F; /* End of Outputs for SubSystem: '/Two inputs CRL' */ d_Temp = T_idx_0 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_0 *= d_Temp; T_idx_4 *= d_Temp; } d_Temp = ((1800.0F - T_idx_0) - T_idx_4) / 2.0F; T_idx_3 = T_idx_4 + d_Temp; T_idx_1 = d_Temp; d_Temp += T_idx_0 + T_idx_4; break; case 6: /* Outputs for Atomic SubSystem: '/Two inputs CRL' */ T_idx_4 = (real32_T)(-2.0 * rtb_convert_pu) * 1800.0F / 1.73205078F / 8.0F; T_idx_3 = (real32_T)(rtb_convert_pu / 1.7320508075688772 + rtb_Switch_idx_0) * 1800.0F / 8.0F; /* End of Outputs for SubSystem: '/Two inputs CRL' */ d_Temp = T_idx_3 + T_idx_4; if (d_Temp > 1800.0F) { d_Temp = 1800.0F / d_Temp; T_idx_3 *= d_Temp; T_idx_4 *= d_Temp; } d_Temp = ((1800.0F - T_idx_3) - T_idx_4) / 2.0F; T_idx_3 = (T_idx_3 + T_idx_4) + d_Temp; T_idx_1 = d_Temp; d_Temp += T_idx_4; break; } /* Outport: '/CCR1' incorporates: * Constant: '/Constant1' * MATLAB Function: '/MATLAB Function1' */ rtY.CCR1 = (1800.0F - T_idx_3) / 2.0F; /* Outport: '/CCR2' incorporates: * Constant: '/Constant1' * MATLAB Function: '/MATLAB Function1' */ rtY.CCR2 = (1800.0F - T_idx_1) / 2.0F; /* Outport: '/CCR3' incorporates: * Constant: '/Constant1' * MATLAB Function: '/MATLAB Function1' */ rtY.CCR3 = (1800.0F - d_Temp) / 2.0F; } /* Model initialize function */ void Open0_initialize(void) { /* (no initialization code required) */ } /* * File trailer for generated code. * * [EOF] */