diff --git a/01_Matlab/01_Libraries/01_Controller/BLDC_controller_Lib.slx b/01_Matlab/01_Libraries/01_Controller/BLDC_controller_Lib.slx index 50475e2..51ac348 100644 Binary files a/01_Matlab/01_Libraries/01_Controller/BLDC_controller_Lib.slx and b/01_Matlab/01_Libraries/01_Controller/BLDC_controller_Lib.slx differ diff --git a/01_Matlab/99_RecycleBin/BLDC_controller_Lib_AccelerationBased.slx b/01_Matlab/99_RecycleBin/BLDC_controller_Lib_AccelerationBased.slx new file mode 100644 index 0000000..ff4e651 Binary files /dev/null and b/01_Matlab/99_RecycleBin/BLDC_controller_Lib_AccelerationBased.slx differ diff --git a/01_Matlab/99_RecycleBin/BLDC_controller_Lib_CounterBased.slx b/01_Matlab/99_RecycleBin/BLDC_controller_Lib_CounterBased.slx new file mode 100644 index 0000000..f7c76e2 Binary files /dev/null and b/01_Matlab/99_RecycleBin/BLDC_controller_Lib_CounterBased.slx differ diff --git a/01_Matlab/99_RecycleBin/init_model.m b/01_Matlab/99_RecycleBin/init_model.m new file mode 100644 index 0000000..2985c9a --- /dev/null +++ b/01_Matlab/99_RecycleBin/init_model.m @@ -0,0 +1,214 @@ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This file is part of the hoverboard-new-firmware-hack project +% Compared to previouse commutation method, this project offers +% 3 more additional control method for BLDC motors. +% The new control methods offers superior performanace +% compared to previous method featuring: +% >> reduced noise and vibrations +% >> smooth torque output +% >> improved motor efficiency -> lower energy consumption +% +% Author: Emanuel FERU +% Copyright © 2019 Emanuel FERU +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program. If not, see . +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Clear workspace +close all +clear +clc + +% Load model parameters +load BLDCmotorControl_data; +Ts = 5e-6; % [s] Model samplind time (200 kHz) +Ts_ctrl = 6e-5; % [s] Controller samplid time (~16 kHz) +% Ts_ctrl = 12e-5; % [s] Controller samplid time (~8 kHz) + +% BLDC control parameters +CTRL_COMM = 0; % Commutation +CTRL_TRAP = 1; % Pure Trapezoidal +CTRL_SIN = 2; % Sinusoidal +CTRL_SIN3 = 3; % Sinusoidal 3rd armonic + +z_ctrlTypSel = CTRL_SIN3; % Control method selection + +% Motor Parameters +n_polePairs = 15; % [-] Number of pole pairs +a_elecPeriod = 360; % [deg] Electrical angle period +a_elecAngle = 60; % [deg] Electrical angle between two Hall sensor changing events +a_mechAngle = a_elecAngle / n_polePairs; % [deg] Mechanical angle + +%% F01_Preliminary_Calculations + +z_hallDebSteps = 3; % [-] Hall debounce time steps + +% Position Calculation Parameters +% Hall = 4*hA + 2*hB + hC +% Hall = [0 1 2 3 4 5 6 7] +vec_hallToPos = [0 5 3 4 1 0 2 0]; % [-] Mapping Hall signal to position + +% Speed Calculation Parameters +f_ctrl = 1/Ts_ctrl; % [Hz] Controller frequency = 1/Ts_ctrl +cf_speedCoef = round(f_ctrl * a_mechAngle * (pi/180) * (30/pi)); % [-] Speed calculation coefficient (factors are due to conversions rpm <-> rad/s) +cf_speedFilt = 10; % [%] Speed filter in percent [1, 100]. Lower values mean softer filter +z_maxCntRst = 1000; % [-] Maximum counter value for reset (works also as time-out to detect standing still) +% z_nrEdgeSpdAcv = 2; % [-] Number of edge detections to activate speed calculation +% cf_speedSca = 3e7; % [-] Scaling factor for speed calculation +% cf_speedCoef = round(cf_speedSca /(f_ctrl * a_mechAngle * (pi/180) * (30/pi))); + +%% F02_Electrical_Angle_Calculation +b_phaAdvEna = 1; % [-] Phase advance enable parameter: 0 = disable, 1 = enable + +% The map below was experimentaly calibrated on the real motor. Objectives: minimum noise and minimum torque ripple +a_phaAdv_M1 = [0 0 7 2 2 2 4 5 9 16 25]; % [deg] Phase advance angle +r_phaAdvDC_XA = [0 100 200 300 400 500 600 700 800 900 1000]; % [-] Phase advance Duty Cycle grid +% plot(r_phaAdvDC_XA, a_phaAdv_M1); + +%% F03_Speed_Control +n_commAcvLo = 30; % [rpm] Commutation method activation speed low +n_commDeacvHi = 50; % [rpm] Commutation method deactivation speed high +r_commDCDeacv = 80; % [-] Commutation method deactivation Duty Cycle threshold (arbitrary small number) +z_errCtrlRstHi = 20; % [-] Error counter reset. Above this value the control resets to Commudation method (only during high dynamics) +z_errCtrlRstLo = 12; + +sca_factor = 1000; % [-] scalling factor (to avoid truncation approximations on integer data type) +% Commutation method +z_commutMap_M1 = sca_factor*[ 1 1 0 -1 -1 0; % Phase A + -1 0 1 1 0 -1 ; % Phase B + 0 -1 -1 0 1 1]; % Phase C [-] Commutation method map + +% Trapezoidal method +a_trapElecAngle_XA = [0 60 120 180 240 300 360]; % [deg] Electrical angle grid +r_trapPhaA_M1 = sca_factor*[ 1 1 1 -1 -1 -1 1]; +r_trapPhaB_M1 = sca_factor*[-1 -1 1 1 1 -1 -1]; +r_trapPhaC_M1 = sca_factor*[ 1 -1 -1 -1 1 1 1]; + +% Sinusoidal method +a_sinElecAngle_XA = 0:10:360; +omega = a_sinElecAngle_XA*(pi/180); +pha_adv = 30; % [deg] Phase advance to mach commands with the Hall position +r_sinPhaA_M1 = sin(omega + pha_adv*(pi/180)); +r_sinPhaB_M1 = sin(omega - 120*(pi/180) + pha_adv*(pi/180)); +r_sinPhaC_M1 = sin(omega + 120*(pi/180) + pha_adv*(pi/180)); + +% Sinusoidal 3rd armonic method +A = 1.15; % Sine amplitude (tunable to get the Saddle sin maximum to value 1000) +sin3Arm = 0.22*sin(3*(omega + pha_adv*(pi/180))); % 3rd armonic +r_sin3PhaA_M1 = sin3Arm + A*r_sinPhaA_M1; +r_sin3PhaB_M1 = sin3Arm + A*r_sinPhaB_M1; +r_sin3PhaC_M1 = sin3Arm + A*r_sinPhaC_M1; + +% Rounding for representation on integer data type +r_sinPhaA_M1 = round(sca_factor * r_sinPhaA_M1); +r_sinPhaB_M1 = round(sca_factor * r_sinPhaB_M1); +r_sinPhaC_M1 = round(sca_factor * r_sinPhaC_M1); +r_sin3PhaA_M1 = round(sca_factor * r_sin3PhaA_M1); +r_sin3PhaB_M1 = round(sca_factor * r_sin3PhaB_M1); +r_sin3PhaC_M1 = round(sca_factor * r_sin3PhaC_M1); + +disp('---- BLDC_controller: Initialization OK ----'); + +%% 2nd Harmonic vs 3rd Harmonic +% figure +% subplot(211) +% a1= (0.22*sin(3*(omega + (pi/180)))); +% b = A*sin(omega + 1*(pi/180)); +% plot(a_sinElecAngle_XA, a1+b,'b', 'Linewidth', lw); hold on +% a2 = abs(0.3*sin(2*(omega + (pi/180)))); +% b = 0.85*sin(omega + 1*(pi/180)); +% plot(a_sinElecAngle_XA,sign(b).*a2+b,'g', 'Linewidth', lw) +% grid +% legend('3rd harmonic', '2nd harmonic'); +% subplot(212) +% plot(a_sinElecAngle_XA,a1,'b', 'Linewidth', lw); hold on +% plot(a_sinElecAngle_XA,sign(b).*a2,'g', 'Linewidth', lw); +% plot(a_sinElecAngle_XA,b,'r', 'Linewidth', lw); +% legend('3rd harmonic', '2nd harmonic','Main sine wave'); +% grid + +%% Plot control methods + +show_fig = 0; +if show_fig + + hall_A = [1 1 1 0 0 0 0] + 4; + hall_B = [0 0 1 1 1 0 0] + 2; + hall_C = [1 0 0 0 1 1 1]; + + color = ['m' 'g' 'b']; + lw = 1.5; + figure + s1 = subplot(321); hold on + stairs(a_trapElecAngle_XA, hall_A, color(1), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, hall_B, color(2), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, hall_C, color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + grid + yticks(0:5); + yticklabels({'0','1','0','1','0','1'}); + title('Hall sensors'); + legend('Phase A','Phase B','Phase C','Location','NorthWest'); + + s2 = subplot(322); hold on + stairs(a_trapElecAngle_XA, hall_A, color(1), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, hall_B, color(2), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, hall_C, color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + grid + yticks(0:5); + yticklabels({'0','1','0','1','0','1'}); + title('Hall sensors'); + legend('Phase A','Phase B','Phase C','Location','NorthWest'); + + s3 = subplot(323); hold on + stairs(a_trapElecAngle_XA, [z_commutMap_M1(1,:) z_commutMap_M1(1,end)] + 6000, color(1), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, [z_commutMap_M1(2,:) z_commutMap_M1(1,end)] + 3000, color(2), 'Linewidth', lw); + stairs(a_trapElecAngle_XA, [z_commutMap_M1(3,:) z_commutMap_M1(1,end)], color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + yticks(-1000:1000:7000); + yticklabels({'-1000','0','1000','-1000','0','1000','-1000','0','1000'}); + ylim([-1000 7000]); + grid + title('Commutation method [0]'); + + s5 = subplot(325); hold on + plot(a_trapElecAngle_XA, r_trapPhaA_M1, color(1), 'Linewidth', lw); + plot(a_trapElecAngle_XA, r_trapPhaB_M1, color(2), 'Linewidth', lw); + plot(a_trapElecAngle_XA, r_trapPhaC_M1, color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + grid + title('Pure trapezoidal method [1]'); + xlabel('Electrical angle [deg]'); + + s4 = subplot(324); hold on + plot(a_sinElecAngle_XA, r_sinPhaA_M1, color(1), 'Linewidth', lw); + plot(a_sinElecAngle_XA, r_sinPhaB_M1, color(2), 'Linewidth', lw); + plot(a_sinElecAngle_XA, r_sinPhaC_M1, color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + grid + title('Sinusoidal method [2]'); + + s6 = subplot(326); hold on + plot(a_sinElecAngle_XA, r_sin3PhaA_M1, color(1), 'Linewidth', lw); + plot(a_sinElecAngle_XA, r_sin3PhaB_M1, color(2), 'Linewidth', lw); + plot(a_sinElecAngle_XA, r_sin3PhaC_M1, color(3), 'Linewidth', lw); + xticks(a_trapElecAngle_XA); + grid + title('Sinusoidal 3rd armonic [3]'); + xlabel('Electrical angle [deg]'); + linkaxes([s1 s2 s3 s4 s5 s6],'x'); + xlim([0 360]); +end diff --git a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.c b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.c index 9f96c3d..f8bb08c 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.c +++ b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.c @@ -7,9 +7,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.817 + * Model version : 1.877 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue May 28 19:55:33 2019 + * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -85,49 +85,13 @@ preprocessor word size checks. #endif #endif -/* Block signals and states (auto storage) */ -DW rtDW; - -/* Previous zero-crossings (trigger) states */ -PrevZCX rtPrevZCX; - -/* External inputs (root inport signals with auto storage) */ -ExtU rtU; - -/* External outputs (root outports fed by signals with auto storage) */ -ExtY rtY; -static uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T - bpSpace, uint32_T maxIndex, uint32_T *fraction); -static int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, - const int16_T table[]); -static int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator); -static void F01_03_Direction_Detection(boolean_T rtu_Enable, uint8_T rtu_z_pos, - uint8_T rtu_z_posPrev, int8_T *rty_z_dir, int8_T *rty_z_dirPrev, - DW_F01_03_Direction_Detection *localDW); -static void Edge_counter_Reset(DW_Edge_counter *localDW); -static void Edge_counter_Disable(uint8_T *rty_cnt, DW_Edge_counter *localDW); -static void Edge_counter(boolean_T rtu_Enable, boolean_T rtu_b_edge, int8_T - rtu_z_dir, int8_T rtu_z_dirPrev, uint8_T *rty_cnt, DW_Edge_counter *localDW); -static void Motor_Speed_Calculation(boolean_T rtu_Trigger, int16_T rtu_z_counter, - int8_T rtu_z_dir, int32_T *rty_n_mot, DW_Motor_Speed_Calculation *localDW, - ZCE_Motor_Speed_Calculation *localZCE); -static void F03_01_Pure_Trapezoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Trap, int16_T *rty_r_phaB_Trap, int16_T *rty_r_phaC_Trap); -static void F03_02_Sinusoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Sin, int16_T *rty_r_phaB_Sin, int16_T *rty_r_phaC_Sin); -static void F03_02_Sinusoidal3rd_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Sin3, int16_T *rty_r_phaB_Sin3, int16_T *rty_r_phaC_Sin3); -static void F02_Electrical_Angle_Ca_Disable(int32_T *rty_a_elecAngleAdv, int32_T - *rty_a_elecAngle); -static void F02_Electrical_Angle_Calculatio(int32_T rtu_r_DC, uint8_T rtu_z_pos, - int8_T rtu_z_dir, int16_T rtu_z_counter, int16_T rtu_z_counterRaw, int32_T - *rty_a_elecAngleAdv, int32_T *rty_a_elecAngle); -static void falling_edge2(void); -static void rising_edge(void); -static void falling_edge2_b(void); -static void rising_edge_f(void); -static uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T - bpSpace, uint32_T maxIndex, uint32_T *fraction) +uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T bpSpace, + uint32_T maxIndex, uint32_T *fraction); +int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, const + int16_T table[]); +int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator); +uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T bpSpace, + uint32_T maxIndex, uint32_T *fraction) { uint8_T bpIndex; uint32_T uAdjust; @@ -160,8 +124,8 @@ static uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T return bpIndex; } -static int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, - const int16_T table[]) +int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, const + int16_T table[]) { uint32_T offset_0d; @@ -176,1128 +140,553 @@ static int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, * frac) >> 31) + table[offset_0d]); } -static int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator) +int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator) { return (((numerator < 0) != (denominator < 0)) && (numerator % denominator != 0) ? -1 : 0) + numerator / denominator; } -/* - * Output and update for enable system: - * '/F01_03_Direction_Detection' - * '/F01_03_Direction_Detection' - */ -static void F01_03_Direction_Detection(boolean_T rtu_Enable, uint8_T rtu_z_pos, - uint8_T rtu_z_posPrev, int8_T *rty_z_dir, int8_T *rty_z_dirPrev, - DW_F01_03_Direction_Detection *localDW) -{ - int8_T rtb_Sum2; - - /* Outputs for Enabled SubSystem: '/F01_03_Direction_Detection' incorporates: - * EnablePort: '/Enable' - */ - if (rtu_Enable) { - /* UnitDelay: '/UnitDelay1' */ - *rty_z_dirPrev = localDW->UnitDelay1_DSTATE; - - /* Sum: '/Sum2' incorporates: - * DataTypeConversion: '/Data Type Conversion1' - * DataTypeConversion: '/Data Type Conversion10' - */ - rtb_Sum2 = (int8_T)((int8_T)rtu_z_pos - (int8_T)rtu_z_posPrev); - - /* Switch: '/Switch2' incorporates: - * Constant: '/Constant20' - * Constant: '/Constant23' - * Constant: '/Constant24' - * Constant: '/Constant8' - * Logic: '/Logical Operator3' - * RelationalOperator: '/Relational Operator1' - * RelationalOperator: '/Relational Operator6' - */ - if ((rtb_Sum2 == 1) || (rtb_Sum2 == -5)) { - *rty_z_dir = 1; - } else { - *rty_z_dir = -1; - } - - /* End of Switch: '/Switch2' */ - - /* Update for UnitDelay: '/UnitDelay1' */ - localDW->UnitDelay1_DSTATE = *rty_z_dir; - } - - /* End of Outputs for SubSystem: '/F01_03_Direction_Detection' */ -} - -/* - * System reset for enable system: - * '/Edge_counter' - * '/Edge_counter' - */ -static void Edge_counter_Reset(DW_Edge_counter *localDW) -{ - /* InitializeConditions for UnitDelay: '/UnitDelay1' */ - localDW->UnitDelay1_DSTATE = 0U; -} - -/* - * Disable for enable system: - * '/Edge_counter' - * '/Edge_counter' - */ -static void Edge_counter_Disable(uint8_T *rty_cnt, DW_Edge_counter *localDW) -{ - /* Outputs for Enabled SubSystem: '/Edge_counter' incorporates: - * EnablePort: '/Enable' - */ - /* Disable for Outport: '/cnt' */ - *rty_cnt = 0U; - - /* End of Outputs for SubSystem: '/Edge_counter' */ - localDW->Edge_counter_MODE = false; -} - -/* - * Output and update for enable system: - * '/Edge_counter' - * '/Edge_counter' - */ -static void Edge_counter(boolean_T rtu_Enable, boolean_T rtu_b_edge, int8_T - rtu_z_dir, int8_T rtu_z_dirPrev, uint8_T *rty_cnt, DW_Edge_counter *localDW) -{ - boolean_T rtb_RelationalOperator1_i; - uint8_T rtb_RelationalOperator1_m1; - - /* Outputs for Enabled SubSystem: '/Edge_counter' incorporates: - * EnablePort: '/Enable' - */ - if (rtu_Enable) { - if (!localDW->Edge_counter_MODE) { - Edge_counter_Reset(localDW); - localDW->Edge_counter_MODE = true; - } - - /* RelationalOperator: '/Relational Operator1' */ - rtb_RelationalOperator1_i = (rtu_z_dir == rtu_z_dirPrev); - - /* Switch: '/Switch1' incorporates: - * Constant: '/Constant23' - * Logic: '/Logical Operator2' - * UnitDelay: '/UnitDelay1' - */ - if (!rtb_RelationalOperator1_i) { - rtb_RelationalOperator1_m1 = 0U; - } else { - rtb_RelationalOperator1_m1 = localDW->UnitDelay1_DSTATE; - } - - /* End of Switch: '/Switch1' */ - - /* Sum: '/Sum2' incorporates: - * Logic: '/Logical Operator1' - */ - *rty_cnt = (uint8_T)((uint32_T)(rtu_b_edge && rtb_RelationalOperator1_i) + - rtb_RelationalOperator1_m1); - - /* Update for UnitDelay: '/UnitDelay1' */ - localDW->UnitDelay1_DSTATE = *rty_cnt; - } else { - if (localDW->Edge_counter_MODE) { - Edge_counter_Disable(rty_cnt, localDW); - } - } - - /* End of Outputs for SubSystem: '/Edge_counter' */ -} - -/* - * Output and update for trigger system: - * '/Motor_Speed_Calculation' - * '/Motor_Speed_Calculation' - */ -static void Motor_Speed_Calculation(boolean_T rtu_Trigger, int16_T rtu_z_counter, - int8_T rtu_z_dir, int32_T *rty_n_mot, DW_Motor_Speed_Calculation *localDW, - ZCE_Motor_Speed_Calculation *localZCE) -{ - int32_T rtb_Sum2; - - /* Outputs for Triggered SubSystem: '/Motor_Speed_Calculation' incorporates: - * TriggerPort: '/Trigger' - */ - if (rtu_Trigger && (localZCE->Motor_Speed_Calculation_Trig_ZC != POS_ZCSIG)) { - /* Switch: '/Switch' incorporates: - * Constant: '/Constant1' - * Constant: '/cf_spdCoef' - * Constant: '/z_maxCntRst' - * Product: '/Divide4' - * RelationalOperator: '/Relational Operator1' - */ - if (rtu_z_counter >= rtP.z_maxCntRst) { - rtb_Sum2 = 0; - } else { - rtb_Sum2 = rtP.cf_speedCoef / rtu_z_counter; - } - - /* End of Switch: '/Switch' */ - - /* Product: '/Product2' */ - rtb_Sum2 *= rtu_z_dir; - - /* Product: '/Divide1' incorporates: - * Constant: '/Constant2' - * Sum: '/Sum2' - * UnitDelay: '/UnitDelay1' - * UnitDelay: '/UnitDelay5' - */ - *rty_n_mot = ((localDW->UnitDelay5_DSTATE + localDW->UnitDelay1_DSTATE) + - rtb_Sum2) / 3; - - /* Update for UnitDelay: '/UnitDelay5' incorporates: - * UnitDelay: '/UnitDelay1' - */ - localDW->UnitDelay5_DSTATE = localDW->UnitDelay1_DSTATE; - - /* Update for UnitDelay: '/UnitDelay1' */ - localDW->UnitDelay1_DSTATE = rtb_Sum2; - } - - localZCE->Motor_Speed_Calculation_Trig_ZC = rtu_Trigger; - - /* End of Outputs for SubSystem: '/Motor_Speed_Calculation' */ -} - -/* Output and update for atomic system: '/falling_edge2' */ -static void falling_edge2(void) -{ - /* Logic: '/Logical Operator' incorporates: - * Logic: '/Logical Operator1' - * UnitDelay: '/UnitDelay' - */ - rtDW.LogicalOperator = ((!rtDW.Logic[0]) && rtDW.UnitDelay_DSTATE_b); - - /* Update for UnitDelay: '/UnitDelay' */ - rtDW.UnitDelay_DSTATE_b = rtDW.Logic[0]; -} - -/* Output and update for atomic system: '/rising_edge' */ -static void rising_edge(void) -{ - /* Logic: '/Logical Operator' incorporates: - * Logic: '/Logical Operator1' - * UnitDelay: '/UnitDelay' - */ - rtDW.LogicalOperator_h = (rtDW.LogicalOperator5 && (!rtDW.UnitDelay_DSTATE_l)); - - /* Update for UnitDelay: '/UnitDelay' */ - rtDW.UnitDelay_DSTATE_l = rtDW.LogicalOperator5; -} - -/* - * Output and update for action system: - * '/F03_01_Pure_Trapezoidal_Method' - * '/F03_01_Pure_Trapezoidal_Method' - */ -static void F03_01_Pure_Trapezoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Trap, int16_T *rty_r_phaB_Trap, int16_T *rty_r_phaC_Trap) -{ - uint8_T rtb_a_trapElecAngle_XA_o1; - uint32_T rtb_a_trapElecAngle_XA_o2; - - /* PreLookup: '/a_trapElecAngle_XA' */ - rtb_a_trapElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 60U, 6U, &rtb_a_trapElecAngle_XA_o2); - - /* Interpolation_n-D: '/r_trapPhaA_M1' */ - *rty_r_phaA_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - rtb_a_trapElecAngle_XA_o2, rtConstP.pooled9); - - /* Interpolation_n-D: '/r_trapPhaB_M1' */ - *rty_r_phaB_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - rtb_a_trapElecAngle_XA_o2, rtConstP.pooled10); - - /* Interpolation_n-D: '/r_trapPhaC_M1' */ - *rty_r_phaC_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - rtb_a_trapElecAngle_XA_o2, rtConstP.pooled11); -} - -/* - * Output and update for action system: - * '/F03_02_Sinusoidal_Method' - * '/F03_02_Sinusoidal_Method' - */ -static void F03_02_Sinusoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Sin, int16_T *rty_r_phaB_Sin, int16_T *rty_r_phaC_Sin) -{ - uint8_T rtb_a_sinElecAngle_XA_o1; - uint32_T rtb_a_sinElecAngle_XA_o2; - - /* PreLookup: '/a_sinElecAngle_XA' */ - rtb_a_sinElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 10U, 36U, &rtb_a_sinElecAngle_XA_o2); - - /* Interpolation_n-D: '/r_sinPhaA_M1' */ - *rty_r_phaA_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled12); - - /* Interpolation_n-D: '/r_sinPhaB_M1' */ - *rty_r_phaB_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled13); - - /* Interpolation_n-D: '/r_sinPhaC_M1' */ - *rty_r_phaC_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled14); -} - -/* - * Output and update for action system: - * '/F03_02_Sinusoidal3rd_Method' - * '/F03_02_Sinusoidal3rd_Method' - */ -static void F03_02_Sinusoidal3rd_Method(int32_T rtu_a_elecAngleAdv, int16_T - *rty_r_phaA_Sin3, int16_T *rty_r_phaB_Sin3, int16_T *rty_r_phaC_Sin3) -{ - uint8_T rtb_a_sinElecAngle_XA_o1; - uint32_T rtb_a_sinElecAngle_XA_o2; - - /* PreLookup: '/a_sinElecAngle_XA' */ - rtb_a_sinElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 10U, 36U, &rtb_a_sinElecAngle_XA_o2); - - /* Interpolation_n-D: '/r_sin3PhaA_M1' */ - *rty_r_phaA_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled15); - - /* Interpolation_n-D: '/r_sin3PhaB_M1' */ - *rty_r_phaB_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled16); - - /* Interpolation_n-D: '/r_sin3PhaC_M1' */ - *rty_r_phaC_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - rtb_a_sinElecAngle_XA_o2, rtConstP.pooled17); -} - -/* - * Disable for action system: - * '/F02_Electrical_Angle_Calculation' - * '/F02_Electrical_Angle_Calculation' - */ -static void F02_Electrical_Angle_Ca_Disable(int32_T *rty_a_elecAngleAdv, int32_T - *rty_a_elecAngle) -{ - /* Disable for Outport: '/a_elecAngleAdv' */ - *rty_a_elecAngleAdv = 0; - - /* Disable for Outport: '/a_elecAngle' */ - *rty_a_elecAngle = 0; -} - -/* - * Output and update for action system: - * '/F02_Electrical_Angle_Calculation' - * '/F02_Electrical_Angle_Calculation' - */ -static void F02_Electrical_Angle_Calculatio(int32_T rtu_r_DC, uint8_T rtu_z_pos, - int8_T rtu_z_dir, int16_T rtu_z_counter, int16_T rtu_z_counterRaw, int32_T - *rty_a_elecAngleAdv, int32_T *rty_a_elecAngle) -{ - uint8_T rtb_Switch3; - int16_T rtb_a_phaAdv_M2; - uint32_T rtb_r_phaAdvDC_XA_o2; - int32_T rtu_r_DC_0; - - /* Switch: '/Switch3' incorporates: - * Constant: '/Constant16' - * RelationalOperator: '/Relational Operator7' - * Sum: '/Sum1' - */ - if (rtu_z_dir == 1) { - rtb_Switch3 = rtu_z_pos; - } else { - rtb_Switch3 = (uint8_T)(rtu_z_pos + 1U); - } - - /* End of Switch: '/Switch3' */ - - /* Sum: '/Sum2' incorporates: - * Constant: '/a_elecAngle1' - * Product: '/Divide4' - * Product: '/Divide5' - * Product: '/Product6' - */ - *rty_a_elecAngle = 60 * rtu_z_counterRaw / rtu_z_counter * rtu_z_dir + - rtb_Switch3 * 60; - - /* Switch: '/Switch_PhaAdv' incorporates: - * Constant: '/a_elecPeriod1' - * Math: '/Math Function' - */ - if (rtP.b_phaAdvEna) { - /* Abs: '/Abs2' */ - if (rtu_r_DC < 0) { - rtu_r_DC_0 = -rtu_r_DC; - } else { - rtu_r_DC_0 = rtu_r_DC; - } - - /* End of Abs: '/Abs2' */ - - /* PreLookup: '/r_phaAdvDC_XA' */ - rtb_Switch3 = plook_u8s32u32n31_evenc_s(rtu_r_DC_0, rtP.r_phaAdvDC_XA[0], - (uint32_T)rtP.r_phaAdvDC_XA[1] - rtP.r_phaAdvDC_XA[0], 10U, - &rtb_r_phaAdvDC_XA_o2); - - /* Interpolation_n-D: '/a_phaAdv_M2' */ - rtb_a_phaAdv_M2 = intrp1d_s16s32s32u8u32n31l_s(rtb_Switch3, - rtb_r_phaAdvDC_XA_o2, rtP.a_phaAdv_M1); - - /* Sum: '/Sum3' incorporates: - * Product: '/Product2' - */ - rtu_r_DC_0 = rtu_z_dir * rtb_a_phaAdv_M2 + *rty_a_elecAngle; - *rty_a_elecAngleAdv = rtu_r_DC_0 - div_nde_s32_floor(rtu_r_DC_0, 360) * 360; - } else { - *rty_a_elecAngleAdv = *rty_a_elecAngle; - } - - /* End of Switch: '/Switch_PhaAdv' */ -} - -/* Output and update for atomic system: '/falling_edge2' */ -static void falling_edge2_b(void) -{ - /* Logic: '/Logical Operator' incorporates: - * Logic: '/Logical Operator1' - * UnitDelay: '/UnitDelay' - */ - rtDW.LogicalOperator_h = ((!rtDW.Logic_j[0]) && rtDW.UnitDelay_DSTATE_i); - - /* Update for UnitDelay: '/UnitDelay' */ - rtDW.UnitDelay_DSTATE_i = rtDW.Logic_j[0]; -} - -/* Output and update for atomic system: '/rising_edge' */ -static void rising_edge_f(void) -{ - /* Logic: '/Logical Operator' incorporates: - * Logic: '/Logical Operator1' - * UnitDelay: '/UnitDelay' - */ - rtDW.LogicalOperator_h = (rtDW.LogicalOperator5 && (!rtDW.UnitDelay_DSTATE_k)); - - /* Update for UnitDelay: '/UnitDelay' */ - rtDW.UnitDelay_DSTATE_k = rtDW.LogicalOperator5; -} - /* Model step function */ -void BLDC_controller_step(void) +void BLDC_controller_step(RT_MODEL *const rtM) { + P *rtP = ((P *) rtM->defaultParam); + DW *rtDW = ((DW *) rtM->dwork); + ExtU *rtU = (ExtU *) rtM->inputs; + ExtY *rtY = (ExtY *) rtM->outputs; uint8_T rtb_Sum; - boolean_T rtb_LogicalOperator; - boolean_T rtb_LogicalOperator3; - int32_T rtb_Abs1; - int8_T rtPrevAction; + int32_T rtb_Sum2; + uint8_T rtb_BitwiseOperator; + int16_T rtb_Abs2; + int16_T rtb_Sum1_a; + int32_T rtb_Abs5; int8_T rtAction; - uint8_T rtb_Sum_a; - int16_T rtb_Switch; - int16_T rtb_Switch_b; - int16_T rtb_Sum1; - int16_T rtb_Sum1_c; + int8_T rtb_Sum2_h; + uint32_T rtb_r_phaAdvDC_XA_o2; int32_T rtb_Switch1_idx_0; int32_T rtb_Switch1_idx_1; - uint8_T tmp; /* Outputs for Atomic SubSystem: '/BLDC_controller' */ - /* Sum: '/Sum' incorporates: - * Gain: '/g_Ha' - * Gain: '/g_Hb' - * Inport: '/b_hallALeft ' - * Inport: '/b_hallBLeft' - * Inport: '/b_hallCLeft' + /* Sum: '/Sum' incorporates: + * Gain: '/g_Ha' + * Gain: '/g_Hb' + * Inport: '/b_hallA ' + * Inport: '/b_hallB' + * Inport: '/b_hallC' */ - rtb_Sum = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU.b_hallALeft << - 2) + (uint8_T)(rtU.b_hallBLeft << 1)) + rtU.b_hallCLeft); + rtb_Sum = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU->b_hallA << 2) + + (uint8_T)(rtU->b_hallB << 1)) + rtU->b_hallC); - /* Logic: '/Logical Operator' incorporates: - * Inport: '/b_hallALeft ' - * Inport: '/b_hallBLeft' - * Inport: '/b_hallCLeft' - * UnitDelay: '/UnitDelay' - * UnitDelay: '/UnitDelay1' - * UnitDelay: '/UnitDelay2' + /* S-Function (sfix_bitop): '/Bitwise Operator' incorporates: + * Inport: '/b_hallA ' + * Inport: '/b_hallB' + * Inport: '/b_hallC' + * UnitDelay: '/UnitDelay' + * UnitDelay: '/UnitDelay1' + * UnitDelay: '/UnitDelay2' */ - rtb_LogicalOperator = (boolean_T)((rtU.b_hallALeft != 0) ^ (rtU.b_hallBLeft != - 0) ^ (rtU.b_hallCLeft != 0) ^ (rtDW.UnitDelay_DSTATE != 0) ^ - (rtDW.UnitDelay1_DSTATE_p != 0)) ^ (rtDW.UnitDelay2_DSTATE != 0); + rtb_BitwiseOperator = (uint8_T)(rtU->b_hallA ^ rtU->b_hallB ^ rtU->b_hallC ^ + rtDW->UnitDelay_DSTATE ^ rtDW->UnitDelay1_DSTATE_i ^ + rtDW->UnitDelay2_DSTATE_h); - /* Outputs for Enabled SubSystem: '/F01_03_Direction_Detection' */ - - /* Selector: '/Selector' incorporates: - * Constant: '/vec_hallToPos' - * UnitDelay: '/UnitDelay1' + /* If: '/If1' incorporates: + * Constant: '/Constant6' + * Constant: '/Constant1' + * Constant: '/Constant23' + * If: '/If2' + * Inport: '/z_counterRawPrev' + * RelationalOperator: '/Relational Operator1' + * Sum: '/Sum1' + * Switch: '/Switch1' + * Switch: '/Switch2' + * UnitDelay: '/UnitDelay1' + * UnitDelay: '/UnitDelay1' */ - F01_03_Direction_Detection(rtb_LogicalOperator, rtConstP.pooled26[rtb_Sum], - rtDW.UnitDelay1_DSTATE_g, &rtDW.Switch2_e, &rtDW.UnitDelay1_k, - &rtDW.F01_03_Direction_Detection_o); - - /* End of Outputs for SubSystem: '/F01_03_Direction_Detection' */ - - /* Logic: '/Logical Operator3' incorporates: - * Constant: '/z_maxCntRst' - * RelationalOperator: '/Relational Operator1' - * UnitDelay: '/z_counterRawPrev' - */ - rtb_LogicalOperator3 = (rtb_LogicalOperator || (rtDW.z_counterRawPrev_DSTATE > - rtP.z_maxCntRst)); - - /* Outputs for Enabled SubSystem: '/Edge_counter' */ - - /* Logic: '/Logical Operator2' incorporates: - * UnitDelay: '/UnitDelay8' - */ - Edge_counter(!rtDW.UnitDelay8_DSTATE, rtb_LogicalOperator, rtDW.Switch2_e, - rtDW.UnitDelay1_k, &rtDW.Sum2_l, &rtDW.Edge_counter_f); - - /* End of Outputs for SubSystem: '/Edge_counter' */ - - /* Logic: '/Logical Operator5' incorporates: - * Constant: '/z_maxCntRst2' - * RelationalOperator: '/Relational Operator3' - * RelationalOperator: '/Relational Operator6' - * UnitDelay: '/z_counterRawPrev' - */ - rtDW.LogicalOperator5 = ((rtDW.Switch2_e != rtDW.UnitDelay1_k) || - (rtDW.z_counterRawPrev_DSTATE > rtP.z_maxCntRst)); - - /* Outputs for Atomic SubSystem: '/rising_edge' */ - rising_edge(); - - /* End of Outputs for SubSystem: '/rising_edge' */ - - /* CombinatorialLogic: '/Logic' incorporates: - * Constant: '/z_nrEdgeSpdAcv' - * Memory: '/Memory' - * RelationalOperator: '/Relational Operator5' - */ - rtb_Switch1_idx_0 = (int32_T)(((((uint32_T)(rtDW.Sum2_l >= rtP.z_nrEdgeSpdAcv) - << 1) + rtDW.LogicalOperator_h) << 1) + rtDW.Memory_PreviousInput); - rtDW.Logic[0U] = rtConstP.pooled30[(uint32_T)rtb_Switch1_idx_0]; - rtDW.Logic[1U] = rtConstP.pooled30[rtb_Switch1_idx_0 + 8U]; - - /* Outputs for Atomic SubSystem: '/falling_edge2' */ - falling_edge2(); - - /* End of Outputs for SubSystem: '/falling_edge2' */ - - /* Switch: '/Switch' incorporates: - * Logic: '/Logical Operator1' - * Switch: '/Switch1' - * UnitDelay: '/z_counter2' - * UnitDelay: '/z_counterRawPrev' - */ - if (rtb_LogicalOperator3 && rtDW.Logic[0]) { - rtb_Switch = rtDW.z_counterRawPrev_DSTATE; - } else if (rtDW.LogicalOperator) { - /* Switch: '/Switch1' incorporates: - * Constant: '/z_maxCntRst1' + if (rtb_BitwiseOperator != 0) { + /* Outputs for IfAction SubSystem: '/F01_03_Direction_Detection' incorporates: + * ActionPort: '/Action Port' */ - rtb_Switch = rtP.z_maxCntRst; + /* UnitDelay: '/UnitDelay1' */ + rtDW->UnitDelay1 = rtDW->Switch2; + + /* Sum: '/Sum2' incorporates: + * Constant: '/vec_hallToPos' + * Selector: '/Selector' + * UnitDelay: '/UnitDelay2' + */ + rtb_Sum2_h = (int8_T)(rtConstP.vec_hallToPos_Value[rtb_Sum] - + rtDW->UnitDelay2_DSTATE_i); + + /* Switch: '/Switch2' incorporates: + * Constant: '/Constant20' + * Constant: '/Constant23' + * Constant: '/Constant24' + * Constant: '/Constant8' + * Logic: '/Logical Operator3' + * RelationalOperator: '/Relational Operator1' + * RelationalOperator: '/Relational Operator6' + */ + if ((rtb_Sum2_h == 1) || (rtb_Sum2_h == -5)) { + rtDW->Switch2 = 1; + } else { + rtDW->Switch2 = -1; + } + + /* End of Switch: '/Switch2' */ + + /* Update for UnitDelay: '/UnitDelay2' incorporates: + * Constant: '/vec_hallToPos' + * Selector: '/Selector' + */ + rtDW->UnitDelay2_DSTATE_i = rtConstP.vec_hallToPos_Value[rtb_Sum]; + + /* End of Outputs for SubSystem: '/F01_03_Direction_Detection' */ + rtb_Abs2 = 1; + + /* Outputs for IfAction SubSystem: '/Counter_Hold_and_Error_Calculation' incorporates: + * ActionPort: '/Action Port' + */ + rtDW->z_counterRawPrev = rtDW->UnitDelay1_DSTATE_c; + + /* Sum: '/Sum4' incorporates: + * Constant: '/Constant6' + * Constant: '/Constant23' + * Inport: '/z_counterRawPrev' + * Sum: '/Sum1' + * UnitDelay: '/UnitDelay1' + * UnitDelay: '/z_counter2' + */ + rtDW->Sum4 = (int16_T)(rtDW->z_counterRawPrev - rtDW->z_counter2_DSTATE); + + /* Update for UnitDelay: '/z_counter2' */ + rtDW->z_counter2_DSTATE = rtDW->z_counterRawPrev; + + /* End of Outputs for SubSystem: '/Counter_Hold_and_Error_Calculation' */ } else { - rtb_Switch = rtDW.z_counter2_DSTATE; + if (rtDW->UnitDelay1_DSTATE < 1500) { + /* Switch: '/Switch2' incorporates: + * UnitDelay: '/UnitDelay1' + */ + rtb_Abs2 = rtDW->UnitDelay1_DSTATE; + } else { + /* Switch: '/Switch2' incorporates: + * Constant: '/Constant1' + */ + rtb_Abs2 = 1500; + } + + rtb_Abs2++; } - /* End of Switch: '/Switch' */ + /* End of If: '/If1' */ - /* Outputs for Triggered SubSystem: '/Motor_Speed_Calculation' */ + /* Sum: '/Sum1' */ + rtb_Sum1_a = rtb_Abs2; - /* Outport: '/n_motLeft' */ - Motor_Speed_Calculation(rtb_LogicalOperator3, rtb_Switch, rtDW.Switch2_e, - &rtY.n_motLeft, &rtDW.Motor_Speed_Calculation_m, - &rtPrevZCX.Motor_Speed_Calculation_m); - - /* End of Outputs for SubSystem: '/Motor_Speed_Calculation' */ - - /* Abs: '/Abs5' incorporates: - * Outport: '/n_motLeft' + /* Switch: '/Switch1' incorporates: + * Constant: '/Constant1' + * Constant: '/cf_spdCoef' + * Constant: '/z_maxCntRst' + * Logic: '/Logical Operator1' + * Product: '/Divide4' + * RelationalOperator: '/Relational Operator2' + * RelationalOperator: '/Relational Operator5' + * Sum: '/Sum1' */ - if (rtY.n_motLeft < 0) { - rtb_Abs1 = -rtY.n_motLeft; + if ((rtb_Abs2 > 1500) || (rtDW->Switch2 != rtDW->UnitDelay1)) { + rtb_Sum2 = 0; } else { - rtb_Abs1 = rtY.n_motLeft; + rtb_Sum2 = rtP->cf_speedCoef * rtDW->Switch2 / rtDW->z_counterRawPrev; } - /* End of Abs: '/Abs5' */ + /* End of Switch: '/Switch1' */ - /* Relay: '/Relay' */ - if (rtb_Abs1 >= rtP.n_commDeacvHi) { - rtDW.Relay_Mode = true; + /* Product: '/Divide2' incorporates: + * Constant: '/Constant2' + * Constant: '/Constant3' + * Constant: '/cf_speedFilt' + * Product: '/Divide1' + * Product: '/Divide3' + * Sum: '/Sum1' + * Sum: '/Sum2' + * UnitDelay: '/UnitDelay2' + */ + rtb_Sum2 = ((100 - rtP->cf_speedFilt) * rtDW->UnitDelay2_DSTATE + rtb_Sum2 * + rtP->cf_speedFilt) / 100; + + /* Abs: '/Abs5' */ + if (rtb_Sum2 < 0) { + rtb_Abs5 = -rtb_Sum2; } else { - if (rtb_Abs1 <= rtP.n_commAcvLo) { - rtDW.Relay_Mode = false; + rtb_Abs5 = rtb_Sum2; + } + + /* End of Abs: '/Abs5' */ + + /* Relay: '/n_commDeacv' */ + if (rtb_Abs5 >= rtP->n_commDeacvHi) { + rtDW->n_commDeacv_Mode = true; + } else { + if (rtb_Abs5 <= rtP->n_commAcvLo) { + rtDW->n_commDeacv_Mode = false; } } - /* Switch: '/Switch1' incorporates: - * Constant: '/Constant23' - * UnitDelay: '/UnitDelay1' - */ - if (rtb_LogicalOperator3) { - rtb_Sum1_c = 0; + /* Abs: '/Abs2' */ + if (rtDW->Sum4 < 0) { + rtb_Abs2 = (int16_T)-rtDW->Sum4; } else { - rtb_Sum1_c = rtDW.UnitDelay1_DSTATE; + rtb_Abs2 = rtDW->Sum4; } - /* End of Switch: '/Switch1' */ + /* End of Abs: '/Abs2' */ - /* Sum: '/Sum1' */ - rtb_Sum1 = (int16_T)(1 + rtb_Sum1_c); + /* Relay: '/dz_counter' */ + if (rtb_Abs2 >= rtP->dz_counterHi) { + rtDW->dz_counter_Mode = true; + } else { + if (rtb_Abs2 <= rtP->dz_counterLo) { + rtDW->dz_counter_Mode = false; + } + } /* If: '/If1' incorporates: - * Constant: '/z_ctrlTypSel1' - * Constant: '/vec_hallToPos' - * Inport: '/r_DCLeft' - * Outport: '/a_elecAngleLeft' - * Selector: '/Selector' + * Constant: '/z_ctrlTypSel1' */ - rtPrevAction = rtDW.If1_ActiveSubsystem; + rtb_Sum2_h = rtDW->If1_ActiveSubsystem; rtAction = -1; - if (rtP.z_ctrlTypSel != 0) { + if (rtP->z_ctrlTypSel != 0) { rtAction = 0; } - rtDW.If1_ActiveSubsystem = rtAction; - if ((rtPrevAction != rtAction) && (rtPrevAction == 0)) { - F02_Electrical_Angle_Ca_Disable(&rtDW.Switch_PhaAdv_a, &rtY.a_elecAngleLeft); + rtDW->If1_ActiveSubsystem = rtAction; + if ((rtb_Sum2_h != rtAction) && (rtb_Sum2_h == 0)) { + /* Disable for Outport: '/a_elecAngleAdv' */ + rtDW->Switch_PhaAdv = 0; + + /* Disable for Outport: '/a_elecAngle' incorporates: + * Outport: '/a_elecAngle' + */ + rtY->a_elecAngle = 0; } if (rtAction == 0) { /* Outputs for IfAction SubSystem: '/F02_Electrical_Angle_Calculation' incorporates: - * ActionPort: '/Action Port' + * ActionPort: '/Action Port' */ - F02_Electrical_Angle_Calculatio(rtU.r_DCLeft, rtConstP.pooled26[rtb_Sum], - rtDW.Switch2_e, rtb_Switch, rtb_Sum1, &rtDW.Switch_PhaAdv_a, - &rtY.a_elecAngleLeft); + /* Switch: '/Switch3' incorporates: + * Constant: '/vec_hallToPos' + * Constant: '/Constant16' + * Gain: '/g_Ha' + * Gain: '/g_Hb' + * Inport: '/b_hallA ' + * Inport: '/b_hallB' + * Inport: '/b_hallC' + * RelationalOperator: '/Relational Operator7' + * Selector: '/Selector' + * Sum: '/Sum' + * Sum: '/Sum1' + */ + if (rtDW->Switch2 == 1) { + rtb_Sum2_h = rtConstP.vec_hallToPos_Value[rtb_Sum]; + } else { + rtb_Sum2_h = (int8_T)(rtConstP.vec_hallToPos_Value[(uint8_T)((uint32_T) + (uint8_T)((uint32_T)(uint8_T)(rtU->b_hallA << 2) + (uint8_T) + (rtU->b_hallB << 1)) + rtU->b_hallC)] + 1); + } + /* End of Switch: '/Switch3' */ + + /* Outport: '/a_elecAngle' incorporates: + * Constant: '/a_elecAngle1' + * Product: '/Divide4' + * Product: '/Divide5' + * Product: '/Product6' + * Sum: '/Sum2' + */ + rtY->a_elecAngle = 60 * rtb_Sum1_a / rtDW->z_counterRawPrev * rtDW->Switch2 + + rtb_Sum2_h * 60; + + /* Switch: '/Switch_PhaAdv' incorporates: + * Constant: '/a_elecPeriod1' + * Outport: '/a_elecAngle' + */ + if (rtP->b_phaAdvEna) { + /* Abs: '/Abs2' incorporates: + * Inport: '/r_DC' + */ + if (rtU->r_DC < 0) { + rtb_Switch1_idx_0 = -rtU->r_DC; + } else { + rtb_Switch1_idx_0 = rtU->r_DC; + } + + /* End of Abs: '/Abs2' */ + + /* PreLookup: '/r_phaAdvDC_XA' */ + rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtb_Switch1_idx_0, + rtP->r_phaAdvDC_XA[0], (uint32_T)rtP->r_phaAdvDC_XA[1] - + rtP->r_phaAdvDC_XA[0], 10U, &rtb_r_phaAdvDC_XA_o2); + + /* Interpolation_n-D: '/a_phaAdv_M2' */ + rtb_Abs2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtP->a_phaAdv_M1); + + /* Sum: '/Sum3' incorporates: + * Outport: '/a_elecAngle' + * Product: '/Product2' + */ + rtb_Switch1_idx_0 = (int16_T)(rtb_Abs2 * rtDW->Switch2) + rtY->a_elecAngle; + + /* Math: '/Math Function' */ + rtDW->Switch_PhaAdv = rtb_Switch1_idx_0 - div_nde_s32_floor + (rtb_Switch1_idx_0, 360) * 360; + } else { + rtDW->Switch_PhaAdv = rtY->a_elecAngle; + } + + /* End of Switch: '/Switch_PhaAdv' */ /* End of Outputs for SubSystem: '/F02_Electrical_Angle_Calculation' */ } /* End of If: '/If1' */ - /* SwitchCase: '/Switch Case' incorporates: - * Constant: '/z_ctrlTypSel1' + /* SwitchCase: '/Switch Case' incorporates: + * Constant: '/z_ctrlTypSel1' */ - switch (rtP.z_ctrlTypSel) { + switch (rtP->z_ctrlTypSel) { case 1: - /* Outputs for IfAction SubSystem: '/F03_01_Pure_Trapezoidal_Method' incorporates: - * ActionPort: '/Action Port' + /* Outputs for IfAction SubSystem: '/F03_01_Pure_Trapezoidal_Method' incorporates: + * ActionPort: '/Action Port' */ - F03_01_Pure_Trapezoidal_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, - &rtDW.Merge1, &rtDW.Merge2); + /* PreLookup: '/a_trapElecAngle_XA' */ + rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 60U, + 6U, &rtb_r_phaAdvDC_XA_o2); - /* End of Outputs for SubSystem: '/F03_01_Pure_Trapezoidal_Method' */ + /* Interpolation_n-D: '/r_trapPhaA_M1' */ + rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaA_M1_Table); + + /* Interpolation_n-D: '/r_trapPhaB_M1' */ + rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaB_M1_Table); + + /* Interpolation_n-D: '/r_trapPhaC_M1' */ + rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaC_M1_Table); + + /* End of Outputs for SubSystem: '/F03_01_Pure_Trapezoidal_Method' */ break; case 2: - /* Outputs for IfAction SubSystem: '/F03_02_Sinusoidal_Method' incorporates: - * ActionPort: '/Action Port' + /* Outputs for IfAction SubSystem: '/F03_02_Sinusoidal_Method' incorporates: + * ActionPort: '/Action Port' */ - F03_02_Sinusoidal_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, &rtDW.Merge1, - &rtDW.Merge2); + /* PreLookup: '/a_sinElecAngle_XA' */ + rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 10U, + 36U, &rtb_r_phaAdvDC_XA_o2); - /* End of Outputs for SubSystem: '/F03_02_Sinusoidal_Method' */ + /* Interpolation_n-D: '/r_sinPhaA_M1' */ + rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaA_M1_Table); + + /* Interpolation_n-D: '/r_sinPhaB_M1' */ + rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaB_M1_Table); + + /* Interpolation_n-D: '/r_sinPhaC_M1' */ + rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaC_M1_Table); + + /* End of Outputs for SubSystem: '/F03_02_Sinusoidal_Method' */ break; case 3: - /* Outputs for IfAction SubSystem: '/F03_02_Sinusoidal3rd_Method' incorporates: - * ActionPort: '/Action Port' + /* Outputs for IfAction SubSystem: '/F03_03_Sinusoidal3rd_Method' incorporates: + * ActionPort: '/Action Port' */ - F03_02_Sinusoidal3rd_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, &rtDW.Merge1, - &rtDW.Merge2); + /* PreLookup: '/a_sinElecAngle_XA' */ + rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 10U, + 36U, &rtb_r_phaAdvDC_XA_o2); - /* End of Outputs for SubSystem: '/F03_02_Sinusoidal3rd_Method' */ + /* Interpolation_n-D: '/r_sin3PhaA_M1' */ + rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaA_M1_Table); + + /* Interpolation_n-D: '/r_sin3PhaB_M1' */ + rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaB_M1_Table); + + /* Interpolation_n-D: '/r_sin3PhaC_M1' */ + rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaC_M1_Table); + + /* End of Outputs for SubSystem: '/F03_03_Sinusoidal3rd_Method' */ break; } - /* End of SwitchCase: '/Switch Case' */ + /* End of SwitchCase: '/Switch Case' */ - /* Abs: '/Abs1' incorporates: - * Inport: '/r_DCLeft' + /* Abs: '/Abs1' incorporates: + * Inport: '/r_DC' + * Signum: '/Sign1' */ - if (rtU.r_DCLeft < 0) { - rtb_Switch1_idx_0 = -rtU.r_DCLeft; + if (rtU->r_DC < 0) { + rtb_Switch1_idx_0 = -rtU->r_DC; + rtb_Switch1_idx_1 = -1; } else { - rtb_Switch1_idx_0 = rtU.r_DCLeft; + rtb_Switch1_idx_0 = rtU->r_DC; + rtb_Switch1_idx_1 = (rtU->r_DC > 0); } - /* End of Abs: '/Abs1' */ + /* End of Abs: '/Abs1' */ - /* Switch: '/Switch1' incorporates: - * Constant: '/z_ctrlTypSel1' - * Constant: '/CTRL_COMM' - * Constant: '/r_commDCDeacv' - * Constant: '/vec_hallToPos' - * Inport: '/r_DCLeft' - * Logic: '/Logical Operator3' - * LookupNDDirect: '/z_commutMap_M1' - * Product: '/Divide2' - * Product: '/Divide4' - * RelationalOperator: '/Relational Operator1' - * RelationalOperator: '/Relational Operator2' - * Relay: '/Relay' - * Selector: '/Selector' + /* Signum: '/Sign' */ + if (rtDW->Switch2 < 0) { + rtb_Sum2_h = -1; + } else { + rtb_Sum2_h = (int8_T)(rtDW->Switch2 > 0); + } + + /* End of Signum: '/Sign' */ + + /* Switch: '/Switch1' incorporates: + * Constant: '/vec_hallToPos' + * Constant: '/CTRL_COMM' + * Constant: '/r_commDCDeacv' + * Constant: '/z_ctrlTypSel1' + * Inport: '/r_DC' + * Logic: '/Logical Operator2' + * LookupNDDirect: '/z_commutMap_M1' + * Product: '/Divide2' + * Product: '/Divide4' + * RelationalOperator: '/Relational Operator1' + * RelationalOperator: '/Relational Operator3' + * RelationalOperator: '/Relational Operator4' + * Relay: '/dz_counter' + * Relay: '/n_commDeacv' + * Selector: '/Selector' * - * About '/z_commutMap_M1': + * About '/z_commutMap_M1': * 2-dimensional Direct Look-Up returning a Column */ - if (rtDW.Relay_Mode && (rtb_Switch1_idx_0 > rtP.r_commDCDeacv) && - (rtP.z_ctrlTypSel != 0)) { - rtb_Switch1_idx_0 = rtU.r_DCLeft * rtDW.Merge; - rtb_Switch1_idx_1 = rtU.r_DCLeft * rtDW.Merge1; - rtb_Abs1 = rtU.r_DCLeft * rtDW.Merge2; + if ((rtP->z_ctrlTypSel != 0) && (rtb_Switch1_idx_0 > rtP->r_commDCDeacv) && + (rtb_Sum2_h == rtb_Switch1_idx_1) && rtDW->n_commDeacv_Mode && + (!rtDW->dz_counter_Mode)) { + rtb_Switch1_idx_0 = rtU->r_DC * rtDW->Merge; + rtb_Switch1_idx_1 = rtU->r_DC * rtDW->Merge1; + rtb_Abs5 = rtU->r_DC * rtDW->Merge2; } else { - if (rtConstP.pooled26[rtb_Sum] < 5) { - /* LookupNDDirect: '/z_commutMap_M1' incorporates: - * Constant: '/vec_hallToPos' - * Selector: '/Selector' + if (rtConstP.vec_hallToPos_Value[rtb_Sum] > 5) { + /* LookupNDDirect: '/z_commutMap_M1' * - * About '/z_commutMap_M1': + * About '/z_commutMap_M1': * 2-dimensional Direct Look-Up returning a Column */ - tmp = rtConstP.pooled26[rtb_Sum]; + rtb_Sum2_h = 5; + } else if (rtConstP.vec_hallToPos_Value[rtb_Sum] < 0) { + /* LookupNDDirect: '/z_commutMap_M1' + * + * About '/z_commutMap_M1': + * 2-dimensional Direct Look-Up returning a Column + */ + rtb_Sum2_h = 0; } else { - /* LookupNDDirect: '/z_commutMap_M1' + /* LookupNDDirect: '/z_commutMap_M1' incorporates: + * Constant: '/vec_hallToPos' + * Selector: '/Selector' * - * About '/z_commutMap_M1': + * About '/z_commutMap_M1': * 2-dimensional Direct Look-Up returning a Column */ - tmp = 5U; + rtb_Sum2_h = rtConstP.vec_hallToPos_Value[rtb_Sum]; } - /* LookupNDDirect: '/z_commutMap_M1' + /* LookupNDDirect: '/z_commutMap_M1' incorporates: + * Constant: '/vec_hallToPos' + * Selector: '/Selector' * - * About '/z_commutMap_M1': + * About '/z_commutMap_M1': * 2-dimensional Direct Look-Up returning a Column */ - rtb_Abs1 = tmp * 3; - rtb_Switch1_idx_0 = rtU.r_DCLeft * rtConstP.pooled18[rtb_Abs1]; - rtb_Switch1_idx_1 = rtConstP.pooled18[1 + rtb_Abs1] * rtU.r_DCLeft; - rtb_Abs1 = rtConstP.pooled18[2 + rtb_Abs1] * rtU.r_DCLeft; + rtb_Abs5 = rtb_Sum2_h * 3; + rtb_Switch1_idx_0 = rtU->r_DC * rtConstP.z_commutMap_M1_table[rtb_Abs5]; + rtb_Switch1_idx_1 = rtConstP.z_commutMap_M1_table[1 + rtb_Abs5] * rtU->r_DC; + rtb_Abs5 = rtConstP.z_commutMap_M1_table[2 + rtb_Abs5] * rtU->r_DC; } - /* End of Switch: '/Switch1' */ + /* End of Switch: '/Switch1' */ - /* Outport: '/DC_phaALeft' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' + /* Outport: '/DC_phaA' incorporates: + * Constant: '/Constant1' + * Product: '/Divide1' */ - rtY.DC_phaALeft = rtb_Switch1_idx_0 / 1000; + rtY->DC_phaA = rtb_Switch1_idx_0 / 1000; - /* Outport: '/DC_phaBLeft' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' + /* Outport: '/DC_phaB' incorporates: + * Constant: '/Constant1' + * Product: '/Divide1' */ - rtY.DC_phaBLeft = rtb_Switch1_idx_1 / 1000; + rtY->DC_phaB = rtb_Switch1_idx_1 / 1000; - /* Outport: '/DC_phaCLeft' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' + /* Update for UnitDelay: '/UnitDelay' incorporates: + * Inport: '/b_hallA ' */ - rtY.DC_phaCLeft = rtb_Abs1 / 1000; + rtDW->UnitDelay_DSTATE = rtU->b_hallA; - /* Sum: '/Sum' incorporates: - * Gain: '/g_Ha' - * Gain: '/g_Hb' - * Inport: '/b_hallARight' - * Inport: '/b_hallBRight' - * Inport: '/b_hallCRight' + /* Update for UnitDelay: '/UnitDelay1' incorporates: + * Inport: '/b_hallB' */ - rtb_Sum_a = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU.b_hallARight - << 2) + (uint8_T)(rtU.b_hallBRight << 1)) + rtU.b_hallCRight); + rtDW->UnitDelay1_DSTATE_i = rtU->b_hallB; - /* Logic: '/Logical Operator' incorporates: - * Inport: '/b_hallARight' - * Inport: '/b_hallBRight' - * Inport: '/b_hallCRight' - * UnitDelay: '/UnitDelay' - * UnitDelay: '/UnitDelay1' - * UnitDelay: '/UnitDelay2' + /* Update for UnitDelay: '/UnitDelay2' incorporates: + * Inport: '/b_hallC' */ - rtb_LogicalOperator = (boolean_T)((rtU.b_hallARight != 0) ^ (rtU.b_hallBRight - != 0) ^ (rtU.b_hallCRight != 0) ^ (rtDW.UnitDelay_DSTATE_j != 0) ^ - (rtDW.UnitDelay1_DSTATE_f != 0)) ^ (rtDW.UnitDelay2_DSTATE_b != 0); + rtDW->UnitDelay2_DSTATE_h = rtU->b_hallC; - /* Outputs for Enabled SubSystem: '/F01_03_Direction_Detection' */ + /* Update for UnitDelay: '/UnitDelay1' */ + rtDW->UnitDelay1_DSTATE = rtb_Sum1_a; - /* Selector: '/Selector' incorporates: - * Constant: '/vec_hallToPos' - * UnitDelay: '/UnitDelay1' + /* Update for UnitDelay: '/UnitDelay1' */ + rtDW->UnitDelay1_DSTATE_c = rtb_Sum1_a; + + /* Update for UnitDelay: '/UnitDelay2' */ + rtDW->UnitDelay2_DSTATE = rtb_Sum2; + + /* Outport: '/DC_phaC' incorporates: + * Constant: '/Constant1' + * Product: '/Divide1' */ - F01_03_Direction_Detection(rtb_LogicalOperator, rtConstP.pooled26[rtb_Sum_a], - rtDW.UnitDelay1_DSTATE_j, &rtDW.Switch2, &rtDW.UnitDelay1, - &rtDW.F01_03_Direction_Detection_j); - - /* End of Outputs for SubSystem: '/F01_03_Direction_Detection' */ - - /* Logic: '/Logical Operator3' incorporates: - * Constant: '/z_maxCntRst' - * RelationalOperator: '/Relational Operator1' - * UnitDelay: '/z_counterRawPrev' - */ - rtb_LogicalOperator3 = (rtb_LogicalOperator || (rtDW.z_counterRawPrev_DSTATE_p - > rtP.z_maxCntRst)); - - /* Outputs for Enabled SubSystem: '/Edge_counter' */ - - /* Logic: '/Logical Operator2' incorporates: - * UnitDelay: '/UnitDelay8' - */ - Edge_counter(!rtDW.UnitDelay8_DSTATE_p, rtb_LogicalOperator, rtDW.Switch2, - rtDW.UnitDelay1, &rtDW.Sum2_i, &rtDW.Edge_counter_l); - - /* End of Outputs for SubSystem: '/Edge_counter' */ - - /* Logic: '/Logical Operator5' incorporates: - * Constant: '/z_maxCntRst2' - * RelationalOperator: '/Relational Operator3' - * RelationalOperator: '/Relational Operator6' - * UnitDelay: '/z_counterRawPrev' - */ - rtDW.LogicalOperator5 = ((rtDW.Switch2 != rtDW.UnitDelay1) || - (rtDW.z_counterRawPrev_DSTATE_p > rtP.z_maxCntRst)); - - /* Outputs for Atomic SubSystem: '/rising_edge' */ - rising_edge_f(); - - /* End of Outputs for SubSystem: '/rising_edge' */ - - /* CombinatorialLogic: '/Logic' incorporates: - * Constant: '/z_nrEdgeSpdAcv' - * Memory: '/Memory' - * RelationalOperator: '/Relational Operator5' - */ - rtb_Switch1_idx_0 = (int32_T)(((((uint32_T)(rtDW.Sum2_i >= rtP.z_nrEdgeSpdAcv) - << 1) + rtDW.LogicalOperator_h) << 1) + rtDW.Memory_PreviousInput_i); - rtDW.Logic_j[0U] = rtConstP.pooled30[(uint32_T)rtb_Switch1_idx_0]; - rtDW.Logic_j[1U] = rtConstP.pooled30[rtb_Switch1_idx_0 + 8U]; - - /* Outputs for Atomic SubSystem: '/falling_edge2' */ - falling_edge2_b(); - - /* End of Outputs for SubSystem: '/falling_edge2' */ - - /* Switch: '/Switch' incorporates: - * Logic: '/Logical Operator1' - * Switch: '/Switch1' - * UnitDelay: '/z_counter2' - * UnitDelay: '/z_counterRawPrev' - */ - if (rtb_LogicalOperator3 && rtDW.Logic_j[0]) { - rtb_Switch_b = rtDW.z_counterRawPrev_DSTATE_p; - } else if (rtDW.LogicalOperator_h) { - /* Switch: '/Switch1' incorporates: - * Constant: '/z_maxCntRst1' - */ - rtb_Switch_b = rtP.z_maxCntRst; - } else { - rtb_Switch_b = rtDW.z_counter2_DSTATE_h; - } - - /* End of Switch: '/Switch' */ - - /* Outputs for Triggered SubSystem: '/Motor_Speed_Calculation' */ - - /* Outport: '/n_motRight' */ - Motor_Speed_Calculation(rtb_LogicalOperator3, rtb_Switch_b, rtDW.Switch2, - &rtY.n_motRight, &rtDW.Motor_Speed_Calculation_k, - &rtPrevZCX.Motor_Speed_Calculation_k); - - /* End of Outputs for SubSystem: '/Motor_Speed_Calculation' */ - - /* Abs: '/Abs5' incorporates: - * Outport: '/n_motRight' - */ - if (rtY.n_motRight < 0) { - rtb_Abs1 = -rtY.n_motRight; - } else { - rtb_Abs1 = rtY.n_motRight; - } - - /* End of Abs: '/Abs5' */ - - /* Relay: '/Relay' */ - if (rtb_Abs1 >= rtP.n_commDeacvHi) { - rtDW.Relay_Mode_m = true; - } else { - if (rtb_Abs1 <= rtP.n_commAcvLo) { - rtDW.Relay_Mode_m = false; - } - } - - /* Switch: '/Switch1' incorporates: - * Constant: '/Constant23' - * UnitDelay: '/UnitDelay1' - */ - if (rtb_LogicalOperator3) { - rtb_Sum1_c = 0; - } else { - rtb_Sum1_c = rtDW.UnitDelay1_DSTATE_k; - } - - /* End of Switch: '/Switch1' */ - - /* Sum: '/Sum1' */ - rtb_Sum1_c++; - - /* If: '/If1' incorporates: - * Constant: '/z_ctrlTypSel1' - * Constant: '/vec_hallToPos' - * Inport: '/r_DCRight' - * Outport: '/a_elecAngleRight' - * Selector: '/Selector' - */ - rtPrevAction = rtDW.If1_ActiveSubsystem_j; - rtAction = -1; - if (rtP.z_ctrlTypSel != 0) { - rtAction = 0; - } - - rtDW.If1_ActiveSubsystem_j = rtAction; - if ((rtPrevAction != rtAction) && (rtPrevAction == 0)) { - F02_Electrical_Angle_Ca_Disable(&rtDW.Switch_PhaAdv, &rtY.a_elecAngleRight); - } - - if (rtAction == 0) { - /* Outputs for IfAction SubSystem: '/F02_Electrical_Angle_Calculation' incorporates: - * ActionPort: '/Action Port' - */ - F02_Electrical_Angle_Calculatio(rtU.r_DCRight, rtConstP.pooled26[rtb_Sum_a], - rtDW.Switch2, rtb_Switch_b, rtb_Sum1_c, &rtDW.Switch_PhaAdv, - &rtY.a_elecAngleRight); - - /* End of Outputs for SubSystem: '/F02_Electrical_Angle_Calculation' */ - } - - /* End of If: '/If1' */ - - /* SwitchCase: '/Switch Case' incorporates: - * Constant: '/z_ctrlTypSel1' - */ - switch (rtP.z_ctrlTypSel) { - case 1: - /* Outputs for IfAction SubSystem: '/F03_01_Pure_Trapezoidal_Method' incorporates: - * ActionPort: '/Action Port' - */ - F03_01_Pure_Trapezoidal_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, - &rtDW.Merge1_m, &rtDW.Merge2_d); - - /* End of Outputs for SubSystem: '/F03_01_Pure_Trapezoidal_Method' */ - break; - - case 2: - /* Outputs for IfAction SubSystem: '/F03_02_Sinusoidal_Method' incorporates: - * ActionPort: '/Action Port' - */ - F03_02_Sinusoidal_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, &rtDW.Merge1_m, - &rtDW.Merge2_d); - - /* End of Outputs for SubSystem: '/F03_02_Sinusoidal_Method' */ - break; - - case 3: - /* Outputs for IfAction SubSystem: '/F03_02_Sinusoidal3rd_Method' incorporates: - * ActionPort: '/Action Port' - */ - F03_02_Sinusoidal3rd_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, - &rtDW.Merge1_m, &rtDW.Merge2_d); - - /* End of Outputs for SubSystem: '/F03_02_Sinusoidal3rd_Method' */ - break; - } - - /* End of SwitchCase: '/Switch Case' */ - - /* Abs: '/Abs1' incorporates: - * Inport: '/r_DCRight' - */ - if (rtU.r_DCRight < 0) { - rtb_Switch1_idx_0 = -rtU.r_DCRight; - } else { - rtb_Switch1_idx_0 = rtU.r_DCRight; - } - - /* End of Abs: '/Abs1' */ - - /* Switch: '/Switch1' incorporates: - * Constant: '/z_ctrlTypSel1' - * Constant: '/CTRL_COMM' - * Constant: '/r_commDCDeacv' - * Constant: '/vec_hallToPos' - * Inport: '/r_DCRight' - * Logic: '/Logical Operator3' - * LookupNDDirect: '/z_commutMap_M1' - * Product: '/Divide2' - * Product: '/Divide4' - * RelationalOperator: '/Relational Operator1' - * RelationalOperator: '/Relational Operator2' - * Relay: '/Relay' - * Selector: '/Selector' - * - * About '/z_commutMap_M1': - * 2-dimensional Direct Look-Up returning a Column - */ - if (rtDW.Relay_Mode_m && (rtb_Switch1_idx_0 > rtP.r_commDCDeacv) && - (rtP.z_ctrlTypSel != 0)) { - rtb_Switch1_idx_0 = rtU.r_DCRight * rtDW.Merge_j; - rtb_Switch1_idx_1 = rtU.r_DCRight * rtDW.Merge1_m; - rtb_Abs1 = rtU.r_DCRight * rtDW.Merge2_d; - } else { - if (rtConstP.pooled26[rtb_Sum_a] < 5) { - /* LookupNDDirect: '/z_commutMap_M1' incorporates: - * Constant: '/vec_hallToPos' - * Selector: '/Selector' - * - * About '/z_commutMap_M1': - * 2-dimensional Direct Look-Up returning a Column - */ - tmp = rtConstP.pooled26[rtb_Sum_a]; - } else { - /* LookupNDDirect: '/z_commutMap_M1' - * - * About '/z_commutMap_M1': - * 2-dimensional Direct Look-Up returning a Column - */ - tmp = 5U; - } - - /* LookupNDDirect: '/z_commutMap_M1' - * - * About '/z_commutMap_M1': - * 2-dimensional Direct Look-Up returning a Column - */ - rtb_Abs1 = tmp * 3; - rtb_Switch1_idx_0 = rtU.r_DCRight * rtConstP.pooled18[rtb_Abs1]; - rtb_Switch1_idx_1 = rtConstP.pooled18[1 + rtb_Abs1] * rtU.r_DCRight; - rtb_Abs1 = rtConstP.pooled18[2 + rtb_Abs1] * rtU.r_DCRight; - } - - /* End of Switch: '/Switch1' */ - - /* Outport: '/DC_phaARight' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' - */ - rtY.DC_phaARight = rtb_Switch1_idx_0 / 1000; - - /* Outport: '/DC_phaBRight' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' - */ - rtY.DC_phaBRight = rtb_Switch1_idx_1 / 1000; - - /* Update for UnitDelay: '/UnitDelay' incorporates: - * Inport: '/b_hallALeft ' - */ - rtDW.UnitDelay_DSTATE = rtU.b_hallALeft; - - /* Update for UnitDelay: '/UnitDelay1' incorporates: - * Inport: '/b_hallBLeft' - */ - rtDW.UnitDelay1_DSTATE_p = rtU.b_hallBLeft; - - /* Update for UnitDelay: '/UnitDelay2' incorporates: - * Inport: '/b_hallCLeft' - */ - rtDW.UnitDelay2_DSTATE = rtU.b_hallCLeft; - - /* Update for UnitDelay: '/UnitDelay1' incorporates: - * Constant: '/vec_hallToPos' - * Selector: '/Selector' - */ - rtDW.UnitDelay1_DSTATE_g = rtConstP.pooled26[rtb_Sum]; - - /* Update for UnitDelay: '/z_counterRawPrev' */ - rtDW.z_counterRawPrev_DSTATE = rtb_Sum1; - - /* Update for UnitDelay: '/UnitDelay8' */ - rtDW.UnitDelay8_DSTATE = rtDW.Logic[0]; - - /* Update for Memory: '/Memory' */ - rtDW.Memory_PreviousInput = rtDW.Logic[0]; - - /* Update for UnitDelay: '/z_counter2' */ - rtDW.z_counter2_DSTATE = rtb_Switch; - - /* Update for UnitDelay: '/UnitDelay1' */ - rtDW.UnitDelay1_DSTATE = rtb_Sum1; - - /* Update for UnitDelay: '/UnitDelay' incorporates: - * Inport: '/b_hallARight' - */ - rtDW.UnitDelay_DSTATE_j = rtU.b_hallARight; - - /* Update for UnitDelay: '/UnitDelay1' incorporates: - * Inport: '/b_hallBRight' - */ - rtDW.UnitDelay1_DSTATE_f = rtU.b_hallBRight; - - /* Update for UnitDelay: '/UnitDelay2' incorporates: - * Inport: '/b_hallCRight' - */ - rtDW.UnitDelay2_DSTATE_b = rtU.b_hallCRight; - - /* Update for UnitDelay: '/UnitDelay1' incorporates: - * Constant: '/vec_hallToPos' - * Selector: '/Selector' - */ - rtDW.UnitDelay1_DSTATE_j = rtConstP.pooled26[rtb_Sum_a]; - - /* Update for UnitDelay: '/z_counterRawPrev' */ - rtDW.z_counterRawPrev_DSTATE_p = rtb_Sum1_c; - - /* Update for UnitDelay: '/UnitDelay8' */ - rtDW.UnitDelay8_DSTATE_p = rtDW.Logic_j[0]; - - /* Update for Memory: '/Memory' */ - rtDW.Memory_PreviousInput_i = rtDW.Logic_j[0]; - - /* Update for UnitDelay: '/z_counter2' */ - rtDW.z_counter2_DSTATE_h = rtb_Switch_b; - - /* Update for UnitDelay: '/UnitDelay1' */ - rtDW.UnitDelay1_DSTATE_k = rtb_Sum1_c; - - /* Outport: '/DC_phaCRight' incorporates: - * Constant: '/Constant1' - * Product: '/Divide1' - */ - rtY.DC_phaCRight = rtb_Abs1 / 1000; + rtY->DC_phaC = rtb_Abs5 / 1000; /* End of Outputs for SubSystem: '/BLDC_controller' */ + + /* Outport: '/n_mot' */ + rtY->n_mot = rtb_Sum2; } /* Model initialize function */ -void BLDC_controller_initialize(void) +void BLDC_controller_initialize(RT_MODEL *const rtM) { + DW *rtDW = ((DW *) rtM->dwork); + /* Start for Atomic SubSystem: '/BLDC_controller' */ /* Start for If: '/If1' */ - rtDW.If1_ActiveSubsystem = -1; - - /* Start for If: '/If1' */ - rtDW.If1_ActiveSubsystem_j = -1; + rtDW->If1_ActiveSubsystem = -1; /* End of Start for SubSystem: '/BLDC_controller' */ - rtPrevZCX.Motor_Speed_Calculation_k.Motor_Speed_Calculation_Trig_ZC = - POS_ZCSIG; - rtPrevZCX.Motor_Speed_Calculation_m.Motor_Speed_Calculation_Trig_ZC = - POS_ZCSIG; /* SystemInitialize for Atomic SubSystem: '/BLDC_controller' */ - /* InitializeConditions for UnitDelay: '/z_counter2' */ - rtDW.z_counter2_DSTATE = rtP.z_maxCntRst; + /* InitializeConditions for UnitDelay: '/UnitDelay1' */ + rtDW->UnitDelay1_DSTATE = 1500; - /* InitializeConditions for UnitDelay: '/z_counter2' */ - rtDW.z_counter2_DSTATE_h = rtP.z_maxCntRst; + /* SystemInitialize for IfAction SubSystem: '/Counter_Hold_and_Error_Calculation' */ + /* InitializeConditions for UnitDelay: '/z_counter2' */ + rtDW->z_counter2_DSTATE = 1500; + /* SystemInitialize for Outport: '/z_counter' */ + rtDW->z_counterRawPrev = 1500; + + /* End of SystemInitialize for SubSystem: '/Counter_Hold_and_Error_Calculation' */ /* End of SystemInitialize for SubSystem: '/BLDC_controller' */ } diff --git a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.h b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.h index 8c99184..9d9b319 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.h +++ b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.h @@ -7,9 +7,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.817 + * Model version : 1.877 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue May 28 19:55:33 2019 + * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -24,302 +24,174 @@ #ifndef RTW_HEADER_BLDC_controller_h_ #define RTW_HEADER_BLDC_controller_h_ #include "rtwtypes.h" -#include "zero_crossing_types.h" #ifndef BLDC_controller_COMMON_INCLUDES_ # define BLDC_controller_COMMON_INCLUDES_ #include "rtwtypes.h" -#include "zero_crossing_types.h" #endif /* BLDC_controller_COMMON_INCLUDES_ */ /* Macros for accessing real-time model data structure */ -/* Block signals and states (auto storage) for system '/F01_03_Direction_Detection' */ -typedef struct { - int8_T UnitDelay1_DSTATE; /* '/UnitDelay1' */ -} DW_F01_03_Direction_Detection; - -/* Block signals and states (auto storage) for system '/Edge_counter' */ -typedef struct { - uint8_T UnitDelay1_DSTATE; /* '/UnitDelay1' */ - boolean_T Edge_counter_MODE; /* '/Edge_counter' */ -} DW_Edge_counter; - -/* Block signals and states (auto storage) for system '/Motor_Speed_Calculation' */ -typedef struct { - int32_T UnitDelay5_DSTATE; /* '/UnitDelay5' */ - int32_T UnitDelay1_DSTATE; /* '/UnitDelay1' */ -} DW_Motor_Speed_Calculation; - -/* Zero-crossing (trigger) state for system '/Motor_Speed_Calculation' */ -typedef struct { - ZCSigState Motor_Speed_Calculation_Trig_ZC;/* '/Motor_Speed_Calculation' */ -} ZCE_Motor_Speed_Calculation; +/* Forward declaration for rtModel */ +typedef struct tag_RTM RT_MODEL; /* Block signals and states (auto storage) for system '' */ typedef struct { - DW_Motor_Speed_Calculation Motor_Speed_Calculation_k;/* '/Motor_Speed_Calculation' */ - DW_Edge_counter Edge_counter_l; /* '/Edge_counter' */ - DW_F01_03_Direction_Detection F01_03_Direction_Detection_j;/* '/F01_03_Direction_Detection' */ - DW_Motor_Speed_Calculation Motor_Speed_Calculation_m;/* '/Motor_Speed_Calculation' */ - DW_Edge_counter Edge_counter_f; /* '/Edge_counter' */ - DW_F01_03_Direction_Detection F01_03_Direction_Detection_o;/* '/F01_03_Direction_Detection' */ - int32_T Switch_PhaAdv; /* '/Switch_PhaAdv' */ - int32_T Switch_PhaAdv_a; /* '/Switch_PhaAdv' */ - int16_T Merge; /* '/Merge' */ - int16_T Merge1; /* '/Merge1' */ - int16_T Merge2; /* '/Merge2' */ - int16_T Merge_j; /* '/Merge' */ - int16_T Merge1_m; /* '/Merge1' */ - int16_T Merge2_d; /* '/Merge2' */ - int16_T z_counterRawPrev_DSTATE; /* '/z_counterRawPrev' */ - int16_T z_counter2_DSTATE; /* '/z_counter2' */ - int16_T UnitDelay1_DSTATE; /* '/UnitDelay1' */ - int16_T z_counterRawPrev_DSTATE_p; /* '/z_counterRawPrev' */ - int16_T z_counter2_DSTATE_h; /* '/z_counter2' */ - int16_T UnitDelay1_DSTATE_k; /* '/UnitDelay1' */ - int8_T UnitDelay1; /* '/UnitDelay1' */ - int8_T Switch2; /* '/Switch2' */ - int8_T UnitDelay1_k; /* '/UnitDelay1' */ - int8_T Switch2_e; /* '/Switch2' */ + int32_T Switch_PhaAdv; /* '/Switch_PhaAdv' */ + int32_T UnitDelay2_DSTATE; /* '/UnitDelay2' */ + int16_T Merge; /* '/Merge' */ + int16_T Merge1; /* '/Merge1' */ + int16_T Merge2; /* '/Merge2' */ + int16_T z_counterRawPrev; /* '/z_counterRawPrev' */ + int16_T Sum4; /* '/Sum4' */ + int16_T UnitDelay1_DSTATE; /* '/UnitDelay1' */ + int16_T UnitDelay1_DSTATE_c; /* '/UnitDelay1' */ + int16_T z_counter2_DSTATE; /* '/z_counter2' */ + int8_T UnitDelay1; /* '/UnitDelay1' */ + int8_T Switch2; /* '/Switch2' */ + int8_T UnitDelay2_DSTATE_i; /* '/UnitDelay2' */ int8_T If1_ActiveSubsystem; /* '/If1' */ - int8_T If1_ActiveSubsystem_j; /* '/If1' */ - uint8_T Sum2_i; /* '/Sum2' */ - uint8_T Sum2_l; /* '/Sum2' */ - uint8_T UnitDelay_DSTATE; /* '/UnitDelay' */ - uint8_T UnitDelay1_DSTATE_p; /* '/UnitDelay1' */ - uint8_T UnitDelay2_DSTATE; /* '/UnitDelay2' */ - uint8_T UnitDelay1_DSTATE_g; /* '/UnitDelay1' */ - uint8_T UnitDelay_DSTATE_j; /* '/UnitDelay' */ - uint8_T UnitDelay1_DSTATE_f; /* '/UnitDelay1' */ - uint8_T UnitDelay2_DSTATE_b; /* '/UnitDelay2' */ - uint8_T UnitDelay1_DSTATE_j; /* '/UnitDelay1' */ - boolean_T Logic[2]; /* '/Logic' */ - boolean_T Logic_j[2]; /* '/Logic' */ - boolean_T LogicalOperator; /* '/Logical Operator' */ - boolean_T LogicalOperator5; /* '/Logical Operator5' */ - boolean_T LogicalOperator_h; /* '/Logical Operator' */ - boolean_T UnitDelay8_DSTATE; /* '/UnitDelay8' */ - boolean_T UnitDelay8_DSTATE_p; /* '/UnitDelay8' */ - boolean_T UnitDelay_DSTATE_k; /* '/UnitDelay' */ - boolean_T UnitDelay_DSTATE_i; /* '/UnitDelay' */ - boolean_T UnitDelay_DSTATE_l; /* '/UnitDelay' */ - boolean_T UnitDelay_DSTATE_b; /* '/UnitDelay' */ - boolean_T Memory_PreviousInput; /* '/Memory' */ - boolean_T Relay_Mode; /* '/Relay' */ - boolean_T Memory_PreviousInput_i; /* '/Memory' */ - boolean_T Relay_Mode_m; /* '/Relay' */ + uint8_T UnitDelay_DSTATE; /* '/UnitDelay' */ + uint8_T UnitDelay1_DSTATE_i; /* '/UnitDelay1' */ + uint8_T UnitDelay2_DSTATE_h; /* '/UnitDelay2' */ + boolean_T n_commDeacv_Mode; /* '/n_commDeacv' */ + boolean_T dz_counter_Mode; /* '/dz_counter' */ } DW; -/* Zero-crossing (trigger) state */ -typedef struct { - ZCE_Motor_Speed_Calculation Motor_Speed_Calculation_k;/* '/Motor_Speed_Calculation' */ - ZCE_Motor_Speed_Calculation Motor_Speed_Calculation_m;/* '/Motor_Speed_Calculation' */ -} PrevZCX; - /* Constant parameters (auto storage) */ typedef struct { - /* Pooled Parameter (Expression: r_trapPhaA_M1) - * Referenced by: - * '/r_trapPhaA_M1' - * '/r_trapPhaA_M1' + /* Computed Parameter: r_trapPhaA_M1_Table + * Referenced by: '/r_trapPhaA_M1' */ - int16_T pooled9[7]; + int16_T r_trapPhaA_M1_Table[7]; - /* Pooled Parameter (Expression: r_trapPhaB_M1) - * Referenced by: - * '/r_trapPhaB_M1' - * '/r_trapPhaB_M1' + /* Computed Parameter: r_trapPhaB_M1_Table + * Referenced by: '/r_trapPhaB_M1' */ - int16_T pooled10[7]; + int16_T r_trapPhaB_M1_Table[7]; - /* Pooled Parameter (Expression: r_trapPhaC_M1) - * Referenced by: - * '/r_trapPhaC_M1' - * '/r_trapPhaC_M1' + /* Computed Parameter: r_trapPhaC_M1_Table + * Referenced by: '/r_trapPhaC_M1' */ - int16_T pooled11[7]; + int16_T r_trapPhaC_M1_Table[7]; - /* Pooled Parameter (Expression: r_sinPhaA_M1) - * Referenced by: - * '/r_sinPhaA_M1' - * '/r_sinPhaA_M1' + /* Computed Parameter: r_sinPhaA_M1_Table + * Referenced by: '/r_sinPhaA_M1' */ - int16_T pooled12[37]; + int16_T r_sinPhaA_M1_Table[37]; - /* Pooled Parameter (Expression: r_sinPhaB_M1) - * Referenced by: - * '/r_sinPhaB_M1' - * '/r_sinPhaB_M1' + /* Computed Parameter: r_sinPhaB_M1_Table + * Referenced by: '/r_sinPhaB_M1' */ - int16_T pooled13[37]; + int16_T r_sinPhaB_M1_Table[37]; - /* Pooled Parameter (Expression: r_sinPhaC_M1) - * Referenced by: - * '/r_sinPhaC_M1' - * '/r_sinPhaC_M1' + /* Computed Parameter: r_sinPhaC_M1_Table + * Referenced by: '/r_sinPhaC_M1' */ - int16_T pooled14[37]; + int16_T r_sinPhaC_M1_Table[37]; - /* Pooled Parameter (Expression: r_sin3PhaA_M1) - * Referenced by: - * '/r_sin3PhaA_M1' - * '/r_sin3PhaA_M1' + /* Computed Parameter: r_sin3PhaA_M1_Table + * Referenced by: '/r_sin3PhaA_M1' */ - int16_T pooled15[37]; + int16_T r_sin3PhaA_M1_Table[37]; - /* Pooled Parameter (Expression: r_sin3PhaB_M1) - * Referenced by: - * '/r_sin3PhaB_M1' - * '/r_sin3PhaB_M1' + /* Computed Parameter: r_sin3PhaB_M1_Table + * Referenced by: '/r_sin3PhaB_M1' */ - int16_T pooled16[37]; + int16_T r_sin3PhaB_M1_Table[37]; - /* Pooled Parameter (Expression: r_sin3PhaC_M1) - * Referenced by: - * '/r_sin3PhaC_M1' - * '/r_sin3PhaC_M1' + /* Computed Parameter: r_sin3PhaC_M1_Table + * Referenced by: '/r_sin3PhaC_M1' */ - int16_T pooled17[37]; + int16_T r_sin3PhaC_M1_Table[37]; - /* Pooled Parameter (Expression: z_commutMap_M1) - * Referenced by: - * '/z_commutMap_M1' - * '/z_commutMap_M1' + /* Computed Parameter: z_commutMap_M1_table + * Referenced by: '/z_commutMap_M1' */ - int16_T pooled18[18]; + int16_T z_commutMap_M1_table[18]; - /* Pooled Parameter (Expression: vec_hallToPos) - * Referenced by: - * '/vec_hallToPos' - * '/vec_hallToPos' + /* Computed Parameter: vec_hallToPos_Value + * Referenced by: '/vec_hallToPos' */ - uint8_T pooled26[8]; - - /* Pooled Parameter (Expression: [0 1;1 0;0 1;0 1;1 0;1 0;0 0;0 0]) - * Referenced by: - * '/Logic' - * '/Logic' - */ - boolean_T pooled30[16]; + int8_T vec_hallToPos_Value[8]; } ConstP; /* External inputs (root inport signals with auto storage) */ typedef struct { - uint8_T b_hallALeft; /* '/b_hallALeft ' */ - uint8_T b_hallBLeft; /* '/b_hallBLeft' */ - uint8_T b_hallCLeft; /* '/b_hallCLeft' */ - int32_T r_DCLeft; /* '/r_DCLeft' */ - uint8_T b_hallARight; /* '/b_hallARight' */ - uint8_T b_hallBRight; /* '/b_hallBRight' */ - uint8_T b_hallCRight; /* '/b_hallCRight' */ - int32_T r_DCRight; /* '/r_DCRight' */ + uint8_T b_hallA; /* '/b_hallA ' */ + uint8_T b_hallB; /* '/b_hallB' */ + uint8_T b_hallC; /* '/b_hallC' */ + int32_T r_DC; /* '/r_DC' */ } ExtU; /* External outputs (root outports fed by signals with auto storage) */ typedef struct { - int32_T DC_phaALeft; /* '/DC_phaALeft' */ - int32_T DC_phaBLeft; /* '/DC_phaBLeft' */ - int32_T DC_phaCLeft; /* '/DC_phaCLeft' */ - int32_T n_motLeft; /* '/n_motLeft' */ - int32_T a_elecAngleLeft; /* '/a_elecAngleLeft' */ - int32_T DC_phaARight; /* '/DC_phaARight' */ - int32_T DC_phaBRight; /* '/DC_phaBRight' */ - int32_T DC_phaCRight; /* '/DC_phaCRight' */ - int32_T n_motRight; /* '/n_motRight' */ - int32_T a_elecAngleRight; /* '/a_elecAngleRight' */ + int32_T DC_phaA; /* '/DC_phaA' */ + int32_T DC_phaB; /* '/DC_phaB' */ + int32_T DC_phaC; /* '/DC_phaC' */ + int32_T n_mot; /* '/n_mot' */ + int32_T a_elecAngle; /* '/a_elecAngle' */ } ExtY; /* Parameters (auto storage) */ struct P_ { int32_T cf_speedCoef; /* Variable: cf_speedCoef - * Referenced by: - * '/cf_spdCoef' - * '/cf_spdCoef' + * Referenced by: '/cf_spdCoef' + */ + int32_T cf_speedFilt; /* Variable: cf_speedFilt + * Referenced by: '/cf_speedFilt' */ int32_T n_commAcvLo; /* Variable: n_commAcvLo - * Referenced by: - * '/Relay' - * '/Relay' + * Referenced by: '/n_commDeacv' */ int32_T n_commDeacvHi; /* Variable: n_commDeacvHi - * Referenced by: - * '/Relay' - * '/Relay' + * Referenced by: '/n_commDeacv' */ int32_T r_commDCDeacv; /* Variable: r_commDCDeacv - * Referenced by: - * '/r_commDCDeacv' - * '/r_commDCDeacv' + * Referenced by: '/r_commDCDeacv' */ int32_T r_phaAdvDC_XA[11]; /* Variable: r_phaAdvDC_XA - * Referenced by: - * '/r_phaAdvDC_XA' - * '/r_phaAdvDC_XA' + * Referenced by: '/r_phaAdvDC_XA' */ int16_T a_phaAdv_M1[11]; /* Variable: a_phaAdv_M1 - * Referenced by: - * '/a_phaAdv_M2' - * '/a_phaAdv_M2' + * Referenced by: '/a_phaAdv_M2' */ - int16_T z_maxCntRst; /* Variable: z_maxCntRst - * Referenced by: - * '/z_maxCntRst' - * '/z_maxCntRst1' - * '/z_maxCntRst2' - * '/z_counter2' - * '/z_maxCntRst' - * '/z_maxCntRst1' - * '/z_maxCntRst2' - * '/z_counter2' - * '/z_maxCntRst' - * '/z_maxCntRst' + int16_T dz_counterHi; /* Variable: dz_counterHi + * Referenced by: '/dz_counter' + */ + int16_T dz_counterLo; /* Variable: dz_counterLo + * Referenced by: '/dz_counter' */ uint8_T z_ctrlTypSel; /* Variable: z_ctrlTypSel - * Referenced by: - * '/z_ctrlTypSel1' - * '/z_ctrlTypSel1' - */ - uint8_T z_nrEdgeSpdAcv; /* Variable: z_nrEdgeSpdAcv - * Referenced by: - * '/z_nrEdgeSpdAcv' - * '/z_nrEdgeSpdAcv' + * Referenced by: '/z_ctrlTypSel1' */ boolean_T b_phaAdvEna; /* Variable: b_phaAdvEna - * Referenced by: - * '/a_elecPeriod1' - * '/a_elecPeriod1' + * Referenced by: '/a_elecPeriod1' */ }; /* Parameters (auto storage) */ typedef struct P_ P; -/* Block parameters (auto storage) */ -extern P rtP; - -/* Block signals and states (auto storage) */ -extern DW rtDW; - -/* External inputs (root inport signals with auto storage) */ -extern ExtU rtU; - -/* External outputs (root outports fed by signals with auto storage) */ -extern ExtY rtY; +/* Real-time Model Data Structure */ +struct tag_RTM { + P *defaultParam; + ExtU *inputs; + ExtY *outputs; + DW *dwork; +}; /* Constant parameters (auto storage) */ extern const ConstP rtConstP; /* Model entry point functions */ -extern void BLDC_controller_initialize(void); -extern void BLDC_controller_step(void); +extern void BLDC_controller_initialize(RT_MODEL *const rtM); +extern void BLDC_controller_step(RT_MODEL *const rtM); /*- * These blocks were eliminated from the model due to optimizations: * - * Block '/Scope2' : Unused code path elimination - * Block '/Scope' : Unused code path elimination - * Block '/Scope2' : Unused code path elimination - * Block '/Scope' : Unused code path elimination + * Block '/Scope2' : Unused code path elimination + * Block '/Scope' : Unused code path elimination */ /*- @@ -341,92 +213,28 @@ extern void BLDC_controller_step(void); * * '' : 'BLDCmotorControl_R2017b' * '' : 'BLDCmotorControl_R2017b/BLDC_controller' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log3' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log4' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log5' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log7' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log8' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log3' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_01_Edge_Detector' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_02_Position_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_03_Direction_Detection' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_01_Edge_Detector/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_02_Position_Calculation/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_03_Direction_Detection/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/S-R Flip-Flop' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/falling_edge2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rising_edge' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_Delay' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log3' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log4' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log5' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter/rst_Delay' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_02_Sinusoidal3rd_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log3' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_01_Edge_Detector' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_02_Position_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_03_Direction_Detection' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_01_Edge_Detector/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_02_Position_Calculation/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_03_Direction_Detection/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/S-R Flip-Flop' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/falling_edge2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rising_edge' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_Delay' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log3' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log4' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log5' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter/rst_Delay' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_02_Sinusoidal3rd_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log6' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log1' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log2' - * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log6' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log1' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log2' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log3' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log6' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F02_Electrical_Angle_Calculation' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F04_Control_Type_Management' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_01_Edge_Detector' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_02_Position_Calculation' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_03_Direction_Detection' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Counter_Hold_and_Error_Calculation' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_DelayLim' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_03_Sinusoidal3rd_Method' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log1' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log2' + * '' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log6' */ #endif /* RTW_HEADER_BLDC_controller_h_ */ diff --git a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.mk b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.mk index 2520b0d..542deac 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.mk +++ b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller.mk @@ -2,7 +2,7 @@ ## Makefile generated for Simulink model 'BLDC_controller'. ## ## Makefile : BLDC_controller.mk -## Generated on : Tue May 28 18:31:31 2019 +## Generated on : Wed Jun 05 20:33:43 2019 ## MATLAB Coder version: 3.4 (R2017b) ## ## Build Info: @@ -32,7 +32,7 @@ MATLAB_ROOT = C:/PROGRA~1/MATLAB/R2017b MATLAB_BIN = C:/PROGRA~1/MATLAB/R2017b/bin MATLAB_ARCH_BIN = $(MATLAB_BIN)/win64 MASTER_ANCHOR_DIR = -START_DIR = D:/Work_home/01_Motor_control +START_DIR = D:/git/hoverboard-firmware-hack/01_Matlab ARCH = win64 SOLVER = SOLVER_OBJ = @@ -215,7 +215,7 @@ INCLUDES = $(INCLUDES_BUILDINFO) ## DEFINES ########################################################################### -DEFINES_BUILD_ARGS = -DTERMFCN=0 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 +DEFINES_BUILD_ARGS = -DTERMFCN=0 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=1 -DINTEGER_CODE=0 -DMT=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 DEFINES_IMPLIED = -DTID01EQ=0 DEFINES_STANDARD = -DMODEL=BLDC_controller -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO diff --git a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller_data.c b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller_data.c index 0458de2..d5a791c 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller_data.c +++ b/01_Matlab/BLDC_controller_ert_rtw/BLDC_controller_data.c @@ -7,9 +7,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.817 + * Model version : 1.877 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue May 28 19:55:33 2019 + * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -23,185 +23,75 @@ #include "BLDC_controller.h" -/* Block parameters (auto storage) */ -P rtP = { - /* Variable: cf_speedCoef - * Referenced by: - * '/cf_spdCoef' - * '/cf_spdCoef' - */ - 66667, - - /* Variable: n_commAcvLo - * Referenced by: - * '/Relay' - * '/Relay' - */ - 100, - - /* Variable: n_commDeacvHi - * Referenced by: - * '/Relay' - * '/Relay' - */ - 180, - - /* Variable: r_commDCDeacv - * Referenced by: - * '/r_commDCDeacv' - * '/r_commDCDeacv' - */ - 70, - - /* Variable: r_phaAdvDC_XA - * Referenced by: - * '/r_phaAdvDC_XA' - * '/r_phaAdvDC_XA' - */ - { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }, - - /* Variable: a_phaAdv_M1 - * Referenced by: - * '/a_phaAdv_M2' - * '/a_phaAdv_M2' - */ - { 0, 0, 7, 2, 2, 2, 4, 5, 9, 16, 25 }, - - /* Variable: z_maxCntRst - * Referenced by: - * '/z_maxCntRst' - * '/z_maxCntRst1' - * '/z_maxCntRst2' - * '/z_counter2' - * '/z_maxCntRst' - * '/z_maxCntRst1' - * '/z_maxCntRst2' - * '/z_counter2' - * '/z_maxCntRst' - * '/z_maxCntRst' - */ - 2000, - - /* Variable: z_ctrlTypSel - * Referenced by: - * '/z_ctrlTypSel1' - * '/z_ctrlTypSel1' - */ - 3U, - - /* Variable: z_nrEdgeSpdAcv - * Referenced by: - * '/z_nrEdgeSpdAcv' - * '/z_nrEdgeSpdAcv' - */ - 3U, - - /* Variable: b_phaAdvEna - * Referenced by: - * '/a_elecPeriod1' - * '/a_elecPeriod1' - */ - 1 -}; - /* Constant parameters (auto storage) */ const ConstP rtConstP = { - /* Pooled Parameter (Expression: r_trapPhaA_M1) - * Referenced by: - * '/r_trapPhaA_M1' - * '/r_trapPhaA_M1' + /* Computed Parameter: r_trapPhaA_M1_Table + * Referenced by: '/r_trapPhaA_M1' */ { 1000, 1000, 1000, -1000, -1000, -1000, 1000 }, - /* Pooled Parameter (Expression: r_trapPhaB_M1) - * Referenced by: - * '/r_trapPhaB_M1' - * '/r_trapPhaB_M1' + /* Computed Parameter: r_trapPhaB_M1_Table + * Referenced by: '/r_trapPhaB_M1' */ { -1000, -1000, 1000, 1000, 1000, -1000, -1000 }, - /* Pooled Parameter (Expression: r_trapPhaC_M1) - * Referenced by: - * '/r_trapPhaC_M1' - * '/r_trapPhaC_M1' + /* Computed Parameter: r_trapPhaC_M1_Table + * Referenced by: '/r_trapPhaC_M1' */ { 1000, -1000, -1000, -1000, 1000, 1000, 1000 }, - /* Pooled Parameter (Expression: r_sinPhaA_M1) - * Referenced by: - * '/r_sinPhaA_M1' - * '/r_sinPhaA_M1' + /* Computed Parameter: r_sinPhaA_M1_Table + * Referenced by: '/r_sinPhaA_M1' */ { 500, 643, 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500 }, - /* Pooled Parameter (Expression: r_sinPhaB_M1) - * Referenced by: - * '/r_sinPhaB_M1' - * '/r_sinPhaB_M1' + /* Computed Parameter: r_sinPhaB_M1_Table + * Referenced by: '/r_sinPhaB_M1' */ { -1000, -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000 }, - /* Pooled Parameter (Expression: r_sinPhaC_M1) - * Referenced by: - * '/r_sinPhaC_M1' - * '/r_sinPhaC_M1' + /* Computed Parameter: r_sinPhaC_M1_Table + * Referenced by: '/r_sinPhaC_M1' */ { 500, 342, 174, 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500 }, - /* Pooled Parameter (Expression: r_sin3PhaA_M1) - * Referenced by: - * '/r_sin3PhaA_M1' - * '/r_sin3PhaA_M1' + /* Computed Parameter: r_sin3PhaA_M1_Table + * Referenced by: '/r_sin3PhaA_M1' */ { 795, 930, 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795 }, - /* Pooled Parameter (Expression: r_sin3PhaB_M1) - * Referenced by: - * '/r_sin3PhaB_M1' - * '/r_sin3PhaB_M1' + /* Computed Parameter: r_sin3PhaB_M1_Table + * Referenced by: '/r_sin3PhaB_M1' */ { -930, -942, -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, -310, -584, -795, -930, -991, -996, -971, -942, -930 }, - /* Pooled Parameter (Expression: r_sin3PhaC_M1) - * Referenced by: - * '/r_sin3PhaC_M1' - * '/r_sin3PhaC_M1' + /* Computed Parameter: r_sin3PhaC_M1_Table + * Referenced by: '/r_sin3PhaC_M1' */ { 795, 584, 310, 0, -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795 }, - /* Pooled Parameter (Expression: z_commutMap_M1) - * Referenced by: - * '/z_commutMap_M1' - * '/z_commutMap_M1' + /* Computed Parameter: z_commutMap_M1_table + * Referenced by: '/z_commutMap_M1' */ { 1000, -1000, 0, 1000, 0, -1000, 0, 1000, -1000, -1000, 1000, 0, -1000, 0, 1000, 0, -1000, 1000 }, - /* Pooled Parameter (Expression: vec_hallToPos) - * Referenced by: - * '/vec_hallToPos' - * '/vec_hallToPos' + /* Computed Parameter: vec_hallToPos_Value + * Referenced by: '/vec_hallToPos' */ - { 0U, 5U, 3U, 4U, 1U, 0U, 2U, 0U }, - - /* Pooled Parameter (Expression: [0 1;1 0;0 1;0 1;1 0;1 0;0 0;0 0]) - * Referenced by: - * '/Logic' - * '/Logic' - */ - { 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 } + { 0, 5, 3, 4, 1, 0, 2, 0 } }; /* diff --git a/01_Matlab/BLDC_controller_ert_rtw/buildInfo.mat b/01_Matlab/BLDC_controller_ert_rtw/buildInfo.mat index e4d7fe7..fb650b7 100644 Binary files a/01_Matlab/BLDC_controller_ert_rtw/buildInfo.mat and b/01_Matlab/BLDC_controller_ert_rtw/buildInfo.mat differ diff --git a/01_Matlab/BLDC_controller_ert_rtw/build_exception.mat b/01_Matlab/BLDC_controller_ert_rtw/build_exception.mat deleted file mode 100644 index dbaacdc..0000000 Binary files a/01_Matlab/BLDC_controller_ert_rtw/build_exception.mat and /dev/null differ diff --git a/01_Matlab/BLDC_controller_ert_rtw/codeInfo.mat b/01_Matlab/BLDC_controller_ert_rtw/codeInfo.mat index c585fbe..d5f0df0 100644 Binary files a/01_Matlab/BLDC_controller_ert_rtw/codeInfo.mat and b/01_Matlab/BLDC_controller_ert_rtw/codeInfo.mat differ diff --git a/01_Matlab/BLDC_controller_ert_rtw/codedescriptor.dmr b/01_Matlab/BLDC_controller_ert_rtw/codedescriptor.dmr index 56cd3cc..2b4363f 100644 Binary files a/01_Matlab/BLDC_controller_ert_rtw/codedescriptor.dmr and b/01_Matlab/BLDC_controller_ert_rtw/codedescriptor.dmr differ diff --git a/01_Matlab/BLDC_controller_ert_rtw/defines.txt b/01_Matlab/BLDC_controller_ert_rtw/defines.txt index 21f4292..7f0b535 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/defines.txt +++ b/01_Matlab/BLDC_controller_ert_rtw/defines.txt @@ -5,7 +5,7 @@ HAVESTDIO TERMFCN=0 ONESTEPFCN=1 MAT_FILE=0 -MULTI_INSTANCE_CODE=0 +MULTI_INSTANCE_CODE=1 INTEGER_CODE=0 MT=0 CLASSIC_INTERFACE=0 diff --git a/01_Matlab/BLDC_controller_ert_rtw/ert_main.c b/01_Matlab/BLDC_controller_ert_rtw/ert_main.c index 53238cd..b1ddf7d 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/ert_main.c +++ b/01_Matlab/BLDC_controller_ert_rtw/ert_main.c @@ -7,9 +7,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.817 + * Model version : 1.877 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue May 28 19:55:33 2019 + * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -25,7 +25,69 @@ #include /* This ert_main.c example uses printf/fflush */ #include "BLDC_controller.h" /* Model's header file */ #include "rtwtypes.h" -#include "zero_crossing_types.h" + +static RT_MODEL rtM_; +static RT_MODEL *const rtMPtr = &rtM_; /* Real-time model */ +static P rtP = { + /* Variable: cf_speedCoef + * Referenced by: '/cf_spdCoef' + */ + 11111, + + /* Variable: cf_speedFilt + * Referenced by: '/cf_speedFilt' + */ + 10, + + /* Variable: n_commAcvLo + * Referenced by: '/n_commDeacv' + */ + 15, + + /* Variable: n_commDeacvHi + * Referenced by: '/n_commDeacv' + */ + 30, + + /* Variable: r_commDCDeacv + * Referenced by: '/r_commDCDeacv' + */ + 70, + + /* Variable: r_phaAdvDC_XA + * Referenced by: '/r_phaAdvDC_XA' + */ + { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }, + + /* Variable: a_phaAdv_M1 + * Referenced by: '/a_phaAdv_M2' + */ + { 0, 0, 0, 0, 0, 2, 3, 5, 9, 16, 25 }, + + /* Variable: dz_counterHi + * Referenced by: '/dz_counter' + */ + 50, + + /* Variable: dz_counterLo + * Referenced by: '/dz_counter' + */ + 20, + + /* Variable: z_ctrlTypSel + * Referenced by: '/z_ctrlTypSel1' + */ + 3U, + + /* Variable: b_phaAdvEna + * Referenced by: '/a_elecPeriod1' + */ + 1 +}; /* Modifiable parameters */ + +static DW rtDW; /* Observable states */ +static ExtU rtU; /* External inputs */ +static ExtY rtY; /* External outputs */ /* * Associating rt_OneStep with a real-time clock or interrupt service routine @@ -38,8 +100,8 @@ * your application needs. This example simply sets an error status in the * real-time model and returns from rt_OneStep. */ -void rt_OneStep(void); -void rt_OneStep(void) +void rt_OneStep(RT_MODEL *const rtM); +void rt_OneStep(RT_MODEL *const rtM) { static boolean_T OverrunFlag = false; @@ -57,7 +119,7 @@ void rt_OneStep(void) /* Set model inputs here */ /* Step the model */ - BLDC_controller_step(); + BLDC_controller_step(rtM); /* Get model outputs here */ @@ -77,18 +139,26 @@ void rt_OneStep(void) */ int_T main(int_T argc, const char *argv[]) { + RT_MODEL *const rtM = rtMPtr; + /* Unused arguments */ (void)(argc); (void)(argv); + /* Pack model data into RTM */ + rtM->defaultParam = &rtP; + rtM->dwork = &rtDW; + rtM->inputs = &rtU; + rtM->outputs = &rtY; + /* Initialize model */ - BLDC_controller_initialize(); + BLDC_controller_initialize(rtM); /* Attach rt_OneStep to a timer or interrupt service routine with - * period 1.0E-5 seconds (the model's base sample time) here. The + * period 6.0E-5 seconds (the model's base sample time) here. The * call syntax for rt_OneStep is * - * rt_OneStep(); + * rt_OneStep(rtM); */ printf("Warning: The simulation will run forever. " "Generated ERT main won't simulate model step behavior. " diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_c.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_c.html index f491ff9..6a7f85e 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_c.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_c.html @@ -21,9 +21,9 @@ 7 * 8 * Code generated for Simulink model 'BLDC_controller'. 9 * - 10 * Model version : 1.817 + 10 * Model version : 1.877 11 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - 12 * C/C++ source code generated on : Tue May 28 19:55:33 2019 + 12 * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 13 * 14 * Target selection: ert.tlc 15 * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -99,1228 +99,617 @@ 85 #endif 86 #endif 87 - 88 /* Block signals and states (auto storage) */ - 89 DW rtDW; - 90 - 91 /* Previous zero-crossings (trigger) states */ - 92 PrevZCX rtPrevZCX; - 93 - 94 /* External inputs (root inport signals with auto storage) */ - 95 ExtU rtU; - 96 - 97 /* External outputs (root outports fed by signals with auto storage) */ - 98 ExtY rtY; - 99 static uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T - 100 bpSpace, uint32_T maxIndex, uint32_T *fraction); - 101 static int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, - 102 const int16_T table[]); - 103 static int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator); - 104 static void F01_03_Direction_Detection(boolean_T rtu_Enable, uint8_T rtu_z_pos, - 105 uint8_T rtu_z_posPrev, int8_T *rty_z_dir, int8_T *rty_z_dirPrev, - 106 DW_F01_03_Direction_Detection *localDW); - 107 static void Edge_counter_Reset(DW_Edge_counter *localDW); - 108 static void Edge_counter_Disable(uint8_T *rty_cnt, DW_Edge_counter *localDW); - 109 static void Edge_counter(boolean_T rtu_Enable, boolean_T rtu_b_edge, int8_T - 110 rtu_z_dir, int8_T rtu_z_dirPrev, uint8_T *rty_cnt, DW_Edge_counter *localDW); - 111 static void Motor_Speed_Calculation(boolean_T rtu_Trigger, int16_T rtu_z_counter, - 112 int8_T rtu_z_dir, int32_T *rty_n_mot, DW_Motor_Speed_Calculation *localDW, - 113 ZCE_Motor_Speed_Calculation *localZCE); - 114 static void F03_01_Pure_Trapezoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - 115 *rty_r_phaA_Trap, int16_T *rty_r_phaB_Trap, int16_T *rty_r_phaC_Trap); - 116 static void F03_02_Sinusoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - 117 *rty_r_phaA_Sin, int16_T *rty_r_phaB_Sin, int16_T *rty_r_phaC_Sin); - 118 static void F03_02_Sinusoidal3rd_Method(int32_T rtu_a_elecAngleAdv, int16_T - 119 *rty_r_phaA_Sin3, int16_T *rty_r_phaB_Sin3, int16_T *rty_r_phaC_Sin3); - 120 static void F02_Electrical_Angle_Ca_Disable(int32_T *rty_a_elecAngleAdv, int32_T - 121 *rty_a_elecAngle); - 122 static void F02_Electrical_Angle_Calculatio(int32_T rtu_r_DC, uint8_T rtu_z_pos, - 123 int8_T rtu_z_dir, int16_T rtu_z_counter, int16_T rtu_z_counterRaw, int32_T - 124 *rty_a_elecAngleAdv, int32_T *rty_a_elecAngle); - 125 static void falling_edge2(void); - 126 static void rising_edge(void); - 127 static void falling_edge2_b(void); - 128 static void rising_edge_f(void); - 129 static uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T - 130 bpSpace, uint32_T maxIndex, uint32_T *fraction) - 131 { - 132 uint8_T bpIndex; - 133 uint32_T uAdjust; - 134 uint32_T fbpIndex; - 135 - 136 /* Prelookup - Index and Fraction - 137 Index Search method: 'even' - 138 Extrapolation method: 'Clip' - 139 Use previous index: 'off' - 140 Use last breakpoint for index at or above upper limit: 'off' - 141 Remove protection against out-of-range input in generated code: 'off' - 142 Rounding mode: 'simplest' - 143 */ - 144 if (u <= bp0) { - 145 bpIndex = 0U; - 146 *fraction = 0U; - 147 } else { - 148 uAdjust = (uint32_T)u - bp0; - 149 fbpIndex = uAdjust / bpSpace; - 150 if (fbpIndex < maxIndex) { - 151 bpIndex = (uint8_T)fbpIndex; - 152 *fraction = (uint32_T)(((uint64_T)(uAdjust - bpIndex * bpSpace) << 31) / - 153 bpSpace); - 154 } else { - 155 bpIndex = (uint8_T)(maxIndex - 1U); - 156 *fraction = 2147483648U; - 157 } - 158 } - 159 - 160 return bpIndex; - 161 } - 162 - 163 static int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, - 164 const int16_T table[]) - 165 { - 166 uint32_T offset_0d; + 88 uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T bpSpace, + 89 uint32_T maxIndex, uint32_T *fraction); + 90 int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, const + 91 int16_T table[]); + 92 int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator); + 93 uint8_T plook_u8s32u32n31_evenc_s(int32_T u, int32_T bp0, uint32_T bpSpace, + 94 uint32_T maxIndex, uint32_T *fraction) + 95 { + 96 uint8_T bpIndex; + 97 uint32_T uAdjust; + 98 uint32_T fbpIndex; + 99 + 100 /* Prelookup - Index and Fraction + 101 Index Search method: 'even' + 102 Extrapolation method: 'Clip' + 103 Use previous index: 'off' + 104 Use last breakpoint for index at or above upper limit: 'off' + 105 Remove protection against out-of-range input in generated code: 'off' + 106 Rounding mode: 'simplest' + 107 */ + 108 if (u <= bp0) { + 109 bpIndex = 0U; + 110 *fraction = 0U; + 111 } else { + 112 uAdjust = (uint32_T)u - bp0; + 113 fbpIndex = uAdjust / bpSpace; + 114 if (fbpIndex < maxIndex) { + 115 bpIndex = (uint8_T)fbpIndex; + 116 *fraction = (uint32_T)(((uint64_T)(uAdjust - bpIndex * bpSpace) << 31) / + 117 bpSpace); + 118 } else { + 119 bpIndex = (uint8_T)(maxIndex - 1U); + 120 *fraction = 2147483648U; + 121 } + 122 } + 123 + 124 return bpIndex; + 125 } + 126 + 127 int16_T intrp1d_s16s32s32u8u32n31l_s(uint8_T bpIndex, uint32_T frac, const + 128 int16_T table[]) + 129 { + 130 uint32_T offset_0d; + 131 + 132 /* Interpolation 1-D + 133 Interpolation method: 'Linear' + 134 Use last breakpoint for index at or above upper limit: 'off' + 135 Rounding mode: 'simplest' + 136 Overflow mode: 'wrapping' + 137 */ + 138 offset_0d = bpIndex; + 139 return (int16_T)((int16_T)(((int64_T)(table[offset_0d + 1U] - table[offset_0d]) + 140 * frac) >> 31) + table[offset_0d]); + 141 } + 142 + 143 int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator) + 144 { + 145 return (((numerator < 0) != (denominator < 0)) && (numerator % denominator != + 146 0) ? -1 : 0) + numerator / denominator; + 147 } + 148 + 149 /* Model step function */ + 150 void BLDC_controller_step(RT_MODEL *const rtM) + 151 { + 152 P *rtP = ((P *) rtM->defaultParam); + 153 DW *rtDW = ((DW *) rtM->dwork); + 154 ExtU *rtU = (ExtU *) rtM->inputs; + 155 ExtY *rtY = (ExtY *) rtM->outputs; + 156 uint8_T rtb_Sum; + 157 int32_T rtb_Sum2; + 158 uint8_T rtb_BitwiseOperator; + 159 int16_T rtb_Abs2; + 160 int16_T rtb_Sum1_a; + 161 int32_T rtb_Abs5; + 162 int8_T rtAction; + 163 int8_T rtb_Sum2_h; + 164 uint32_T rtb_r_phaAdvDC_XA_o2; + 165 int32_T rtb_Switch1_idx_0; + 166 int32_T rtb_Switch1_idx_1; 167 - 168 /* Interpolation 1-D - 169 Interpolation method: 'Linear' - 170 Use last breakpoint for index at or above upper limit: 'off' - 171 Rounding mode: 'simplest' - 172 Overflow mode: 'wrapping' - 173 */ - 174 offset_0d = bpIndex; - 175 return (int16_T)((int16_T)(((int64_T)(table[offset_0d + 1U] - table[offset_0d]) - 176 * frac) >> 31) + table[offset_0d]); - 177 } + 168 /* Outputs for Atomic SubSystem: '<Root>/BLDC_controller' */ + 169 /* Sum: '<S12>/Sum' incorporates: + 170 * Gain: '<S12>/g_Ha' + 171 * Gain: '<S12>/g_Hb' + 172 * Inport: '<Root>/b_hallA ' + 173 * Inport: '<Root>/b_hallB' + 174 * Inport: '<Root>/b_hallC' + 175 */ + 176 rtb_Sum = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU->b_hallA << 2) + 177 + (uint8_T)(rtU->b_hallB << 1)) + rtU->b_hallC); 178 - 179 static int32_T div_nde_s32_floor(int32_T numerator, int32_T denominator) - 180 { - 181 return (((numerator < 0) != (denominator < 0)) && (numerator % denominator != - 182 0) ? -1 : 0) + numerator / denominator; - 183 } - 184 - 185 /* - 186 * Output and update for enable system: - 187 * '<S12>/F01_03_Direction_Detection' - 188 * '<S50>/F01_03_Direction_Detection' - 189 */ - 190 static void F01_03_Direction_Detection(boolean_T rtu_Enable, uint8_T rtu_z_pos, - 191 uint8_T rtu_z_posPrev, int8_T *rty_z_dir, int8_T *rty_z_dirPrev, - 192 DW_F01_03_Direction_Detection *localDW) - 193 { - 194 int8_T rtb_Sum2; - 195 - 196 /* Outputs for Enabled SubSystem: '<S12>/F01_03_Direction_Detection' incorporates: - 197 * EnablePort: '<S22>/Enable' - 198 */ - 199 if (rtu_Enable) { - 200 /* UnitDelay: '<S22>/UnitDelay1' */ - 201 *rty_z_dirPrev = localDW->UnitDelay1_DSTATE; - 202 - 203 /* Sum: '<S22>/Sum2' incorporates: - 204 * DataTypeConversion: '<S22>/Data Type Conversion1' - 205 * DataTypeConversion: '<S22>/Data Type Conversion10' - 206 */ - 207 rtb_Sum2 = (int8_T)((int8_T)rtu_z_pos - (int8_T)rtu_z_posPrev); - 208 - 209 /* Switch: '<S22>/Switch2' incorporates: - 210 * Constant: '<S22>/Constant20' - 211 * Constant: '<S22>/Constant23' - 212 * Constant: '<S22>/Constant24' - 213 * Constant: '<S22>/Constant8' - 214 * Logic: '<S22>/Logical Operator3' - 215 * RelationalOperator: '<S22>/Relational Operator1' - 216 * RelationalOperator: '<S22>/Relational Operator6' - 217 */ - 218 if ((rtb_Sum2 == 1) || (rtb_Sum2 == -5)) { - 219 *rty_z_dir = 1; - 220 } else { - 221 *rty_z_dir = -1; - 222 } - 223 - 224 /* End of Switch: '<S22>/Switch2' */ - 225 - 226 /* Update for UnitDelay: '<S22>/UnitDelay1' */ - 227 localDW->UnitDelay1_DSTATE = *rty_z_dir; - 228 } - 229 - 230 /* End of Outputs for SubSystem: '<S12>/F01_03_Direction_Detection' */ - 231 } - 232 - 233 /* - 234 * System reset for enable system: - 235 * '<S23>/Edge_counter' - 236 * '<S61>/Edge_counter' - 237 */ - 238 static void Edge_counter_Reset(DW_Edge_counter *localDW) - 239 { - 240 /* InitializeConditions for UnitDelay: '<S37>/UnitDelay1' */ - 241 localDW->UnitDelay1_DSTATE = 0U; - 242 } - 243 - 244 /* - 245 * Disable for enable system: - 246 * '<S23>/Edge_counter' - 247 * '<S61>/Edge_counter' - 248 */ - 249 static void Edge_counter_Disable(uint8_T *rty_cnt, DW_Edge_counter *localDW) - 250 { - 251 /* Outputs for Enabled SubSystem: '<S23>/Edge_counter' incorporates: - 252 * EnablePort: '<S27>/Enable' - 253 */ - 254 /* Disable for Outport: '<S27>/cnt' */ - 255 *rty_cnt = 0U; - 256 - 257 /* End of Outputs for SubSystem: '<S23>/Edge_counter' */ - 258 localDW->Edge_counter_MODE = false; - 259 } - 260 - 261 /* - 262 * Output and update for enable system: - 263 * '<S23>/Edge_counter' - 264 * '<S61>/Edge_counter' - 265 */ - 266 static void Edge_counter(boolean_T rtu_Enable, boolean_T rtu_b_edge, int8_T - 267 rtu_z_dir, int8_T rtu_z_dirPrev, uint8_T *rty_cnt, DW_Edge_counter *localDW) - 268 { - 269 boolean_T rtb_RelationalOperator1_i; - 270 uint8_T rtb_RelationalOperator1_m1; - 271 - 272 /* Outputs for Enabled SubSystem: '<S23>/Edge_counter' incorporates: - 273 * EnablePort: '<S27>/Enable' - 274 */ - 275 if (rtu_Enable) { - 276 if (!localDW->Edge_counter_MODE) { - 277 Edge_counter_Reset(localDW); - 278 localDW->Edge_counter_MODE = true; - 279 } - 280 - 281 /* RelationalOperator: '<S27>/Relational Operator1' */ - 282 rtb_RelationalOperator1_i = (rtu_z_dir == rtu_z_dirPrev); - 283 - 284 /* Switch: '<S37>/Switch1' incorporates: - 285 * Constant: '<S37>/Constant23' - 286 * Logic: '<S27>/Logical Operator2' - 287 * UnitDelay: '<S37>/UnitDelay1' - 288 */ - 289 if (!rtb_RelationalOperator1_i) { - 290 rtb_RelationalOperator1_m1 = 0U; - 291 } else { - 292 rtb_RelationalOperator1_m1 = localDW->UnitDelay1_DSTATE; - 293 } - 294 - 295 /* End of Switch: '<S37>/Switch1' */ - 296 - 297 /* Sum: '<S27>/Sum2' incorporates: - 298 * Logic: '<S27>/Logical Operator1' - 299 */ - 300 *rty_cnt = (uint8_T)((uint32_T)(rtu_b_edge && rtb_RelationalOperator1_i) + - 301 rtb_RelationalOperator1_m1); + 179 /* S-Function (sfix_bitop): '<S11>/Bitwise Operator' incorporates: + 180 * Inport: '<Root>/b_hallA ' + 181 * Inport: '<Root>/b_hallB' + 182 * Inport: '<Root>/b_hallC' + 183 * UnitDelay: '<S11>/UnitDelay' + 184 * UnitDelay: '<S11>/UnitDelay1' + 185 * UnitDelay: '<S11>/UnitDelay2' + 186 */ + 187 rtb_BitwiseOperator = (uint8_T)(rtU->b_hallA ^ rtU->b_hallB ^ rtU->b_hallC ^ + 188 rtDW->UnitDelay_DSTATE ^ rtDW->UnitDelay1_DSTATE_i ^ + 189 rtDW->UnitDelay2_DSTATE_h); + 190 + 191 /* If: '<S14>/If1' incorporates: + 192 * Constant: '<S14>/Constant6' + 193 * Constant: '<S17>/Constant1' + 194 * Constant: '<S17>/Constant23' + 195 * If: '<S7>/If2' + 196 * Inport: '<S15>/z_counterRawPrev' + 197 * RelationalOperator: '<S17>/Relational Operator1' + 198 * Sum: '<S14>/Sum1' + 199 * Switch: '<S17>/Switch1' + 200 * Switch: '<S17>/Switch2' + 201 * UnitDelay: '<S14>/UnitDelay1' + 202 * UnitDelay: '<S17>/UnitDelay1' + 203 */ + 204 if (rtb_BitwiseOperator != 0) { + 205 /* Outputs for IfAction SubSystem: '<S7>/F01_03_Direction_Detection' incorporates: + 206 * ActionPort: '<S13>/Action Port' + 207 */ + 208 /* UnitDelay: '<S13>/UnitDelay1' */ + 209 rtDW->UnitDelay1 = rtDW->Switch2; + 210 + 211 /* Sum: '<S13>/Sum2' incorporates: + 212 * Constant: '<S12>/vec_hallToPos' + 213 * Selector: '<S12>/Selector' + 214 * UnitDelay: '<S13>/UnitDelay2' + 215 */ + 216 rtb_Sum2_h = (int8_T)(rtConstP.vec_hallToPos_Value[rtb_Sum] - + 217 rtDW->UnitDelay2_DSTATE_i); + 218 + 219 /* Switch: '<S13>/Switch2' incorporates: + 220 * Constant: '<S13>/Constant20' + 221 * Constant: '<S13>/Constant23' + 222 * Constant: '<S13>/Constant24' + 223 * Constant: '<S13>/Constant8' + 224 * Logic: '<S13>/Logical Operator3' + 225 * RelationalOperator: '<S13>/Relational Operator1' + 226 * RelationalOperator: '<S13>/Relational Operator6' + 227 */ + 228 if ((rtb_Sum2_h == 1) || (rtb_Sum2_h == -5)) { + 229 rtDW->Switch2 = 1; + 230 } else { + 231 rtDW->Switch2 = -1; + 232 } + 233 + 234 /* End of Switch: '<S13>/Switch2' */ + 235 + 236 /* Update for UnitDelay: '<S13>/UnitDelay2' incorporates: + 237 * Constant: '<S12>/vec_hallToPos' + 238 * Selector: '<S12>/Selector' + 239 */ + 240 rtDW->UnitDelay2_DSTATE_i = rtConstP.vec_hallToPos_Value[rtb_Sum]; + 241 + 242 /* End of Outputs for SubSystem: '<S7>/F01_03_Direction_Detection' */ + 243 rtb_Abs2 = 1; + 244 + 245 /* Outputs for IfAction SubSystem: '<S14>/Counter_Hold_and_Error_Calculation' incorporates: + 246 * ActionPort: '<S15>/Action Port' + 247 */ + 248 rtDW->z_counterRawPrev = rtDW->UnitDelay1_DSTATE_c; + 249 + 250 /* Sum: '<S15>/Sum4' incorporates: + 251 * Constant: '<S14>/Constant6' + 252 * Constant: '<S17>/Constant23' + 253 * Inport: '<S15>/z_counterRawPrev' + 254 * Sum: '<S14>/Sum1' + 255 * UnitDelay: '<S14>/UnitDelay1' + 256 * UnitDelay: '<S15>/z_counter2' + 257 */ + 258 rtDW->Sum4 = (int16_T)(rtDW->z_counterRawPrev - rtDW->z_counter2_DSTATE); + 259 + 260 /* Update for UnitDelay: '<S15>/z_counter2' */ + 261 rtDW->z_counter2_DSTATE = rtDW->z_counterRawPrev; + 262 + 263 /* End of Outputs for SubSystem: '<S14>/Counter_Hold_and_Error_Calculation' */ + 264 } else { + 265 if (rtDW->UnitDelay1_DSTATE < 1500) { + 266 /* Switch: '<S17>/Switch2' incorporates: + 267 * UnitDelay: '<S17>/UnitDelay1' + 268 */ + 269 rtb_Abs2 = rtDW->UnitDelay1_DSTATE; + 270 } else { + 271 /* Switch: '<S17>/Switch2' incorporates: + 272 * Constant: '<S17>/Constant1' + 273 */ + 274 rtb_Abs2 = 1500; + 275 } + 276 + 277 rtb_Abs2++; + 278 } + 279 + 280 /* End of If: '<S14>/If1' */ + 281 + 282 /* Sum: '<S14>/Sum1' */ + 283 rtb_Sum1_a = rtb_Abs2; + 284 + 285 /* Switch: '<S16>/Switch1' incorporates: + 286 * Constant: '<S16>/Constant1' + 287 * Constant: '<S16>/cf_spdCoef' + 288 * Constant: '<S16>/z_maxCntRst' + 289 * Logic: '<S16>/Logical Operator1' + 290 * Product: '<S16>/Divide4' + 291 * RelationalOperator: '<S16>/Relational Operator2' + 292 * RelationalOperator: '<S16>/Relational Operator5' + 293 * Sum: '<S14>/Sum1' + 294 */ + 295 if ((rtb_Abs2 > 1500) || (rtDW->Switch2 != rtDW->UnitDelay1)) { + 296 rtb_Sum2 = 0; + 297 } else { + 298 rtb_Sum2 = rtP->cf_speedCoef * rtDW->Switch2 / rtDW->z_counterRawPrev; + 299 } + 300 + 301 /* End of Switch: '<S16>/Switch1' */ 302 - 303 /* Update for UnitDelay: '<S37>/UnitDelay1' */ - 304 localDW->UnitDelay1_DSTATE = *rty_cnt; - 305 } else { - 306 if (localDW->Edge_counter_MODE) { - 307 Edge_counter_Disable(rty_cnt, localDW); - 308 } - 309 } - 310 - 311 /* End of Outputs for SubSystem: '<S23>/Edge_counter' */ - 312 } - 313 - 314 /* - 315 * Output and update for trigger system: - 316 * '<S23>/Motor_Speed_Calculation' - 317 * '<S61>/Motor_Speed_Calculation' - 318 */ - 319 static void Motor_Speed_Calculation(boolean_T rtu_Trigger, int16_T rtu_z_counter, - 320 int8_T rtu_z_dir, int32_T *rty_n_mot, DW_Motor_Speed_Calculation *localDW, - 321 ZCE_Motor_Speed_Calculation *localZCE) - 322 { - 323 int32_T rtb_Sum2; + 303 /* Product: '<S16>/Divide2' incorporates: + 304 * Constant: '<S16>/Constant2' + 305 * Constant: '<S16>/Constant3' + 306 * Constant: '<S16>/cf_speedFilt' + 307 * Product: '<S16>/Divide1' + 308 * Product: '<S16>/Divide3' + 309 * Sum: '<S16>/Sum1' + 310 * Sum: '<S16>/Sum2' + 311 * UnitDelay: '<S16>/UnitDelay2' + 312 */ + 313 rtb_Sum2 = ((100 - rtP->cf_speedFilt) * rtDW->UnitDelay2_DSTATE + rtb_Sum2 * + 314 rtP->cf_speedFilt) / 100; + 315 + 316 /* Abs: '<S14>/Abs5' */ + 317 if (rtb_Sum2 < 0) { + 318 rtb_Abs5 = -rtb_Sum2; + 319 } else { + 320 rtb_Abs5 = rtb_Sum2; + 321 } + 322 + 323 /* End of Abs: '<S14>/Abs5' */ 324 - 325 /* Outputs for Triggered SubSystem: '<S23>/Motor_Speed_Calculation' incorporates: - 326 * TriggerPort: '<S28>/Trigger' - 327 */ - 328 if (rtu_Trigger && (localZCE->Motor_Speed_Calculation_Trig_ZC != POS_ZCSIG)) { - 329 /* Switch: '<S28>/Switch' incorporates: - 330 * Constant: '<S28>/Constant1' - 331 * Constant: '<S28>/cf_spdCoef' - 332 * Constant: '<S28>/z_maxCntRst' - 333 * Product: '<S28>/Divide4' - 334 * RelationalOperator: '<S28>/Relational Operator1' - 335 */ - 336 if (rtu_z_counter >= rtP.z_maxCntRst) { - 337 rtb_Sum2 = 0; - 338 } else { - 339 rtb_Sum2 = rtP.cf_speedCoef / rtu_z_counter; - 340 } - 341 - 342 /* End of Switch: '<S28>/Switch' */ - 343 - 344 /* Product: '<S28>/Product2' */ - 345 rtb_Sum2 *= rtu_z_dir; - 346 - 347 /* Product: '<S28>/Divide1' incorporates: - 348 * Constant: '<S28>/Constant2' - 349 * Sum: '<S28>/Sum2' - 350 * UnitDelay: '<S28>/UnitDelay1' - 351 * UnitDelay: '<S28>/UnitDelay5' - 352 */ - 353 *rty_n_mot = ((localDW->UnitDelay5_DSTATE + localDW->UnitDelay1_DSTATE) + - 354 rtb_Sum2) / 3; - 355 - 356 /* Update for UnitDelay: '<S28>/UnitDelay5' incorporates: - 357 * UnitDelay: '<S28>/UnitDelay1' - 358 */ - 359 localDW->UnitDelay5_DSTATE = localDW->UnitDelay1_DSTATE; + 325 /* Relay: '<S14>/n_commDeacv' */ + 326 if (rtb_Abs5 >= rtP->n_commDeacvHi) { + 327 rtDW->n_commDeacv_Mode = true; + 328 } else { + 329 if (rtb_Abs5 <= rtP->n_commAcvLo) { + 330 rtDW->n_commDeacv_Mode = false; + 331 } + 332 } + 333 + 334 /* Abs: '<S14>/Abs2' */ + 335 if (rtDW->Sum4 < 0) { + 336 rtb_Abs2 = (int16_T)-rtDW->Sum4; + 337 } else { + 338 rtb_Abs2 = rtDW->Sum4; + 339 } + 340 + 341 /* End of Abs: '<S14>/Abs2' */ + 342 + 343 /* Relay: '<S14>/dz_counter' */ + 344 if (rtb_Abs2 >= rtP->dz_counterHi) { + 345 rtDW->dz_counter_Mode = true; + 346 } else { + 347 if (rtb_Abs2 <= rtP->dz_counterLo) { + 348 rtDW->dz_counter_Mode = false; + 349 } + 350 } + 351 + 352 /* If: '<S2>/If1' incorporates: + 353 * Constant: '<S7>/z_ctrlTypSel1' + 354 */ + 355 rtb_Sum2_h = rtDW->If1_ActiveSubsystem; + 356 rtAction = -1; + 357 if (rtP->z_ctrlTypSel != 0) { + 358 rtAction = 0; + 359 } 360 - 361 /* Update for UnitDelay: '<S28>/UnitDelay1' */ - 362 localDW->UnitDelay1_DSTATE = rtb_Sum2; - 363 } - 364 - 365 localZCE->Motor_Speed_Calculation_Trig_ZC = rtu_Trigger; - 366 - 367 /* End of Outputs for SubSystem: '<S23>/Motor_Speed_Calculation' */ - 368 } - 369 - 370 /* Output and update for atomic system: '<S23>/falling_edge2' */ - 371 static void falling_edge2(void) - 372 { - 373 /* Logic: '<S30>/Logical Operator' incorporates: - 374 * Logic: '<S30>/Logical Operator1' - 375 * UnitDelay: '<S30>/UnitDelay' - 376 */ - 377 rtDW.LogicalOperator = ((!rtDW.Logic[0]) && rtDW.UnitDelay_DSTATE_b); - 378 - 379 /* Update for UnitDelay: '<S30>/UnitDelay' */ - 380 rtDW.UnitDelay_DSTATE_b = rtDW.Logic[0]; - 381 } - 382 - 383 /* Output and update for atomic system: '<S23>/rising_edge' */ - 384 static void rising_edge(void) - 385 { - 386 /* Logic: '<S31>/Logical Operator' incorporates: - 387 * Logic: '<S31>/Logical Operator1' - 388 * UnitDelay: '<S31>/UnitDelay' - 389 */ - 390 rtDW.LogicalOperator_h = (rtDW.LogicalOperator5 && (!rtDW.UnitDelay_DSTATE_l)); - 391 - 392 /* Update for UnitDelay: '<S31>/UnitDelay' */ - 393 rtDW.UnitDelay_DSTATE_l = rtDW.LogicalOperator5; - 394 } - 395 - 396 /* - 397 * Output and update for action system: - 398 * '<S14>/F03_01_Pure_Trapezoidal_Method' - 399 * '<S52>/F03_01_Pure_Trapezoidal_Method' - 400 */ - 401 static void F03_01_Pure_Trapezoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - 402 *rty_r_phaA_Trap, int16_T *rty_r_phaB_Trap, int16_T *rty_r_phaC_Trap) - 403 { - 404 uint8_T rtb_a_trapElecAngle_XA_o1; - 405 uint32_T rtb_a_trapElecAngle_XA_o2; - 406 - 407 /* PreLookup: '<S41>/a_trapElecAngle_XA' */ - 408 rtb_a_trapElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 409 60U, 6U, &rtb_a_trapElecAngle_XA_o2); - 410 - 411 /* Interpolation_n-D: '<S41>/r_trapPhaA_M1' */ - 412 *rty_r_phaA_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - 413 rtb_a_trapElecAngle_XA_o2, rtConstP.pooled9); - 414 - 415 /* Interpolation_n-D: '<S41>/r_trapPhaB_M1' */ - 416 *rty_r_phaB_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - 417 rtb_a_trapElecAngle_XA_o2, rtConstP.pooled10); - 418 - 419 /* Interpolation_n-D: '<S41>/r_trapPhaC_M1' */ - 420 *rty_r_phaC_Trap = intrp1d_s16s32s32u8u32n31l_s(rtb_a_trapElecAngle_XA_o1, - 421 rtb_a_trapElecAngle_XA_o2, rtConstP.pooled11); - 422 } - 423 - 424 /* - 425 * Output and update for action system: - 426 * '<S14>/F03_02_Sinusoidal_Method' - 427 * '<S52>/F03_02_Sinusoidal_Method' - 428 */ - 429 static void F03_02_Sinusoidal_Method(int32_T rtu_a_elecAngleAdv, int16_T - 430 *rty_r_phaA_Sin, int16_T *rty_r_phaB_Sin, int16_T *rty_r_phaC_Sin) - 431 { - 432 uint8_T rtb_a_sinElecAngle_XA_o1; - 433 uint32_T rtb_a_sinElecAngle_XA_o2; - 434 - 435 /* PreLookup: '<S43>/a_sinElecAngle_XA' */ - 436 rtb_a_sinElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 437 10U, 36U, &rtb_a_sinElecAngle_XA_o2); - 438 - 439 /* Interpolation_n-D: '<S43>/r_sinPhaA_M1' */ - 440 *rty_r_phaA_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 441 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled12); - 442 - 443 /* Interpolation_n-D: '<S43>/r_sinPhaB_M1' */ - 444 *rty_r_phaB_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 445 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled13); + 361 rtDW->If1_ActiveSubsystem = rtAction; + 362 if ((rtb_Sum2_h != rtAction) && (rtb_Sum2_h == 0)) { + 363 /* Disable for Outport: '<S8>/a_elecAngleAdv' */ + 364 rtDW->Switch_PhaAdv = 0; + 365 + 366 /* Disable for Outport: '<Root>/a_elecAngle' incorporates: + 367 * Outport: '<S8>/a_elecAngle' + 368 */ + 369 rtY->a_elecAngle = 0; + 370 } + 371 + 372 if (rtAction == 0) { + 373 /* Outputs for IfAction SubSystem: '<S2>/F02_Electrical_Angle_Calculation' incorporates: + 374 * ActionPort: '<S8>/Action Port' + 375 */ + 376 /* Switch: '<S8>/Switch3' incorporates: + 377 * Constant: '<S12>/vec_hallToPos' + 378 * Constant: '<S8>/Constant16' + 379 * Gain: '<S12>/g_Ha' + 380 * Gain: '<S12>/g_Hb' + 381 * Inport: '<Root>/b_hallA ' + 382 * Inport: '<Root>/b_hallB' + 383 * Inport: '<Root>/b_hallC' + 384 * RelationalOperator: '<S8>/Relational Operator7' + 385 * Selector: '<S12>/Selector' + 386 * Sum: '<S12>/Sum' + 387 * Sum: '<S8>/Sum1' + 388 */ + 389 if (rtDW->Switch2 == 1) { + 390 rtb_Sum2_h = rtConstP.vec_hallToPos_Value[rtb_Sum]; + 391 } else { + 392 rtb_Sum2_h = (int8_T)(rtConstP.vec_hallToPos_Value[(uint8_T)((uint32_T) + 393 (uint8_T)((uint32_T)(uint8_T)(rtU->b_hallA << 2) + (uint8_T) + 394 (rtU->b_hallB << 1)) + rtU->b_hallC)] + 1); + 395 } + 396 + 397 /* End of Switch: '<S8>/Switch3' */ + 398 + 399 /* Outport: '<Root>/a_elecAngle' incorporates: + 400 * Constant: '<S8>/a_elecAngle1' + 401 * Product: '<S8>/Divide4' + 402 * Product: '<S8>/Divide5' + 403 * Product: '<S8>/Product6' + 404 * Sum: '<S8>/Sum2' + 405 */ + 406 rtY->a_elecAngle = 60 * rtb_Sum1_a / rtDW->z_counterRawPrev * rtDW->Switch2 + 407 + rtb_Sum2_h * 60; + 408 + 409 /* Switch: '<S8>/Switch_PhaAdv' incorporates: + 410 * Constant: '<S8>/a_elecPeriod1' + 411 * Outport: '<Root>/a_elecAngle' + 412 */ + 413 if (rtP->b_phaAdvEna) { + 414 /* Abs: '<S8>/Abs2' incorporates: + 415 * Inport: '<Root>/r_DC' + 416 */ + 417 if (rtU->r_DC < 0) { + 418 rtb_Switch1_idx_0 = -rtU->r_DC; + 419 } else { + 420 rtb_Switch1_idx_0 = rtU->r_DC; + 421 } + 422 + 423 /* End of Abs: '<S8>/Abs2' */ + 424 + 425 /* PreLookup: '<S8>/r_phaAdvDC_XA' */ + 426 rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtb_Switch1_idx_0, + 427 rtP->r_phaAdvDC_XA[0], (uint32_T)rtP->r_phaAdvDC_XA[1] - + 428 rtP->r_phaAdvDC_XA[0], 10U, &rtb_r_phaAdvDC_XA_o2); + 429 + 430 /* Interpolation_n-D: '<S8>/a_phaAdv_M2' */ + 431 rtb_Abs2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 432 rtb_r_phaAdvDC_XA_o2, rtP->a_phaAdv_M1); + 433 + 434 /* Sum: '<S8>/Sum3' incorporates: + 435 * Outport: '<Root>/a_elecAngle' + 436 * Product: '<S8>/Product2' + 437 */ + 438 rtb_Switch1_idx_0 = (int16_T)(rtb_Abs2 * rtDW->Switch2) + rtY->a_elecAngle; + 439 + 440 /* Math: '<S8>/Math Function' */ + 441 rtDW->Switch_PhaAdv = rtb_Switch1_idx_0 - div_nde_s32_floor + 442 (rtb_Switch1_idx_0, 360) * 360; + 443 } else { + 444 rtDW->Switch_PhaAdv = rtY->a_elecAngle; + 445 } 446 - 447 /* Interpolation_n-D: '<S43>/r_sinPhaC_M1' */ - 448 *rty_r_phaC_Sin = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 449 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled14); - 450 } - 451 - 452 /* - 453 * Output and update for action system: - 454 * '<S14>/F03_02_Sinusoidal3rd_Method' - 455 * '<S52>/F03_02_Sinusoidal3rd_Method' - 456 */ - 457 static void F03_02_Sinusoidal3rd_Method(int32_T rtu_a_elecAngleAdv, int16_T - 458 *rty_r_phaA_Sin3, int16_T *rty_r_phaB_Sin3, int16_T *rty_r_phaC_Sin3) - 459 { - 460 uint8_T rtb_a_sinElecAngle_XA_o1; - 461 uint32_T rtb_a_sinElecAngle_XA_o2; - 462 - 463 /* PreLookup: '<S42>/a_sinElecAngle_XA' */ - 464 rtb_a_sinElecAngle_XA_o1 = plook_u8s32u32n31_evenc_s(rtu_a_elecAngleAdv, 0, - 465 10U, 36U, &rtb_a_sinElecAngle_XA_o2); - 466 - 467 /* Interpolation_n-D: '<S42>/r_sin3PhaA_M1' */ - 468 *rty_r_phaA_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 469 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled15); - 470 - 471 /* Interpolation_n-D: '<S42>/r_sin3PhaB_M1' */ - 472 *rty_r_phaB_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 473 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled16); - 474 - 475 /* Interpolation_n-D: '<S42>/r_sin3PhaC_M1' */ - 476 *rty_r_phaC_Sin3 = intrp1d_s16s32s32u8u32n31l_s(rtb_a_sinElecAngle_XA_o1, - 477 rtb_a_sinElecAngle_XA_o2, rtConstP.pooled17); - 478 } + 447 /* End of Switch: '<S8>/Switch_PhaAdv' */ + 448 /* End of Outputs for SubSystem: '<S2>/F02_Electrical_Angle_Calculation' */ + 449 } + 450 + 451 /* End of If: '<S2>/If1' */ + 452 + 453 /* SwitchCase: '<S9>/Switch Case' incorporates: + 454 * Constant: '<S7>/z_ctrlTypSel1' + 455 */ + 456 switch (rtP->z_ctrlTypSel) { + 457 case 1: + 458 /* Outputs for IfAction SubSystem: '<S9>/F03_01_Pure_Trapezoidal_Method' incorporates: + 459 * ActionPort: '<S18>/Action Port' + 460 */ + 461 /* PreLookup: '<S18>/a_trapElecAngle_XA' */ + 462 rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 60U, + 463 6U, &rtb_r_phaAdvDC_XA_o2); + 464 + 465 /* Interpolation_n-D: '<S18>/r_trapPhaA_M1' */ + 466 rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 467 rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaA_M1_Table); + 468 + 469 /* Interpolation_n-D: '<S18>/r_trapPhaB_M1' */ + 470 rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 471 rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaB_M1_Table); + 472 + 473 /* Interpolation_n-D: '<S18>/r_trapPhaC_M1' */ + 474 rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 475 rtb_r_phaAdvDC_XA_o2, rtConstP.r_trapPhaC_M1_Table); + 476 + 477 /* End of Outputs for SubSystem: '<S9>/F03_01_Pure_Trapezoidal_Method' */ + 478 break; 479 - 480 /* - 481 * Disable for action system: - 482 * '<S2>/F02_Electrical_Angle_Calculation' - 483 * '<S3>/F02_Electrical_Angle_Calculation' - 484 */ - 485 static void F02_Electrical_Angle_Ca_Disable(int32_T *rty_a_elecAngleAdv, int32_T - 486 *rty_a_elecAngle) - 487 { - 488 /* Disable for Outport: '<S13>/a_elecAngleAdv' */ - 489 *rty_a_elecAngleAdv = 0; - 490 - 491 /* Disable for Outport: '<S13>/a_elecAngle' */ - 492 *rty_a_elecAngle = 0; - 493 } - 494 - 495 /* - 496 * Output and update for action system: - 497 * '<S2>/F02_Electrical_Angle_Calculation' - 498 * '<S3>/F02_Electrical_Angle_Calculation' - 499 */ - 500 static void F02_Electrical_Angle_Calculatio(int32_T rtu_r_DC, uint8_T rtu_z_pos, - 501 int8_T rtu_z_dir, int16_T rtu_z_counter, int16_T rtu_z_counterRaw, int32_T - 502 *rty_a_elecAngleAdv, int32_T *rty_a_elecAngle) - 503 { - 504 uint8_T rtb_Switch3; - 505 int16_T rtb_a_phaAdv_M2; - 506 uint32_T rtb_r_phaAdvDC_XA_o2; - 507 int32_T rtu_r_DC_0; - 508 - 509 /* Switch: '<S13>/Switch3' incorporates: - 510 * Constant: '<S13>/Constant16' - 511 * RelationalOperator: '<S13>/Relational Operator7' - 512 * Sum: '<S13>/Sum1' - 513 */ - 514 if (rtu_z_dir == 1) { - 515 rtb_Switch3 = rtu_z_pos; - 516 } else { - 517 rtb_Switch3 = (uint8_T)(rtu_z_pos + 1U); - 518 } - 519 - 520 /* End of Switch: '<S13>/Switch3' */ - 521 - 522 /* Sum: '<S13>/Sum2' incorporates: - 523 * Constant: '<S13>/a_elecAngle1' - 524 * Product: '<S13>/Divide4' - 525 * Product: '<S13>/Divide5' - 526 * Product: '<S13>/Product6' - 527 */ - 528 *rty_a_elecAngle = 60 * rtu_z_counterRaw / rtu_z_counter * rtu_z_dir + - 529 rtb_Switch3 * 60; - 530 - 531 /* Switch: '<S13>/Switch_PhaAdv' incorporates: - 532 * Constant: '<S13>/a_elecPeriod1' - 533 * Math: '<S13>/Math Function' - 534 */ - 535 if (rtP.b_phaAdvEna) { - 536 /* Abs: '<S13>/Abs2' */ - 537 if (rtu_r_DC < 0) { - 538 rtu_r_DC_0 = -rtu_r_DC; - 539 } else { - 540 rtu_r_DC_0 = rtu_r_DC; - 541 } + 480 case 2: + 481 /* Outputs for IfAction SubSystem: '<S9>/F03_02_Sinusoidal_Method' incorporates: + 482 * ActionPort: '<S19>/Action Port' + 483 */ + 484 /* PreLookup: '<S19>/a_sinElecAngle_XA' */ + 485 rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 10U, + 486 36U, &rtb_r_phaAdvDC_XA_o2); + 487 + 488 /* Interpolation_n-D: '<S19>/r_sinPhaA_M1' */ + 489 rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 490 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaA_M1_Table); + 491 + 492 /* Interpolation_n-D: '<S19>/r_sinPhaB_M1' */ + 493 rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 494 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaB_M1_Table); + 495 + 496 /* Interpolation_n-D: '<S19>/r_sinPhaC_M1' */ + 497 rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 498 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sinPhaC_M1_Table); + 499 + 500 /* End of Outputs for SubSystem: '<S9>/F03_02_Sinusoidal_Method' */ + 501 break; + 502 + 503 case 3: + 504 /* Outputs for IfAction SubSystem: '<S9>/F03_03_Sinusoidal3rd_Method' incorporates: + 505 * ActionPort: '<S20>/Action Port' + 506 */ + 507 /* PreLookup: '<S20>/a_sinElecAngle_XA' */ + 508 rtb_BitwiseOperator = plook_u8s32u32n31_evenc_s(rtDW->Switch_PhaAdv, 0, 10U, + 509 36U, &rtb_r_phaAdvDC_XA_o2); + 510 + 511 /* Interpolation_n-D: '<S20>/r_sin3PhaA_M1' */ + 512 rtDW->Merge = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 513 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaA_M1_Table); + 514 + 515 /* Interpolation_n-D: '<S20>/r_sin3PhaB_M1' */ + 516 rtDW->Merge1 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 517 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaB_M1_Table); + 518 + 519 /* Interpolation_n-D: '<S20>/r_sin3PhaC_M1' */ + 520 rtDW->Merge2 = intrp1d_s16s32s32u8u32n31l_s(rtb_BitwiseOperator, + 521 rtb_r_phaAdvDC_XA_o2, rtConstP.r_sin3PhaC_M1_Table); + 522 + 523 /* End of Outputs for SubSystem: '<S9>/F03_03_Sinusoidal3rd_Method' */ + 524 break; + 525 } + 526 + 527 /* End of SwitchCase: '<S9>/Switch Case' */ + 528 + 529 /* Abs: '<S14>/Abs1' incorporates: + 530 * Inport: '<Root>/r_DC' + 531 * Signum: '<S14>/Sign1' + 532 */ + 533 if (rtU->r_DC < 0) { + 534 rtb_Switch1_idx_0 = -rtU->r_DC; + 535 rtb_Switch1_idx_1 = -1; + 536 } else { + 537 rtb_Switch1_idx_0 = rtU->r_DC; + 538 rtb_Switch1_idx_1 = (rtU->r_DC > 0); + 539 } + 540 + 541 /* End of Abs: '<S14>/Abs1' */ 542 - 543 /* End of Abs: '<S13>/Abs2' */ - 544 - 545 /* PreLookup: '<S13>/r_phaAdvDC_XA' */ - 546 rtb_Switch3 = plook_u8s32u32n31_evenc_s(rtu_r_DC_0, rtP.r_phaAdvDC_XA[0], - 547 (uint32_T)rtP.r_phaAdvDC_XA[1] - rtP.r_phaAdvDC_XA[0], 10U, - 548 &rtb_r_phaAdvDC_XA_o2); + 543 /* Signum: '<S14>/Sign' */ + 544 if (rtDW->Switch2 < 0) { + 545 rtb_Sum2_h = -1; + 546 } else { + 547 rtb_Sum2_h = (int8_T)(rtDW->Switch2 > 0); + 548 } 549 - 550 /* Interpolation_n-D: '<S13>/a_phaAdv_M2' */ - 551 rtb_a_phaAdv_M2 = intrp1d_s16s32s32u8u32n31l_s(rtb_Switch3, - 552 rtb_r_phaAdvDC_XA_o2, rtP.a_phaAdv_M1); - 553 - 554 /* Sum: '<S13>/Sum3' incorporates: - 555 * Product: '<S13>/Product2' - 556 */ - 557 rtu_r_DC_0 = rtu_z_dir * rtb_a_phaAdv_M2 + *rty_a_elecAngle; - 558 *rty_a_elecAngleAdv = rtu_r_DC_0 - div_nde_s32_floor(rtu_r_DC_0, 360) * 360; - 559 } else { - 560 *rty_a_elecAngleAdv = *rty_a_elecAngle; - 561 } - 562 - 563 /* End of Switch: '<S13>/Switch_PhaAdv' */ - 564 } - 565 - 566 /* Output and update for atomic system: '<S61>/falling_edge2' */ - 567 static void falling_edge2_b(void) - 568 { - 569 /* Logic: '<S68>/Logical Operator' incorporates: - 570 * Logic: '<S68>/Logical Operator1' - 571 * UnitDelay: '<S68>/UnitDelay' - 572 */ - 573 rtDW.LogicalOperator_h = ((!rtDW.Logic_j[0]) && rtDW.UnitDelay_DSTATE_i); - 574 - 575 /* Update for UnitDelay: '<S68>/UnitDelay' */ - 576 rtDW.UnitDelay_DSTATE_i = rtDW.Logic_j[0]; - 577 } - 578 - 579 /* Output and update for atomic system: '<S61>/rising_edge' */ - 580 static void rising_edge_f(void) - 581 { - 582 /* Logic: '<S69>/Logical Operator' incorporates: - 583 * Logic: '<S69>/Logical Operator1' - 584 * UnitDelay: '<S69>/UnitDelay' - 585 */ - 586 rtDW.LogicalOperator_h = (rtDW.LogicalOperator5 && (!rtDW.UnitDelay_DSTATE_k)); - 587 - 588 /* Update for UnitDelay: '<S69>/UnitDelay' */ - 589 rtDW.UnitDelay_DSTATE_k = rtDW.LogicalOperator5; - 590 } - 591 - 592 /* Model step function */ - 593 void BLDC_controller_step(void) - 594 { - 595 uint8_T rtb_Sum; - 596 boolean_T rtb_LogicalOperator; - 597 boolean_T rtb_LogicalOperator3; - 598 int32_T rtb_Abs1; - 599 int8_T rtPrevAction; - 600 int8_T rtAction; - 601 uint8_T rtb_Sum_a; - 602 int16_T rtb_Switch; - 603 int16_T rtb_Switch_b; - 604 int16_T rtb_Sum1; - 605 int16_T rtb_Sum1_c; - 606 int32_T rtb_Switch1_idx_0; - 607 int32_T rtb_Switch1_idx_1; - 608 uint8_T tmp; - 609 - 610 /* Outputs for Atomic SubSystem: '<Root>/BLDC_controller' */ - 611 /* Sum: '<S21>/Sum' incorporates: - 612 * Gain: '<S21>/g_Ha' - 613 * Gain: '<S21>/g_Hb' - 614 * Inport: '<Root>/b_hallALeft ' - 615 * Inport: '<Root>/b_hallBLeft' - 616 * Inport: '<Root>/b_hallCLeft' - 617 */ - 618 rtb_Sum = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU.b_hallALeft << - 619 2) + (uint8_T)(rtU.b_hallBLeft << 1)) + rtU.b_hallCLeft); - 620 - 621 /* Logic: '<S20>/Logical Operator' incorporates: - 622 * Inport: '<Root>/b_hallALeft ' - 623 * Inport: '<Root>/b_hallBLeft' - 624 * Inport: '<Root>/b_hallCLeft' - 625 * UnitDelay: '<S20>/UnitDelay' - 626 * UnitDelay: '<S20>/UnitDelay1' - 627 * UnitDelay: '<S20>/UnitDelay2' + 550 /* End of Signum: '<S14>/Sign' */ + 551 + 552 /* Switch: '<S10>/Switch1' incorporates: + 553 * Constant: '<S12>/vec_hallToPos' + 554 * Constant: '<S14>/CTRL_COMM' + 555 * Constant: '<S14>/r_commDCDeacv' + 556 * Constant: '<S7>/z_ctrlTypSel1' + 557 * Inport: '<Root>/r_DC' + 558 * Logic: '<S14>/Logical Operator2' + 559 * LookupNDDirect: '<S10>/z_commutMap_M1' + 560 * Product: '<S10>/Divide2' + 561 * Product: '<S10>/Divide4' + 562 * RelationalOperator: '<S14>/Relational Operator1' + 563 * RelationalOperator: '<S14>/Relational Operator3' + 564 * RelationalOperator: '<S14>/Relational Operator4' + 565 * Relay: '<S14>/dz_counter' + 566 * Relay: '<S14>/n_commDeacv' + 567 * Selector: '<S12>/Selector' + 568 * + 569 * About '<S10>/z_commutMap_M1': + 570 * 2-dimensional Direct Look-Up returning a Column + 571 */ + 572 if ((rtP->z_ctrlTypSel != 0) && (rtb_Switch1_idx_0 > rtP->r_commDCDeacv) && + 573 (rtb_Sum2_h == rtb_Switch1_idx_1) && rtDW->n_commDeacv_Mode && + 574 (!rtDW->dz_counter_Mode)) { + 575 rtb_Switch1_idx_0 = rtU->r_DC * rtDW->Merge; + 576 rtb_Switch1_idx_1 = rtU->r_DC * rtDW->Merge1; + 577 rtb_Abs5 = rtU->r_DC * rtDW->Merge2; + 578 } else { + 579 if (rtConstP.vec_hallToPos_Value[rtb_Sum] > 5) { + 580 /* LookupNDDirect: '<S10>/z_commutMap_M1' + 581 * + 582 * About '<S10>/z_commutMap_M1': + 583 * 2-dimensional Direct Look-Up returning a Column + 584 */ + 585 rtb_Sum2_h = 5; + 586 } else if (rtConstP.vec_hallToPos_Value[rtb_Sum] < 0) { + 587 /* LookupNDDirect: '<S10>/z_commutMap_M1' + 588 * + 589 * About '<S10>/z_commutMap_M1': + 590 * 2-dimensional Direct Look-Up returning a Column + 591 */ + 592 rtb_Sum2_h = 0; + 593 } else { + 594 /* LookupNDDirect: '<S10>/z_commutMap_M1' incorporates: + 595 * Constant: '<S12>/vec_hallToPos' + 596 * Selector: '<S12>/Selector' + 597 * + 598 * About '<S10>/z_commutMap_M1': + 599 * 2-dimensional Direct Look-Up returning a Column + 600 */ + 601 rtb_Sum2_h = rtConstP.vec_hallToPos_Value[rtb_Sum]; + 602 } + 603 + 604 /* LookupNDDirect: '<S10>/z_commutMap_M1' incorporates: + 605 * Constant: '<S12>/vec_hallToPos' + 606 * Selector: '<S12>/Selector' + 607 * + 608 * About '<S10>/z_commutMap_M1': + 609 * 2-dimensional Direct Look-Up returning a Column + 610 */ + 611 rtb_Abs5 = rtb_Sum2_h * 3; + 612 rtb_Switch1_idx_0 = rtU->r_DC * rtConstP.z_commutMap_M1_table[rtb_Abs5]; + 613 rtb_Switch1_idx_1 = rtConstP.z_commutMap_M1_table[1 + rtb_Abs5] * rtU->r_DC; + 614 rtb_Abs5 = rtConstP.z_commutMap_M1_table[2 + rtb_Abs5] * rtU->r_DC; + 615 } + 616 + 617 /* End of Switch: '<S10>/Switch1' */ + 618 + 619 /* Outport: '<Root>/DC_phaA' incorporates: + 620 * Constant: '<S10>/Constant1' + 621 * Product: '<S10>/Divide1' + 622 */ + 623 rtY->DC_phaA = rtb_Switch1_idx_0 / 1000; + 624 + 625 /* Outport: '<Root>/DC_phaB' incorporates: + 626 * Constant: '<S10>/Constant1' + 627 * Product: '<S10>/Divide1' 628 */ - 629 rtb_LogicalOperator = (boolean_T)((rtU.b_hallALeft != 0) ^ (rtU.b_hallBLeft != - 630 0) ^ (rtU.b_hallCLeft != 0) ^ (rtDW.UnitDelay_DSTATE != 0) ^ - 631 (rtDW.UnitDelay1_DSTATE_p != 0)) ^ (rtDW.UnitDelay2_DSTATE != 0); - 632 - 633 /* Outputs for Enabled SubSystem: '<S12>/F01_03_Direction_Detection' */ - 634 - 635 /* Selector: '<S21>/Selector' incorporates: - 636 * Constant: '<S21>/vec_hallToPos' - 637 * UnitDelay: '<S21>/UnitDelay1' + 629 rtY->DC_phaB = rtb_Switch1_idx_1 / 1000; + 630 + 631 /* Update for UnitDelay: '<S11>/UnitDelay' incorporates: + 632 * Inport: '<Root>/b_hallA ' + 633 */ + 634 rtDW->UnitDelay_DSTATE = rtU->b_hallA; + 635 + 636 /* Update for UnitDelay: '<S11>/UnitDelay1' incorporates: + 637 * Inport: '<Root>/b_hallB' 638 */ - 639 F01_03_Direction_Detection(rtb_LogicalOperator, rtConstP.pooled26[rtb_Sum], - 640 rtDW.UnitDelay1_DSTATE_g, &rtDW.Switch2_e, &rtDW.UnitDelay1_k, - 641 &rtDW.F01_03_Direction_Detection_o); - 642 - 643 /* End of Outputs for SubSystem: '<S12>/F01_03_Direction_Detection' */ - 644 - 645 /* Logic: '<S23>/Logical Operator3' incorporates: - 646 * Constant: '<S23>/z_maxCntRst' - 647 * RelationalOperator: '<S23>/Relational Operator1' - 648 * UnitDelay: '<S23>/z_counterRawPrev' - 649 */ - 650 rtb_LogicalOperator3 = (rtb_LogicalOperator || (rtDW.z_counterRawPrev_DSTATE > - 651 rtP.z_maxCntRst)); - 652 - 653 /* Outputs for Enabled SubSystem: '<S23>/Edge_counter' */ + 639 rtDW->UnitDelay1_DSTATE_i = rtU->b_hallB; + 640 + 641 /* Update for UnitDelay: '<S11>/UnitDelay2' incorporates: + 642 * Inport: '<Root>/b_hallC' + 643 */ + 644 rtDW->UnitDelay2_DSTATE_h = rtU->b_hallC; + 645 + 646 /* Update for UnitDelay: '<S17>/UnitDelay1' */ + 647 rtDW->UnitDelay1_DSTATE = rtb_Sum1_a; + 648 + 649 /* Update for UnitDelay: '<S14>/UnitDelay1' */ + 650 rtDW->UnitDelay1_DSTATE_c = rtb_Sum1_a; + 651 + 652 /* Update for UnitDelay: '<S16>/UnitDelay2' */ + 653 rtDW->UnitDelay2_DSTATE = rtb_Sum2; 654 - 655 /* Logic: '<S23>/Logical Operator2' incorporates: - 656 * UnitDelay: '<S23>/UnitDelay8' - 657 */ - 658 Edge_counter(!rtDW.UnitDelay8_DSTATE, rtb_LogicalOperator, rtDW.Switch2_e, - 659 rtDW.UnitDelay1_k, &rtDW.Sum2_l, &rtDW.Edge_counter_f); + 655 /* Outport: '<Root>/DC_phaC' incorporates: + 656 * Constant: '<S10>/Constant1' + 657 * Product: '<S10>/Divide1' + 658 */ + 659 rtY->DC_phaC = rtb_Abs5 / 1000; 660 - 661 /* End of Outputs for SubSystem: '<S23>/Edge_counter' */ + 661 /* End of Outputs for SubSystem: '<Root>/BLDC_controller' */ 662 - 663 /* Logic: '<S23>/Logical Operator5' incorporates: - 664 * Constant: '<S23>/z_maxCntRst2' - 665 * RelationalOperator: '<S23>/Relational Operator3' - 666 * RelationalOperator: '<S23>/Relational Operator6' - 667 * UnitDelay: '<S23>/z_counterRawPrev' - 668 */ - 669 rtDW.LogicalOperator5 = ((rtDW.Switch2_e != rtDW.UnitDelay1_k) || - 670 (rtDW.z_counterRawPrev_DSTATE > rtP.z_maxCntRst)); + 663 /* Outport: '<Root>/n_mot' */ + 664 rtY->n_mot = rtb_Sum2; + 665 } + 666 + 667 /* Model initialize function */ + 668 void BLDC_controller_initialize(RT_MODEL *const rtM) + 669 { + 670 DW *rtDW = ((DW *) rtM->dwork); 671 - 672 /* Outputs for Atomic SubSystem: '<S23>/rising_edge' */ - 673 rising_edge(); - 674 - 675 /* End of Outputs for SubSystem: '<S23>/rising_edge' */ - 676 - 677 /* CombinatorialLogic: '<S29>/Logic' incorporates: - 678 * Constant: '<S23>/z_nrEdgeSpdAcv' - 679 * Memory: '<S29>/Memory' - 680 * RelationalOperator: '<S23>/Relational Operator5' - 681 */ - 682 rtb_Switch1_idx_0 = (int32_T)(((((uint32_T)(rtDW.Sum2_l >= rtP.z_nrEdgeSpdAcv) - 683 << 1) + rtDW.LogicalOperator_h) << 1) + rtDW.Memory_PreviousInput); - 684 rtDW.Logic[0U] = rtConstP.pooled30[(uint32_T)rtb_Switch1_idx_0]; - 685 rtDW.Logic[1U] = rtConstP.pooled30[rtb_Switch1_idx_0 + 8U]; - 686 - 687 /* Outputs for Atomic SubSystem: '<S23>/falling_edge2' */ - 688 falling_edge2(); - 689 - 690 /* End of Outputs for SubSystem: '<S23>/falling_edge2' */ - 691 - 692 /* Switch: '<S23>/Switch' incorporates: - 693 * Logic: '<S23>/Logical Operator1' - 694 * Switch: '<S23>/Switch1' - 695 * UnitDelay: '<S23>/z_counter2' - 696 * UnitDelay: '<S23>/z_counterRawPrev' - 697 */ - 698 if (rtb_LogicalOperator3 && rtDW.Logic[0]) { - 699 rtb_Switch = rtDW.z_counterRawPrev_DSTATE; - 700 } else if (rtDW.LogicalOperator) { - 701 /* Switch: '<S23>/Switch1' incorporates: - 702 * Constant: '<S23>/z_maxCntRst1' - 703 */ - 704 rtb_Switch = rtP.z_maxCntRst; - 705 } else { - 706 rtb_Switch = rtDW.z_counter2_DSTATE; - 707 } - 708 - 709 /* End of Switch: '<S23>/Switch' */ - 710 - 711 /* Outputs for Triggered SubSystem: '<S23>/Motor_Speed_Calculation' */ - 712 - 713 /* Outport: '<Root>/n_motLeft' */ - 714 Motor_Speed_Calculation(rtb_LogicalOperator3, rtb_Switch, rtDW.Switch2_e, - 715 &rtY.n_motLeft, &rtDW.Motor_Speed_Calculation_m, - 716 &rtPrevZCX.Motor_Speed_Calculation_m); - 717 - 718 /* End of Outputs for SubSystem: '<S23>/Motor_Speed_Calculation' */ - 719 - 720 /* Abs: '<S15>/Abs5' incorporates: - 721 * Outport: '<Root>/n_motLeft' - 722 */ - 723 if (rtY.n_motLeft < 0) { - 724 rtb_Abs1 = -rtY.n_motLeft; - 725 } else { - 726 rtb_Abs1 = rtY.n_motLeft; - 727 } - 728 - 729 /* End of Abs: '<S15>/Abs5' */ - 730 - 731 /* Relay: '<S15>/Relay' */ - 732 if (rtb_Abs1 >= rtP.n_commDeacvHi) { - 733 rtDW.Relay_Mode = true; - 734 } else { - 735 if (rtb_Abs1 <= rtP.n_commAcvLo) { - 736 rtDW.Relay_Mode = false; - 737 } - 738 } - 739 - 740 /* Switch: '<S32>/Switch1' incorporates: - 741 * Constant: '<S32>/Constant23' - 742 * UnitDelay: '<S32>/UnitDelay1' - 743 */ - 744 if (rtb_LogicalOperator3) { - 745 rtb_Sum1_c = 0; - 746 } else { - 747 rtb_Sum1_c = rtDW.UnitDelay1_DSTATE; - 748 } - 749 - 750 /* End of Switch: '<S32>/Switch1' */ - 751 - 752 /* Sum: '<S23>/Sum1' */ - 753 rtb_Sum1 = (int16_T)(1 + rtb_Sum1_c); - 754 - 755 /* If: '<S2>/If1' incorporates: - 756 * Constant: '<S12>/z_ctrlTypSel1' - 757 * Constant: '<S21>/vec_hallToPos' - 758 * Inport: '<Root>/r_DCLeft' - 759 * Outport: '<Root>/a_elecAngleLeft' - 760 * Selector: '<S21>/Selector' - 761 */ - 762 rtPrevAction = rtDW.If1_ActiveSubsystem; - 763 rtAction = -1; - 764 if (rtP.z_ctrlTypSel != 0) { - 765 rtAction = 0; - 766 } - 767 - 768 rtDW.If1_ActiveSubsystem = rtAction; - 769 if ((rtPrevAction != rtAction) && (rtPrevAction == 0)) { - 770 F02_Electrical_Angle_Ca_Disable(&rtDW.Switch_PhaAdv_a, &rtY.a_elecAngleLeft); - 771 } - 772 - 773 if (rtAction == 0) { - 774 /* Outputs for IfAction SubSystem: '<S2>/F02_Electrical_Angle_Calculation' incorporates: - 775 * ActionPort: '<S13>/Action Port' - 776 */ - 777 F02_Electrical_Angle_Calculatio(rtU.r_DCLeft, rtConstP.pooled26[rtb_Sum], - 778 rtDW.Switch2_e, rtb_Switch, rtb_Sum1, &rtDW.Switch_PhaAdv_a, - 779 &rtY.a_elecAngleLeft); - 780 - 781 /* End of Outputs for SubSystem: '<S2>/F02_Electrical_Angle_Calculation' */ - 782 } - 783 - 784 /* End of If: '<S2>/If1' */ - 785 - 786 /* SwitchCase: '<S14>/Switch Case' incorporates: - 787 * Constant: '<S12>/z_ctrlTypSel1' - 788 */ - 789 switch (rtP.z_ctrlTypSel) { - 790 case 1: - 791 /* Outputs for IfAction SubSystem: '<S14>/F03_01_Pure_Trapezoidal_Method' incorporates: - 792 * ActionPort: '<S41>/Action Port' - 793 */ - 794 F03_01_Pure_Trapezoidal_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, - 795 &rtDW.Merge1, &rtDW.Merge2); - 796 - 797 /* End of Outputs for SubSystem: '<S14>/F03_01_Pure_Trapezoidal_Method' */ - 798 break; - 799 - 800 case 2: - 801 /* Outputs for IfAction SubSystem: '<S14>/F03_02_Sinusoidal_Method' incorporates: - 802 * ActionPort: '<S43>/Action Port' - 803 */ - 804 F03_02_Sinusoidal_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, &rtDW.Merge1, - 805 &rtDW.Merge2); - 806 - 807 /* End of Outputs for SubSystem: '<S14>/F03_02_Sinusoidal_Method' */ - 808 break; - 809 - 810 case 3: - 811 /* Outputs for IfAction SubSystem: '<S14>/F03_02_Sinusoidal3rd_Method' incorporates: - 812 * ActionPort: '<S42>/Action Port' - 813 */ - 814 F03_02_Sinusoidal3rd_Method(rtDW.Switch_PhaAdv_a, &rtDW.Merge, &rtDW.Merge1, - 815 &rtDW.Merge2); - 816 - 817 /* End of Outputs for SubSystem: '<S14>/F03_02_Sinusoidal3rd_Method' */ - 818 break; - 819 } - 820 - 821 /* End of SwitchCase: '<S14>/Switch Case' */ - 822 - 823 /* Abs: '<S15>/Abs1' incorporates: - 824 * Inport: '<Root>/r_DCLeft' - 825 */ - 826 if (rtU.r_DCLeft < 0) { - 827 rtb_Switch1_idx_0 = -rtU.r_DCLeft; - 828 } else { - 829 rtb_Switch1_idx_0 = rtU.r_DCLeft; - 830 } - 831 - 832 /* End of Abs: '<S15>/Abs1' */ - 833 - 834 /* Switch: '<S15>/Switch1' incorporates: - 835 * Constant: '<S12>/z_ctrlTypSel1' - 836 * Constant: '<S15>/CTRL_COMM' - 837 * Constant: '<S15>/r_commDCDeacv' - 838 * Constant: '<S21>/vec_hallToPos' - 839 * Inport: '<Root>/r_DCLeft' - 840 * Logic: '<S15>/Logical Operator3' - 841 * LookupNDDirect: '<S15>/z_commutMap_M1' - 842 * Product: '<S15>/Divide2' - 843 * Product: '<S15>/Divide4' - 844 * RelationalOperator: '<S15>/Relational Operator1' - 845 * RelationalOperator: '<S15>/Relational Operator2' - 846 * Relay: '<S15>/Relay' - 847 * Selector: '<S21>/Selector' - 848 * - 849 * About '<S15>/z_commutMap_M1': - 850 * 2-dimensional Direct Look-Up returning a Column - 851 */ - 852 if (rtDW.Relay_Mode && (rtb_Switch1_idx_0 > rtP.r_commDCDeacv) && - 853 (rtP.z_ctrlTypSel != 0)) { - 854 rtb_Switch1_idx_0 = rtU.r_DCLeft * rtDW.Merge; - 855 rtb_Switch1_idx_1 = rtU.r_DCLeft * rtDW.Merge1; - 856 rtb_Abs1 = rtU.r_DCLeft * rtDW.Merge2; - 857 } else { - 858 if (rtConstP.pooled26[rtb_Sum] < 5) { - 859 /* LookupNDDirect: '<S15>/z_commutMap_M1' incorporates: - 860 * Constant: '<S21>/vec_hallToPos' - 861 * Selector: '<S21>/Selector' - 862 * - 863 * About '<S15>/z_commutMap_M1': - 864 * 2-dimensional Direct Look-Up returning a Column - 865 */ - 866 tmp = rtConstP.pooled26[rtb_Sum]; - 867 } else { - 868 /* LookupNDDirect: '<S15>/z_commutMap_M1' - 869 * - 870 * About '<S15>/z_commutMap_M1': - 871 * 2-dimensional Direct Look-Up returning a Column - 872 */ - 873 tmp = 5U; - 874 } - 875 - 876 /* LookupNDDirect: '<S15>/z_commutMap_M1' - 877 * - 878 * About '<S15>/z_commutMap_M1': - 879 * 2-dimensional Direct Look-Up returning a Column - 880 */ - 881 rtb_Abs1 = tmp * 3; - 882 rtb_Switch1_idx_0 = rtU.r_DCLeft * rtConstP.pooled18[rtb_Abs1]; - 883 rtb_Switch1_idx_1 = rtConstP.pooled18[1 + rtb_Abs1] * rtU.r_DCLeft; - 884 rtb_Abs1 = rtConstP.pooled18[2 + rtb_Abs1] * rtU.r_DCLeft; - 885 } - 886 - 887 /* End of Switch: '<S15>/Switch1' */ - 888 - 889 /* Outport: '<Root>/DC_phaALeft' incorporates: - 890 * Constant: '<S15>/Constant1' - 891 * Product: '<S15>/Divide1' - 892 */ - 893 rtY.DC_phaALeft = rtb_Switch1_idx_0 / 1000; - 894 - 895 /* Outport: '<Root>/DC_phaBLeft' incorporates: - 896 * Constant: '<S15>/Constant1' - 897 * Product: '<S15>/Divide1' - 898 */ - 899 rtY.DC_phaBLeft = rtb_Switch1_idx_1 / 1000; - 900 - 901 /* Outport: '<Root>/DC_phaCLeft' incorporates: - 902 * Constant: '<S15>/Constant1' - 903 * Product: '<S15>/Divide1' - 904 */ - 905 rtY.DC_phaCLeft = rtb_Abs1 / 1000; - 906 - 907 /* Sum: '<S59>/Sum' incorporates: - 908 * Gain: '<S59>/g_Ha' - 909 * Gain: '<S59>/g_Hb' - 910 * Inport: '<Root>/b_hallARight' - 911 * Inport: '<Root>/b_hallBRight' - 912 * Inport: '<Root>/b_hallCRight' - 913 */ - 914 rtb_Sum_a = (uint8_T)((uint32_T)(uint8_T)((uint32_T)(uint8_T)(rtU.b_hallARight - 915 << 2) + (uint8_T)(rtU.b_hallBRight << 1)) + rtU.b_hallCRight); - 916 - 917 /* Logic: '<S58>/Logical Operator' incorporates: - 918 * Inport: '<Root>/b_hallARight' - 919 * Inport: '<Root>/b_hallBRight' - 920 * Inport: '<Root>/b_hallCRight' - 921 * UnitDelay: '<S58>/UnitDelay' - 922 * UnitDelay: '<S58>/UnitDelay1' - 923 * UnitDelay: '<S58>/UnitDelay2' - 924 */ - 925 rtb_LogicalOperator = (boolean_T)((rtU.b_hallARight != 0) ^ (rtU.b_hallBRight - 926 != 0) ^ (rtU.b_hallCRight != 0) ^ (rtDW.UnitDelay_DSTATE_j != 0) ^ - 927 (rtDW.UnitDelay1_DSTATE_f != 0)) ^ (rtDW.UnitDelay2_DSTATE_b != 0); - 928 - 929 /* Outputs for Enabled SubSystem: '<S50>/F01_03_Direction_Detection' */ - 930 - 931 /* Selector: '<S59>/Selector' incorporates: - 932 * Constant: '<S59>/vec_hallToPos' - 933 * UnitDelay: '<S59>/UnitDelay1' - 934 */ - 935 F01_03_Direction_Detection(rtb_LogicalOperator, rtConstP.pooled26[rtb_Sum_a], - 936 rtDW.UnitDelay1_DSTATE_j, &rtDW.Switch2, &rtDW.UnitDelay1, - 937 &rtDW.F01_03_Direction_Detection_j); - 938 - 939 /* End of Outputs for SubSystem: '<S50>/F01_03_Direction_Detection' */ - 940 - 941 /* Logic: '<S61>/Logical Operator3' incorporates: - 942 * Constant: '<S61>/z_maxCntRst' - 943 * RelationalOperator: '<S61>/Relational Operator1' - 944 * UnitDelay: '<S61>/z_counterRawPrev' - 945 */ - 946 rtb_LogicalOperator3 = (rtb_LogicalOperator || (rtDW.z_counterRawPrev_DSTATE_p - 947 > rtP.z_maxCntRst)); - 948 - 949 /* Outputs for Enabled SubSystem: '<S61>/Edge_counter' */ - 950 - 951 /* Logic: '<S61>/Logical Operator2' incorporates: - 952 * UnitDelay: '<S61>/UnitDelay8' - 953 */ - 954 Edge_counter(!rtDW.UnitDelay8_DSTATE_p, rtb_LogicalOperator, rtDW.Switch2, - 955 rtDW.UnitDelay1, &rtDW.Sum2_i, &rtDW.Edge_counter_l); - 956 - 957 /* End of Outputs for SubSystem: '<S61>/Edge_counter' */ - 958 - 959 /* Logic: '<S61>/Logical Operator5' incorporates: - 960 * Constant: '<S61>/z_maxCntRst2' - 961 * RelationalOperator: '<S61>/Relational Operator3' - 962 * RelationalOperator: '<S61>/Relational Operator6' - 963 * UnitDelay: '<S61>/z_counterRawPrev' - 964 */ - 965 rtDW.LogicalOperator5 = ((rtDW.Switch2 != rtDW.UnitDelay1) || - 966 (rtDW.z_counterRawPrev_DSTATE_p > rtP.z_maxCntRst)); - 967 - 968 /* Outputs for Atomic SubSystem: '<S61>/rising_edge' */ - 969 rising_edge_f(); - 970 - 971 /* End of Outputs for SubSystem: '<S61>/rising_edge' */ - 972 - 973 /* CombinatorialLogic: '<S67>/Logic' incorporates: - 974 * Constant: '<S61>/z_nrEdgeSpdAcv' - 975 * Memory: '<S67>/Memory' - 976 * RelationalOperator: '<S61>/Relational Operator5' - 977 */ - 978 rtb_Switch1_idx_0 = (int32_T)(((((uint32_T)(rtDW.Sum2_i >= rtP.z_nrEdgeSpdAcv) - 979 << 1) + rtDW.LogicalOperator_h) << 1) + rtDW.Memory_PreviousInput_i); - 980 rtDW.Logic_j[0U] = rtConstP.pooled30[(uint32_T)rtb_Switch1_idx_0]; - 981 rtDW.Logic_j[1U] = rtConstP.pooled30[rtb_Switch1_idx_0 + 8U]; - 982 - 983 /* Outputs for Atomic SubSystem: '<S61>/falling_edge2' */ - 984 falling_edge2_b(); - 985 - 986 /* End of Outputs for SubSystem: '<S61>/falling_edge2' */ - 987 - 988 /* Switch: '<S61>/Switch' incorporates: - 989 * Logic: '<S61>/Logical Operator1' - 990 * Switch: '<S61>/Switch1' - 991 * UnitDelay: '<S61>/z_counter2' - 992 * UnitDelay: '<S61>/z_counterRawPrev' - 993 */ - 994 if (rtb_LogicalOperator3 && rtDW.Logic_j[0]) { - 995 rtb_Switch_b = rtDW.z_counterRawPrev_DSTATE_p; - 996 } else if (rtDW.LogicalOperator_h) { - 997 /* Switch: '<S61>/Switch1' incorporates: - 998 * Constant: '<S61>/z_maxCntRst1' - 999 */ - 1000 rtb_Switch_b = rtP.z_maxCntRst; - 1001 } else { - 1002 rtb_Switch_b = rtDW.z_counter2_DSTATE_h; - 1003 } - 1004 - 1005 /* End of Switch: '<S61>/Switch' */ - 1006 - 1007 /* Outputs for Triggered SubSystem: '<S61>/Motor_Speed_Calculation' */ - 1008 - 1009 /* Outport: '<Root>/n_motRight' */ - 1010 Motor_Speed_Calculation(rtb_LogicalOperator3, rtb_Switch_b, rtDW.Switch2, - 1011 &rtY.n_motRight, &rtDW.Motor_Speed_Calculation_k, - 1012 &rtPrevZCX.Motor_Speed_Calculation_k); - 1013 - 1014 /* End of Outputs for SubSystem: '<S61>/Motor_Speed_Calculation' */ - 1015 - 1016 /* Abs: '<S53>/Abs5' incorporates: - 1017 * Outport: '<Root>/n_motRight' - 1018 */ - 1019 if (rtY.n_motRight < 0) { - 1020 rtb_Abs1 = -rtY.n_motRight; - 1021 } else { - 1022 rtb_Abs1 = rtY.n_motRight; - 1023 } - 1024 - 1025 /* End of Abs: '<S53>/Abs5' */ - 1026 - 1027 /* Relay: '<S53>/Relay' */ - 1028 if (rtb_Abs1 >= rtP.n_commDeacvHi) { - 1029 rtDW.Relay_Mode_m = true; - 1030 } else { - 1031 if (rtb_Abs1 <= rtP.n_commAcvLo) { - 1032 rtDW.Relay_Mode_m = false; - 1033 } - 1034 } - 1035 - 1036 /* Switch: '<S70>/Switch1' incorporates: - 1037 * Constant: '<S70>/Constant23' - 1038 * UnitDelay: '<S70>/UnitDelay1' - 1039 */ - 1040 if (rtb_LogicalOperator3) { - 1041 rtb_Sum1_c = 0; - 1042 } else { - 1043 rtb_Sum1_c = rtDW.UnitDelay1_DSTATE_k; - 1044 } - 1045 - 1046 /* End of Switch: '<S70>/Switch1' */ - 1047 - 1048 /* Sum: '<S61>/Sum1' */ - 1049 rtb_Sum1_c++; - 1050 - 1051 /* If: '<S3>/If1' incorporates: - 1052 * Constant: '<S50>/z_ctrlTypSel1' - 1053 * Constant: '<S59>/vec_hallToPos' - 1054 * Inport: '<Root>/r_DCRight' - 1055 * Outport: '<Root>/a_elecAngleRight' - 1056 * Selector: '<S59>/Selector' - 1057 */ - 1058 rtPrevAction = rtDW.If1_ActiveSubsystem_j; - 1059 rtAction = -1; - 1060 if (rtP.z_ctrlTypSel != 0) { - 1061 rtAction = 0; - 1062 } - 1063 - 1064 rtDW.If1_ActiveSubsystem_j = rtAction; - 1065 if ((rtPrevAction != rtAction) && (rtPrevAction == 0)) { - 1066 F02_Electrical_Angle_Ca_Disable(&rtDW.Switch_PhaAdv, &rtY.a_elecAngleRight); - 1067 } - 1068 - 1069 if (rtAction == 0) { - 1070 /* Outputs for IfAction SubSystem: '<S3>/F02_Electrical_Angle_Calculation' incorporates: - 1071 * ActionPort: '<S51>/Action Port' - 1072 */ - 1073 F02_Electrical_Angle_Calculatio(rtU.r_DCRight, rtConstP.pooled26[rtb_Sum_a], - 1074 rtDW.Switch2, rtb_Switch_b, rtb_Sum1_c, &rtDW.Switch_PhaAdv, - 1075 &rtY.a_elecAngleRight); - 1076 - 1077 /* End of Outputs for SubSystem: '<S3>/F02_Electrical_Angle_Calculation' */ - 1078 } - 1079 - 1080 /* End of If: '<S3>/If1' */ - 1081 - 1082 /* SwitchCase: '<S52>/Switch Case' incorporates: - 1083 * Constant: '<S50>/z_ctrlTypSel1' - 1084 */ - 1085 switch (rtP.z_ctrlTypSel) { - 1086 case 1: - 1087 /* Outputs for IfAction SubSystem: '<S52>/F03_01_Pure_Trapezoidal_Method' incorporates: - 1088 * ActionPort: '<S79>/Action Port' - 1089 */ - 1090 F03_01_Pure_Trapezoidal_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, - 1091 &rtDW.Merge1_m, &rtDW.Merge2_d); - 1092 - 1093 /* End of Outputs for SubSystem: '<S52>/F03_01_Pure_Trapezoidal_Method' */ - 1094 break; - 1095 - 1096 case 2: - 1097 /* Outputs for IfAction SubSystem: '<S52>/F03_02_Sinusoidal_Method' incorporates: - 1098 * ActionPort: '<S81>/Action Port' - 1099 */ - 1100 F03_02_Sinusoidal_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, &rtDW.Merge1_m, - 1101 &rtDW.Merge2_d); - 1102 - 1103 /* End of Outputs for SubSystem: '<S52>/F03_02_Sinusoidal_Method' */ - 1104 break; - 1105 - 1106 case 3: - 1107 /* Outputs for IfAction SubSystem: '<S52>/F03_02_Sinusoidal3rd_Method' incorporates: - 1108 * ActionPort: '<S80>/Action Port' - 1109 */ - 1110 F03_02_Sinusoidal3rd_Method(rtDW.Switch_PhaAdv, &rtDW.Merge_j, - 1111 &rtDW.Merge1_m, &rtDW.Merge2_d); - 1112 - 1113 /* End of Outputs for SubSystem: '<S52>/F03_02_Sinusoidal3rd_Method' */ - 1114 break; - 1115 } - 1116 - 1117 /* End of SwitchCase: '<S52>/Switch Case' */ - 1118 - 1119 /* Abs: '<S53>/Abs1' incorporates: - 1120 * Inport: '<Root>/r_DCRight' - 1121 */ - 1122 if (rtU.r_DCRight < 0) { - 1123 rtb_Switch1_idx_0 = -rtU.r_DCRight; - 1124 } else { - 1125 rtb_Switch1_idx_0 = rtU.r_DCRight; - 1126 } - 1127 - 1128 /* End of Abs: '<S53>/Abs1' */ - 1129 - 1130 /* Switch: '<S53>/Switch1' incorporates: - 1131 * Constant: '<S50>/z_ctrlTypSel1' - 1132 * Constant: '<S53>/CTRL_COMM' - 1133 * Constant: '<S53>/r_commDCDeacv' - 1134 * Constant: '<S59>/vec_hallToPos' - 1135 * Inport: '<Root>/r_DCRight' - 1136 * Logic: '<S53>/Logical Operator3' - 1137 * LookupNDDirect: '<S53>/z_commutMap_M1' - 1138 * Product: '<S53>/Divide2' - 1139 * Product: '<S53>/Divide4' - 1140 * RelationalOperator: '<S53>/Relational Operator1' - 1141 * RelationalOperator: '<S53>/Relational Operator2' - 1142 * Relay: '<S53>/Relay' - 1143 * Selector: '<S59>/Selector' - 1144 * - 1145 * About '<S53>/z_commutMap_M1': - 1146 * 2-dimensional Direct Look-Up returning a Column - 1147 */ - 1148 if (rtDW.Relay_Mode_m && (rtb_Switch1_idx_0 > rtP.r_commDCDeacv) && - 1149 (rtP.z_ctrlTypSel != 0)) { - 1150 rtb_Switch1_idx_0 = rtU.r_DCRight * rtDW.Merge_j; - 1151 rtb_Switch1_idx_1 = rtU.r_DCRight * rtDW.Merge1_m; - 1152 rtb_Abs1 = rtU.r_DCRight * rtDW.Merge2_d; - 1153 } else { - 1154 if (rtConstP.pooled26[rtb_Sum_a] < 5) { - 1155 /* LookupNDDirect: '<S53>/z_commutMap_M1' incorporates: - 1156 * Constant: '<S59>/vec_hallToPos' - 1157 * Selector: '<S59>/Selector' - 1158 * - 1159 * About '<S53>/z_commutMap_M1': - 1160 * 2-dimensional Direct Look-Up returning a Column - 1161 */ - 1162 tmp = rtConstP.pooled26[rtb_Sum_a]; - 1163 } else { - 1164 /* LookupNDDirect: '<S53>/z_commutMap_M1' - 1165 * - 1166 * About '<S53>/z_commutMap_M1': - 1167 * 2-dimensional Direct Look-Up returning a Column - 1168 */ - 1169 tmp = 5U; - 1170 } - 1171 - 1172 /* LookupNDDirect: '<S53>/z_commutMap_M1' - 1173 * - 1174 * About '<S53>/z_commutMap_M1': - 1175 * 2-dimensional Direct Look-Up returning a Column - 1176 */ - 1177 rtb_Abs1 = tmp * 3; - 1178 rtb_Switch1_idx_0 = rtU.r_DCRight * rtConstP.pooled18[rtb_Abs1]; - 1179 rtb_Switch1_idx_1 = rtConstP.pooled18[1 + rtb_Abs1] * rtU.r_DCRight; - 1180 rtb_Abs1 = rtConstP.pooled18[2 + rtb_Abs1] * rtU.r_DCRight; - 1181 } - 1182 - 1183 /* End of Switch: '<S53>/Switch1' */ - 1184 - 1185 /* Outport: '<Root>/DC_phaARight' incorporates: - 1186 * Constant: '<S53>/Constant1' - 1187 * Product: '<S53>/Divide1' - 1188 */ - 1189 rtY.DC_phaARight = rtb_Switch1_idx_0 / 1000; - 1190 - 1191 /* Outport: '<Root>/DC_phaBRight' incorporates: - 1192 * Constant: '<S53>/Constant1' - 1193 * Product: '<S53>/Divide1' - 1194 */ - 1195 rtY.DC_phaBRight = rtb_Switch1_idx_1 / 1000; - 1196 - 1197 /* Update for UnitDelay: '<S20>/UnitDelay' incorporates: - 1198 * Inport: '<Root>/b_hallALeft ' - 1199 */ - 1200 rtDW.UnitDelay_DSTATE = rtU.b_hallALeft; - 1201 - 1202 /* Update for UnitDelay: '<S20>/UnitDelay1' incorporates: - 1203 * Inport: '<Root>/b_hallBLeft' - 1204 */ - 1205 rtDW.UnitDelay1_DSTATE_p = rtU.b_hallBLeft; - 1206 - 1207 /* Update for UnitDelay: '<S20>/UnitDelay2' incorporates: - 1208 * Inport: '<Root>/b_hallCLeft' - 1209 */ - 1210 rtDW.UnitDelay2_DSTATE = rtU.b_hallCLeft; - 1211 - 1212 /* Update for UnitDelay: '<S21>/UnitDelay1' incorporates: - 1213 * Constant: '<S21>/vec_hallToPos' - 1214 * Selector: '<S21>/Selector' - 1215 */ - 1216 rtDW.UnitDelay1_DSTATE_g = rtConstP.pooled26[rtb_Sum]; - 1217 - 1218 /* Update for UnitDelay: '<S23>/z_counterRawPrev' */ - 1219 rtDW.z_counterRawPrev_DSTATE = rtb_Sum1; - 1220 - 1221 /* Update for UnitDelay: '<S23>/UnitDelay8' */ - 1222 rtDW.UnitDelay8_DSTATE = rtDW.Logic[0]; - 1223 - 1224 /* Update for Memory: '<S29>/Memory' */ - 1225 rtDW.Memory_PreviousInput = rtDW.Logic[0]; - 1226 - 1227 /* Update for UnitDelay: '<S23>/z_counter2' */ - 1228 rtDW.z_counter2_DSTATE = rtb_Switch; - 1229 - 1230 /* Update for UnitDelay: '<S32>/UnitDelay1' */ - 1231 rtDW.UnitDelay1_DSTATE = rtb_Sum1; - 1232 - 1233 /* Update for UnitDelay: '<S58>/UnitDelay' incorporates: - 1234 * Inport: '<Root>/b_hallARight' - 1235 */ - 1236 rtDW.UnitDelay_DSTATE_j = rtU.b_hallARight; - 1237 - 1238 /* Update for UnitDelay: '<S58>/UnitDelay1' incorporates: - 1239 * Inport: '<Root>/b_hallBRight' - 1240 */ - 1241 rtDW.UnitDelay1_DSTATE_f = rtU.b_hallBRight; - 1242 - 1243 /* Update for UnitDelay: '<S58>/UnitDelay2' incorporates: - 1244 * Inport: '<Root>/b_hallCRight' - 1245 */ - 1246 rtDW.UnitDelay2_DSTATE_b = rtU.b_hallCRight; - 1247 - 1248 /* Update for UnitDelay: '<S59>/UnitDelay1' incorporates: - 1249 * Constant: '<S59>/vec_hallToPos' - 1250 * Selector: '<S59>/Selector' - 1251 */ - 1252 rtDW.UnitDelay1_DSTATE_j = rtConstP.pooled26[rtb_Sum_a]; - 1253 - 1254 /* Update for UnitDelay: '<S61>/z_counterRawPrev' */ - 1255 rtDW.z_counterRawPrev_DSTATE_p = rtb_Sum1_c; - 1256 - 1257 /* Update for UnitDelay: '<S61>/UnitDelay8' */ - 1258 rtDW.UnitDelay8_DSTATE_p = rtDW.Logic_j[0]; - 1259 - 1260 /* Update for Memory: '<S67>/Memory' */ - 1261 rtDW.Memory_PreviousInput_i = rtDW.Logic_j[0]; - 1262 - 1263 /* Update for UnitDelay: '<S61>/z_counter2' */ - 1264 rtDW.z_counter2_DSTATE_h = rtb_Switch_b; - 1265 - 1266 /* Update for UnitDelay: '<S70>/UnitDelay1' */ - 1267 rtDW.UnitDelay1_DSTATE_k = rtb_Sum1_c; - 1268 - 1269 /* Outport: '<Root>/DC_phaCRight' incorporates: - 1270 * Constant: '<S53>/Constant1' - 1271 * Product: '<S53>/Divide1' - 1272 */ - 1273 rtY.DC_phaCRight = rtb_Abs1 / 1000; - 1274 - 1275 /* End of Outputs for SubSystem: '<Root>/BLDC_controller' */ - 1276 } - 1277 - 1278 /* Model initialize function */ - 1279 void BLDC_controller_initialize(void) - 1280 { - 1281 /* Start for Atomic SubSystem: '<Root>/BLDC_controller' */ - 1282 /* Start for If: '<S2>/If1' */ - 1283 rtDW.If1_ActiveSubsystem = -1; - 1284 - 1285 /* Start for If: '<S3>/If1' */ - 1286 rtDW.If1_ActiveSubsystem_j = -1; - 1287 - 1288 /* End of Start for SubSystem: '<Root>/BLDC_controller' */ - 1289 rtPrevZCX.Motor_Speed_Calculation_k.Motor_Speed_Calculation_Trig_ZC = - 1290 POS_ZCSIG; - 1291 rtPrevZCX.Motor_Speed_Calculation_m.Motor_Speed_Calculation_Trig_ZC = - 1292 POS_ZCSIG; - 1293 - 1294 /* SystemInitialize for Atomic SubSystem: '<Root>/BLDC_controller' */ - 1295 /* InitializeConditions for UnitDelay: '<S23>/z_counter2' */ - 1296 rtDW.z_counter2_DSTATE = rtP.z_maxCntRst; - 1297 - 1298 /* InitializeConditions for UnitDelay: '<S61>/z_counter2' */ - 1299 rtDW.z_counter2_DSTATE_h = rtP.z_maxCntRst; - 1300 - 1301 /* End of SystemInitialize for SubSystem: '<Root>/BLDC_controller' */ - 1302 } - 1303 - 1304 /* - 1305 * File trailer for generated code. - 1306 * - 1307 * [EOF] - 1308 */ - 1309 + 672 /* Start for Atomic SubSystem: '<Root>/BLDC_controller' */ + 673 /* Start for If: '<S2>/If1' */ + 674 rtDW->If1_ActiveSubsystem = -1; + 675 + 676 /* End of Start for SubSystem: '<Root>/BLDC_controller' */ + 677 + 678 /* SystemInitialize for Atomic SubSystem: '<Root>/BLDC_controller' */ + 679 /* InitializeConditions for UnitDelay: '<S17>/UnitDelay1' */ + 680 rtDW->UnitDelay1_DSTATE = 1500; + 681 + 682 /* SystemInitialize for IfAction SubSystem: '<S14>/Counter_Hold_and_Error_Calculation' */ + 683 /* InitializeConditions for UnitDelay: '<S15>/z_counter2' */ + 684 rtDW->z_counter2_DSTATE = 1500; + 685 + 686 /* SystemInitialize for Outport: '<S15>/z_counter' */ + 687 rtDW->z_counterRawPrev = 1500; + 688 + 689 /* End of SystemInitialize for SubSystem: '<S14>/Counter_Hold_and_Error_Calculation' */ + 690 /* End of SystemInitialize for SubSystem: '<Root>/BLDC_controller' */ + 691 } + 692 + 693 /* + 694 * File trailer for generated code. + 695 * + 696 * [EOF] + 697 */ + 698

diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_contents.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_contents.html index 66aa5c6..dcf33e3 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_contents.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_contents.html @@ -256,10 +256,10 @@ BLDC_controller_data.c @@ -277,15 +277,6 @@ rtwtypes.h - - - -
-[+] +[+] -Utility files (2) +Utility files (1)
- -zero_crossing_types.h - - -
diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_data_c.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_data_c.html index 3b009bd..e2cd23c 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_data_c.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_data_c.html @@ -21,9 +21,9 @@ 7 * 8 * Code generated for Simulink model 'BLDC_controller'. 9 * - 10 * Model version : 1.817 + 10 * Model version : 1.877 11 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - 12 * C/C++ source code generated on : Tue May 28 19:55:33 2019 + 12 * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 13 * 14 * Target selection: ert.tlc 15 * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -37,193 +37,83 @@ 23 24 #include "BLDC_controller.h" 25 - 26 /* Block parameters (auto storage) */ - 27 P rtP = { - 28 /* Variable: cf_speedCoef - 29 * Referenced by: - 30 * '<S28>/cf_spdCoef' - 31 * '<S66>/cf_spdCoef' - 32 */ - 33 66667, - 34 - 35 /* Variable: n_commAcvLo - 36 * Referenced by: - 37 * '<S15>/Relay' - 38 * '<S53>/Relay' - 39 */ - 40 100, - 41 - 42 /* Variable: n_commDeacvHi - 43 * Referenced by: - 44 * '<S15>/Relay' - 45 * '<S53>/Relay' - 46 */ - 47 180, - 48 - 49 /* Variable: r_commDCDeacv - 50 * Referenced by: - 51 * '<S15>/r_commDCDeacv' - 52 * '<S53>/r_commDCDeacv' - 53 */ - 54 70, - 55 - 56 /* Variable: r_phaAdvDC_XA - 57 * Referenced by: - 58 * '<S13>/r_phaAdvDC_XA' - 59 * '<S51>/r_phaAdvDC_XA' - 60 */ - 61 { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }, - 62 - 63 /* Variable: a_phaAdv_M1 - 64 * Referenced by: - 65 * '<S13>/a_phaAdv_M2' - 66 * '<S51>/a_phaAdv_M2' - 67 */ - 68 { 0, 0, 7, 2, 2, 2, 4, 5, 9, 16, 25 }, - 69 - 70 /* Variable: z_maxCntRst - 71 * Referenced by: - 72 * '<S23>/z_maxCntRst' - 73 * '<S23>/z_maxCntRst1' - 74 * '<S23>/z_maxCntRst2' - 75 * '<S23>/z_counter2' - 76 * '<S61>/z_maxCntRst' - 77 * '<S61>/z_maxCntRst1' - 78 * '<S61>/z_maxCntRst2' - 79 * '<S61>/z_counter2' - 80 * '<S28>/z_maxCntRst' - 81 * '<S66>/z_maxCntRst' - 82 */ - 83 2000, + 26 /* Constant parameters (auto storage) */ + 27 const ConstP rtConstP = { + 28 /* Computed Parameter: r_trapPhaA_M1_Table + 29 * Referenced by: '<S18>/r_trapPhaA_M1' + 30 */ + 31 { 1000, 1000, 1000, -1000, -1000, -1000, 1000 }, + 32 + 33 /* Computed Parameter: r_trapPhaB_M1_Table + 34 * Referenced by: '<S18>/r_trapPhaB_M1' + 35 */ + 36 { -1000, -1000, 1000, 1000, 1000, -1000, -1000 }, + 37 + 38 /* Computed Parameter: r_trapPhaC_M1_Table + 39 * Referenced by: '<S18>/r_trapPhaC_M1' + 40 */ + 41 { 1000, -1000, -1000, -1000, 1000, 1000, 1000 }, + 42 + 43 /* Computed Parameter: r_sinPhaA_M1_Table + 44 * Referenced by: '<S19>/r_sinPhaA_M1' + 45 */ + 46 { 500, 643, 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, + 47 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, -985, -940, -866, + 48 -766, -643, -500, -342, -174, 0, 174, 342, 500 }, + 49 + 50 /* Computed Parameter: r_sinPhaB_M1_Table + 51 * Referenced by: '<S19>/r_sinPhaB_M1' + 52 */ + 53 { -1000, -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, + 54 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, 0, -174, + 55 -342, -500, -643, -766, -866, -940, -985, -1000 }, + 56 + 57 /* Computed Parameter: r_sinPhaC_M1_Table + 58 * Referenced by: '<S19>/r_sinPhaC_M1' + 59 */ + 60 { 500, 342, 174, 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, + 61 -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, 766, + 62 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500 }, + 63 + 64 /* Computed Parameter: r_sin3PhaA_M1_Table + 65 * Referenced by: '<S20>/r_sin3PhaA_M1' + 66 */ + 67 { 795, 930, 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, + 68 -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, -971, -996, -991, + 69 -930, -795, -584, -310, 0, 310, 584, 795 }, + 70 + 71 /* Computed Parameter: r_sin3PhaB_M1_Table + 72 * Referenced by: '<S20>/r_sin3PhaB_M1' + 73 */ + 74 { -930, -942, -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, + 75 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, -310, + 76 -584, -795, -930, -991, -996, -971, -942, -930 }, + 77 + 78 /* Computed Parameter: r_sin3PhaC_M1_Table + 79 * Referenced by: '<S20>/r_sin3PhaC_M1' + 80 */ + 81 { 795, 584, 310, 0, -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, + 82 -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, 991, 996, + 83 971, 942, 930, 942, 971, 996, 991, 930, 795 }, 84 - 85 /* Variable: z_ctrlTypSel - 86 * Referenced by: - 87 * '<S12>/z_ctrlTypSel1' - 88 * '<S50>/z_ctrlTypSel1' - 89 */ - 90 3U, - 91 - 92 /* Variable: z_nrEdgeSpdAcv - 93 * Referenced by: - 94 * '<S23>/z_nrEdgeSpdAcv' - 95 * '<S61>/z_nrEdgeSpdAcv' - 96 */ - 97 3U, - 98 - 99 /* Variable: b_phaAdvEna - 100 * Referenced by: - 101 * '<S13>/a_elecPeriod1' - 102 * '<S51>/a_elecPeriod1' - 103 */ - 104 1 - 105 }; - 106 - 107 /* Constant parameters (auto storage) */ - 108 const ConstP rtConstP = { - 109 /* Pooled Parameter (Expression: r_trapPhaA_M1) - 110 * Referenced by: - 111 * '<S41>/r_trapPhaA_M1' - 112 * '<S79>/r_trapPhaA_M1' - 113 */ - 114 { 1000, 1000, 1000, -1000, -1000, -1000, 1000 }, - 115 - 116 /* Pooled Parameter (Expression: r_trapPhaB_M1) - 117 * Referenced by: - 118 * '<S41>/r_trapPhaB_M1' - 119 * '<S79>/r_trapPhaB_M1' - 120 */ - 121 { -1000, -1000, 1000, 1000, 1000, -1000, -1000 }, - 122 - 123 /* Pooled Parameter (Expression: r_trapPhaC_M1) - 124 * Referenced by: - 125 * '<S41>/r_trapPhaC_M1' - 126 * '<S79>/r_trapPhaC_M1' - 127 */ - 128 { 1000, -1000, -1000, -1000, 1000, 1000, 1000 }, - 129 - 130 /* Pooled Parameter (Expression: r_sinPhaA_M1) - 131 * Referenced by: - 132 * '<S43>/r_sinPhaA_M1' - 133 * '<S81>/r_sinPhaA_M1' - 134 */ - 135 { 500, 643, 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, - 136 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, -985, -940, -866, - 137 -766, -643, -500, -342, -174, 0, 174, 342, 500 }, - 138 - 139 /* Pooled Parameter (Expression: r_sinPhaB_M1) - 140 * Referenced by: - 141 * '<S43>/r_sinPhaB_M1' - 142 * '<S81>/r_sinPhaB_M1' - 143 */ - 144 { -1000, -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, - 145 766, 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500, 342, 174, 0, -174, - 146 -342, -500, -643, -766, -866, -940, -985, -1000 }, - 147 - 148 /* Pooled Parameter (Expression: r_sinPhaC_M1) - 149 * Referenced by: - 150 * '<S43>/r_sinPhaC_M1' - 151 * '<S81>/r_sinPhaC_M1' - 152 */ - 153 { 500, 342, 174, 0, -174, -342, -500, -643, -766, -866, -940, -985, -1000, - 154 -985, -940, -866, -766, -643, -500, -342, -174, 0, 174, 342, 500, 643, 766, - 155 866, 940, 985, 1000, 985, 940, 866, 766, 643, 500 }, - 156 - 157 /* Pooled Parameter (Expression: r_sin3PhaA_M1) - 158 * Referenced by: - 159 * '<S42>/r_sin3PhaA_M1' - 160 * '<S80>/r_sin3PhaA_M1' - 161 */ - 162 { 795, 930, 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, - 163 -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, -971, -996, -991, - 164 -930, -795, -584, -310, 0, 310, 584, 795 }, - 165 - 166 /* Pooled Parameter (Expression: r_sin3PhaB_M1) - 167 * Referenced by: - 168 * '<S42>/r_sin3PhaB_M1' - 169 * '<S80>/r_sin3PhaB_M1' - 170 */ - 171 { -930, -942, -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, - 172 991, 996, 971, 942, 930, 942, 971, 996, 991, 930, 795, 584, 310, 0, -310, - 173 -584, -795, -930, -991, -996, -971, -942, -930 }, - 174 - 175 /* Pooled Parameter (Expression: r_sin3PhaC_M1) - 176 * Referenced by: - 177 * '<S42>/r_sin3PhaC_M1' - 178 * '<S80>/r_sin3PhaC_M1' - 179 */ - 180 { 795, 584, 310, 0, -310, -584, -795, -930, -991, -996, -971, -942, -930, -942, - 181 -971, -996, -991, -930, -795, -584, -310, 0, 310, 584, 795, 930, 991, 996, - 182 971, 942, 930, 942, 971, 996, 991, 930, 795 }, - 183 - 184 /* Pooled Parameter (Expression: z_commutMap_M1) - 185 * Referenced by: - 186 * '<S15>/z_commutMap_M1' - 187 * '<S53>/z_commutMap_M1' - 188 */ - 189 { 1000, -1000, 0, 1000, 0, -1000, 0, 1000, -1000, -1000, 1000, 0, -1000, 0, - 190 1000, 0, -1000, 1000 }, - 191 - 192 /* Pooled Parameter (Expression: vec_hallToPos) - 193 * Referenced by: - 194 * '<S21>/vec_hallToPos' - 195 * '<S59>/vec_hallToPos' - 196 */ - 197 { 0U, 5U, 3U, 4U, 1U, 0U, 2U, 0U }, - 198 - 199 /* Pooled Parameter (Expression: [0 1;1 0;0 1;0 1;1 0;1 0;0 0;0 0]) - 200 * Referenced by: - 201 * '<S29>/Logic' - 202 * '<S67>/Logic' - 203 */ - 204 { 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 } - 205 }; - 206 - 207 /* - 208 * File trailer for generated code. - 209 * - 210 * [EOF] - 211 */ - 212 + 85 /* Computed Parameter: z_commutMap_M1_table + 86 * Referenced by: '<S10>/z_commutMap_M1' + 87 */ + 88 { 1000, -1000, 0, 1000, 0, -1000, 0, 1000, -1000, -1000, 1000, 0, -1000, 0, + 89 1000, 0, -1000, 1000 }, + 90 + 91 /* Computed Parameter: vec_hallToPos_Value + 92 * Referenced by: '<S12>/vec_hallToPos' + 93 */ + 94 { 0, 5, 3, 4, 1, 0, 2, 0 } + 95 }; + 96 + 97 /* + 98 * File trailer for generated code. + 99 * + 100 * [EOF] + 101 */ + 102

diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_h.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_h.html index 7cf5d7f..29f631b 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_h.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_h.html @@ -21,9 +21,9 @@ 7 * 8 * Code generated for Simulink model 'BLDC_controller'. 9 * - 10 * Model version : 1.817 + 10 * Model version : 1.877 11 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - 12 * C/C++ source code generated on : Tue May 28 19:55:33 2019 + 12 * C/C++ source code generated on : Wed Jun 5 22:29:28 2019 13 * 14 * Target selection: ert.tlc 15 * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -38,418 +38,226 @@ 24 #ifndef RTW_HEADER_BLDC_controller_h_ 25 #define RTW_HEADER_BLDC_controller_h_ 26 #include "rtwtypes.h" - 27 #include "zero_crossing_types.h" - 28 #ifndef BLDC_controller_COMMON_INCLUDES_ - 29 # define BLDC_controller_COMMON_INCLUDES_ - 30 #include "rtwtypes.h" - 31 #include "zero_crossing_types.h" - 32 #endif /* BLDC_controller_COMMON_INCLUDES_ */ + 27 #ifndef BLDC_controller_COMMON_INCLUDES_ + 28 # define BLDC_controller_COMMON_INCLUDES_ + 29 #include "rtwtypes.h" + 30 #endif /* BLDC_controller_COMMON_INCLUDES_ */ + 31 + 32 /* Macros for accessing real-time model data structure */ 33 - 34 /* Macros for accessing real-time model data structure */ - 35 - 36 /* Block signals and states (auto storage) for system '<S12>/F01_03_Direction_Detection' */ - 37 typedef struct { - 38 int8_T UnitDelay1_DSTATE; /* '<S22>/UnitDelay1' */ - 39 } DW_F01_03_Direction_Detection; - 40 - 41 /* Block signals and states (auto storage) for system '<S23>/Edge_counter' */ - 42 typedef struct { - 43 uint8_T UnitDelay1_DSTATE; /* '<S37>/UnitDelay1' */ - 44 boolean_T Edge_counter_MODE; /* '<S23>/Edge_counter' */ - 45 } DW_Edge_counter; - 46 - 47 /* Block signals and states (auto storage) for system '<S23>/Motor_Speed_Calculation' */ - 48 typedef struct { - 49 int32_T UnitDelay5_DSTATE; /* '<S28>/UnitDelay5' */ - 50 int32_T UnitDelay1_DSTATE; /* '<S28>/UnitDelay1' */ - 51 } DW_Motor_Speed_Calculation; - 52 - 53 /* Zero-crossing (trigger) state for system '<S23>/Motor_Speed_Calculation' */ - 54 typedef struct { - 55 ZCSigState Motor_Speed_Calculation_Trig_ZC;/* '<S23>/Motor_Speed_Calculation' */ - 56 } ZCE_Motor_Speed_Calculation; - 57 - 58 /* Block signals and states (auto storage) for system '<Root>' */ - 59 typedef struct { - 60 DW_Motor_Speed_Calculation Motor_Speed_Calculation_k;/* '<S61>/Motor_Speed_Calculation' */ - 61 DW_Edge_counter Edge_counter_l; /* '<S61>/Edge_counter' */ - 62 DW_F01_03_Direction_Detection F01_03_Direction_Detection_j;/* '<S50>/F01_03_Direction_Detection' */ - 63 DW_Motor_Speed_Calculation Motor_Speed_Calculation_m;/* '<S23>/Motor_Speed_Calculation' */ - 64 DW_Edge_counter Edge_counter_f; /* '<S23>/Edge_counter' */ - 65 DW_F01_03_Direction_Detection F01_03_Direction_Detection_o;/* '<S12>/F01_03_Direction_Detection' */ - 66 int32_T Switch_PhaAdv; /* '<S51>/Switch_PhaAdv' */ - 67 int32_T Switch_PhaAdv_a; /* '<S13>/Switch_PhaAdv' */ - 68 int16_T Merge; /* '<S14>/Merge' */ - 69 int16_T Merge1; /* '<S14>/Merge1' */ - 70 int16_T Merge2; /* '<S14>/Merge2' */ - 71 int16_T Merge_j; /* '<S52>/Merge' */ - 72 int16_T Merge1_m; /* '<S52>/Merge1' */ - 73 int16_T Merge2_d; /* '<S52>/Merge2' */ - 74 int16_T z_counterRawPrev_DSTATE; /* '<S23>/z_counterRawPrev' */ - 75 int16_T z_counter2_DSTATE; /* '<S23>/z_counter2' */ - 76 int16_T UnitDelay1_DSTATE; /* '<S32>/UnitDelay1' */ - 77 int16_T z_counterRawPrev_DSTATE_p; /* '<S61>/z_counterRawPrev' */ - 78 int16_T z_counter2_DSTATE_h; /* '<S61>/z_counter2' */ - 79 int16_T UnitDelay1_DSTATE_k; /* '<S70>/UnitDelay1' */ - 80 int8_T UnitDelay1; /* '<S60>/UnitDelay1' */ - 81 int8_T Switch2; /* '<S60>/Switch2' */ - 82 int8_T UnitDelay1_k; /* '<S22>/UnitDelay1' */ - 83 int8_T Switch2_e; /* '<S22>/Switch2' */ - 84 int8_T If1_ActiveSubsystem; /* '<S2>/If1' */ - 85 int8_T If1_ActiveSubsystem_j; /* '<S3>/If1' */ - 86 uint8_T Sum2_i; /* '<S65>/Sum2' */ - 87 uint8_T Sum2_l; /* '<S27>/Sum2' */ - 88 uint8_T UnitDelay_DSTATE; /* '<S20>/UnitDelay' */ - 89 uint8_T UnitDelay1_DSTATE_p; /* '<S20>/UnitDelay1' */ - 90 uint8_T UnitDelay2_DSTATE; /* '<S20>/UnitDelay2' */ - 91 uint8_T UnitDelay1_DSTATE_g; /* '<S21>/UnitDelay1' */ - 92 uint8_T UnitDelay_DSTATE_j; /* '<S58>/UnitDelay' */ - 93 uint8_T UnitDelay1_DSTATE_f; /* '<S58>/UnitDelay1' */ - 94 uint8_T UnitDelay2_DSTATE_b; /* '<S58>/UnitDelay2' */ - 95 uint8_T UnitDelay1_DSTATE_j; /* '<S59>/UnitDelay1' */ - 96 boolean_T Logic[2]; /* '<S29>/Logic' */ - 97 boolean_T Logic_j[2]; /* '<S67>/Logic' */ - 98 boolean_T LogicalOperator; /* '<S30>/Logical Operator' */ - 99 boolean_T LogicalOperator5; /* '<S61>/Logical Operator5' */ - 100 boolean_T LogicalOperator_h; /* '<S68>/Logical Operator' */ - 101 boolean_T UnitDelay8_DSTATE; /* '<S23>/UnitDelay8' */ - 102 boolean_T UnitDelay8_DSTATE_p; /* '<S61>/UnitDelay8' */ - 103 boolean_T UnitDelay_DSTATE_k; /* '<S69>/UnitDelay' */ - 104 boolean_T UnitDelay_DSTATE_i; /* '<S68>/UnitDelay' */ - 105 boolean_T UnitDelay_DSTATE_l; /* '<S31>/UnitDelay' */ - 106 boolean_T UnitDelay_DSTATE_b; /* '<S30>/UnitDelay' */ - 107 boolean_T Memory_PreviousInput; /* '<S29>/Memory' */ - 108 boolean_T Relay_Mode; /* '<S15>/Relay' */ - 109 boolean_T Memory_PreviousInput_i; /* '<S67>/Memory' */ - 110 boolean_T Relay_Mode_m; /* '<S53>/Relay' */ - 111 } DW; - 112 - 113 /* Zero-crossing (trigger) state */ - 114 typedef struct { - 115 ZCE_Motor_Speed_Calculation Motor_Speed_Calculation_k;/* '<S61>/Motor_Speed_Calculation' */ - 116 ZCE_Motor_Speed_Calculation Motor_Speed_Calculation_m;/* '<S23>/Motor_Speed_Calculation' */ - 117 } PrevZCX; - 118 - 119 /* Constant parameters (auto storage) */ - 120 typedef struct { - 121 /* Pooled Parameter (Expression: r_trapPhaA_M1) - 122 * Referenced by: - 123 * '<S41>/r_trapPhaA_M1' - 124 * '<S79>/r_trapPhaA_M1' - 125 */ - 126 int16_T pooled9[7]; - 127 - 128 /* Pooled Parameter (Expression: r_trapPhaB_M1) - 129 * Referenced by: - 130 * '<S41>/r_trapPhaB_M1' - 131 * '<S79>/r_trapPhaB_M1' - 132 */ - 133 int16_T pooled10[7]; + 34 /* Forward declaration for rtModel */ + 35 typedef struct tag_RTM RT_MODEL; + 36 + 37 /* Block signals and states (auto storage) for system '<Root>' */ + 38 typedef struct { + 39 int32_T Switch_PhaAdv; /* '<S8>/Switch_PhaAdv' */ + 40 int32_T UnitDelay2_DSTATE; /* '<S16>/UnitDelay2' */ + 41 int16_T Merge; /* '<S9>/Merge' */ + 42 int16_T Merge1; /* '<S9>/Merge1' */ + 43 int16_T Merge2; /* '<S9>/Merge2' */ + 44 int16_T z_counterRawPrev; /* '<S15>/z_counterRawPrev' */ + 45 int16_T Sum4; /* '<S15>/Sum4' */ + 46 int16_T UnitDelay1_DSTATE; /* '<S17>/UnitDelay1' */ + 47 int16_T UnitDelay1_DSTATE_c; /* '<S14>/UnitDelay1' */ + 48 int16_T z_counter2_DSTATE; /* '<S15>/z_counter2' */ + 49 int8_T UnitDelay1; /* '<S13>/UnitDelay1' */ + 50 int8_T Switch2; /* '<S13>/Switch2' */ + 51 int8_T UnitDelay2_DSTATE_i; /* '<S13>/UnitDelay2' */ + 52 int8_T If1_ActiveSubsystem; /* '<S2>/If1' */ + 53 uint8_T UnitDelay_DSTATE; /* '<S11>/UnitDelay' */ + 54 uint8_T UnitDelay1_DSTATE_i; /* '<S11>/UnitDelay1' */ + 55 uint8_T UnitDelay2_DSTATE_h; /* '<S11>/UnitDelay2' */ + 56 boolean_T n_commDeacv_Mode; /* '<S14>/n_commDeacv' */ + 57 boolean_T dz_counter_Mode; /* '<S14>/dz_counter' */ + 58 } DW; + 59 + 60 /* Constant parameters (auto storage) */ + 61 typedef struct { + 62 /* Computed Parameter: r_trapPhaA_M1_Table + 63 * Referenced by: '<S18>/r_trapPhaA_M1' + 64 */ + 65 int16_T r_trapPhaA_M1_Table[7]; + 66 + 67 /* Computed Parameter: r_trapPhaB_M1_Table + 68 * Referenced by: '<S18>/r_trapPhaB_M1' + 69 */ + 70 int16_T r_trapPhaB_M1_Table[7]; + 71 + 72 /* Computed Parameter: r_trapPhaC_M1_Table + 73 * Referenced by: '<S18>/r_trapPhaC_M1' + 74 */ + 75 int16_T r_trapPhaC_M1_Table[7]; + 76 + 77 /* Computed Parameter: r_sinPhaA_M1_Table + 78 * Referenced by: '<S19>/r_sinPhaA_M1' + 79 */ + 80 int16_T r_sinPhaA_M1_Table[37]; + 81 + 82 /* Computed Parameter: r_sinPhaB_M1_Table + 83 * Referenced by: '<S19>/r_sinPhaB_M1' + 84 */ + 85 int16_T r_sinPhaB_M1_Table[37]; + 86 + 87 /* Computed Parameter: r_sinPhaC_M1_Table + 88 * Referenced by: '<S19>/r_sinPhaC_M1' + 89 */ + 90 int16_T r_sinPhaC_M1_Table[37]; + 91 + 92 /* Computed Parameter: r_sin3PhaA_M1_Table + 93 * Referenced by: '<S20>/r_sin3PhaA_M1' + 94 */ + 95 int16_T r_sin3PhaA_M1_Table[37]; + 96 + 97 /* Computed Parameter: r_sin3PhaB_M1_Table + 98 * Referenced by: '<S20>/r_sin3PhaB_M1' + 99 */ + 100 int16_T r_sin3PhaB_M1_Table[37]; + 101 + 102 /* Computed Parameter: r_sin3PhaC_M1_Table + 103 * Referenced by: '<S20>/r_sin3PhaC_M1' + 104 */ + 105 int16_T r_sin3PhaC_M1_Table[37]; + 106 + 107 /* Computed Parameter: z_commutMap_M1_table + 108 * Referenced by: '<S10>/z_commutMap_M1' + 109 */ + 110 int16_T z_commutMap_M1_table[18]; + 111 + 112 /* Computed Parameter: vec_hallToPos_Value + 113 * Referenced by: '<S12>/vec_hallToPos' + 114 */ + 115 int8_T vec_hallToPos_Value[8]; + 116 } ConstP; + 117 + 118 /* External inputs (root inport signals with auto storage) */ + 119 typedef struct { + 120 uint8_T b_hallA; /* '<Root>/b_hallA ' */ + 121 uint8_T b_hallB; /* '<Root>/b_hallB' */ + 122 uint8_T b_hallC; /* '<Root>/b_hallC' */ + 123 int32_T r_DC; /* '<Root>/r_DC' */ + 124 } ExtU; + 125 + 126 /* External outputs (root outports fed by signals with auto storage) */ + 127 typedef struct { + 128 int32_T DC_phaA; /* '<Root>/DC_phaA' */ + 129 int32_T DC_phaB; /* '<Root>/DC_phaB' */ + 130 int32_T DC_phaC; /* '<Root>/DC_phaC' */ + 131 int32_T n_mot; /* '<Root>/n_mot' */ + 132 int32_T a_elecAngle; /* '<Root>/a_elecAngle' */ + 133 } ExtY; 134 - 135 /* Pooled Parameter (Expression: r_trapPhaC_M1) - 136 * Referenced by: - 137 * '<S41>/r_trapPhaC_M1' - 138 * '<S79>/r_trapPhaC_M1' - 139 */ - 140 int16_T pooled11[7]; - 141 - 142 /* Pooled Parameter (Expression: r_sinPhaA_M1) - 143 * Referenced by: - 144 * '<S43>/r_sinPhaA_M1' - 145 * '<S81>/r_sinPhaA_M1' - 146 */ - 147 int16_T pooled12[37]; - 148 - 149 /* Pooled Parameter (Expression: r_sinPhaB_M1) - 150 * Referenced by: - 151 * '<S43>/r_sinPhaB_M1' - 152 * '<S81>/r_sinPhaB_M1' - 153 */ - 154 int16_T pooled13[37]; - 155 - 156 /* Pooled Parameter (Expression: r_sinPhaC_M1) - 157 * Referenced by: - 158 * '<S43>/r_sinPhaC_M1' - 159 * '<S81>/r_sinPhaC_M1' - 160 */ - 161 int16_T pooled14[37]; - 162 - 163 /* Pooled Parameter (Expression: r_sin3PhaA_M1) - 164 * Referenced by: - 165 * '<S42>/r_sin3PhaA_M1' - 166 * '<S80>/r_sin3PhaA_M1' - 167 */ - 168 int16_T pooled15[37]; - 169 - 170 /* Pooled Parameter (Expression: r_sin3PhaB_M1) - 171 * Referenced by: - 172 * '<S42>/r_sin3PhaB_M1' - 173 * '<S80>/r_sin3PhaB_M1' - 174 */ - 175 int16_T pooled16[37]; - 176 - 177 /* Pooled Parameter (Expression: r_sin3PhaC_M1) - 178 * Referenced by: - 179 * '<S42>/r_sin3PhaC_M1' - 180 * '<S80>/r_sin3PhaC_M1' - 181 */ - 182 int16_T pooled17[37]; - 183 - 184 /* Pooled Parameter (Expression: z_commutMap_M1) - 185 * Referenced by: - 186 * '<S15>/z_commutMap_M1' - 187 * '<S53>/z_commutMap_M1' - 188 */ - 189 int16_T pooled18[18]; - 190 - 191 /* Pooled Parameter (Expression: vec_hallToPos) - 192 * Referenced by: - 193 * '<S21>/vec_hallToPos' - 194 * '<S59>/vec_hallToPos' - 195 */ - 196 uint8_T pooled26[8]; - 197 - 198 /* Pooled Parameter (Expression: [0 1;1 0;0 1;0 1;1 0;1 0;0 0;0 0]) - 199 * Referenced by: - 200 * '<S29>/Logic' - 201 * '<S67>/Logic' - 202 */ - 203 boolean_T pooled30[16]; - 204 } ConstP; - 205 - 206 /* External inputs (root inport signals with auto storage) */ - 207 typedef struct { - 208 uint8_T b_hallALeft; /* '<Root>/b_hallALeft ' */ - 209 uint8_T b_hallBLeft; /* '<Root>/b_hallBLeft' */ - 210 uint8_T b_hallCLeft; /* '<Root>/b_hallCLeft' */ - 211 int32_T r_DCLeft; /* '<Root>/r_DCLeft' */ - 212 uint8_T b_hallARight; /* '<Root>/b_hallARight' */ - 213 uint8_T b_hallBRight; /* '<Root>/b_hallBRight' */ - 214 uint8_T b_hallCRight; /* '<Root>/b_hallCRight' */ - 215 int32_T r_DCRight; /* '<Root>/r_DCRight' */ - 216 } ExtU; - 217 - 218 /* External outputs (root outports fed by signals with auto storage) */ - 219 typedef struct { - 220 int32_T DC_phaALeft; /* '<Root>/DC_phaALeft' */ - 221 int32_T DC_phaBLeft; /* '<Root>/DC_phaBLeft' */ - 222 int32_T DC_phaCLeft; /* '<Root>/DC_phaCLeft' */ - 223 int32_T n_motLeft; /* '<Root>/n_motLeft' */ - 224 int32_T a_elecAngleLeft; /* '<Root>/a_elecAngleLeft' */ - 225 int32_T DC_phaARight; /* '<Root>/DC_phaARight' */ - 226 int32_T DC_phaBRight; /* '<Root>/DC_phaBRight' */ - 227 int32_T DC_phaCRight; /* '<Root>/DC_phaCRight' */ - 228 int32_T n_motRight; /* '<Root>/n_motRight' */ - 229 int32_T a_elecAngleRight; /* '<Root>/a_elecAngleRight' */ - 230 } ExtY; - 231 - 232 /* Parameters (auto storage) */ - 233 struct P_ { - 234 int32_T cf_speedCoef; /* Variable: cf_speedCoef - 235 * Referenced by: - 236 * '<S28>/cf_spdCoef' - 237 * '<S66>/cf_spdCoef' - 238 */ - 239 int32_T n_commAcvLo; /* Variable: n_commAcvLo - 240 * Referenced by: - 241 * '<S15>/Relay' - 242 * '<S53>/Relay' - 243 */ - 244 int32_T n_commDeacvHi; /* Variable: n_commDeacvHi - 245 * Referenced by: - 246 * '<S15>/Relay' - 247 * '<S53>/Relay' - 248 */ - 249 int32_T r_commDCDeacv; /* Variable: r_commDCDeacv - 250 * Referenced by: - 251 * '<S15>/r_commDCDeacv' - 252 * '<S53>/r_commDCDeacv' - 253 */ - 254 int32_T r_phaAdvDC_XA[11]; /* Variable: r_phaAdvDC_XA - 255 * Referenced by: - 256 * '<S13>/r_phaAdvDC_XA' - 257 * '<S51>/r_phaAdvDC_XA' - 258 */ - 259 int16_T a_phaAdv_M1[11]; /* Variable: a_phaAdv_M1 - 260 * Referenced by: - 261 * '<S13>/a_phaAdv_M2' - 262 * '<S51>/a_phaAdv_M2' - 263 */ - 264 int16_T z_maxCntRst; /* Variable: z_maxCntRst - 265 * Referenced by: - 266 * '<S23>/z_maxCntRst' - 267 * '<S23>/z_maxCntRst1' - 268 * '<S23>/z_maxCntRst2' - 269 * '<S23>/z_counter2' - 270 * '<S61>/z_maxCntRst' - 271 * '<S61>/z_maxCntRst1' - 272 * '<S61>/z_maxCntRst2' - 273 * '<S61>/z_counter2' - 274 * '<S28>/z_maxCntRst' - 275 * '<S66>/z_maxCntRst' - 276 */ - 277 uint8_T z_ctrlTypSel; /* Variable: z_ctrlTypSel - 278 * Referenced by: - 279 * '<S12>/z_ctrlTypSel1' - 280 * '<S50>/z_ctrlTypSel1' - 281 */ - 282 uint8_T z_nrEdgeSpdAcv; /* Variable: z_nrEdgeSpdAcv - 283 * Referenced by: - 284 * '<S23>/z_nrEdgeSpdAcv' - 285 * '<S61>/z_nrEdgeSpdAcv' - 286 */ - 287 boolean_T b_phaAdvEna; /* Variable: b_phaAdvEna - 288 * Referenced by: - 289 * '<S13>/a_elecPeriod1' - 290 * '<S51>/a_elecPeriod1' - 291 */ - 292 }; - 293 - 294 /* Parameters (auto storage) */ - 295 typedef struct P_ P; - 296 - 297 /* Block parameters (auto storage) */ - 298 extern P rtP; - 299 - 300 /* Block signals and states (auto storage) */ - 301 extern DW rtDW; - 302 - 303 /* External inputs (root inport signals with auto storage) */ - 304 extern ExtU rtU; - 305 - 306 /* External outputs (root outports fed by signals with auto storage) */ - 307 extern ExtY rtY; - 308 - 309 /* Constant parameters (auto storage) */ - 310 extern const ConstP rtConstP; - 311 - 312 /* Model entry point functions */ - 313 extern void BLDC_controller_initialize(void); - 314 extern void BLDC_controller_step(void); - 315 - 316 /*- - 317 * These blocks were eliminated from the model due to optimizations: - 318 * - 319 * Block '<S23>/Scope2' : Unused code path elimination - 320 * Block '<S13>/Scope' : Unused code path elimination - 321 * Block '<S61>/Scope2' : Unused code path elimination - 322 * Block '<S51>/Scope' : Unused code path elimination - 323 */ - 324 - 325 /*- - 326 * The generated code includes comments that allow you to trace directly - 327 * back to the appropriate location in the model. The basic format - 328 * is <system>/block_name, where system is the system number (uniquely - 329 * assigned by Simulink) and block_name is the name of the block. - 330 * - 331 * Note that this particular code originates from a subsystem build, - 332 * and has its own system numbers different from the parent model. - 333 * Refer to the system hierarchy for this subsystem below, and use the - 334 * MATLAB hilite_system command to trace the generated code back - 335 * to the parent model. For example, - 336 * - 337 * hilite_system('BLDCmotorControl_R2017b/BLDC_controller') - opens subsystem BLDCmotorControl_R2017b/BLDC_controller - 338 * hilite_system('BLDCmotorControl_R2017b/BLDC_controller/Kp') - opens and selects block Kp - 339 * - 340 * Here is the system hierarchy for this model - 341 * - 342 * '<Root>' : 'BLDCmotorControl_R2017b' - 343 * '<S1>' : 'BLDCmotorControl_R2017b/BLDC_controller' - 344 * '<S2>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left' - 345 * '<S3>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right' - 346 * '<S4>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log1' - 347 * '<S5>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log2' - 348 * '<S6>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log3' - 349 * '<S7>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log4' - 350 * '<S8>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log5' - 351 * '<S9>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log6' - 352 * '<S10>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log7' - 353 * '<S11>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log8' - 354 * '<S12>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations' - 355 * '<S13>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation' - 356 * '<S14>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection' - 357 * '<S15>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management' - 358 * '<S16>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log1' - 359 * '<S17>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log2' - 360 * '<S18>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log3' - 361 * '<S19>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/signal_log6' - 362 * '<S20>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_01_Edge_Detector' - 363 * '<S21>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_02_Position_Calculation' - 364 * '<S22>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_03_Direction_Detection' - 365 * '<S23>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation' - 366 * '<S24>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_01_Edge_Detector/signal_log6' - 367 * '<S25>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_02_Position_Calculation/signal_log6' - 368 * '<S26>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_03_Direction_Detection/signal_log6' - 369 * '<S27>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter' - 370 * '<S28>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' - 371 * '<S29>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/S-R Flip-Flop' - 372 * '<S30>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/falling_edge2' - 373 * '<S31>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rising_edge' - 374 * '<S32>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_Delay' - 375 * '<S33>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log1' - 376 * '<S34>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log3' - 377 * '<S35>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log4' - 378 * '<S36>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log5' - 379 * '<S37>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter/rst_Delay' - 380 * '<S38>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log1' - 381 * '<S39>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log2' - 382 * '<S40>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F02_Electrical_Angle_Calculation/signal_log6' - 383 * '<S41>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' - 384 * '<S42>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_02_Sinusoidal3rd_Method' - 385 * '<S43>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' - 386 * '<S44>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log1' - 387 * '<S45>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log2' - 388 * '<S46>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F03_Control_Method_Selection/signal_log6' - 389 * '<S47>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log1' - 390 * '<S48>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log2' - 391 * '<S49>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Left/F04_Control_Type_Management/signal_log6' - 392 * '<S50>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations' - 393 * '<S51>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation' - 394 * '<S52>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection' - 395 * '<S53>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management' - 396 * '<S54>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log1' - 397 * '<S55>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log2' - 398 * '<S56>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log3' - 399 * '<S57>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/signal_log6' - 400 * '<S58>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_01_Edge_Detector' - 401 * '<S59>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_02_Position_Calculation' - 402 * '<S60>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_03_Direction_Detection' - 403 * '<S61>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation' - 404 * '<S62>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_01_Edge_Detector/signal_log6' - 405 * '<S63>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_02_Position_Calculation/signal_log6' - 406 * '<S64>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_03_Direction_Detection/signal_log6' - 407 * '<S65>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter' - 408 * '<S66>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' - 409 * '<S67>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/S-R Flip-Flop' - 410 * '<S68>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/falling_edge2' - 411 * '<S69>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rising_edge' - 412 * '<S70>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_Delay' - 413 * '<S71>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log1' - 414 * '<S72>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log3' - 415 * '<S73>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log4' - 416 * '<S74>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/signal_log5' - 417 * '<S75>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Edge_counter/rst_Delay' - 418 * '<S76>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log1' - 419 * '<S77>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log2' - 420 * '<S78>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F02_Electrical_Angle_Calculation/signal_log6' - 421 * '<S79>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' - 422 * '<S80>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_02_Sinusoidal3rd_Method' - 423 * '<S81>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' - 424 * '<S82>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log1' - 425 * '<S83>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log2' - 426 * '<S84>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F03_Control_Method_Selection/signal_log6' - 427 * '<S85>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log1' - 428 * '<S86>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log2' - 429 * '<S87>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller_Right/F04_Control_Type_Management/signal_log6' - 430 */ - 431 #endif /* RTW_HEADER_BLDC_controller_h_ */ - 432 - 433 /* - 434 * File trailer for generated code. - 435 * - 436 * [EOF] - 437 */ - 438 + 135 /* Parameters (auto storage) */ + 136 struct P_ { + 137 int32_T cf_speedCoef; /* Variable: cf_speedCoef + 138 * Referenced by: '<S16>/cf_spdCoef' + 139 */ + 140 int32_T cf_speedFilt; /* Variable: cf_speedFilt + 141 * Referenced by: '<S16>/cf_speedFilt' + 142 */ + 143 int32_T n_commAcvLo; /* Variable: n_commAcvLo + 144 * Referenced by: '<S14>/n_commDeacv' + 145 */ + 146 int32_T n_commDeacvHi; /* Variable: n_commDeacvHi + 147 * Referenced by: '<S14>/n_commDeacv' + 148 */ + 149 int32_T r_commDCDeacv; /* Variable: r_commDCDeacv + 150 * Referenced by: '<S14>/r_commDCDeacv' + 151 */ + 152 int32_T r_phaAdvDC_XA[11]; /* Variable: r_phaAdvDC_XA + 153 * Referenced by: '<S8>/r_phaAdvDC_XA' + 154 */ + 155 int16_T a_phaAdv_M1[11]; /* Variable: a_phaAdv_M1 + 156 * Referenced by: '<S8>/a_phaAdv_M2' + 157 */ + 158 int16_T dz_counterHi; /* Variable: dz_counterHi + 159 * Referenced by: '<S14>/dz_counter' + 160 */ + 161 int16_T dz_counterLo; /* Variable: dz_counterLo + 162 * Referenced by: '<S14>/dz_counter' + 163 */ + 164 uint8_T z_ctrlTypSel; /* Variable: z_ctrlTypSel + 165 * Referenced by: '<S7>/z_ctrlTypSel1' + 166 */ + 167 boolean_T b_phaAdvEna; /* Variable: b_phaAdvEna + 168 * Referenced by: '<S8>/a_elecPeriod1' + 169 */ + 170 }; + 171 + 172 /* Parameters (auto storage) */ + 173 typedef struct P_ P; + 174 + 175 /* Real-time Model Data Structure */ + 176 struct tag_RTM { + 177 P *defaultParam; + 178 ExtU *inputs; + 179 ExtY *outputs; + 180 DW *dwork; + 181 }; + 182 + 183 /* Constant parameters (auto storage) */ + 184 extern const ConstP rtConstP; + 185 + 186 /* Model entry point functions */ + 187 extern void BLDC_controller_initialize(RT_MODEL *const rtM); + 188 extern void BLDC_controller_step(RT_MODEL *const rtM); + 189 + 190 /*- + 191 * These blocks were eliminated from the model due to optimizations: + 192 * + 193 * Block '<S14>/Scope2' : Unused code path elimination + 194 * Block '<S8>/Scope' : Unused code path elimination + 195 */ + 196 + 197 /*- + 198 * The generated code includes comments that allow you to trace directly + 199 * back to the appropriate location in the model. The basic format + 200 * is <system>/block_name, where system is the system number (uniquely + 201 * assigned by Simulink) and block_name is the name of the block. + 202 * + 203 * Note that this particular code originates from a subsystem build, + 204 * and has its own system numbers different from the parent model. + 205 * Refer to the system hierarchy for this subsystem below, and use the + 206 * MATLAB hilite_system command to trace the generated code back + 207 * to the parent model. For example, + 208 * + 209 * hilite_system('BLDCmotorControl_R2017b/BLDC_controller') - opens subsystem BLDCmotorControl_R2017b/BLDC_controller + 210 * hilite_system('BLDCmotorControl_R2017b/BLDC_controller/Kp') - opens and selects block Kp + 211 * + 212 * Here is the system hierarchy for this model + 213 * + 214 * '<Root>' : 'BLDCmotorControl_R2017b' + 215 * '<S1>' : 'BLDCmotorControl_R2017b/BLDC_controller' + 216 * '<S2>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller' + 217 * '<S3>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log1' + 218 * '<S4>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log2' + 219 * '<S5>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log3' + 220 * '<S6>' : 'BLDCmotorControl_R2017b/BLDC_controller/signal_log6' + 221 * '<S7>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations' + 222 * '<S8>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F02_Electrical_Angle_Calculation' + 223 * '<S9>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection' + 224 * '<S10>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F04_Control_Type_Management' + 225 * '<S11>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_01_Edge_Detector' + 226 * '<S12>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_02_Position_Calculation' + 227 * '<S13>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_03_Direction_Detection' + 228 * '<S14>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation' + 229 * '<S15>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Counter_Hold_and_Error_Calculation' + 230 * '<S16>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/Motor_Speed_Calculation' + 231 * '<S17>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F01_Preliminary_Calculations/F01_04_Speed_Calculation/rst_DelayLim' + 232 * '<S18>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_01_Pure_Trapezoidal_Method' + 233 * '<S19>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_02_Sinusoidal_Method' + 234 * '<S20>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/F03_03_Sinusoidal3rd_Method' + 235 * '<S21>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log1' + 236 * '<S22>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log2' + 237 * '<S23>' : 'BLDCmotorControl_R2017b/BLDC_controller/BLDC_controller/F03_Control_Method_Selection/signal_log6' + 238 */ + 239 #endif /* RTW_HEADER_BLDC_controller_h_ */ + 240 + 241 /* + 242 * File trailer for generated code. + 243 * + 244 * [EOF] + 245 */ + 246

diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_interface.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_interface.html index 331ce17..6360cbe 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_interface.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_interface.html @@ -63,7 +63,7 @@ Prototype -void BLDC_controller_initialize(void) +void BLDC_controller_initialize(RT_MODEL *const rtM) @@ -92,7 +92,52 @@ Must be called exactly once Arguments -None + + + + + + + + + + + + + + + + +
+ +# + + + + +Name + + + + +Data Type + + + + +Description + + +
+1 + +rtM + +RT_MODEL *const + +RTModel +
+ @@ -126,7 +171,7 @@ Prototype -void BLDC_controller_step(void) +void BLDC_controller_step(RT_MODEL *const rtM) @@ -146,7 +191,7 @@ Output entry point of generated code Timing -Must be called periodically, every 1e-05 seconds +Must be called periodically, every 6e-05 seconds @@ -155,7 +200,52 @@ Must be called periodically, every 1e-05 seconds Arguments -None + + + + + + + + + + + + + + + + +
+ +# + + + + +Name + + + + +Data Type + + + + +Description + + +
+1 + +rtM + +RT_MODEL *const + +RTModel +
+ @@ -215,10 +305,13 @@ Dimension -<S1>/b_hallALeft +<S1>/b_hallA -rtU.b_hallALeft + +Defined externally + + uint8_T @@ -230,10 +323,13 @@ uint8_T -<S1>/b_hallBLeft +<S1>/b_hallB -rtU.b_hallBLeft + +Defined externally + + uint8_T @@ -245,10 +341,13 @@ uint8_T -<S1>/b_hallCLeft +<S1>/b_hallC -rtU.b_hallCLeft + +Defined externally + + uint8_T @@ -260,70 +359,13 @@ uint8_T -<S1>/r_DCLeft +<S1>/r_DC -rtU.r_DCLeft - - -int32_T - - -1 - + +Defined externally + - - - -<S1>/b_hallARight - - -rtU.b_hallARight - - -uint8_T - - -1 - - - - - -<S1>/b_hallBRight - - -rtU.b_hallBRight - - -uint8_T - - -1 - - - - - -<S1>/b_hallCRight - - -rtU.b_hallCRight - - -uint8_T - - -1 - - - - - -<S1>/r_DCRight - - -rtU.r_DCRight int32_T @@ -371,10 +413,13 @@ Dimension -<S1>/DC_phaALeft +<S1>/DC_phaA -rtY.DC_phaALeft + +Defined externally + + int32_T @@ -386,10 +431,13 @@ int32_T -<S1>/DC_phaBLeft +<S1>/DC_phaB -rtY.DC_phaBLeft + +Defined externally + + int32_T @@ -401,10 +449,13 @@ int32_T -<S1>/DC_phaCLeft +<S1>/DC_phaC -rtY.DC_phaCLeft + +Defined externally + + int32_T @@ -416,10 +467,13 @@ int32_T -<S1>/n_motLeft +<S1>/n_mot -rtY.n_motLeft + +Defined externally + + int32_T @@ -431,85 +485,13 @@ int32_T -<S1>/a_elecAngleLeft +<S1>/a_elecAngle -rtY.a_elecAngleLeft - - -int32_T - - -1 - + +Defined externally + - - - -<S1>/DC_phaARight - - -rtY.DC_phaARight - - -int32_T - - -1 - - - - - -<S1>/DC_phaBRight - - -rtY.DC_phaBRight - - -int32_T - - -1 - - - - - -<S1>/DC_phaCRight - - -rtY.DC_phaCRight - - -int32_T - - -1 - - - - - -<S1>/n_motRight - - -rtY.n_motRight - - -int32_T - - -1 - - - - - -<S1>/a_elecAngleRight - - -rtY.a_elecAngleRight int32_T @@ -560,7 +542,10 @@ Dimension cf_speedCoef -rtP.cf_speedCoef + +Defined externally + + int32_T @@ -572,25 +557,31 @@ int32_T +cf_speedFilt + + + +Defined externally + + + + +int32_T + + +1 + + + + + n_commAcvLo -rtP.n_commAcvLo - - -int32_T - - -1 - + +Defined externally + - - - -n_commDeacvHi - - -rtP.n_commDeacvHi int32_T @@ -602,10 +593,13 @@ int32_T -r_commDCDeacv +n_commDeacvHi -rtP.r_commDCDeacv + +Defined externally + + int32_T @@ -617,10 +611,31 @@ int32_T +r_commDCDeacv + + + +Defined externally + + + + +int32_T + + +1 + + + + + r_phaAdvDC_XA -rtP.r_phaAdvDC_XA + +Defined externally + + int32_T @@ -630,12 +645,15 @@ int32_T - + a_phaAdv_M1 -rtP.a_phaAdv_M1 + +Defined externally + + int16_T @@ -645,12 +663,33 @@ int16_T - + -z_maxCntRst +dz_counterHi -rtP.z_maxCntRst + +Defined externally + + + + +int16_T + + +1 + + + + + +dz_counterLo + + + +Defined externally + + int16_T @@ -665,7 +704,10 @@ int16_T z_ctrlTypSel -rtP.z_ctrlTypSel + +Defined externally + + uint8_T @@ -677,25 +719,13 @@ uint8_T -z_nrEdgeSpdAcv - - -rtP.z_nrEdgeSpdAcv - - -uint8_T - - -1 - - - - - b_phaAdvEna -rtP.b_phaAdvEna + +Defined externally + + boolean_T diff --git a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_metrics.html b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_metrics.html index 71c6cbc..4860635 100644 --- a/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_metrics.html +++ b/01_Matlab/BLDC_controller_ert_rtw/html/BLDC_controller_metrics.html @@ -40,7 +40,7 @@ Global Variables
  • - + Function Information @@ -85,7 +85,7 @@ Function Information : -3 +2   @@ -100,7 +100,7 @@ Function Information : -746 +408   @@ -115,7 +115,7 @@ Function Information : -2,126 +1,155   @@ -169,13 +169,13 @@ BLDC_controller.c -506 +258 -1,309 +698 -05/28/2019 7:55 PM +06/05/2019 10:29 PM @@ -187,13 +187,13 @@ BLDC_controller.h -137 +79 -438 +246 -05/28/2019 7:55 PM +06/05/2019 10:29 PM @@ -211,7 +211,7 @@ rtwtypes.h 109 -05/28/2019 7:55 PM +06/05/2019 10:29 PM @@ -223,31 +223,13 @@ BLDC_controller_data.c -40 +27 -212 +102 -05/28/2019 7:55 PM - - - - - - -zero_crossing_types.h - - - - -19 - - -58 - - -05/28/2019 7:55 PM +06/05/2019 10:29 PM @@ -316,1414 +298,34 @@ Global variables defined in the generated code. - - - - - - - - - - - - - -
    - - - - - - - - - -
    -[+] -rtDW - - - -87 - -150  - -126  -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - -
    - - - - - - - - - -
    -[+] -rtP - - - -87 - -29  - -20  -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - -
    - - - - - - - - - -
    -[+] -rtY - - - -40 - -18  - -18  -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - -
    - - - - - - - - - -
    -[+] -rtU - - - -14 - -38  - -38  -
    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - - - - - -
    - - - - - - - - - -
    -[+] -rtPrevZCX - - - -2 - -4  - -2  -
    - -
    - - - - - - - - - - - - -
    - - - @@ -1748,9 +350,9 @@ rtPrevZCX
    + Total + + -230 + +0 + + -239  + +0  + + + + +

    -3. Function Information [hide] +3. Function Information [hide]

    - +
    @@ -1870,43 +472,7 @@ BLDC_controller_step
    View function metrics in a call tree format or table format. Accumulated stack numbers include the estimated stack size of the function plus the maximum of the accumulated stack size of the subroutines that the function calls. @@ -1840,19 +442,19 @@ BLDC_controller_step -47 +69 -27 +60 -232 +185 -684 +516 -29 +24
    - - - - - - - - -
    -      [+]  -F02_Electrical_Angle_Calculatio - - - -20 - -11 - -27 - -65 - -4 -
    - - - - - - - - -