/* Model step function */ void c2000_profiler_step(void) { /* local block i/o variables */ int32_T rtb_SpaceVectorGenerator_o3; int32_T rtb_u; int32_T rtb_y; int32_T rtb_Sum2; int32_T rtb_SpaceVectorGenerator_o1; int32_T rtb_SpaceVectorGenerator_o2; int32_T rtb_sinIQN; int32_T rtb_UnitDelay_idx_0; int32_T rtb_UnitDelay_idx_1; /* UnitDelay: '<S7>/Unit Delay' */ rtb_UnitDelay_idx_0 = c2000_profiler_DWork.UnitDelay_DSTATE[0]; rtb_UnitDelay_idx_1 = c2000_profiler_DWork.UnitDelay_DSTATE[1]; /* S-Function (scheckfractionlength): '<S1>/ ' incorporates: * Inport: '<Root>/Ia' */ rtb_Sum2 = c2000_profiler_U.Ia; /* S-Function (scheckfractionlength): '<S3>/ ' */ rtb_sinIQN = rtb_Sum2; /* S-Function (scheckfractionlength): '<S3>/ 1' incorporates: * Inport: '<Root>/Position' */ rtb_u = c2000_profiler_U.Position; /* C28x IQmath Library (stiiqmath_iqtrig) - '<S3>/cos IQN1' */ { rtb_SpaceVectorGenerator_o3 = _IQ16cosPU(rtb_u); } /* Product: '<S3>/Product' */ rtb_SpaceVectorGenerator_o2 = __IQmpy(rtb_sinIQN, rtb_SpaceVectorGenerator_o3, 16); /* S-Function (scheckfractionlength): '<S1>/ 1' incorporates: * Inport: '<Root>/Ib' */ rtb_SpaceVectorGenerator_o1 = c2000_profiler_U.Ib; /* Sum: '<S1>/Sum1' incorporates: * ArithShift: '<S1>/Multiply by 2' */ rtb_SpaceVectorGenerator_o1 = (rtb_SpaceVectorGenerator_o1 << 1U) + rtb_Sum2; /* MATLAB Function: '<S5>/Embedded MATLAB Function' */ /* MATLAB Function 'Ramp Generator/Convert Param To fix-pt with floor rounding mode/Embedded MATLAB Function': '<S6>:1' */ /* '<S6>:1:5' */ /* Product: '<S1>/Product1' */ rtb_SpaceVectorGenerator_o1 = __IQmpy(37837L, rtb_SpaceVectorGenerator_o1, 16); /* C28x IQmath Library (stiiqmath_iqtrig) - '<S3>/sin IQN1' */ { rtb_Sum2 = _IQ16sinPU(rtb_u); } /* Product: '<S3>/Product1' */ rtb_u = __IQmpy(rtb_SpaceVectorGenerator_o1, rtb_Sum2, 16); /* Sum: '<S3>/Sum4' */ rtb_y = rtb_SpaceVectorGenerator_o2 + rtb_u; /* Product: '<S3>/Product2' */ rtb_SpaceVectorGenerator_o2 = __IQmpy(rtb_SpaceVectorGenerator_o1, rtb_SpaceVectorGenerator_o3, 16); /* Product: '<S3>/Product3' */ rtb_SpaceVectorGenerator_o1 = __IQmpy(rtb_sinIQN, rtb_Sum2, 16); /* Sum: '<S3>/Sum3' */ rtb_SpaceVectorGenerator_o3 = rtb_SpaceVectorGenerator_o2 - rtb_SpaceVectorGenerator_o1; /* C28x IQmath Library (stiiqmath_iqmag) - '<S7>/Magnitude IQN' */ { rtb_SpaceVectorGenerator_o1 = _IQ16mag (rtb_y, rtb_SpaceVectorGenerator_o3); } /* Switch: '<S7>/Switch1' */ if (!(rtb_SpaceVectorGenerator_o1 >= c2000_profiler_P.Switch1_Threshold)) { rtb_UnitDelay_idx_0 = rtb_y; rtb_UnitDelay_idx_1 = rtb_SpaceVectorGenerator_o3; } /* End of Switch: '<S7>/Switch1' */ /* S-Function (scheckfractionlength): '<S2>/ ' */ rtb_y = rtb_UnitDelay_idx_0; /* S-Function (scheckfractionlength): '<S2>/ 2' incorporates: * Inport: '<Root>/Position' */ rtb_SpaceVectorGenerator_o1 = c2000_profiler_U.Position; /* C28x IQmath Library (stiiqmath_iqtrig) - '<S2>/cos IQN' */ { rtb_SpaceVectorGenerator_o2 = _IQ16cosPU(rtb_SpaceVectorGenerator_o1); } /* Product: '<S2>/Product' */ rtb_SpaceVectorGenerator_o3 = __IQmpy(rtb_y, rtb_SpaceVectorGenerator_o2, 16); /* S-Function (scheckfractionlength): '<S2>/ 1' */ rtb_u = rtb_UnitDelay_idx_1; /* C28x IQmath Library (stiiqmath_iqtrig) - '<S2>/sin IQN' */ { rtb_sinIQN = _IQ16sinPU(rtb_SpaceVectorGenerator_o1); } /* Product: '<S2>/Product1' */ rtb_SpaceVectorGenerator_o1 = __IQmpy(rtb_u, rtb_sinIQN, 16); /* Sum: '<S2>/Sum2' */ rtb_Sum2 = rtb_SpaceVectorGenerator_o3 - rtb_SpaceVectorGenerator_o1; /* Product: '<S2>/Product2' */ rtb_SpaceVectorGenerator_o1 = __IQmpy(rtb_u, rtb_SpaceVectorGenerator_o2, 16); /* Product: '<S2>/Product3' */ rtb_SpaceVectorGenerator_o2 = __IQmpy(rtb_y, rtb_sinIQN, 16); /* Sum: '<S2>/Sum1' */ rtb_y = rtb_SpaceVectorGenerator_o1 + rtb_SpaceVectorGenerator_o2; /* C28x DMC Library (tidmcsvgendq) - '<Root>/Space Vector Generator' */ { int16_T sector; int32_T Va, Vb, Vc; sector = 0; Va = rtb_y; Vb = _IQ16mpy (_IQ16(-0.5),rtb_y) + _IQ16mpy (_IQ16(0.8660254),rtb_Sum2); Vc = _IQ16mpy (_IQ16(-0.5),rtb_y) - _IQ16mpy (_IQ16(0.8660254),rtb_Sum2); if (Va > 0) sector = 1; if (Vb > 0) sector = sector + 2; if (Vc > 0) sector = sector + 4; Vb = _IQ16mpy (_IQ16(0.5),rtb_y) + _IQ16mpy (_IQ16(0.8660254),rtb_Sum2); Vc = _IQ16mpy (_IQ16(0.5),rtb_y) - _IQ16mpy (_IQ16(0.8660254),rtb_Sum2); if (sector==0) { rtb_SpaceVectorGenerator_o1 = _IQ16(0.5); rtb_SpaceVectorGenerator_o2 = _IQ16(0.5); rtb_SpaceVectorGenerator_o3 = _IQ16(0.5); } else if (sector==1) { rtb_SpaceVectorGenerator_o2 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) - Vc - Vb)); rtb_SpaceVectorGenerator_o1 = rtb_SpaceVectorGenerator_o2 + Vc; rtb_SpaceVectorGenerator_o3 = rtb_SpaceVectorGenerator_o1 + Vb; } else if (sector==2) { rtb_SpaceVectorGenerator_o1 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) - Vb + Va)); rtb_SpaceVectorGenerator_o3 = rtb_SpaceVectorGenerator_o1 + Vb; rtb_SpaceVectorGenerator_o2 = rtb_SpaceVectorGenerator_o3 - Va; } else if (sector==3) { rtb_SpaceVectorGenerator_o1 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) + Vc - Va)); rtb_SpaceVectorGenerator_o2 = rtb_SpaceVectorGenerator_o1 - Vc; rtb_SpaceVectorGenerator_o3 = rtb_SpaceVectorGenerator_o2 + Va; } else if (sector==4) { rtb_SpaceVectorGenerator_o3 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) + Va - Vc)); rtb_SpaceVectorGenerator_o2 = rtb_SpaceVectorGenerator_o3 - Va; rtb_SpaceVectorGenerator_o1 = rtb_SpaceVectorGenerator_o2 + Vc; } else if (sector==5) { rtb_SpaceVectorGenerator_o2 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) - Va + Vb)); rtb_SpaceVectorGenerator_o3 = rtb_SpaceVectorGenerator_o2 + Va; rtb_SpaceVectorGenerator_o1 = rtb_SpaceVectorGenerator_o3 - Vb; } else if (sector==6) { rtb_SpaceVectorGenerator_o3 = _IQ16mpy (_IQ16(0.5), (_IQ16(1) + Vb + Vc)); rtb_SpaceVectorGenerator_o1 = rtb_SpaceVectorGenerator_o3 - Vb; rtb_SpaceVectorGenerator_o2 = rtb_SpaceVectorGenerator_o1 - Vc; } rtb_SpaceVectorGenerator_o1 = _IQ16mpy (_IQ16(2), (rtb_SpaceVectorGenerator_o1 - _IQ16(0.5))); rtb_SpaceVectorGenerator_o2 = _IQ16mpy (_IQ16(2), (rtb_SpaceVectorGenerator_o2 - _IQ16(0.5))); rtb_SpaceVectorGenerator_o3 = _IQ16mpy (_IQ16(2), (rtb_SpaceVectorGenerator_o3 - _IQ16(0.5))); } /* Outport: '<Root>/Voltage outputs' */ c2000_profiler_Y.Voltageoutputs[0] = rtb_SpaceVectorGenerator_o1; c2000_profiler_Y.Voltageoutputs[1] = rtb_SpaceVectorGenerator_o2; c2000_profiler_Y.Voltageoutputs[2] = rtb_SpaceVectorGenerator_o3; /* Update for UnitDelay: '<S7>/Unit Delay' */ c2000_profiler_DWork.UnitDelay_DSTATE[0] = rtb_UnitDelay_idx_0; c2000_profiler_DWork.UnitDelay_DSTATE[1] = rtb_UnitDelay_idx_1; }
TEST(IQmath_ExtractInteger, IQ16int) { LONGS_EQUAL(32767, _IQ16int(_IQ16(32767.999984741))) ; LONGS_EQUAL(-32768, _IQ16int(_IQ16(-32768.0))) ; }