version = 4.2

//
// Saved by sw version: 2025.1 RC22
//

model "model" {
    configuration {
        hil_device = "HIL604"
        hil_configuration_id = 1
        simulation_method = exact
        simulation_time_step = auto
        simulation_discret_scaling = 1.0
        dsp_timer_periods = 100e-6, 50e-3
        ss_calc_method = "systematic elimination"
        enb_pole_shift = True
        enb_gds_oversampling = True
        show_modes = False
        device_ao_limit_enable = False
        reset_analog_outputs_on_sim_stop = True
        reset_analog_outputs_on_sim_stop_mode = Offset values
        reset_digital_outputs_on_sim_stop = True
        vhil_adio_loopback = False
        cpl_stb = True
        enb_dep_sw_detect = False
        code_section = "internal memory"
        data_section = "internal memory"
        sys_sp_rate_1 = 0.0001
        sys_sp_rate_2 = 0.05
        sys_real_type_precision = "default"
        user_real_type_precision = "default"
        sys_cpu_optimization = "high"
        user_cpu_optimization = "high"
        user_cpu_part_option = "default"
        matrix_based_reduction = True
        cpl_dynamics_analysis = False
        export_ss_to_pickle = False
        ground_scope_core = False
        dss_num_tol = 1e-15
        cce_platform = "generic"
        cce_use_relative_names = False
        cce_type_mapping_real = "double"
        cce_type_mapping_uint = "unsigned int"
        cce_type_mapping_int = "int"
        cce_platform = "generic"
        cce_use_relative_names = False
        cce_type_mapping_real = "double"
        cce_type_mapping_uint = "unsigned int"
        cce_type_mapping_int = "int"
        cce_term_var_location = "local"
        cce_directory = ""
        cce_custom_type_int = ""
        cce_custom_type_uint = ""
        cce_custom_type_real = ""
        tunable_params = "component defined"
        sp_compiler_type = "C compiler"
        sig_stim = "off"
        export_resource_list = ""
        export_dependency_list = ""
        excluded_resource_list = ""
        excluded_component_from_locking_list = ""
        export_out_file = ""
        export_lock_top_level = True
        export_encrypt_library = True
        export_encrypt_resources = True
        solver_type = "DAE"
        integration_method = "BDF"
        max_sim_step = 1e-4
        simulation_time = 1.0
        abs_tol = 1e-3
        rel_tol = 1e-3
        init_sim_step = 1e-6
        r_on_sw = 1e-3
        v_on_diode = 0.2
        data_sampling_rate = 0
        feedthrough_validation_error_level = error
    }

    component Subsystem Root {
        component "core/C function" "Square Wave Source" {
            arb_defs = "/*Begin code section*/

/*End code section*/"
            global_variables = "real frequency_var;real duty_cycle_var;real phase_var;real angle_var;real angle_phase_var;real MIN_FREQUENCY;real MIN_DUTY_CYCLE;real MAX_DUTY_CYCLE;real MIN_PHASE;real MAX_PHASE;"
            init_fnc = "/*Begin code section*/
// Define max and min values of inputs
MIN_FREQUENCY = 0.000001;
MIN_DUTY_CYCLE = 0;
MAX_DUTY_CYCLE = 1;
MIN_PHASE = 0;
MAX_PHASE = 1;

//Initialize angle variable
angle_var = 0;
/*End code section*/"
            input_terminals = "real hs_output;inherit ls_output;inherit frequency;inherit duty_cycle;inherit phase;"
            input_terminals_dimensions = "inherit;inherit;inherit;inherit;inherit"
            input_terminals_feedthrough = "True;True;True;True;True"
            input_terminals_show_labels = "True;True;True;True;True"
            output_fnc = "/*Begin code section*/
// Limit inputs to min and max values
if (frequency < MIN_FREQUENCY)
    frequency_var = MIN_FREQUENCY;
else    
    frequency_var = frequency;
if (duty_cycle < MIN_DUTY_CYCLE)
    duty_cycle_var = MIN_DUTY_CYCLE;
else if (duty_cycle > MAX_DUTY_CYCLE)
    duty_cycle_var = MAX_DUTY_CYCLE;
else
    duty_cycle_var = duty_cycle;
if (phase < MIN_PHASE)
    phase_var = MIN_PHASE;
else if (phase > MAX_PHASE)
    phase_var = MAX_PHASE;
else 
    phase_var = phase; 

// Offset angle variable by phase input
angle_phase_var = angle_var + phase_var;

// Keep angle between 0 and 1
if (angle_phase_var > 1.0)
{
    angle_var -=1;
    angle_phase_var -=1;
}
// Define output as high-state or low-state
if (angle_phase_var > duty_cycle_var)
    out = ls_output;
else 
    out = hs_output;

// Increase angle variable by elapsed time
angle_var += execution_rate*frequency_var;
/*End code section*/"
            output_terminals_dimensions = "inherit"
            output_terminals_feedthrough = "True"
            output_terminals_show_labels = "False"
            update_fnc = "/*Begin code section*/

/*End code section*/"
        }
        [
            position = 5720, 8640
            size = 104, 272
        ]

        component "core/SCADA Input" hs_output {
            def_value = "1"
            execution_rate = "Ts"
            unit = ""
        }
        [
            position = 5524, 8528
        ]

        component "core/Probe" "Library component" {
        }
        [
            position = 5732, 8840
        ]

        component "core/SCADA Input" ls_output {
            execution_rate = "Ts"
            unit = ""
        }
        [
            position = 5524, 8584
        ]

        component "core/SCADA Input" frequency {
            def_value = "50"
            execution_rate = "Ts"
            max = "10e3"
            min = "0.000001"
            unit = ""
        }
        [
            position = 5524, 8640
        ]

        component "core/SCADA Input" duty_cycle {
            def_value = "0.5"
            execution_rate = "Ts"
            max = "1"
            min = "0"
            unit = ""
        }
        [
            position = 5524, 8696
        ]

        component "core/SCADA Input" phase {
            execution_rate = "Ts"
            max = "1"
            min = "0"
            unit = ""
        }
        [
            position = 5524, 8752
        ]

        component "core/Square Wave Source" "Square Wave Source1" {
            _tunable = "True"
        }
        [
            position = 5524, 8840
        ]

        component "core/Probe" "C function" {
        }
        [
            position = 5844, 8640
        ]

        connect hs_output.out "Square Wave Source.hs_output" as Connection2
        connect ls_output.out "Square Wave Source.ls_output" as Connection3
        connect frequency.out "Square Wave Source.frequency" as Connection4
        connect duty_cycle.out "Square Wave Source.duty_cycle" as Connection5
        connect "Square Wave Source.phase" phase.out as Connection6
        connect "Square Wave Source1.out" "Library component.in" as Connection7
        connect "C function.in" "Square Wave Source.out" as Connection8
    }

    default {
        "core/C function" {
            input_terminals = "real in;"
            input_terminals_show_labels = "False;"
            input_terminals_feedthrough = "True;"
            input_terminals_dimensions = "inherit;"
            output_terminals = "real out;"
            output_terminals_show_labels = "False;"
            output_terminals_feedthrough = "True;"
            output_terminals_dimensions = "inherit;"
            output_fnc = ""
            update_fnc = ""
            init_fnc = ""
            global_variables = ""
            parameters = ""
            library_load_type = "Compile-time load"
            dll_file_path = ""
            dll_file_path_full = ""
            arm_a9_file_path = ""
            arm_a9_file_path_full = ""
            arm_a53_file_path = ""
            arm_a53_file_path_full = ""
            h_file_path = ""
            h_file_path_full = ""
            add_src_path = ""
            add_src_path_full = ""
            convert_to_relative_dll = "True"
            convert_to_relative_a = "True"
            convert_to_relative_src = "True"
            arb_defs = ""
            add_macros = ""
            skip_pre_cmpl_check = "False"
            generate_for_hil = "True"
            execution_rate = "inherit"
            _supported_platforms = "[\'generic\']"
            refresh = "refresh"
        }

        "core/Probe" {
            signal_access = "inherit"
            addr = "0"
            override_signal_name = "False"
            signal_name = ""
            signal_type = "generic"
            streaming_en = "False"
            streaming_er_idx = "0"
            execution_rate = "inherit"
        }

        "core/SCADA Input" {
            signal_access = "inherit"
            addr = "0"
            format = "real"
            override_signal_name = "False"
            signal_name = ""
            signal_type = "real"
            min = "-1e6"
            max = "1e6"
            def_value = "0"
            unit = " "
            execution_rate = "100e-6"
        }

        "core/Square Wave Source" {
            hs_output = "1"
            ls_output = "0"
            frequency = "50"
            duty_cycle = "0.5"
            phase = "0"
            signal_type = "real"
            execution_rate = "100e-6"
            _tunable = "False"
        }
    }

    CODE model_init
        # Numpy module is imported as 'np'
        # Scipy module is imported as 'sp'
        # The Schematic API is imported as 'mdl'
        # To get the model file path, use 'mdl.get_model_file_path()'
        # To print information to the console, use info()
        
        Ts = 100e-6
    ENDCODE
}
