function mcb_param_est_InitFunc(hostModelName)

%   Copyright 2020 The MathWorks, Inc.

% Motor driver parameters

freqStepTime = 0.6;
assignin('base', 'freqStepTime', freqStepTime);
freqStart = 1000;
assignin('base', 'freqStart', freqStart);
freqChangeStep = -10;
assignin('base', 'freqChangeStep', freqChangeStep);
freqEnd = 10;
assignin('base', 'freqEnd', freqEnd);

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 =  sqrt(2) * str2double(get_param([hostModelName '/Algorithm/SerialSend/I_rated'], 'Value'));
motorParam.ratedSpeed =  str2double(get_param([hostModelName '/Algorithm/SerialSend/speed_rated'], 'Value'));
motorParam.PositionOffset =  str2double(get_param([hostModelName '/Algorithm/SerialSend/Position_Offset'], 'Value'));
motorParam.SensorSelection =  str2double(get_param([hostModelName '/Algorithm/SerialSend/Sensor_Selection'], 'Value'));
motorParam.QEPSlits =  str2double(get_param([hostModelName '/Algorithm/SerialSend/qepSlits'], 'Value'));
%% Inverter Parameters

if str2double(get_param([hostModelName '/boardSelection'], 'Value')) % DRV8305 2nd Option
    inverter.R_board = 0.002+0.007/3;
    % Update ADC Gain for DRV8305
    if motorParam.nomCurrent < 7
        inverter.ADCGain = 4;   % ADC Range = +- 4.825A wrto 0-4095 counts
        inverter.SPI_Gain_Setting = 0x502A;
        
    elseif motorParam.nomCurrent < 10
        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');
        
else % DRV8312 1st Option
    inverter.V_max = 66.3;
    inverter.I_max = 8.65;
    inverter.R_board = 0.080+0.01/3+0.005/3;
    set_param([hostModelName '/Host Serial Setup'],'baudRateA', '5.625e6');
    set_param([hostModelName '/Algorithm/SerialSend/Data_Conditioning_Tx'],'LabelModeActiveChoice','Fixed_Point_Target');
    set_param([hostModelName '/Algorithm/SerialReceive'],'LabelModeActiveChoice','Fixed_Point_Target');

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

if str2double(get_param([hostModelName '/Algorithm/UserInput/BoardSel'], 'Value')) == 0
    CPU_frequency = 90e6; %(Hz);
elseif str2double(get_param([hostModelName '/Algorithm/UserInput/BoardSel'], 'Value')) == 1
    CPU_frequency = 200e6; %(Hz);
end
assignin('base', 'CPU_frequency', CPU_frequency);

%% PWM Settings
PWM_frequency = 20e3; %(Hz);
Ts = 1/PWM_frequency;
assignin('base', 'Ts', Ts);
PWM_Counter_Period = 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.ratedSpeed; %(+/-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);

