%%%%%%%%%%%%%%%%%%%% Parametros de entrada %%%%%%%%%%%%%%%%%%%%%%%%%
Potencia = 486.21;           % Potencia del motor
T_max = 2.451;               % Par maximo del motor
Vnom = 135.8;                % Tension nominal rms
Vdc = 340;                   % Tension DC

Rs = 0.3398;                 % Resistencia de fase
Ld = 0.6154e-3;              % d axis inductance (H)
Lq = 1.094e-3;               % q axis inductance (H)
Phi_r = 46.6027e-3;          % Estimated rotor magnetic flux (Wb)

clock = 25000;               % Reloj del sistema
delay_velocidad = 200;

fc_corrientes = 1e3;         % Frecuendia corte filtros corriente (Hz)

p = 3;                       % Pares de Polos
CPR = 300;                   % Precision del encoder

desfase_z_d = -0.9425;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Calculos %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
time_step = 1/clock;
f_triangular = clock/10;                    % Frecuencia onda triangular

cte_encoder = 2*pi/CPR;
Vmax = Vdc/sqrt(2)/sqrt(3);                 % Max phase voltage (V) (sinusoidal PWM generation)
wb = Vmax/Phi_r;                            % per unit speed (pu)

k = Ld/Lq;
kp_id = Rs/(k*Lq);                          % d current PI proportional gain
kp_iq = Rs/(Lq);                            % q current PI proportional gain
ki_id=(Rs/(k*Lq)+wb/k*kp_id)^2/(4*wb/k);    % d current PI integral gain
ki_iq=(Rs/(Lq)+wb*kp_iq)^2/(4*wb);          % q current PI integral gain

nmax = 0.98 * clock/2 * 60 / CPR;
gain_velocidad = clock/delay_velocidad * 60/(2*pi);


n_lim_direccion = nmax/10;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%