Uploaded by dohogap393

% TI F28379D BLDC Motor Control Cod

advertisement
% TI F28379D BLDC Motor Control Code
% Define the pins for the Hall sensors
ha_pin = 78;
hb_pin = 79;
hc_pin = 80;
% Define the pins for the motor phases
A_high = 1;
A_low = 2;
B_high = 3;
B_low = 4;
C_high = 5;
C_low = 6;
% Define the commutation sequence
comm_seq = [5 4; 1 2; 5 6; 3 2; 3 4; 1 6];
% Define the number of commutation steps
num_steps = 6;
% Define the timer period (in seconds) for each commutation step
% This is calculated based on the motor RPM and number of steps
timer_period = 60 / (num_steps * 32 * (3000 / 60));
% Initialize the GPIO pins
gpio = gpio_init();
gpio_setup(gpio, ha_pin, 'in');
gpio_setup(gpio, hb_pin, 'in');
gpio_setup(gpio, hc_pin, 'in');
gpio_setup(gpio, A_high, 'out');
gpio_setup(gpio, A_low, 'out');
gpio_setup(gpio, B_high, 'out');
gpio_setup(gpio, B_low, 'out');
gpio_setup(gpio, C_high, 'out');
gpio_setup(gpio, C_low, 'out');
% Set the initial commutation step
step = 1;
% Set the initial state of the Hall sensors
Ha = gpio_read(gpio, ha_pin);
Hb = gpio_read(gpio, hb_pin);
Hc = gpio_read(gpio, hc_pin);
% Define the timer for each commutation step
t = timer('TimerFcn', @(~,~) commutate(step, gpio, comm_seq), 'Period', timer_period, 'ExecutionMode', 'fixedRate');
% Start the timer
start(t);
% Define the commutation function
function commutate(step, gpio, comm_seq)
% Read the Hall sensor states
Ha = gpio_read(gpio, 78);
Hb = gpio_read(gpio, 79);
Hc = gpio_read(gpio, 80);
% Determine the current commutation state based on the Hall sensor states
if (Ha == 0 && Hb == 0 && Hc == 1)
Hstate = 1;
elseif (Ha ==
Download