Major improvements

- reduced FOC computational complexity by up to 20%, from 85% (old) to 65% (new)
- updated Field Weakening by allowing more freedom set-up: field weakening blended in the input fully, partially blended, or fully outside the input range
- major improvemets on current and speed limitations. It allows seemless limitation protection -> very happy with the result
This commit is contained in:
EmanuelFeru 2019-12-12 23:44:33 +01:00
parent 8ae3770708
commit 31d42b4a17
18 changed files with 1884 additions and 1987 deletions

View File

@ -56,7 +56,7 @@ r_cos_M1 = cos((a_elecAngle_XA + 30)*(pi/180));
% stairs(a_elecAngle_XA, r_cos_M1);
% legend('sin','cos');
%% Control Manager
%% Control selection
% Control type selection
CTRL_COM = 0; % [-] Commutation Control
CTRL_SIN = 1; % [-] Sinusoidal Control
@ -70,6 +70,7 @@ SPD_MODE = 2; % [-] Speed mode
TRQ_MODE = 3; % [-] Torque mode
z_ctrlModReq = VLT_MODE; % [-] Control Mode Request (default)
%% F01_Estimations
% Position Estimation Parameters
% Hall = 4*hA + 2*hB + hC
@ -87,41 +88,36 @@ n_stdStillDet = 3; % [rpm] Speed threshold for Stand still detectio
cf_currFilt = 0.12; % [%] Current filter coefficient [0, 1]. Lower values mean softer filter
%% F02_Diagnostics
b_diagEna = 1; % [-] Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default)
t_errQual = 0.6 * f_ctrl; % [s] Error qualification time
t_errDequal = 2.0 * f_ctrl; % [s] Error dequalification time
r_errInpTgtThres = 400; % [-] Error input target threshold (for "Blocked motor" detection)
b_diagEna = 1; % [-] Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default)
t_errQual = 0.6 * f_ctrl/3; % [s] Error qualification time
t_errDequal = 2.0 * f_ctrl/3; % [s] Error dequalification time
r_errInpTgtThres = 400; % [-] Error input target threshold (for "Blocked motor" detection)
%% F04_Field_Oriented_Control
%% F03_Control_Mode_Manager
dV_openRate = 1000 / (f_ctrl/3);% [V/s] Rate for voltage cut-off in Open Mode (Sample Time included in the rate)
% Current measurement
b_selPhaABCurrMeas = 1; % [-] Measured phase currents selection: {iA,iB} = 1 (default); {iB,iC} = 0
dV_openRate = 1000 / f_ctrl; % [V/s] Rate for voltage cut-off in Open Mode (Sample Time included in the rate)
% Field Weakening
%% F04_Field_Weakening
b_fieldWeakEna = 0; % [-] Field weakening enable flag: 0 = disable (default), 1 = enable
n_fieldWeakAuthHi = 200; % [rpm] Motor speed High for field weakening authorization
n_fieldWeakAuthLo = 140; % [rpm] Motor speed Low for field weakening authorization
id_fieldWeak_M1 = [0 0.1 0.3 0.7 1.3 2.1 3 3.8 4.4 4.8 5 5] * i_sca; % [-] Field weakening current map
r_fieldWeak_XA = [570 600 630 660 690 720 750 780 810 840 870 900]; % [-] Scaled input target grid
% figure
% plot(r_fieldWeak_XA, id_fieldWeak_M1, '.-'); hold on
% grid
r_fieldWeakHi = 1500; % [-] Input target High threshold for reaching maximum Field Weakening / Phase Advance
r_fieldWeakLo = 1000; % [-] Input target Low threshold for starting Field Weakening / Phase Advance
n_fieldWeakAuthHi = 400; % [rpm] Motor speed High for field weakening authorization
n_fieldWeakAuthLo = 300; % [rpm] Motor speed Low for field weakening authorization
% Q axis control gains
cf_iqKp = 0.5; % [-] P gain
cf_iqKi = 100 / f_ctrl; % [-] I gain
% FOC method
id_fieldWeakMax = 5 * i_sca; % [A] Field weakening maximum current
% D axis control gains
cf_idKp = 0.2; % [-] P gain
cf_idKi = 60 / f_ctrl; % [-] I gain
% SIN method
a_phaAdvMax = 25; % [deg] Maximum phase advance angle
% Speed control gains
cf_nKp = 1.18; % [-] P gain
cf_nKi = 20.4 / f_ctrl; % [-] I gain
% Limitations
%-------------------------------
%% F05_Field_Oriented_Control
b_selPhaABCurrMeas = 1; % [-] Select measured current phases: {iA,iB} = 1 (default); {iB,iC} = 0
% Motor Limitations Calibratables
cf_iqKiLimProt = 60 / (f_ctrl/3); % [-] Current limit protection integral gain (only used in VLT_MODE and SPD_MODE)
cf_nKiLimProt = 20 / (f_ctrl/3); % [-] Speed limit protection integral gain (only used in VLT_MODE and TRQ_MODE)
cf_KbLimProt = 1000 / (f_ctrl/3);% [-] Back calculation gain for integral anti-windup
% Voltage Limitations
V_margin = 100; % [-] Voltage margin to make sure that there is a sufficiently wide pulse for a good phase current measurement
Vd_max = 1000 - V_margin;
@ -131,12 +127,9 @@ Vq_max_M1 = sqrt(Vd_max^2 - Vq_max_XA.^2); % Circle limitations look-
% stairs(Vq_max_XA, Vq_max_M1); legend('V_{max}');
% Speed limitations
cf_nKpLimProt = 5; % [-] Speed limit protection gain (only used in VLT_MODE and TRQ_MODE)
n_max = 800; % [rpm] Maximum motor speed
n_max = 1000; % [rpm] Maximum motor speed
% Current Limitations
cf_iqKpLimProt = 7.2; % [-] Current limit protection gain (only used in VLT_MODE and SPD_MODE)
cf_iqKiLimProt = 40.7 / f_ctrl; % [-] Current limit protection integral gain (only used in SPD_MODE)
i_max = 15; % [A] Maximum allowed motor current (continuous)
i_max = i_max * i_sca;
iq_maxSca_XA = 0:0.02:0.99;
@ -146,18 +139,25 @@ iq_maxSca_M1 = sqrt(1 - iq_maxSca_XA.^2);
% stairs(iq_maxSca_XA, iq_maxSca_M1); legend('i_{maxSca}');
%-------------------------------
%% F05_Control_Type_Management
% Q axis control gains
cf_iqKp = 0.3; % [-] P gain
cf_iqKi = 100 / (f_ctrl/3); % [-] I gain
% D axis control gains
cf_idKp = 0.2; % [-] P gain
cf_idKi = 60 / (f_ctrl/3); % [-] I gain
% Speed control gains
cf_nKp = 1.18; % [-] P gain
cf_nKi = 20.4 / (f_ctrl/3);% [-] I gain
%-------------------------------
%% F06_Control_Type_Management
% Commutation method
z_commutMap_M1 = [-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
% Sinusoidal method
% The map below was experimentaly calibrated on the real motor. Objectives: minimum noise and minimum torque ripple
a_phaAdv_M1 = [0 0 0 0 0 2 3 5 9 16 25]; % [deg] Phase advance angle
r_phaAdv_XA = [0 100 200 300 400 500 600 700 800 900 1000]; % [-] Scaled input target grid
% plot(r_phaAdv_XA, a_phaAdv_M1);
0 1 1 0 -1 -1]; % Phase C [-] Commutation method map
omega = a_elecAngle_XA*(pi/180);
pha_adv = 30; % [deg] Phase advance to mach commands with the Hall position
@ -165,7 +165,7 @@ 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
% Sinusoidal 3rd harmonic method
A = 1.15; % Sine amplitude (tunable to get the Saddle sin maximum to value 1000)
sin3Arm = -0.224*sin(3*(omega + pha_adv*(pi/180))); % 3rd armonic
r_sin3PhaA_M1 = sin3Arm + A*r_sinPhaA_M1;

View File

