Pārlūkot izejas kodu

add close loop for speed & current

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 4 gadi atpakaļ
vecāks
revīzija
ca2e400d52

BIN
Simulink/MotorController_FOC.slx


BIN
Simulink/MotorController_FOC.slx.autosave


BIN
Simulink/MotorController_FOC.slxc


BIN
Simulink/foc_libs.slx


+ 20 - 7
Simulink/init_model.m

@@ -39,14 +39,22 @@ i_pwm_count         = 4000;
 i_dead              = 10;
 i_adc               = 10;
 i_sample_before     = 10;
-i_Udc               = 560;
+i_Udc               = 300;
 i_half_pwm_count    = i_pwm_count;
 i_sample_min        = (i_dead + i_adc + i_sample_before);
 i_hall_count_max    = 1/Ts;
 
+% Motor Paramaters
+Rs = 0.0918;
+Ld = 0.0009262;
+Lq = 0.001024;
+band_current = 3.14 * 2 * 4000;
+% Kp = 0.0009262 * 3.14 * 8000 = 26
+% Ki = 0.0918/0.0009262 = 99.11
+% Kserial = 99.11 / 0.5816 = 170.42
 % Current sample parameters
 n_adc_max = 4096;
-n_resistance = 0.005;
+n_resistance = 0.0005;
 n_ref_vol = 3.3;
 n_gain    = 17.1;
 
@@ -59,6 +67,14 @@ a_elecAngle_XA      = 0:res_elecAngle:360;          % [deg] Electrical angle gri
 r_sin_M1            = sin((a_elecAngle_XA)*(pi/180));  
 r_cos_M1            = cos((a_elecAngle_XA)*(pi/180));
 
+% Speed limitations
+n_max               = 5000;             % [rpm] Maximum motor speed: [-5000, 5000]
+
+% open loop speed -> voltage lookup table
+res_rpm_openloop     = 100;
+delta_rpm_openloop = 100; % delta rpm that when speed decreased, enter open loop
+min_start_voltage_openloop = 50;
+a_rpm_step = i_Udc / (n_max / res_rpm_openloop);
 % Motor parameters
 n_polePairs         = 4;                           % [-] Number of motor pole pairs
 a_elecPeriod        = 360;                          % [deg] Electrical angle period
@@ -115,14 +131,11 @@ cf_KbLimProt        = 1000 / (f_ctrl/3);% [-] Back calculation gain for integral
 
 % Voltage Limitations
 V_margin            = 0.95;              % [-] Voltage margin to make sure that there is a sufficiently wide pulse for a good phase current measurement
-Vd_max              = 560 * V_margin;
+Vd_max              = i_Udc * V_margin;
 Vq_max_XA           = 0:1:Vd_max;
 Vq_max_M1           = sqrt(Vd_max^2 - Vq_max_XA.^2);  % Circle limitations look-up table
 
-
-% Speed limitations
-n_max               = 1000;             % [rpm] Maximum motor speed: [-1500, 1500]
-i_sca               = 20;                           % [-] [not tunable] Scalling factor A to int16 (50 = 1/0.02)
+i_sca               = 1;                           % [-] [not tunable] Scalling factor A to int16 (50 = 1/0.02)
 % Current Limitations
 i_max               = 100;               % [A] Maximum allowed motor current (continuous)
 i_max               = i_max * i_sca;