|
|
@@ -1,41 +1,14 @@
|
|
|
-
|
|
|
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
-% This file is part of the hoverboard-new-firmware-hack-FOC project
|
|
|
-% Compared to previouse commutation method, this project implements
|
|
|
-% FOC (Field Oriented Control) for BLDC motors with Hall sensors.
|
|
|
-% 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-2021 Emanuel FERU <aerdronix@gmail.com>
|
|
|
-%
|
|
|
-% 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 <http://www.gnu.org/licenses/>.
|
|
|
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
-
|
|
|
% Clear workspace
|
|
|
close all
|
|
|
clear
|
|
|
clc
|
|
|
|
|
|
% Load model parameters
|
|
|
-Ts = 5e-6; % [s] Model sampling time (1 MHz)
|
|
|
-f_ctrl = 20e3; % [Hz] Controller frequency = 1/Ts_ctrl (16 kHz)
|
|
|
-Ts_ctrl = 1/f_ctrl; % [s] Controller sampling time (~16 kHz)
|
|
|
-speed_ctrl = 20; %delay for f_ctrl
|
|
|
+Ts = 5e-6; % [s] Model sampling time (200 KHz)
|
|
|
+f_ctrl = 20e3; % [Hz] Controller frequency = 1/Ts_ctrl (20 kHz)
|
|
|
+Ts_ctrl = 1/f_ctrl; % [s] Controller sampling time (50us)
|
|
|
+f_speed_ctrl = 1e3; % [Hz] Speed/torque Controller frequency = (1 kHz)
|
|
|
+speed_ctrl = f_ctrl/f_speed_ctrl; % [count] Delay for f_speed_ctrl of the FOC controller
|
|
|
i_pwm_count = f_ctrl/4;
|
|
|
i_dead = 10;
|
|
|
i_adc = 10;
|
|
|
@@ -45,15 +18,7 @@ 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
|
|
|
+%Current sample hw parameters
|
|
|
n_adc_max = 4096;
|
|
|
n_resistance = 0.0005;
|
|
|
n_ref_vol = 3.3;
|
|
|
@@ -63,8 +28,9 @@ n_gain = 17.1;
|
|
|
|
|
|
b_start_with_commutation = 0;
|
|
|
% Sine/Cosine wave look-up table
|
|
|
-res_elecAngle = 1;
|
|
|
+res_elecAngle = 0.25;
|
|
|
a_elecAngle_XA = 0:res_elecAngle:360; % [deg] Electrical angle grid
|
|
|
+a_elecAngle_XA = fixpt_evenspace_cleanup(a_elecAngle_XA, sfix(16), 2^-3); % Make sure the data is evely spaced up to the last bit
|
|
|
r_sin_M1 = sin((a_elecAngle_XA)*(pi/180));
|
|
|
r_cos_M1 = cos((a_elecAngle_XA)*(pi/180));
|
|
|
|
|
|
@@ -72,11 +38,8 @@ r_cos_M1 = cos((a_elecAngle_XA)*(pi/180));
|
|
|
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 = 10;
|
|
|
min_openVol = 10;
|
|
|
-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
|