@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'BLDC_controller'.
*
* Model version : 1.1212
* Model version : 1.1249
* Simulink Coder version : 8.13 (R2017b) 24-Jul-2017
* C/C++ source code generated on : Sat Nov 30 08:54:28 2019
* C/C++ source code generated on : Thu Dec 12 20:22:31 2019
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
@ -30,138 +30,150 @@
/* Forward declaration for rtModel */
typedef struct tag_RTM RT_MODEL;
/* Block signals and states (auto storage) for system '<S10>/Counter' */
/* Block signals and states (auto storage) for system '<S12>/Counter' */
typedef struct {
int16_T UnitDelay_DSTATE; /* '<S14>/UnitDelay' */
int16_T UnitDelay_DSTATE; /* '<S16>/UnitDelay' */
} DW_Counter;
/* Block signals and states (auto storage) for system '<S46>/PI_clamp_fixdt_id' */
/* Block signals and states (auto storage) for system '<S54>/PI_clamp_fixdt' */
typedef struct {
int32_T UnitDelay_DSTATE; /* '<S67>/UnitDelay' */
boolean_T UnitDelay1_DSTATE; /* '<S64>/UnitDelay1' */
int32_T UnitDelay_DSTATE; /* '<S68>/UnitDelay' */
boolean_T UnitDelay1_DSTATE; /* '<S65>/UnitDelay1' */
} DW_PI_clamp_fixdt;
/* Block signals and states (auto storage) for system '<S37>/Low_Pass_Filter' */
/* Block signals and states (auto storage) for system '<S41>/Low_Pass_Filter' */
typedef struct {
int16_T UnitDelay3_DSTATE[2]; /* '<S50>/UnitDelay3' */
} DW_Low_Pass_Filter;
/* Block signals and states (auto storage) for system '<S44>/PI_clamp_fixdt_n' */
/* Block signals and states (auto storage) for system '<S73>/I_backCalc_fixdt' */
typedef struct {
int32_T UnitDelay_DSTATE; /* '<S57>/UnitDelay' */
boolean_T UnitDelay1_DSTATE; /* '<S55>/UnitDelay1' */
} DW_PI_clamp_fixdt_c;
int32_T UnitDelay_DSTATE; /* '<S78>/UnitDelay' */
int32_T UnitDelay_DSTATE_h; /* '<S80>/UnitDelay' */
} DW_I_backCalc_fixdt;
/* Block signals and states (auto storage) for system '<S19>/Counter' */
/* Block signals and states (auto storage) for system '<S21>/Counter' */
typedef struct {
uint16_T UnitDelay_DSTATE; /* '<S24>/UnitDelay' */
uint16_T UnitDelay_DSTATE; /* '<S26>/UnitDelay' */
} DW_Counter_l;
/* Block signals and states (auto storage) for system '<S15>/either_edge' */
/* Block signals and states (auto storage) for system '<S17>/either_edge' */
typedef struct {
boolean_T UnitDelay_DSTATE; /* '<S20>/UnitDelay' */
boolean_T UnitDelay_DSTATE; /* '<S22>/UnitDelay' */
} DW_either_edge;
/* Block signals and states (auto storage) for system '<S3>/Debounce_Filter' */
typedef struct {
DW_either_edge either_edge_k; /* '<S15>/either_edge' */
DW_Counter_l Counter_h; /* '<S18>/Counter' */
DW_Counter_l Counter_i0; /* '<S19>/Counter' */
boolean_T UnitDelay_DSTATE; /* '<S15>/UnitDelay' */
DW_either_edge either_edge_k; /* '<S17>/either_edge' */
DW_Counter_l Counter_h; /* '<S20>/Counter' */
DW_Counter_l Counter_i0; /* '<S21>/Counter' */
boolean_T UnitDelay_DSTATE; /* '<S17>/UnitDelay' */
} DW_Debounce_Filter;
/* Block signals and states (auto storage) for system '<Root>' */
typedef struct {
DW_either_edge either_edge_a; /* '<S3>/either_edge' */
DW_Debounce_Filter Debounce_Filter_f;/* '<S3>/Debounce_Filter' */
DW_PI_clamp_fixdt PI_clamp_fixdt_iq; /* '<S45>/PI_clamp_fixdt_iq' */
DW_PI_clamp_fixdt_c PI_clamp_fixdt_n_o;/* '<S44>/PI_clamp_fixdt_n' */
DW_Low_Pass_Filter Low_Pass_Filter_m;/* '<S37>/Low_Pass_Filter' */
DW_PI_clamp_fixdt PI_clamp_fixdt_id; /* '<S46>/PI_clamp_fixdt_id' */
DW_Counter Counter_e; /* '<S10>/Counter' */
int32_T UnitDelay_DSTATE; /* '<S34>/UnitDelay' */
int16_T Gain4[3]; /* '<S39>/Gain4' */
DW_I_backCalc_fixdt I_backCalc_fixdt_g;/* '<S72>/I_backCalc_fixdt' */
DW_I_backCalc_fixdt I_backCalc_fixdt1;/* '<S73>/I_backCalc_fixdt1' */
DW_I_backCalc_fixdt I_backCalc_fixdt_i;/* '<S73>/I_backCalc_fixdt' */
DW_Low_Pass_Filter Low_Pass_Filter_m;/* '<S41>/Low_Pass_Filter' */
DW_PI_clamp_fixdt PI_clamp_fixdt_a; /* '<S53>/PI_clamp_fixdt' */
DW_PI_clamp_fixdt PI_clamp_fixdt_o; /* '<S52>/PI_clamp_fixdt' */
DW_PI_clamp_fixdt PI_clamp_fixdt_k; /* '<S54>/PI_clamp_fixdt' */
DW_Counter Counter_e; /* '<S12>/Counter' */
int32_T Divide1; /* '<S71>/Divide1' */
int32_T UnitDelay_DSTATE; /* '<S36>/UnitDelay' */
int16_T Gain4[3]; /* '<S43>/Gain4' */
int16_T Sum1[2]; /* '<S50>/Sum1' */
int16_T z_counterRawPrev; /* '<S13>/z_counterRawPrev' */
int16_T Merge; /* '<S5>/Merge' */
int16_T Divide1; /* '<S52>/Divide1' */
int16_T Divide4; /* '<S51>/Divide4' */
int16_T Switch1; /* '<S68>/Switch1' */
int16_T Divide11; /* '<S13>/Divide11' */
int16_T UnitDelay3_DSTATE; /* '<S10>/UnitDelay3' */
int16_T UnitDelay4_DSTATE; /* '<S13>/UnitDelay4' */
int16_T UnitDelay2_DSTATE; /* '<S13>/UnitDelay2' */
int16_T UnitDelay3_DSTATE_o; /* '<S13>/UnitDelay3' */
int16_T UnitDelay5_DSTATE; /* '<S13>/UnitDelay5' */
int16_T UnitDelay4_DSTATE_e; /* '<S10>/UnitDelay4' */
int16_T UnitDelay4_DSTATE_eu; /* '<S6>/UnitDelay4' */
int8_T Switch2; /* '<S9>/Switch2' */
int8_T UnitDelay2_DSTATE_b; /* '<S9>/UnitDelay2' */
int8_T If2_ActiveSubsystem; /* '<S1>/If2' */
int8_T If2_ActiveSubsystem_j; /* '<S27>/If2' */
int16_T z_counterRawPrev; /* '<S15>/z_counterRawPrev' */
int16_T Merge1; /* '<S29>/Merge1' */
int16_T Divide3; /* '<S5>/Divide3' */
int16_T Vd_max1; /* '<S45>/Vd_max1' */
int16_T Gain3; /* '<S45>/Gain3' */
int16_T Vq_max_M1; /* '<S45>/Vq_max_M1' */
int16_T Gain5; /* '<S45>/Gain5' */
int16_T i_max; /* '<S45>/i_max' */
int16_T Divide1_a; /* '<S45>/Divide1' */
int16_T Gain1; /* '<S45>/Gain1' */
int16_T Gain4_c; /* '<S45>/Gain4' */
int16_T Switch2; /* '<S77>/Switch2' */
int16_T Switch2_l; /* '<S83>/Switch2' */
int16_T Switch2_c; /* '<S81>/Switch2' */
int16_T Merge; /* '<S42>/Merge' */
int16_T Switch1; /* '<S69>/Switch1' */
int16_T Divide11; /* '<S15>/Divide11' */
int16_T UnitDelay3_DSTATE; /* '<S12>/UnitDelay3' */
int16_T UnitDelay4_DSTATE; /* '<S15>/UnitDelay4' */
int16_T UnitDelay2_DSTATE; /* '<S15>/UnitDelay2' */
int16_T UnitDelay3_DSTATE_o; /* '<S15>/UnitDelay3' */
int16_T UnitDelay5_DSTATE; /* '<S15>/UnitDelay5' */
int16_T UnitDelay4_DSTATE_e; /* '<S12>/UnitDelay4' */
int16_T UnitDelay4_DSTATE_eu; /* '<S7>/UnitDelay4' */
int16_T UnitDelay4_DSTATE_h; /* '<S6>/UnitDelay4' */
int8_T Switch2_e; /* '<S11>/Switch2' */
int8_T UnitDelay2_DSTATE_b; /* '<S11>/UnitDelay2' */
int8_T If4_ActiveSubsystem; /* '<S1>/If4' */
int8_T If1_ActiveSubsystem; /* '<S1>/If1' */
int8_T If2_ActiveSubsystem_a; /* '<S5>/If2' */
int8_T If1_ActiveSubsystem_e; /* '<S5>/If1' */
int8_T If1_ActiveSubsystem_f; /* '<S41>/If1' */
int8_T If2_ActiveSubsystem_c; /* '<S41>/If2' */
int8_T SwitchCase_ActiveSubsystem; /* '<S5>/Switch Case' */
uint8_T UnitDelay3_DSTATE_fy; /* '<S7>/UnitDelay3' */
uint8_T UnitDelay1_DSTATE; /* '<S7>/UnitDelay1' */
uint8_T UnitDelay2_DSTATE_f; /* '<S7>/UnitDelay2' */
uint8_T UnitDelay1_DSTATE_p; /* '<S4>/UnitDelay1' */
uint8_T UnitDelay_DSTATE_c; /* '<S3>/UnitDelay' */
int8_T If2_ActiveSubsystem; /* '<S29>/If2' */
int8_T If2_ActiveSubsystem_a; /* '<S6>/If2' */
uint8_T z_ctrlMod; /* '<S4>/F03_02_Control_Mode_Manager' */
uint8_T UnitDelay3_DSTATE_fy; /* '<S9>/UnitDelay3' */
uint8_T UnitDelay1_DSTATE; /* '<S9>/UnitDelay1' */
uint8_T UnitDelay2_DSTATE_f; /* '<S9>/UnitDelay2' */
uint8_T is_active_c1_BLDC_controller;/* '<S4>/F03_02_Control_Mode_Manager' */
uint8_T is_c1_BLDC_controller; /* '<S4>/F03_02_Control_Mode_Manager' */
uint8_T is_ACTIVE; /* '<S4>/F03_02_Control_Mode_Manager' */
boolean_T Merge_n; /* '<S15>/Merge' */
boolean_T dz_cntTrnsDet; /* '<S13>/dz_cntTrnsDet' */
boolean_T UnitDelay_DSTATE_e; /* '<S33>/UnitDelay' */
boolean_T UnitDelay1_DSTATE_n; /* '<S13>/UnitDelay1' */
boolean_T n_commDeacv_Mode; /* '<S10>/n_commDeacv' */
boolean_T n_fieldWeakAuth_Mode; /* '<S38>/n_fieldWeakAuth' */
boolean_T n_fieldWeakAuth_Mode_m; /* '<S73>/n_fieldWeakAuth' */
boolean_T dz_cntTrnsDet_Mode; /* '<S13>/dz_cntTrnsDet' */
boolean_T Merge_n; /* '<S17>/Merge' */
boolean_T dz_cntTrnsDet; /* '<S15>/dz_cntTrnsDet' */
boolean_T UnitDelay2_DSTATE_g; /* '<S8>/UnitDelay2' */
boolean_T UnitDelay5_DSTATE_l; /* '<S8>/UnitDelay5' */
boolean_T UnitDelay6_DSTATE; /* '<S8>/UnitDelay6' */
boolean_T UnitDelay_DSTATE_e; /* '<S35>/UnitDelay' */
boolean_T UnitDelay1_DSTATE_n; /* '<S15>/UnitDelay1' */
boolean_T n_commDeacv_Mode; /* '<S12>/n_commDeacv' */
boolean_T dz_cntTrnsDet_Mode; /* '<S15>/dz_cntTrnsDet' */
} DW;
/* Constant parameters (auto storage) */
typedef struct {
/* Computed Parameter: r_sin3PhaA_M1_Table
* Referenced by: '<S71>/r_sin3PhaA_M1'
* Referenced by: '<S86>/r_sin3PhaA_M1'
*/
int16_T r_sin3PhaA_M1_Table[181];
/* Computed Parameter: r_sin3PhaB_M1_Table
* Referenced by: '<S71>/r_sin3PhaB_M1'
* Referenced by: '<S86>/r_sin3PhaB_M1'
*/
int16_T r_sin3PhaB_M1_Table[181];
/* Computed Parameter: r_sin3PhaC_M1_Table
* Referenced by: '<S71>/r_sin3PhaC_M1'
* Referenced by: '<S86>/r_sin3PhaC_M1'
*/
int16_T r_sin3PhaC_M1_Table[181];
/* Computed Parameter: r_sin_M1_Table
* Referenced by: '<S38>/r_sin_M1'
* Referenced by: '<S47>/r_sin_M1'
*/
int16_T r_sin_M1_Table[181];
/* Computed Parameter: r_cos_M1_Table
* Referenced by: '<S38>/r_cos_M1'
* Referenced by: '<S47>/r_cos_M1'
*/
int16_T r_cos_M1_Table[181];
/* Computed Parameter: iq_maxSca_M1_Table
* Referenced by: '<S41>/iq_maxSca_M1'
* Referenced by: '<S45>/iq_maxSca_M1'
*/
uint16_T iq_maxSca_M1_Table[50];
/* Computed Parameter: z_commutMap_M1_table
* Referenced by: '<S70>/z_commutMap_M1'
* Referenced by: '<S84>/z_commutMap_M1'
*/
int8_T z_commutMap_M1_table[18];
/* Computed Parameter: vec_hallToPos_Value
* Referenced by: '<S8>/vec_hallToPos'
* Referenced by: '<S10>/vec_hallToPos'
*/
int8_T vec_hallToPos_Value[8];
} ConstP;
@ -194,24 +206,24 @@ typedef struct {
/* Parameters (auto storage) */
struct P_ {
int32_T dV_openRate; /* Variable: dV_openRate
* Referenced by: '<S31>/dV_openRate'
* Referenced by: '<S33>/dV_openRate'
*/
int16_T dz_cntTrnsDetHi; /* Variable: dz_cntTrnsDetHi
* Referenced by: '<S13>/dz_cntTrnsDet'
* Referenced by: '<S15>/dz_cntTrnsDet'
*/
int16_T dz_cntTrnsDetLo; /* Variable: dz_cntTrnsDetLo
* Referenced by: '<S13>/dz_cntTrnsDet'
* Referenced by: '<S15>/dz_cntTrnsDet'
*/
int16_T z_maxCntRst; /* Variable: z_maxCntRst
* Referenced by:
* '<S10>/Counter'
* '<S10>/z_maxCntRst'
* '<S10>/z_maxCntRst2'
* '<S10>/UnitDelay3'
* '<S13>/z_counter'
* '<S12>/Counter'
* '<S12>/z_maxCntRst'
* '<S12>/z_maxCntRst2'
* '<S12>/UnitDelay3'
* '<S15>/z_counter'
*/
uint16_T cf_speedCoef; /* Variable: cf_speedCoef
* Referenced by: '<S13>/cf_speedCoef'
* Referenced by: '<S15>/cf_speedCoef'
*/
uint16_T t_errDequal; /* Variable: t_errDequal
* Referenced by: '<S3>/t_errDequal'
@ -221,88 +233,90 @@ struct P_ {
*/
int16_T Vd_max; /* Variable: Vd_max
* Referenced by:
* '<S41>/Vd_max1'
* '<S30>/Vd_max'
* '<S45>/Vd_max1'
* '<S32>/Vd_max'
*/
int16_T Vq_max_M1[46]; /* Variable: Vq_max_M1
* Referenced by: '<S41>/Vq_max_M1'
* Referenced by: '<S45>/Vq_max_M1'
*/
int16_T Vq_max_XA[46]; /* Variable: Vq_max_XA
* Referenced by: '<S41>/Vq_max_XA'
* Referenced by: '<S45>/Vq_max_XA'
*/
int16_T a_phaAdvMax; /* Variable: a_phaAdvMax
* Referenced by: '<S5>/a_phaAdvMax'
*/
int16_T i_max; /* Variable: i_max
* Referenced by:
* '<S41>/i_max'
* '<S30>/i_max'
* '<S45>/i_max'
* '<S32>/i_max'
*/
int16_T id_fieldWeak_M1[12]; /* Variable: id_fieldWeak_M1
* Referenced by: '<S38>/id_fieldWeak_M1'
int16_T id_fieldWeakMax; /* Variable: id_fieldWeakMax
* Referenced by: '<S5>/id_fieldWeakMax'
*/
int16_T n_commAcvLo; /* Variable: n_commAcvLo
* Referenced by: '<S10>/n_commDeacv'
* Referenced by: '<S12>/n_commDeacv'
*/
int16_T n_commDeacvHi; /* Variable: n_commDeacvHi
* Referenced by: '<S10>/n_commDeacv'
* Referenced by: '<S12>/n_commDeacv'
*/
int16_T n_fieldWeakAuthHi; /* Variable: n_fieldWeakAuthHi
* Referenced by:
* '<S38>/n_fieldWeakAuth'
* '<S73>/n_fieldWeakAuth'
* Referenced by: '<S5>/n_fieldWeakAuthHi'
*/
int16_T n_fieldWeakAuthLo; /* Variable: n_fieldWeakAuthLo
* Referenced by:
* '<S38>/n_fieldWeakAuth'
* '<S73>/n_fieldWeakAuth'
* Referenced by: '<S5>/n_fieldWeakAuthLo'
*/
int16_T n_max; /* Variable: n_max
* Referenced by:
* '<S41>/n_max1'
* '<S30>/n_max'
* '<S45>/n_max1'
* '<S32>/n_max'
*/
int16_T n_stdStillDet; /* Variable: n_stdStillDet
* Referenced by: '<S10>/n_stdStillDet'
* Referenced by: '<S12>/n_stdStillDet'
*/
int16_T r_errInpTgtThres; /* Variable: r_errInpTgtThres
* Referenced by: '<S3>/r_errInpTgtThres'
*/
int16_T r_fieldWeak_XA[12]; /* Variable: r_fieldWeak_XA
* Referenced by: '<S38>/r_fieldWeak_XA'
int16_T r_fieldWeakHi; /* Variable: r_fieldWeakHi
* Referenced by: '<S5>/r_fieldWeakHi'
*/
int16_T r_phaAdv_XA[11]; /* Variable: r_phaAdv_XA
* Referenced by: '<S73>/r_phaAdv_XA'
int16_T r_fieldWeakLo; /* Variable: r_fieldWeakLo
* Referenced by: '<S5>/r_fieldWeakLo'
*/
uint16_T cf_KbLimProt; /* Variable: cf_KbLimProt
* Referenced by:
* '<S72>/cf_KbLimProt'
* '<S73>/cf_KbLimProt'
*/
uint16_T cf_idKp; /* Variable: cf_idKp
* Referenced by: '<S46>/cf_idKp1'
* Referenced by: '<S54>/cf_idKp1'
*/
uint16_T cf_iqKp; /* Variable: cf_iqKp
* Referenced by: '<S45>/cf_iqKp'
* Referenced by: '<S53>/cf_iqKp'
*/
uint16_T cf_nKp; /* Variable: cf_nKp
* Referenced by: '<S44>/cf_nKp'
* Referenced by: '<S52>/cf_nKp'
*/
uint16_T cf_currFilt; /* Variable: cf_currFilt
* Referenced by: '<S37>/cf_currFilt'
* Referenced by: '<S41>/cf_currFilt'
*/
uint16_T cf_idKi; /* Variable: cf_idKi
* Referenced by: '<S46>/cf_idKi1'
* Referenced by: '<S54>/cf_idKi1'
*/
uint16_T cf_iqKi; /* Variable: cf_iqKi
* Referenced by: '<S45>/cf_iqKi'
* Referenced by: '<S53>/cf_iqKi'
*/
uint16_T cf_iqKiLimProt; /* Variable: cf_iqKiLimProt
* Referenced by: '<S44>/cf_iqKiLimProt'
* Referenced by:
* '<S71>/cf_iqKiLimProt'
* '<S73>/cf_iqKiLimProt'
*/
uint16_T cf_nKi; /* Variable: cf_nKi
* Referenced by: '<S44>/cf_nKi'
* Referenced by: '<S52>/cf_nKi'
*/
uint16_T cf_iqKpLimProt; /* Variable: cf_iqKpLimProt
* Referenced by: '<S51>/cf_iqKpLimProt'
*/
uint16_T cf_nKpLimProt; /* Variable: cf_nKpLimProt
* Referenced by: '<S52>/cf_nKpLimProt'
*/
int16_T a_phaAdv_M1[11]; /* Variable: a_phaAdv_M1
* Referenced by: '<S73>/a_phaAdv_M1'
uint16_T cf_nKiLimProt; /* Variable: cf_nKiLimProt
* Referenced by:
* '<S72>/cf_nKiLimProt'
* '<S73>/cf_nKiLimProt'
*/
uint8_T z_ctrlTypSel; /* Variable: z_ctrlTypSel
* Referenced by: '<S1>/z_ctrlTypSel1'
@ -312,11 +326,11 @@ struct P_ {
*/
boolean_T b_fieldWeakEna; /* Variable: b_fieldWeakEna
* Referenced by:
* '<S38>/b_fieldWeakEna'
* '<S73>/b_fieldWeakEna'
* '<S1>/b_fieldWeakEna'
* '<S87>/b_fieldWeakEna'
*/
boolean_T b_selPhaABCurrMeas; /* Variable: b_selPhaABCurrMeas
* Referenced by: '<S36>/b_selPhaABCurrMeas'
* Referenced by: '<S40>/b_selPhaABCurrMeas'
*/
};
@ -341,24 +355,33 @@ extern void BLDC_controller_step(RT_MODEL *const rtM);
/*-
* These blocks were eliminated from the model due to optimizations:
*
* Block '<S10>/Scope2' : Unused code path elimination
* Block '<S11>/Scope' : Unused code path elimination
* Block '<S35>/Data Type Duplicate' : Unused code path elimination
* Block '<S35>/Data Type Propagation' : Unused code path elimination
* Block '<S53>/Data Type Duplicate' : Unused code path elimination
* Block '<S53>/Data Type Propagation' : Unused code path elimination
* Block '<S54>/Data Type Duplicate' : Unused code path elimination
* Block '<S54>/Data Type Propagation' : Unused code path elimination
* Block '<S5>/Scope12' : Unused code path elimination
* Block '<S5>/Scope8' : Unused code path elimination
* Block '<S5>/Scope9' : Unused code path elimination
* Block '<S60>/Data Type Duplicate' : Unused code path elimination
* Block '<S60>/Data Type Propagation' : Unused code path elimination
* Block '<S65>/Data Type Duplicate' : Unused code path elimination
* Block '<S65>/Data Type Propagation' : Unused code path elimination
* Block '<S69>/Data Type Duplicate' : Unused code path elimination
* Block '<S69>/Data Type Propagation' : Unused code path elimination
* Block '<S73>/Scope' : Unused code path elimination
* Block '<S12>/Scope2' : Unused code path elimination
* Block '<S13>/Scope' : Unused code path elimination
* Block '<S37>/Data Type Duplicate' : Unused code path elimination
* Block '<S37>/Data Type Propagation' : Unused code path elimination
* Block '<S38>/Data Type Duplicate' : Unused code path elimination
* Block '<S38>/Data Type Propagation' : Unused code path elimination
* Block '<S39>/Data Type Duplicate' : Unused code path elimination
* Block '<S39>/Data Type Propagation' : Unused code path elimination
* Block '<S61>/Data Type Duplicate' : Unused code path elimination
* Block '<S61>/Data Type Propagation' : Unused code path elimination
* Block '<S66>/Data Type Duplicate' : Unused code path elimination
* Block '<S66>/Data Type Propagation' : Unused code path elimination
* Block '<S70>/Data Type Duplicate' : Unused code path elimination
* Block '<S70>/Data Type Propagation' : Unused code path elimination
* Block '<S74>/Data Type Duplicate' : Unused code path elimination
* Block '<S74>/Data Type Propagation' : Unused code path elimination
* Block '<S77>/Data Type Duplicate' : Unused code path elimination
* Block '<S77>/Data Type Propagation' : Unused code path elimination
* Block '<S81>/Data Type Duplicate' : Unused code path elimination
* Block '<S81>/Data Type Propagation' : Unused code path elimination
* Block '<S83>/Data Type Duplicate' : Unused code path elimination
* Block '<S83>/Data Type Propagation' : Unused code path elimination
* Block '<S6>/Scope12' : Unused code path elimination
* Block '<S6>/Scope8' : Unused code path elimination
* Block '<S6>/Scope9' : Unused code path elimination
* Block '<S87>/Scope' : Unused code path elimination
* Block '<S8>/Data Type Conversion' : Eliminate redundant data type conversion
*/
/*-
@ -383,76 +406,90 @@ extern void BLDC_controller_step(RT_MODEL *const rtM);
* '<S2>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations'
* '<S3>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics'
* '<S4>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager'
* '<S5>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control'
* '<S6>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management'
* '<S7>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_01_Edge_Detector'
* '<S8>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_02_Position_Calculation'
* '<S9>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_03_Direction_Detection'
* '<S10>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation'
* '<S11>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_05_Electrical_Angle_Estimation'
* '<S12>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Counter'
* '<S13>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Raw_Motor_Speed_Estimation'
* '<S14>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Counter/rst_Delay'
* '<S15>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter'
* '<S16>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/either_edge'
* '<S17>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Default'
* '<S18>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification'
* '<S19>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification'
* '<S20>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/either_edge'
* '<S21>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification/Counter'
* '<S22>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification/Counter/rst_Delay'
* '<S23>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification/Counter'
* '<S24>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification/Counter/rst_Delay'
* '<S25>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_01_Mode_Transition_Calculation'
* '<S26>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_02_Control_Mode_Manager'
* '<S27>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis'
* '<S28>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Default_Control_Type'
* '<S29>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Default_Mode'
* '<S30>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/FOC_Control_Type'
* '<S31>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode'
* '<S32>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter'
* '<S33>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/rising_edge_init'
* '<S34>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter/Delay_Init1'
* '<S35>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter/Saturation Dynamic'
* '<S36>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Clarke_Transform'
* '<S37>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Current_Filtering'
* '<S38>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Field_Weakening'
* '<S39>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Inv_Clarke_Transform'
* '<S40>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Inv_Park_Transform'
* '<S41>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Motor_Limitations'
* '<S42>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Open_Mode'
* '<S43>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Park_Transform'
* '<S44>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Speed_Mode'
* '<S45>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode'
* '<S46>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation'
* '<S47>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Voltage_Mode'
* '<S48>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Clarke_Transform/Clarke_PhasesAB'
* '<S49>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Clarke_Transform/Clarke_PhasesBC'
* '<S50>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Current_Filtering/Low_Pass_Filter'
* '<S51>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Motor_Limitations/Current_Limit_Protection'
* '<S52>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Motor_Limitations/Speed_Limit_Protection'
* '<S53>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Motor_Limitations/Current_Limit_Protection/Saturation Dynamic'
* '<S54>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Motor_Limitations/Speed_Limit_Protection/Saturation Dynamic1'
* '<S55>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Speed_Mode/PI_clamp_fixdt_n'
* '<S56>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Speed_Mode/PI_clamp_fixdt_n/Clamping_circuit'
* '<S57>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Speed_Mode/PI_clamp_fixdt_n/Integrator'
* '<S58>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Speed_Mode/PI_clamp_fixdt_n/Saturation_hit'
* '<S59>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode/PI_clamp_fixdt_iq'
* '<S60>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode/Saturation Dynamic'
* '<S61>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode/PI_clamp_fixdt_iq/Clamping_circuit'
* '<S62>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode/PI_clamp_fixdt_iq/Integrator'
* '<S63>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Torque_Mode/PI_clamp_fixdt_iq/Saturation_hit'
* '<S64>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation/PI_clamp_fixdt_id'
* '<S65>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation/Saturation Dynamic'
* '<S66>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation/PI_clamp_fixdt_id/Clamping_circuit'
* '<S67>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation/PI_clamp_fixdt_id/Integrator'
* '<S68>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Vd_Calculation/PI_clamp_fixdt_id/Saturation_hit'
* '<S69>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Oriented_Control/Voltage_Mode/Saturation Dynamic1'
* '<S70>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management/F05_00_COM_Method'
* '<S71>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management/F05_01_SIN_Method'
* '<S72>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management/F05_02_FOC_Method'
* '<S73>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management/F05_01_SIN_Method/Phase_Advance_Calculation'
* '<S74>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Control_Type_Management/F05_01_SIN_Method/Phase_Advance_Calculation/Modulo_fixdt'
* '<S5>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Weakening'
* '<S6>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control'
* '<S7>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management'
* '<S8>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/Task_Scheduler'
* '<S9>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_01_Edge_Detector'
* '<S10>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_02_Position_Calculation'
* '<S11>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_03_Direction_Detection'
* '<S12>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation'
* '<S13>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_05_Electrical_Angle_Estimation'
* '<S14>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Counter'
* '<S15>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Raw_Motor_Speed_Estimation'
* '<S16>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F01_Estimations/F01_04_Speed_Estimation/Counter/rst_Delay'
* '<S17>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter'
* '<S18>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/either_edge'
* '<S19>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Default'
* '<S20>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification'
* '<S21>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification'
* '<S22>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/either_edge'
* '<S23>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification/Counter'
* '<S24>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Dequalification/Counter/rst_Delay'
* '<S25>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification/Counter'
* '<S26>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F02_Diagnostics/Debounce_Filter/Qualification/Counter/rst_Delay'
* '<S27>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_01_Mode_Transition_Calculation'
* '<S28>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_02_Control_Mode_Manager'
* '<S29>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis'
* '<S30>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Default_Control_Type'
* '<S31>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Default_Mode'
* '<S32>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/FOC_Control_Type'
* '<S33>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode'
* '<S34>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter'
* '<S35>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/rising_edge_init'
* '<S36>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter/Delay_Init1'
* '<S37>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F03_Control_Mode_Manager/F03_03_Input_Target_Synthesis/Open_Mode/Rate_Limiter/Saturation Dynamic'
* '<S38>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Weakening/Saturation Dynamic'
* '<S39>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F04_Field_Weakening/Saturation Dynamic1'
* '<S40>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Clarke_Transform'
* '<S41>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Current_Filtering'
* '<S42>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC'
* '<S43>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Inv_Clarke_Transform'
* '<S44>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Inv_Park_Transform'
* '<S45>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations'
* '<S46>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Park_Transform'
* '<S47>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Sine_Cosine_Approximation'
* '<S48>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Clarke_Transform/Clarke_PhasesAB'
* '<S49>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Clarke_Transform/Clarke_PhasesBC'
* '<S50>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Current_Filtering/Low_Pass_Filter'
* '<S51>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Open_Mode'
* '<S52>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Speed_Mode'
* '<S53>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode'
* '<S54>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation'
* '<S55>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Voltage_Mode'
* '<S56>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Speed_Mode/PI_clamp_fixdt'
* '<S57>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Speed_Mode/PI_clamp_fixdt/Clamping_circuit'
* '<S58>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Speed_Mode/PI_clamp_fixdt/Integrator'
* '<S59>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Speed_Mode/PI_clamp_fixdt/Saturation_hit'
* '<S60>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode/PI_clamp_fixdt'
* '<S61>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode/Saturation Dynamic1'
* '<S62>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode/PI_clamp_fixdt/Clamping_circuit'
* '<S63>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode/PI_clamp_fixdt/Integrator'
* '<S64>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Torque_Mode/PI_clamp_fixdt/Saturation_hit'
* '<S65>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation/PI_clamp_fixdt'
* '<S66>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation/Saturation Dynamic'
* '<S67>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation/PI_clamp_fixdt/Clamping_circuit'
* '<S68>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation/PI_clamp_fixdt/Integrator'
* '<S69>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Vd_Calculation/PI_clamp_fixdt/Saturation_hit'
* '<S70>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/FOC/Voltage_Mode/Saturation Dynamic1'
* '<S71>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Speed_Mode_Protection'
* '<S72>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Torque_Mode_Protection'
* '<S73>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection'
* '<S74>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Speed_Mode_Protection/Saturation Dynamic'
* '<S75>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Torque_Mode_Protection/I_backCalc_fixdt'
* '<S76>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Torque_Mode_Protection/I_backCalc_fixdt/Integrator'
* '<S77>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Torque_Mode_Protection/I_backCalc_fixdt/Saturation Dynamic1'
* '<S78>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt'
* '<S79>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt1'
* '<S80>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt/Integrator'
* '<S81>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt/Saturation Dynamic1'
* '<S82>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt1/Integrator'
* '<S83>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F05_Field_Oriented_Control/Motor_Limitations/Voltage_Mode_Protection/I_backCalc_fixdt1/Saturation Dynamic1'
* '<S84>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management/COM_Method'
* '<S85>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management/FOC_Method'
* '<S86>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management/SIN_Method'
* '<S87>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management/SIN_Method/Final_Phase_Advance_Calculation'
* '<S88>' : 'BLDCmotorControl_FOC_R2017b_fixdt/BLDC_controller/F06_Control_Type_Management/SIN_Method/Final_Phase_Advance_Calculation/Modulo_fixdt'
*/
#endif /* RTW_HEADER_BLDC_controller_h_ */

View File

@ -123,11 +123,11 @@
* Make, flash and test it.
*/
#define CONTROL_ADC // use ADC as input. disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
#define ADC1_MID_POT // ADC1 middle resting poti: comment-out if NOT a middle resting poti
#define ADC2_MID_POT // ADC2 middle resting poti: comment-out if NOT a middle resting poti
// #define ADC1_MID_POT // ADC1 middle resting poti: comment-out if NOT a middle resting poti
#define ADC1_MIN 0 // min ADC1-value while poti at minimum-position (0 - 4095)
#define ADC1_MID 1963 // mid ADC1-value while poti at minimum-position (ADC1_MIN - ADC1_MAX)
#define ADC1_MAX 4095 // max ADC1-value while poti at maximum-position (0 - 4095)
// #define ADC2_MID_POT // ADC2 middle resting poti: comment-out if NOT a middle resting poti
#define ADC2_MIN 0 // min ADC2-value while poti at minimum-position (0 - 4095)
#define ADC2_MID 2006 // mid ADC2-value while poti at minimum-position (ADC2_MIN - ADC2_MAX)
#define ADC2_MAX 4095 // max ADC2-value while poti at maximum-position (0 - 4095)
@ -141,39 +141,55 @@
// #define CONTROL_NUNCHUCK // use nunchuck as input. disable FEEDBACK_SERIAL_USART3, DEBUG_SERIAL_USART3!
// ############################### MOTOR CONTROL (overwrite) #########################
// ############################### MOTOR CONTROL #########################
// Control selections
#define CTRL_TYP_SEL 2 // [-] Control type selection: 0 = Commutation , 1 = Sinusoidal, 2 = FOC Field Oriented Control (default)
#define CTRL_MOD_REQ 1 // [-] Control mode request: 0 = Open mode, 1 = VOLTAGE mode (default), 2 = SPEED mode, 3 = TORQUE mode. Note: SPEED and TORQUE modes are only available for FOC!
#define DIAG_ENA 1 // [-] Motor Diagnostics enable flag: 0 = Disabled, 1 = Enabled (default)
#define FIELD_WEAK_ENA 0 // [-] Field Weakening enable flag: 0 = Disabled (default), 1 = Enabled
#define I_MOT_MAX (15 * A2BIT_CONV) << 4 // [A] Maximum motor current limit (Change only the first number, the rest is needed for fixed-point conversion, fixdt(1,16,4))
#define I_DC_MAX (17 * A2BIT_CONV) // [A] Maximum DC Link current limit (This is the final current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A )
#define N_MOT_MAX 800 << 4 // [rpm] Maximum motor speed (change only the first number, the rest is needed for fixed-point conversion, fixdt(1,16,4))
// Limitation settings
#define I_MOT_MAX 15 // [A] Maximum motor current limit
#define I_DC_MAX 17 // [A] Maximum DC Link current limit (This is the final current protection. Above this value, current chopping is applied. To avoid this make sure that I_DC_MAX = I_MOT_MAX + 2A)
#define N_MOT_MAX 1000 // [rpm] Maximum motor speed limit
// Field Weakening / Phase Advance
#define FIELD_WEAK_ENA 0 // [-] Field Weakening / Phase Advance enable flag: 0 = Disabled (default), 1 = Enabled
#define FIELD_WEAK_MAX 5 // [A] Maximum Field Weakening D axis current (only for FOC). Higher current results in higher maximum speed.
#define PHASE_ADV_MAX 25 // [deg] Maximum Phase Advance angle (only for SIN). Higher angle results in higher maximum speed.
#define FIELD_WEAK_HI 1500 // [-] Input target High threshold for reaching maximum Field Weakening / Phase Advance. Do NOT set this higher than 1500.
#define FIELD_WEAK_LO 1000 // [-] Input target Low threshold for starting Field Weakening / Phase Advance. Do NOT set this higher than 1000.
// Data checks - Do NOT touch
#if (FIELD_WEAK_ENA == 0)
#undef FIELD_WEAK_HI
#define FIELD_WEAK_HI 1000 // [-] This prevents the input target going beyond 1000 when Field Weakening is not enabled
#endif
#define INPUT_MAX MAX( 1000, FIELD_WEAK_HI) // [-] Defines the Input target maximum limitation
#define INPUT_MIN MIN(-1000,-FIELD_WEAK_HI) // [-] Defines the Input target minimum limitation
#define INPUT_MID INPUT_MAX / 2
/* GENERAL NOTES:
* 1. The above parameters are over-writing the default motor parameters. For all the available parameters check BLDC_controller_data.c
* 2. The parameters are represented in fixed point data type for a more efficient code execution
* 3. For calibrating the fixed-point parameters use the Fixed-Point Viewer tool (see <https://github.com/EmanuelFeru/FixedPointViewer>)
* 4. For more details regarding the parameters and the working principle of the controller please consult the Simulink model
* 5. A webview was created, so Matlab/Simulink installation is not needed, unless you want to regenerate the code
* 5. A webview was created, so Matlab/Simulink installation is not needed, unless you want to regenerate the code. The webview is an html page that can be opened with browsers like: Microsoft Internet Explorer or Microsoft Edge
*
* NOTES Field weakening:
* 1. In BLDC_controller_data.c you can find the field weakening Map as a function of input target: MAP = id_fieldWeak_M1, XAXIS = r_fieldWeak_XA
* 2. The default calibration was experimentally calibrated to my particular needs
* 3. If you re-calibrate the field weakening map please take all the safety measures! The motors can spin very fast!
* 4. During the recalibration make sure the values in XAXIS are equally spaced for a correct Map interpolation.
* NOTES Field Weakening / Phase Advance:
* 1. The Field Weakening is a linear interpolation from 0 to FIELD_WEAK_MAX or PHASE_ADV_MAX (depeding if FOC or SIN is selected, respectively)
* 2. The Field Weakening starts engaging at FIELD_WEAK_LO and reaches the maximum value at FIELD_WEAK_HI
* 3. If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!
*/
// ############################### DRIVING BEHAVIOR ###############################
/* Inputs:
* - cmd1 and cmd2: analog normalized input values. -1000 to 1000
* - cmd1 and cmd2: analog normalized input values. INPUT_MIN to INPUT_MAX
* - button1 and button2: digital input values. 0 or 1
* - adc_buffer.l_tx2 and adc_buffer.l_rx2: unfiltered ADC values (you do not need them). 0 to 4095
* Outputs:
* - speedR and speedL: normal driving -1000 to 1000
* - speedR and speedL: normal driving INPUT_MIN to INPUT_MAX
*/
// Value of RATE is in fixdt(1,16,4): VAL_fixedPoint = VAL_floatingPoint * 2^4. In this case 480 = 30 * 2^4

View File

@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'BLDC_controller'.
*
* Model version : 1.1212
* Model version : 1.1249
* Simulink Coder version : 8.13 (R2017b) 24-Jul-2017
* C/C++ source code generated on : Sat Nov 30 08:54:28 2019
* C/C++ source code generated on : Thu Dec 12 20:22:31 2019
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'BLDC_controller'.
*
* Model version : 1.1212
* Model version : 1.1249
* Simulink Coder version : 8.13 (R2017b) 24-Jul-2017
* C/C++ source code generated on : Sat Nov 30 08:54:28 2019
* C/C++ source code generated on : Thu Dec 12 20:22:31 2019
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
@ -22,7 +22,7 @@
/* Constant parameters (auto storage) */
const ConstP rtConstP = {
/* Computed Parameter: r_sin3PhaA_M1_Table
* Referenced by: '<S71>/r_sin3PhaA_M1'
* Referenced by: '<S86>/r_sin3PhaA_M1'
*/
{ -13091, -13634, -14126, -14565, -14953, -15289, -15577, -15816, -16009,
-16159, -16269, -16340, -16377, -16383, -16362, -16317, -16253, -16172,
@ -44,7 +44,7 @@ const ConstP rtConstP = {
-9623, -10411, -11154, -11849, -12496, -13091 },
/* Computed Parameter: r_sin3PhaB_M1_Table
* Referenced by: '<S71>/r_sin3PhaB_M1'
* Referenced by: '<S86>/r_sin3PhaB_M1'
*/
{ 15172, 15180, 15206, 15248, 15306, 15377, 15461, 15555, 15656, 15762, 15870,
15977, 16079, 16172, 16253, 16317, 16362, 16383, 16377, 16340, 16269, 16159,
@ -66,7 +66,7 @@ const ConstP rtConstP = {
15377, 15306, 15248, 15206, 15180, 15172 },
/* Computed Parameter: r_sin3PhaC_M1_Table
* Referenced by: '<S71>/r_sin3PhaC_M1'
* Referenced by: '<S86>/r_sin3PhaC_M1'
*/
{ -13091, -12496, -11849, -11154, -10411, -9623, -8791, -7921, -7014, -6075,
-5107, -4115, -3104, -2077, -1041, 0, 1041, 2077, 3104, 4115, 5107, 6075,
@ -88,7 +88,7 @@ const ConstP rtConstP = {
-15289, -14953, -14565, -14126, -13634, -13091 },
/* Computed Parameter: r_sin_M1_Table
* Referenced by: '<S38>/r_sin_M1'
* Referenced by: '<S47>/r_sin_M1'
*/
{ 8192, 8682, 9162, 9630, 10087, 10531, 10963, 11381, 11786, 12176, 12551,
12911, 13255, 13583, 13894, 14189, 14466, 14726, 14968, 15191, 15396, 15582,
@ -109,7 +109,7 @@ const ConstP rtConstP = {
2280, 2845, 3406, 3964, 4516, 5063, 5604, 6138, 6664, 7182, 7692, 8192 },
/* Computed Parameter: r_cos_M1_Table
* Referenced by: '<S38>/r_cos_M1'
* Referenced by: '<S47>/r_cos_M1'
*/
{ 14189, 13894, 13583, 13255, 12911, 12551, 12176, 11786, 11381, 10963, 10531,
10087, 9630, 9162, 8682, 8192, 7692, 7182, 6664, 6138, 5604, 5063, 4516,
@ -130,7 +130,7 @@ const ConstP rtConstP = {
16026, 15897, 15749, 15582, 15396, 15191, 14968, 14726, 14466, 14189 },
/* Computed Parameter: iq_maxSca_M1_Table
* Referenced by: '<S41>/iq_maxSca_M1'
* Referenced by: '<S45>/iq_maxSca_M1'
*/
{ 65535U, 65523U, 65484U, 65418U, 65326U, 65207U, 65062U, 64890U, 64691U,
64465U, 64211U, 63930U, 63620U, 63281U, 62913U, 62516U, 62088U, 61630U,
@ -140,66 +140,66 @@ const ConstP rtConstP = {
28540U, 25655U, 22323U, 18304U, 12974U },
/* Computed Parameter: z_commutMap_M1_table
* Referenced by: '<S70>/z_commutMap_M1'
* Referenced by: '<S84>/z_commutMap_M1'
*/
{ -1, 1, 0, -1, 0, 1, 0, -1, 1, 1, -1, 0, 1, 0, -1, 0, 1, -1 },
/* Computed Parameter: vec_hallToPos_Value
* Referenced by: '<S8>/vec_hallToPos'
* Referenced by: '<S10>/vec_hallToPos'
*/
{ 0, 2, 0, 1, 4, 3, 5, 0 }
};
P rtP_Left = {
/* Variable: dV_openRate
* Referenced by: '<S31>/dV_openRate'
* Referenced by: '<S33>/dV_openRate'
*/
4096,
12288,
/* Variable: dz_cntTrnsDetHi
* Referenced by: '<S13>/dz_cntTrnsDet'
* Referenced by: '<S15>/dz_cntTrnsDet'
*/
40,
/* Variable: dz_cntTrnsDetLo
* Referenced by: '<S13>/dz_cntTrnsDet'
* Referenced by: '<S15>/dz_cntTrnsDet'
*/
20,
/* Variable: z_maxCntRst
* Referenced by:
* '<S10>/Counter'
* '<S10>/z_maxCntRst'
* '<S10>/z_maxCntRst2'
* '<S10>/UnitDelay3'
* '<S13>/z_counter'
* '<S12>/Counter'
* '<S12>/z_maxCntRst'
* '<S12>/z_maxCntRst2'
* '<S12>/UnitDelay3'
* '<S15>/z_counter'
*/
2000,
/* Variable: cf_speedCoef
* Referenced by: '<S13>/cf_speedCoef'
* Referenced by: '<S15>/cf_speedCoef'
*/
10667U,
/* Variable: t_errDequal
* Referenced by: '<S3>/t_errDequal'
*/
32000U,
10667U,
/* Variable: t_errQual
* Referenced by: '<S3>/t_errQual'
*/
9600U,
3200U,
/* Variable: Vd_max
* Referenced by:
* '<S41>/Vd_max1'
* '<S30>/Vd_max'
* '<S45>/Vd_max1'
* '<S32>/Vd_max'
*/
14400,
/* Variable: Vq_max_M1
* Referenced by: '<S41>/Vq_max_M1'
* Referenced by: '<S45>/Vq_max_M1'
*/
{ 14400, 14396, 14386, 14368, 14343, 14311, 14271, 14225, 14171, 14109, 14040,
13963, 13879, 13786, 13685, 13576, 13459, 13333, 13198, 13053, 12900, 12736,
@ -207,58 +207,59 @@ P rtP_Left = {
9790, 9433, 9051, 8640, 8196, 7713, 7184, 6597, 5935, 5170, 4245, 3019, 0 },
/* Variable: Vq_max_XA
* Referenced by: '<S41>/Vq_max_XA'
* Referenced by: '<S45>/Vq_max_XA'
*/
{ 0, 320, 640, 960, 1280, 1600, 1920, 2240, 2560, 2880, 3200, 3520, 3840, 4160,
4480, 4800, 5120, 5440, 5760, 6080, 6400, 6720, 7040, 7360, 7680, 8000, 8320,
8640, 8960, 9280, 9600, 9920, 10240, 10560, 10880, 11200, 11520, 11840,
12160, 12480, 12800, 13120, 13440, 13760, 14080, 14400 },
/* Variable: a_phaAdvMax
* Referenced by: '<S5>/a_phaAdvMax'
*/
400,
/* Variable: i_max
* Referenced by:
* '<S41>/i_max'
* '<S30>/i_max'
* '<S45>/i_max'
* '<S32>/i_max'
*/
12000,
/* Variable: id_fieldWeak_M1
* Referenced by: '<S38>/id_fieldWeak_M1'
/* Variable: id_fieldWeakMax
* Referenced by: '<S5>/id_fieldWeakMax'
*/
{ 0, 80, 240, 560, 1040, 1680, 2400, 3040, 3520, 3840, 4000, 4000 },
4000,
/* Variable: n_commAcvLo
* Referenced by: '<S10>/n_commDeacv'
* Referenced by: '<S12>/n_commDeacv'
*/
240,
/* Variable: n_commDeacvHi
* Referenced by: '<S10>/n_commDeacv'
* Referenced by: '<S12>/n_commDeacv'
*/
480,
/* Variable: n_fieldWeakAuthHi
* Referenced by:
* '<S38>/n_fieldWeakAuth'
* '<S73>/n_fieldWeakAuth'
* Referenced by: '<S5>/n_fieldWeakAuthHi'
*/
3200,
6400,
/* Variable: n_fieldWeakAuthLo
* Referenced by:
* '<S38>/n_fieldWeakAuth'
* '<S73>/n_fieldWeakAuth'
* Referenced by: '<S5>/n_fieldWeakAuthLo'
*/
2240,
4800,
/* Variable: n_max
* Referenced by:
* '<S41>/n_max1'
* '<S30>/n_max'
* '<S45>/n_max1'
* '<S32>/n_max'
*/
12800,
16000,
/* Variable: n_stdStillDet
* Referenced by: '<S10>/n_stdStillDet'
* Referenced by: '<S12>/n_stdStillDet'
*/
48,
@ -267,71 +268,71 @@ P rtP_Left = {
*/
6400,
/* Variable: r_fieldWeak_XA
* Referenced by: '<S38>/r_fieldWeak_XA'
/* Variable: r_fieldWeakHi
* Referenced by: '<S5>/r_fieldWeakHi'
*/
{ 9120, 9600, 10080, 10560, 11040, 11520, 12000, 12480, 12960, 13440, 13920,
14400 },
24000,
/* Variable: r_phaAdv_XA
* Referenced by: '<S73>/r_phaAdv_XA'
/* Variable: r_fieldWeakLo
* Referenced by: '<S5>/r_fieldWeakLo'
*/
{ 0, 1600, 3200, 4800, 6400, 8000, 9600, 11200, 12800, 14400, 16000 },
16000,
/* Variable: cf_KbLimProt
* Referenced by:
* '<S72>/cf_KbLimProt'
* '<S73>/cf_KbLimProt'
*/
768U,
/* Variable: cf_idKp
* Referenced by: '<S46>/cf_idKp1'
* Referenced by: '<S54>/cf_idKp1'
*/
819U,
/* Variable: cf_iqKp
* Referenced by: '<S45>/cf_iqKp'
* Referenced by: '<S53>/cf_iqKp'
*/
2048U,
1229U,
/* Variable: cf_nKp
* Referenced by: '<S44>/cf_nKp'
* Referenced by: '<S52>/cf_nKp'
*/
4833U,
/* Variable: cf_currFilt
* Referenced by: '<S37>/cf_currFilt'
* Referenced by: '<S41>/cf_currFilt'
*/
7864U,
/* Variable: cf_idKi
* Referenced by: '<S46>/cf_idKi1'
* Referenced by: '<S54>/cf_idKi1'
*/
246U,
737U,
/* Variable: cf_iqKi
* Referenced by: '<S45>/cf_iqKi'
* Referenced by: '<S53>/cf_iqKi'
*/
410U,
1229U,
/* Variable: cf_iqKiLimProt
* Referenced by: '<S44>/cf_iqKiLimProt'
* Referenced by:
* '<S71>/cf_iqKiLimProt'
* '<S73>/cf_iqKiLimProt'
*/
167U,
737U,
/* Variable: cf_nKi
* Referenced by: '<S44>/cf_nKi'
* Referenced by: '<S52>/cf_nKi'
*/
84U,
251U,
/* Variable: cf_iqKpLimProt
* Referenced by: '<S51>/cf_iqKpLimProt'
/* Variable: cf_nKiLimProt
* Referenced by:
* '<S72>/cf_nKiLimProt'
* '<S73>/cf_nKiLimProt'
*/
1843U,
/* Variable: cf_nKpLimProt
* Referenced by: '<S52>/cf_nKpLimProt'
*/
1280U,
/* Variable: a_phaAdv_M1
* Referenced by: '<S73>/a_phaAdv_M1'
*/
{ 0, 0, 0, 0, 0, 512, 768, 1280, 2304, 4096, 6400 },
246U,
/* Variable: z_ctrlTypSel
* Referenced by: '<S1>/z_ctrlTypSel1'
@ -345,13 +346,13 @@ P rtP_Left = {
/* Variable: b_fieldWeakEna
* Referenced by:
* '<S38>/b_fieldWeakEna'
* '<S73>/b_fieldWeakEna'
* '<S1>/b_fieldWeakEna'
* '<S87>/b_fieldWeakEna'
*/
0,
/* Variable: b_selPhaABCurrMeas
* Referenced by: '<S36>/b_selPhaABCurrMeas'
* Referenced by: '<S40>/b_selPhaABCurrMeas'
*/
1
}; /* Modifiable parameters */

View File

@ -47,6 +47,7 @@ extern ExtY rtY_Right; /* External outputs */
static int16_t pwm_margin = 100; /* This margin allows to always have a window in the PWM signal for proper Phase currents measurement */
extern uint8_t ctrlModReq;
static int16_t curDC_max = (I_DC_MAX * A2BIT_CONV);
int16_t curL_phaA = 0, curL_phaB = 0, curL_DC = 0;
int16_t curR_phaB = 0, curR_phaC = 0, curR_DC = 0;
uint8_t errCode_Left = 0;
@ -116,13 +117,13 @@ void DMA1_Channel1_IRQHandler(void) {
// Disable PWM when current limit is reached (current chopping)
// This is the Level 2 of current protection. The Level 1 should kick in first given by I_MOT_MAX
if(ABS(curL_DC) > I_DC_MAX || timeout > TIMEOUT || enable == 0) {
if(ABS(curL_DC) > curDC_max || timeout > TIMEOUT || enable == 0) {
LEFT_TIM->BDTR &= ~TIM_BDTR_MOE;
} else {
LEFT_TIM->BDTR |= TIM_BDTR_MOE;
}
if(ABS(curR_DC) > I_DC_MAX || timeout > TIMEOUT || enable == 0) {
if(ABS(curR_DC) > curDC_max || timeout > TIMEOUT || enable == 0) {
RIGHT_TIM->BDTR &= ~TIM_BDTR_MOE;
} else {
RIGHT_TIM->BDTR |= TIM_BDTR_MOE;

View File

@ -35,18 +35,18 @@
RT_MODEL rtM_Left_; /* Real-time model */
RT_MODEL rtM_Right_; /* Real-time model */
RT_MODEL *const rtM_Left = &rtM_Left_;
RT_MODEL *const rtM_Right = &rtM_Right_;
RT_MODEL *const rtM_Left = &rtM_Left_;
RT_MODEL *const rtM_Right = &rtM_Right_;
P rtP_Left; /* Block parameters (auto storage) */
DW rtDW_Left; /* Observable states */
ExtU rtU_Left; /* External inputs */
ExtY rtY_Left; /* External outputs */
P rtP_Left; /* Block parameters (auto storage) */
DW rtDW_Left; /* Observable states */
ExtU rtU_Left; /* External inputs */
ExtY rtY_Left; /* External outputs */
P rtP_Right; /* Block parameters (auto storage) */
DW rtDW_Right; /* Observable states */
ExtU rtU_Right; /* External inputs */
ExtY rtY_Right; /* External outputs */
P rtP_Right; /* Block parameters (auto storage) */
DW rtDW_Right; /* Observable states */
ExtU rtU_Right; /* External inputs */
ExtY rtY_Right; /* External outputs */
extern uint8_t errCode_Left; /* Global variable to handle Motor error codes */
extern uint8_t errCode_Right; /* Global variable to handle Motor error codes */
@ -99,27 +99,27 @@ static uint8_t serialSendCounter; // serial send counter
static uint8_t button1, button2;
#endif
uint8_t ctrlModReqRaw = CTRL_MOD_REQ;
uint8_t ctrlModReq; // Final control mode request
static int cmd1; // normalized input value. -1000 to 1000
static int cmd2; // normalized input value. -1000 to 1000
static int16_t steer; // local variable for steering. -1000 to 1000
static int16_t speed; // local variable for speed. -1000 to 1000
static int16_t steerFixdt; // local fixed-point variable for steering low-pass filter
static int16_t speedFixdt; // local fixed-point variable for speed low-pass filter
static int16_t steerRateFixdt; // local fixed-point variable for steering rate limiter
static int16_t speedRateFixdt; // local fixed-point variable for speed rate limiter
uint8_t ctrlModReqRaw = CTRL_MOD_REQ;
uint8_t ctrlModReq = CTRL_MOD_REQ; // Final control mode request
static int cmd1; // normalized input value. -1000 to 1000
static int cmd2; // normalized input value. -1000 to 1000
static int16_t steer; // local variable for steering. -1000 to 1000
static int16_t speed; // local variable for speed. -1000 to 1000
static int16_t steerFixdt; // local fixed-point variable for steering low-pass filter
static int16_t speedFixdt; // local fixed-point variable for speed low-pass filter
static int16_t steerRateFixdt; // local fixed-point variable for steering rate limiter
static int16_t speedRateFixdt; // local fixed-point variable for speed rate limiter
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
extern uint8_t buzzerFreq; // global variable for the buzzer pitch. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t buzzerPattern; // global variable for the buzzer pattern. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t buzzerFreq; // global variable for the buzzer pitch. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t buzzerPattern; // global variable for the buzzer pattern. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t enable; // global variable for motor enable
extern uint8_t enable; // global variable for motor enable
extern volatile uint32_t timeout; // global variable for timeout
extern int16_t batVoltage; // global variable for battery voltage
extern volatile uint32_t timeout; // global variable for timeout
extern int16_t batVoltage; // global variable for battery voltage
static uint32_t inactivity_timeout_counter;
@ -187,16 +187,24 @@ int main(void) {
rtP_Left.b_selPhaABCurrMeas = 1; // Left motor measured current phases = {iA, iB} -> do NOT change
rtP_Left.z_ctrlTypSel = CTRL_TYP_SEL;
rtP_Left.b_diagEna = DIAG_ENA;
rtP_Left.i_max = (I_MOT_MAX * A2BIT_CONV) << 4; // fixdt(1,16,4)
rtP_Left.n_max = N_MOT_MAX << 4; // fixdt(1,16,4)
rtP_Left.b_fieldWeakEna = FIELD_WEAK_ENA;
rtP_Left.i_max = I_MOT_MAX;
rtP_Left.n_max = N_MOT_MAX;
rtP_Left.id_fieldWeakMax = (FIELD_WEAK_MAX * A2BIT_CONV) << 4; // fixdt(1,16,4)
rtP_Left.a_phaAdvMax = PHASE_ADV_MAX << 4; // fixdt(1,16,4)
rtP_Left.r_fieldWeakHi = FIELD_WEAK_HI << 4; // fixdt(1,16,4)
rtP_Left.r_fieldWeakLo = FIELD_WEAK_LO << 4; // fixdt(1,16,4)
rtP_Right.b_selPhaABCurrMeas = 0; // Left motor measured current phases = {iB, iC} -> do NOT change
rtP_Right.z_ctrlTypSel = CTRL_TYP_SEL;
rtP_Right.b_diagEna = DIAG_ENA;
rtP_Right.i_max = (I_MOT_MAX * A2BIT_CONV) << 4; // fixdt(1,16,4)
rtP_Right.n_max = N_MOT_MAX << 4; // fixdt(1,16,4)
rtP_Right.b_fieldWeakEna = FIELD_WEAK_ENA;
rtP_Right.i_max = I_MOT_MAX;
rtP_Right.n_max = N_MOT_MAX;
rtP_Right.id_fieldWeakMax = (FIELD_WEAK_MAX * A2BIT_CONV) << 4; // fixdt(1,16,4)
rtP_Right.a_phaAdvMax = PHASE_ADV_MAX << 4; // fixdt(1,16,4)
rtP_Right.r_fieldWeakHi = FIELD_WEAK_HI << 4; // fixdt(1,16,4)
rtP_Right.r_fieldWeakLo = FIELD_WEAK_LO << 4; // fixdt(1,16,4)
/* Pack LEFT motor data into RTM */
rtM_Left->defaultParam = &rtP_Left;
@ -282,34 +290,34 @@ int main(void) {
#ifdef CONTROL_NUNCHUCK
Nunchuck_Read();
cmd1 = CLAMP((nunchuck_data[0] - 127) * 8, -1000, 1000); // x - axis. Nunchuck joystick readings range 30 - 230
cmd2 = CLAMP((nunchuck_data[1] - 128) * 8, -1000, 1000); // y - axis
cmd1 = CLAMP((nunchuck_data[0] - 127) * 8, INPUT_MIN, INPUT_MAX); // x - axis. Nunchuck joystick readings range 30 - 230
cmd2 = CLAMP((nunchuck_data[1] - 128) * 8, INPUT_MIN, INPUT_MAX); // y - axis
button1 = (uint8_t)nunchuck_data[5] & 1;
button2 = (uint8_t)(nunchuck_data[5] >> 1) & 1;
#endif
#ifdef CONTROL_PPM
cmd1 = CLAMP((ppm_captured_value[0] - 500) * 2, -1000, 1000);
cmd2 = CLAMP((ppm_captured_value[1] - 500) * 2, -1000, 1000);
button1 = ppm_captured_value[5] > 500;
cmd1 = CLAMP((ppm_captured_value[0] - INPUT_MID) * 2, INPUT_MIN, INPUT_MAX);
cmd2 = CLAMP((ppm_captured_value[1] - INPUT_MID) * 2, INPUT_MIN, INPUT_MAX);
button1 = ppm_captured_value[5] > INPUT_MID;
float scale = ppm_captured_value[2] / 1000.0f;
#endif
#ifdef CONTROL_ADC
// ADC values range: 0-4095, see ADC-calibration in config.h
#ifdef ADC1_MID_POT
cmd1 = CLAMP((adc_buffer.l_tx2 - ADC1_MID) * 1000 / (ADC1_MAX - ADC1_MID), 0, 1000)
-CLAMP((ADC1_MID - adc_buffer.l_tx2) * 1000 / (ADC1_MID - ADC1_MIN), 0, 1000); // ADC1
cmd1 = CLAMP((adc_buffer.l_tx2 - ADC1_MID) * INPUT_MAX / (ADC1_MAX - ADC1_MID), 0, INPUT_MAX)
-CLAMP((ADC1_MID - adc_buffer.l_tx2) * INPUT_MAX / (ADC1_MID - ADC1_MIN), 0, INPUT_MAX); // ADC1
#else
cmd1 = CLAMP((adc_buffer.l_tx2 - ADC1_MIN) * 1000 / (ADC1_MAX - ADC1_MIN), 0, 1000); // ADC1
cmd1 = CLAMP((adc_buffer.l_tx2 - ADC1_MIN) * INPUT_MAX / (ADC1_MAX - ADC1_MIN), 0, INPUT_MAX); // ADC1
#endif
#ifdef ADC2_MID_POT
cmd2 = CLAMP((adc_buffer.l_rx2 - ADC2_MID) * 1000 / (ADC2_MAX - ADC2_MID), 0, 1000)
-CLAMP((ADC2_MID - adc_buffer.l_rx2) * 1000 / (ADC2_MID - ADC2_MIN), 0, 1000); // ADC2
cmd2 = CLAMP((adc_buffer.l_rx2 - ADC2_MID) * INPUT_MAX / (ADC2_MAX - ADC2_MID), 0, INPUT_MAX)
-CLAMP((ADC2_MID - adc_buffer.l_rx2) * INPUT_MAX / (ADC2_MID - ADC2_MIN), 0, INPUT_MAX); // ADC2
#else
cmd2 = CLAMP((adc_buffer.l_rx2 - ADC2_MIN) * 1000 / (ADC2_MAX - ADC2_MIN), 0, 1000); // ADC2
cmd2 = CLAMP((adc_buffer.l_rx2 - ADC2_MIN) * INPUT_MAX / (ADC2_MAX - ADC2_MIN), 0, INPUT_MAX); // ADC2
#endif
// use ADCs as button inputs:
@ -327,8 +335,8 @@ int main(void) {
if (timeoutCnt-- <= 0) // Timeout de-qualification
timeoutFlag = 0; // Timeout flag cleared
} else {
cmd1 = CLAMP((int16_t)command.steer, -1000, 1000);
cmd2 = CLAMP((int16_t)command.speed, -1000, 1000);
cmd1 = CLAMP((int16_t)command.steer, INPUT_MIN, INPUT_MAX);
cmd2 = CLAMP((int16_t)command.speed, INPUT_MIN, INPUT_MAX);
command.start = 0xFFFF; // Change the Start Frame for timeout detection in the next cycle
timeoutCnt = 0; // Reset the timeout counter
}
@ -620,12 +628,12 @@ void mixerFcn(int16_t rtu_speed, int16_t rtu_steer, int16_t *rty_speedR, int16_t
tmp = prodSpeed - prodSteer;
tmp = CLAMP(tmp, -32768, 32767); // Overflow protection
*rty_speedR = (int16_t)(tmp >> 4); // Convert from fixed-point to int
*rty_speedR = CLAMP(*rty_speedR, -1000, 1000);
*rty_speedR = CLAMP(*rty_speedR, INPUT_MIN, INPUT_MAX);
tmp = prodSpeed + prodSteer;
tmp = CLAMP(tmp, -32768, 32767); // Overflow protection
*rty_speedL = (int16_t)(tmp >> 4); // Convert from fixed-point to int
*rty_speedL = CLAMP(*rty_speedL, -1000, 1000);
*rty_speedL = CLAMP(*rty_speedL, INPUT_MIN, INPUT_MAX);
}
// ===========================================================

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB