% Clear workspace
close all
clear
clc

% Load model parameters
Ts                  = 5e-7;                         % [s] Model sampling time (200 KHz)
Ts_ctrl             = 6e-5;                     % [s] Controller sampling time (50us)5e-5
f_speed_ctrl        = 500;                          % [Hz] Speed/torque Controller frequency = (500 Hz)
Ts_Spd_ctl          = 1/f_speed_ctrl;
PWM_Cnt             = 6000;
PWM_Half_Cnt        = PWM_Cnt/2;
DeatTime = 0.6e-6;
DT_PWM_CNT = PWM_Cnt/(Ts_ctrl)*DeatTime;
Torque_Mode = 1;
Speed_Mode = 2;
Ctrl_Mode = Torque_Mode;
%Simulink provider Motor parameters
n_polePairs  = 4;        % [-] Number of motor pole pairs
PM           = 0.013;   % Permanent magnet flux linkage, 
Ld           = 0.07e-3;% d-axis inductance, 
Lq           = 0.178e-3; % q-axis inductance,
Rs           = 0.011;   % Stator resistance,
J            = 0.03945; % Moment of inertia,
bandwith     = 800*2*pi;
i_Udc        = 96;      % DCbus max voltage
lamda1 = -0.000001;
lamda2 = -0.1;
A=[-Rs/Ld 0 -1/Ld 0;0 -Rs/Ld 0 -1/Ld;0 0 0 -200;0 0 200 0];
B=[1/Ld 0; 0 1/Ld;0 0 ;0 0];
C=[1 0 0 0;0 1 0 0];
D=[0 0 0 0;0 0 0 0];
G=place(A', C', [-10 -8 -4 -1])';