function mcb_acim_param_est_InitFunc(hostModelName)
% mcb_acim_param_est_InitFunc Initialization function for parameter estimation

% Copyright 2021 The MathWorks, Inc.

% Motor and driver parameters

RsMeasTestTime = str2double(get_param([hostModelName '/Algorithm/SerialSend/RsMeasTestTime'], 'Value'));
simTime = RsMeasTestTime + 25;
motorParam.v_dc = str2double(get_param([hostModelName '/Algorithm/SerialSend/V_bus'], 'Value'));
motorParam.p = str2double(get_param([hostModelName '/Algorithm/SerialSend/pole_pairs'], 'Value'));
motorParam.nomCurrent =  str2double(get_param([hostModelName '/Algorithm/SerialSend/I_rated'], 'Value'));
motorParam.ratedFrequency = str2double(get_param([hostModelName '/Algorithm/SerialSend/Rated_Frequency'], 'Value'));
motorParam.QEPSlits =  str2double(get_param([hostModelName '/Algorithm/SerialSend/qepSlits'], 'Value'));
motorParam.Id0 =  str2double(get_param([hostModelName '/Algorithm/SerialSend/Magnetizing_Current'], 'Value'));
motorParam.baseSpeed = 60*motorParam.ratedFrequency/motorParam.p;  
set_param([hostModelName '/Algorithm/SerialSend/speed_base'],'Value', num2str(motorParam.baseSpeed));

%% Variables for param est algorithm
% stator resisatnce DC test
algoVar.dcTestVoltLevel_1 = single(eval(get_param([bdroot '/Algorithm/Parameters/Dc Test Voltage Level1'], 'Value')));
algoVar.dcTestVoltLevel_2 = single(eval(get_param([bdroot '/Algorithm/Parameters/Dc Test Voltage Level2'], 'Value')));
% Scale of overCuurent and underVolatge for fault detection. 
% scale*rated is consider for fault detection. 
algoVar.scaleOverCur = single(eval(get_param([bdroot '/Algorithm/Parameters/Scale Over Current'], 'Value')));
algoVar.scaleUnderVolt = single(eval(get_param([bdroot '/Algorithm/Parameters/Scale Under Voltage'], 'Value')));

assignin('base', 'algoVar', algoVar);

%% Inverter Parameters
% Details for other board are avaiable for future support. 
  % LaunchXL-F28379D + DRV8305 Option
inverter.R_board = 0.002+0.007/3;
% Update ADC Gain for DRV8305
if motorParam.nomCurrent < 5
    inverter.ADCGain = 4;   % ADC Range = +- 4.825A wrto 0-4095 counts
    inverter.SPI_Gain_Setting = 0x502A;

elseif motorParam.nomCurrent < 7
    inverter.ADCGain = 2;   % ADC Range = +- 9.650A wrto 0-4095 counts
    inverter.SPI_Gain_Setting = 0x5015;

else
    inverter.ADCGain = 1;   % ADC Range = +- 19.300A wrto 0-4095 counts
    inverter.SPI_Gain_Setting = 0x5000;        
end
inverter.I_max = 19.2857*(2048/1842.8)/inverter.ADCGain;
inverter.V_max = 44.3*(3/3.3);
set_param([hostModelName '/Host Serial Setup'],'baudRateA', '12e6');
set_param([hostModelName '/Algorithm/SerialSend/Data_Conditioning_Tx'],'LabelModeActiveChoice','Floating_Point_Target');
set_param([hostModelName '/Algorithm/SerialReceive'],'LabelModeActiveChoice','Floating_Point_Target');


assignin('base', 'inverter', inverter); 
assignin('base', 'simTime', simTime);
assignin('base', 'motorParam', motorParam);


CPU_frequency = 200e6; %(Hz);

assignin('base', 'CPU_frequency', CPU_frequency);

%% PWM Settings


PWM_frequency = 20e3; %(Hz);    % Sample time for f28379D


Ts = 1/PWM_frequency;
assignin('base', 'Ts', Ts);
PWM_Counter_Period = round(CPU_frequency/PWM_frequency/2); %(PWM timer counts);
assignin('base', 'PWM_Counter_Period', PWM_Counter_Period);

% Speed Per Unit Scaler
Speed_per_unit_scaler = motorParam.baseSpeed; %(+/-1200rpm <=> +/-1 in Q format)
assignin('base', 'Speed_per_unit_scaler', Speed_per_unit_scaler);

%% Controller design
sigma   = evalin('base', get_param([hostModelName '/Algorithm/SerialSend/Overall_Delay'], 'Value'));            % TIC2000   //  Estimated practical delay between duty update and feedback update
assignin('base', 'sigma',sigma);

