From a6023bbdcb9e97013ce8477f14e6654a6c04080b Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Wed, 15 Jan 2025 13:39:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D1=82=D0=B8=D1=82=D1=8C=2023550?= =?UTF-8?q?=5Fon=5Fship.=20=D1=82=D0=B0=D0=BA=D0=B0=D1=8F=20=D0=B6=D0=B5?= =?UTF-8?q?=20=D1=84=D0=B8=D0=B3=D0=BD=D1=8F,=20=D1=88=D0=B8=D0=BC=20?= =?UTF-8?q?=D0=BA=D1=80=D0=B0=D1=81=D0=B8=D0=B2=D1=8B=D0=B9=20=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inu/Src/N12_Libs/CAN_Setup.c | 480 +-- Inu/Src/N12_Libs/CAN_Setup.h | 83 +- Inu/Src/N12_Libs/RS_modbus_pultl.c | 16 +- Inu/Src/N12_Libs/build_version.c | 7 - Inu/Src/N12_Libs/build_version.h | 4 - Inu/Src/N12_Libs/control_station.c | 13 +- Inu/Src/N12_Libs/control_station.h | 9 +- Inu/Src/N12_Libs/filter_v1.c | 3 - Inu/Src/N12_Libs/filter_v1.h | 3 + Inu/Src/N12_Libs/global_time.c | 67 +- Inu/Src/N12_Libs/global_time.h | 10 - Inu/Src/N12_Libs/math_pi.h | 17 +- Inu/Src/N12_Libs/mathlib.c | 136 +- Inu/Src/N12_Libs/mathlib.h | 17 +- Inu/Src/N12_Libs/modbus_table_v2.c | 11 +- Inu/Src/N12_Libs/modbus_table_v2.h | 1 - Inu/Src/N12_Libs/uf_alg_ing.c | 23 +- Inu/Src/N12_VectorControl/alg_pll.c | 30 +- Inu/Src/N12_VectorControl/alg_pll.h | 14 +- Inu/Src/N12_VectorControl/teta_calc.c | 7 +- Inu/Src/N12_VectorControl/vector_control.c | 7 +- Inu/Src/N12_VectorControl/vector_control.h | 12 +- Inu/Src/N12_Xilinx/RS_Function_terminal.h | 95 - Inu/Src/N12_Xilinx/RS_Functions.c | 515 +-- Inu/Src/N12_Xilinx/RS_Functions.h | 5 +- Inu/Src/N12_Xilinx/Spartan2E_Functions.c | 26 - Inu/Src/N12_Xilinx/Spartan2E_Functions.h | 3 - Inu/Src/N12_Xilinx/TuneUpPlane.c | 12 +- Inu/Src/N12_Xilinx/x_int13.c | 61 +- Inu/Src/N12_Xilinx/x_parallel_bus.h | 1 - Inu/Src/N12_Xilinx/xp_cds_in.c | 138 +- Inu/Src/N12_Xilinx/xp_cds_tk_23550.c | 51 +- Inu/Src/N12_Xilinx/xp_cds_tk_23550.h | 37 +- Inu/Src/N12_Xilinx/xp_hwp.c | 13 +- Inu/Src/N12_Xilinx/xp_inc_sensor.c | 131 +- Inu/Src/N12_Xilinx/xp_inc_sensor.h | 21 +- Inu/Src/N12_Xilinx/xp_project.c | 23 +- Inu/Src/N12_Xilinx/xp_rotation_sensor.c | 267 ++ Inu/Src/N12_Xilinx/xp_rotation_sensor.h | 346 ++ Inu/Src/N12_Xilinx/xp_write_xpwm_time.h | 6 +- Inu/Src/main/281xEvTimersInit.c | 51 +- Inu/Src/main/CAN_project.h | 11 +- Inu/Src/main/Main.c | 6 +- Inu/Src/main/PWMTools.c | 1902 +++++---- Inu/Src/main/PWMTools.h | 12 +- Inu/Src/main/adc_tools.c | 620 +-- Inu/Src/main/adc_tools.h | 45 +- Inu/Src/main/alg_simple_scalar.c | 488 +-- Inu/Src/main/alg_simple_scalar.h | 38 +- Inu/Src/main/break_regul.c | 22 +- Inu/Src/main/calc_tempers.c | 17 - Inu/Src/main/can_bs2bs.c | 10 +- Inu/Src/main/can_bs2bs.h | 2 +- Inu/Src/main/control_station_project.c | 672 +-- Inu/Src/main/control_station_project.h | 3 +- Inu/Src/main/detect_error_3_phase.c | 2 +- Inu/Src/main/detect_error_3_phase.h | 2 +- Inu/Src/main/detect_errors.c | 244 +- Inu/Src/main/detect_errors.h | 62 +- Inu/Src/main/detect_errors_adc.c | 41 +- Inu/Src/main/detect_errors_adc.h | 3 +- Inu/Src/main/detect_overload.c | 50 +- Inu/Src/main/edrk_main.c | 3703 +++++++++++------ Inu/Src/main/edrk_main.h | 504 +-- .../main/not_use => Src/main}/log_to_mem.c | 26 +- .../main/not_use => Src/main}/log_to_mem.h | 138 +- Inu/Src/main/master_slave.h | 13 - Inu/Src/main/message2.c | 370 +- Inu/Src/main/message2test.c | 229 +- Inu/Src/main/message_modbus.c | 222 +- Inu/Src/main/message_modbus.h | 8 +- Inu/Src/main/modbus_hmi.c | 227 +- Inu/Src/main/modbus_hmi.h | 30 +- Inu/Src/main/modbus_hmi_read.c | 46 +- Inu/Src/main/modbus_hmi_update.c | 911 +--- Inu/Src/main/modbus_hmi_update.h | 15 - Inu/Src/main/modbus_svu_update.c | 125 +- Inu/Src/main/optical_bus.c | 19 +- Inu/Src/main/optical_bus.h | 4 +- Inu/Src/main/overheat_limit.c | 19 +- Inu/Src/main/params.h | 25 +- Inu/Src/main/params_alg.h | 208 +- Inu/Src/main/params_bsu.h | 39 +- Inu/Src/main/params_hwp.h | 9 +- Inu/Src/main/params_motor.h | 8 +- Inu/Src/main/params_norma.h | 61 +- Inu/Src/main/params_protect_adc.h | 20 +- Inu/Src/main/params_pwm24.h | 9 +- Inu/Src/main/params_temper_p.h | 19 +- Inu/Src/main/project.c | 235 +- Inu/Src/main/project_setup.h | 15 +- Inu/Src/main/protect_levels.h | 2 +- Inu/Src/main/pump_control.c | 20 +- Inu/Src/main/pwm_test_lines.c | 10 +- Inu/Src/main/sbor_shema.c | 566 +-- Inu/Src/main/sbor_shema.h | 9 - Inu/Src/main/sync_tools.c | 260 +- Inu/Src/main/sync_tools.h | 12 +- Inu/Src/main/tk_Test.c | 101 +- Inu/Src/main/tk_Test.h | 3 +- Inu/Src/main/v_pwm24_v2.c | 331 +- Inu/Src/main/v_pwm24_v2.h | 16 +- Inu/Src/main/v_rotor.c | 1825 ++++---- Inu/Src/main/v_rotor.h | 98 +- Inu/Src/main/vector.h | 10 +- .../.vscode/c_cpp_properties.json | 0 Inu/Src2/551/main/PWMTools.c | 2438 ----------- Inu/Src2/551/main/PWMTools.h | 54 - Inu/Src2/551/main/adc_tools.c | 1412 ------- Inu/Src2/551/main/adc_tools.h | 402 -- Inu/Src2/551/main/alarm_log.c | 196 - Inu/Src2/551/main/alarm_log.h | 16 - Inu/Src2/551/main/another_bs.c | 458 -- Inu/Src2/551/main/another_bs.h | 21 - Inu/Src2/551/main/can_protocol_ukss.h | 63 - Inu/Src2/551/main/digital_filters.c | 103 - Inu/Src2/551/main/digital_filters.h | 19 - Inu/Src2/551/main/limit_lib.c | 50 - Inu/Src2/551/main/limit_lib.h | 15 - Inu/Src2/551/main/limit_power.c | 237 -- Inu/Src2/551/main/limit_power.h | 21 - Inu/Src2/551/main/logs_hmi.c | 1150 ----- Inu/Src2/551/main/logs_hmi.h | 86 - Inu/Src2/551/main/master_slave.c | 586 --- Inu/Src2/551/main/optical_bus_tools.c | 791 ---- Inu/Src2/551/main/optical_bus_tools.h | 14 - Inu/Src2/551/main/params.h | 182 - Inu/Src2/551/main/pll_tools.c | 105 - Inu/Src2/551/main/pll_tools.h | 22 - Inu/Src2/551/main/pwm_logs.c | 476 --- Inu/Src2/551/main/pwm_logs.h | 16 - Inu/Src2/551/main/ramp_zadanie_tools.c | 417 -- Inu/Src2/551/main/ramp_zadanie_tools.h | 20 - Inu/Src2/551/main/sim_model.c | 222 - Inu/Src2/551/main/sim_model.h | 21 - Inu/Src2/551/main/synhro_tools.c | 144 - Inu/Src2/551/main/synhro_tools.h | 19 - Inu/Src2/551/main/temper_p_tools.c | 77 - Inu/Src2/551/main/temper_p_tools.h | 22 - Inu/Src2/551/main/ukss_tools.c | 605 --- Inu/Src2/551/main/ukss_tools.h | 33 - Inu/Src2/551/main/uom_tools.c | 149 - Inu/Src2/551/main/uom_tools.h | 15 - Inu/Src2/551/main/v_rotor_22220.c | 666 --- Inu/Src2/551/main/v_rotor_22220.h | 54 - Inu/Src2/551/main/vector.h | 254 -- Inu/Src2/N12_Libs/CAN_Setup.c | 2201 ++++++++++ Inu/Src2/N12_Libs/CAN_Setup.h | 751 ++++ Inu/Src2/N12_Libs/RS_modbus_pult.h | 31 + Inu/Src2/N12_Libs/RS_modbus_pultl.c | 1013 +++++ Inu/Src2/N12_Libs/alarm_log_can.c | 543 +++ Inu/Src2/N12_Libs/alarm_log_can.h | 135 + Inu/Src2/N12_Libs/big_dsp_module.c | 26 + Inu/Src2/N12_Libs/big_dsp_module.h | 19 + Inu/Src2/N12_Libs/build_version.c | 24 + Inu/Src2/N12_Libs/build_version.h | 30 + Inu/Src2/N12_Libs/control_station.c | 194 + Inu/Src2/N12_Libs/control_station.h | 134 + Inu/Src2/N12_Libs/filter_v1.c | 367 ++ .../my_filter.h => N12_Libs/filter_v1.h} | 5 +- Inu/Src2/N12_Libs/global_time.c | 149 + Inu/Src2/N12_Libs/global_time.h | 58 + .../N12_Libs/iq_values_norma_f.h | 0 .../N12_Libs/iq_values_norma_iu.h | 0 .../N12_Libs/iq_values_norma_oborot.h | 0 Inu/{Src => Src2}/N12_Libs/log_params.c | 0 Inu/{Src => Src2}/N12_Libs/log_params.h | 0 Inu/{Src => Src2}/N12_Libs/log_to_memory.c | 0 Inu/{Src => Src2}/N12_Libs/log_to_memory.h | 0 Inu/Src2/N12_Libs/math_pi.h | 50 + Inu/Src2/N12_Libs/mathlib.c | 437 ++ Inu/Src2/N12_Libs/mathlib.h | 81 + Inu/Src2/N12_Libs/modbus_table_v2.c | 89 + Inu/Src2/N12_Libs/modbus_table_v2.h | 42 + .../N12_Libs/not_use/IQmathLib.h | 0 .../N12_Libs/not_use/adaptive_filters.c | 0 .../N12_Libs/not_use/pi_adaptive.c | 0 Inu/Src2/N12_Libs/options_table.c | 37 + Inu/Src2/N12_Libs/options_table.h | 17 + Inu/Src2/N12_Libs/oscil_can.c | 293 ++ Inu/Src2/N12_Libs/oscil_can.h | 103 + Inu/Src2/N12_Libs/params_protect.h | 63 + Inu/Src2/{main => N12_Libs}/pid_reg3.c | 47 +- Inu/Src2/{main => N12_Libs}/pid_reg3.h | 21 +- Inu/Src2/N12_Libs/rmp_cntl_v1.c | 51 + Inu/Src2/N12_Libs/rmp_cntl_v1.h | 48 + Inu/{Src => Src2}/N12_Libs/rmp_cntl_v2.c | 0 Inu/{Src => Src2}/N12_Libs/rmp_cntl_v2.h | 0 Inu/Src2/{main => N12_Libs}/svgen_dq.h | 0 Inu/Src2/{main => N12_Libs}/svgen_dq_v2.c | 34 +- Inu/Src2/N12_Libs/svgen_mf.c | 164 + Inu/Src2/N12_Libs/svgen_mf.h | 46 + Inu/Src2/N12_Libs/uf_alg_ing.c | 736 ++++ Inu/Src2/N12_Libs/uf_alg_ing.h | 93 + Inu/Src2/N12_Libs/vhzprof.c | 45 + Inu/Src2/N12_Libs/vhzprof.h | 41 + Inu/Src2/{main => N12_Libs}/word_structurs.h | 6 +- .../abc_to_alphabeta.c | 0 .../abc_to_alphabeta.h | 0 .../abc_to_dq.c | 0 .../abc_to_dq.h | 0 .../alg_pll.c | 0 .../alg_pll.h | 0 .../alphabeta_to_dq.c | 0 .../alphabeta_to_dq.h | 0 .../dq_to_alphabeta_cos.c | 0 .../dq_to_alphabeta_cos.h | 0 .../params_pll.h | 0 .../regul_power.c | 0 .../regul_power.h | 0 .../regul_turns.c | 0 .../regul_turns.h | 0 .../smooth.c | 0 .../smooth.h | 0 .../teta_calc.c | 0 .../teta_calc.h | 0 .../vector_control.c | 0 .../vector_control.h | 0 Inu/Src2/N12_Xilinx/CRC_Functions.c | 143 + Inu/Src2/N12_Xilinx/CRC_Functions.h | 12 + Inu/Src2/N12_Xilinx/MemoryFunctions.c | 325 ++ Inu/Src2/N12_Xilinx/MemoryFunctions.h | 36 + Inu/Src2/N12_Xilinx/RS_Function_terminal.c | 98 + Inu/Src2/N12_Xilinx/RS_Function_terminal.h | 605 +++ Inu/Src2/N12_Xilinx/RS_Functions.c | 2639 ++++++++++++ Inu/Src2/N12_Xilinx/RS_Functions.h | 142 + Inu/Src2/N12_Xilinx/RS_modbus_svu.c | 328 ++ Inu/Src2/N12_Xilinx/RS_modbus_svu.h | 27 + Inu/Src2/N12_Xilinx/Spartan2E_Adr.h | 90 + Inu/Src2/N12_Xilinx/Spartan2E_Functions.c | 896 ++++ Inu/Src2/N12_Xilinx/Spartan2E_Functions.h | 264 ++ Inu/Src2/N12_Xilinx/TuneUpPlane.c | 340 ++ Inu/Src2/N12_Xilinx/TuneUpPlane.h | 38 + Inu/Src2/N12_Xilinx/modbus_struct.h | 39 + .../N12_Xilinx/not_use/xp_rotation_sensor.c | 0 .../N12_Xilinx/not_use/xp_rotation_sensor.h | 0 .../N12_Xilinx/profile_interrupt.c | 0 .../N12_Xilinx/profile_interrupt.h | 0 Inu/Src2/N12_Xilinx/xHWP.c | 11 + Inu/Src2/N12_Xilinx/xHWP.h | 6 + Inu/Src2/N12_Xilinx/xPeriphSP6_loader.c | 561 +++ Inu/Src2/N12_Xilinx/xPeriphSP6_loader.h | 133 + Inu/Src2/N12_Xilinx/x_basic_types.h | 111 + Inu/Src2/N12_Xilinx/x_int13.c | 218 + Inu/Src2/N12_Xilinx/x_int13.h | 36 + Inu/Src2/N12_Xilinx/x_parallel_bus.c | 238 ++ Inu/Src2/N12_Xilinx/x_parallel_bus.h | 127 + Inu/Src2/N12_Xilinx/x_project_useit.h | 7 + Inu/Src2/N12_Xilinx/x_serial_bus.c | 319 ++ Inu/Src2/N12_Xilinx/x_serial_bus.h | 87 + Inu/Src2/N12_Xilinx/x_wdog.c | 23 + Inu/Src2/N12_Xilinx/x_wdog.h | 18 + Inu/Src2/N12_Xilinx/xerror.c | 428 ++ Inu/Src2/N12_Xilinx/xerror.h | 66 + Inu/Src2/N12_Xilinx/xp_adc.c | 643 +++ Inu/Src2/N12_Xilinx/xp_adc.h | 267 ++ Inu/Src2/N12_Xilinx/xp_cds_in.c | 440 ++ Inu/Src2/N12_Xilinx/xp_cds_in.h | 517 +++ Inu/Src2/N12_Xilinx/xp_cds_out.c | 310 ++ Inu/Src2/N12_Xilinx/xp_cds_out.h | 286 ++ Inu/Src2/N12_Xilinx/xp_cds_rs.c | 399 ++ Inu/Src2/N12_Xilinx/xp_cds_rs.h | 182 + Inu/Src2/N12_Xilinx/xp_cds_status_bus.c | 217 + Inu/Src2/N12_Xilinx/xp_cds_status_bus.h | 95 + Inu/Src2/N12_Xilinx/xp_cds_tk.c | 196 + Inu/Src2/N12_Xilinx/xp_cds_tk.h | 114 + Inu/Src2/N12_Xilinx/xp_cds_tk_10510.c | 280 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_10510.h | 460 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_21180.c | 280 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_21180.h | 459 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_21300.c | 280 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_21300.h | 460 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_22220.c | 302 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_22220.h | 539 +++ Inu/Src2/N12_Xilinx/xp_cds_tk_23470.c | 280 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_23470.h | 459 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_23550.c | 560 +++ Inu/Src2/N12_Xilinx/xp_cds_tk_23550.h | 616 +++ Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.c | 236 ++ Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.h | 403 ++ Inu/Src2/N12_Xilinx/xp_controller.c | 58 + Inu/Src2/N12_Xilinx/xp_controller.h | 144 + Inu/Src2/N12_Xilinx/xp_hwp.c | 1419 +++++++ Inu/Src2/N12_Xilinx/xp_hwp.h | 445 ++ Inu/Src2/N12_Xilinx/xp_id_plate_info.h | 71 + Inu/Src2/N12_Xilinx/xp_inc_sensor.c | 396 ++ Inu/Src2/N12_Xilinx/xp_inc_sensor.h | 137 + Inu/Src2/N12_Xilinx/xp_incremental_sensors.c | 235 ++ Inu/Src2/N12_Xilinx/xp_incremental_sensors.h | 531 +++ Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.c | 98 + Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.h | 110 + Inu/Src2/N12_Xilinx/xp_plane_adr.h | 175 + Inu/Src2/N12_Xilinx/xp_project.c | 1986 +++++++++ Inu/Src2/N12_Xilinx/xp_project.h | 462 ++ Inu/Src2/N12_Xilinx/xp_tools.c | 41 + Inu/Src2/N12_Xilinx/xp_tools.h | 16 + Inu/Src2/N12_Xilinx/xp_write_xpwm_time.c | 671 +++ .../{main => N12_Xilinx}/xp_write_xpwm_time.h | 135 +- Inu/Src2/VectorControl/abc_to_alphabeta.c | 23 - Inu/Src2/VectorControl/abc_to_alphabeta.h | 39 - Inu/Src2/VectorControl/abc_to_dq.c | 38 - Inu/Src2/VectorControl/abc_to_dq.h | 42 - Inu/Src2/VectorControl/alphabeta_to_abc.c | 24 - Inu/Src2/VectorControl/alphabeta_to_abc.h | 38 - Inu/Src2/VectorControl/alphabeta_to_dq.c | 22 - Inu/Src2/VectorControl/alphabeta_to_dq.h | 32 - Inu/Src2/VectorControl/dq_to_alphabeta_cos.c | 39 - Inu/Src2/VectorControl/dq_to_alphabeta_cos.h | 40 - .../VectorControl/efficiency_compensation.c | 107 - .../VectorControl/efficiency_compensation.h | 13 - Inu/Src2/VectorControl/params_motor.h | 23 - Inu/Src2/VectorControl/pwm_vector_regul.c | 666 --- Inu/Src2/VectorControl/pwm_vector_regul.h | 81 - Inu/Src2/VectorControl/regul_power.c | 269 -- Inu/Src2/VectorControl/regul_power.h | 32 - Inu/Src2/VectorControl/regul_turns.c | 185 - Inu/Src2/VectorControl/regul_turns.h | 12 - Inu/Src2/VectorControl/teta_calc.c | 262 -- Inu/Src2/VectorControl/teta_calc.h | 39 - Inu/Src2/{551 => }/main/281xEvTimersInit.c | 0 Inu/Src2/{551 => }/main/281xEvTimersInit.h | 0 Inu/Src2/{551 => }/main/CAN_project.h | 0 Inu/Src2/main/IQmathLib.c | 182 - Inu/Src2/main/IQmathLib.h | 661 --- Inu/Src2/{551 => }/main/Main.c | 0 Inu/Src2/{551 => }/main/PWMTMSHandle.c | 0 Inu/Src2/{551 => }/main/PWMTMSHandle.h | 0 Inu/Src2/main/PWMTools.c | 3007 ++++++++++--- Inu/Src2/main/PWMTools.h | 51 +- Inu/Src2/{551 => }/main/adc_internal.h | 0 Inu/Src2/main/adc_tools.c | 1754 ++++++-- Inu/Src2/main/adc_tools.h | 471 ++- Inu/{Src => Src2}/main/alarm_log.c | 0 Inu/{Src => Src2}/main/alarm_log.h | 0 Inu/Src2/{551 => }/main/alg_simple_scalar.c | 0 Inu/Src2/{551 => }/main/alg_simple_scalar.h | 0 Inu/Src2/{551 => }/main/alg_uf_const.c | 0 Inu/Src2/{551 => }/main/alg_uf_const.h | 0 Inu/{Src => Src2}/main/another_bs.c | 0 Inu/{Src => Src2}/main/another_bs.h | 0 Inu/Src2/{551 => }/main/break_regul.c | 0 Inu/Src2/{551 => }/main/break_regul.h | 0 Inu/Src2/{551 => }/main/calc_rms_vals.c | 0 Inu/Src2/{551 => }/main/calc_rms_vals.h | 0 Inu/Src2/{551 => }/main/calc_tempers.c | 0 Inu/Src2/{551 => }/main/calc_tempers.h | 0 Inu/Src2/{551 => }/main/can_bs2bs.c | 0 Inu/Src2/{551 => }/main/can_bs2bs.h | 0 Inu/{Src => Src2}/main/can_protocol_ukss.h | 0 .../{551 => }/main/control_station_project.c | 0 .../{551 => }/main/control_station_project.h | 0 .../{551 => }/main/detect_error_3_phase.c | 0 .../{551 => }/main/detect_error_3_phase.h | 0 Inu/Src2/{551 => }/main/detect_errors.c | 0 Inu/Src2/{551 => }/main/detect_errors.h | 0 Inu/Src2/{551 => }/main/detect_errors_adc.c | 0 Inu/Src2/{551 => }/main/detect_errors_adc.h | 0 Inu/Src2/{551 => }/main/detect_overload.c | 0 Inu/Src2/{551 => }/main/detect_overload.h | 0 Inu/Src2/{551 => }/main/detect_phase_break.c | 0 Inu/Src2/{551 => }/main/detect_phase_break.h | 0 Inu/Src2/{551 => }/main/detect_phase_break2.c | 0 Inu/Src2/{551 => }/main/detect_phase_break2.h | 0 Inu/{Src => Src2}/main/digital_filters.c | 0 Inu/{Src => Src2}/main/digital_filters.h | 0 Inu/Src2/main/dmctype.h | 31 - Inu/Src2/{551 => }/main/edrk_main.c | 0 Inu/Src2/{551 => }/main/edrk_main.h | 0 Inu/Src2/{551 => }/main/f281xbmsk.h | 0 Inu/Src2/{551 => }/main/f281xpwm.c | 0 Inu/Src2/{551 => }/main/f281xpwm.h | 0 Inu/{Src => Src2}/main/limit_lib.c | 0 Inu/{Src => Src2}/main/limit_lib.h | 0 Inu/{Src => Src2}/main/limit_power.c | 0 Inu/{Src => Src2}/main/limit_power.h | 0 Inu/{Src => Src2}/main/logs_hmi.c | 0 Inu/{Src => Src2}/main/logs_hmi.h | 0 Inu/Src2/{551 => }/main/manch.h | 0 Inu/{Src => Src2}/main/master_slave.c | 0 Inu/Src2/{551 => }/main/master_slave.h | 0 Inu/Src2/{551 => }/main/message2.c | 0 Inu/Src2/{551 => }/main/message2.h | 0 Inu/Src2/{551 => }/main/message2can.c | 0 Inu/Src2/{551 => }/main/message2can.h | 0 Inu/Src2/{551 => }/main/message2test.c | 0 Inu/Src2/{551 => }/main/message2test.h | 0 Inu/Src2/{551 => }/main/message_modbus.c | 0 Inu/Src2/{551 => }/main/message_modbus.h | 0 .../{551 => }/main/message_terminals_can.c | 0 .../{551 => }/main/message_terminals_can.h | 0 Inu/Src2/{551 => }/main/modbus_hmi.c | 0 Inu/Src2/{551 => }/main/modbus_hmi.h | 0 Inu/Src2/{551 => }/main/modbus_hmi_read.c | 0 Inu/Src2/{551 => }/main/modbus_hmi_read.h | 0 Inu/Src2/{551 => }/main/modbus_hmi_update.c | 0 Inu/Src2/{551 => }/main/modbus_hmi_update.h | 0 Inu/Src2/{551 => }/main/modbus_svu_update.c | 0 Inu/Src2/{551 => }/main/modbus_svu_update.h | 0 Inu/Src2/main/my_filter.c | 122 - Inu/{Src => Src2}/main/not_use/log_to_mem.c | 0 Inu/{Src => Src2}/main/not_use/log_to_mem.h | 0 Inu/Src2/{551 => }/main/optical_bus.c | 0 Inu/Src2/{551 => }/main/optical_bus.h | 0 Inu/{Src => Src2}/main/optical_bus_tools.c | 0 Inu/{Src => Src2}/main/optical_bus_tools.h | 0 Inu/Src2/{551 => }/main/overheat_limit.c | 0 Inu/Src2/{551 => }/main/overheat_limit.h | 0 Inu/Src2/main/params.h | 275 +- Inu/Src2/{551 => }/main/params_alg.h | 0 Inu/Src2/{551 => }/main/params_bsu.h | 0 Inu/Src2/{551 => }/main/params_hwp.h | 0 Inu/Src2/{551 => }/main/params_motor.h | 0 Inu/Src2/{551 => }/main/params_norma.h | 0 Inu/Src2/{551 => }/main/params_protect_adc.h | 0 Inu/Src2/{551 => }/main/params_pwm24.h | 0 Inu/Src2/{551 => }/main/params_temper_p.h | 0 Inu/{Src => Src2}/main/pll_tools.c | 0 Inu/{Src => Src2}/main/pll_tools.h | 0 Inu/Src2/{551 => }/main/project.c | 0 Inu/Src2/{551 => }/main/project.h | 0 Inu/Src2/{551 => }/main/project_setup.h | 0 Inu/Src2/{551 => }/main/protect_levels.h | 0 Inu/Src2/{551 => }/main/pump_control.c | 0 Inu/Src2/{551 => }/main/pump_control.h | 0 Inu/{Src => Src2}/main/pwm_logs.c | 0 Inu/{Src => Src2}/main/pwm_logs.h | 0 Inu/Src2/{551 => }/main/pwm_test_lines.c | 0 Inu/Src2/{551 => }/main/pwm_test_lines.h | 0 Inu/{Src => Src2}/main/ramp_zadanie_tools.c | 0 Inu/{Src => Src2}/main/ramp_zadanie_tools.h | 0 Inu/Src2/main/rotation_speed.h | 44 - Inu/Src2/{551 => }/main/sbor_shema.c | 0 Inu/Src2/{551 => }/main/sbor_shema.h | 0 Inu/{Src => Src2}/main/sim_model.c | 0 Inu/{Src => Src2}/main/sim_model.h | 0 Inu/Src2/{551 => }/main/sync_tools.c | 0 Inu/Src2/{551 => }/main/sync_tools.h | 0 Inu/{Src => Src2}/main/synhro_tools.c | 0 Inu/{Src => Src2}/main/synhro_tools.h | 0 Inu/{Src => Src2}/main/temper_p_tools.c | 0 Inu/{Src => Src2}/main/temper_p_tools.h | 0 Inu/Src2/{551 => }/main/tk_Test.c | 0 Inu/Src2/{551 => }/main/tk_Test.h | 0 Inu/{Src => Src2}/main/ukss_tools.c | 0 Inu/{Src => Src2}/main/ukss_tools.h | 0 Inu/{Src => Src2}/main/uom_tools.c | 0 Inu/{Src => Src2}/main/uom_tools.h | 0 Inu/Src2/main/v_pwm24.c | 1635 -------- Inu/Src2/main/v_pwm24.h | 190 - Inu/Src2/{551 => }/main/v_pwm24_v2.c | 0 Inu/Src2/{551 => }/main/v_pwm24_v2.h | 2 +- Inu/Src2/{551 => }/main/v_rotor.c | 2196 +++++----- Inu/Src2/{551 => }/main/v_rotor.h | 0 Inu/{Src => Src2}/main/v_rotor_22220.c | 0 Inu/{Src => Src2}/main/v_rotor_22220.h | 0 Inu/Src2/main/vector.h | 184 +- Inu/Src2/{551 => }/main/xPlatesAddress.h | 0 Inu/Src2/main/xp_write_xpwm_time.c | 361 -- Inu/def.h | 2 +- Inu/main_matlab/init28335.c | 328 +- Inu/main_matlab/main_matlab.c | 10 +- Inu/main_matlab/param.c | 6 +- Inu/mcu_app_includes.h | 3 +- allmex.m | 19 +- run_mex.bat | 8 +- 465 files changed, 45973 insertions(+), 29835 deletions(-) create mode 100644 Inu/Src/N12_Xilinx/xp_rotation_sensor.c create mode 100644 Inu/Src/N12_Xilinx/xp_rotation_sensor.h rename Inu/{Src2/551/main/not_use => Src/main}/log_to_mem.c (92%) rename Inu/{Src2/551/main/not_use => Src/main}/log_to_mem.h (51%) rename Inu/{Src => Src2}/.vscode/c_cpp_properties.json (100%) delete mode 100644 Inu/Src2/551/main/PWMTools.c delete mode 100644 Inu/Src2/551/main/PWMTools.h delete mode 100644 Inu/Src2/551/main/adc_tools.c delete mode 100644 Inu/Src2/551/main/adc_tools.h delete mode 100644 Inu/Src2/551/main/alarm_log.c delete mode 100644 Inu/Src2/551/main/alarm_log.h delete mode 100644 Inu/Src2/551/main/another_bs.c delete mode 100644 Inu/Src2/551/main/another_bs.h delete mode 100644 Inu/Src2/551/main/can_protocol_ukss.h delete mode 100644 Inu/Src2/551/main/digital_filters.c delete mode 100644 Inu/Src2/551/main/digital_filters.h delete mode 100644 Inu/Src2/551/main/limit_lib.c delete mode 100644 Inu/Src2/551/main/limit_lib.h delete mode 100644 Inu/Src2/551/main/limit_power.c delete mode 100644 Inu/Src2/551/main/limit_power.h delete mode 100644 Inu/Src2/551/main/logs_hmi.c delete mode 100644 Inu/Src2/551/main/logs_hmi.h delete mode 100644 Inu/Src2/551/main/master_slave.c delete mode 100644 Inu/Src2/551/main/optical_bus_tools.c delete mode 100644 Inu/Src2/551/main/optical_bus_tools.h delete mode 100644 Inu/Src2/551/main/params.h delete mode 100644 Inu/Src2/551/main/pll_tools.c delete mode 100644 Inu/Src2/551/main/pll_tools.h delete mode 100644 Inu/Src2/551/main/pwm_logs.c delete mode 100644 Inu/Src2/551/main/pwm_logs.h delete mode 100644 Inu/Src2/551/main/ramp_zadanie_tools.c delete mode 100644 Inu/Src2/551/main/ramp_zadanie_tools.h delete mode 100644 Inu/Src2/551/main/sim_model.c delete mode 100644 Inu/Src2/551/main/sim_model.h delete mode 100644 Inu/Src2/551/main/synhro_tools.c delete mode 100644 Inu/Src2/551/main/synhro_tools.h delete mode 100644 Inu/Src2/551/main/temper_p_tools.c delete mode 100644 Inu/Src2/551/main/temper_p_tools.h delete mode 100644 Inu/Src2/551/main/ukss_tools.c delete mode 100644 Inu/Src2/551/main/ukss_tools.h delete mode 100644 Inu/Src2/551/main/uom_tools.c delete mode 100644 Inu/Src2/551/main/uom_tools.h delete mode 100644 Inu/Src2/551/main/v_rotor_22220.c delete mode 100644 Inu/Src2/551/main/v_rotor_22220.h delete mode 100644 Inu/Src2/551/main/vector.h create mode 100644 Inu/Src2/N12_Libs/CAN_Setup.c create mode 100644 Inu/Src2/N12_Libs/CAN_Setup.h create mode 100644 Inu/Src2/N12_Libs/RS_modbus_pult.h create mode 100644 Inu/Src2/N12_Libs/RS_modbus_pultl.c create mode 100644 Inu/Src2/N12_Libs/alarm_log_can.c create mode 100644 Inu/Src2/N12_Libs/alarm_log_can.h create mode 100644 Inu/Src2/N12_Libs/big_dsp_module.c create mode 100644 Inu/Src2/N12_Libs/big_dsp_module.h create mode 100644 Inu/Src2/N12_Libs/build_version.c create mode 100644 Inu/Src2/N12_Libs/build_version.h create mode 100644 Inu/Src2/N12_Libs/control_station.c create mode 100644 Inu/Src2/N12_Libs/control_station.h create mode 100644 Inu/Src2/N12_Libs/filter_v1.c rename Inu/Src2/{main/my_filter.h => N12_Libs/filter_v1.h} (89%) create mode 100644 Inu/Src2/N12_Libs/global_time.c create mode 100644 Inu/Src2/N12_Libs/global_time.h rename Inu/{Src => Src2}/N12_Libs/iq_values_norma_f.h (100%) rename Inu/{Src => Src2}/N12_Libs/iq_values_norma_iu.h (100%) rename Inu/{Src => Src2}/N12_Libs/iq_values_norma_oborot.h (100%) rename Inu/{Src => Src2}/N12_Libs/log_params.c (100%) rename Inu/{Src => Src2}/N12_Libs/log_params.h (100%) rename Inu/{Src => Src2}/N12_Libs/log_to_memory.c (100%) rename Inu/{Src => Src2}/N12_Libs/log_to_memory.h (100%) create mode 100644 Inu/Src2/N12_Libs/math_pi.h create mode 100644 Inu/Src2/N12_Libs/mathlib.c create mode 100644 Inu/Src2/N12_Libs/mathlib.h create mode 100644 Inu/Src2/N12_Libs/modbus_table_v2.c create mode 100644 Inu/Src2/N12_Libs/modbus_table_v2.h rename Inu/{Src => Src2}/N12_Libs/not_use/IQmathLib.h (100%) rename Inu/{Src => Src2}/N12_Libs/not_use/adaptive_filters.c (100%) rename Inu/{Src => Src2}/N12_Libs/not_use/pi_adaptive.c (100%) create mode 100644 Inu/Src2/N12_Libs/options_table.c create mode 100644 Inu/Src2/N12_Libs/options_table.h create mode 100644 Inu/Src2/N12_Libs/oscil_can.c create mode 100644 Inu/Src2/N12_Libs/oscil_can.h create mode 100644 Inu/Src2/N12_Libs/params_protect.h rename Inu/Src2/{main => N12_Libs}/pid_reg3.c (60%) rename Inu/Src2/{main => N12_Libs}/pid_reg3.h (80%) create mode 100644 Inu/Src2/N12_Libs/rmp_cntl_v1.c create mode 100644 Inu/Src2/N12_Libs/rmp_cntl_v1.h rename Inu/{Src => Src2}/N12_Libs/rmp_cntl_v2.c (100%) rename Inu/{Src => Src2}/N12_Libs/rmp_cntl_v2.h (100%) rename Inu/Src2/{main => N12_Libs}/svgen_dq.h (100%) rename Inu/Src2/{main => N12_Libs}/svgen_dq_v2.c (82%) create mode 100644 Inu/Src2/N12_Libs/svgen_mf.c create mode 100644 Inu/Src2/N12_Libs/svgen_mf.h create mode 100644 Inu/Src2/N12_Libs/uf_alg_ing.c create mode 100644 Inu/Src2/N12_Libs/uf_alg_ing.h create mode 100644 Inu/Src2/N12_Libs/vhzprof.c create mode 100644 Inu/Src2/N12_Libs/vhzprof.h rename Inu/Src2/{main => N12_Libs}/word_structurs.h (93%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/abc_to_alphabeta.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/abc_to_alphabeta.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/abc_to_dq.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/abc_to_dq.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/alg_pll.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/alg_pll.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/alphabeta_to_dq.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/alphabeta_to_dq.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/dq_to_alphabeta_cos.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/dq_to_alphabeta_cos.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/params_pll.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/regul_power.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/regul_power.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/regul_turns.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/regul_turns.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/smooth.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/smooth.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/teta_calc.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/teta_calc.h (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/vector_control.c (100%) rename Inu/Src2/{551/VectorControl => N12_VectorControl}/vector_control.h (100%) create mode 100644 Inu/Src2/N12_Xilinx/CRC_Functions.c create mode 100644 Inu/Src2/N12_Xilinx/CRC_Functions.h create mode 100644 Inu/Src2/N12_Xilinx/MemoryFunctions.c create mode 100644 Inu/Src2/N12_Xilinx/MemoryFunctions.h create mode 100644 Inu/Src2/N12_Xilinx/RS_Function_terminal.c create mode 100644 Inu/Src2/N12_Xilinx/RS_Function_terminal.h create mode 100644 Inu/Src2/N12_Xilinx/RS_Functions.c create mode 100644 Inu/Src2/N12_Xilinx/RS_Functions.h create mode 100644 Inu/Src2/N12_Xilinx/RS_modbus_svu.c create mode 100644 Inu/Src2/N12_Xilinx/RS_modbus_svu.h create mode 100644 Inu/Src2/N12_Xilinx/Spartan2E_Adr.h create mode 100644 Inu/Src2/N12_Xilinx/Spartan2E_Functions.c create mode 100644 Inu/Src2/N12_Xilinx/Spartan2E_Functions.h create mode 100644 Inu/Src2/N12_Xilinx/TuneUpPlane.c create mode 100644 Inu/Src2/N12_Xilinx/TuneUpPlane.h create mode 100644 Inu/Src2/N12_Xilinx/modbus_struct.h rename Inu/{Src => Src2}/N12_Xilinx/not_use/xp_rotation_sensor.c (100%) rename Inu/{Src => Src2}/N12_Xilinx/not_use/xp_rotation_sensor.h (100%) rename Inu/{Src => Src2}/N12_Xilinx/profile_interrupt.c (100%) rename Inu/{Src => Src2}/N12_Xilinx/profile_interrupt.h (100%) create mode 100644 Inu/Src2/N12_Xilinx/xHWP.c create mode 100644 Inu/Src2/N12_Xilinx/xHWP.h create mode 100644 Inu/Src2/N12_Xilinx/xPeriphSP6_loader.c create mode 100644 Inu/Src2/N12_Xilinx/xPeriphSP6_loader.h create mode 100644 Inu/Src2/N12_Xilinx/x_basic_types.h create mode 100644 Inu/Src2/N12_Xilinx/x_int13.c create mode 100644 Inu/Src2/N12_Xilinx/x_int13.h create mode 100644 Inu/Src2/N12_Xilinx/x_parallel_bus.c create mode 100644 Inu/Src2/N12_Xilinx/x_parallel_bus.h create mode 100644 Inu/Src2/N12_Xilinx/x_project_useit.h create mode 100644 Inu/Src2/N12_Xilinx/x_serial_bus.c create mode 100644 Inu/Src2/N12_Xilinx/x_serial_bus.h create mode 100644 Inu/Src2/N12_Xilinx/x_wdog.c create mode 100644 Inu/Src2/N12_Xilinx/x_wdog.h create mode 100644 Inu/Src2/N12_Xilinx/xerror.c create mode 100644 Inu/Src2/N12_Xilinx/xerror.h create mode 100644 Inu/Src2/N12_Xilinx/xp_adc.c create mode 100644 Inu/Src2/N12_Xilinx/xp_adc.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_in.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_in.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_out.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_out.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_rs.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_rs.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_status_bus.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_status_bus.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_10510.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_10510.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_21180.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_21180.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_21300.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_21300.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_22220.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_22220.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_23470.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_23470.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_23550.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_23550.h create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.c create mode 100644 Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.h create mode 100644 Inu/Src2/N12_Xilinx/xp_controller.c create mode 100644 Inu/Src2/N12_Xilinx/xp_controller.h create mode 100644 Inu/Src2/N12_Xilinx/xp_hwp.c create mode 100644 Inu/Src2/N12_Xilinx/xp_hwp.h create mode 100644 Inu/Src2/N12_Xilinx/xp_id_plate_info.h create mode 100644 Inu/Src2/N12_Xilinx/xp_inc_sensor.c create mode 100644 Inu/Src2/N12_Xilinx/xp_inc_sensor.h create mode 100644 Inu/Src2/N12_Xilinx/xp_incremental_sensors.c create mode 100644 Inu/Src2/N12_Xilinx/xp_incremental_sensors.h create mode 100644 Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.c create mode 100644 Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.h create mode 100644 Inu/Src2/N12_Xilinx/xp_plane_adr.h create mode 100644 Inu/Src2/N12_Xilinx/xp_project.c create mode 100644 Inu/Src2/N12_Xilinx/xp_project.h create mode 100644 Inu/Src2/N12_Xilinx/xp_tools.c create mode 100644 Inu/Src2/N12_Xilinx/xp_tools.h create mode 100644 Inu/Src2/N12_Xilinx/xp_write_xpwm_time.c rename Inu/Src2/{main => N12_Xilinx}/xp_write_xpwm_time.h (55%) delete mode 100644 Inu/Src2/VectorControl/abc_to_alphabeta.c delete mode 100644 Inu/Src2/VectorControl/abc_to_alphabeta.h delete mode 100644 Inu/Src2/VectorControl/abc_to_dq.c delete mode 100644 Inu/Src2/VectorControl/abc_to_dq.h delete mode 100644 Inu/Src2/VectorControl/alphabeta_to_abc.c delete mode 100644 Inu/Src2/VectorControl/alphabeta_to_abc.h delete mode 100644 Inu/Src2/VectorControl/alphabeta_to_dq.c delete mode 100644 Inu/Src2/VectorControl/alphabeta_to_dq.h delete mode 100644 Inu/Src2/VectorControl/dq_to_alphabeta_cos.c delete mode 100644 Inu/Src2/VectorControl/dq_to_alphabeta_cos.h delete mode 100644 Inu/Src2/VectorControl/efficiency_compensation.c delete mode 100644 Inu/Src2/VectorControl/efficiency_compensation.h delete mode 100644 Inu/Src2/VectorControl/params_motor.h delete mode 100644 Inu/Src2/VectorControl/pwm_vector_regul.c delete mode 100644 Inu/Src2/VectorControl/pwm_vector_regul.h delete mode 100644 Inu/Src2/VectorControl/regul_power.c delete mode 100644 Inu/Src2/VectorControl/regul_power.h delete mode 100644 Inu/Src2/VectorControl/regul_turns.c delete mode 100644 Inu/Src2/VectorControl/regul_turns.h delete mode 100644 Inu/Src2/VectorControl/teta_calc.c delete mode 100644 Inu/Src2/VectorControl/teta_calc.h rename Inu/Src2/{551 => }/main/281xEvTimersInit.c (100%) rename Inu/Src2/{551 => }/main/281xEvTimersInit.h (100%) rename Inu/Src2/{551 => }/main/CAN_project.h (100%) delete mode 100644 Inu/Src2/main/IQmathLib.c delete mode 100644 Inu/Src2/main/IQmathLib.h rename Inu/Src2/{551 => }/main/Main.c (100%) rename Inu/Src2/{551 => }/main/PWMTMSHandle.c (100%) rename Inu/Src2/{551 => }/main/PWMTMSHandle.h (100%) rename Inu/Src2/{551 => }/main/adc_internal.h (100%) rename Inu/{Src => Src2}/main/alarm_log.c (100%) rename Inu/{Src => Src2}/main/alarm_log.h (100%) rename Inu/Src2/{551 => }/main/alg_simple_scalar.c (100%) rename Inu/Src2/{551 => }/main/alg_simple_scalar.h (100%) rename Inu/Src2/{551 => }/main/alg_uf_const.c (100%) rename Inu/Src2/{551 => }/main/alg_uf_const.h (100%) rename Inu/{Src => Src2}/main/another_bs.c (100%) rename Inu/{Src => Src2}/main/another_bs.h (100%) rename Inu/Src2/{551 => }/main/break_regul.c (100%) rename Inu/Src2/{551 => }/main/break_regul.h (100%) rename Inu/Src2/{551 => }/main/calc_rms_vals.c (100%) rename Inu/Src2/{551 => }/main/calc_rms_vals.h (100%) rename Inu/Src2/{551 => }/main/calc_tempers.c (100%) rename Inu/Src2/{551 => }/main/calc_tempers.h (100%) rename Inu/Src2/{551 => }/main/can_bs2bs.c (100%) rename Inu/Src2/{551 => }/main/can_bs2bs.h (100%) rename Inu/{Src => Src2}/main/can_protocol_ukss.h (100%) rename Inu/Src2/{551 => }/main/control_station_project.c (100%) rename Inu/Src2/{551 => }/main/control_station_project.h (100%) rename Inu/Src2/{551 => }/main/detect_error_3_phase.c (100%) rename Inu/Src2/{551 => }/main/detect_error_3_phase.h (100%) rename Inu/Src2/{551 => }/main/detect_errors.c (100%) rename Inu/Src2/{551 => }/main/detect_errors.h (100%) rename Inu/Src2/{551 => }/main/detect_errors_adc.c (100%) rename Inu/Src2/{551 => }/main/detect_errors_adc.h (100%) rename Inu/Src2/{551 => }/main/detect_overload.c (100%) rename Inu/Src2/{551 => }/main/detect_overload.h (100%) rename Inu/Src2/{551 => }/main/detect_phase_break.c (100%) rename Inu/Src2/{551 => }/main/detect_phase_break.h (100%) rename Inu/Src2/{551 => }/main/detect_phase_break2.c (100%) rename Inu/Src2/{551 => }/main/detect_phase_break2.h (100%) rename Inu/{Src => Src2}/main/digital_filters.c (100%) rename Inu/{Src => Src2}/main/digital_filters.h (100%) delete mode 100644 Inu/Src2/main/dmctype.h rename Inu/Src2/{551 => }/main/edrk_main.c (100%) rename Inu/Src2/{551 => }/main/edrk_main.h (100%) rename Inu/Src2/{551 => }/main/f281xbmsk.h (100%) rename Inu/Src2/{551 => }/main/f281xpwm.c (100%) rename Inu/Src2/{551 => }/main/f281xpwm.h (100%) rename Inu/{Src => Src2}/main/limit_lib.c (100%) rename Inu/{Src => Src2}/main/limit_lib.h (100%) rename Inu/{Src => Src2}/main/limit_power.c (100%) rename Inu/{Src => Src2}/main/limit_power.h (100%) rename Inu/{Src => Src2}/main/logs_hmi.c (100%) rename Inu/{Src => Src2}/main/logs_hmi.h (100%) rename Inu/Src2/{551 => }/main/manch.h (100%) rename Inu/{Src => Src2}/main/master_slave.c (100%) rename Inu/Src2/{551 => }/main/master_slave.h (100%) rename Inu/Src2/{551 => }/main/message2.c (100%) rename Inu/Src2/{551 => }/main/message2.h (100%) rename Inu/Src2/{551 => }/main/message2can.c (100%) rename Inu/Src2/{551 => }/main/message2can.h (100%) rename Inu/Src2/{551 => }/main/message2test.c (100%) rename Inu/Src2/{551 => }/main/message2test.h (100%) rename Inu/Src2/{551 => }/main/message_modbus.c (100%) rename Inu/Src2/{551 => }/main/message_modbus.h (100%) rename Inu/Src2/{551 => }/main/message_terminals_can.c (100%) rename Inu/Src2/{551 => }/main/message_terminals_can.h (100%) rename Inu/Src2/{551 => }/main/modbus_hmi.c (100%) rename Inu/Src2/{551 => }/main/modbus_hmi.h (100%) rename Inu/Src2/{551 => }/main/modbus_hmi_read.c (100%) rename Inu/Src2/{551 => }/main/modbus_hmi_read.h (100%) rename Inu/Src2/{551 => }/main/modbus_hmi_update.c (100%) rename Inu/Src2/{551 => }/main/modbus_hmi_update.h (100%) rename Inu/Src2/{551 => }/main/modbus_svu_update.c (100%) rename Inu/Src2/{551 => }/main/modbus_svu_update.h (100%) delete mode 100644 Inu/Src2/main/my_filter.c rename Inu/{Src => Src2}/main/not_use/log_to_mem.c (100%) rename Inu/{Src => Src2}/main/not_use/log_to_mem.h (100%) rename Inu/Src2/{551 => }/main/optical_bus.c (100%) rename Inu/Src2/{551 => }/main/optical_bus.h (100%) rename Inu/{Src => Src2}/main/optical_bus_tools.c (100%) rename Inu/{Src => Src2}/main/optical_bus_tools.h (100%) rename Inu/Src2/{551 => }/main/overheat_limit.c (100%) rename Inu/Src2/{551 => }/main/overheat_limit.h (100%) rename Inu/Src2/{551 => }/main/params_alg.h (100%) rename Inu/Src2/{551 => }/main/params_bsu.h (100%) rename Inu/Src2/{551 => }/main/params_hwp.h (100%) rename Inu/Src2/{551 => }/main/params_motor.h (100%) rename Inu/Src2/{551 => }/main/params_norma.h (100%) rename Inu/Src2/{551 => }/main/params_protect_adc.h (100%) rename Inu/Src2/{551 => }/main/params_pwm24.h (100%) rename Inu/Src2/{551 => }/main/params_temper_p.h (100%) rename Inu/{Src => Src2}/main/pll_tools.c (100%) rename Inu/{Src => Src2}/main/pll_tools.h (100%) rename Inu/Src2/{551 => }/main/project.c (100%) rename Inu/Src2/{551 => }/main/project.h (100%) rename Inu/Src2/{551 => }/main/project_setup.h (100%) rename Inu/Src2/{551 => }/main/protect_levels.h (100%) rename Inu/Src2/{551 => }/main/pump_control.c (100%) rename Inu/Src2/{551 => }/main/pump_control.h (100%) rename Inu/{Src => Src2}/main/pwm_logs.c (100%) rename Inu/{Src => Src2}/main/pwm_logs.h (100%) rename Inu/Src2/{551 => }/main/pwm_test_lines.c (100%) rename Inu/Src2/{551 => }/main/pwm_test_lines.h (100%) rename Inu/{Src => Src2}/main/ramp_zadanie_tools.c (100%) rename Inu/{Src => Src2}/main/ramp_zadanie_tools.h (100%) delete mode 100644 Inu/Src2/main/rotation_speed.h rename Inu/Src2/{551 => }/main/sbor_shema.c (100%) rename Inu/Src2/{551 => }/main/sbor_shema.h (100%) rename Inu/{Src => Src2}/main/sim_model.c (100%) rename Inu/{Src => Src2}/main/sim_model.h (100%) rename Inu/Src2/{551 => }/main/sync_tools.c (100%) rename Inu/Src2/{551 => }/main/sync_tools.h (100%) rename Inu/{Src => Src2}/main/synhro_tools.c (100%) rename Inu/{Src => Src2}/main/synhro_tools.h (100%) rename Inu/{Src => Src2}/main/temper_p_tools.c (100%) rename Inu/{Src => Src2}/main/temper_p_tools.h (100%) rename Inu/Src2/{551 => }/main/tk_Test.c (100%) rename Inu/Src2/{551 => }/main/tk_Test.h (100%) rename Inu/{Src => Src2}/main/ukss_tools.c (100%) rename Inu/{Src => Src2}/main/ukss_tools.h (100%) rename Inu/{Src => Src2}/main/uom_tools.c (100%) rename Inu/{Src => Src2}/main/uom_tools.h (100%) delete mode 100644 Inu/Src2/main/v_pwm24.c delete mode 100644 Inu/Src2/main/v_pwm24.h rename Inu/Src2/{551 => }/main/v_pwm24_v2.c (100%) rename Inu/Src2/{551 => }/main/v_pwm24_v2.h (98%) rename Inu/Src2/{551 => }/main/v_rotor.c (96%) rename Inu/Src2/{551 => }/main/v_rotor.h (100%) rename Inu/{Src => Src2}/main/v_rotor_22220.c (100%) rename Inu/{Src => Src2}/main/v_rotor_22220.h (100%) rename Inu/Src2/{551 => }/main/xPlatesAddress.h (100%) delete mode 100644 Inu/Src2/main/xp_write_xpwm_time.c diff --git a/Inu/Src/N12_Libs/CAN_Setup.c b/Inu/Src/N12_Libs/CAN_Setup.c index e43a61c..cbb7fd2 100644 --- a/Inu/Src/N12_Libs/CAN_Setup.c +++ b/Inu/Src/N12_Libs/CAN_Setup.c @@ -5,27 +5,21 @@ #include "DSP281x_Device.h" #include "global_time.h" #include "TuneUpPlane.h" -#include "profile_interrupt.h" -unsigned int CanTimeOutErrorTR = 0; -unsigned int CanBusOffError = 0; - - - +int CanTimeOutErrorTR = 0; int enable_can_recive_after_units_box = 0; int flag_enable_can_from_mpu=0; int flag_enable_can_from_terminal=0; long time_pause_enable_can_from_mpu=0; long time_pause_enable_can_from_terminal=0; -int flag_disable_update_modbus_in_can_from_mpu=0; //unsigned long can_base_adr_terminal, can_base_adr_units, can_base_adr_mpu1, can_base_adr_alarm_log; -//unsigned int enable_profile_led1_can = 1; -//unsigned int enable_profile_led2_can = 0; +unsigned int enable_profile_led1_can = 1; +unsigned int enable_profile_led2_can = 0; #pragma DATA_SECTION(cycle,".slow_vars") CYCLE cycle[UNIT_QUA]; @@ -83,7 +77,7 @@ int CAN_count_cycle_input_units[UNIT_QUA_UNITS]; #pragma DATA_SECTION(CAN_timeout_cicle,".fast_vars") //#pragma DATA_SECTION(CAN_timeout_cicle, ".slow_vars") // счетчик -unsigned int CAN_timeout_cicle[UNIT_QUA]; +int CAN_timeout_cicle[UNIT_QUA]; @@ -211,7 +205,7 @@ int init_alarm_log_can_boxs(ALARM_LOG_CAN_SETUP *p ) int c,e; e = 0; - for (c=0;cactive_box[c]) { @@ -410,24 +404,17 @@ void reset_CAN_timeout_cicle(int box) #pragma CODE_SECTION(inc_CAN_timeout_cicle, ".fast_run2"); void inc_CAN_timeout_cicle() { - unsigned int i, t_refresh; - static unsigned int old_time = 0; - - t_refresh = get_delta_milisec(&old_time, 1); - if (t_refresh>1000) - t_refresh = 1000; + int i; - for(i = 0; i < UNIT_QUA; i++) { if (CAN_timeout_cicle[i] < MAX_CAN_WAIT_TIMEOUT) { - CAN_timeout_cicle[i] += t_refresh; + CAN_timeout_cicle[i]++; } else { CAN_timeout[i] = 1; - CAN_refresh_cicle[i] = -1; } } } @@ -556,44 +543,22 @@ void InitCan(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, u ECanaShadow.CANBTC.all = ECanaRegs.CANBTC.all; // ECanaShadow.CANBTC.bit.SJWREG = 1; -#if (CAN_SPEED_BITS==125000) -// ECanaShadow.CANBTC.bit.BRPREG = 23;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock -// ECanaShadow.CANBTC.bit.TSEG1REG = 15;// 15; //5;//7;//14;//10;//7; // Bit time = 15 -// ECanaShadow.CANBTC.bit.TSEG2REG = 2; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) -// ECanaShadow.CANBTC.bit.SJWREG=1; - ECanaShadow.CANBTC.bit.BRPREG = 63;//29;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock - ECanaShadow.CANBTC.bit.TSEG1REG = 9;//9;// 15; //5;//7;//14;//10;//7; // Bit time = 15 - ECanaShadow.CANBTC.bit.TSEG2REG = 3;//4; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) - ECanaShadow.CANBTC.bit.SJWREG = 3;//3; -// ECanaShadow.CANBTC.bit.BRPREG = 31;//29;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock -// ECanaShadow.CANBTC.bit.TSEG1REG = 6;//9;// 15; //5;//7;//14;//10;//7; // Bit time = 15 -// ECanaShadow.CANBTC.bit.TSEG2REG = 1;//4; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) -// ECanaShadow.CANBTC.bit.SJWREG = 1;//3; -#else + #if (CAN_SPEED_BITS==250000) -// ECanaShadow.CANBTC.bit.BRPREG = 23;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock -// ECanaShadow.CANBTC.bit.TSEG1REG = 15;// 15; //5;//7;//14;//10;//7; // Bit time = 15 -// ECanaShadow.CANBTC.bit.TSEG2REG = 2; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) -// ECanaShadow.CANBTC.bit.SJWREG = 1; - - - ECanaShadow.CANBTC.bit.BRPREG = 47;//29;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock - ECanaShadow.CANBTC.bit.TSEG1REG = 6;//9;// 15; //5;//7;//14;//10;//7; // Bit time = 15 - ECanaShadow.CANBTC.bit.TSEG2REG = 1;//4; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) - ECanaShadow.CANBTC.bit.SJWREG = 1;//3; + ECanaShadow.CANBTC.bit.BRPREG = 23;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock + ECanaShadow.CANBTC.bit.TSEG1REG = 15;// 15; //5;//7;//14;//10;//7; // Bit time = 15 + ECanaShadow.CANBTC.bit.TSEG2REG = 2; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) #else #if (CAN_SPEED_BITS==500000) ECanaShadow.CANBTC.bit.BRPREG = 14;//11;//23;//11;// 47; //59;//49;//4;//9; // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock ECanaShadow.CANBTC.bit.TSEG1REG = 11;//12;//15;// 15; //5;//7;//14;//10;//7; // Bit time = 15 ECanaShadow.CANBTC.bit.TSEG2REG = 2; // 2; //4;//5;//7;//2;//5 ; // to the CAN module. (150 / 10 = 15) - ECanaShadow.CANBTC.bit.SJWREG=1; #else #error "Set Can speed in CAN_project.h!!!" #endif #endif -#endif - + ECanaShadow.CANBTC.bit.SJWREG=1; ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all; ECanaShadow.CANMC.all = ECanaRegs.CANMC.all; @@ -633,18 +598,18 @@ void InitCan(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, u PieVectTable.ECAN0INTA = &CAN_handler; PieCtrlRegs.PIEIER9.bit.INTx5=1; // PIE Group 9, INT6 - ECanaShadow.CANGIM.bit.AAIM=1; //Abort Acknowledge Interrupt Mask. - ECanaShadow.CANGIM.bit.BOIM=1; // Bus-off interrupt mask - ECanaShadow.CANGIM.bit.EPIM=1; // Error-passive interrupt mask - ECanaShadow.CANGIM.bit.RMLIM=1; // Received-message-lost interrupt mask - ECanaShadow.CANGIM.bit.WUIM=1; // Wake-up interrupt mask - ECanaShadow.CANGIM.bit.WLIM=1; // Warning level interrupt mask - ECanaShadow.CANGIM.bit.WDIM=1; // Write denied interrupt mask - ECanaShadow.CANGIM.bit.TCOM=1; // Time stamp counter overflow mask + ECanaShadow.CANGIM.bit.AAIM=1; + ECanaShadow.CANGIM.bit.BOIM=1; + ECanaShadow.CANGIM.bit.EPIM=1; + ECanaShadow.CANGIM.bit.RMLIM=1; + ECanaShadow.CANGIM.bit.WUIM=1; + ECanaShadow.CANGIM.bit.WLIM=1; + ECanaShadow.CANGIM.bit.WDIM=1; + ECanaShadow.CANGIM.bit.TCOM=1; - ECanaShadow.CANGIM.bit.MTOM = 1; //Mailbox time-out interrupt mask - ECanaShadow.CANGIM.bit.I1EN = 1; //Interrupt 1 enable - ECanaShadow.CANGIM.bit.GIL = 1; // Global interrupt level for the interrupts TCOF, WDIF, WUIF, BOIF, EPIF, RMLIF, AAIF and WLIF. + ECanaShadow.CANGIM.bit.MTOM = 1; + ECanaShadow.CANGIM.bit.I1EN = 1; + ECanaShadow.CANGIM.bit.GIL = 1; ECanaRegs.CANGIM.all = ECanaShadow.CANGIM.all; PieVectTable.ECAN1INTA = &CAN_reset_err; @@ -673,14 +638,14 @@ void InitCan(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, u for(i=0;i=MPU_UNIT_QUA_UNITS) - return; - - if (adr==mpu_can_setup.adr_detect_refresh[box]) - { - //CAN_count_cycle_input_units[box]++; - if (box0) + if ((adr>0) && flag_enable_can_from_mpu) { - if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) - modbus_table_can_in[adr-1].all = /*(unsigned int)*/((hiword ) & 0xffff); - detect_time_refresh_mpu(local_number_box,adr-1); + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((hiword ) & 0xffff); } adr++; } @@ -1472,11 +1415,9 @@ void parse_data_from_mbox(unsigned int box, unsigned long hiword, timer_pause_enable_can_from_mpu(); if (adr0) + if ((adr>0) && flag_enable_can_from_mpu) { - if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) - modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword>>16) & 0xffff); - detect_time_refresh_mpu(local_number_box,adr-1); + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword>>16) & 0xffff); } adr++; } @@ -1491,11 +1432,9 @@ void parse_data_from_mbox(unsigned int box, unsigned long hiword, timer_pause_enable_can_from_mpu(); if (adr0) + if ((adr>0) && flag_enable_can_from_mpu) { - if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) - modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword) & 0xffff); - detect_time_refresh_mpu(local_number_box,adr-1); + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword) & 0xffff); } adr++; } @@ -1625,11 +1564,11 @@ interrupt void CAN_handler(void) PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.can) + if (enable_profile_led1_can) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.can) + if (enable_profile_led2_can) i_led2_on_off_special(1); #endif @@ -1755,11 +1694,11 @@ interrupt void CAN_handler(void) PieCtrlRegs.PIEIER9.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.can) + if (enable_profile_led1_can) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.can) + if (enable_profile_led2_can) i_led2_on_off_special(0); #endif @@ -1780,47 +1719,25 @@ interrupt void CAN_reset_err(void) #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.can) + if (enable_profile_led1_can) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.can) + if (enable_profile_led2_can) i_led2_on_off_special(1); #endif EINT; - -// ECanaShadow.CANGIM.bit.AAIM=1; //Abort Acknowledge Interrupt Mask. -// ECanaShadow.CANGIM.bit.BOIM=1; // Bus-off interrupt mask -// ECanaShadow.CANGIM.bit.EPIM=1; // Error-passive interrupt mask -// ECanaShadow.CANGIM.bit.RMLIM=1; // Received-message-lost interrupt mask -// ECanaShadow.CANGIM.bit.WUIM=1; // Wake-up interrupt mask -// ECanaShadow.CANGIM.bit.WLIM=1; // Warning level interrupt mask -// ECanaShadow.CANGIM.bit.WDIM=1; // Write denied interrupt mask -// ECanaShadow.CANGIM.bit.TCOM=1; // Time stamp counter overflow mask -// -// ECanaShadow.CANGIM.bit.MTOM = 1; //Mailbox time-out interrupt mask - - - if (ECanaRegs.CANGIF1.bit.AAIF1) // Abort-acknowledge interrupt flag + if (ECanaRegs.CANGIF1.bit.AAIF1) { ECanaRegs.CANAA.all = ECanaRegs.CANAA.all; } - if (ECanaRegs.CANGIF1.bit.WDIF1) //Write-denied interrupt flag + if (ECanaRegs.CANGIF1.bit.WDIF1) { ECanaRegs.CANGIF1.bit.WDIF1=1; } - - if (ECanaRegs.CANGIF1.bit.BOIF1) // Bus off interrupt flag - { - ECanaRegs.CANGIF1.bit.BOIF1=1; - CanBusOffError++; - } - - - // ECanaRegs.CANTRR.all = 1; CanTimeOutErrorTR++; @@ -1833,11 +1750,11 @@ interrupt void CAN_reset_err(void) #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.can) + if (enable_profile_led1_can) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.can) + if (enable_profile_led2_can) i_led2_on_off_special(0); #endif @@ -1888,311 +1805,6 @@ unsigned int test_can_live_terminal(int n) -void InitCanSoft(void) -{ - struct ECAN_REGS ECanaShadow; - int i, c; - volatile struct MBOX *tmbox; - volatile Uint32 *tmoto; - - unsigned long canme_bits = 0; - unsigned long canmd_bits = 0; - unsigned long canmim_bits = 0; - - -// Configure CAN pins using GPIO regs here - EALLOW; - -// GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1; -// GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1; - -// Configure the eCAN RX and TX pins for eCAN transmissions -// ECanaRegs.CANTIOC.all = 8; // only 3rd bit, TXFUNC, is significant -// ECanaRegs.CANRIOC.all = 8; // only 3rd bit, RXFUNC, is significant - - -// Specify that 8 bits will be sent/received -// for (c=0;c<32;c++) -// { -// tmbox = &ECanaMboxes.MBOX0 + c; -// tmbox->MSGCTRL.all = 0x00000008; -// } - -// Disable all Mailboxes -// Required before writing the MSGIDs -// ECanaRegs.CANME.all = 0; - - canme_bits = 0; - canmd_bits = 0; - canmim_bits = 0; - - // receive+transive //Ura - for (c=0;c<32;c++) - { - - if (mailboxs_can_setup.can_mbox_adr[c]) - { -// tmbox = &ECanaMboxes.MBOX0 + c; -// if(mailboxs_can_setup.type_box[c] == UNITS_TYPE_BOX) -// { -//// tmbox->MSGID.bit.IDE = 0; -//// tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; -// tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; -// } -// else -// { -// if(mailboxs_can_setup.type_box[c] == CANOPEN_TYPE_BOX) -// { -// tmbox->MSGID.bit.IDE = 0; -// tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; -// //tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; -// } -// else -// tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; -// } - - canme_bits |= ((unsigned long)1<buffer[9] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, 10); @@ -261,7 +260,6 @@ void ModbusRTUsend3(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_star rs_arr->buffer[9] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, 10); @@ -353,7 +351,6 @@ void ModbusRTUsend4(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_star rs_arr->buffer[9] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, 10); @@ -515,7 +512,6 @@ void ModbusRTUsend5(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_star rs_arr->buffer[8] = 0; rs_arr->buffer[9] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, 10); /* ждем ответа */ @@ -590,7 +586,6 @@ void ModbusRTUsend6(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_star rs_arr->buffer[9] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, 10); // control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; @@ -722,7 +717,6 @@ void ModbusRTUsend15(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_sta rs_arr->buffer[count_data_bytes + 10] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; // RS_Send(rs_arr, rs_arr->buffer, (count_data_bytes + 10 + 2)); RS_Send(rs_arr, rs_arr->buffer, (count_data_bytes + 10)); @@ -885,7 +879,6 @@ void ModbusRTUsend16(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_sta rs_arr->buffer[count_word * 2 + 10] = 0; rs_arr->RS_DataWillSend = 1; - rs_arr->RS_DataWillSend2 = 1; RS_Send(rs_arr, rs_arr->buffer, (count_word * 2 + 10)); // control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; @@ -893,7 +886,6 @@ void ModbusRTUsend16(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_sta // ждем ответа if (adr_contr > 0 && adr_contr < 0xff) { - //rs_arr->RS_Length = -1; RS_Len[CMD_RS232_MODBUS_16] = 8; RS_SetControllerLeading(rs_arr, true); RS_SetAdrAnswerController(rs_arr, adr_contr); diff --git a/Inu/Src/N12_Libs/build_version.c b/Inu/Src/N12_Libs/build_version.c index 147f0c1..a3f1f3e 100644 --- a/Inu/Src/N12_Libs/build_version.c +++ b/Inu/Src/N12_Libs/build_version.c @@ -15,10 +15,3 @@ float build_time_f = BUILD_TIME; int build_data_i = (BUILD_DATA*1000); int build_time_i = (BUILD_TIME*1000); - -int build_year = BUILD_YEAR; -int build_month = BUILD_MONTH; -int build_day = BUILD_DAY; - - - diff --git a/Inu/Src/N12_Libs/build_version.h b/Inu/Src/N12_Libs/build_version.h index 1100fb0..c4aa15c 100644 --- a/Inu/Src/N12_Libs/build_version.h +++ b/Inu/Src/N12_Libs/build_version.h @@ -23,8 +23,4 @@ extern int build_data_i; extern int build_time_i; -extern int build_year, build_month, build_day; - - - #endif /* SRC_N12_LIBS_BUILD_VERSION_H_ */ diff --git a/Inu/Src/N12_Libs/control_station.c b/Inu/Src/N12_Libs/control_station.c index 58b9cf8..a271130 100644 --- a/Inu/Src/N12_Libs/control_station.c +++ b/Inu/Src/N12_Libs/control_station.c @@ -20,7 +20,7 @@ CONTROL_STATION control_station = CONTROL_STATION_DEFAULTS; void control_station_clear(CONTROL_STATION_handle cs) { - int i,k,j; + int i,k; for (i=0;itime_detect_answer_485[i] = 0; for (k=0;kraw_array_data[i][k].all = 0; - for (j=0;jraw_array_data_temp[i][k][j].all = 0; - } cs->flag_refresh_array[i] = 0; - - cs->prev_CAN_count_cycle_input_units[i] = 0; - cs->count_raw_array_data_temp[i] = 0; - } - - for (k=0;kactive_array_cmd[k] = 0; } /////////////////////////////////////////////////////////////////// diff --git a/Inu/Src/N12_Libs/control_station.h b/Inu/Src/N12_Libs/control_station.h index a40ee94..662c92d 100644 --- a/Inu/Src/N12_Libs/control_station.h +++ b/Inu/Src/N12_Libs/control_station.h @@ -30,8 +30,7 @@ #define CONTROL_STATION_SETUP_TIME_DETECT_ACTIVE_RESEND_485 2 // в тиках от CONTROL_STATION_TIME_WAIT #define CONTROL_STATION_SETUP_TIME_SEND_CMD_AFTER_OFF 5 // в тиках от CONTROL_STATION_TIME_WAIT -#define CONTROL_STATION_MAX_RAW_DATA 256 //128 // максимальное кол-во данных для сырых данных полученных от постов -#define CONTROL_STATION_MAX_RAW_DATA_TEMP 3 //128 // сколько данных храним для временного буфера +#define CONTROL_STATION_MAX_RAW_DATA 256 //128 // максимальное кол-во данных для сырых данных полученных от постов ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// @@ -59,7 +58,6 @@ typedef struct { int active_array_cmd[CONTROL_STATION_CMD_LAST]; // массив данных актуальных для автивного поста, данные после parse WORD_UINT2BITS_STRUCT raw_array_data[COUNT_CONTROL_STATION][CONTROL_STATION_MAX_RAW_DATA]; // сырой массив данных полученных от каждого из постов, без parse. - WORD_UINT2BITS_STRUCT raw_array_data_temp[COUNT_CONTROL_STATION][CONTROL_STATION_MAX_RAW_DATA][CONTROL_STATION_MAX_RAW_DATA_TEMP]; // временный сырой массив данных полученных от каждого из постов, без parse. unsigned int flag_message_sent[COUNT_CONTROL_STATION]; // флаг на ожидание ответа по системе запрос-ответ unsigned int flag_waiting_answer[COUNT_CONTROL_STATION]; // ожидать ли ответ по системе запрос-ответ @@ -78,8 +76,6 @@ typedef struct { unsigned int cmd_checkback_from_control_station[COUNT_CONTROL_STATION]; // квитирование от поста unsigned int cmd_test_leds_from_control_station[COUNT_CONTROL_STATION]; // тест ламп от поста */ - unsigned int prev_CAN_count_cycle_input_units[COUNT_CONTROL_STATION]; // пред кол-во обновлений из CAN - unsigned int count_raw_array_data_temp[COUNT_CONTROL_STATION]; // индекс перебора по CONTROL_STATION_MAX_RAW_DATA_TEMP void (*clear)(); // Clear buffers void (*update_timers)(); // Обнуляем таймеры на постах с которыми есть обмен @@ -109,9 +105,6 @@ typedef CONTROL_STATION *CONTROL_STATION_handle; {0}, \ {0}, \ {0}, \ - {0}, \ - {0}, \ - {0}, \ control_station_clear, \ control_station_update_timers, \ control_station_detect_active_station \ diff --git a/Inu/Src/N12_Libs/filter_v1.c b/Inu/Src/N12_Libs/filter_v1.c index 5a8d337..609206c 100644 --- a/Inu/Src/N12_Libs/filter_v1.c +++ b/Inu/Src/N12_Libs/filter_v1.c @@ -278,9 +278,6 @@ _iq19 exp_regul_iq19(_iq19 k_exp_regul, _iq19 InpVarCurr, _iq19 InpVarInstant) #pragma CODE_SECTION(exp_regul_iq,".fast_run"); -// -// Tсек = Tпериод/k_exp_regul -// _iq exp_regul_iq(_iq k_exp_regul, _iq InpVarFiltered, _iq InpVarInstant) { _iq t1; diff --git a/Inu/Src/N12_Libs/filter_v1.h b/Inu/Src/N12_Libs/filter_v1.h index 6ca43e9..2bd2ddf 100644 --- a/Inu/Src/N12_Libs/filter_v1.h +++ b/Inu/Src/N12_Libs/filter_v1.h @@ -65,6 +65,9 @@ void exp_regul_iq_fast(_iq k_exp_regul, _iq *InpVarCurr, _iq InpVarInstant); + + + #ifdef __cplusplus } #endif diff --git a/Inu/Src/N12_Libs/global_time.c b/Inu/Src/N12_Libs/global_time.c index a5db6ef..3cbbfda 100644 --- a/Inu/Src/N12_Libs/global_time.c +++ b/Inu/Src/N12_Libs/global_time.c @@ -7,13 +7,9 @@ GLOBAL_TIME global_time = GLOBAL_TIME_DEFAULTS; void init_global_time_struct(unsigned int freq_pwm) { global_time.total_seconds = 0; - global_time.total_seconds10 = 0; - global_time.total_seconds10full = 0; global_time.microseconds = 0; - global_time.microseconds_temp = 0; global_time.pwm_tics = 0; global_time.miliseconds = 0; - global_time.miliseconds_long = 0; global_time.seconds = 0; global_time.minuts = 0; global_time.hours = 0; @@ -24,40 +20,14 @@ void init_global_time_struct(unsigned int freq_pwm) #pragma CODE_SECTION(global_time_calc,".fast_run2"); void global_time_calc(GLOBAL_TIME_handle gt) { - unsigned int miliseconds_temp = 0; - static unsigned int miliseconds_temp10 = 0; - gt->pwm_tics++; gt->microseconds += gt->microseconds_add; - gt->microseconds_temp += gt->microseconds_add; - - if (gt->microseconds_temp>=1000) - { - if (gt->microseconds_temp>=2000) - { - miliseconds_temp = gt->microseconds_temp/1000; - gt->microseconds_temp -= miliseconds_temp*1000; - } - else - { - miliseconds_temp = 1; - gt->microseconds_temp -= 1000; - } - } - -// gt->miliseconds = gt->microseconds / 1000; - - gt->miliseconds += miliseconds_temp; - miliseconds_temp10 += miliseconds_temp; - + gt->miliseconds = gt->microseconds / 1000; if(gt->pwm_tics == gt->freq_pwm_hz) { gt->total_seconds++; - gt->total_seconds10 += 10; - gt->seconds++; gt->pwm_tics = 0; - miliseconds_temp10 = 0; if(gt->seconds == 60) { @@ -71,9 +41,6 @@ void global_time_calc(GLOBAL_TIME_handle gt) } } } - - //gt->total_seconds10 += 10; - gt->total_seconds10full = gt->total_seconds10 + miliseconds_temp10/100; } @@ -90,17 +57,9 @@ void init_timer_milisec(unsigned int *start_time) int detect_pause_sec(unsigned int wait_pause, unsigned int *old_time) { unsigned long delta; + delta = (unsigned int)((unsigned int)global_time.total_seconds - *old_time); - if(global_time.total_seconds >= *old_time) - { - delta = (unsigned int)((unsigned int)global_time.total_seconds - *old_time); - } - else - { - delta = (unsigned int)((unsigned int)global_time.total_seconds + (0xFFFFUL - *old_time)); - } - - if (delta>=wait_pause) + if (delta>wait_pause) { *old_time = (unsigned int)global_time.total_seconds; return 1; @@ -121,7 +80,7 @@ int detect_pause_milisec(unsigned int wait_pause, unsigned int *old_time) delta = (unsigned int)((unsigned int)global_time.miliseconds + (0xFFFFUL - *old_time)); } - if (delta>=wait_pause) + if (delta>wait_pause) { *old_time = (unsigned int)global_time.miliseconds; return 1; @@ -129,21 +88,3 @@ int detect_pause_milisec(unsigned int wait_pause, unsigned int *old_time) else return 0; } - -unsigned int get_delta_milisec(unsigned int *old_time, unsigned int upd) -{ - unsigned long delta; - - if(global_time.miliseconds >= *old_time) - { - delta = (unsigned int)((unsigned int)global_time.miliseconds - *old_time); - } - else - { - delta = (unsigned int)((unsigned int)global_time.miliseconds + (0xFFFFUL - *old_time)); - } - if (upd) - *old_time = (unsigned int)global_time.miliseconds; - - return delta; -} diff --git a/Inu/Src/N12_Libs/global_time.h b/Inu/Src/N12_Libs/global_time.h index f4f4e2c..5d4789b 100644 --- a/Inu/Src/N12_Libs/global_time.h +++ b/Inu/Src/N12_Libs/global_time.h @@ -3,13 +3,8 @@ typedef struct { unsigned long total_seconds; //Всего секунд с момента включениЯ - unsigned long total_seconds10; //Всего секунд с момента включениЯ с десятыми - unsigned long total_seconds10full; //Всего секунд с момента включениЯ с десятыми unsigned long microseconds; - unsigned int microseconds_temp; - unsigned int miliseconds; //??? - unsigned long miliseconds_long; //??? unsigned int pwm_tics; unsigned int seconds; unsigned int minuts; @@ -30,11 +25,7 @@ Default initalizer for the GLOBAL_TIME object. #define GLOBAL_TIME_DEFAULTS { 0, \ 0, \ 0, \ - 0, \ 0, \ - 0, \ - 0, \ - 0, \ 0, \ 0, \ 0, \ @@ -53,6 +44,5 @@ void init_timer_sec(unsigned int *start_time); // void init_timer_milisec(unsigned int *start_time); //Инициализирует переменную, времЯ старта в милисекундах int detect_pause_sec(unsigned int wait_pause, unsigned int *old_time); //пауза в секундах int detect_pause_milisec(unsigned int wait_pause, unsigned int *old_time); //Пауза в милисекундах (не более 60000млсек) -unsigned int get_delta_milisec(unsigned int *old_time, unsigned int upd); // вернули сколько времени прошло от времени old_time ; upd=1 - обновить old_time - текущим #endif //_GLOBAL_TIME diff --git a/Inu/Src/N12_Libs/math_pi.h b/Inu/Src/N12_Libs/math_pi.h index a12ecd2..c6b5619 100644 --- a/Inu/Src/N12_Libs/math_pi.h +++ b/Inu/Src/N12_Libs/math_pi.h @@ -12,23 +12,8 @@ #define CONST_SQRT3 29058990 //1.7320508075688772935274463415059 = sqrt(3) #define CONST_SQRT3_2 14529495 //1.7320508075688772935274463415059/2=0.8660254 = sqrt(3)/2 #define CONST_IQ_1 16777216 //1 - - -#define CONST_IQ_2 33554432 //2 - - - -#define CONST_IQ_01 1677721 //0.1 -#define CONST_IQ_02 3355442 //0.2 -#define CONST_IQ_03 5033163 //0.3 -#define CONST_IQ_04 6710884 //0.4 #define CONST_IQ_05 8388608 //0.5 - -#define CONST_IQ_06 10066329 //0.6 -#define CONST_IQ_07 11744051 //0.7 -#define CONST_IQ_08 13421772 //0.8 -#define CONST_IQ_09 15099494 //0.9 - +#define CONST_IQ_2 33554432 //2 #define CONST_IQ_PI6 8784530 //30 #define CONST_IQ_PI3 17569060 // 60 diff --git a/Inu/Src/N12_Libs/mathlib.c b/Inu/Src/N12_Libs/mathlib.c index b8d401c..433dd9c 100644 --- a/Inu/Src/N12_Libs/mathlib.c +++ b/Inu/Src/N12_Libs/mathlib.c @@ -19,13 +19,13 @@ #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File #include + + #include "mathlib.h" -#include "params_norma.h" -#include "math_pi.h" -#include "params_pwm24.h" -#include -#include "params_norma.h" +#include + + _iq SQRT_32 = _IQ(0.8660254037844); _iq CONST_23 = _IQ(2.0/3.0); @@ -36,38 +36,28 @@ _iq CONST_15 = _IQ(1.5); #define real float -float my_satur_float(float Input, float Positive, float Negative, float DeadZone) +float my_satur_float(float Input, float Positive, float Negative) { - if (fabs(DeadZone)>0.000001 && Input>-DeadZone && Input=Positive) Input=Positive; - else - if (Input<=Negative) Input=Negative; - return Input; -} - -int my_satur_int(int Input, int Positive, int Negative, int DeadZone) -{ - if (DeadZone!=0 && Input>-DeadZone && Input=Positive) Input=Positive; - else if (Input<=Negative) Input=Negative; return Input; } -long my_satur_long(long Input, long Positive, long Negative, long DeadZone) +int my_satur_int(int Input, int Positive, int Negative) +{ + + if (Input>=Positive) Input=Positive; + if (Input<=Negative) Input=Negative; + + return Input; +} + +long my_satur_long(long Input, long Positive, long Negative) { - if (DeadZone!=0 && Input>-DeadZone && Input=Positive) Input=Positive; - else if (Input<=Negative) Input=Negative; return Input; @@ -152,12 +142,9 @@ real exp_regul(real Tperiod_regul, real Texp_regul, real InpVarCurr, real InpVar - -*/ - -float zad_intensiv(float StepP, float StepN, float InpVarCurr, float InpVarInstant) +real zad_intensiv(real StepP, real StepN, real InpVarCurr, real InpVarInstant) { - float deltaVar, VarOut; + real deltaVar, VarOut; deltaVar = InpVarInstant-InpVarCurr; @@ -173,7 +160,7 @@ float zad_intensiv(float StepP, float StepN, float InpVarCurr, float InpVarInsta VarOut = InpVarCurr; return VarOut; } - +*/ #pragma CODE_SECTION(zad_intensiv_q,".fast_run"); _iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant) { @@ -350,88 +337,3 @@ float fast_round(float x) } -float fast_round_with_delta(float prev, float x, float delta) -{ - float d; - long i; - - - i = (long)x; - - if (x<0) - { - d = i - x; - if (d>=0.5) - i = i - 1; - } - else - { - d = x - i; - if (d>=0.5) - i = i + 1; - } - - if (fabs(prev-x)>=delta) - return (float)i; - else - return (float)prev; - -} - - -float fast_round_with_limiter(float x, float lim) -{ - float d; - long i; - - - if (fabs(x)<=lim) - return 0; - - i = (long)x; - - if (x<0) - { - d = i - x; - if (d>=0.5) - i = i - 1; - } - else - { - d = x - i; - if (d>=0.5) - i = i + 1; - } - return (float)i; - -} - - -#pragma CODE_SECTION(calc_rms,".fast_run"); -_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal) -{ - static _iq pi_pwm = _IQ(PI*NORMA_FROTOR/(FREQ_PWM/5.0)); - - _iq cosw, sinw, wdt, y2, z1, z2, z3, y; - - wdt = _IQmpy(pi_pwm,freq_signal); - sinw = _IQsinPU(wdt); - cosw = _IQcosPU(wdt); - - if (cosw==0) - return 0; - - z1 = input_prev - _IQmpy(input,cosw); -// z2 = sinw; - z3 = _IQdiv(z1,sinw); - - y2 = _IQmpy(input,input)+_IQmpy(z3,z3); - -// cosw = _IQsin(); - - y = _IQsqrt(y2); - return y; -} - - - diff --git a/Inu/Src/N12_Libs/mathlib.h b/Inu/Src/N12_Libs/mathlib.h index 2910690..a684714 100644 --- a/Inu/Src/N12_Libs/mathlib.h +++ b/Inu/Src/N12_Libs/mathlib.h @@ -4,7 +4,6 @@ #include "IQmathLib.h" - /* real pi_regul(real Kp_regul, real Tintegral_regul, real Tperiod_regul, @@ -12,7 +11,7 @@ real pi_regul(real Kp_regul, real Tintegral_regul, real Tperiod_regul, real exp_regul(real Tperiod_regul, real Texp_regul, real InpVarCurr, real InpVarInstant); - +real zad_intensiv(real StepP, real StepN, real InpVarCurr, real InpVarInstant); real pid_regul2(real Kp_regul, real Tperiod_regul, real Minimum, real Maximum, real yk, real *uk1, real *yk1, real *yk2, real *yzad, @@ -28,9 +27,7 @@ real pi_regul3(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, r real pi_regul4(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, real Maximum, real InpVar, real *InpVarPrev, real *OutVarPrev); -*/ -float zad_intensiv(float StepP, float StepN, float InpVarCurr, float InpVarInstant); - +*/ _iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant); _iq im_calc( _iq ia, _iq ib, _iq ic); @@ -38,10 +35,9 @@ float exp_regul(float Tperiod_regul, float Texp_regul, float InpVarCurr, float I -float my_satur_float(float Input, float Positive, float Negative, float DeadZone); - -int my_satur_int(int Input, int Positive, int Negative, int DeadZone); -long my_satur_long(long Input, long Positive, long Negative, long DeadZone); +float my_satur_float(float Input, float Positive, float Negative); +int my_satur_int(int Input, int Positive, int Negative); +long my_satur_long(long Input, long Positive, long Negative); @@ -72,10 +68,7 @@ typedef struct { _iq calc_rms_array_var_period(RMS_CALC_ARRAY_THINNING *v); _iq calc_rms_array_var_period_IQ15(RMS_CALC_ARRAY_THINNING *v); float fast_round(float x); -float fast_round_with_limiter(float x, float lim); -float fast_round_with_delta(float prev, float x, float delta); -_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal); #endif diff --git a/Inu/Src/N12_Libs/modbus_table_v2.c b/Inu/Src/N12_Libs/modbus_table_v2.c index 0ccb1ef..cecf62d 100644 --- a/Inu/Src/N12_Libs/modbus_table_v2.c +++ b/Inu/Src/N12_Libs/modbus_table_v2.c @@ -31,8 +31,6 @@ MODBUS_REG_STRUCT modbus_table_can_in[SIZE_MODBUS_TABLE]; #pragma DATA_SECTION(modbus_table_can_out,".logs"); MODBUS_REG_STRUCT modbus_table_can_out[SIZE_MODBUS_TABLE]; -#pragma DATA_SECTION(modbus_table_can_out_temp,".logs"); -MODBUS_REG_STRUCT modbus_table_can_out_temp[SIZE_MODBUS_TABLE]; @@ -42,8 +40,8 @@ int i; for (i=0;i max_Km) { - Uq_zad = _IQsqrt(max_Km_square - _IQmpy(Ud_zad, Ud_zad)); + Uq = _IQsqrt(max_Km_square - _IQmpy(Ud_zad, Ud_zad)); } - Umod = _IQsqrt(_IQmpy(Ud_zad, Ud_zad) + _IQmpy(Uq_zad, Uq_zad)); - uf_disbalance_uzpt(Umod, disable_alg_u_disbalance, kplus_u_disbalance, k_u_disbalance, U_1, U_2, Uzad_max, &Kplus); *Kplus_out = Kplus; - *Uzad_out = Umod; //////////////////////////////////////// //////////////////////////////////////// diff --git a/Inu/Src/N12_VectorControl/alg_pll.c b/Inu/Src/N12_VectorControl/alg_pll.c index b7f3a9c..5356010 100644 --- a/Inu/Src/N12_VectorControl/alg_pll.c +++ b/Inu/Src/N12_VectorControl/alg_pll.c @@ -2,9 +2,9 @@ #include "alg_pll.h" #include "params_pll.h" -#include "params_norma.h" -//#define NORMA_ACP 3000 + +#define NORMA_ACP 3000 //#define FREQ_PWM_VIPR 1975 //#define SIZE_PLL_AVG 50 @@ -12,9 +12,8 @@ //_iq w_in_avg[SIZE_PLL_AVG]; //_iq w_out_avg[SIZE_PLL_AVG]; -#define DETECT_PLL_D (2000.0/NORMA_ACP) // ampl -#define DETECT_PLL_Q (500.0/NORMA_ACP) // zero - +#define DETECT_PLL_D (100.0/NORMA_ACP) // ampl +#define DETECT_PLL_Q (100.0/NORMA_ACP) // zero _iq iqDetect_PLL_d=_IQ(DETECT_PLL_D); _iq iqDetect_PLL_q=_IQ(DETECT_PLL_Q); @@ -105,7 +104,7 @@ void AB_BC_CA_To_ABC(_iq U_AB, _iq U_BC, _iq U_CA, _iq *Ua, _iq *Ub, _iq *Uc) ///////////////////////////////////////////////// -#pragma CODE_SECTION(PLLController,".fast_run"); +//#pragma CODE_SECTION(PLLController,".fast_run"); ///////////////////////////////////////////////// void PLLController(PLL_REC *v) { @@ -319,9 +318,9 @@ void PLLController(PLL_REC *v) ////////////////////////////////////////////////// ////////////////////////////////////////////////// ///////////////////////////////////////////////// -//#pragma CODE_SECTION(pll_get_freq,".fast_run"); +#pragma CODE_SECTION(pll_get_freq,".fast_run"); ///////////////////////////////////////////////// -void pll_get_freq_float(PLL_REC *v) +void pll_get_freq(PLL_REC *v) { if (v->output.flag_find_pll) @@ -337,22 +336,9 @@ void pll_get_freq_float(PLL_REC *v) ////////////////////////////////////////////////// ////////////////////////////////////////////////// -void pll_get_freq_iq(PLL_REC *v) -{ - - if (v->output.flag_find_pll) - { - v->output.iq_freq_net = v->vars.w_shtrih;//_IQtoF( v->vars.w_shtrih) * v->setup.freq_run_pll / PI * 50.00; // freq*100 - } - else - { - v->output.iq_freq_net = 0; - } - -} ////////////////////////////////////////////////// -//#pragma CODE_SECTION(detect_phase_count,".fast_run"); + void detect_phase_count(PLL_REC *v) { static _iq prev_Ua = 0; diff --git a/Inu/Src/N12_VectorControl/alg_pll.h b/Inu/Src/N12_VectorControl/alg_pll.h index 0a63dde..490aff2 100644 --- a/Inu/Src/N12_VectorControl/alg_pll.h +++ b/Inu/Src/N12_VectorControl/alg_pll.h @@ -59,11 +59,10 @@ typedef struct { _iq Input_U_AB; // typedef struct { int flag_find_pll; int int_freq_net; - _iq iq_freq_net; int status; } PLL_OUTPUT; -#define PLL_OUTPUT_DEFAULT {0, 0, 0, STATUS_PLL_NOT_INITED} +#define PLL_OUTPUT_DEFAULT {0, 0, STATUS_PLL_NOT_INITED} //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// @@ -140,8 +139,7 @@ typedef struct { PLL_INPUT input; PLL_VARS vars; void (*init)(); // Pointer to calculation function void (*calc_pll)(); // Pointer to calculation function - void (*get_freq_float)(); // Pointer to calculation function - void (*get_freq_iq)(); + void (*get_freq)(); // Pointer to calculation function }PLL_REC; typedef PLL_REC *PLL_REC_handle; @@ -153,14 +151,12 @@ typedef PLL_REC *PLL_REC_handle; PLL_VARS_DEFAULT,\ (void (*)(unsigned long))pll_init,\ (void (*)(unsigned long))pll_calc,\ - (void (*)(unsigned long))pll_get_freq_float,\ - (void (*)(unsigned long))pll_get_freq_iq \ - } + (void (*)(unsigned long))pll_get_freq\ + } void pll_init(PLL_REC_handle); void pll_calc(PLL_REC_handle); -void pll_get_freq_float(PLL_REC_handle); -void pll_get_freq_iq(PLL_REC_handle); +void pll_get_freq(PLL_REC_handle); void Find_zero_Uabc(PLL_REC_handle); void PLLController(PLL_REC *v); diff --git a/Inu/Src/N12_VectorControl/teta_calc.c b/Inu/Src/N12_VectorControl/teta_calc.c index 8a64daf..34d34ab 100644 --- a/Inu/Src/N12_VectorControl/teta_calc.c +++ b/Inu/Src/N12_VectorControl/teta_calc.c @@ -32,7 +32,7 @@ void init_teta_calc_struct() tetta_calc.hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / FREQ_PWM); } -//#pragma CODE_SECTION(calc_teta_Id,".fast_run"); +#pragma CODE_SECTION(calc_teta_Id,".fast_run"); void calc_teta_Id(_iq Frot, _iq Id, _iq Iq, _iq *theta_out, _iq *theta_to_slave, _iq *Fsl_out, _iq *Fstator_out, unsigned int master, int reset) { @@ -56,10 +56,9 @@ void calc_teta_Id(_iq Frot, _iq Id, _iq Iq, _iq *theta_out, _iq *theta_to_slave, } else { Fsl = 0; } - if (Fsl > MAX_Ud_Pid_Out_Id) { Fsl = MAX_Ud_Pid_Out_Id;} - if (Fsl < -MAX_Ud_Pid_Out_Id) { Fsl = -MAX_Ud_Pid_Out_Id;} -// if (Fsl < 0) { Fsl = 0;} +// if (Fsl < -MAX_Ud_Pid_Out_Id) { Fsl = -MAX_Ud_Pid_Out_Id;} + if (Fsl < 0) { Fsl = 0;} Fst = Frot * POLUS + Fsl; add_to_tic = _IQmpy(Fst, tetta_calc.hz_to_angle); diff --git a/Inu/Src/N12_VectorControl/vector_control.c b/Inu/Src/N12_VectorControl/vector_control.c index 901b75d..5cf4689 100644 --- a/Inu/Src/N12_VectorControl/vector_control.c +++ b/Inu/Src/N12_VectorControl/vector_control.c @@ -85,7 +85,7 @@ void vectorControlConstId (_iq Pzad, _iq Fzad, int direction, _iq Frot, _iq P_measured = 0; static _iq Ud_zad1 = 0, Uq_zad1 = 0, Ud_zad2 = 0, Uq_zad2 = 0; -// if(direction < 0) { Frot = -Frot; } + if(direction < 0) { Frot = -Frot; } if (reset) { Ud_zad1 = 0; @@ -134,13 +134,8 @@ void vectorControlConstId (_iq Pzad, _iq Fzad, int direction, _iq Frot, vect_control.iqUqKm = Uq_zad1 + vect_control.iqUqCompensation; } - vect_control.sqrtIdq1 = _IQsqrt(_IQmpy(vect_control.iqId1, vect_control.iqId1) + _IQmpy(vect_control.iqIq1, vect_control.iqIq1)); analog_Udq_calc(Ud_zad1, Uq_zad1, Ud_zad2, Uq_zad2); *Iq_to_slave = Iq_zad; - - vect_control.Iq_zad1 = Iq_zad; - vect_control.Id_zad1 = Id_zad; - } diff --git a/Inu/Src/N12_VectorControl/vector_control.h b/Inu/Src/N12_VectorControl/vector_control.h index 3307fb1..9183b51 100644 --- a/Inu/Src/N12_VectorControl/vector_control.h +++ b/Inu/Src/N12_VectorControl/vector_control.h @@ -49,22 +49,12 @@ typedef struct { _iq koef_Ud_comp; _iq koef_Uq_comp; _iq koef_zero_Uzad; - _iq add_tetta; - - _iq sqrtIdq1; - _iq sqrtIdq2; - - _iq Iq_zad1; - _iq Id_zad1; - - _iq add_bpsi; - } VECTOR_CONTROL; #define VECTOR_CONTROL_DEFAULTS {PIDREG3_DEFAULTS, PIDREG3_DEFAULTS, \ PIDREG3_DEFAULTS, PIDREG3_DEFAULTS, \ 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + 0,0,0,0,0,0,0,0,0,0,0} void vectorControlConstId (_iq Pzad, _iq Fzad, int direction, _iq Frot, int n_alg, unsigned int master, _iq mzz_zad, diff --git a/Inu/Src/N12_Xilinx/RS_Function_terminal.h b/Inu/Src/N12_Xilinx/RS_Function_terminal.h index 13c9485..fb76718 100644 --- a/Inu/Src/N12_Xilinx/RS_Function_terminal.h +++ b/Inu/Src/N12_Xilinx/RS_Function_terminal.h @@ -73,9 +73,6 @@ typedef struct CMD_DIGIT_BYTE_STRUCT Byte03; CMD_DIGIT_BYTE_STRUCT Byte04; - CMD_DIGIT_BYTE_STRUCT Byte05; - CMD_DIGIT_BYTE_STRUCT Byte06; - } CMD_DIGIT_DATA_STRUCT; typedef struct @@ -115,13 +112,6 @@ typedef struct CHAR analog1_hi; // старший байт заданной скорости CHAR analog2_lo; // младший байт заданной скорости CHAR analog2_hi; // старший байт заданной скорости - CHAR analog3_lo; // младший байт заданной скорости - CHAR analog3_hi; // старший байт заданной скорости - CHAR analog4_lo; // младший байт заданной скорости - CHAR analog4_hi; // старший байт заданной скорости - CHAR analog5_lo; // младший байт заданной скорости - CHAR analog5_hi; // старший байт заданной скорости - } CMD_ANALOG_DATA_TEST_ALL_STRUCT; typedef struct @@ -221,19 +211,6 @@ typedef struct CMD_DIGIT_BYTE_STRUCT byte49; CMD_DIGIT_BYTE_STRUCT byte50; - CMD_DIGIT_BYTE_STRUCT byte51; - CMD_DIGIT_BYTE_STRUCT byte52; - - CMD_DIGIT_BYTE_STRUCT byte53; - CMD_DIGIT_BYTE_STRUCT byte54; - - CMD_DIGIT_BYTE_STRUCT byte55; - CMD_DIGIT_BYTE_STRUCT byte56; - - CMD_DIGIT_BYTE_STRUCT byte57; - CMD_DIGIT_BYTE_STRUCT byte58; - CMD_DIGIT_BYTE_STRUCT byte59; - CMD_DIGIT_BYTE_STRUCT byte60; } ANS_DIGIT_DATA_TO_TERMINAL_STRUCT; // Дискретные величины посылки от СУ @@ -384,67 +361,6 @@ typedef struct CHAR analog68_lo; CHAR analog68_hi; - CHAR analog69_lo; - CHAR analog69_hi; - CHAR analog70_lo; - CHAR analog70_hi; - CHAR analog71_lo; - CHAR analog71_hi; - CHAR analog72_lo; - CHAR analog72_hi; - CHAR analog73_lo; - CHAR analog73_hi; - CHAR analog74_lo; - CHAR analog74_hi; - CHAR analog75_lo; - CHAR analog75_hi; - CHAR analog76_lo; - CHAR analog76_hi; - CHAR analog77_lo; - CHAR analog77_hi; - CHAR analog78_lo; - CHAR analog78_hi; - CHAR analog79_lo; - CHAR analog79_hi; - CHAR analog80_lo; - CHAR analog80_hi; - - CHAR analog81_lo; - CHAR analog81_hi; - CHAR analog82_lo; - CHAR analog82_hi; - CHAR analog83_lo; - CHAR analog83_hi; - CHAR analog84_lo; - CHAR analog84_hi; - - CHAR analog85_lo; - CHAR analog85_hi; - CHAR analog86_lo; - CHAR analog86_hi; - CHAR analog87_lo; - CHAR analog87_hi; - CHAR analog88_lo; - CHAR analog88_hi; - CHAR analog89_lo; - CHAR analog89_hi; - - CHAR analog90_lo; - CHAR analog90_hi; - CHAR analog91_lo; - CHAR analog91_hi; - CHAR analog92_lo; - CHAR analog92_hi; - CHAR analog93_lo; - CHAR analog93_hi; - CHAR analog94_lo; - CHAR analog94_hi; - - CHAR analog95_lo; - CHAR analog95_hi; - CHAR analog96_lo; - CHAR analog96_hi; - } TMS_ANALOG_DATA_STRUCT; @@ -498,17 +414,6 @@ typedef struct CMD_DIGIT_BYTE_STRUCT byte23; CMD_DIGIT_BYTE_STRUCT byte24; - CMD_DIGIT_BYTE_STRUCT byte25; - CMD_DIGIT_BYTE_STRUCT byte26; - CMD_DIGIT_BYTE_STRUCT byte27; - CMD_DIGIT_BYTE_STRUCT byte28; - CMD_DIGIT_BYTE_STRUCT byte29; - CMD_DIGIT_BYTE_STRUCT byte30; - CMD_DIGIT_BYTE_STRUCT byte31; - CMD_DIGIT_BYTE_STRUCT byte32; - CMD_DIGIT_BYTE_STRUCT byte33; - CMD_DIGIT_BYTE_STRUCT byte34; - } ANS_DIGIT_DATA_TO_TERMINAL_TEST_ALL_STRUCT; typedef struct diff --git a/Inu/Src/N12_Xilinx/RS_Functions.c b/Inu/Src/N12_Xilinx/RS_Functions.c index 0057622..7496ceb 100644 --- a/Inu/Src/N12_Xilinx/RS_Functions.c +++ b/Inu/Src/N12_Xilinx/RS_Functions.c @@ -1,5 +1,3 @@ -#include "params.h" -#include "global_time.h" #include "RS_Functions.h" #include @@ -18,9 +16,6 @@ #include "CRC_Functions.h" #include "TuneUpPlane.h" //светодиодик -#include "pwm_test_lines.h" -#include "profile_interrupt.h" - #define _ENABLE_INTERRUPT_RS232_LED2 0//1 @@ -29,8 +24,8 @@ #define RS232_SPEED 57600//115200 -#define COM_1 0 //1 -#define COM_2 1 //2 +#define COM_1 1 +#define COM_2 2 //#define SIZE_MODBUS_TABLE 334 //#define ADR_MODBUS_TABLE 0x0001 @@ -82,7 +77,8 @@ //#define SCIb_Wait4OK() while(!SCIb_OK()) #define SCIb_Send(a) ScibRegs.SCITXBUF = (unsigned char)a - +#define EnableReceiveRS485() GpioDataRegs.GPBDAT.bit.GPIOB14 = 1 +#define EnableSendRS485() GpioDataRegs.GPBDAT.bit.GPIOB14 = 0 #define SCIa_Get() SciaRegs.SCIRXBUF.bit.RXDT @@ -111,10 +107,10 @@ unsigned int RS_Len[RS_LEN_CMD] = {0}; char size_cmd15 = 1; char size_cmd16 = 1; -//unsigned int enable_profile_led1_rsa = 1; -//unsigned int enable_profile_led1_rsb = 1; -//unsigned int enable_profile_led2_rsa = 0; -//unsigned int enable_profile_led2_rsb = 0; +unsigned int enable_profile_led1_rsa = 1; +unsigned int enable_profile_led1_rsb = 1; +unsigned int enable_profile_led2_rsa = 0; +unsigned int enable_profile_led2_rsb = 0; @@ -125,8 +121,6 @@ int ADDR_FOR_ALL = ADDR_FOR_ALL_DEF; float KmodTerm = 0.0, freqTerm = 0.0; int flag_special_mode_rs = 0; -int disable_flag_special_mode_rs = 0; - void RS_Wait4OK_TXRDY(char commnumber); @@ -147,27 +141,6 @@ void RS_LineToSend(char commnumber); void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr); //int RS232_BSend(RS_DATA_STRUCT *RS232_Arr,unsigned int *pBuf, unsigned long len); - -void EnableReceiveRS485(void) -{ -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_19_ON; -#endif - - GpioDataRegs.GPBDAT.bit.GPIOB14 = 1; -} - -void EnableSendRS485(void) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_19_OFF; -#endif - - GpioDataRegs.GPBDAT.bit.GPIOB14 = 0; -} - - void T_Flash(RS_DATA_STRUCT *RS232_Arr) { volatile unsigned long Address1,Address2; @@ -338,12 +311,9 @@ void SCI_SwReset(char commnumber) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// -//static int buf_fifo_rsa[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; -//static int buf_fifo_rsb[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; +static int buf_fifo_rsa[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; +static int buf_fifo_rsb[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; -static int buf_fifo_rs_ab[2][17]={ {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0} }; - -#pragma CODE_SECTION(my_test_rs,".fast_run2"); int my_test_rs(int comn) { int cc=0; @@ -353,7 +323,7 @@ int my_test_rs(int comn) { while ((SciaRegs.SCIFFRX.bit.RXFIFST != 0) ) { - buf_fifo_rs_ab[comn][cc++] = SciaRegs.SCIRXBUF.bit.RXDT; + buf_fifo_rsa[cc++] = SciaRegs.SCIRXBUF.bit.RXDT; if (cc>=17) cc = 0; } return cc; @@ -362,7 +332,7 @@ int my_test_rs(int comn) { while ((ScibRegs.SCIFFRX.bit.RXFIFST != 0) ) { - buf_fifo_rs_ab[comn][cc++] = ScibRegs.SCIRXBUF.bit.RXDT; + buf_fifo_rsb[cc++] = ScibRegs.SCIRXBUF.bit.RXDT; if (cc>=17) cc = 0; } return cc; @@ -371,7 +341,6 @@ int my_test_rs(int comn) } /////////////// -//#pragma CODE_SECTION(RS_RXA_Handler_fast,".fast_run2"); void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) { char Rc; @@ -380,7 +349,6 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) //i_led2_on_off(1); - ClearTimerRS_Live(RS232_Arr); cn = RS232_Arr->commnumber; @@ -393,7 +361,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) if (SciaRegs.SCIRXST.bit.RXERROR) { // Rc = SciaRegs.SCIRXBUF.all; - (RS232_Arr->count_recive_rxerror)++; + RS232_Arr->count_recive_rxerror++; RS232_Arr->do_resetup_rs = 1; } if (SciaRegs.SCIRXST.bit.RXWAKE) @@ -407,7 +375,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) if (ScibRegs.SCIRXST.bit.RXERROR) { // Rc = SciaRegs.SCIRXBUF.all; - (RS232_Arr->count_recive_rxerror)++; + RS232_Arr->count_recive_rxerror++; RS232_Arr->do_resetup_rs = 1; } if (ScibRegs.SCIRXST.bit.RXWAKE) @@ -435,14 +403,12 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) // continue; // } cc1--; + if (cn==COM_1) + Rc = buf_fifo_rsa[cc2++];//SciaRegs.SCIRXBUF.all;// SciaRegs.SCIRXBUF.bit.RXDT;//RS_Get(RS232_Arr->commnumber); // Читаем символ в любом случае + else + Rc = buf_fifo_rsb[cc2++]; -// if (cn==COM_1) - Rc = buf_fifo_rs_ab[cn][cc2];//SciaRegs.SCIRXBUF.all;// SciaRegs.SCIRXBUF.bit.RXDT;//RS_Get(RS232_Arr->commnumber); // Читаем символ в любом случае -// else -// Rc = buf_fifo_rsb[cc2]; - cc2++; - - (RS232_Arr->count_recive_bytes_all)++; + RS232_Arr->count_recive_bytes_all++; //i_led2_on_off(0); if(RS232_Arr->RS_DataReady) @@ -462,7 +428,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) //i_led2_on_off(1); if(RS232_Arr->RS_FlagSkiping) { - (RS232_Arr->count_recive_bytes_skipped)++; + RS232_Arr->count_recive_bytes_skipped++; continue; // Не нам } @@ -482,10 +448,10 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) } else { -//i_led1_toggle(); +i_led1_toggle(); RS232_Arr->RS_FlagSkiping = true; // Не нашему контроллеру RS232_Arr->RS_FlagBegin = false; // остались в 9-бит режиме - (RS232_Arr->count_recive_cmd_skipped)++; + RS232_Arr->count_recive_cmd_skipped++; //i_led1_on_off(0); } //i_led2_on_off(1); @@ -524,7 +490,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) RS232_Arr->RS_FlagBegin = true; RS232_Arr->RS_FlagSkiping = false; RS232_Arr->RS_Cmd=0; - (RS232_Arr->count_recive_bad)++; + RS232_Arr->count_recive_bad++; continue; } if(RS232_Arr->RS_Cmd == 4) { @@ -544,7 +510,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) RS232_Arr->RS_FlagSkiping = true; RS232_Arr->RS_DataReady = true; RS232_Arr->RS_Cmd=0; - (RS232_Arr->count_recive_dirty)++; + RS232_Arr->count_recive_dirty++; } //i_led2_on_off(1); } @@ -559,14 +525,14 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) if(RS232_Arr->RS_PrevCmd != CMD_RS232_INITLOAD) { - (RS232_Arr->count_recive_bad)++; + RS232_Arr->count_recive_bad++; continue; // Мы здесь оказались по какой-то чудовищной ошибке } if(RS232_Arr->RS_DataReady) // Если данные в основном цикле не забраны, { // то пропускаем следующую посылку RS232_Arr->RS_FlagSkiping = true; // Игнорируем до следующего заголовка - (RS232_Arr->count_recive_cmd_skipped)++; + RS232_Arr->count_recive_cmd_skipped++; continue; } @@ -580,7 +546,7 @@ void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) RS_SetBitMode(RS232_Arr,9); // Получили все данные перестроились в 9-бит длЯ RS485? RS232_Arr->RS_FlagSkiping = true; // Игнорируем до следующего заголовка RS232_Arr->RS_DataReady = true; // Флаг в основной цикл - данные получены - (RS232_Arr->count_recive_dirty)++; + RS232_Arr->count_recive_dirty++; } } } @@ -603,20 +569,15 @@ int get_free_rs_fifo_tx(char commnumber) void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) { char RS232_BytePtr; - unsigned int final_flag=0, free_fifo; - unsigned int i; + int final_flag=0, free_fifo; + int i; - static unsigned int max_s_b = 1; // посылаем по max_s_b штук - unsigned int final_free_fifo=0; // if(RS232_Arr->RS_SendBlockMode == BM_CHAR32) // { free_fifo = get_free_rs_fifo_tx(RS232_Arr->commnumber); ClearTimerRS_Live(RS232_Arr); - if (free_fifo>=max_s_b) - free_fifo=max_s_b; // посылаем по max_s_b штук - for (i=0;icommnumber,*(RS232_Arr->pRS_SendPtr_stage1++)); - (RS232_Arr->RS_SendLen)++; + RS232_Arr->RS_SendLen++; break; } break; @@ -663,7 +624,7 @@ void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) else SCI_Send(RS232_Arr->commnumber,*(RS232_Arr->pRS_SendPtr_stage2++)); - (RS232_Arr->RS_SendLen)++; + RS232_Arr->RS_SendLen++; break; } break; @@ -687,7 +648,7 @@ void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) else SCI_Send(RS232_Arr->commnumber,*(RS232_Arr->pRS_SendPtr++)); - (RS232_Arr->RS_SendLen)++; + RS232_Arr->RS_SendLen++; } break; default : @@ -700,14 +661,10 @@ void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) if (final_flag) { - final_free_fifo = get_free_rs_fifo_tx(RS232_Arr->commnumber); - - if (final_free_fifo>=15) // все уехали? буфер чист? - { if(RS232_Arr->RS_SendBlockMode == BM_CHAR32) { -// if (max_s_b>1) -// RS_Wait4OK(RS232_Arr->commnumber); + // RS_Wait4OK_TXRDY(RS232_Arr->commnumber); + RS_Wait4OK(RS232_Arr->commnumber); RS_SetBitMode(RS232_Arr,9); /* Передали все перестроились в 9-бит длЯ RS485?*/ RS_LineToReceive(RS232_Arr->commnumber); /* режим приема RS485 */ @@ -721,7 +678,6 @@ void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) EnableUART_Int_RX(RS232_Arr->commnumber); /* Запрещаем прерываниЯ по передаче */ } - } } // @@ -731,7 +687,6 @@ void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -//#pragma CODE_SECTION(RSA_TX_Handler,".fast_run2"); interrupt void RSA_TX_Handler(void) { // Set interrupt priority: @@ -746,16 +701,14 @@ i_led2_on_off(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsa) + if (enable_profile_led1_rsa) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsa) + if (enable_profile_led2_rsa) i_led2_on_off_special(1); #endif - - EINT; @@ -778,11 +731,11 @@ i_led2_on_off(1); PieCtrlRegs.PIEIER9.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsa) + if (enable_profile_led1_rsa) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsa) + if (enable_profile_led2_rsa) i_led2_on_off_special(0); #endif @@ -791,13 +744,13 @@ i_led2_on_off(1); i_led2_on_off(0); #endif + } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -//#pragma CODE_SECTION(RSB_TX_Handler,".fast_run2"); interrupt void RSB_TX_Handler(void) { // Set interrupt priority: @@ -807,20 +760,17 @@ interrupt void RSB_TX_Handler(void) PieCtrlRegs.PIEIER9.all &= MG94; // Set "group" priority PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_16_ON; -#endif #if (_ENABLE_INTERRUPT_RS232_LED2) i_led2_on_off(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsb) + if (enable_profile_led1_rsb) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsb) + if (enable_profile_led2_rsb) i_led2_on_off_special(1); #endif @@ -846,11 +796,11 @@ i_led2_on_off(1); #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsb) + if (enable_profile_led1_rsb) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsb) + if (enable_profile_led2_rsb) i_led2_on_off_special(0); #endif @@ -858,17 +808,11 @@ i_led2_on_off(1); i_led2_on_off(0); #endif -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_16_OFF; -#endif - - } /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -//#pragma CODE_SECTION(RSA_RX_Handler,".fast_run2"); interrupt void RSA_RX_Handler(void) { // Set interrupt priority: @@ -884,11 +828,11 @@ i_led2_on_off(1); #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsa) + if (enable_profile_led1_rsa) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsa) + if (enable_profile_led2_rsa) i_led2_on_off_special(1); #endif @@ -920,11 +864,11 @@ i_led2_on_off(1); PieCtrlRegs.PIEIER9.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsa) + if (enable_profile_led1_rsa) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsa) + if (enable_profile_led2_rsa) i_led2_on_off_special(0); #endif @@ -938,7 +882,7 @@ i_led2_on_off(0); /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// -//#pragma CODE_SECTION(RSB_RX_Handler,".fast_run2"); + interrupt void RSB_RX_Handler(void) { // Set interrupt priority: @@ -948,23 +892,17 @@ interrupt void RSB_RX_Handler(void) PieCtrlRegs.PIEIER9.all &= MG93; // Set "group" priority PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts - -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_17_ON; -#endif - - #if (_ENABLE_INTERRUPT_RS232_LED2) i_led2_on_off(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsb) + if (enable_profile_led1_rsb) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsb) + if (enable_profile_led2_rsb) i_led2_on_off_special(1); #endif @@ -987,11 +925,11 @@ i_led2_on_off(1); #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.rsb) + if (enable_profile_led1_rsb) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.rsb) + if (enable_profile_led2_rsb) i_led2_on_off_special(0); #endif @@ -999,9 +937,6 @@ i_led2_on_off(1); i_led2_on_off(0); #endif -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_17_OFF; -#endif } @@ -1120,10 +1055,6 @@ float SciBaud; ////////////////////////////////////////////////////// void EnableUART_Int_RX(char commnumber) { -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_18_ON; -#endif - switch (commnumber) { case COM_1: //SciaRegs.SCICTL2.bit.RXBKINTENA = 0;//1; //enableUARTInt_A(); @@ -1154,10 +1085,6 @@ void EnableUART_Int_RX(char commnumber) void EnableUART_Int_TX(char commnumber) { -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_18_OFF; -#endif - switch (commnumber) { case COM_1: rs_a.RS_OnTransmitedData = 1; @@ -1372,31 +1299,22 @@ int test_rs_live(RS_DATA_STRUCT *rs_arr) void inc_RS_timeout_cicle(void) { - unsigned int i, t_refresh; - static unsigned int old_time_rs = 0; - - t_refresh = get_delta_milisec(&old_time_rs, 1); - if (t_refresh>1000) - t_refresh = 1000; - if (t_refresh<1) - t_refresh = 1; - if (rs_a.time_wait_rs_outRS_Header[i] = 0; - - for (i=0;ibuffer[i] = 0; - -} - -/////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////// #ifdef _USE_RS_FIFO void SetupUART(char commnumber, unsigned long speed_baud) @@ -1535,7 +1440,6 @@ void SetupUART(char commnumber, unsigned long speed_baud) EDIS; SetupArrCmdLength(); - clear_buffers_rs(&rs_a); RS_SetControllerLeading(&rs_a,false); @@ -1549,7 +1453,66 @@ void SetupUART(char commnumber, unsigned long speed_baud) resetup_mpu_rs(&rs_a); +/////// +// +//// enable TX, RX, internal SCICLK, +//// Disable RX ERR, SLEEP, TXWAKE +// SciaRegs.SCIFFCT.bit.ABDCLR=1; +// SciaRegs.SCIFFCT.bit.CDC=0; +// +// SciaRegs.SCICTL1.bit.RXERRINTENA=0; +// SciaRegs.SCICTL1.bit.SWRESET=0; +// SciaRegs.SCICTL1.bit.TXWAKE=0; +// SciaRegs.SCICTL1.bit.SLEEP=0; +// SciaRegs.SCICTL1.bit.TXENA=1; +// SciaRegs.SCICTL1.bit.RXENA=1; +// +//// +//// SciaRegs.SCIFFTX.all=0xC028; +// SciaRegs.SCIFFRX.all=0x0000; +// +// SciaRegs.SCIFFRX.bit.RXFFIL=2; //Длина наименьшей команды +// SciaRegs.SCIFFRX.bit.RXFFIENA = 1;//Receive FIFO interrupt enable +// SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1;//Write 1 to clear RXFFINT flag in bit 7 +// +// SciaRegs.SCIFFCT.all=0x00; +// +// +// +//// SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset +//// SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; +// +//// +// +// SciaRegs.SCIFFTX.bit.SCIFFENA=0; // TX fifo off +// +// EALLOW; +// PieVectTable.RXAINT = &RSA_RX_Handler; +// PieVectTable.TXAINT = &RSA_TX_Handler; +// PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1 +// PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2 +// IER |= M_INT9; // Enable CPU INT +// EDIS; +// +// SetupArrCmdLength(); +// RS_SetLineSpeed(commnumber,speed_baud); /* скорость линии */ +// RS_SetControllerLeading(&rs_a,false); +// +// RS_LineToReceive(commnumber); // режим приема RS485 +// EnableUART_Int(commnumber); // разрешение прерываний UART +// +// RS_SetBitMode(&rs_a,9); +// rs_a.RS_PrevCmd = 0; // не было никаких команд +// SCI_RX_IntClear(commnumber); +// +// SciaRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset +//// SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; +//// SciaRegs.SCIFFRX.bit.RXFIFORESET=1; +// +// SciaRegs.SCIFFRX.bit.RXFIFORESET=1; // Re-enable receive FIFO operation +// +// } @@ -1635,8 +1598,6 @@ void SetupUART(char commnumber, unsigned long speed_baud) EDIS; SetupArrCmdLength(); - clear_buffers_rs(&rs_b); - RS_SetControllerLeading(&rs_b,false); @@ -1653,7 +1614,64 @@ void SetupUART(char commnumber, unsigned long speed_baud) } +/* + if(commnumber==COM_2) + { +// Initialize SCI-B: +// Note: Clocks were turned on to the SCIA peripheral +// in the InitSysCtrl() function + EALLOW; + GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5=1; + GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4=1; + GpioMuxRegs.GPBMUX.bit.C5TRIP_GPIOB14=0; + + GpioMuxRegs.GPBDIR.bit.GPIOB14=1; + + EDIS; + RS_SetLineMode(commnumber,8,'N',1); + +// enable TX, RX, internal SCICLK, +// Disable RX ERR, SLEEP, TXWAKE + ScibRegs.SCIFFCT.bit.CDC=0; + ScibRegs.SCIFFCT.bit.ABDCLR=1; + ScibRegs.SCICTL1.bit.RXERRINTENA=0; + ScibRegs.SCICTL1.bit.SWRESET=0; + ScibRegs.SCICTL1.bit.TXWAKE=0; + ScibRegs.SCICTL1.bit.SLEEP=0; + ScibRegs.SCICTL1.bit.TXENA=1; + ScibRegs.SCICTL1.bit.RXENA=1; + + ScibRegs.SCIFFTX.bit.SCIFFENA=0; // fifo off + ScibRegs.SCIFFRX.bit.RXFFIL=1; //Длина наименьшей команды + + EALLOW; + PieVectTable.RXBINT = &RSB_RX_Handler; + PieVectTable.TXBINT = &RSB_TX_Handler; + + PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3 + PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4 + IER |= M_INT9; // Enable CPU INT + EDIS; + + SetupArrCmdLength(); + RS_SetLineSpeed(commnumber,speed_baud); // скорость линии + RS_SetControllerLeading(&rs_b,false); + + RS_LineToReceive(commnumber); // режим приема RS485 + EnableUART_Int(commnumber); // разрешение прерываний UART + + RS_SetBitMode(&rs_b,9); + rs_b.RS_PrevCmd = 0; // не было никаких команд + SCI_RX_IntClear(commnumber); + + ScibRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset + +// SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; +// SciaRegs.SCIFFRX.bit.RXFIFORESET=1; + + } +*/ } #else @@ -2000,7 +2018,7 @@ int GetCommand(RS_DATA_STRUCT *RS232_Arr) // ПроверЯем длину команды длЯ считываниЯ CRC if((RS_Len[cmd]<3) || (RS_Len[cmd]>MAX_RECEIVE_LENGTH)) { - (RS232_Arr->count_recive_bad)++; + RS232_Arr->count_recive_bad++; RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 RS_SetBitMode(RS232_Arr,9); @@ -2029,7 +2047,7 @@ int GetCommand(RS_DATA_STRUCT *RS232_Arr) if(crc == rcrc) // ПроверЯем crc { - (RS232_Arr->count_recive_ok)++; + RS232_Arr->count_recive_ok++; RS232_Arr->RS_PrevCmd = cmd; if (RS232_Arr->RS_DataSended) @@ -2041,7 +2059,7 @@ int GetCommand(RS_DATA_STRUCT *RS232_Arr) } else { - (RS232_Arr->count_recive_error_crc)++; + RS232_Arr->count_recive_error_crc++; RS_SetAdrAnswerController(RS232_Arr,0); RS_SetControllerLeading(RS232_Arr, false); @@ -2065,8 +2083,7 @@ void ExtendBios(RS_DATA_STRUCT *RS232_Arr) unsigned long AdrOut1,AdrOut2,LengthOut; unsigned int cerr, repl, count_ok, return_code, old_started; - volatile unsigned int go_to_reset = 0, go_to_set_baud = 0; - unsigned long set_baud; + volatile unsigned int go_to_reset = 0; //int code_eeprom; old_started = x_parallel_bus_project.flags.bit.started; @@ -2210,18 +2227,6 @@ void ExtendBios(RS_DATA_STRUCT *RS232_Arr) break; - case 100: - go_to_set_baud = 1; - set_baud = Address1; -// SetLoad28_FromResetInternalFlash(); -// SelectReset28(); - //speed_baud = Address1; - - - break; - - - default: break; } @@ -2276,23 +2281,6 @@ void ExtendBios(RS_DATA_STRUCT *RS232_Arr) } - - if (go_to_set_baud) - { - // for (i=0;i<2;i++) - DELAY_US(1000000); - -// DRTM; -// DINT; - -// for (i=0;i<2;i++) -// DELAY_US(1000000); - - RS_SetLineSpeed(RS232_Arr->commnumber, set_baud); /* скорость линии */ - - go_to_set_baud = 0; - - } return; } @@ -2321,7 +2309,7 @@ int RS_Send(RS_DATA_STRUCT *RS232_Arr,unsigned int *pBuf,unsigned long len) if (RS232_Arr->RS_DataWillSend) { -// RS232_Arr->RS_DataReadyAnswer = 0; + RS232_Arr->RS_DataReadyAnswer = 0; RS232_Arr->RS_DataReadyAnswer = 0; RS232_Arr->RS_DataSended = 0; } @@ -2384,31 +2372,10 @@ void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsig switch (GetCommand(&rs_a)) { case CMD_RS232_INIT: break; - - case CMD_RS232_INITLOAD: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - InitLoad(&rs_a); - break; - - case CMD_RS232_LOAD: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - Load(&rs_a); - break; - + case CMD_RS232_INITLOAD: flag_special_mode_rs = 1; InitLoad(&rs_a); break; + case CMD_RS232_LOAD: flag_special_mode_rs = 1; Load(&rs_a); break; case CMD_RS232_RUN: break; - - case CMD_RS232_PEEK: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - Peek(&rs_a); + case CMD_RS232_PEEK: flag_special_mode_rs = 1; Peek(&rs_a); //Led1_Toggle(); break; @@ -2429,47 +2396,16 @@ void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsig #if (USE_TEST_TERMINAL) case CMD_RS232_STD: - rs_a.RS_DataReadyRequest = 1; - flag_special_mode_rs = 0; - ReceiveCommand(&rs_a); - break; - - case CMD_RS232_TEST_ALL: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - ReceiveCommandTestAll(&rs_a); - break; + rs_a.RS_DataReadyRequest = 1; + flag_special_mode_rs = 0; + ReceiveCommand(&rs_a); + break; + case CMD_RS232_TEST_ALL: flag_special_mode_rs = 1; ReceiveCommandTestAll(&rs_a); break; #endif - case CMD_RS232_POKE: - if (disable_flag_special_mode_rs) - break; - - - flag_special_mode_rs = 1; - Poke(&rs_a); - Led2_Toggle(); - break; - case CMD_RS232_UPLOAD: -// flag_special_mode_rs = 1; - Upload(&rs_a); - break; - case CMD_RS232_TFLASH: - if (disable_flag_special_mode_rs) - break; - - - flag_special_mode_rs = 1; - T_Flash(&rs_a); - break; - case CMD_RS232_EXTEND: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - ExtendBios(&rs_a); - break; + case CMD_RS232_POKE: flag_special_mode_rs = 1; Poke(&rs_a); Led2_Toggle(); break; + case CMD_RS232_UPLOAD: flag_special_mode_rs = 1; Upload(&rs_a); break; + case CMD_RS232_TFLASH: flag_special_mode_rs = 1; T_Flash(&rs_a); break; + case CMD_RS232_EXTEND: flag_special_mode_rs = 1; ExtendBios(&rs_a); break; default: break; } // end switch @@ -2482,31 +2418,10 @@ void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsig switch (GetCommand(&rs_b)) { case CMD_RS232_INIT: break; - - case CMD_RS232_INITLOAD: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - InitLoad(&rs_b); - break; - - case CMD_RS232_LOAD: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - Load(&rs_b); - break; - + case CMD_RS232_INITLOAD: flag_special_mode_rs = 1; InitLoad(&rs_b); break; + case CMD_RS232_LOAD: flag_special_mode_rs = 1; Load(&rs_b); break; case CMD_RS232_RUN: break; - case CMD_RS232_PEEK: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - Peek(&rs_b); - break; + case CMD_RS232_PEEK: flag_special_mode_rs = 1; Peek(&rs_b); break; #if USE_MODBUS_TABLE_SVU @@ -2593,43 +2508,13 @@ void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsig #endif #if (USE_TEST_TERMINAL) - case CMD_RS232_STD: flag_special_mode_rs = 0; - ReceiveCommand(&rs_b); - break; - case CMD_RS232_TEST_ALL: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - ReceiveCommandTestAll(&rs_b); - break; + case CMD_RS232_STD: flag_special_mode_rs = 0; ReceiveCommand(&rs_b); break; + case CMD_RS232_TEST_ALL: flag_special_mode_rs = 1; ReceiveCommandTestAll(&rs_b); break; #endif - case CMD_RS232_POKE: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - Poke(&rs_b); - break; - case CMD_RS232_UPLOAD: -// flag_special_mode_rs = 1; - - Upload(&rs_b); - break; - case CMD_RS232_TFLASH: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - T_Flash(&rs_b); - break; - case CMD_RS232_EXTEND: - if (disable_flag_special_mode_rs) - break; - - flag_special_mode_rs = 1; - ExtendBios(&rs_b); - break; + case CMD_RS232_POKE: flag_special_mode_rs = 1; Poke(&rs_b); break; + case CMD_RS232_UPLOAD: flag_special_mode_rs = 1; Upload(&rs_b); break; + case CMD_RS232_TFLASH: flag_special_mode_rs = 1; T_Flash(&rs_b); break; + case CMD_RS232_EXTEND: flag_special_mode_rs = 1; ExtendBios(&rs_b); break; default: break; } // end switch diff --git a/Inu/Src/N12_Xilinx/RS_Functions.h b/Inu/Src/N12_Xilinx/RS_Functions.h index e98725e..9b285d2 100644 --- a/Inu/Src/N12_Xilinx/RS_Functions.h +++ b/Inu/Src/N12_Xilinx/RS_Functions.h @@ -94,14 +94,13 @@ typedef struct { unsigned int do_resetup_rs; // выполнить пересброс порта при ошибках. - int RS_DataWillSend2; // флаг2, что мы подготовили свой запрос и сейчас начнем его передавать и мы мастер } RS_DATA_STRUCT; -#define RS_DATA_STRUCT_DEFAULT {0,0,0,0,0,0,0,0,0,{0}, 0,0,0,{0},{0}, 0,0,0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0, 0,0,0, 0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0} +#define RS_DATA_STRUCT_DEFAULT {0,0,0,0,0,0,0,0,0,{0}, 0,0,0,{0},{0}, 0,0,0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0, 0,0,0, 0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0} ////////////////////////////////////////////////////////// #define TMS_TO_TERMINAL_TEST_ALL_STRUCT_DEFAULT {{0}, {0}, {0}, 0, 0, 0} @@ -137,6 +136,6 @@ void SetCntrlAddr (int cntrl_addr,int cntrl_addr_for_all); extern float KmodTerm, freqTerm; extern unsigned int RS_Len[RS_LEN_CMD]; -extern int flag_special_mode_rs, disable_flag_special_mode_rs; +extern int flag_special_mode_rs; #endif diff --git a/Inu/Src/N12_Xilinx/Spartan2E_Functions.c b/Inu/Src/N12_Xilinx/Spartan2E_Functions.c index 9da7fa4..679d1aa 100644 --- a/Inu/Src/N12_Xilinx/Spartan2E_Functions.c +++ b/Inu/Src/N12_Xilinx/Spartan2E_Functions.c @@ -638,32 +638,6 @@ void xseeprom_delay(void) pause_1000(10000); } -void ResetNPeriphPlane(unsigned int np) -{ - - Controll.bit.line_P7_4_Is = np; - - Controll.bit.OE_BUF_Is_ON = 1; - Controll.bit.line_Z_ER0_OUT_Is = 0; - Controll.bit.line_SET_MODE_Is = 1; - xControll_wr(); - pause_1000(10000); - - - - Controll.bit.line_P7_4_Is = 0x0; - Controll.bit.line_Z_ER0_OUT_Is = 1; - xControll_wr(); - - - -// Controll.bit.RemotePlane_Is_Reset = 1; - xControll_wr(); - pause_1000(10000); -// Controll.bit.RemotePlane_Is_Reset = 0; - Controll.bit.line_P7_4_Is = 0x0; -} - void ResetPeriphPlane() { Controll.bit.line_P7_4_Is = 0xf; diff --git a/Inu/Src/N12_Xilinx/Spartan2E_Functions.h b/Inu/Src/N12_Xilinx/Spartan2E_Functions.h index be1577a..224a3b6 100644 --- a/Inu/Src/N12_Xilinx/Spartan2E_Functions.h +++ b/Inu/Src/N12_Xilinx/Spartan2E_Functions.h @@ -257,8 +257,5 @@ int test_xilinx_live(void); int enable_er0_control(void); -void ResetNPeriphPlane(unsigned int np); - - #endif diff --git a/Inu/Src/N12_Xilinx/TuneUpPlane.c b/Inu/Src/N12_Xilinx/TuneUpPlane.c index 9dd05b3..07d183c 100644 --- a/Inu/Src/N12_Xilinx/TuneUpPlane.c +++ b/Inu/Src/N12_Xilinx/TuneUpPlane.c @@ -134,7 +134,7 @@ void pause_1000(unsigned long t) DSP28x_usDelay(40L); } } -//Xilinx Zone + void XintfZone0_Timing(void) { // Zone 0------------------------------------ @@ -256,12 +256,12 @@ void XintfZone2_Timing(void) // Lead must always be 1 or greater // Zone write timing XintfRegs.XTIMING2.bit.XWRLEAD = 3;//2; - XintfRegs.XTIMING2.bit.XWRACTIVE = 4;//2; - XintfRegs.XTIMING2.bit.XWRTRAIL = 2;//2; + XintfRegs.XTIMING2.bit.XWRACTIVE = 7;//2; + XintfRegs.XTIMING2.bit.XWRTRAIL = 3;//2; // Zone read timing - XintfRegs.XTIMING2.bit.XRDLEAD = 2; - XintfRegs.XTIMING2.bit.XRDACTIVE = 3; //1; - XintfRegs.XTIMING2.bit.XRDTRAIL = 1;//2;//0; + XintfRegs.XTIMING2.bit.XRDLEAD = 3; + XintfRegs.XTIMING2.bit.XRDACTIVE = 7; //1; + XintfRegs.XTIMING2.bit.XRDTRAIL = 3;//2;//0; // do not double all Zone read/write lead/active/trail timing XintfRegs.XTIMING2.bit.X2TIMING = 0; diff --git a/Inu/Src/N12_Xilinx/x_int13.c b/Inu/Src/N12_Xilinx/x_int13.c index fe5f9d1..676d890 100644 --- a/Inu/Src/N12_Xilinx/x_int13.c +++ b/Inu/Src/N12_Xilinx/x_int13.c @@ -9,11 +9,7 @@ #include "MemoryFunctions.h" #include "Spartan2E_Adr.h" #include "TuneUpPlane.h" -#include "xp_write_xpwm_time.h" -#include "params.h" -#include "pwm_test_lines.h" -#include "sync_tools.h" -#include "profile_interrupt.h" + //Pointers to handler functions void (*int13_handler)() = NULL; @@ -24,8 +20,8 @@ void (*int13_handler)() = NULL; ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// -//unsigned int enable_profile_led1_pwm = 1; -//unsigned int enable_profile_led2_pwm = 1; +unsigned int enable_profile_led1_pwm = 1; +unsigned int enable_profile_led2_pwm = 1; @@ -55,59 +51,21 @@ int InitXilinxSpartan2E(void (*int_handler)()) return err; } -#pragma CODE_SECTION(XIntc_INT13_Handler,".fast_run2"); interrupt void XIntc_INT13_Handler(void) { - static int l2; IER &= MINT13; // Set "global" priority - if (xpwm_time.disable_sync_out==0) - { - if (xpwm_time.do_sync_out) - { - i_sync_pin_on(); - - #if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_17_ON; - #endif - - - } - else - { - i_sync_pin_off(); - - #if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_17_OFF; - #endif - - } - } - - if (xpwm_time.what_next_interrupt==PWM_LOW_LEVEL_INTERRUPT) - { - l2 = 1; - } - else - l2 = 0; - - #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.pwm && l2) + if (enable_profile_led1_pwm) i_led1_on_off_special(1); #endif - #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.pwm && l2) - i_led2_on_off_special(1); - + if (enable_profile_led2_pwm) + i_led2_on_off_special(1); #endif - - - EINT; // Insert ISR Code here....... @@ -157,13 +115,12 @@ interrupt void XIntc_INT13_Handler(void) #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.pwm) + if (enable_profile_led1_pwm) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.pwm) - if (l2) - i_led2_on_off_special(0); + if (enable_profile_led2_pwm) + i_led2_on_off_special(0); #endif diff --git a/Inu/Src/N12_Xilinx/x_parallel_bus.h b/Inu/Src/N12_Xilinx/x_parallel_bus.h index 493b96b..33520c2 100644 --- a/Inu/Src/N12_Xilinx/x_parallel_bus.h +++ b/Inu/Src/N12_Xilinx/x_parallel_bus.h @@ -116,7 +116,6 @@ extern X_PARALLEL_BUS x_parallel_bus_project; // ver 2 #define read_pbus_value_v2(bit,adr,res) {if (bit) { res = i_ReadMemory(adr); i_WriteMemory(adr++,0x0); } else res = 0; } #define read_pbus_value_full_v2(bit,adr,res) {res = i_ReadMemory(adr); i_WriteMemory(adr++,0x0); } -#define read_pbus_value_full_v3(bit,adr,res) {res = i_ReadMemory(adr++); } #define read_pbus_adc_value_v2(bit,adr,res) {if (bit) { res = i_ReadMemory(adr) & 0xfff; i_WriteMemory(adr++,0x0);} else res = 0; } #define read_pbus_adc_value_full_v2(bit,adr,res) {res = i_ReadMemory(adr) & 0xfff; i_WriteMemory(adr++,0x0); } diff --git a/Inu/Src/N12_Xilinx/xp_cds_in.c b/Inu/Src/N12_Xilinx/xp_cds_in.c index 96a2c35..f6f19c4 100644 --- a/Inu/Src/N12_Xilinx/xp_cds_in.c +++ b/Inu/Src/N12_Xilinx/xp_cds_in.c @@ -327,33 +327,123 @@ int cds_in_read_pbus(T_cds_in *v) if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) { - adr_pbus = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; + adr_pbus = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; - if ((v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) && (v->type_plate == cds_in_type_in_1)) - { - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus, t); - v->read.pbus.data_in.all = (t & 0xff00) | ((~t) & 0x00ff); - } - else - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.data_in.all); + if ((v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) && (v->type_plate == cds_in_type_in_1)) + { + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus, t); + v->read.pbus.data_in.all = (t & 0xff00) | ((~t) & 0x00ff); + } + else + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.data_in.all); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.ready_in.all); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.direction_in.all); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.SpeedS1_cnt); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.SpeedS1_cnt90); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.SpeedS2_cnt); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg6,adr_pbus,v->read.pbus.SpeedS2_cnt90); - if ((v->type_cds_xilinx == TYPE_CDS_XILINX_SP6)) - { - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg7,adr_pbus,v->read.pbus.Time_since_zero_point_S1); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg8,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S1); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg9,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S1); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg10,adr_pbus,v->read.pbus.Time_since_zero_point_S2); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg11,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S2); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg12,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S2); - read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg13,adr_pbus,v->read.pbus.channel_alive.all); - } + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.ready_in.all); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.direction_in.all); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.SpeedS1_cnt); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.SpeedS1_cnt90); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.SpeedS2_cnt); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg6,adr_pbus,v->read.pbus.SpeedS2_cnt90); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg7,adr_pbus,v->read.pbus.Time_since_zero_point_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg8,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg9,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg10,adr_pbus,v->read.pbus.Time_since_zero_point_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg11,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg12,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg13,adr_pbus,v->read.pbus.channel_alive.all); +/* +//0 + if (v->setup_pbus.use_reg_in_pbus.bit.reg0) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[0]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.data_in.all = x_parallel_bus_project.data_table_read; + } +//1 + if (v->setup_pbus.use_reg_in_pbus.bit.reg1) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[1]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.ready_in.all = x_parallel_bus_project.data_table_read; + } +//2 + if (v->setup_pbus.use_reg_in_pbus.bit.reg2) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[2]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.direction_in.all = x_parallel_bus_project.data_table_read; + } +//3 + if (v->setup_pbus.use_reg_in_pbus.bit.reg3) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[3]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.SpeedS1_cnt = x_parallel_bus_project.data_table_read; + } +//4 + if (v->setup_pbus.use_reg_in_pbus.bit.reg4) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[4]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.SpeedS1_cnt90 = x_parallel_bus_project.data_table_read; + } +//5 + if (v->setup_pbus.use_reg_in_pbus.bit.reg5) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[5]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.SpeedS2_cnt = x_parallel_bus_project.data_table_read; + } +//6 + if (v->setup_pbus.use_reg_in_pbus.bit.reg6) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[6]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.SpeedS2_cnt90 = x_parallel_bus_project.data_table_read; + } +//7 + if (v->setup_pbus.use_reg_in_pbus.bit.reg7) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[7]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_S1 = x_parallel_bus_project.data_table_read; + } +//8 + if (v->setup_pbus.use_reg_in_pbus.bit.reg8) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[8]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_Rising_S1 = x_parallel_bus_project.data_table_read; + } +//9 + if (v->setup_pbus.use_reg_in_pbus.bit.reg9) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[9]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_Falling_S1 = x_parallel_bus_project.data_table_read; + } +//10 + if (v->setup_pbus.use_reg_in_pbus.bit.reg10) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[10]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_S2 = x_parallel_bus_project.data_table_read; + } +//11 + if (v->setup_pbus.use_reg_in_pbus.bit.reg11) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[11]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_Rising_S2 = x_parallel_bus_project.data_table_read; + } +//12 + if (v->setup_pbus.use_reg_in_pbus.bit.reg12) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[12]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.Time_since_zero_point_Falling_S2 = x_parallel_bus_project.data_table_read; + } +*/ } else { diff --git a/Inu/Src/N12_Xilinx/xp_cds_tk_23550.c b/Inu/Src/N12_Xilinx/xp_cds_tk_23550.c index ea8424b..f7b97be 100644 --- a/Inu/Src/N12_Xilinx/xp_cds_tk_23550.c +++ b/Inu/Src/N12_Xilinx/xp_cds_tk_23550.c @@ -64,12 +64,6 @@ int cds_tk_write_sbus_23550(T_cds_tk_23550 *v) v->status_serial_bus.count_write_error++; -//10 time_after_err - x_serial_bus_project.reg_addr = 10; // adr memory in plate - x_serial_bus_project.write_data = v->write.sbus.time_after_err; // write data - - if (x_serial_bus_project.write(&x_serial_bus_project)) // make write - v->status_serial_bus.count_write_error++; @@ -199,25 +193,6 @@ int cds_tk_read_sbus_23550(T_cds_tk_23550 *v) else v->status_serial_bus.count_read_error++; -//9 id_plate - x_serial_bus_project.reg_addr = 9; // adr memory in plate - x_serial_bus_project.read(&x_serial_bus_project); // read - - if (x_serial_bus_project.flags.bit.read_error == 0) // check error - v->read.sbus.id_plate.all = x_serial_bus_project.read_data; - else - v->status_serial_bus.count_read_error++; - -//10 time_after_err - x_serial_bus_project.reg_addr = 10; // adr memory in plate - x_serial_bus_project.read(&x_serial_bus_project); // read - - if (x_serial_bus_project.flags.bit.read_error == 0) // check error - v->read.sbus.time_after_err = x_serial_bus_project.read_data; - else - v->status_serial_bus.count_read_error++; - - //11 time_err_tk_all x_serial_bus_project.reg_addr = 11; // adr memory in plate x_serial_bus_project.read(&x_serial_bus_project); // read @@ -266,7 +241,7 @@ int cds_tk_read_pbus_23550(T_cds_tk_23550 *v) { unsigned long adr_pbus; - if (v->useit == 0 || v->setup_pbus.use_reg_in_pbus.all==0) + if (v->useit == 0) return 0; if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) @@ -275,12 +250,12 @@ int cds_tk_read_pbus_23550(T_cds_tk_23550 *v) if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) { adr_pbus = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.status1.all); - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.DataReg0.all); - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.DataReg1.all); - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.DataReg2.all); - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.DataReg3.all); - read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.status2.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.status1.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.DataReg0.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.DataReg1.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.DataReg2.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.DataReg3.all); + read_pbus_value_full_v2(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.status2.all); } } else @@ -338,9 +313,8 @@ void cds_tk_optical_bus_check_error_read(T_cds_tk_23550 *v) if ( v->optical_data_in.status_1.bit.id_sbus == v->optical_data_in.status_2.bit.id_sbus && v->optical_data_in.status_1.bit.id == v->optical_data_in.status_2.bit.id -// && (v->read.pbus.status1.bit.receiver_error==0) -// && (v->read.pbus.status2.bit.receiver_error==0) - ) + && (v->read.pbus.status1.bit.receiver_error==0) + && (v->read.pbus.status2.bit.receiver_error==0) ) { // если выставился этот бит, то знвчит приемник в приеме данных, но т.к. эти данные мы получаем по PBUS с некоторым лагом // смысл этого бита теряет свой смысл, просто как информация, данные мы получим всегда последние удачные. @@ -352,17 +326,10 @@ void cds_tk_optical_bus_check_error_read(T_cds_tk_23550 *v) // data old v->optical_data_in.status_read.bit.old_data = 1; v->optical_data_in.same_id_count += 1; - - if (v->optical_data_in.same_id_count_between < v->optical_data_in.setup_count_error_between) - v->optical_data_in.same_id_count_between += 1; - else - // читали все время старые данные, передатчик умер на той стороне? - v->optical_data_in.ready = 0; } else { // очистка ошибок - v->optical_data_in.same_id_count_between = 0; v->optical_data_in.local_count_error = 0; v->optical_data_in.raw_local_error = 0; v->optical_data_in.ready = 1; diff --git a/Inu/Src/N12_Xilinx/xp_cds_tk_23550.h b/Inu/Src/N12_Xilinx/xp_cds_tk_23550.h index f12da6d..0d13050 100644 --- a/Inu/Src/N12_Xilinx/xp_cds_tk_23550.h +++ b/Inu/Src/N12_Xilinx/xp_cds_tk_23550.h @@ -99,9 +99,7 @@ typedef struct { UInt16 all; struct { - UInt16 reserv :8; - UInt16 detect_soft_disconnect :1; - UInt16 enable_soft_disconnect :1; + UInt16 reserv :10; UInt16 enable_line_err :1; UInt16 disable_err_mintime :1; UInt16 disable_err_hwp :1; @@ -113,8 +111,7 @@ typedef struct { //7 UInt16 cmd_reset_error; -//10 - UInt16 time_after_err; //time_after_err = 4000<-DEC * 0.02 = 80mc +// } T_cds_tk_write_sbus_23550; @@ -198,9 +195,7 @@ typedef struct { UInt16 all; struct { - UInt16 reserv :8; - UInt16 detect_soft_disconnect :1; - UInt16 enable_soft_disconnect :1; + UInt16 reserv :10; UInt16 enable_line_err :1; UInt16 disable_err_mintime :1; UInt16 disable_err_hwp :1; @@ -266,9 +261,7 @@ typedef struct { UInt16 all; struct { - UInt16 reserv :5; - UInt16 ErrorSoftShutdownForbidComb :1; - UInt16 ErrorSoftShutdownFromErr0 :1; + UInt16 reserv :7; UInt16 line_err_keys_3210 :1; UInt16 line_err_keys_7654 :1; UInt16 mintime_err_keys_3210 :1; @@ -306,22 +299,6 @@ typedef struct { } bit; } status_protect_current_ack; -//9 - union - { - UInt16 all; - struct - { - UInt16 revision :5; - UInt16 version :6; - T_plate_type plate_type :5; - } bit; - } id_plate; - -//10 - - UInt16 time_after_err; - //11 union @@ -503,14 +480,12 @@ typedef union { ////////////////////////////////////////////////////////////// typedef struct { UInt16 setup_count_error; // сколько ждем до падения шины - UInt16 setup_count_error_between; // сколько ждем до падения шины при чтении старых значений UInt16 full_count_error; // всего ошибок UInt16 local_count_error; // текущий счетчик ошибок, идет до setup_count_error и снимается ready, при удачном чтении обнуляется UInt16 count_ok; // сколько удачных чтений UInt16 count_lost; // сколько потерь данных (по id_sbus) UInt16 ready; // шина работает, ошибки не превысили setup_count_error - UInt16 same_id_count; // сколько всего повторных чтений техже данных, т.е. передатчик в др.ПЧ не прислал ничего нового - UInt16 same_id_count_between; // между удачными чтениями, сколько повторных чтений техже данных, т.е. передатчик в др.ПЧ не прислал ничего нового + UInt16 same_id_count; // сколько повторных чтений техже данных, т.е. передатчик в др.ПЧ не прислал ничего нового UInt16 error_not_ready_count; // сколько ошибок не готовности шины ready UInt16 raw_local_error; // есть ошибка при чтении, но шина не упала еще UInt16 buf[4]; // данные @@ -521,7 +496,7 @@ typedef struct { STATUS_DATA_READ_OPT_BUS prev_status_read;// статус после чтения и анализа данных } T_cds_optical_bus_data_in; -#define T_CDS_OPTICAL_BUS_DATA_IN_DEFAULTS {15,50,0,0,0,0,0,0,0,0,0,{0,0,0,0},0,0,0,0,0} +#define T_CDS_OPTICAL_BUS_DATA_IN_DEFAULTS {15,0,0,0,0,0,0,0,0,{0,0,0,0},0,0,0,0,0} ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// diff --git a/Inu/Src/N12_Xilinx/xp_hwp.c b/Inu/Src/N12_Xilinx/xp_hwp.c index 37a7d0d..5fdb6f1 100644 --- a/Inu/Src/N12_Xilinx/xp_hwp.c +++ b/Inu/Src/N12_Xilinx/xp_hwp.c @@ -183,18 +183,15 @@ void hwp_init(T_hwp *v) #if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_NORMAL) -// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp - v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL; + v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp #endif #if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_SLOW) -// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp - v->write.HWP_Speed = MODE_HWP_SPEED_SLOW; + v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp #endif #if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_AUTO) -// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_AUTO;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp - v->write.HWP_Speed = MODE_HWP_SPEED_AUTO; + v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_AUTO;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp #endif } @@ -1270,7 +1267,7 @@ int hwp_write_all_dacs(T_hwp *v) int hwp_write_all(T_hwp *v) { - int err = 0, err_ready = 0; + int err = 0; if (v->useit == 0) return 0; @@ -1315,8 +1312,6 @@ int hwp_write_all(T_hwp *v) else v->status = component_Ready; - err_ready = check_cds_ready_hwpbus( err, ITS_WRITE_BUS, &v->status_hwp_bus); - return 0; diff --git a/Inu/Src/N12_Xilinx/xp_inc_sensor.c b/Inu/Src/N12_Xilinx/xp_inc_sensor.c index 493c106..86e0e2c 100644 --- a/Inu/Src/N12_Xilinx/xp_inc_sensor.c +++ b/Inu/Src/N12_Xilinx/xp_inc_sensor.c @@ -23,7 +23,6 @@ static void write_command_reg(T_inc_sensor *inc_s); static void tune_sampling_time(T_inc_sensor *inc_s); static void wait_for_registers_updated(T_inc_sensor *inc_s); static void read_direction_in_plane(T_inc_sensor *inc_s); -static void detect_break_sensor_1_2(T_inc_sensor *inc_s); void sensor_set(T_inc_sensor *inc_s) { @@ -81,8 +80,6 @@ void inc_sensor_read(T_inc_sensor *inc_s) inc_s->read_sensor2(inc_s); } - detect_break_sensor_1_2(inc_s); - #ifdef AUTO_CHANGE_SAMPLING_TIME tune_sampling_time(inc_s); #endif @@ -90,8 +87,7 @@ void inc_sensor_read(T_inc_sensor *inc_s) //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// -#define MAX_COUNT_OVERFULL_DISCRET_3 150 -#pragma CODE_SECTION(inc_sensor_read1,".fast_run"); + void inc_sensor_read1(T_inc_sensor *inc_s) { read_in_sensor_line1(inc_s); @@ -111,47 +107,8 @@ void inc_sensor_read1(T_inc_sensor *inc_s) //#endif - //inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; - - if (inc_s->pm67regs.zero_time_line1==0) - { - if (inc_s->data.countCountZero1==MAX_COUNT_OVERFULL_DISCRET_3) - { - inc_s->data.prev_CountZero1 = inc_s->data.CountZero1 = 0; - } - else - { - inc_s->data.CountZero1 = inc_s->data.prev_CountZero1; - inc_s->data.countCountZero1++; - } - } - else - { - inc_s->data.countCountZero1 = 0; - inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; - inc_s->data.prev_CountZero1 = inc_s->pm67regs.zero_time_line1; - } - -// inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; - if (inc_s->pm67regs.one_time_line1==0) - { - if (inc_s->data.countCountOne1==MAX_COUNT_OVERFULL_DISCRET_3) - { - inc_s->data.prev_CountOne1 = inc_s->data.CountOne1 = 0; - } - else - { - inc_s->data.CountOne1 = inc_s->data.prev_CountOne1; - inc_s->data.countCountOne1++; - } - } - else - { - inc_s->data.countCountOne1 = 0; - inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; - inc_s->data.prev_CountOne1 = inc_s->pm67regs.one_time_line1; - } - + inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; + inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; inc_s->data.counter_freq1 = inc_s->pm67regs.read_comand_reg.bit.sampling_time1; @@ -160,7 +117,7 @@ void inc_sensor_read1(T_inc_sensor *inc_s) //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// -#pragma CODE_SECTION(inc_sensor_read2,".fast_run"); + void inc_sensor_read2(T_inc_sensor *inc_s) { read_in_sensor_line2(inc_s); @@ -179,46 +136,8 @@ void inc_sensor_read2(T_inc_sensor *inc_s) inc_s->data.TimeCalcFromImpulses2 = 0; //#endif - //inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; - - if (inc_s->pm67regs.zero_time_line2==0) - { - if (inc_s->data.countCountZero2==MAX_COUNT_OVERFULL_DISCRET_3) - { - inc_s->data.prev_CountZero2 = inc_s->data.CountZero2 = 0; - } - else - { - inc_s->data.CountZero2 = inc_s->data.prev_CountZero2; - inc_s->data.countCountZero2++; - } - } - else - { - inc_s->data.countCountZero2 = 0; - inc_s->data.CountZero2 = inc_s->pm67regs.zero_time_line2; - inc_s->data.prev_CountZero2 = inc_s->pm67regs.zero_time_line2; - } - -// inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; - if (inc_s->pm67regs.one_time_line2==0) - { - if (inc_s->data.countCountOne2==MAX_COUNT_OVERFULL_DISCRET_3) - { - inc_s->data.prev_CountOne2 = inc_s->data.CountOne2 = 0; - } - else - { - inc_s->data.CountOne2 = inc_s->data.prev_CountOne2; - inc_s->data.countCountOne2++; - } - } - else - { - inc_s->data.countCountOne2 = 0; - inc_s->data.CountOne2 = inc_s->pm67regs.one_time_line2; - inc_s->data.prev_CountOne2 = inc_s->pm67regs.one_time_line2; - } + inc_s->data.CountZero2 = inc_s->pm67regs.zero_time_line2; + inc_s->data.CountOne2 = inc_s->pm67regs.one_time_line2; inc_s->data.counter_freq2 = inc_s->pm67regs.read_comand_reg.bit.sampling_time2; @@ -332,32 +251,6 @@ void wait_for_registers_updated(T_inc_sensor *inc_s) } //////////////////////////////////////////////////////// -void detect_break_sensor_1_2(T_inc_sensor *inc_s) -{ - unsigned int f1 = (inc_s->data.CountOne1 || inc_s->data.CountZero1); - unsigned int f2 = (inc_s->data.CountOne2 || inc_s->data.CountZero2); - - - if (f1 && f2==0) - { - inc_s->break_sensor1 = 0; - inc_s->break_sensor2 = 1; - } - - if (f1==0 && f2) - { - inc_s->break_sensor1 = 1; - inc_s->break_sensor2 = 0; - } - - if ((f1==0 && f2==0) || (f1 && f2)) - { - inc_s->break_sensor1 = 0; - inc_s->break_sensor2 = 0; - } - - -} //////////////////////////////////////////////////////// @@ -366,20 +259,16 @@ void tune_sampling_time(T_inc_sensor *inc_s) // сначала проверЯем на максимум, т.к. если датчик отвалилсЯ, то он покажет = 0. - if( - (inc_s->use_sensor1 && inc_s->break_sensor1==0 && (inc_s->data.CountOne1 > LEVEL_SWITCH_MICROSEC) && (inc_s->data.CountZero1 > LEVEL_SWITCH_MICROSEC) ) - || (inc_s->use_sensor2 && inc_s->break_sensor2==0 && (inc_s->data.CountOne2 > LEVEL_SWITCH_MICROSEC) && (inc_s->data.CountZero2 > LEVEL_SWITCH_MICROSEC) ) - ) + if((inc_s->use_sensor1 && (inc_s->pm67regs.zero_time_line1 > LEVEL_SWITCH_MICROSEC)) + || (inc_s->use_sensor2 && (inc_s->pm67regs.zero_time_line2 > LEVEL_SWITCH_MICROSEC))) { inc_s->pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS; return; } // проверка на минимум - if( - (inc_s->use_sensor1 && inc_s->break_sensor1==0 && (inc_s->data.CountOne1 < LEVEL_SWITCH_NANOSEC) && (inc_s->data.CountZero1 < LEVEL_SWITCH_NANOSEC) ) - || (inc_s->use_sensor2 && inc_s->break_sensor2==0 && (inc_s->data.CountOne2 < LEVEL_SWITCH_NANOSEC) && (inc_s->data.CountZero2 < LEVEL_SWITCH_NANOSEC) ) - ) + if((inc_s->use_sensor1 && (inc_s->pm67regs.zero_time_line1 < LEVEL_SWITCH_NANOSEC)) + || (inc_s->use_sensor2 && (inc_s->pm67regs.zero_time_line2 < LEVEL_SWITCH_NANOSEC))) { inc_s->pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_NS; } diff --git a/Inu/Src/N12_Xilinx/xp_inc_sensor.h b/Inu/Src/N12_Xilinx/xp_inc_sensor.h index 6c4684d..8d9ccec 100644 --- a/Inu/Src/N12_Xilinx/xp_inc_sensor.h +++ b/Inu/Src/N12_Xilinx/xp_inc_sensor.h @@ -67,10 +67,6 @@ typedef struct { unsigned int error_update; unsigned int use_sensor1; unsigned int use_sensor2; - unsigned int break_sensor1; - unsigned int break_sensor2; - unsigned int break_direction; - struct { @@ -78,10 +74,6 @@ typedef struct { unsigned int Impulses1; // Quantity of full impulses during survey time unsigned int CountZero1; // Value of the zero-half-period counter unsigned int CountOne1; // Value of the one-half-period counter - unsigned int prev_CountZero1; // Value of the prev zero-half-period counter - unsigned int prev_CountOne1; // Value of the prev one-half-period counter - unsigned int countCountZero1; // Value of the zero-half-period counter - unsigned int countCountOne1; // Value of the one-half-period counter unsigned int counter_freq1; // 1 - 60MHz; 0 - 600KHz unsigned long TimeCalcFromImpulses1; // Пересчет времени импульса из количества Impulses1 и времени Time1 int direction1; // 1 - direct; 0 - reverse @@ -90,10 +82,6 @@ typedef struct { unsigned int Impulses2; // Quantity of full impulses during survey time unsigned int CountZero2; // Value of the zero-half-period counter unsigned int CountOne2; // Value of the one-half-period counter - unsigned int prev_CountZero2; // Value of the prev zero-half-period counter - unsigned int prev_CountOne2; // Value of the prev one-half-period counter - unsigned int countCountZero2; // Value of the zero-half-period counter - unsigned int countCountOne2; // Value of the one-half-period counter unsigned int counter_freq2; // 1 - 60MHz; 0 - 600KHz unsigned long TimeCalcFromImpulses2; // Пересчет времени импульса из количества Impulses1 и времени Time1 int direction2; // 1 - direct; 0 - reverse @@ -110,14 +98,7 @@ typedef struct { } T_inc_sensor; -#define T_INC_SENSOR_DEFAULT {0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0, 0,0,0,0}, \ - T_INC_SENSOR_REGS_DEFAULTS, \ - inc_sensor_set,\ - update_sensors_data_s, \ - inc_sensor_read, \ - inc_sensor_read1, \ - inc_sensor_read2 \ - } +#define T_INC_SENSOR_DEFAULT {0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, T_INC_SENSOR_REGS_DEFAULTS, inc_sensor_set, update_sensors_data_s, inc_sensor_read, inc_sensor_read1, inc_sensor_read2} ////////////////////////////////////////////////////////////////////////////////// //// diff --git a/Inu/Src/N12_Xilinx/xp_project.c b/Inu/Src/N12_Xilinx/xp_project.c index b9be18e..65450bb 100644 --- a/Inu/Src/N12_Xilinx/xp_project.c +++ b/Inu/Src/N12_Xilinx/xp_project.c @@ -1229,8 +1229,6 @@ void project_autospeed_all_hwp(void) #define PAUSE_WAIT_SBUS 10000 #define MAX_COUNT_ERR_READ_SBUS 1100 //2000 запас по времени 2х относительно нормального периода загрузки всей корзины -#define MAX_COUNT_ERR_READ_SBUS_2 600 //2000 запас по времени 2х относительно нормального периода загрузки всей корзины - #define MAX_COUNT_OR_READ_SBUS 20//200 @@ -1245,8 +1243,6 @@ unsigned int project_wait_load_all_cds(int flag_reset) unsigned int counterOk = 0, err; unsigned int i,count_find_plat; unsigned int old_status_max_read_error = 0; - unsigned int prev_count_one_find_plat = 0, count_one_find_plat = 0; - unsigned int max_count_err_read_sbus = MAX_COUNT_ERR_READ_SBUS; // unsigned int erReg, rd; /* for (i=0;i= max_count_err_read_sbus) + if (counterErr >= MAX_COUNT_ERR_READ_SBUS) { if (flag_reset == 0) xerror(xserial_bus_er_ID(2), (void *)0); diff --git a/Inu/Src/N12_Xilinx/xp_rotation_sensor.c b/Inu/Src/N12_Xilinx/xp_rotation_sensor.c new file mode 100644 index 0000000..d869f25 --- /dev/null +++ b/Inu/Src/N12_Xilinx/xp_rotation_sensor.c @@ -0,0 +1,267 @@ +#include "xp_project.h" +#include "xp_rotation_sensor.h" + +#include "xp_project.h" + + +T_rotation_sensor rotation_sensor = T_CDS_ROTATION_SENSOR_DEFAULTS; + +//Дискретизацию, при которой расчитываетсю длительность импульсов +#define SAMPLING_TIME_NS 1 // 16,666667ns +#define SAMPLING_TIME_MS 0 // 1,666667us +// Количество импульсов, при которых переключаетсу период дискретизации. +// Величины выбраны с "нахлёстом" что бы не было постоюнных переключений +// в районе граничных величин +#define LEVEL_SWITCH_NANOSEC 327 +#define LEVEL_SWITCH_MICROSEC 0xC000 + + +static void read_in_sensor_line1(T_cds_in_rotation_sensor *rs); +static void read_in_sensor_line2(T_cds_in_rotation_sensor *rs); +static void read_command_reg(T_cds_in_rotation_sensor *rs); +static void write_command_reg(T_cds_in_rotation_sensor *rs); +static void tune_sampling_time(T_rotation_sensor *rs); +static void wait_for_registers_updated(T_cds_in_rotation_sensor *rs); +static void read_direction_in_plane(T_cds_in_rotation_sensor *rs); + +void rot_sensor_set(T_rotation_sensor *rs) +{ + + if(rs->use_sensor1 || rs->use_sensor2) + { + rs->in_plane.set(&rs->in_plane); + } + if(rs->use_angle_plane) + { + rs->rotation_plane.set(&rs->rotation_plane); + } +} + +void in_plane_set(T_cds_in_rotation_sensor* rs) +{ + if(!rs->cds_in->useit) + { + return; + } + + rs->cds_in->write.sbus.enabled_channels.all = rs->write.sbus.enabled_channels.all; + rs->cds_in->write.sbus.first_sensor.all = rs->write.sbus.first_sensor_inputs.all; + rs->cds_in->write.sbus.second_sensor.all = rs->write.sbus.second_sensor_inputs.all; + // rs->cds_in->write_sbus(rs->cds_in); + write_command_reg(rs); + +} + + +void angle_plane_set(T_cds_angle_sensor *rs) +{ + if((rs->cds_rs == NULL) || (!rs->cds_rs->useit)) + { + return; + } + + rs->cds_rs->write.sbus.config.all = rs->write.sbus.config.all; + rs->cds_rs->write_sbus(rs->cds_rs); +} + +void sensor_read(T_rotation_sensor *rs) +{ + if(rs->use_sensor1 || rs->use_sensor2 || rs->use_angle_plane) + { + wait_for_registers_updated(&rs->in_plane); + read_direction_in_plane(&rs->in_plane); + } + else + { + return; + } + if(rs->use_sensor1) + { + rs->in_plane.read_sensor1(&rs->in_plane); + } + if(rs->use_sensor2) + { + rs->in_plane.read_sensor2(&rs->in_plane); + } + if(rs->use_angle_plane) + { + rs->rotation_plane.read_sensor(&rs->rotation_plane); + } +#ifdef AUTO_CHANGE_SAMPLING_TIME + tune_sampling_time(rs); +#endif +} + +void in_sensor_read1(T_cds_in_rotation_sensor *rs) +{ + read_in_sensor_line1(rs); +#if C_PROJECT_TYPE != PROJECT_BALZAM + rs->out.Impulses1 = rs->read.regs.n_impulses_line1; + rs->out.Time1 = rs->read.regs.time_line1 / 60; + //Counter`s freq is 60МГц => N/60 = time in mksec +#endif + rs->out.CountZero1 = rs->read.regs.zero_time_line1; + rs->out.CountOne1 = rs->read.regs.one_time_line1; + + rs->out.counter_freq1 = rs->read.regs.comand_reg.bit.sampling_time1; + + rs->out.direction1 = rs->read.pbus.direction.bit.sensor1; +} + +void in_sensor_read2(T_cds_in_rotation_sensor *rs) +{ + read_in_sensor_line2(rs); +#if C_PROJECT_TYPE != PROJECT_BALZAM + rs->out.Impulses2 = rs->read.regs.n_impulses_line2; + rs->out.Time2 = rs->read.regs.time_line2 / 60; +#endif + rs->out.CountZero2 = rs->read.regs.zero_time_line2; + rs->out.CountOne2 = rs->read.regs.one_time_line2; + + rs->out.counter_freq2 = rs->read.regs.comand_reg.bit.sampling_time2; + + rs->out.direction2 = rs->read.pbus.direction.bit.sensor2; +} + +void read_in_sensor_line1(T_cds_in_rotation_sensor *rs) +{ + if(!rs->read.regs.comand_reg.bit.update_registers) + { +#if C_PROJECT_TYPE != PROJECT_BALZAM + rs->read.regs.time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD);//TODO check time when turn off + rs->read.regs.n_impulses_line1 = i_ReadMemory(ADR_SENSOR_S1_COUNT_IMPULS); +#endif + rs->read.regs.zero_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_LOW_ONE_IMPULS); + rs->read.regs.one_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_HIGH_ONE_IMPULS); + } +} + +void read_in_sensor_line2(T_cds_in_rotation_sensor *rs) +{ + if(!rs->read.regs.comand_reg.bit.update_registers) + { +#if C_PROJECT_TYPE != PROJECT_BALZAM + rs->read.regs.time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD); + rs->read.regs.n_impulses_line2 = i_ReadMemory(ADR_SENSOR_S2_COUNT_IMPULS); +#endif + rs->read.regs.zero_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_LOW_ONE_IMPULS); + rs->read.regs.one_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_HIGH_ONE_IMPULS); + } +} + +void write_command_reg(T_cds_in_rotation_sensor *rs) +{ + WriteMemory(ADR_SENSOR_CMD, rs->write.regs.comand_reg.all); +} + +void read_command_reg(T_cds_in_rotation_sensor *rs) +{ + rs->read.regs.comand_reg.all = i_ReadMemory(ADR_SENSOR_CMD); +} + +void update_sensors_data_r(T_rotation_sensor *rs) +{ + rs->in_plane.write.regs.comand_reg.bit.update_registers = 1; + write_command_reg(&rs->in_plane); +// rs->in_plane.write.regs.comand_reg.bit.update_registers = 0; +} + +void read_direction_in_plane(T_cds_in_rotation_sensor *rs) +{ +/* + rs->read.pbus.direction.bit.sensor1 = rs->cds_in->read.pbus.direction_in.bit.dir0 == 2 ? 1 : + rs->cds_in->read.pbus.direction_in.bit.dir0 == 1 ? -1 : + 0; + rs->read.pbus.direction.bit.sensor2 = rs->cds_in->read.pbus.direction_in.bit.dir1 == 2 ? 1 : + rs->cds_in->read.pbus.direction_in.bit.dir1 == 1 ? -1 : + 0; + rs->read.pbus.direction.bit.sens_err1 = rs->cds_in->read.pbus.direction_in.bit.dir0 == 3; + rs->read.pbus.direction.bit.sens_err2 = rs->cds_in->read.pbus.direction_in.bit.dir1 == 3; +*/ + //Direction changes not often. May be, it`s enough to read it in main cycle. +} + +void wait_for_registers_updated(T_cds_in_rotation_sensor *rs) +{ + int counter_in_while = 0; + read_command_reg(rs); + while(rs->read.regs.comand_reg.bit.update_registers) + { + read_command_reg(rs); + rs->count_wait_for_update_registers++; + counter_in_while++; + if(counter_in_while > 1000) + { + rs->error_update++; + break; + } + } +} + +void tune_sampling_time(T_rotation_sensor *rs) +{ + if((rs->use_sensor1 && (rs->in_plane.read.regs.zero_time_line1 < LEVEL_SWITCH_NANOSEC)) + || (rs->use_sensor2 && (rs->in_plane.read.regs.zero_time_line2 < LEVEL_SWITCH_NANOSEC))) + { + rs->in_plane.write.regs.comand_reg.bit.set_sampling_time = SAMPLING_TIME_NS; + } + + if((rs->use_sensor1 && (rs->in_plane.read.regs.zero_time_line1 > LEVEL_SWITCH_MICROSEC)) + || (rs->use_sensor2 && (rs->in_plane.read.regs.zero_time_line2 > LEVEL_SWITCH_MICROSEC))) + { + rs->in_plane.write.regs.comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS; + } +} + +void angle_sensor_read(T_cds_angle_sensor *as) +{ + as->cds_rs->read_pbus(as->cds_rs); + + if(as->cds_rs->read.sbus.config.bit.channel1_enable) + { +// logpar.log15 = as->cds_rs->read.pbus.sensor[0].turned_angle; +// logpar.log16 = as->cds_rs->read.pbus.sensor[0].angle; + + as->out.Delta_angle1 = as->cds_rs->read.pbus.sensor[0].turned_angle; + as->out.Current_angle1 = as->cds_rs->read.pbus.sensor[0].angle << 3; + } + else + { + as->out.Delta_angle1 = 0; + as->out.Current_angle1 = 0; + } + if(as->cds_rs->read.sbus.config.bit.channel2_enable) + { + as->out.Delta_angle2 = as->cds_rs->read.pbus.sensor[1].turned_angle; + as->out.Current_angle2 = as->cds_rs->read.pbus.sensor[1].angle << 3; + } + else + { + as->out.Delta_angle2 = 0; + as->out.Current_angle2 = 0; + } + if(as->cds_rs->read.sbus.config.bit.channel3_enable) + { + as->out.Delta_angle3 = as->cds_rs->read.pbus.sensor[2].turned_angle; + as->out.Current_angle3 = as->cds_rs->read.pbus.sensor[2].angle << 3; + } + else + { + as->out.Delta_angle3 = 0; + as->out.Current_angle3 = 0; + } + if(as->cds_rs->read.sbus.config.bit.channel4_enable) + { + as->out.Delta_angle4 = as->cds_rs->read.pbus.sensor[3].turned_angle; + as->out.Current_angle4 = as->cds_rs->read.pbus.sensor[3].angle << 3; + } + else + { + as->out.Delta_angle4 = 0; + as->out.Current_angle4 = 0; + } + + as->out.survey_time_mks = (as->read.sbus.config.bit.survey_time + 1) * 10; + +} + diff --git a/Inu/Src/N12_Xilinx/xp_rotation_sensor.h b/Inu/Src/N12_Xilinx/xp_rotation_sensor.h new file mode 100644 index 0000000..b09ac6e --- /dev/null +++ b/Inu/Src/N12_Xilinx/xp_rotation_sensor.h @@ -0,0 +1,346 @@ +#ifndef XP_ROT_SENS_H +#define XP_ROT_SENS_H + +#include "x_basic_types.h" +#include "xp_cds_in.h" +#include "xp_cds_rs.h" + + +//RS speed of angle sensor +#define TS400 0 +#define TS350 1 +#define TS300 2 +#define TS250 3 +#define TS200 4 + +//Дискретизацию, при которой расчитываетсю длительность импульсов +#define SAMPLING_TIME_NS 1 // 16,666667ns +#define SAMPLING_TIME_MS 0 // 1,666667us + +//Автоматически переключает счётчик, когда количество отсчётов +// на 1 импульс становитсЯ слишком большим или маленьким. +//#define AUTO_CHANGE_SAMPLING_TIME +/* + Что бы прочитать данные из датчика, нужно вызвать + rotation_sensor.read_sensors(&rotation_sensor); + Результат платы IN будет в + rotation_sensor.in_plane.out.... + Результат платы RS будет в + rotation_sensor.rotation_plane.out.... +*/ + +///////////////////////////////////////////////////////////// +// IN plane +///////////////////////////////////////////////////////////// + +// Registers with data for rotation sensor + +typedef union { + unsigned int all; + struct { + unsigned int filter_sensitivity:12; + unsigned int set_sampling_time:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time2:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time1:1; + unsigned int update_registers:1; //0 - updated + }bit; +}T_cds_in_comand; + +#define R_CDS_IN_COMAND_DEFAULT 0 + +typedef struct { + unsigned int time_line1; + unsigned int n_impulses_line1; + unsigned int time_line2; + unsigned int n_impulses_line2; + + unsigned int zero_time_line1; + unsigned int one_time_line1; + unsigned int zero_time_line2; + unsigned int one_time_line2; + + T_cds_in_comand comand_reg; + +} T_cds_in_rotation_sensor_read_regs; + +#define T_CDS_IN_ROTATION_SENSOR_READ_REGS_DEFAULTS {0,0,0,0, 0,0,0,0, R_CDS_IN_COMAND_DEFAULT} + +typedef struct { + T_cds_in_comand comand_reg; + +} T_cds_in_rotation_sensor_write_regs; + +#define T_CDS_IN_ROTATION_SENSOR_WRITE_REGS_DEFAULTS {R_CDS_IN_COMAND_DEFAULT} + +///////////////////////////////////////////////////////////// +//read reg parallel bus +///////////////////////////////////////////////////////////// +typedef struct { + union { + unsigned int all; + struct { + int sensor1:4; + int sensor2:4; + unsigned int sens_err1:1; + unsigned int sens_err2:1; + unsigned int reserved:6; + } bit; + } direction; + +} T_cds_in_rotation_sensor_read_pbus; + +#define T_CDS_IN_ROTATION_SENSOR_READ_PBUS_DEFAULTS {0} + +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { + //0 + union + { + UInt16 all; + struct{ + UInt16 discret : 8; + UInt16 reserv : 7; + UInt16 sens_2_inv_ch_90deg : 1; + UInt16 sens_2_direct_ch_90deg : 1; + UInt16 sens_2_inv_ch : 1; + UInt16 sens_2_direct_ch : 1; + UInt16 sens_1_inv_ch_90deg : 1; + UInt16 sens_1_direct_ch_90deg : 1; + UInt16 sens_1_inv_ch : 1; + UInt16 sens_1_direct_ch : 1; + }bit; + }enabled_channels; + + //1 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }first_sensor_inputs; + +//2 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }second_sensor_inputs; + +} T_cds_in_rotation_sensor_write_sbus; + +#define T_CDS_IN_ROTATION_SENSOR_WRITE_SBUS_DEFAULTS {0, 0, 0} + +//////////////////////////////////////////////////////// +typedef struct { + T_cds_in_rotation_sensor_read_pbus pbus; + T_cds_in_rotation_sensor_read_regs regs; +}T_cds_in_rotation_sensor_read; + +#define T_CDS_IN_ROTATION_SENSOR_READ_DEFAULTS \ + {T_CDS_IN_ROTATION_SENSOR_READ_PBUS_DEFAULTS, \ + T_CDS_IN_ROTATION_SENSOR_READ_REGS_DEFAULTS} + +typedef struct { + T_cds_in_rotation_sensor_write_sbus sbus; + T_cds_in_rotation_sensor_read_regs regs; +}T_cds_in_rotation_sensor_write; + +#define T_CDS_IN_ROTATION_SENSOR_WRITE_DEFAULTS \ + {T_CDS_IN_ROTATION_SENSOR_WRITE_SBUS_DEFAULTS, \ + T_CDS_IN_ROTATION_SENSOR_WRITE_REGS_DEFAULTS} + + +////// Rotation sensor with IN plane +typedef struct { + //UInt16 plane_address; + unsigned int count_wait_for_update_registers; + unsigned int error_update; + + struct { + + unsigned int Time1; // Sensor's survey time in mksec + unsigned int Impulses1; // Quantity of full impulses during survey time + unsigned int CountZero1; // Value of the zero-half-period counter + unsigned int CountOne1; // Value of the one-half-period counter + unsigned int counter_freq1; // 1 - 60MHz; 0 - 600KHz + int direction1; // 1 - direct; 0 - reverse + + unsigned int Time2; // Sensor's survey time in mksec + unsigned int Impulses2; // Quantity of full impulses during survey time + unsigned int CountZero2; // Value of the zero-half-period counter + unsigned int CountOne2; // Value of the one-half-period counter + unsigned int counter_freq2; // 1 - 60MHz; 0 - 600KHz + int direction2; // 1 - direct; 0 - reverse + } out; + + T_cds_in *cds_in; + + T_cds_in_rotation_sensor_write write; + T_cds_in_rotation_sensor_read read; + + void (*set)(); // Pointer to calculation function + + void (*read_sensor1)(); + + void (*read_sensor2)(); + +} T_cds_in_rotation_sensor; + +#define T_CDS_IN_ROTATION_SENSOR_DEFAULT \ + {0, 0, \ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \ + NULL, \ + T_CDS_IN_ROTATION_SENSOR_WRITE_DEFAULTS, \ + T_CDS_IN_ROTATION_SENSOR_READ_DEFAULTS, \ + in_plane_set, \ + in_sensor_read1, \ + in_sensor_read2} + + +/////////////////////////////////////////////////////////////////////////// +///// Rotation Plane +/////////////////////////////////////////////////////////////////////////// +typedef union { + unsigned int all; + struct { + unsigned int survey_time:8; //Период опроса по 10мкс (0==10, 1==20,...) + unsigned int channel4_enable:1; + unsigned int channel3_enable:1; + unsigned int channel2_enable:1; + unsigned int channel1_enable:1; + unsigned int transmition_speed:3; + unsigned int plane_is_master:1; + }bit; +} T_cds_rotation_plane_config; + +#define T_CDS_ROTATION_PLANE_CONFIG_DEFAULT 0xA031 //{49, 1, 0, 0, 0, 2, 1} + +typedef struct { + T_cds_rotation_plane_config config; +} T_cds_rotation_plane_write_sbus; + +#define T_CDS_ROTATION_PLANE_WRITE_SBUS_DEFAULT \ + {T_CDS_ROTATION_PLANE_CONFIG_DEFAULT} + +typedef struct { + int direction; + unsigned int turned_angle; + unsigned int angle; +} RsSensor; + +#define SENSOR_DEFAULT {0, 0, 0} + +typedef struct { + RsSensor sensor[4]; +} T_cds_rotation_plane_read_pbus; + +#define T_CDS_ROTATION_PLANE_READ_PBUS_DEFAULT { \ + {SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT}} + +typedef struct { + T_cds_rotation_plane_config config; +} T_cds_rotation_plane_read_sbus; + +#define T_CDS_ROTATION_PLANE_READ_SBUS_DEFAULT {T_CDS_ROTATION_PLANE_CONFIG_DEFAULT} + +typedef struct { + T_cds_rotation_plane_write_sbus sbus; +} T_cds_rotation_plane_write; + +#define T_CDS_ROTATION_PLANE_WRITE_DEFAULT \ + {T_CDS_ROTATION_PLANE_WRITE_SBUS_DEFAULT} + +typedef struct { + T_cds_rotation_plane_read_pbus pbus; + T_cds_rotation_plane_read_sbus sbus; +} T_cds_rotation_plane_read; + +#define T_CDS_ROTATION_PLANE_READ_DEFAULT \ + {T_CDS_ROTATION_PLANE_READ_PBUS_DEFAULT, T_CDS_ROTATION_PLANE_READ_SBUS_DEFAULT} + +typedef struct { + + struct { + unsigned long Delta_angle1; + unsigned long Delta_angle2; + unsigned long Delta_angle3; + unsigned long Delta_angle4; + unsigned long Current_angle1; + unsigned long Current_angle2; + unsigned long Current_angle3; + unsigned long Current_angle4; + unsigned int survey_time_mks; //ВремЯ опроса датчика в мкс + unsigned int direction; + } out; + + unsigned int error; + + T_cds_rs *cds_rs; + + T_cds_rotation_plane_read read; + T_cds_rotation_plane_write write; + + void (*set)(); // Pointer to calculation function + + void (*read_sensor)(); + +} T_cds_angle_sensor; + +#define T_CDS_ANGLE_SENSOR_DEFAULT { \ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \ + 0, NULL, \ + T_CDS_ROTATION_PLANE_READ_DEFAULT, \ + T_CDS_ROTATION_PLANE_WRITE_DEFAULT, \ + angle_plane_set, angle_sensor_read} + + +////////////////////////////////////////////////////////////////////////////////// +//// +////////////////////////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 use_sensor1; + UInt16 use_sensor2; + UInt16 use_angle_plane; + + T_cds_in_rotation_sensor in_plane; + T_cds_angle_sensor rotation_plane; + + void (*set)(); // Pointer to calculation function + void (*read_sensors)(); + void (*update_registers)(); + +} T_rotation_sensor; + +#define T_CDS_ROTATION_SENSOR_DEFAULTS {0, 0, 0, \ + T_CDS_IN_ROTATION_SENSOR_DEFAULT, \ + T_CDS_ANGLE_SENSOR_DEFAULT, \ + rot_sensor_set, \ + sensor_read, \ + update_sensors_data_r} + +//Public functions +void rot_sensor_set(T_rotation_sensor *rs); +void sensor_read(T_rotation_sensor *rs); +void update_sensors_data_r(T_rotation_sensor *rs); +void angle_plane_set(T_cds_angle_sensor *rs); +void angle_sensor_read(T_cds_angle_sensor *as); +void in_plane_set(T_cds_in_rotation_sensor* rs); +void in_sensor_read1(T_cds_in_rotation_sensor *rs); +void in_sensor_read2(T_cds_in_rotation_sensor *rs); + + +extern T_rotation_sensor rotation_sensor; + +#endif //XP_ROT_SENS_H diff --git a/Inu/Src/N12_Xilinx/xp_write_xpwm_time.h b/Inu/Src/N12_Xilinx/xp_write_xpwm_time.h index 22293a9..c7d9e68 100644 --- a/Inu/Src/N12_Xilinx/xp_write_xpwm_time.h +++ b/Inu/Src/N12_Xilinx/xp_write_xpwm_time.h @@ -123,7 +123,6 @@ typedef struct unsigned int Tclosed_high; // unsigned int Tclosed_1; unsigned int pwm_tics; - unsigned int half_pwm_tics; unsigned int inited; unsigned int freq_pwm; unsigned int Tclosed_saw_direct_0; @@ -132,16 +131,13 @@ typedef struct unsigned int where_interrupt; unsigned int mode_reload; unsigned int one_or_two_interrupts_run; - unsigned int what_next_interrupt; - unsigned int do_sync_out; - unsigned int disable_sync_out; WORD_UINT2BITS_STRUCT saw_direct; void (*write_1_2_winding_break_times)(); void (*write_zero_winding_break_times)(); void (*init)(); } XPWM_TIME; -#define DEFAULT_XPWM_TIME {0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0, 0,0,0, 0, 0, 0, 0, 0,0,0, 0,0, {0}, \ +#define DEFAULT_XPWM_TIME {0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0, 0, 0, 0, 0, 0,0,0, {0}, \ xpwm_write_1_2_winding_break_times_16_lines, \ xpwm_write_zero_winding_break_times_16_lines, \ initXpwmTimeStructure \ diff --git a/Inu/Src/main/281xEvTimersInit.c b/Inu/Src/main/281xEvTimersInit.c index 59b7005..871a631 100644 --- a/Inu/Src/main/281xEvTimersInit.c +++ b/Inu/Src/main/281xEvTimersInit.c @@ -43,7 +43,6 @@ #include #include "TuneUpPlane.h" -#include "profile_interrupt.h" // Prototype statements for functions found within this file. interrupt void eva_timer1_isr(void); @@ -58,15 +57,15 @@ Uint32 EvaTimer2InterruptCount = 0; Uint32 EvbTimer3InterruptCount = 0; Uint32 EvbTimer4InterruptCount = 0; -//unsigned int enable_profile_led1_Timer1 = 1; -//unsigned int enable_profile_led1_Timer2 = 1; -//unsigned int enable_profile_led1_Timer3 = 1; -//unsigned int enable_profile_led1_Timer4 = 1; -// -//unsigned int enable_profile_led2_Timer1 = 0; -//unsigned int enable_profile_led2_Timer2 = 0; -//unsigned int enable_profile_led2_Timer3 = 0; -//unsigned int enable_profile_led2_Timer4 = 0; +unsigned int enable_profile_led1_Timer1 = 1; +unsigned int enable_profile_led1_Timer2 = 1; +unsigned int enable_profile_led1_Timer3 = 1; +unsigned int enable_profile_led1_Timer4 = 1; + +unsigned int enable_profile_led2_Timer1 = 0; +unsigned int enable_profile_led2_Timer2 = 0; +unsigned int enable_profile_led2_Timer3 = 0; +unsigned int enable_profile_led2_Timer4 = 0; //Pointers to handler functions void (*timer1_handler)() = NULL; @@ -333,11 +332,11 @@ interrupt void eva_timer1_isr(void) PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer1) + if (enable_profile_led1_Timer1) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer1) + if (enable_profile_led2_Timer1) i_led2_on_off_special(1); #endif EINT; @@ -355,11 +354,11 @@ interrupt void eva_timer1_isr(void) DINT; PieCtrlRegs.PIEIER2.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer1) + if (enable_profile_led1_Timer1) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer1) + if (enable_profile_led2_Timer1) i_led2_on_off_special(0); #endif @@ -405,11 +404,11 @@ interrupt void eva_timer2_isr(void) PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer2) + if (enable_profile_led1_Timer2) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer2) + if (enable_profile_led2_Timer2) i_led2_on_off_special(1); #endif @@ -429,11 +428,11 @@ interrupt void eva_timer2_isr(void) PieCtrlRegs.PIEIER3.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer2) + if (enable_profile_led1_Timer2) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer2) + if (enable_profile_led2_Timer2) i_led2_on_off_special(0); #endif @@ -485,11 +484,11 @@ interrupt void evb_timer3_isr(void) PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer3) + if (enable_profile_led1_Timer3) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer3) + if (enable_profile_led2_Timer3) i_led2_on_off_special(1); #endif @@ -512,11 +511,11 @@ interrupt void evb_timer3_isr(void) PieCtrlRegs.PIEIER4.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer3) + if (enable_profile_led1_Timer3) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer3) + if (enable_profile_led2_Timer3) i_led2_on_off_special(0); #endif @@ -567,11 +566,11 @@ interrupt void evb_timer4_isr(void) PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer4) + if (enable_profile_led1_Timer4) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer4) + if (enable_profile_led2_Timer4) i_led2_on_off_special(1); #endif @@ -591,11 +590,11 @@ interrupt void evb_timer4_isr(void) PieCtrlRegs.PIEIER5.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.timer4) + if (enable_profile_led1_Timer4) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.timer4) + if (enable_profile_led2_Timer4) i_led2_on_off_special(0); #endif diff --git a/Inu/Src/main/CAN_project.h b/Inu/Src/main/CAN_project.h index 3454f1e..950451a 100644 --- a/Inu/Src/main/CAN_project.h +++ b/Inu/Src/main/CAN_project.h @@ -8,9 +8,6 @@ #ifndef SRC_MAIN_CAN_PROJECT_H_ #define SRC_MAIN_CAN_PROJECT_H_ - -#include "can_protocol_ukss.h" - ////////////////////////////////////////////////////////////////// // настройка базовых адресов CAN // PCH_1 или PCH_2 выбирается джамперов на ПМ67 @@ -31,21 +28,23 @@ //#define CAN_PROTOCOL_VERSION 1 #define CAN_PROTOCOL_VERSION 2 -#define CAN_SPEED_BITS 125000 -//#define CAN_SPEED_BITS 250000 + +#define CAN_SPEED_BITS 250000 //#define CAN_SPEED_BITS 500000 #define ENABLE_CAN_SEND_TO_UKSS_FROM_MAIN 1 #define ENABLE_CAN_SEND_TO_MPU_FROM_MAIN 1 -#define ENABLE_CAN_SEND_TO_TERMINAL_FROM_MAIN 0//1 +#define ENABLE_CAN_SEND_TO_TERMINAL_FROM_MAIN 1 #define ENABLE_CAN_SEND_TO_TERMINAL_OSCIL 0//1 #define ENABLE_CAN_SEND_TO_ANOTHER_BSU_FROM_MAIN 1 ////////////////////////////////////////////////////// + + #ifndef ENABLE_CAN_SEND_TO_UKSS_FROM_MAIN #define ENABLE_CAN_SEND_TO_UKSS_FROM_MAIN 0 #endif diff --git a/Inu/Src/main/Main.c b/Inu/Src/main/Main.c index 9716206..787e6bf 100644 --- a/Inu/Src/main/Main.c +++ b/Inu/Src/main/Main.c @@ -14,9 +14,9 @@ void main() // This example function is found in the DSP281x_SysCtrl.c file. InitSysCtrl(); - XintfZone0_Timing();//Xilinx Zone - XintfZone6_And7_Timing();//Flash Zone - XintfZone2_Timing();//External RAM Zone + XintfZone0_Timing(); + XintfZone6_And7_Timing(); + XintfZone2_Timing(); // Step 2. Initalize GPIO: // This example function is found in the DSP281x_Gpio.c file and diff --git a/Inu/Src/main/PWMTools.c b/Inu/Src/main/PWMTools.c index b62f7b3..9583296 100644 --- a/Inu/Src/main/PWMTools.c +++ b/Inu/Src/main/PWMTools.c @@ -8,7 +8,7 @@ #include #include #include -//#include +#include #include #include #include //22.06 @@ -41,23 +41,9 @@ #include "TuneUpPlane.h" #include "xp_write_xpwm_time.h" #include "pwm_test_lines.h" -#include "detect_errors.h" -#include "modbus_table_v2.h" -#include "params_alg.h" -#include "v_rotor_22220.h" -#include "log_to_memory.h" -#include "log_params.h" -#include "limit_power.h" -#include "pwm_logs.h" -#include "optical_bus_tools.h" -#include "ramp_zadanie_tools.h" -#include "pll_tools.h" - ///////////////////////////////////// -#if (_SIMULATE_AC==1) -#include "sim_model.h" -#endif + //#pragma DATA_SECTION(freq1,".fast_vars1"); //_iq freq1; @@ -65,22 +51,14 @@ //#pragma DATA_SECTION(k1,".fast_vars1"); //_iq k1 = 0; -#define ENABLE_LOG_INTERRUPTS 0 //1 - - -#if (ENABLE_LOG_INTERRUPTS) - #pragma DATA_SECTION(log_interrupts,".slow_vars"); #define MAX_COUNT_LOG_INTERRUPTS 100 unsigned int log_interrupts[MAX_COUNT_LOG_INTERRUPTS+2] = {0}; - - - ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// - +#define ENABLE_LOG_INTERRUPTS 0 //1 void add_log_interrupts(int cmd) { @@ -100,9 +78,6 @@ void add_log_interrupts(int cmd) } -#endif //if (ENABLE_LOG_INTERRUPTS) - - #pragma DATA_SECTION(iq_U_1_save,".fast_vars1"); _iq iq_U_1_save = 0; @@ -114,13 +89,24 @@ unsigned int enable_calc_vector = 0; -//WINDING winding1 = WINDING_DEFAULT; +WINDING a = WINDING_DEFAULT; //#define COUNT_SAVE_LOG_OFF 50 //Сколько тактов ШИМ сохранЯетсЯ после остановки #define COUNT_START_IMP 5 //10 #define CONST_005 838860 /////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + +int i = 0; +/*void InitPWM() +{ + i_WriteMemory(ADR_PWM_MODE_0, 0x0000); //Выбираем в качестве источника ШИМ TMS +}*/ + /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// @@ -182,30 +168,7 @@ control_station_test_alive_all_control(); /////////////////////////////////////////////////////////////////// //#define get_tics_timer_pwm2(k) {time_buf2[k] = (EvbRegs.T3CNT-start_tics_4timer);k++;} //unsigned int time_buf2[10] = {0}; - - /////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -#define PAUSE_INC_TIMEOUT_CICLE 10 // FREQPWM/10 -void pwm_inc_interrupt(void) -{ - static unsigned int t_inc = 0; - - if (t_inc>=PAUSE_INC_TIMEOUT_CICLE) - { - inc_RS_timeout_cicle(); - inc_CAN_timeout_cicle(); - t_inc = 0; - } - else - t_inc++; -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - #pragma CODE_SECTION(pwm_analog_ext_interrupt,".fast_run2"); void pwm_analog_ext_interrupt(void) { @@ -248,12 +211,479 @@ void pwm_analog_ext_interrupt(void) // i_led2_off(); + inc_RS_timeout_cicle(); + inc_CAN_timeout_cicle(); + // global_time.calc(&global_time); } /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// + +unsigned int sum_count_err_read_opt_bus=0; + +#pragma CODE_SECTION(optical_bus_read_write_interrupt,".fast_run2"); +void optical_bus_read_write_interrupt(void) +{ + + + static unsigned int prev_error_read = 0, count_read_optical_bus_error = 0; + static unsigned int flag_disable_resend = 0; + static unsigned int count_resend = 0, cc=0; +// static STATUS_DATA_READ_OPT_BUS buf_status[10]; + static STATUS_DATA_READ_OPT_BUS optbus_status; + static unsigned int tt=0, t1 = 6; //t1 = 10 //, t2 = 3, t3 = 30; + static unsigned int cmd_wdog_sbus = 0, count_wait_wdog_sbus = 0, wdog_sbus = 0; + + if (flag_special_mode_rs==1) + return; + + if (edrk.KvitirProcess) + return; + + if (edrk.disable_interrupt_timer2) + return; + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_17_ON; +#endif + +//i_led2_on_off(1); + + +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(2); +#endif + + +// pause_1000(100); + if (optical_read_data.flag_clear) + { + // stage_1 = 0; + optical_read_data.timer = 0; + optical_read_data.flag_clear = 0; + optical_read_data.error_wdog = 0; +// count_wait_wdog_sbus = 0; + + +// if (optical_read_data.data_was_update_between_pwm_int==0) +// sum_count_err_read_opt_bus++; +// +// optical_read_data.data_was_update_between_pwm_int = 0; + + // optical_read_data.data_was_update_between_pwm_int = 0; + cc = 0; + } + +// else + optical_read_data.timer++; + +// if (edrk.into_pwm_interrupt==1) +// { +// if (optical_read_data.timer>=2) +// { +// optical_read_data.timer--; +// optical_read_data.timer--; +// } +// flag_disable_resend = 0; +// count_resend = 0; +// +// } + +// +// +// +// if (stage_1==0) +// tt = t1; +// +// if (stage_1==1) +// tt = t2; + + if (edrk.ms.another_bs_maybe_on==1 && edrk.flag_second_PCH==0 /*edrk.auto_master_slave.local.bits.master*/ ) + { + + if (optical_read_data.data.cmd.bit.wdog_tick) + { + // i_led1_on(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_21_ON; +#endif + } + else + { + // i_led1_off(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_21_OFF; +#endif + + } + + optical_write_data.data.cmd.bit.wdog_tick = optical_read_data.data.cmd.bit.wdog_tick; + + if (optical_write_data.data.cmd.bit.wdog_tick) + { + // i_led2_on(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_22_ON; +#endif + + } + else + { + // i_led2_off(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_22_OFF; +#endif + } + + + + } + + + if (edrk.ms.another_bs_maybe_on==1 && edrk.flag_second_PCH==1 /*edrk.auto_master_slave.local.bits.slave*/ ) + { + + if (optical_write_data.data.cmd.bit.wdog_tick) + { + // i_led2_on(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_22_ON; +#endif + + } + else + { + // i_led2_off(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_22_OFF; +#endif + } + + + + if (optical_read_data.data.cmd.bit.wdog_tick) + { + // i_led1_on(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_21_ON; +#endif + } + else + { + // i_led1_off(); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_21_OFF; +#endif + } + + + + + // пишем + optical_write_data.data.cmd.bit.wdog_tick = wdog_sbus; + if (cmd_wdog_sbus==0) + { +// optical_write_data.data.cmd.bit.wdog_tick = wdog_sbus; + count_wait_wdog_sbus = 0; + cmd_wdog_sbus++; + } + else + // ждем подтверждения + if (cmd_wdog_sbus==1) + { + if (optical_read_data.data.cmd.bit.wdog_tick == wdog_sbus) //&& prev_error_read==0 + { + // result_code_wdog_sbus = 1; + optical_read_data.count_error_wdog = count_wait_wdog_sbus; + count_wait_wdog_sbus = 0; + wdog_sbus = !wdog_sbus; + cmd_wdog_sbus = 0; + } + else + { + if (count_wait_wdog_sbus<(8*t1) ) //6 + { + count_wait_wdog_sbus++; + } + else + { + if (optical_read_data.error_wdog==0) + { + // не было ошибок и вдруг есть! + +// i_led2_toggle(); +// pause_1000(10); +// i_led2_toggle(); +// pause_1000(10); + } + // if (optical_read_data.data.cmd.bit.alarm==0) // пока так! + optical_read_data.error_wdog = 1; // даем ошибку + + } + + + } + } + + + } + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + +// if (count_wait_wdog_sbus==0) +// { +// PWM_LINES_TK_16_ON; +// } +// else +// { +// PWM_LINES_TK_16_OFF; +// } + + +#endif + + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + if (optical_read_data.error_wdog) + { + PWM_LINES_TK_23_ON; + PWM_LINES_TK_23_ON; + } + else + { + PWM_LINES_TK_23_OFF; + } +#endif + + + + if (optical_read_data.timer>=t1 || prev_error_read==1) + { + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_18_OFF; + PWM_LINES_TK_16_OFF; +#endif +// i_led2_on_off(1); +// i_led2_on_off(0); +// i_led2_on_off(1); + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_19_ON; + +#endif + project.cds_tk[3].read_pbus(&project.cds_tk[3]); //optical_bus_read(); + + +// i_led2_on_off(0); +// i_led2_on_off(1); + + optbus_status = optical_bus_get_status_and_read(); + +// i_led2_on_off(0); + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_19_OFF; +#endif + cc++; + + if (optbus_status.bit.new_data_ready) + { + + prev_error_read = 0; + + if (optical_read_data.data_was_update_between_pwm_int<10000) + optical_read_data.data_was_update_between_pwm_int += 1; + + count_read_optical_bus_error = 0; + } + + if (optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 + ) + { + + prev_error_read = 1; + + if (count_read_optical_bus_error<=t1) + count_read_optical_bus_error++; + else + { + optical_read_data.data.pzad_or_wzad = 0; + optical_read_data.data.angle_pwm = 0; + optical_read_data.data.iq_zad_i_zad = 0; +// optical_read_data.data.cmd.all = 0x40; // временно! alarm = 1 + optical_read_data.data.cmd.all = 0; + } + } + + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + if (optbus_status.bit.new_data_ready) + { + PWM_LINES_TK_18_ON; + } +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12) + { + PWM_LINES_TK_16_ON; + } +#endif + + } + + + + + + if (optical_read_data.timer>=t1) + { +//i_led2_on_off(1); +//i_led2_on_off(0); +//i_led2_on_off(1); +//i_led2_on_off(0); +//i_led2_on_off(1); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_20_ON; +#endif + optical_bus_write(); + ///////////////// +//i_led2_on_off(0); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_20_OFF; +#endif + + optical_read_data.timer = 0; + + } + +// if (prev_error_read==0) +// i_led2_off(); + + +// if (optical_read_data.timer==t2) +// { +// +// // if (edrk.flag_second_PCH==0) +// stage_2 = 1; +// // else +// // stage_1 = 1; +// +// optical_read_data.timer = 0; +// } + +// if (optical_read_data.timer>=t3) +// { +// optical_read_data.timer = 0; +// } + + + + + +// +// if (stage_1==2 && prev_stage1!=stage_1) +// { +// // i_led2_on(); +//// if (flag_disable_resend==0) +//// { +// // if (edrk.ms.another_bs_maybe_on==1 && (edrk.auto_master_slave.local.bits.master ) ) +// +// // if (edrk.flag_second_PCH==0) +// { +// i_led2_on(); +// i_led2_off(); +// i_led2_on(); +// +// optical_bus_write(); +// } +//// else +//// { +//// i_led2_on(); +//// +//// optical_bus_read(); +//// optbus_status = optical_bus_get_status_and_read(); +//// buf_status[cc] = optbus_status; +//// cc++; +//// +//// if (optbus_status.bit.new_data_ready) +//// optical_read_data.data_was_update_between_pwm_int = 1; +//// +//// if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 +//// ) +//// { +//// i_led1_on(); +//// i_led1_off(); +//// +//// } +//// +//// } +// stage_1 = 0; +// } + +// if (stage_1==1 && prev_stage1!=stage_1) +// { +// +//// if (edrk.flag_second_PCH==1) +//// { +//// i_led2_on(); +//// i_led2_off(); +//// i_led2_on(); +//// +//// optical_bus_write(); +//// } +//// else +// // { +// i_led2_on(); +// +// optical_bus_read(); +// optbus_status = optical_bus_get_status_and_read(); +// buf_status[cc] = optbus_status; +// cc++; +// +// if (optbus_status.bit.new_data_ready) +// optical_read_data.data_was_update_between_pwm_int = 1; +// +// if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 +// ) +// { +// i_led1_on(); +// i_led1_off(); +// +// } +// +// // } +// +// +// // stage_1 = 0; +// } + + // prev_stage1 = stage_1; + // } +// if (edrk.flag_second_PCH==1) +// { +// i_led2_off(); +// } + +//i_led2_on_off(0); + +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(102); +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + PWM_LINES_TK_17_OFF; +#endif + + +} +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// inline void init_regulators() @@ -272,8 +702,7 @@ inline void init_regulators() #define PAUSE_ERROR_DETECT_UPDATE_OPTBUS_DATA 900// ((unsigned int)(1*FREQ_PWM*2)) // ~1sec //50 #define MAX_TIMER_WAIT_SET_TO_ZERO_ZADANIE 27000 //((unsigned int)(30*FREQ_PWM*2)) // 60 sec -//#define MAX_TIMER_WAIT_BOTH_READY2 108000 //(120*FREQ_PWM*2) // 120 sec -#define MAX_TIMER_WAIT_BOTH_READY2 216000 //(120*FREQ_PWM*2) // 240 sec +#define MAX_TIMER_WAIT_BOTH_READY2 108000 //(120*FREQ_PWM*2) // 120 sec #define MAX_TIMER_WAIT_MASTER_SLAVE 4500 // 5 sec /////////////////////////////////////////////////////////////////// @@ -285,29 +714,20 @@ inline void init_regulators() /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// -//#define _ENABLE_PWM_LED2_PROFILE 1 - - -#if (_ENABLE_PWM_LED2_PROFILE) -unsigned int profile_pwm[30]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; -unsigned int pos_profile_pwm = 0; -#endif - /////////////////////////////////////////////////////////////////// -#define _ENABLE_LOG_TICS_PWM 0//1 -#define _ENABLE_SLOW_PWM 0//1 -#define _ENABLE_INTERRUPT_PWM_LED2 0//1 +//#define _ENABLE_LOG_TICS_PWM 1 +#define _ENABLE_SLOW_PWM 1 +#define _ENABLE_INTERRUPT_PWM_LED2 0//1 #if (_ENABLE_LOG_TICS_PWM==1) static int c_run=0; static int c_run_start=0; -static int i_log; #pragma DATA_SECTION(time_buf,".slow_vars"); #define MAX_COUNT_TIME_BUF 50 -int time_buf[MAX_COUNT_TIME_BUF] = {0}; +unsigned int time_buf[MAX_COUNT_TIME_BUF] = {0}; //#define get_tics_timer_pwm(flag,k) {if (flag) {time_buf[k] = (unsigned int)(EvbRegs.T3CNT-start_tics_4timer);k++;}else{time_buf[k] = -1; k++;}} @@ -320,7 +740,7 @@ static int count_timer_buf=0; #define get_tics_timer_pwm(flag) asm(" NOP;") #define set_tics_timer_pwm(flag,k) asm(" NOP;") -//static int count_timer_buf=0; +static int count_timer_buf=0; #endif @@ -334,15 +754,10 @@ int stop_count_time_buf=0; unsigned int log_wait; unsigned int end_tics_4timer, start_tics_4timer; -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// #if (_ENABLE_LOG_TICS_PWM==1) -//#pragma CODE_SECTION(get_tics_timer_pwm,".fast_run"); +#pragma CODE_SECTION(get_tics_timer_pwm,".fast_run"); void get_tics_timer_pwm(unsigned int flag) { unsigned int delta; @@ -367,238 +782,16 @@ void get_tics_timer_pwm(unsigned int flag) #endif -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////// -// получаем данные с датчика оборотов -/////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(calc_rotors,".fast_run"); -void calc_rotors(int flag) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_17_ON; -#endif - - update_rot_sensors(); - - - - set_tics_timer_pwm(6,count_timer_buf); - get_tics_timer_pwm(flag); - - -#if(C_cds_in_number>=1) - project.cds_in[0].read_pbus(&project.cds_in[0]); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_17_OFF; -#endif - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_19_ON; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - RotorMeasureDetectDirection(); - RotorMeasure();// измеритель -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - Rotor_measure_22220(); - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_19_OFF; -#endif - - set_tics_timer_pwm(7,count_timer_buf); - get_tics_timer_pwm(flag); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_ON; -#endif - -// RotorMeasurePBus(); -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow, &WRotorPBus.RotorDirectionSlow2, &WRotorPBus.RotorDirectionCount); -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) - // 22220 - // nothing -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_ON; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - select_values_wrotor(); -#endif -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - select_values_wrotor_22220(); - -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_OFF; -#endif - - set_tics_timer_pwm(8,count_timer_buf); - get_tics_timer_pwm(flag); - -#endif //(C_cds_in_number>=1) - - - edrk.rotor_direction = WRotor.RotorDirectionSlow; - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - edrk.iq_f_rotor_hz = WRotor.iqWRotorSumFilter; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - edrk.iq_f_rotor_hz = WRotor.iqWRotorSum; -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(calc_zadanie_rampa,".fast_run"); -void calc_zadanie_rampa(void) -{ -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_19_ON; -#endif - - - // подхват при смене режима - load_current_ramp_oborots_power(); - - if (edrk.StartGEDfromControl==0) - ramp_all_zadanie(2); // форсируем в ноль - else - if (edrk.flag_wait_set_to_zero_zadanie || edrk.flag_block_zadanie || edrk.Status_Ready.bits.ready_final==0 || /*edrk.StartGEDfromControl==0 ||*/ edrk.run_razbor_shema == 1) - ramp_all_zadanie(1); // стремим рампы в ноль, ка ктолько они доедут в ноль, то снимается edrk.StartGEDfromZadanie - else - ramp_all_zadanie(0); // тут все по штатному - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_19_OFF; -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -#pragma CODE_SECTION(async_pwm_ext_interrupt,".fast_run2"); -void async_pwm_ext_interrupt(void) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_19_ON; -#endif - if (edrk.run_to_pwm_async) - { - PWM_interrupt(); - edrk.run_to_pwm_async = 0; - } - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_19_OFF; -#endif - -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -void run_detect_fast_error(void) -{ - - detect_error_u_zpt_fast(); - detect_error_u_in(); - -} -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(PWM_interrupt_main,".fast_run"); -void PWM_interrupt_main(void) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_16_ON; -#endif - - norma_adc_nc(0); - - edrk.run_to_pwm_async = 1; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_16_OFF; -#endif - -} -//////////////////////////////////////////////////////////////////////////////// - - -#define MAX_COUNT_COUNTSTARTGEDFROMZADANIE FREQ_PWM //3000 // задержка в тактах появления единицы в edrk.StartGEDfromZadanie - - - #pragma CODE_SECTION(PWM_interrupt,".fast_run"); void PWM_interrupt(void) { static unsigned int pwm_run = 0; - static _iq Uzad1=0, Fzad=0, Uzad2=0, Izad_out = 0, Uzad_from_master = 0; - -// static int count_step_ram_off = 0; -// static int count_start_impuls = 0; - + static _iq Uzad1=0, Fzad=0, Uzad2=0, Izad_out = 0; + static int count_step=0; + static int count_step_ram_off = 0; + static int count_start_impuls = 0; + static int flag_record_log = 0; static int prevGo = -1; static volatile unsigned int go_a = 0; static volatile unsigned int go_b = 0; @@ -611,16 +804,21 @@ void PWM_interrupt(void) static unsigned int prev_timer = 0; unsigned int cur_timer; static unsigned int count_lost_interrupt=0; - static int en_rotor = 1;//1; + static int en_rotor = 0;//1; + static unsigned long timer_wait_set_to_zero_zadanie = 0; static unsigned long timer_wait_both_ready2 = 0; + static unsigned int prev_error_controller = 0,error_controller=0; - static unsigned long time_delta = 0; - static unsigned int run_calc_uf = 0, prev_run_calc_uf = 0, count_wait_go_0 = 0; + + + unsigned long time_delta = 0; + + static unsigned int count_step_run = 0, run_calc_uf = 0, prev_run_calc_uf = 0, count_wait_go_0 = 0; int pwm_enable_calc_main = 0, pwm_up_down = 0, err_interr = 0, slow_error = 0; @@ -641,28 +839,14 @@ void PWM_interrupt(void) static int pwm_enable_calc_main_log = 1; - static int what_pwm = 0; - - int localStartGEDfromZadanie; - static unsigned int countStartGEDfromZadanie = 0; - // OPTICAL_BUS_CODE_STATUS optbus_status = {0}; - static STATUS_DATA_READ_OPT_BUS optbus_status; + STATUS_DATA_READ_OPT_BUS optbus_status; _iq wd; // if (edrk.disable_interrupt_sync==0) // start_sync_interrupt(); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_16_ON; -#endif - #if(_ENABLE_PWM_LINES_FOR_TESTS) // PWM_LINES_TK_16_ON; #endif @@ -675,57 +859,24 @@ i_led2_on_off(1); if (edrk.disable_interrupt_pwm) { - pwm_inc_interrupt(); +// i_led1_on_off(0); return; } if (flag_special_mode_rs==1) { - calc_norm_ADC_0(1); - calc_norm_ADC_1(1); - pwm_inc_interrupt(); + calc_norm_ADC(0); +// inc_RS_timeout_cicle(); +// inc_CAN_timeout_cicle(); + +//i_led2_on_off(0); return; } -#if (_ENABLE_PWM_LED2_PROFILE) - pos_profile_pwm = 0; -#endif - - - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - -// if (xpwm_time.what_next_interrupt==PWM_LOW_LEVEL_INTERRUPT) -// { -//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) -// PWM_LINES_TK_17_ON; -//#endif -// -// i_sync_pin_on(); -// -// } -// else -// { -//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) -// PWM_LINES_TK_17_OFF; -//#endif -// -// i_sync_pin_off(); -// } - - //////////////// -//PWN_COUNT_RUN_PER_INTERRUPT PWM_TWICE_INTERRUPT_RUN - err_interr = detect_level_interrupt(edrk.flag_second_PCH); - + err_interr = detect_level_interrupt(); if (err_interr) edrk.errors.e3.bits.ERR_INT_PWM_LONG |=1; @@ -742,9 +893,8 @@ i_led2_on_off(1); // sync line if (pwm_up_down==2 || pwm_up_down==0) { -// what_pwm = 0; - // i_sync_pin_on(); - calculate_sync_detected(); + i_sync_pin_on(); +// i_led1_on_off(1); } ///////////////// @@ -768,6 +918,8 @@ i_led2_on_off(1); #endif + + edrk.into_pwm_interrupt = 1; // подготовка подсчета времени работы в прерывании @@ -795,19 +947,11 @@ i_led2_on_off(1); set_tics_timer_pwm(1,count_timer_buf); get_tics_timer_pwm(1); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_17_ON; -#endif - -#if (_SIMULATE_AC==1) - calc_norm_ADC_0_sim(0); -#else - calc_norm_ADC_0(0); // читаем АЦП а norma была запущена в Pwm_main() -#endif - run_detect_fast_error(); //быстрые защиты - + calc_norm_ADC(0); // читаем АЦП +//i_led2_on_off(0);//1 +//i_led2_on_off(1); ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// @@ -815,7 +959,7 @@ i_led2_on_off(1); if (edrk.Kvitir==0 && prev_edrk_Kvitir==1) { count_err_read_opt_bus = 0; - edrk.sum_count_err_read_opt_bus = 0; + sum_count_err_read_opt_bus = 0; } set_tics_timer_pwm(2,count_timer_buf); @@ -825,10 +969,17 @@ i_led2_on_off(1); // inc_RS_timeout_cicle(); //////////////////////////////// //////////////////////////////////////////// +// i_led1_off(); +// set_tics_timer_pwm(3,count_timer_buf); +// get_tics_timer_pwm(1); + //////////////////////////////////////////// // inc_CAN_timeout_cicle(); //////////////////////////////////////////// +// set_tics_timer_pwm(4,count_timer_buf); +// get_tics_timer_pwm(1); + if (edrk.ms.another_bs_maybe_on==1 && (edrk.auto_master_slave.local.bits.master || edrk.auto_master_slave.local.bits.slave) ) { @@ -875,61 +1026,74 @@ i_led2_on_off(1); optical_read_data.flag_clear = 1; +//i_led2_on_off(0);//2 +//i_led2_on_off(1); + + if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT || xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) { pwm_enable_calc_main = 1; - if (sync_data.what_main_pch) +// if (edrk.flag_second_PCH) { - if (sync_data.what_main_pch==2) - { - if (edrk.flag_second_PCH==1) // только на втором БС - { - fix_pwm_freq_synchro_ain(); - } - } - - if (sync_data.what_main_pch==1) - { - if (edrk.flag_second_PCH==0) // только на втором БС - { - fix_pwm_freq_synchro_ain(); - } - } - } - else fix_pwm_freq_synchro_ain(); + } + set_tics_timer_pwm(5,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + if (en_rotor) + update_rot_sensors(); + + set_tics_timer_pwm(6,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + if (en_rotor) + { + RotorMeasure(); + set_tics_timer_pwm(7,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + RotorMeasurePBus(); + set_tics_timer_pwm(8,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + } } else - { pwm_enable_calc_main = 0; - } + + +// calc_norm_ADC(); + set_tics_timer_pwm(9,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + // calc_pll_50hz(); + +//i_led2_on_off(0);//1 +//i_led2_on_off(1); + ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// -//#if(C_cds_in_number>=1) -// project.cds_in[0].read_pbus(&project.cds_in[0]); -//#endif - +#if(C_cds_in_number>=1) + project.cds_in[0].read_pbus(&project.cds_in[0]); +#endif #if(C_cds_in_number>=2) project.cds_in[1].read_pbus(&project.cds_in[1]); #endif -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_17_OFF; -#endif - - +//i_led2_on_off(0);//2 +//i_led2_on_off(1); set_tics_timer_pwm(10,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); +// i_led1_on_off(1); + if (pwm_run == 1) { // зашли в прерывание но почему-то мы уже были тут, повторный заход? @@ -941,12 +1105,16 @@ i_led2_on_off(1); pwm_run = 1; // detect_I_M_overload(); -// if (edrk.from_rs.bits.ACTIVE) -// edrk.Go = edrk.StartGEDRS; -// project_read_errors_controller(); // чтение ADR_ERRORS_TOTAL_INFO - if ( (edrk.errors.e0.all) + // if (edrk.from_rs.bits.ACTIVE) +// edrk.Go = edrk.StartGEDRS; + + + +// project_read_errors_controller(); // чтение ADR_ERRORS_TOTAL_INFO + + if ((edrk.errors.e0.all) || (edrk.errors.e1.all) || (edrk.errors.e2.all) || (edrk.errors.e3.all) @@ -955,23 +1123,23 @@ i_led2_on_off(1); || (edrk.errors.e6.all) || (edrk.errors.e7.all) || (edrk.errors.e8.all) - || (edrk.errors.e9.all) - || (edrk.errors.e10.all) - || (edrk.errors.e11.all) - || (edrk.errors.e12.all) - ) + ||(edrk.errors.e9.all) + ||(edrk.errors.e10.all) + ||(edrk.errors.e11.all) + ||(edrk.errors.e12.all) + ) edrk.Stop |= 1; else edrk.Stop = 0; +//i_led2_on_off(0);//3 +//i_led2_on_off(1); project.read_errors_controller(); error_controller = (project.controller.read.errors.all | project.controller.read.errors_buses.bit.slave_addr_error | project.controller.read.errors_buses.bit.count_error_pbus); // project.controller.read.errors.all = error_controller; - - if(error_controller && prev_error_controller==0) { edrk.errors.e11.bits.ERROR_CONTROLLER_BUS |= 1; @@ -985,54 +1153,9 @@ i_led2_on_off(1); prev_error_controller = error_controller;//project.controller.read.errors.all; - if (pwm_enable_calc_main==0)// заходим в расчет только раз за период шима - вторая часть - { - - if (en_rotor) - { -#if (_SIMULATE_AC==1) -// calc_rotors_sim(); -#else - calc_rotors(pwm_enable_calc_main_log); // получаем данные с датчика оборотов -#endif - - - - } - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - calc_zadanie_rampa(); - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - calc_norm_ADC_1(1); // замер температур - - calc_power_full(); - - calc_all_limit_koeffs(); - - } - - ///////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////// - - if (pwm_enable_calc_main)// заходим в расчет только раз за период шима { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_18_ON; -#endif - if (edrk.Obmotka1 == 0) go_a = 1; else @@ -1053,11 +1176,14 @@ i_led2_on_off(1); edrk.master_Uzad = _IQ15toIQ( optical_read_data.data.pzad_or_wzad); edrk.master_theta = _IQ12toIQ( optical_read_data.data.angle_pwm); edrk.master_Izad = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); - edrk.master_Iq = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); + edrk.master_Iq = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); set_tics_timer_pwm(11,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); +//i_led2_on_off(0);//4 +//i_led2_on_off(1); + ///////////////////////// if ((edrk.auto_master_slave.local.bits.slave==1 && edrk.auto_master_slave.local.bits.master==0) @@ -1094,61 +1220,42 @@ i_led2_on_off(1); timer_wait_to_master_slave = 0; } +//i_led2_on_off(0);//5 +//i_led2_on_off(1); set_tics_timer_pwm(12,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { if (edrk.MasterSlave == MODE_MASTER) { if (get_start_ged_from_zadanie()) { edrk.prepare_stop_PWM = 0; - //edrk.StartGEDfromZadanie = 1; - localStartGEDfromZadanie = 1; + edrk.StartGEDfromZadanie = 1; } else { edrk.prepare_stop_PWM = 1; if (edrk.k_stator1 < 41943) { //335544 ~ 2% - //edrk.StartGEDfromZadanie = 0; - localStartGEDfromZadanie = 0; + edrk.StartGEDfromZadanie = 0; } } } else { if (get_start_ged_from_zadanie()) { - //edrk.StartGEDfromZadanie = 1; - localStartGEDfromZadanie = 1; + edrk.StartGEDfromZadanie = 1; } else { if (edrk.k_stator1 < 41943) { //335544 ~ 2% - //edrk.StartGEDfromZadanie = 0; - localStartGEDfromZadanie = 0; + edrk.StartGEDfromZadanie = 0; } } edrk.prepare_stop_PWM = optical_read_data.data.cmd.bit.prepare_stop_PWM; } } else { - //edrk.StartGEDfromZadanie = - localStartGEDfromZadanie = get_start_ged_from_zadanie(); + edrk.StartGEDfromZadanie = get_start_ged_from_zadanie(); } - // задержка прохождения localStartGEDfromZadanie=1 в edrk.StartGEDfromZadanie - if (localStartGEDfromZadanie && edrk.prevStartGEDfromZadanie==0) - { - if (countStartGEDfromZadanie 0) + if (count_step_ram_off > 0) { - f.count_step_ram_off--; - f.flag_record_log = 1; + count_step_ram_off--; + flag_record_log = 1; } else { - f.flag_record_log = 0; + flag_record_log = 0; } +// pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor, + // rotor.iqFout, 0); + // ручной разряд + if (edrk.ManualDischarge && prev_ManualDischarge!=edrk.ManualDischarge) edrk.Discharge = 1; prev_ManualDischarge =edrk.ManualDischarge; - if (f.count_start_impuls == 0) - { - - if (edrk.Discharge || (edrk.ManualDischarge ) ) - { + if (count_start_impuls == 0) { + if (edrk.Discharge || (edrk.ManualDischarge ) ) { break_resistor_managment_calc(); soft_start_x24_break_1(); + } else { + // это произойдет только на последнем такте выключения + soft_stop_x24_pwm_all(); } - else - { - - if (f.count_step_ram_off > 0) - { - break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); - // soft_start_x24_break_1(); - } - else - { - // это произойдет только на последнем такте выключения - soft_stop_x24_pwm_all(); - - } - } - } set_tics_timer_pwm(16,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); - if (f.count_start_impuls==COUNT_START_IMP) + if (count_start_impuls==COUNT_START_IMP) { if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { @@ -1499,7 +1588,7 @@ i_led2_on_off(1); } vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, @@ -1533,7 +1622,7 @@ i_led2_on_off(1); } else { - if (f.count_start_impuls==COUNT_START_IMP-1) + if (count_start_impuls==COUNT_START_IMP-1) { if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) @@ -1545,7 +1634,7 @@ i_led2_on_off(1); } vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, @@ -1580,7 +1669,7 @@ i_led2_on_off(1); } else { - if (f.count_start_impuls==COUNT_START_IMP-2) + if (count_start_impuls==COUNT_START_IMP-2) { // тут опять middle состояние перед выключением ключей // svgen_set_time_keys_closed(&svgen_pwm24_1); @@ -1601,27 +1690,29 @@ i_led2_on_off(1); } - if (f.count_start_impuls > 0) { - f.count_start_impuls -= 1; + if (count_start_impuls > 0) { + count_start_impuls -= 1; } else { - f.count_start_impuls = 0; + count_start_impuls = 0; } enable_calc_vector = 0; - +// k1 = 0; //Edited Aleksey +// k2 = 0; Uzad1 = 0; Uzad2 = 0; } // end if Go==1 -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_18_OFF; -#endif - } // end pwm_enable_calc_main one interrupt one period only + +//i_led2_on_off(0);//10 +//i_led2_on_off(1); + + /* * // if ((m.m0.bit.EnableGoA == 1) && (f.Obmotka1 == 0)) @@ -1680,7 +1771,8 @@ i_led2_on_off(1); { - if (f.count_start_impuls==1 && edrk.Go==1) + + if (count_start_impuls==1 && edrk.Go==1) { // а тут мы еше не включились svgen_set_time_keys_closed(&svgen_pwm24_1); @@ -1693,7 +1785,7 @@ i_led2_on_off(1); wd = uf_alg.winding_displacement_bs2; } vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.P_from_slave, @@ -1701,7 +1793,7 @@ i_led2_on_off(1); } } - if (f.count_start_impuls==2 && edrk.Go==1) + if (count_start_impuls==2 && edrk.Go==1) { // включаем ШИМ if (go_a == 1 && go_b == 1) { @@ -1712,21 +1804,10 @@ i_led2_on_off(1); } else if (go_b == 1) { soft_start_x24_pwm_2(); } - - // enable work break -#if (DISABLE_WORK_BREAK==1) - -#else -// if (edrk.disable_break_work==0) - { - soft_start_x24_break_1(); - } -#endif - } // end if (count_start_impuls==5) - if (f.count_start_impuls==3 && edrk.Go==1) + if (count_start_impuls==3 && edrk.Go==1) { // готовимся разрешить ШИМ svgen_set_time_middle_keys_open(&svgen_pwm24_1); @@ -1735,7 +1816,7 @@ i_led2_on_off(1); - if (f.count_start_impuls==4 && edrk.Go==1) + if (count_start_impuls==4 && edrk.Go==1) { if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { @@ -1751,7 +1832,7 @@ i_led2_on_off(1); } vectorControlConstId(0, 0, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, @@ -1781,8 +1862,8 @@ i_led2_on_off(1); &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); - simple_scalar(1,0, WRotor.RotorDirectionSlow, - WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter, + simple_scalar(1,0, + WRotor.iqWRotorCalcBeforeRegul1, WRotor.iqWRotorCalcBeforeRegul1, 0, 0, 0, edrk.iq_bpsi_normal, @@ -1791,24 +1872,18 @@ i_led2_on_off(1); edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, 0, edrk.zadanie.iq_power_zad_rmp, 0, - edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, - 0,0, edrk.count_bs_work+1, + 0,0, &Fzad, &Uzad1, &Uzad2, &Izad_out); } } - if (f.count_start_impuls == COUNT_START_IMP && edrk.Go==1) + if (count_start_impuls == COUNT_START_IMP && edrk.Go==1) { if (pwm_enable_calc_main) // заходим в расчет только раз за период шима { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_21_ON; -#endif - - //break_resistor_recup_calc(edrk.zadanie.iq_ZadanieU_Charge); - break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); + break_resistor_recup_calc(edrk.zadanie.iq_ZadanieU_Charge); set_tics_timer_pwm(17,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); @@ -1818,34 +1893,18 @@ i_led2_on_off(1); // основная работа тут, ШИМ уже включен в middle if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_UF_CONST) { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif + uf_const(&Fzad,&Uzad1,&Uzad2); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - - test_calc_simple_dq_pwm24_Ing(Fzad, - Uzad1, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance, - edrk.zadanie.iq_k_u_disbalance, - filter.iqU_1_fast, - filter.iqU_2_fast, + test_calc_simple_dq_pwm24_Ing(Fzad, Uzad1, edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance, edrk.zadanie.iq_k_u_disbalance, filter.iqU_1_fast, filter.iqU_2_fast, 0, edrk.Uzad_max, edrk.master_theta, edrk.master_Uzad, edrk.MasterSlave, edrk.flag_second_PCH, - &edrk.Kplus, - &edrk.tetta_to_slave, - &edrk.Uzad_to_slave); + &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); // rmp_freq.DesiredInput = alg_pwm24.freq1; // rmp_freq.calc(&rmp_freq); // Fzad = rmp_freq.Out; @@ -1857,9 +1916,7 @@ i_led2_on_off(1); // Uzad1 = alg_pwm24.k1; // Uzad2 = alg_pwm24.k1; -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif + // test_calc_pwm24(Uzad1, Uzad2, Fzad); // analog_dq_calc_const(); @@ -1868,81 +1925,40 @@ i_led2_on_off(1); else if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER) { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - simple_scalar(1, - 0, - WRotor.RotorDirectionSlow, - WRotor.iqWRotorSumFilter, //rotor_22220.iqFlong * rotor_22220.direct_rotor; - WRotor.iqWRotorSumFilter, //rotor_22220.iqFout * rotor_22220.direct_rotor; - //0, 0, - edrk.zadanie.iq_oborots_zad_hz_rmp, - edrk.all_limit_koeffs.sum_limit, - edrk.zadanie.iq_Izad_rmp, - edrk.iq_bpsi_normal, + simple_scalar(1,0, + WRotor.iqWRotorCalcBeforeRegul1, WRotor.iqWRotorCalcBeforeRegul1, edrk.zadanie.iq_oborots_zad_hz_rmp, + edrk.temper_limit_koeffs.sum_limit, + edrk.zadanie.iq_Izad_rmp, edrk.iq_bpsi_normal, analog.iqIm, // analog.iqU_1_long+analog.iqU_2_long, edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, analog.iqIin_sum, - edrk.zadanie.iq_power_zad_rmp, - edrk.iq_power_kw_full_znak,//(filter.PowerScalar+edrk.iq_power_kw_another_bs), - edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, - edrk.master_Izad, - edrk.MasterSlave, - edrk.count_bs_work+1, - &Fzad, - &Uzad1, - &Uzad2, - &Izad_out); + edrk.zadanie.iq_power_zad_rmp, (filter.PowerScalar+edrk.iq_power_kw_another_bs), + edrk.master_Izad, edrk.MasterSlave, + &Fzad, &Uzad1, &Uzad2, &Izad_out); set_tics_timer_pwm(18,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - - - - if (edrk.cmd_disable_calc_km_on_slave) - Uzad_from_master = edrk.master_Uzad; - else - { -#if (DISABLE_CALC_KM_ON_SLAVE==1) - Uzad_from_master = edrk.master_Uzad; -#else - Uzad_from_master = Uzad1; -#endif - - } test_calc_simple_dq_pwm24_Ing(Fzad, Uzad1, edrk.disable_alg_u_disbalance, edrk.zadanie.iq_kplus_u_disbalance, edrk.zadanie.iq_k_u_disbalance, filter.iqU_1_fast, filter.iqU_2_fast, 0, edrk.Uzad_max, edrk.master_theta, - Uzad_from_master, + Uzad1, //edrk.master_Uzad, edrk.MasterSlave, edrk.flag_second_PCH, &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif set_tics_timer_pwm(19,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); - if (edrk.flag_second_PCH == 0) { wd = uf_alg.winding_displacement_bs1; } else { wd = uf_alg.winding_displacement_bs2; } - analog_dq_calc_external(wd, uf_alg.tetta); } // end ALG_MODE_SCALAR_OBOROTS @@ -1959,23 +1975,14 @@ i_led2_on_off(1); } else { wd = uf_alg.winding_displacement_bs2; } -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif + vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, 0, edrk.prepare_stop_PWM); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, edrk.disable_alg_u_disbalance, @@ -1986,55 +1993,35 @@ i_led2_on_off(1); edrk.MasterSlave, edrk.flag_second_PCH, &edrk.Kplus, &edrk.Uzad_to_slave); - analog.PowerFOC = edrk.P_to_master; Fzad = vect_control.iqFstator; Izad_out = edrk.Iq_to_slave; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif } // end ALG_MODE_FOC_OBOROTS -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_21_OFF; -#endif } // end pwm_enable_calc_main } // end (count_start_impuls == COUNT_START_IMP && edrk.Go==1) else { - run_calc_uf = 0; - if (pwm_enable_calc_main) // заходим в расчет только раз за период шима - { - - } - svgen_pwm24_1.Ta_imp = 0; - svgen_pwm24_1.Tb_imp = 0; - svgen_pwm24_1.Tc_imp = 0; - svgen_pwm24_2.Ta_imp = 0; - svgen_pwm24_2.Tb_imp = 0; - svgen_pwm24_2.Tc_imp = 0; - + run_calc_uf = 0; } // end else (count_start_impuls == COUNT_START_IMP && edrk.Go==1) + + prevGo = edrk.Go; - - ////////////////////////////////// optical_write_data.data.cmd.bit.start_pwm = edrk.Go; optical_write_data.data.cmd.bit.prepare_stop_PWM = edrk.prepare_stop_PWM; - optical_write_data.data.angle_pwm = _IQtoIQ12(edrk.tetta_to_slave + vect_control.add_tetta); + optical_write_data.data.angle_pwm = _IQtoIQ12(edrk.tetta_to_slave); optical_write_data.data.pzad_or_wzad = _IQtoIQ15(edrk.Uzad_to_slave); optical_write_data.data.iq_zad_i_zad = _IQtoIQ15(edrk.Izad_out); optical_bus_update_data_write(); - set_tics_timer_pwm(20,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); + get_tics_timer_pwm(pwm_enable_calc_main_log); if (edrk.ms.another_bs_maybe_on==1 && edrk.auto_master_slave.local.bits.master) @@ -2045,6 +2032,41 @@ i_led2_on_off(1); ////////////////////////////////// ////////////////////////////////// +// write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); + +// if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN || count_start_impuls= (2 * COUNT_START_IMP) ) { + + uf_const_f_24(Fzad, Fzad, Uzad1, Uzad2, f.Revers, edrk.disable_alg_u_disbalance, edrk.kplus_u_disbalance, edrk.k_u_disbalance, filter.iqU_1_fast, filter.iqU_1_fast); + + } else { +// svgen_set_time_keys_closed(&svgen_pwm24_1); +// svgen_set_time_keys_closed(&svgen_pwm24_2); + svgen_set_time_middle_keys_open(&svgen_pwm24_1); + svgen_set_time_middle_keys_open(&svgen_pwm24_2); + } +*/ + + + +/* + if (flag_record_log) + { + // i_led1_on_off(0); + // test_calc_pwm24(Uzad1, Uzad2, Fzad); +// uf_const_f( Fzad, Fzad, Uzad1, Uzad2, f.Revers ); // space vector pwm sandart algoritm + uf_const_f_24(Fzad, Fzad, Uzad1, Uzad2, f.Revers, edrk.disable_alg_u_disbalance, edrk.kplus_u_disbalance, edrk.k_u_disbalance, filter.iqU_1_fast, filter.iqU_1_fast); + + + // i_led1_on_off(1); + + if (go_a == 0) { + svgen_set_time_keys_closed(&svgen_pwm24_1); + } + if (go_b == 0) { + svgen_set_time_keys_closed(&svgen_pwm24_2); + } + + + } else { + svgen_set_time_keys_closed(&svgen_pwm24_1); + svgen_set_time_keys_closed(&svgen_pwm24_2); + } +*/ + + // test write oscil buf - if ( pwm_enable_calc_main==0) // заходим в расчет только раз за период шима + if ( pwm_enable_calc_main) // заходим в расчет только раз за период шима { +// if (oscil_can.enable_rewrite && oscil_can.global_enable) + if (oscil_can.enable_rewrite) + { - run_write_logs(); + if (edrk.Go) + oscil_can.status_pwm = 1; + else + oscil_can.status_pwm = 0; + + + if ( (edrk.Stop == 0) && (project.controller.read.errors.all==0) ) + oscil_can.status_error = 0; + else + oscil_can.status_error = 1; + + oscil_can.oscil_buffer[0][oscil_can.current_position] = global_time.pwm_tics; +// if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { + oscil_can.oscil_buffer[1][oscil_can.current_position] = (int16) _IQtoIQ15(filter.iqU_1_long);//xpwm_time.Ta0_0; //(int16) _IQtoIQ15(turns.pidFvect.Ui); + oscil_can.oscil_buffer[2][oscil_can.current_position] = (int16) _IQtoIQ15(filter.iqU_2_long);//xpwm_time.Ta0_1; //(int16) _IQtoIQ15(turns.pidFvect.Up); + oscil_can.oscil_buffer[3][oscil_can.current_position] = (int16) _IQtoIQ15(turns.pidFvect.Out); + oscil_can.oscil_buffer[4][oscil_can.current_position] = (int16) _IQtoIQ15(turns.pidFvect.OutMax); + oscil_can.oscil_buffer[5][oscil_can.current_position] = (int16) _IQtoIQ15(power.pidP.Out); + oscil_can.oscil_buffer[6][oscil_can.current_position] = (int16) _IQtoIQ15(power.pidP.OutMax); +// } else { +// oscil_can.oscil_buffer[1][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidF.Ui); // count_updated_sbus;//xpwm_time.Ta0_0; +// oscil_can.oscil_buffer[2][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidF.Up); +// oscil_can.oscil_buffer[3][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidF.Out);//xpwm_time.Tb0_0; +// oscil_can.oscil_buffer[4][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidF.OutMax);//xpwm_time.Tb0_1; +// oscil_can.oscil_buffer[5][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidPower.Out);//xpwm_time.Tc0_0; +// oscil_can.oscil_buffer[6][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidPower.OutMax); //xpwm_time.Tc0_1; +// } + + + oscil_can.oscil_buffer[7][oscil_can.current_position] = (int16) _IQtoIQ15(edrk.master_Uzad) ; + oscil_can.oscil_buffer[8][oscil_can.current_position] = (int16) _IQtoIQ12(edrk.master_theta);//global_time.microseconds; + + oscil_can.oscil_buffer[9][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIu_1); + oscil_can.oscil_buffer[10][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIv_1); + oscil_can.oscil_buffer[11][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIw_1); + + oscil_can.oscil_buffer[12][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIu_2); + oscil_can.oscil_buffer[13][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIv_2); + oscil_can.oscil_buffer[14][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIw_2); + + oscil_can.oscil_buffer[15][oscil_can.current_position] = (int16) _IQtoIQ15(turns.Fzad_rmp);//(int16) _IQtoIQ15(analog.iqU_1); + oscil_can.oscil_buffer[16][oscil_can.current_position] = (int16) _IQtoIQ15(WRotor.iqWRotorCalcBeforeRegul1);//(int16) _IQtoIQ15(analog.iqU_2); + +// oscil_can.oscil_buffer[17][oscil_can.current_position] = 0; + + oscil_can.oscil_buffer[18][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqIin_2); + oscil_can.oscil_buffer[19][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqUdCompensation); + oscil_can.oscil_buffer[20][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqUqCompensation); + + oscil_can.oscil_buffer[21][oscil_can.current_position] = (int16) _IQtoIQ15(edrk.f_stator); + oscil_can.oscil_buffer[22][oscil_can.current_position] = (int16) _IQtoIQ12(edrk.k_stator1); + + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { + oscil_can.oscil_buffer[17][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqPvsi1 + vect_control.iqPvsi2); + oscil_can.oscil_buffer[23][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqId1);//(int16) _IQtoIQ15(WRotorPBus.iqAngle1F); + oscil_can.oscil_buffer[24][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqIq1);//(int16) _IQtoIQ15(WRotorPBus.iqAngle2F); + oscil_can.oscil_buffer[25][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.iqFsl); + oscil_can.oscil_buffer[26][oscil_can.current_position] = (int16) _IQtoIQ15(turns.mzz_zad_int); + oscil_can.oscil_buffer[27][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.pidD1.Out);//(int16) _IQtoIQ15(WRotorPBus.iqWRotorCalcBeforeRegul1); + oscil_can.oscil_buffer[28][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.pidQ1.Out); + oscil_can.oscil_buffer[29][oscil_can.current_position] = (int16) _IQtoIQ15(vect_control.pidD1.Ref); + } else { + oscil_can.oscil_buffer[17][oscil_can.current_position] = (int16) _IQtoIQ15(analog.PowerScalar); + oscil_can.oscil_buffer[23][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidIm1.Ui); // count_updated_sbus;//xpwm_time.Ta0_0; + oscil_can.oscil_buffer[24][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidIm1.Up); + oscil_can.oscil_buffer[25][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.pidIm1.Out); + oscil_can.oscil_buffer[26][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.mzz_zad_int);//(int16) _IQtoIQ15(WRotor.iqWRotorCalcBeforeRegul1); + oscil_can.oscil_buffer[27][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.Im_regul);//(int16) _IQtoIQ15(WRotorPBus.iqWRotorCalcBeforeRegul1); + oscil_can.oscil_buffer[28][oscil_can.current_position] = (int16) _IQtoIQ15(edrk.Kplus); + oscil_can.oscil_buffer[29][oscil_can.current_position] = (int16) _IQtoIQ15(filter.iqIm); + } + + +// oscil_can.oscil_buffer[23][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.Izad);//(int16) _IQtoIQ15(WRotorPBus.iqAngle1F); +// oscil_can.oscil_buffer[24][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.Izad_from_master);//(int16) _IQtoIQ15(WRotorPBus.iqAngle2F); +// oscil_can.oscil_buffer[25][oscil_can.current_position] = (int16) _IQtoIQ15(simple_scalar1.mzz_zad);//(int16) _IQtoIQ15(WRotor.iqWRotorImpulses1); + + + + oscil_can.oscil_buffer[30][oscil_can.current_position] = (int16) _IQtoIQ12(edrk.master_theta);//_IQtoIQ15(edrk.Uzad_to_slave); + oscil_can.oscil_buffer[31][oscil_can.current_position] = (int16) _IQtoIQ12(edrk.tetta_to_slave); + + +// oscil_can.oscil_buffer[26][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_m1); +// oscil_can.oscil_buffer[27][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_m2); +// +// oscil_can.oscil_buffer[28][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_A1B1); +// oscil_can.oscil_buffer[29][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_B1C1); +// oscil_can.oscil_buffer[30][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_A2B2); +// oscil_can.oscil_buffer[31][oscil_can.current_position] = (int16) _IQtoIQ15(analog.iqUin_B2C2); + + + oscil_can.set_next_position(&oscil_can); + } + + set_tics_timer_pwm(22,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + // + + + // if ((m.m2.bit.LatchCrashError == 0) && (f.Startstoplog == 0))// && (edrk.Go == 1)) + if ( (f.Startstoplog == 0) && flag_record_log)// && (edrk.Go == 1)) + { + test_mem_limit(FAST_LOG, !f.Ciclelog); + + count_step++; + + if (count_step >= 0) + { + count_step_run++; + // i_led1_on_off(1); + write_to_mem(FAST_LOG, (int16)count_step_run); + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIu_1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIv_1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIw_1)); + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIu_2)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIv_2)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIw_2)); + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqUin_A1B1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqUin_A2B2)); + + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqU_1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqU_2));//10 + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIin_1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIin_2)); + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIm_1)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(analog.iqIm_2)); + + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(filter.iqU_1_long)); + write_to_mem(FAST_LOG, (int16) _IQtoIQ15(filter.iqU_2_long)); + + + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Ta_0); + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Ta_1); + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Tb_0); + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Tb_1); + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Tc_0); + write_to_mem(FAST_LOG,(int16)svgen_pwm24_1.Tc_1); //22 + + write_to_mem(FAST_LOG, (int16) logpar.log1); + write_to_mem(FAST_LOG, (int16) logpar.log2); + write_to_mem(FAST_LOG, (int16) logpar.log3); + write_to_mem(FAST_LOG, (int16) logpar.log4); + write_to_mem(FAST_LOG, (int16) logpar.log5); + write_to_mem(FAST_LOG, (int16) logpar.log6); + write_to_mem(FAST_LOG, (int16) logpar.log7); + write_to_mem(FAST_LOG, (int16) logpar.log8); + write_to_mem(FAST_LOG, (int16) logpar.log9); + + write_to_mem(FAST_LOG, (int16) logpar.log10); + write_to_mem(FAST_LOG, (int16) logpar.log11); + write_to_mem(FAST_LOG, (int16) logpar.log12); + write_to_mem(FAST_LOG, (int16) logpar.log13); + + write_to_mem(FAST_LOG, (int16) project.cds_in[0].read.pbus.ready_in.all); + write_to_mem(FAST_LOG, (int16) project.cds_in[1].read.pbus.ready_in.all); + + if (logpar.start_write_fast_log) { + get_log_params_count(); + logpar.start_write_fast_log = 0; + } + count_step = 0; + } + } + set_tics_timer_pwm(23,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); } + // i_led2_on(); // if (edrk.SumSbor == 1) { @@ -2149,27 +2432,20 @@ i_led2_on_off(1); } // fill_RMS_buff_interrupt(uf_alg.tetta_bs, uf_alg.tetta_bs); - set_tics_timer_pwm(24,count_timer_buf); get_tics_timer_pwm(pwm_enable_calc_main_log); - - + // i_led2_off(); + // i_led2_on(); + // // out_I_over_1_6.calc(&out_I_over_1_6); // i_led2_off(); pwm_run = 0; - + } // end if pwm_run==1 -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif if (pwm_enable_calc_main==0) // заходим в расчет только раз за период шима { @@ -2180,24 +2456,19 @@ i_led2_on_off(1); // inc_RS_timeout_cicle(); // inc_CAN_timeout_cicle(); -#if (_SIMULATE_AC==1) - sim_model_execute(); -#endif } pwm_analog_ext_interrupt(); - pwm_inc_interrupt(); +// i_led1_off(); +// optical_bus_write(); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_OFF; -#endif + // pause_1000(50); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif + // i_led2_off(); + // i_led1_off(); @@ -2207,7 +2478,7 @@ i_led2_on_off(1); #if (_ENABLE_SLOW_PWM) -// pause_1000(slow_pwm_pause); + pause_1000(slow_pwm_pause); #endif set_tics_timer_pwm(26,count_timer_buf); @@ -2237,9 +2508,9 @@ i_led2_on_off(1); #if (_ENABLE_LOG_TICS_PWM==1) - for (i_log=count_timer_buf;i_log 0) - { - flag_revers = 1; - } - else - if (direction == 1 && fzad < 0) - { - flag_revers = 1; - } - else - { - flag_revers = 0; - } - - if (flag_revers && prev_revers==0) - edrk.count_revers++; - - prev_revers = flag_revers; - -} -void calc_power_full(void) -{ - _iq power_full_abs, power_one_abs, power_full_abs_f, power_one_abs_f; - - // - power_one_abs = _IQabs(filter.PowerScalar); - power_one_abs_f = _IQabs(filter.PowerScalarFilter2); - power_full_abs = power_one_abs + _IQabs(edrk.iq_power_kw_another_bs); - power_full_abs_f = power_one_abs_f + _IQabs(edrk.iq_power_kw_another_bs); - - if (edrk.oborots>=0) - { - edrk.iq_power_kw_full_znak = power_full_abs; - edrk.iq_power_kw_one_znak = power_one_abs; - edrk.iq_power_kw_full_filter_znak = power_full_abs_f; - edrk.iq_power_kw_one_filter_znak = power_one_abs_f; - } - else - { - edrk.iq_power_kw_full_znak = -power_full_abs; - edrk.iq_power_kw_one_znak = -power_one_abs; - edrk.iq_power_kw_full_filter_znak = -power_full_abs_f; - edrk.iq_power_kw_one_filter_znak = -power_one_abs_f; - } - - edrk.iq_power_kw_full_abs = power_full_abs; - edrk.iq_power_kw_one_abs = power_one_abs; - edrk.iq_power_kw_full_filter_abs = power_full_abs_f; - edrk.iq_power_kw_one_filter_abs = power_one_abs_f; - -} diff --git a/Inu/Src/main/PWMTools.h b/Inu/Src/main/PWMTools.h index 67f30b2..1fd8297 100644 --- a/Inu/Src/main/PWMTools.h +++ b/Inu/Src/main/PWMTools.h @@ -11,8 +11,7 @@ void InitPWM(void); void PWM_interrupt(void); -void PWM_interrupt_main(void); - +void InitPWM_Variables(void); void stop_wdog(void); @@ -22,20 +21,11 @@ void start_wdog(void); void global_time_interrupt(void); void optical_bus_read_write_interrupt(void); void pwm_analog_ext_interrupt(void); -void pwm_inc_interrupt(void); void fix_pwm_freq_synchro_ain(void); -void async_pwm_ext_interrupt(void); -void calc_rotors(int flag); - -void detect_work_revers(int direction, _iq fzad, _iq frot); - -void calc_power_full(void); - - ////////////////////////////////////////////////// ////////////////////////////////////////////////// diff --git a/Inu/Src/main/adc_tools.c b/Inu/Src/main/adc_tools.c index 80b3b8d..4686bc3 100644 --- a/Inu/Src/main/adc_tools.c +++ b/Inu/Src/main/adc_tools.c @@ -132,8 +132,6 @@ ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF],mask_err_adc_protect[COUNT_AR _iq koef_Im_filter=0; -_iq koef_Power_filter=0; -_iq koef_Power_filter2=0; #pragma DATA_SECTION(k_norm_ADC,".slow_vars") _iq19 k_norm_ADC[COUNT_ARR_ADC_BUF][16]; @@ -167,8 +165,8 @@ _iq koef_Uin_filter=0; void fast_detect_protect_ACP(); -//void fast_read_all_adc_one(int cc); -//void fast_read_all_adc_more(void); +void fast_read_all_adc_one(int cc); +void fast_read_all_adc_more(void); #if (USE_INTERNAL_ADC==1) @@ -576,7 +574,7 @@ void Init_Adc_Variables(void) } - for (i=0;i= component_Ready) detect_zero_analog(i); @@ -592,7 +590,7 @@ void Init_Adc_Variables(void) -#if (COUNT_ARR_ADC_BUF>1) + zero_ADC[1][1]=zero_ADC[1][15]; zero_ADC[1][2]=zero_ADC[1][15]; zero_ADC[1][3]=zero_ADC[1][15]; @@ -607,12 +605,12 @@ void Init_Adc_Variables(void) zero_ADC[1][12]=zero_ADC[1][15]; zero_ADC[1][13]=zero_ADC[1][15]; zero_ADC[1][14]=zero_ADC[1][15]; -#endif + for (k=0;k<16;k++) { - for (i=0;i2200) || (zero_ADC[i][k]<1900)) zero_ADC[i][k] = DEFAULT_ZERO_ADC; @@ -623,7 +621,7 @@ void Init_Adc_Variables(void) for (k=0;k<16;k++) { - for (i=0;iADC_fast[0][k][1] || cc==3) -// ADC_fast[0][k][1] = t; -// // save min values -// if (tADC_fast[0][k][1] || cc==3) + ADC_fast[0][k][1] = t; + // save min values + if (tflags.bit.error==0 ) -// { -// -// -// -// fast_read_all_adc_one(3); -// pause_1000(p); -// fast_read_all_adc_one(4); -// pause_1000(p); -// fast_read_all_adc_one(5); -// pause_1000(p); -// fast_read_all_adc_one(6); -// pause_1000(p); -// fast_read_all_adc_one(7); -// pause_1000(p); -// fast_read_all_adc_one(8); -// -// -// -// for (k=0;k<16;k++) -// { -// ADC_fast[0][k][0] = (-ADC_fast[0][k][1] - ADC_fast[0][k][2] + ADC_fast[0][k][3] + ADC_fast[0][k][4] -// +ADC_fast[0][k][5] + ADC_fast[0][k][6] + ADC_fast[0][k][7] + ADC_fast[0][k][8]) >> 2; // сумму делим на 4 -// } -// -// } -// else -// { -// for (k=0;k<16;k++) -// { -// ADC_fast[0][k][0] = 5000; // error -// } -// } -// -// -// if (project.adc[1].status == component_Ready -// && project.controller.read.errors.bit.error_pbus == 0 -// && project.controller.read.errors_buses.bit.slave_addr_error==0 -// && project.x_parallel_bus->flags.bit.error==0 ) -// { -// -// fast_read_all_adc_two(); -// } -// else -// { -// for (k=0;k<16;k++) -// { -// ADC_fast[1][k][0] = 5000; // error -// } -// } -// -//} +#define PAUSE_BETWEEN_ADC_FAST 5 +#pragma CODE_SECTION(fast_read_all_adc_more,".fast_run"); +void fast_read_all_adc_more(void) +{ + int i,k; + static int p = PAUSE_BETWEEN_ADC_FAST; -///////////////////////////////////////////////////////// -// -//#pragma CODE_SECTION(norma_fast_adc,".fast_run"); -//void norma_fast_adc(void) -//{ -// int i,k; -//// int bb; -// -//#ifdef LOG_ACP_TO_BUF -// static int c_log=0; -// static int n_log_acp_p=0; -// static int n_log_acp_c=2; -// static int n_log_acp_p_2=0; -// static int n_log_acp_c_2=2; -// -//#endif -// -// for (i=0;iflags.bit.error==0 ) -// { -// for (k=0;k<16;k++) -// { -// iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_fast[i][k][0]<<19) ),iq19_k_norm_ADC[i][k])); -// } -// } -// else -// { -// for (k=0;k<16;k++) -// { -// iq_norm_ADC[i][k] = 0; -// } -// -// } -// -// } -// -//#ifdef LOG_ACP_TO_BUF -// if (c_log>=SIZE_BUF_LOG_ACP) -// c_log=0; -// BUF_ADC[c_log]=ADC_fast[n_log_acp_p][n_log_acp_c][0]; -// BUF_ADC_2[c_log]=ADC_fast[n_log_acp_p_2][n_log_acp_c_2][3]; -// c_log++; -//#endif -// -////i_led2_off(); -//} + project.read_errors_controller(); + + if (project.adc[0].status == component_Ready + && project.controller.read.errors.bit.error_pbus == 0 + && project.controller.read.errors_buses.bit.slave_addr_error==0 + && project.x_parallel_bus->flags.bit.error==0 ) + { + + + + fast_read_all_adc_one(3); + pause_1000(p); + fast_read_all_adc_one(4); + pause_1000(p); + fast_read_all_adc_one(5); + pause_1000(p); + fast_read_all_adc_one(6); + pause_1000(p); + fast_read_all_adc_one(7); + pause_1000(p); + fast_read_all_adc_one(8); + + + + for (k=0;k<16;k++) + { + ADC_fast[0][k][0] = (-ADC_fast[0][k][1] - ADC_fast[0][k][2] + ADC_fast[0][k][3] + ADC_fast[0][k][4] + +ADC_fast[0][k][5] + ADC_fast[0][k][6] + ADC_fast[0][k][7] + ADC_fast[0][k][8]) >> 2; // сумму делим на 4 + } + + } + else + { + for (k=0;k<16;k++) + { + ADC_fast[0][k][0] = 5000; // error + } + } + + + if (project.adc[1].status == component_Ready + && project.controller.read.errors.bit.error_pbus == 0 + && project.controller.read.errors_buses.bit.slave_addr_error==0 + && project.x_parallel_bus->flags.bit.error==0 ) + { + + fast_read_all_adc_two(); + } + else + { + for (k=0;k<16;k++) + { + ADC_fast[1][k][0] = 5000; // error + } + } + +} ///////////////////////////////////////////////////////// -/* +#pragma CODE_SECTION(norma_fast_adc,".fast_run"); +void norma_fast_adc(void) +{ + int i,k; +// int bb; + +#ifdef LOG_ACP_TO_BUF + static int c_log=0; + static int n_log_acp_p=0; + static int n_log_acp_c=2; + static int n_log_acp_p_2=0; + static int n_log_acp_c_2=2; + +#endif + + for (i=0;iflags.bit.error==0 ) + { + for (k=0;k<16;k++) + { + iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_fast[i][k][0]<<19) ),iq19_k_norm_ADC[i][k])); + } + } + else + { + for (k=0;k<16;k++) + { + iq_norm_ADC[i][k] = 0; + } + + } + + } + +#ifdef LOG_ACP_TO_BUF + if (c_log>=SIZE_BUF_LOG_ACP) + c_log=0; + BUF_ADC[c_log]=ADC_fast[n_log_acp_p][n_log_acp_c][0]; + BUF_ADC_2[c_log]=ADC_fast[n_log_acp_p_2][n_log_acp_c_2][3]; + c_log++; +#endif + +//i_led2_off(); +} + +///////////////////////////////////////////////////////// + + #pragma CODE_SECTION(norma_all_adc,".fast_run"); void norma_all_adc(void) { @@ -1040,7 +1036,76 @@ void norma_all_adc(void) #endif - for (i=0;idata.adc[nadc].acc_short[ncan]; + + +/// +/* + + iq_norm_ADC[0][0] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][0] - ((long)ADC_f[0][0]<<19) ),iq19_k_norm_ADC[0][0])); + iq_norm_ADC[0][1] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][1] - ((long)ADC_f[0][1]<<19) ),iq19_k_norm_ADC[0][1])); + + iq_norm_ADC[0][2] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][2] - ((long)ADC_f[0][2]<<19) ),iq19_k_norm_ADC[0][2])); + iq_norm_ADC[0][3] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][3] - ((long)ADC_f[0][3]<<19) ),iq19_k_norm_ADC[0][3])); + iq_norm_ADC[0][4] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][4] - ((long)ADC_f[0][4]<<19) ),iq19_k_norm_ADC[0][4])); + iq_norm_ADC[0][5] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][5] - ((long)ADC_f[0][5]<<19) ),iq19_k_norm_ADC[0][5])); + iq_norm_ADC[0][6] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][6] - ((long)ADC_f[0][6]<<19) ),iq19_k_norm_ADC[0][6])); + iq_norm_ADC[0][7] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][7] - ((long)ADC_f[0][7]<<19) ),iq19_k_norm_ADC[0][7])); + + +//i1 second mes +// ADC_f[0][8] = (int)pr->data.adc[0].acc_short[2]; +// ADC_f[0][9] = (int)pr->data.adc[0].acc_short[3]; +// ADC_f[0][10] = (int)pr->data.adc[0].acc_short[4]; +// ADC_f[0][11] = (int)pr->data.adc[0].acc_short[5]; +// ADC_f[0][12] = (int)pr->data.adc[0].acc_short[6]; +// ADC_f[0][13] = (int)pr->data.adc[0].acc_short[7]; + + + + iq_norm_ADC[0][8] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][8] - ((long)ADC_f[0][8]<<19) ),iq19_k_norm_ADC[0][8])); + iq_norm_ADC[0][9] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][9] - ((long)ADC_f[0][9]<<19) ),iq19_k_norm_ADC[0][9])); + iq_norm_ADC[0][10] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][10] - ((long)ADC_f[0][10]<<19) ),iq19_k_norm_ADC[0][10])); + iq_norm_ADC[0][11] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][11] - ((long)ADC_f[0][11]<<19) ),iq19_k_norm_ADC[0][11])); + iq_norm_ADC[0][12] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][12] - ((long)ADC_f[0][12]<<19) ),iq19_k_norm_ADC[0][12])); + iq_norm_ADC[0][13] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][13] - ((long)ADC_f[0][13]<<19) ),iq19_k_norm_ADC[0][13])); + +// iq_norm_ADC[0][14] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][14] - ((long)ADC_f[0][14]<<19) ),iq19_k_norm_ADC[0][14])); +// iq_norm_ADC[0][15] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[0][15] - ((long)ADC_f[0][15]<<19) ),iq19_k_norm_ADC[0][15])); + +/// +// iq_norm_ADC[1][0] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][0] - ((long)ADC_f[1][0]<<19) ),iq19_k_norm_ADC[1][0])); +// iq_norm_ADC[1][1] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][1] - ((long)ADC_f[1][1]<<19) ),iq19_k_norm_ADC[1][1])); + + iq_norm_ADC[1][2] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][2] - ((long)ADC_f[1][2]<<19) ),iq19_k_norm_ADC[1][2])); + iq_norm_ADC[1][3] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][3] - ((long)ADC_f[1][3]<<19) ),iq19_k_norm_ADC[1][3])); + iq_norm_ADC[1][4] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][4] - ((long)ADC_f[1][4]<<19) ),iq19_k_norm_ADC[1][4])); + +// iq_norm_ADC[1][5] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][5] - ((long)ADC_f[1][5]<<19) ),iq19_k_norm_ADC[1][5])); +// iq_norm_ADC[1][6] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][6] - ((long)ADC_f[1][6]<<19) ),iq19_k_norm_ADC[1][6])); +// iq_norm_ADC[1][7] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][7] - ((long)ADC_f[1][7]<<19) ),iq19_k_norm_ADC[1][7])); + + iq_norm_ADC[1][8] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][8] - ((long)ADC_f[1][8]<<19) ),iq19_k_norm_ADC[1][8])); + iq_norm_ADC[1][9] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][9] - ((long)ADC_f[1][9]<<19) ),iq19_k_norm_ADC[1][9])); + iq_norm_ADC[1][10] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][10] - ((long)ADC_f[1][10]<<19) ),iq19_k_norm_ADC[1][10])); + iq_norm_ADC[1][11] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][11] - ((long)ADC_f[1][11]<<19) ),iq19_k_norm_ADC[1][11])); + iq_norm_ADC[1][12] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][12] - ((long)ADC_f[1][12]<<19) ),iq19_k_norm_ADC[1][12])); + iq_norm_ADC[1][13] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][13] - ((long)ADC_f[1][13]<<19) ),iq19_k_norm_ADC[1][13])); + iq_norm_ADC[1][14] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][14] - ((long)ADC_f[1][14]<<19) ),iq19_k_norm_ADC[1][14])); + iq_norm_ADC[1][15] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[1][15] - ((long)ADC_f[1][15]<<19) ),iq19_k_norm_ADC[1][15])); + + + +*/ + + for (i=0;iflags.bit.error==0 ) - { - for (k=0;k<16;k++) - { - - ADC_f[nc][k] = project.adc[nc].read.pbus.adc_value[k]; - ADC_sf[nc][k] += (((int)(ADC_f[nc][k] - ADC_sf[nc][k]))>>SDVIG_K_FILTER_S); - iq_norm_ADC[nc][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[nc][k] + ((long)ADC_f[nc][k]<<19) ),iq19_k_norm_ADC[nc][k])); - } - } - else - { - for (k=0;k<16;k++) - { - ADC_f[nc][k] = 5000;//DEFAULT_ZERO_ADC; - ADC_sf[nc][k] = 5000;//DEFAULT_ZERO_ADC; - iq_norm_ADC[nc][k] = 0; - } - - } -} +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(calc_norm_ADC_1,".fast_run"); -void calc_norm_ADC_1(int run_norma) +#pragma CODE_SECTION(calc_norm_ADC,".fast_run"); +void calc_norm_ADC(int fast) { _iq a1,a2,a3; +// _iq19 t1; +// int k; -#if (USE_ADC_1) +//i_led1_on_off(0); - if (run_norma) - norma_adc_nc(1); +//i_led1_on_off(1); +// return; + //if (fast) + //{ + // fast_read_all_adc_more(); + // norma_fast_adc(); + //} + //else + // norma_all_adc(); + + + + + analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1; + analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2; + + analog.iqIu_1 = iq_norm_ADC[0][2]; + analog.iqIv_1 = iq_norm_ADC[0][3]; + analog.iqIw_1 = iq_norm_ADC[0][4]; + + analog.iqIu_2 = iq_norm_ADC[0][5]; + analog.iqIv_2 = iq_norm_ADC[0][6]; + analog.iqIw_2 = iq_norm_ADC[0][7]; + + analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут + analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут + + analog.iqUin_A1B1 = iq_norm_ADC[0][10]; + +// два варианта подключения датчиков 23550.1 более правильный - по схеме +// 23550.1 + + analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1 + analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1 + +// 23550.3 bs1 bs2 + +// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3 +// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3 +// + + + analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1); + + + analog.iqUin_B2C2 = iq_norm_ADC[0][13]; + analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2); + + + analog.iqIbreak_1 = iq_norm_ADC[0][14]; + analog.iqIbreak_2 = iq_norm_ADC[0][15]; #if (_FLOOR6==1) @@ -1186,86 +1267,9 @@ void calc_norm_ADC_1(int run_norma) #endif -#else +// analog.iqI_vozbud = iq_norm_ADC[1][13]; - analog.T_U01 = - analog.T_U02 = - analog.T_U03 = - analog.T_U04 = - analog.T_U05 = - analog.T_U06 = - analog.T_U07 = - analog.T_Water_external = - analog.T_Water_internal = - - analog.P_Water_internal = - - analog.T_Air_01 = - analog.T_Air_02 = - analog.T_Air_03 = - analog.T_Air_04 = 0; - -#endif -// analog.iqI_vozbud = iq_norm_ADC[1][13]; - -} - -//////////////////////////////////////////////////////////////////// -#pragma CODE_SECTION(calc_norm_ADC_0,".fast_run"); -void calc_norm_ADC_0(int run_norma) -{ - _iq a1,a2,a3; - -#if (USE_ADC_0) - - if (run_norma) - norma_adc_nc(0); - -#if (_FLOOR6) - analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit; - analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit; -#else - analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1; - analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2; -#endif - analog.iqIu_1 = iq_norm_ADC[0][2]; - analog.iqIv_1 = iq_norm_ADC[0][3]; - analog.iqIw_1 = iq_norm_ADC[0][4]; - - analog.iqIu_2 = iq_norm_ADC[0][5]; - analog.iqIv_2 = iq_norm_ADC[0][6]; - analog.iqIw_2 = iq_norm_ADC[0][7]; - - analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут - analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут - - analog.iqUin_A1B1 = iq_norm_ADC[0][10]; - -// два варианта подключения датчиков 23550.1 более правильный - по схеме -// 23550.1 - - analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1 - analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1 - -// 23550.3 bs1 bs2 - -// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3 -// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3 -// - analog.iqUin_B2C2 = iq_norm_ADC[0][13]; - - analog.iqIbreak_1 = iq_norm_ADC[0][14]; - analog.iqIbreak_2 = iq_norm_ADC[0][15]; - -#else - analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 = - analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 = - analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2 - = 0; -#endif - - analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1); - analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2); + @@ -1335,8 +1339,11 @@ void calc_norm_ADC_0(int run_norma) a3 = _IQmpy(a1,a2); analog.PowerScalar = a3; // filter.Power = analog.iqU_1+analog.iqU_2; - filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar); - filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar); + filter.PowerScalar = exp_regul_iq(koef_Im_filter, filter.PowerScalar, analog.PowerScalar); + +//i_led1_on_off(0); + +//i_led1_on_off(1); } @@ -1367,10 +1374,7 @@ void detect_zero_analog(int nc) for (i=0; i #include -//#include +#include #include #include #include #include #include -//#include "log_to_mem.h" +#include "log_to_mem.h" #include "IQmathLib.h" #include "math_pi.h" #include "mathlib.h" #include "params_pwm24.h" -#include "filter_v1.h" -#include "log_to_memory.h" + #pragma DATA_SECTION(simple_scalar1,".slow_vars"); ALG_SIMPLE_SCALAR simple_scalar1 = ALG_SIMPLE_SCALAR_DEFAULT; -_iq koefBpsi = _IQ(0.05); //0.05 + void init_simple_scalar(void) { simple_scalar1.mzz_add_1 = _IQ(MZZ_ADD_1/NORMA_MZZ); simple_scalar1.mzz_add_2 = _IQ(MZZ_ADD_2/NORMA_MZZ); - simple_scalar1.mzz_add_3 = _IQ(MZZ_ADD_3/NORMA_MZZ); - simple_scalar1.poluses = _IQ(POLUS); simple_scalar1.iq_mzz_max_for_fzad = _IQ(1000.0/NORMA_MZZ); simple_scalar1.powerzad_add = _IQ(POWERZAD_ADD_MAX); simple_scalar1.powerzad_dec = _IQ(POWERZAD_DEC); -// simple_scalar1.k_freq_for_pid = _IQ(1.0); + simple_scalar1.k_freq_for_pid = _IQ(1.0); simple_scalar1.k_freq_for_pid = _IQ(450.0/FREQ_PWM); simple_scalar1.iq_add_kp_df = _IQ(ADD_KP_DF); @@ -63,7 +60,7 @@ void init_simple_scalar(void) simple_scalar1.pidIm1.OutMax=_IQ(K_STATOR_MAX); - simple_scalar1.pidIm1.OutMin=_IQ(K_STATOR_MIN); + simple_scalar1.pidIm1.OutMin=_IQ(0); ////////////// @@ -100,8 +97,7 @@ void init_simple_scalar(void) // мин. скольжение - simple_scalar1.min_bpsi = _IQ(BPSI_MINIMAL/NORMA_FROTOR); - simple_scalar1.max_bpsi = _IQ(BPSI_MAXIMAL/NORMA_FROTOR); + simple_scalar1.min_bpsi = _IQ(0.05/NORMA_FROTOR); } @@ -122,32 +118,14 @@ void init_simple_scalar(void) Идет расчет напрyжениy через модуль тока по одной из 3-х фазной стоек. Замыкаетсy обратнаy свyзь по оборотам */ /****************************************************************/ - - //#pragma CODE_SECTION(simple_scalar,".fast_run"); -void simple_scalar(int n_alg, - int n_wind_pump, - int direction, - _iq Frot_pid, - _iq Frot, - _iq fzad, +void simple_scalar(int n_alg, int n_wind_pump, + _iq Frot_pid,_iq Frot, _iq fzad, _iq iqKoefOgran, - _iq mzz_zad, - _iq bpsi_const, - _iq iqIm, - _iq iqUin, - _iq Iin, - _iq powerzad, - _iq power_pid, - _iq power_limit, - int mode_oborots_power, - _iq Izad_from_master, - int master, - int count_bs_work, - _iq *Fz, - _iq *Uz1, - _iq *Uz2, - _iq *Izad_out) + _iq mzz_zad, _iq bpsi_const, + _iq iqIm, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, + _iq Izad_from_master, int master, + _iq *Fz, _iq *Uz1, _iq *Uz2, _iq *Izad_out) { _iq mzz, dF, dI1, Izad, Uz_t1, Kpred_Ip, pred_Ip;//, znak_moment; @@ -157,7 +135,6 @@ void simple_scalar(int n_alg, _iq Im_regul=0; - static _iq bpsi=0; // static _iq IQ_POLUS=0; @@ -191,7 +168,7 @@ void simple_scalar(int n_alg, static _iq fzad_add=0; //fzad_dec _iq halfIm1, halfIm2; - static _iq powerzad_int=0, powerzad_add_max=0, pidFOutMax = 0, pidFOutMin = 0 ; + static _iq powerzad_int=0, powerzad_add_max=0 ; //powerzad_dec powerzad_add // static _iq koef_bpsi=0; // static _iq min_bpsi=0; @@ -206,217 +183,15 @@ void simple_scalar(int n_alg, // static _iq iq_spad_k=1; static _iq myq_temp=0; - static _iq bpsi_filter=0; - static _iq _iq_koef_im_on_tormog = _IQ(KOEF_IM_ON_TORMOG); - static _iq _iq_koef_im_on_tormog_max_temper_break = _IQ(KOEF_IM_ON_TORMOG_WITH_MAX_TEMPER_BREAK); - static _iq n_iq_koef_im_on_tormog = CONST_IQ_1, t_iq_koef_im_on_tormog = CONST_IQ_1; - - static _iq _iq_koef_im_on_tormog_add =_IQ(0.0005), _iq_koef_im_on_tormog_dec = _IQ(0.01); - -// static _iq F_revers_level00= _IQ(70.0/60.0/NORMA_FROTOR); - static _iq F_revers_level0 = _IQ(90.0/60.0/NORMA_FROTOR); - static _iq F_revers_level1 = _IQ(100.0/60.0/NORMA_FROTOR); - static _iq F_revers_level2 = _IQ(110.0/60.0/NORMA_FROTOR); - static _iq F_revers_level3 = _IQ(120.0/60.0/NORMA_FROTOR); - static _iq F_revers_level4 = _IQ(130.0/60.0/NORMA_FROTOR); - static _iq F_revers_level5 = _IQ(140.0/60.0/NORMA_FROTOR); - static _iq F_revers_level6 = _IQ(150.0/60.0/NORMA_FROTOR); - static _iq F_revers_level7 = _IQ(160.0/60.0/NORMA_FROTOR); - static _iq F_revers_level8 = _IQ(170.0/60.0/NORMA_FROTOR); - static _iq F_revers_level9 = _IQ(180.0/60.0/NORMA_FROTOR); - static _iq F_revers_level10 = _IQ(190.0/60.0/NORMA_FROTOR); - static _iq F_revers_level11 = _IQ(200.0/60.0/NORMA_FROTOR); - static _iq F_revers_level12 = _IQ(210.0/60.0/NORMA_FROTOR); - static _iq F_revers_level13 = _IQ(220.0/60.0/NORMA_FROTOR); - - static _iq kF_revers_level00 = _IQ(0.65); - static _iq kF_revers_level0 = _IQ(0.70); - static _iq kF_revers_level1 = _IQ(0.75); - static _iq kF_revers_level2 = _IQ(0.78); - static _iq kF_revers_level3 = _IQ(0.80); - static _iq kF_revers_level4 = _IQ(0.82); - static _iq kF_revers_level5 = _IQ(0.84); - static _iq kF_revers_level6 = _IQ(0.86); - static _iq kF_revers_level7 = _IQ(0.88); - static _iq kF_revers_level8 = _IQ(0.90); - static _iq kF_revers_level9 = _IQ(0.91); - static _iq kF_revers_level10 = _IQ(0.92); - static _iq kF_revers_level11 = _IQ(0.93); - static _iq kF_revers_level12 = _IQ(0.94); - static _iq kF_revers_level13 = _IQ(0.96); - - - static _iq P_level0 = _IQ(70.0/60.0/NORMA_FROTOR); - static _iq P_level1 = _IQ(150.0/60.0/NORMA_FROTOR); - static _iq P_level2 = _IQ(160.0/60.0/NORMA_FROTOR); - static _iq P_level3 = _IQ(170.0/60.0/NORMA_FROTOR); - static _iq P_level4 = _IQ(180.0/60.0/NORMA_FROTOR); - static _iq P_level5 = _IQ(190.0/60.0/NORMA_FROTOR); - static _iq P_level6 = _IQ(200.0/60.0/NORMA_FROTOR); - static _iq P_level7 = _IQ(210.0/60.0/NORMA_FROTOR); - static _iq P_level8 = _IQ(220.0/60.0/NORMA_FROTOR); - static _iq P_level9 = _IQ(230.0/60.0/NORMA_FROTOR); -// static _iq P_level9 = _IQ(300.0/60.0/NORMA_FROTOR); - - static _iq kP_level0 = _IQ(0.9); - static _iq kP_level1 = _IQ(0.9); - static _iq kP_level2 = _IQ(0.9); - static _iq kP_level3 = _IQ(0.85); - static _iq kP_level4 = _IQ(0.8); - static _iq kP_level5 = _IQ(0.75); - static _iq kP_level6 = _IQ(0.7); - static _iq kP_level7 = _IQ(0.65); - static _iq kP_level8 = _IQ(0.6); - static _iq kP_level9 = _IQ(0.55); - - static _iq pid_kp_power = _IQ(PID_KP_POWER); - static _iq add_mzz_outmax_pidp = _IQ(100.0/NORMA_MZZ); - _iq new_pidP_OutMax = 0; - - _iq k_ogr_p_koef_1 = 0; - _iq k_ogr_p_koef_2 = 0; - - _iq k_ogr_n = 0; - - - _iq Frot_pid_abs; - - _iq d_m=0; - - _iq iq_decr_mzz_power; - - _iq level1_power_ain_decr_mzz, level2_power_ain_decr_mzz; - _iq new_power_limit = 0; - - static _iq koef_Power_filter2 = _IQ(1.0/(FREQ_PWM*EXP_FILTER_KOEF_OGRAN_POWER_LIMIT));//2.2 сек //30000;// 0,0012//16777;//0,001//13981; - - - - - - Frot_pid_abs = _IQabs(Frot_pid); - -// попытка пересчитать pidPower.Kp на лету -// -// if (Frot_pid_abs>=P_level0) -// { -// k_ogr_p_koef_1 = CONST_IQ_1 - _IQdiv( (Frot_pid_abs-P_level0) , (P_level9-P_level0) ); -// if (k_ogr_p_koef_1<0) k_ogr_p_koef_1 = 0; -// } -// else -// k_ogr_p_koef_1 = CONST_IQ_1; -// -// //k_ogr_p_koef_1 меняется от 1 до 0 с -// -// k_ogr_p_koef_2 = CONST_IQ_01 + _IQmpy(CONST_IQ_09, k_ogr_p_koef_1); - -// simple_scalar1.pidPower.Kp = _IQmpy (pid_kp_power, k_ogr_p_koef_2);// _IQ(PID_KP_POWER) - - simple_scalar1.pidPower.Kp = pid_kp_power;//_IQmpy (pid_kp_power, k_ogr_p_koef_2);// _IQ(PID_KP_POWER) - - if (mode_oborots_power == ALG_MODE_SCALAR_OBOROTS) - { - if (simple_scalar1.cmd_new_calc_p_limit) - { - simple_scalar1.flag_decr_mzz_power = 0; - simple_scalar1.iq_decr_mzz_power_filter = CONST_IQ_1; - simple_scalar1.iq_decr_mzz_power = CONST_IQ_1; - new_power_limit = power_limit; - } - else - { - // расчет коэф ограничения мощности по превышению запаса, выше лимита - // если тек мощность приближается к лимиту то начинаем пропоруционально уменьшать ток через коэф. - // simple_scalar1.iq_decr_mzz_power_filter который идет от 1.0 - нет ограничения, - // до 1-MAX_KOEF_OGRAN_POWER_LIMIT - полное ограничение - new_power_limit = power_limit - simple_scalar1.sdvig_power_limit; - if (new_power_limit=(level2_power_ain_decr_mzz-level1_power_ain_decr_mzz)) - d_m = CONST_IQ_1; - else - d_m = _IQdiv(d_m,(level2_power_ain_decr_mzz - level1_power_ain_decr_mzz)); - } - - if (d_m<0) - d_m=0; // все в норме - - if (d_m>CONST_IQ_1) - d_m=CONST_IQ_1; // полное ограничение - - // перевели уровень от 1.0 до 0.0 в уровень от MAX_KOEF_OGRAN_POWER_LIMIT до 0.0 - d_m = _IQmpy(d_m, MAX_KOEF_OGRAN_POWER_LIMIT); // - - simple_scalar1.iq_decr_mzz_power = CONST_IQ_1 - d_m;// теперь коэф меняется от 1.0 - нет огран. до MAX_KOEF_OGRAN_POWER_LIMIT макс. огранич. - - if (simple_scalar1.iq_decr_mzz_power<0) - simple_scalar1.iq_decr_mzz_power=0; - - - simple_scalar1.iq_decr_mzz_power_filter = exp_regul_iq(koef_Power_filter2, - simple_scalar1.iq_decr_mzz_power_filter, - simple_scalar1.iq_decr_mzz_power); - - if (simple_scalar1.iq_decr_mzz_power_filter<0) - simple_scalar1.iq_decr_mzz_power_filter = 0; - - - if (d_m>0) - simple_scalar1.flag_decr_mzz_power = 1; - else - simple_scalar1.flag_decr_mzz_power=0; - - } - } - else - { - simple_scalar1.flag_decr_mzz_power = 0; - simple_scalar1.iq_decr_mzz_power_filter = CONST_IQ_1; - simple_scalar1.iq_decr_mzz_power = CONST_IQ_1; - new_power_limit = power_limit; - } - -#if (ENABLE_DECR_MZZ_POWER_IZAD) - if (simple_scalar1.disable_KoefOgranIzad==0) - simple_scalar1.iqKoefOgranIzad = _IQmpy(iqKoefOgran,simple_scalar1.iq_decr_mzz_power_filter); - else - simple_scalar1.iqKoefOgranIzad = iqKoefOgran; -#else - simple_scalar1.iqKoefOgranIzad = iqKoefOgran; -#endif - //static _iq _iq_1 = _IQ(1.0); - // static _iq mzz_int_level1_on_F=0; // mzz = _IQsat(mzz,mzz_zad_int,0); - simple_scalar1.mzz_zad_in1 = mzz_zad; + simple_scalar1.mzz_zad = mzz_zad; simple_scalar1.Izad_from_master = Izad_from_master; - iqKoefOgran = _IQsat(iqKoefOgran,CONST_IQ_1,0); /* устанавливаем начальные условиy всех регулyторов */ if ( (Frot==0) && (fzad==0) ) @@ -424,16 +199,11 @@ void simple_scalar(int n_alg, mzzi = 0; fzad_int = 0; powerzad_int = 0; - bpsi_filter = 0; - pidFOutMax = pidFOutMin = 0; - n_iq_koef_im_on_tormog = CONST_IQ_1;//_IQ(1.0); - simple_scalar1.iq_decr_mzz_power_filter = CONST_IQ_1; } if (mzz_zad==0) { - bpsi_filter = 0; mzz=0; I1_i=0; mzzi=0; @@ -505,88 +275,6 @@ void simple_scalar(int n_alg, } - // ограничение при рекуперации - if (direction==0) - { - // стоим - n_iq_koef_im_on_tormog = CONST_IQ_1;//_IQ(1.0); - } - else - if (direction==-1 && fzad <= 0) - { -// едем назад, задание совпадает с направлением вращения - if (Frot_pid<-F_revers_level13) - n_iq_koef_im_on_tormog = kF_revers_level13; - else - if (Frot_pid<-F_revers_level12) - n_iq_koef_im_on_tormog = kF_revers_level12; - else - if (Frot_pid<-F_revers_level11) - n_iq_koef_im_on_tormog = kF_revers_level11; - else - if (Frot_pid<-F_revers_level10) - n_iq_koef_im_on_tormog = kF_revers_level10; - else - if (Frot_pid<-F_revers_level9) - n_iq_koef_im_on_tormog = kF_revers_level9; - else - if (Frot_pid<-F_revers_level8) - n_iq_koef_im_on_tormog = kF_revers_level8; - else - if (Frot_pid<-F_revers_level7) - n_iq_koef_im_on_tormog = kF_revers_level7; - else - if (Frot_pid<-F_revers_level6) - n_iq_koef_im_on_tormog = kF_revers_level6; - else - if (Frot_pid<-F_revers_level5) - n_iq_koef_im_on_tormog = kF_revers_level5; - else - if (Frot_pid<-F_revers_level4) - n_iq_koef_im_on_tormog = kF_revers_level4; - else - if (Frot_pid<-F_revers_level3) - n_iq_koef_im_on_tormog = kF_revers_level3; - else - if (Frot_pid<-F_revers_level2) - n_iq_koef_im_on_tormog = kF_revers_level2; - else - if (Frot_pid<-F_revers_level1) - n_iq_koef_im_on_tormog = kF_revers_level1; - if (Frot_pid<-F_revers_level0) - n_iq_koef_im_on_tormog = kF_revers_level0; - else - n_iq_koef_im_on_tormog = kF_revers_level00; - - } - else - if (direction==1 && fzad>=0) - { - // едем вперед, задание совпадает с направлением вращения - n_iq_koef_im_on_tormog = CONST_IQ_1;//_IQ(1.0); - } - else - { - // если рекуперация то уменьшим ток в _iq_koef_im_on_tormog раз меньше от заданного -// mzz_zad = _IQmpy(mzz_zad, _iq_koef_im_on_tormog); - - if (edrk.warnings.e9.bits.BREAK_TEMPER_ALARM == 1) - // есть перегрев аварийный, снижаем мощность - n_iq_koef_im_on_tormog = _iq_koef_im_on_tormog_max_temper_break; - else - n_iq_koef_im_on_tormog = _iq_koef_im_on_tormog; - } - - t_iq_koef_im_on_tormog = zad_intensiv_q(_iq_koef_im_on_tormog_add, - _iq_koef_im_on_tormog_dec, - t_iq_koef_im_on_tormog, - n_iq_koef_im_on_tormog); - - - mzz_zad = _IQmpy(mzz_zad, t_iq_koef_im_on_tormog); - - simple_scalar1.mzz_zad_in2 = mzz_zad; - /* задатчик интенсивности момента */ if (n_alg==1) { @@ -605,13 +293,13 @@ void simple_scalar(int n_alg, mzz_zad_int = zad_intensiv_q(simple_scalar1.mzz_add_2, simple_scalar1.mzz_add_2, mzz_zad_int, mzz_zad); // myq_temp = _IQdiv(mzz_zad, simple_scalar1.iq_mzz_max_for_fzad); + // myq_temp = _IQmpy( myq_temp, fzad_add_max); -// fzad_add = myq_temp; - - fzad_int = zad_intensiv_q(fzad_add, fzad_add, fzad_int, fzad ); + // fzad_add = myq_temp; + fzad_int = zad_intensiv_q(fzad_add, fzad_add, fzad_int, fzad); powerzad_int = zad_intensiv_q(simple_scalar1.powerzad_add, simple_scalar1.powerzad_add, powerzad_int, powerzad); @@ -620,31 +308,11 @@ void simple_scalar(int n_alg, /* регулyтор скорости */ if (mzz_zad_int>=0) { - dF = fzad_int - Frot_pid;//*direction; + dF = fzad_int - Frot_pid; ////////// Power PI ////////////// - - //if (_IQabs(simple_scalar1.pidF.Out)) - - k_ogr_n = (_IQabs(power_pid) - _IQabs(powerzad_int)); - // if (k_ogr_n<0) k_ogr_n = 0; - - k_ogr_n = CONST_IQ_1 - _IQdiv(k_ogr_n, _IQabs(powerzad_int)); - - simple_scalar1.k_ogr_n = _IQsat(k_ogr_n,CONST_IQ_1,-CONST_IQ_1); - - - // новое ограничения для pidP OutMax - new_pidP_OutMax = _IQabs(simple_scalar1.pidF.Out)+add_mzz_outmax_pidp; - new_pidP_OutMax = _IQsat(new_pidP_OutMax, mzz_zad_int, add_mzz_outmax_pidp ); // от 100 до результата выхода регулятора simple_scalar1.pidF.Out - - // старый вариант ограничения -// new_pidP_OutMax = mzz_zad_int; - - simple_scalar1.pidPower.OutMax = new_pidP_OutMax; - simple_scalar1.pidPower.OutMin = 0; - + simple_scalar1.pidPower.OutMax=mzz_zad; // pidPower.Kp = _IQmpy( _IQdiv(iq_add_kp_dpower, _IQsat(mzz_zad,mzz_zad,MIN_MZZ_FOR_DPOWER)), pidPower_Kp); // pidPower.Ki = _IQmpy( _IQdiv(iq_add_ki_dpower, _IQsat(mzz_zad,mzz_zad,MIN_MZZ_FOR_DPOWER)), pidPower_Ki); @@ -652,9 +320,9 @@ void simple_scalar(int n_alg, // simple_scalar1.pidPower.Ki = _IQmpy(simple_scalar1.pidPower.Ki, simple_scalar1.k_freq_for_pid); - simple_scalar1.pidPower.Ref = _IQabs(powerzad_int); // тут только положительная мощность + simple_scalar1.pidPower.Ref = powerzad_int; - simple_scalar1.pidPower.Fdb = _IQabs(power_pid); + simple_scalar1.pidPower.Fdb = power_pid; simple_scalar1.pidPower.calc(&simple_scalar1.pidPower); @@ -674,56 +342,12 @@ void simple_scalar(int n_alg, // pidF.OutMax=mzz_zad_int; // или так - pidFOutMax = zad_intensiv_q(simple_scalar1.mzz_add_3, simple_scalar1.mzz_add_1, pidFOutMax, simple_scalar1.pidPower.Out); - pidFOutMin = zad_intensiv_q(simple_scalar1.mzz_add_3, simple_scalar1.mzz_add_1, pidFOutMin, simple_scalar1.pidPower.Out); - - -// fzad - if (direction==-1 && fzad <= 0) - { - pidFOutMax = 0; - simple_scalar1.pidF.OutMax = 0;//simple_scalar1.pidPower.Out; - simple_scalar1.pidF.OutMin = -pidFOutMin;//-simple_scalar1.pidPower.Out; - - } - else - if (direction==1 && fzad>=0) - { - pidFOutMin = 0; - simple_scalar1.pidF.OutMax = pidFOutMax;//simple_scalar1.pidPower.Out; - simple_scalar1.pidF.OutMin = 0;//-simple_scalar1.pidPower.Out; - } - else - { - simple_scalar1.pidF.OutMax = pidFOutMax;//simple_scalar1.pidPower.Out; - simple_scalar1.pidF.OutMin = -pidFOutMin;//-simple_scalar1.pidPower.Out; - } - -/* -// pzad - if (direction==-1 && powerzad <= 0) - { - - - } - else - if (direction==1 && powerzad>=0) - { - - } - else - { - - } -*/ + simple_scalar1.pidF.OutMax = simple_scalar1.pidPower.Out; // pidF.OutMax = mzz_zad; - if (count_bs_work==2) - simple_scalar1.pidF.Kp = simple_scalar1.pidF_Kp;//_IQmpy( _IQdiv(simple_scalar1.iq_add_kp_df, _IQsat(mzz_zad,mzz_zad,simple_scalar1.min_mzz_for_df)), simple_scalar1.pidF_Kp); - else - simple_scalar1.pidF.Kp = _IQmpy2(simple_scalar1.pidF_Kp); - simple_scalar1.pidF.Ki = simple_scalar1.pidF_Ki;//_IQmpy( _IQdiv(simple_scalar1.iq_add_ki_df, _IQsat(mzz_zad,mzz_zad,simple_scalar1.min_mzz_for_df)), simple_scalar1.pidF_Ki); + simple_scalar1.pidF.Kp = _IQmpy( _IQdiv(simple_scalar1.iq_add_kp_df, _IQsat(mzz_zad,mzz_zad,simple_scalar1.min_mzz_for_df)), simple_scalar1.pidF_Kp); + simple_scalar1.pidF.Ki = _IQmpy( _IQdiv(simple_scalar1.iq_add_ki_df, _IQsat(mzz_zad,mzz_zad,simple_scalar1.min_mzz_for_df)), simple_scalar1.pidF_Ki); simple_scalar1.pidF.Ki = _IQmpy(simple_scalar1.pidF.Ki,simple_scalar1.k_freq_for_pid); @@ -742,10 +366,9 @@ void simple_scalar(int n_alg, ////////////////////////////////// // без коррекций dF - //fzad_int = - simple_scalar1.pidF.Ref = _IQmpy(fzad_int, iqKoefOgran); + simple_scalar1.pidF.Ref = fzad_int; - simple_scalar1.pidF.Fdb = Frot_pid;//*direction; + simple_scalar1.pidF.Fdb = Frot_pid; simple_scalar1.pidF.calc(&simple_scalar1.pidF); @@ -757,7 +380,7 @@ void simple_scalar(int n_alg, simple_scalar1.pidF.Ui = simple_scalar1.pidF.OutMin; ///////////////////////////////////// - mzz = _IQabs(simple_scalar1.pidF.Out); // тут модуль!!! + mzz = simple_scalar1.pidF.Out; /////////////////////////////////////// @@ -818,8 +441,8 @@ void simple_scalar(int n_alg, */ - - Izad = _IQmpy(mzz, simple_scalar1.iqKoefOgranIzad); + iqKoefOgran = _IQsat(iqKoefOgran,CONST_IQ_1,0); + Izad = _IQmpy(mzz, iqKoefOgran); // if ((n_alg==1) || (n_alg==2)) // { @@ -901,7 +524,7 @@ void simple_scalar(int n_alg, Uze_t1 = Uz_t1; } - Uze_t1 = _IQsat(Uze_t1,simple_scalar1.pidIm1.OutMax, simple_scalar1.pidIm1.OutMin); + Uze_t1 = _IQsat(Uze_t1,simple_scalar1.pidIm1.OutMax,0); // } @@ -911,13 +534,15 @@ void simple_scalar(int n_alg, *Uz2 = Uze_t1; - bpsi = bpsi_const + simple_scalar1.add_bpsi; + + + + bpsi = bpsi_const; // скольж. ~ моменту // bpsi = _IQmpy(koef_bpsi,mzz); - - bpsi = _IQsat(bpsi,simple_scalar1.max_bpsi, simple_scalar1.min_bpsi); + bpsi = _IQsat(bpsi,bpsi_const, simple_scalar1.min_bpsi); #ifdef BAN_ROTOR_REVERS_DIRECT // используем защиту от неправильного вращениЯ @@ -930,35 +555,12 @@ void simple_scalar(int n_alg, #else - if (simple_scalar1.pidF.Out < 0) - { - bpsi_filter = exp_regul_iq(koefBpsi, bpsi_filter, -bpsi); - } - else - if (simple_scalar1.pidF.Out > 0) - { - bpsi_filter = exp_regul_iq(koefBpsi, bpsi_filter, bpsi); - } - else - bpsi_filter = exp_regul_iq(koefBpsi, bpsi_filter, 0); - - -// *Fz = _IQmpy(Frot*direction,simple_scalar1.poluses) + bpsi_filter; - *Fz = _IQmpy(Frot, simple_scalar1.poluses) + bpsi_filter; - - - simple_scalar1.bpsi_curent = bpsi_filter; + *Fz = _IQmpy(Frot,simple_scalar1.poluses) + bpsi; /* bpsi - скольжение, берем пока + константой хотy тоже должен регулироватьсy */ #endif - simple_scalar1.mzz_zad_int = mzz_zad_int; - simple_scalar1.Uze_t1 = Uze_t1; - simple_scalar1.iqKoefOgran = iqKoefOgran; - simple_scalar1.Fz = *Fz; - simple_scalar1.direction = direction; - simple_scalar1.fzad_int = fzad_int; - // if (n_alg==2) @@ -970,6 +572,20 @@ void simple_scalar(int n_alg, // } +// logpar.log1 = (int16)(_IQtoIQ15(Izad)); +// logpar.log2 = (int16)(_IQtoIQ15(mzz_zad));//(int16)(_IQtoIQ15(Uze_t1)); +// logpar.log3 = (int16)(_IQtoIQ15(fzad_int)); +// logpar.log4 = (int16)(_IQtoIQ15(simple_scalar1.pidF.Ui)); +// logpar.log5 = (int16)(_IQtoIQ14(simple_scalar1.pidF.Up)); +// logpar.log6 = (int16)(_IQtoIQ14(simple_scalar1.pidF.SatErr)); +// logpar.log7 = (int16)(_IQtoIQ15(mzz_zad_int)); +// logpar.log8 = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Ref)); +// logpar.log9 = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Fdb)); +// logpar.log10 = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Ui)); +// logpar.log11 = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Up)); + + + } diff --git a/Inu/Src/main/alg_simple_scalar.h b/Inu/Src/main/alg_simple_scalar.h index f05ca38..1e550a1 100644 --- a/Inu/Src/main/alg_simple_scalar.h +++ b/Inu/Src/main/alg_simple_scalar.h @@ -39,38 +39,11 @@ typedef struct { PIDREG3 pidIm1; int UpravIm2; _iq pidIm_Ki; - _iq mzz_zad_in1; - _iq mzz_zad_in2; - + _iq mzz_zad; _iq mzz_zad_int; _iq Im_regul; _iq Izad; _iq Izad_from_master; - _iq bpsi_curent; - _iq Uze_t1; - - _iq iqKoefOgran; - _iq Fz; - int direction; - _iq fzad_int; - - _iq add_bpsi; - _iq max_bpsi; - - _iq mzz_add_3; - - _iq k_ogr_n; - _iq iq_decr_mzz_power; - _iq iq_decr_mzz_power_filter; - int flag_decr_mzz_power; - - _iq iqKoefOgranIzad; - int disable_KoefOgranIzad; - _iq add_power_limit; - _iq sdvig_power_limit; - - int cmd_new_calc_p_limit; - } ALG_SIMPLE_SCALAR; @@ -79,8 +52,7 @@ typedef struct { PIDREG3 pidIm1; 0,0,0,0,0,\ 0,0,0,0,0,\ 0,0,0,0,0,\ - 0,0,0,0,0,0,0, \ - 0,0, 0,0,0, 0,0, 0, 0, 0,0,0,0,0,0, 0,0 \ + 0,0,0,0,0 \ } @@ -88,12 +60,10 @@ extern ALG_SIMPLE_SCALAR simple_scalar1; -void simple_scalar(int n_alg, int n_wind_pump, int direction, - _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, +void simple_scalar(int n_alg, int n_wind_pump, _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, _iq iqKoefOgran, _iq iqIm, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, - _iq power_limit, int mode_oborots_power, - _iq Izad_from_master, int master, int count_bs_work, + _iq Izad_from_master, int master, _iq *Fz, _iq *Uz1, _iq *Uz2, _iq *Izad); void init_simple_scalar(void); diff --git a/Inu/Src/main/break_regul.c b/Inu/Src/main/break_regul.c index 1de2cd1..094414b 100644 --- a/Inu/Src/main/break_regul.c +++ b/Inu/Src/main/break_regul.c @@ -64,34 +64,25 @@ void break_resistor_managment_calc() { static unsigned int break_counter = 0;//MAX_BREAK_IMPULSE + 1; - if(edrk.Discharge && edrk.from_shema_filter.bits.QTV_ON_OFF==0 - && edrk.from_shema_filter.bits.UMP_ON_OFF==0)// && edrk.to_shema.bits.QTV_ON == 0) + if(edrk.Discharge && edrk.from_shema.bits.QTV_ON_OFF==0 && edrk.from_shema.bits.UMP_ON_OFF==0) { if (break_counter < MAX_BREAK_IMPULSE) { break_counter++; - if ((filter.iqU_1_fast > BREAK_INSENSITIVE_LEVEL_MIN) - || edrk.ManualDischarge || edrk.NoDetectUZeroDischarge) + if ((filter.iqU_1_fast > BREAK_INSENSITIVE_LEVEL_MIN) || edrk.ManualDischarge || edrk.NoDetectUZeroDischarge) { - if (edrk.Obmotka1 == 0) - break_result_1 = 300; - else - break_result_1 = 0; + break_result_1 = 300; } else { break_result_1 = 0; } - if ((filter.iqU_2_fast > BREAK_INSENSITIVE_LEVEL_MIN) - || edrk.ManualDischarge || edrk.NoDetectUZeroDischarge ) + if ((filter.iqU_2_fast > BREAK_INSENSITIVE_LEVEL_MIN) || edrk.ManualDischarge || edrk.NoDetectUZeroDischarge ) { - if (edrk.Obmotka2 == 0) - break_result_2 = 300; - else - break_result_2 = 0; + break_result_2 = 300; } else { @@ -158,8 +149,7 @@ void break_resistor_recup_calc(_iq Uzpt_nominal) { _iq Uzpt_start_recup = Uzpt_nominal + IQ_DELTA_U_START_RECUP; _iq Uzpt_max_open_break_keys = Uzpt_nominal + IQ_DELTA_U_MAX_OPEN_BREAK_KEYS; - - if (/*edrk.Go &&*/ (edrk.SborFinishOk || edrk.Status_Ready.bits.ImitationReady2) ) + if (edrk.Go && edrk.SborFinishOk) { break_result_1 = calc_recup(filter.iqU_1_fast, Uzpt_start_recup, Uzpt_max_open_break_keys); break_result_2 = calc_recup(filter.iqU_2_fast, Uzpt_start_recup, Uzpt_max_open_break_keys); diff --git a/Inu/Src/main/calc_tempers.c b/Inu/Src/main/calc_tempers.c index a5988cc..92ac4c8 100644 --- a/Inu/Src/main/calc_tempers.c +++ b/Inu/Src/main/calc_tempers.c @@ -19,8 +19,6 @@ int calc_max_temper_acdrive_winding(void); int calc_max_temper_edrk_u(void); int calc_max_temper_edrk_water(void); int calc_max_temper_edrk_air(void); -int calc_min_temper_edrk_air(void); - @@ -96,19 +94,6 @@ int calc_max_temper_edrk_air(void) return max_t; -} -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// -int calc_min_temper_edrk_air(void) -{ - int i, min_t=1000; - - for (i=0;i<4;i++) - if (edrk.temper_edrk.real_int_temper_air[i]=level_d1) || (count_press==1)) - { if (ff>ff_dec) - { ff=ff-ff_dec; - if (ff0) - ff = 0; - } else if (ff<=ff_dec && ff>0) ff=0; else - if (ff<0 && only_plus==0) + if (ff<=0 && only_plus==0) ff=ff-ff_add; - else - if (ff==0 && only_plus==0) - ff=ff-DEAD_ZONE_ZADANIE_OBOROTS_ROTOR; - - count_press2 = 0; - } } else if (key_plus) { - if ((count_press2>=level_d1) || (count_press==1)) - { - if (ff==0 && only_minus==0) - ff=ff+DEAD_ZONE_ZADANIE_OBOROTS_ROTOR; - else if (ff>=0 && only_minus==0) ff=ff+ff_add; else @@ -265,22 +228,15 @@ float plus_minus_oborots(int key_plus, int key_minus, float ff, int ufconst_vect ff=0; else if (ff<-ff_dec) - { ff=ff+ff_dec; - if (ff>-DEAD_ZONE_ZADANIE_OBOROTS_ROTOR && ff<0) - ff = 0; - } - - count_press2 = 0; - } } } if (ufconst_vector==0) - ff = my_satur_float(ff,fast_round(MAX_ZADANIE_F*100.0),fast_round(-MAX_ZADANIE_F*100.0), 0); + ff = my_satur_float(ff,fast_round(MAX_ZADANIE_F*100.0),fast_round(-MAX_ZADANIE_F*100.0)); else - ff = my_satur_float(ff, MAX_ZADANIE_OBOROTS_ROTOR, MIN_ZADANIE_OBOROTS_ROTOR, 0); + ff = my_satur_float(ff,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR); prev_key_plus = key_plus; @@ -295,12 +251,12 @@ float plus_minus_oborots(int key_plus, int key_minus, float ff, int ufconst_vect ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_another_bs(int cc) { - int i;//, pos_numbercmd; + int i, pos_numbercmd; static int prev_checkback = 0; static int flag_wait_revers_go = 0; _iq _iq_ff; - static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge=0, key_local_uncharge=0; + static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge, key_local_uncharge; static unsigned int old_time_pult_ing = 0; float ff=0, ff_add=0, ff_dec=0; int key_plus = 0, key_minus = 0; @@ -469,12 +425,12 @@ void parse_parameters_from_one_control_station_another_bs(int cc) ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_pult_vpu(int cc) { - int i;//, pos_numbercmd; + int i, pos_numbercmd; static int prev_checkback = 0, prev_key_oborots = 0; static int flag_wait_revers_go = 0; _iq _iq_ff; - static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge=0, key_local_uncharge=0; + static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge, key_local_uncharge; static unsigned int old_time_pult_ing = 0, old_time_pult_ing2 = 0; float ff=0, ff_add=0, ff_dec=0; int key_plus = 0, key_minus = 0; @@ -503,11 +459,10 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) // эти берем с терминалки control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_IZAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_KM] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_KM]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD;//control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_U_DISBALANCE]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], - SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); // scalar, vector, ufconst @@ -516,6 +471,7 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) control_station.array_cmd[cc][CONTROL_STATION_CMD_ROTOR_POWER] = 0; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; // аналоговые @@ -555,15 +511,6 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) } - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]>=0) - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = -control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - - - - - // цифровые // pos_numbercmd = 15; // с какого элемента массива идут команды, они после аналоговых данных @@ -614,8 +561,6 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_QTV] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_QTV]; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_UMP] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_UMP]; control_station.array_cmd[cc][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_MANUAL_DISCHARGE]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_STOP_LOGS] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_STOP_LOGS]; - } else if (control_station.alive_control_station[CONTROL_STATION_INGETEAM_PULT_RS485]) @@ -633,14 +578,6 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) edrk.disable_alg_u_disbalance = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][193].all; - edrk.Run_Rascepitel_from_RS = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][182].all; - edrk.stop_logs_rs232 = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][183].all; - edrk.stop_slow_log = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][184].all; - edrk.disable_limit_power_from_svu = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][185].all; - edrk.disable_uom = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][186].all; - - - } @@ -669,7 +606,7 @@ void parse_parameters_from_one_control_station_pult_vpu(int cc) ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) { - int i;//, pos_numbercmd; + int i, pos_numbercmd; static int prev_checkback = 0, prev_key_oborots = 0; static int flag_wait_revers_go = 0; @@ -677,7 +614,7 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) int key_plus = 0, key_minus = 0; _iq _iq_ff; - static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge=0, key_local_uncharge=0; + static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge, key_local_uncharge; static unsigned int old_time_pult_ing = 0, old_time_pult_ing2 = 0; if (control_station.alive_control_station[cc]) @@ -702,11 +639,10 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) // эти берем с терминалки control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_IZAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_KM] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_KM]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD;//control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_U_DISBALANCE]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], - SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); @@ -715,6 +651,7 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) control_station.array_cmd[cc][CONTROL_STATION_CMD_SCALAR_FOC] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SCALAR_FOC]; control_station.array_cmd[cc][CONTROL_STATION_CMD_ROTOR_POWER] = 0; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; // аналоговые // if @@ -755,10 +692,7 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) // control_station.array_cmd[CONTROL_STATION_VPU_CAN][CONTROL_STATION_CMD_SET_ROTOR] = ff; } - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]>=0) - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = -control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; + // цифровые // pos_numbercmd = 15; // с какого элемента массива идут команды, они после аналоговых данных @@ -766,15 +700,14 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) control_station.array_cmd[cc][CONTROL_STATION_CMD_CHECKBACK] = edrk.from_zadat4ik.bits.KVITIR; // заряд, разряд - key_local_charge = edrk.from_shema_filter.bits.SBOR_SHEMA; - key_local_uncharge = edrk.from_shema_filter.bits.RAZBOR_SHEMA; + key_local_charge = edrk.from_shema.bits.SBOR_SHEMA; + key_local_uncharge = edrk.from_shema.bits.RAZBOR_SHEMA; if (key_local_uncharge && key_local_charge) { - key_local_uncharge = 0; key_local_charge = 0; - //edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; + edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; } if (key_local_charge && prev_charge==0) @@ -833,12 +766,6 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) edrk.Obmotka2 = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][195].all; edrk.disable_alg_u_disbalance = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][193].all; - edrk.Run_Rascepitel_from_RS = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][182].all; - edrk.stop_logs_rs232 = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][183].all; - edrk.stop_slow_log = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][184].all; - edrk.disable_limit_power_from_svu = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][185].all; - edrk.disable_uom = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][186].all; - } @@ -862,21 +789,19 @@ void parse_parameters_from_one_control_station_pult_zadat4ik(int cc) ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_pult_ingeteam(int cc) { - int i, zad_power; //pos_numbercmd + int i, pos_numbercmd; static int prev_checkback = 0; static int flag_wait_revers_go = 0; float ff=0, ff_add=0, ff_dec=0; int key_plus = 0, key_minus = 0; - _iq _iq_ff=0; - static unsigned int prev_key_local_charge_key=0, prev_key_local_uncharge_key=0, - key_local_charge_key=0, key_local_uncharge_key=0; - static unsigned int prev_key_local_charge_display=0, prev_key_local_uncharge_display=0, - key_local_charge_display=0, key_local_uncharge_display=0; + _iq _iq_ff; + static unsigned int prev_key_local_charge_key=0, prev_key_local_uncharge_key=0, key_local_charge_key, key_local_uncharge_key; + static unsigned int prev_key_local_charge_display=0, prev_key_local_uncharge_display=0, key_local_charge_display, key_local_uncharge_display; - static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge=0, key_local_uncharge=0; + static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge, key_local_uncharge; static unsigned int old_time_pult_ing = 0, old_time_pult_ing2 = 0; - static unsigned int prev_key_local_charge_uncharge_display=0, key_local_charge_uncharge_display=0; + static unsigned int prev_key_local_charge_uncharge_display=0, key_local_charge_uncharge_display; if (control_station.alive_control_station[cc]) { @@ -908,11 +833,10 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_IZAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_KM] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_KM]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD;//control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_U_DISBALANCE]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], - SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); // vector, ufconst control_station.array_cmd[cc][CONTROL_STATION_CMD_UFCONST_VECTOR] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_UFCONST_VECTOR]; @@ -931,21 +855,12 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) if (control_station.array_cmd[cc][CONTROL_STATION_CMD_ROTOR_POWER]==1) { - zad_power = (int)control_station.raw_array_data[cc][4].all; - if (zad_power<0) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = zad_power; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = -MAX_ZADANIE_OBOROTS_ROTOR; - } - else - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.raw_array_data[cc][4].all; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = MAX_ZADANIE_OBOROTS_ROTOR; - } + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.raw_array_data[cc][4].all; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = MAX_ZADANIE_OBOROTS_ROTOR; } else { - + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; ff = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]; @@ -965,19 +880,13 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) if (detect_pause_milisec(3000,&old_time_pult_ing2)) if (control_station.flag_refresh_array[cc] == 0) - ff = (int)(control_station.raw_array_data[cc][5].all); + ff = control_station.raw_array_data[cc][5].all; } control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = ff; // control_station.array_cmd[CONTROL_STATION_ZADATCHIK_CAN][CONTROL_STATION_CMD_SET_ROTOR] = ff; // control_station.array_cmd[CONTROL_STATION_VPU_CAN][CONTROL_STATION_CMD_SET_ROTOR] = ff; - - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]>=0) - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = -control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - } @@ -1035,15 +944,12 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) if (key_local_uncharge_key && key_local_charge_key) { - key_local_uncharge_key = 0; - key_local_charge_key = 0; -// edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; + key_local_charge = 0; + edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; } - if (edrk.Status_Ready.bits.ImitationReady2==0) // объехали сбор с пульта, т.к. не нужен при имитации - { if (key_local_charge && prev_charge==0) { control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 1; @@ -1051,7 +957,7 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) } else control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - + prev_charge = key_local_charge; if (key_local_uncharge) @@ -1062,14 +968,6 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) else control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - } - else - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - } - - prev_charge = key_local_charge; prev_uncharge = key_local_uncharge; @@ -1090,30 +988,22 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) if (control_station.alive_control_station[CONTROL_STATION_TERMINAL_RS232]) { control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_PUMP] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_PUMP] - || control_station.raw_array_data[cc][188].all; + | control_station.raw_array_data[cc][188].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] - || control_station.raw_array_data[cc][191].all; + | control_station.raw_array_data[cc][191].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_QTV] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_QTV] - || control_station.raw_array_data[cc][189].all; + | control_station.raw_array_data[cc][189].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_UMP] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_UMP] - || control_station.raw_array_data[cc][190].all; + | control_station.raw_array_data[cc][190].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_MANUAL_DISCHARGE] - || control_station.raw_array_data[cc][180].all; + | control_station.raw_array_data[cc][180].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_GO] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_GO] - || !control_station.raw_array_data[cc][192].all; + | !control_station.raw_array_data[cc][192].all; } else { edrk.Status_Ready.bits.ImitationReady2 = control_station.raw_array_data[cc][181].all; - edrk.Run_Rascepitel_from_RS = control_station.raw_array_data[cc][182].all; - edrk.stop_logs_rs232 = control_station.raw_array_data[cc][183].all; - edrk.stop_slow_log = control_station.raw_array_data[cc][184].all; - edrk.disable_limit_power_from_svu = control_station.raw_array_data[cc][185].all; - edrk.disable_uom = control_station.raw_array_data[cc][186].all; - - - edrk.Obmotka1 = control_station.raw_array_data[cc][194].all; edrk.Obmotka2 = control_station.raw_array_data[cc][195].all; edrk.disable_alg_u_disbalance = control_station.raw_array_data[cc][193].all; @@ -1171,23 +1061,15 @@ void parse_parameters_from_one_control_station_pult_ingeteam(int cc) ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_MPU_SVU(int cc) { - int i, zad_power, limit_power; + int i; + static int prev_checkback = 0; + static int flag_wait_revers_go = 0; _iq _iq_ff; + static unsigned int prev_charge=0, prev_uncharge=0, cmd_local_charge, cmd_local_uncharge; + static unsigned int old_time_MPU_SVU = 0; - static int prev_checkback_3 = 0; - static int flag_wait_revers_go_3 = 0; - static unsigned int prev_charge_3 = 0, prev_uncharge_3 = 0, cmd_local_charge_3 = 0, cmd_local_uncharge_3 = 0; - static unsigned int old_time_MPU_SVU_3 = 0; - - static int prev_checkback_4 = 0; - static int flag_wait_revers_go_4 = 0; - static unsigned int prev_charge_4 = 0, prev_uncharge_4 = 0, cmd_local_charge_4 = 0, cmd_local_uncharge_4 = 0; - static unsigned int old_time_MPU_SVU_4 = 0; - - - if (control_station.alive_control_station[cc]) { @@ -1211,32 +1093,18 @@ void parse_parameters_from_one_control_station_MPU_SVU(int cc) // control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL] = control_station.active_control_station[CONTROL_STATION_MPU_SVU_CAN]; -// control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL] = control_station.active_control_station[CONTROL_STATION_MPU_KEY_CAN]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL] = control_station.active_control_station[cc]; + control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL] = control_station.active_control_station[CONTROL_STATION_MPU_KEY_CAN]; /////////////////////////////////////////// // эти берем с терминалки control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_IZAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_KM] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_KM]; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD;//control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_U_DISBALANCE]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE]; - - - if (edrk.disable_limit_power_from_svu) - limit_power = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], - SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); - else - limit_power = control_station.raw_array_data[cc][12].all; // Запас мощности - - if (limit_power==0) - limit_power = MIN_ZADANIE_LIMIT_POWER; - - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = limit_power; //my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], - // MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, DEAD_ZONE_ZADANIE_LIMIT_POWER); - -// //control_station.raw_array_data[cc][12].all; // Запас мощности + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER], MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); + //control_station.raw_array_data[cc][12].all; // Запас мощности // vector, ufconst control_station.array_cmd[cc][CONTROL_STATION_CMD_UFCONST_VECTOR] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_UFCONST_VECTOR]; control_station.array_cmd[cc][CONTROL_STATION_CMD_SCALAR_FOC] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SCALAR_FOC]; @@ -1248,128 +1116,63 @@ void parse_parameters_from_one_control_station_MPU_SVU(int cc) // if - if (cc==CONTROL_STATION_MPU_SVU_CAN) - old_time_MPU_SVU = old_time_MPU_SVU_3; - if (cc==CONTROL_STATION_MPU_KEY_CAN) - old_time_MPU_SVU = old_time_MPU_SVU_4; - if ((detect_pause_milisec(100, &old_time_MPU_SVU)) && control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL]) { if (control_station.array_cmd[cc][CONTROL_STATION_CMD_ROTOR_POWER] == 1) { - zad_power = (int)control_station.raw_array_data[cc][3].all; - if (zad_power<0) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = zad_power; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = -MAX_ZADANIE_OBOROTS_ROTOR; - } - else - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = zad_power; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = MAX_ZADANIE_OBOROTS_ROTOR; - } + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.raw_array_data[cc][3].all; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = MAX_ZADANIE_OBOROTS_ROTOR; } else { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = (int)control_station.raw_array_data[cc][2].all; - - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]>=0) control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = -control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = control_station.raw_array_data[cc][2].all; } } //Квитирование control_station.array_cmd[cc][CONTROL_STATION_CMD_CHECKBACK] = control_station.raw_array_data[cc][0].all; - if (cc==CONTROL_STATION_MPU_SVU_CAN) - { - // заряд, разряд - if (edrk.flag_second_PCH == 0) { - cmd_local_charge_3 = control_station.raw_array_data[cc][6].all; - cmd_local_uncharge_3 = control_station.raw_array_data[cc][9].all; - } else { - cmd_local_charge_3 = control_station.raw_array_data[cc][7].all;//modbus_table_can_in[129].all; //control_station.raw_array_data[cc][7].all; - cmd_local_uncharge_3 = control_station.raw_array_data[cc][10].all; - } - - - if (cmd_local_charge_3 && cmd_local_uncharge_3) - { - cmd_local_charge_3 = 0; - cmd_local_uncharge_3 = 0; - // edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; - } - - - - if (cmd_local_charge_3 && prev_charge_3==0) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 1; - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - } - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - prev_charge_3 = cmd_local_charge_3; - - - if (cmd_local_uncharge_3) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 1; - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - } - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - - prev_uncharge_3 = cmd_local_uncharge_3; +// заряд, разряд + if (edrk.flag_second_PCH == 0) { + cmd_local_charge = control_station.raw_array_data[cc][6].all; + cmd_local_uncharge = control_station.raw_array_data[cc][9].all; + } else { + cmd_local_charge = modbus_table_can_in[129].all; //control_station.raw_array_data[cc][7].all; + cmd_local_uncharge = control_station.raw_array_data[cc][10].all; } - if (cc==CONTROL_STATION_MPU_KEY_CAN) + + if (cmd_local_charge && cmd_local_uncharge) { - // заряд, разряд - if (edrk.flag_second_PCH == 0) { - cmd_local_charge_4 = control_station.raw_array_data[cc][6].all; - cmd_local_uncharge_4 = control_station.raw_array_data[cc][9].all; - } else { - cmd_local_charge_4 = control_station.raw_array_data[cc][7].all;//modbus_table_can_in[129].all; //control_station.raw_array_data[cc][7].all; - cmd_local_uncharge_4 = control_station.raw_array_data[cc][10].all; - } - - - if (cmd_local_charge_4 && cmd_local_uncharge_4) - { - cmd_local_charge_4 = 0; - cmd_local_uncharge_4 = 0; - // edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; - } - - - - if (cmd_local_charge_4 && prev_charge_4==0) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 1; - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - } - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - prev_charge_4 = cmd_local_charge_4; - - - if (cmd_local_uncharge_4) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 1; - control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; - } - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; - - prev_uncharge_4 = cmd_local_uncharge_4; + cmd_local_charge = 0; + edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; } + + + if (cmd_local_charge && prev_charge==0) + { + control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 1; + control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; + } + else + control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; + prev_charge = cmd_local_charge; + + + if (cmd_local_uncharge) + { + control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 1; + control_station.array_cmd[cc][CONTROL_STATION_CMD_CHARGE] = 0; + } + else + control_station.array_cmd[cc][CONTROL_STATION_CMD_UNCHARGE] = 0; + + prev_uncharge = cmd_local_uncharge; + control_station.array_cmd[cc][CONTROL_STATION_CMD_BLOCK_BS] = control_station.raw_array_data[cc][4].all; // if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]!=0) @@ -1408,11 +1211,7 @@ void parse_parameters_from_one_control_station_MPU_SVU(int cc) edrk.Obmotka2 = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][195].all; edrk.disable_alg_u_disbalance = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][193].all; - edrk.Run_Rascepitel_from_RS = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][182].all; - edrk.stop_logs_rs232 = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][183].all; - edrk.stop_slow_log = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][184].all; - edrk.disable_limit_power_from_svu = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][185].all; - edrk.disable_uom = control_station.raw_array_data[CONTROL_STATION_INGETEAM_PULT_RS485][186].all; + } @@ -1427,15 +1226,6 @@ void parse_parameters_from_one_control_station_MPU_SVU(int cc) //Автовыбор насоса control_station.array_cmd[cc][CONTROL_STATION_CMD_MODE_PUMP] = control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_MODE_PUMP]; - - edrk.breaker_on = control_station.raw_array_data[cc][17].all; - - edrk.break_tempers[0] = control_station.raw_array_data[cc][18].all; - edrk.break_tempers[1] = control_station.raw_array_data[cc][19].all; - edrk.break_tempers[2] = control_station.raw_array_data[cc][20].all; - edrk.break_tempers[3] = control_station.raw_array_data[cc][21].all; - - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL]==0) return; @@ -1446,14 +1236,12 @@ void parse_parameters_from_one_control_station_MPU_SVU(int cc) ///////////////////////////////////////////////////////////// void parse_parameters_from_one_control_station_terminal_rs232(int cc) { - static int pos_numbercmd = (sizeof(CMD_ANALOG_DATA_STRUCT) >> 1); - int i, fint; - static int prev_checkback = 0, lock_ImitationReady2 = 0; + int i, pos_numbercmd; + static int prev_checkback = 0; static int flag_wait_revers_go = 0; - static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge=0, key_local_uncharge=0; + static unsigned int prev_charge=0, prev_uncharge=0, key_local_charge, key_local_uncharge; float ff; _iq _iq_ff; - int zad_power=0; if (control_station.alive_control_station[cc]) { @@ -1479,7 +1267,7 @@ void parse_parameters_from_one_control_station_terminal_rs232(int cc) edrk.test_mode = 0; // f.RScount = SECOND * 3; -// pos_numbercmd = sizeof(CMD_ANALOG_DATA_STRUCT);//15; // с какого элемента массива идут команды, они после аналоговых данных + pos_numbercmd = 15; // с какого элемента массива идут команды, они после аналоговых данных control_station.array_cmd[cc][CONTROL_STATION_CMD_ACTIVE_CONTROL] = control_station.raw_array_data[cc][pos_numbercmd].bits.bit0; control_station.array_cmd[cc][CONTROL_STATION_CMD_CHECKBACK] = control_station.raw_array_data[cc][pos_numbercmd].bits.bit1; control_station.array_cmd[cc][CONTROL_STATION_CMD_UFCONST_VECTOR] = control_station.raw_array_data[cc][pos_numbercmd].bits.bit2; @@ -1501,8 +1289,7 @@ void parse_parameters_from_one_control_station_terminal_rs232(int cc) if (key_local_uncharge && key_local_charge) { key_local_charge = 0; - key_local_uncharge = 0; -// edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; + edrk.errors.e1.bits.BOTH_KEYS_CHARGE_DISCHARGE |=1; } if (key_local_charge && prev_charge==0) @@ -1549,42 +1336,17 @@ void parse_parameters_from_one_control_station_terminal_rs232(int cc) } else // ручное включение { - - if (control_station.raw_array_data[cc][pos_numbercmd].bits.bit9==0) // Авто выбор - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_MODE_PUMP] = 6; - } - else - // ручной выбор для ручного включения - { if (control_station.raw_array_data[cc][pos_numbercmd].bits.bit10==0) //Ручной выбор насоса_1_2 ручное включение control_station.array_cmd[cc][CONTROL_STATION_CMD_MODE_PUMP] = 3; else control_station.array_cmd[cc][CONTROL_STATION_CMD_MODE_PUMP] = 4; - } } control_station.array_cmd[cc][CONTROL_STATION_CMD_TEST_LEDS] = control_station.raw_array_data[cc][pos_numbercmd].bits.bit11; //control_station.raw_array_data[cc][pos_numbercmd].bits.bit12 - if (edrk.Stop) - { - if (control_station.raw_array_data[cc][pos_numbercmd].bits.bit13) - lock_ImitationReady2 = 1; - edrk.Status_Ready.bits.ImitationReady2 = 0; - } - - if (lock_ImitationReady2) - edrk.Status_Ready.bits.ImitationReady2 = 0; - - if (edrk.Stop == 0 && lock_ImitationReady2 && control_station.raw_array_data[cc][pos_numbercmd].bits.bit13 == 0) - lock_ImitationReady2 = 0; - - if (edrk.Stop == 0 && lock_ImitationReady2 == 0) - edrk.Status_Ready.bits.ImitationReady2 = control_station.raw_array_data[cc][pos_numbercmd].bits.bit13; - - + edrk.Status_Ready.bits.ImitationReady2 = control_station.raw_array_data[cc][pos_numbercmd].bits.bit13; edrk.Run_Rascepitel_from_RS = control_station.raw_array_data[cc][pos_numbercmd].bits.bit14; edrk.Obmotka1 = control_station.raw_array_data[cc][pos_numbercmd].bits.bit15; @@ -1595,151 +1357,46 @@ void parse_parameters_from_one_control_station_terminal_rs232(int cc) // control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit3; // control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit4; - control_station.array_cmd[cc][CONTROL_STATION_CMD_WDOG_OFF] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit2; + control_station.array_cmd[cc][CONTROL_STATION_CMD_CROSS_STEND_AUTOMATS] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit2; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_UMP] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit3; control_station.array_cmd[cc][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit4; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_PUMP] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit5; control_station.array_cmd[cc][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit6; control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_ON_QTV] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit7; - - - - // control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_INTERRUPT_SYNC] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit8; // control_station.array_cmd[cc][CONTROL_STATION_CMD_DISABLE_INTERRUPT_TIMER2] = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit9; - // edrk.disable_break_work = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit8; edrk.disable_rascepitel_work = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit10; edrk.enable_pwm_test_lines = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit11; - edrk.stop_logs_rs232 = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit12; - edrk.stop_slow_log = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit13; - - edrk.disable_limit_power_from_svu = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit14; - edrk.disable_uom = control_station.raw_array_data[cc][pos_numbercmd+1].bits.bit15; - edrk.imit_limit_freq = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit0; - edrk.imit_limit_uom = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit1; - edrk.set_limit_uom_50 = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit2; - - - edrk.imit_save_slow_logs = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit3; - edrk.imit_send_alarm_log_pult = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit4; - -// edrk.cmd_clear_can_error = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit5; - - edrk.cmd_imit_low_isolation = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit5; - edrk.cmd_very_slow_start = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit6; - - simple_scalar1.disable_KoefOgranIzad = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit7; - - - edrk.cmd_disable_calc_km_on_slave = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit8; - simple_scalar1.cmd_new_calc_p_limit = control_station.raw_array_data[cc][pos_numbercmd+2].bits.bit9; // analog - - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.raw_array_data[cc][7].all, - SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); - - - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_ROTOR_POWER]==1) - { - zad_power = my_satur_int(control_station.raw_array_data[cc][2].all, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER, DEAD_ZONE_ZADANIE_POWER); - if (zad_power<0) - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = zad_power; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = -MAX_ZADANIE_OBOROTS_ROTOR; - } - else - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = zad_power; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = MAX_ZADANIE_OBOROTS_ROTOR; - } - } - else - { - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = (int)control_station.raw_array_data[cc][0].all; - - if (control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR]>=0) - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - else - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = -control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER]; - } - - //control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = (int)control_station.raw_array_data[cc][0].all; - //control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = my_satur_int(control_station.raw_array_data[cc][2].all, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); - + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_ROTOR] = control_station.raw_array_data[cc][0].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_KM] = control_station.raw_array_data[cc][1].all; - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = my_satur_int(control_station.raw_array_data[cc][3].all, MAX_ZADANIE_I_M, 0, 0); - control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.raw_array_data[cc][4].all; + + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_POWER] = my_satur_int(control_station.raw_array_data[cc][2].all, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_IZAD] = my_satur_int(control_station.raw_array_data[cc][3].all, MAX_ZADANIE_I_M, 0); + + if (control_station.array_cmd[cc][CONTROL_STATION_CMD_CROSS_STEND_AUTOMATS]==0) + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = control_station.raw_array_data[cc][4].all; + else + // блокируем сбор схемы, т.к. мы в пробросе автоматов + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_U_ZARYAD] = 0; + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = control_station.raw_array_data[cc][5].all; control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = control_station.raw_array_data[cc][6].all; - + control_station.array_cmd[cc][CONTROL_STATION_CMD_SET_LIMIT_POWER] = my_satur_int(control_station.raw_array_data[cc][7].all, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER); if (control_station.raw_array_data[cc][8].all > 0 && control_station.raw_array_data[cc][8].all <= 600 && edrk.MasterSlave == MODE_MASTER) { vect_control.iqId_min = _IQ((float)control_station.raw_array_data[cc][8].all / NORMA_ACP); } - fint = (int)control_station.raw_array_data[cc][9].all; - if (fint>=-360 && fint<=360 && edrk.MasterSlave == MODE_MASTER) - { - vect_control.add_tetta = _IQ(fint / 180.0 * PI); - } - else - vect_control.add_tetta = 0; - - fint = (int)control_station.raw_array_data[cc][10].all; - if (fint>=0) - { - edrk.t_slow_log = fint; - } - else - edrk.t_slow_log = 0; - - fint = (int)control_station.raw_array_data[cc][11].all; - if (fint) - { - simple_scalar1.add_bpsi = _IQ(fint/1000.0/NORMA_FROTOR);//_IQ(0.05/NORMA_FROTOR); - } - else - simple_scalar1.add_bpsi = 0; - - fint = (int)control_station.raw_array_data[cc][12].all; - if (fint) - { - simple_scalar1.add_power_limit = _IQ(fint*1000.0/(NORMA_MZZ*NORMA_MZZ));//_IQ(0.05/NORMA_FROTOR); - } - else - simple_scalar1.add_power_limit = 0; - - - fint = (int)control_station.raw_array_data[cc][13].all; - if (fint) - { - simple_scalar1.sdvig_power_limit = _IQ(fint*1000.0/(NORMA_MZZ*NORMA_MZZ));//_IQ(0.05/NORMA_FROTOR); - } - else - simple_scalar1.sdvig_power_limit = 0; - - -//#if (_FLOOR6) - fint = (int)control_station.raw_array_data[cc][14].all; - if (fint>=0 && fint<=3200) - { - analog.iqU_1_imit = _IQ(fint/NORMA_ACP); - } - else - analog.iqU_1_imit = 0; -//#else -// analog.iqU_1_imit = 0; -//#endif - prev_checkback = control_station.array_cmd[cc][CONTROL_STATION_CMD_CHECKBACK];//control_station.raw_array_data[cc][pos_numbercmd].bits.bit1; // edrk.KvitirRS = 1; @@ -1829,7 +1486,7 @@ void parse_data_from_master_to_alg(void) void parse_analog_data_from_active_control_station_to_alg(void) { - float ff, ff1; + float ff; _iq _iq_ff; int i; @@ -1870,8 +1527,7 @@ void parse_analog_data_from_active_control_station_to_alg(void) ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_U_ZARYAD]; - - edrk.zadanie.ZadanieU_Charge = my_satur_float(ff,MAX_ZADANIE_U_CHARGE,0,0); + edrk.zadanie.ZadanieU_Charge = my_satur_float(ff,MAX_ZADANIE_U_CHARGE,0); edrk.zadanie.iq_ZadanieU_Charge = _IQ(edrk.zadanie.ZadanieU_Charge/NORMA_ACP); @@ -1897,16 +1553,14 @@ void parse_analog_data_from_active_control_station_to_alg(void) if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_UF_CONST) { ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_ROTOR]/100.0; - ff = my_satur_float(ff,MAX_ZADANIE_F,MIN_ZADANIE_F,0); + ff = my_satur_float(ff,MAX_ZADANIE_F,MIN_ZADANIE_F); edrk.zadanie.fzad = ff; // Гц. edrk.zadanie.iq_fzad = _IQ(edrk.zadanie.fzad/NORMA_FROTOR); } else { ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_ROTOR]; - ff = my_satur_float(ff,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR, 0); - edrk.zadanie.oborots_zad_no_dead_zone = ff; - ff = my_satur_float(ff,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR, DEAD_ZONE_ZADANIE_OBOROTS_ROTOR); + ff = my_satur_float(ff,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR); edrk.zadanie.oborots_zad = ff;// об/мин edrk.zadanie.oborots_zad_hz = ff/60.0;// из оборотов в Гц. edrk.zadanie.iq_oborots_zad_hz = _IQ(edrk.zadanie.oborots_zad_hz/NORMA_FROTOR); @@ -1914,40 +1568,30 @@ void parse_analog_data_from_active_control_station_to_alg(void) ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_KM]/10000.0; - edrk.zadanie.kzad = my_satur_float(ff,K_STATOR_MAX,0,0); + edrk.zadanie.kzad = my_satur_float(ff,K_STATOR_MAX,0); edrk.zadanie.iq_kzad = _IQ(edrk.zadanie.kzad); ff = (control_station.active_array_cmd[CONTROL_STATION_CMD_SET_K_U_DISBALANCE]/100.0); - edrk.zadanie.k_u_disbalance = my_satur_float(ff,MAX_ZADANIE_K_U_DISBALANCE,0.0,0); + edrk.zadanie.k_u_disbalance = my_satur_float(ff,MAX_ZADANIE_K_U_DISBALANCE,0.0); edrk.zadanie.iq_k_u_disbalance = _IQ(edrk.zadanie.k_u_disbalance); ff = (control_station.active_array_cmd[CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE]/1000.0); - edrk.zadanie.kplus_u_disbalance = my_satur_float(ff,1.0,0.0,0); + edrk.zadanie.kplus_u_disbalance = my_satur_float(ff,1.0,0.0); edrk.zadanie.iq_kplus_u_disbalance = _IQ(edrk.zadanie.kplus_u_disbalance); ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_IZAD]; - edrk.zadanie.Izad = my_satur_float(ff,MAX_ZADANIE_I_M,0,0); + edrk.zadanie.Izad = my_satur_float(ff,MAX_ZADANIE_I_M,0); edrk.zadanie.iq_Izad = _IQ(edrk.zadanie.Izad/NORMA_MZZ); - if (edrk.from_uom.level_value == 0) - { - ff1 = SUPER_MAX_ZADANIE_LIMIT_POWER; - } - else - ff1 = MAX_ZADANIE_LIMIT_POWER * (1.0 - edrk.from_uom.level_value/100.0) - POWER_ZAPAS_FOR_UOM; //kWt - - ff1 = my_satur_float(ff1, SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); - - ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_LIMIT_POWER];// * (1.0 - edrk.from_uom.level_value/100.0); //kWt - ff = my_satur_float(ff, ff1, MIN_ZADANIE_LIMIT_POWER, 0); - edrk.zadanie.limit_power_zad = my_satur_float(ff,SUPER_MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); // kWt + ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_LIMIT_POWER]; //kWt + edrk.zadanie.limit_power_zad = my_satur_float(ff,MAX_ZADANIE_POWER,MIN_ZADANIE_POWER); // kWt edrk.zadanie.iq_limit_power_zad = _IQ(edrk.zadanie.limit_power_zad*1000.0/(NORMA_MZZ*NORMA_MZZ)); //Wt ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_POWER]; //kWt - ff = my_satur_float(ff,MAX_ZADANIE_POWER,MIN_ZADANIE_POWER,DEAD_ZONE_ZADANIE_POWER); // kWt - ff = my_satur_float(ff,edrk.zadanie.limit_power_zad,-edrk.zadanie.limit_power_zad,DEAD_ZONE_ZADANIE_POWER); // kWt + ff = my_satur_float(ff,MAX_ZADANIE_POWER,MIN_ZADANIE_POWER); // kWt + ff = my_satur_float(ff,edrk.zadanie.limit_power_zad,-edrk.zadanie.limit_power_zad); // kWt edrk.zadanie.power_zad = ff; // kWt edrk.zadanie.iq_power_zad = _IQ(edrk.zadanie.power_zad*1000.0/(NORMA_MZZ*NORMA_MZZ)); //Wt @@ -2092,11 +1736,10 @@ void parse_parameters_from_all_control_station(void) parse_parameters_from_one_control_station_pult_vpu(CONTROL_STATION_VPU_CAN); parse_parameters_from_one_control_station_another_bs(CONTROL_STATION_ANOTHER_BS); // unpack_answer_from_MPU_SVU_CAN(CONTROL_STATION_MPU_SVU_CAN); - unpack_answer_from_MPU_SVU_CAN(CONTROL_STATION_MPU_KEY_CAN); //4 - unpack_answer_from_MPU_SVU_CAN(CONTROL_STATION_MPU_SVU_CAN); //3 + unpack_answer_from_MPU_SVU_CAN(CONTROL_STATION_MPU_KEY_CAN); // unpack_answer_from_MPU_SVU_RS(CONTROL_STATION_MPU_SVU_RS485); - parse_parameters_from_one_control_station_MPU_SVU(CONTROL_STATION_MPU_SVU_CAN); //3 - parse_parameters_from_one_control_station_MPU_SVU(CONTROL_STATION_MPU_KEY_CAN); //4 + // parse_parameters_from_one_control_station_MPU_SVU(CONTROL_STATION_MPU_SVU_CAN); + parse_parameters_from_one_control_station_MPU_SVU(CONTROL_STATION_MPU_KEY_CAN); // parse_parameters_from_one_control_station_MPU_SVU(CONTROL_STATION_MPU_SVU_RS485); @@ -2113,29 +1756,7 @@ void load_parameters_from_active_control_station(int current_control) { // что-то не то! пост не определен! for (i=0;iiqVal_U - v->iqVal_W); return d1 > v->setup.levels.iqAsymmetry_delta || d2 > v->setup.levels.iqAsymmetry_delta || - d3 > v->setup.levels.iqAsymmetry_delta ? 1 : 0; + d2 > v->setup.levels.iqAsymmetry_delta ? 1 : 0; } diff --git a/Inu/Src/main/detect_error_3_phase.h b/Inu/Src/main/detect_error_3_phase.h index bdb7307..da22f26 100644 --- a/Inu/Src/main/detect_error_3_phase.h +++ b/Inu/Src/main/detect_error_3_phase.h @@ -118,7 +118,7 @@ typedef struct { //Setup SETUP_3_PHASE_PROTECT setup; - int (*calc_detect_error_3_phase)(); + int (*calc)(); } DETECT_PROTECT_3_PHASE; diff --git a/Inu/Src/main/detect_errors.c b/Inu/Src/main/detect_errors.c index 07ff17c..fffa4d3 100644 --- a/Inu/Src/main/detect_errors.c +++ b/Inu/Src/main/detect_errors.c @@ -15,14 +15,9 @@ #include #include #include -#include "v_rotor.h" - #include "control_station.h" #include "DSP281x_Device.h" -#include "master_slave.h" -#include "another_bs.h" -#include "digital_filters.h" void detect_error_from_knopka_avaria(void); @@ -64,17 +59,10 @@ void detect_error_acdrive_winding(void); int get_common_state_warning(void); int get_common_state_overheat(void); -void detect_error_sensor_rotor(void); - - - #pragma DATA_SECTION(protect_levels,".slow_vars"); PROTECT_LEVELS protect_levels = PROTECT_LEVELS_DEFAULTS; - - - /////////////////////////////////////////////// int get_status_temper_acdrive_winding(int nc) { @@ -212,54 +200,6 @@ int get_status_p_water_min(int pump_on_off) } /////////////////////////////////////////////// /////////////////////////////////////////////// -void detect_error_sensor_rotor(void) -{ - static unsigned int count_err1 = 0, count_err2 = 0, count_err3 = 0, count_err4 = 0; - - - if (edrk.Go) - { - // стоим на месте? - if (edrk.iq_f_rotor_hz==0) - { - // долго стоим! - if (pause_detect_error(&count_err3,TIME_WAIT_SENSOR_ROTOR_BREAK_ALL,1)) - { - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 1; - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 1; - //edrk.errors.e9.bits.SENSOR_ROTOR_1_2_BREAK |= 1; // пока уберем! - } - else - { -// edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 0; -// edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 0; - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = pause_detect_error(&count_err1,TIME_WAIT_SENSOR_ROTOR_BREAK_ONE_SENSOR, - inc_sensor.break_sensor1); - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = pause_detect_error(&count_err2,TIME_WAIT_SENSOR_ROTOR_BREAK_ONE_SENSOR, - inc_sensor.break_sensor2); - } - } - else - { - count_err3 = 0; -// edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 0; -// edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 0; - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK |= pause_detect_error(&count_err1,TIME_WAIT_ERROR,inc_sensor.break_sensor1); - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK |= pause_detect_error(&count_err2,TIME_WAIT_ERROR,inc_sensor.break_sensor2); - - } - } - else - { - - count_err1 = count_err2 = 0; - count_err3 = 0; - - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 0; - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 0; - } - -} /////////////////////////////////////////////// #define TIME_WAIT_T_WATER 30 void detect_error_t_water(void) @@ -513,7 +453,7 @@ void detect_error_acdrive_bear(void) static unsigned int count_run = 0, count_run_static = 0; int status,i; -// status = 0; + status = 0; status = get_status_temper_acdrive_bear_with_limits(0, protect_levels.alarm_temper_acdrive_bear_DNE, protect_levels.abnormal_temper_acdrive_bear_DNE); @@ -616,7 +556,7 @@ void detect_error_ground(void) } if ((edrk.from_ing1.bits.ZAZEML_OFF == 1) && (edrk.from_ing1.bits.ZAZEML_ON == 0)) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } @@ -632,7 +572,7 @@ void detect_error_nagrev(void) edrk.errors.e5.bits.ERROR_HEAT |= 1; } else - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } @@ -675,11 +615,10 @@ void detect_error_block_izol(void) if (edrk.from_ing1.bits.BLOCK_IZOL_AVARIA == 0 && edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ) { - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_IZOL,0); + } - if (edrk.cmd_imit_low_isolation) - edrk.errors.e5.bits.ERROR_ISOLATE |= 1; } @@ -700,7 +639,7 @@ void detect_error_pre_charge(void) if (edrk.from_ing1.bits.ZARYAD_ON == 0 && edrk.to_ing.bits.ZARYAD_ON == 0) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_CHARGE_ANSWER,0); // edrk.errors.e6.bits.ERROR_PRE_CHARGE_ANSWER |= 1; @@ -715,7 +654,7 @@ void detect_error_qtv(void) // нет команды на выкл, но сухой контакт пришел - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 1 && edrk.cmd_to_qtv == 0) + if (edrk.from_shema.bits.QTV_ON_OFF == 1 && edrk.cmd_to_qtv == 0) { if (pause_detect_error(&count_err_off,TIME_WAIT_ERROR_QTV,1)) edrk.errors.e6.bits.QTV_ERROR_NOT_ANSWER |= 1; @@ -726,7 +665,7 @@ void detect_error_qtv(void) } // была команда на вкл, но сухой контакт не пришел - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 0 && edrk.cmd_to_qtv == 1) + if (edrk.from_shema.bits.QTV_ON_OFF == 0 && edrk.cmd_to_qtv == 1) { if (pause_detect_error(&count_err_on,TIME_WAIT_ERROR_QTV,1)) edrk.errors.e6.bits.QTV_ERROR_NOT_ANSWER |= 1; @@ -757,77 +696,20 @@ void detect_error_predohr_vipr(void) edrk.errors.e5.bits.ERROR_PRED_VIPR |= 1; if (edrk.from_ing1.bits.VIPR_PREDOHR_NORMA == 1) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } /////////////////////////////////////////////// -#define TIME_WAIT_ERROR_UMP_READY 1200 //120 сек //750 // ждем 75 сек т.к. возможно умр занят на сбор второго бс -#define TIME_WAIT_WARNING_UMP_READY 10 void detect_error_ump(void) { static unsigned int count_err = 0; - static unsigned int count_err2 = 0; - static unsigned int prev_SumSbor = 0; - static unsigned int StageUMP = 0; - static unsigned int count_UMP_NOT_READY = 0; - int local_warning_ump = 0; + if (edrk.from_shema.bits.READY_UMP == 0) + if (pause_detect_error(&count_err,TIME_WAIT_ERROR,1)) + edrk.errors.e7.bits.UMP_NOT_READY |= 1; - if (edrk.SumSbor==1) - { - switch (StageUMP) { - case 0: if (edrk.from_shema_filter.bits.UMP_ON_OFF == 1) - StageUMP++; - break; - case 1: if (edrk.from_shema_filter.bits.UMP_ON_OFF == 0) - StageUMP++; - break; - case 2: - break; - case 3: - break; - - - default: break; - } - - if ((edrk.from_shema_filter.bits.READY_UMP == 0) && (StageUMP==0) && control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_UMP]==0) - { - - if (pause_detect_error(&count_err,TIME_WAIT_ERROR_UMP_READY,1)) - edrk.errors.e7.bits.UMP_NOT_READY |= 1; - } - if (edrk.from_shema_filter.bits.READY_UMP == 1) - count_err = 0; - } - else - { - count_err= 0; - - // УМП включен, а не должен! - if (edrk.from_shema_filter.bits.UMP_ON_OFF==1) - if (pause_detect_error(&count_err2,TIME_WAIT_ERROR,1)) - edrk.errors.e11.bits.ERROR_UMP_NOT_OFF |= 1; - - if (edrk.from_shema_filter.bits.UMP_ON_OFF == 0) - count_err2 = 0; - - // нет готовности - if (edrk.ump_cmd_another_bs==0) // другой БС не занял УМП - local_warning_ump = !edrk.from_shema_filter.bits.READY_UMP; - // edrk.warnings.e7.bits.UMP_NOT_READY = !edrk.from_shema_filter.bits.READY_UMP; - - - - StageUMP = 0; - } - - edrk.warnings.e7.bits.UMP_NOT_READY = filter_digital_input( edrk.warnings.e7.bits.UMP_NOT_READY, - &count_UMP_NOT_READY, - TIME_WAIT_WARNING_UMP_READY, - local_warning_ump); - - prev_SumSbor = edrk.SumSbor; + if (edrk.from_ing1.bits.VIPR_PREDOHR_NORMA == 1) + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } @@ -839,14 +721,8 @@ void detect_error_block_qtv_from_svu(void) if (edrk.from_shema.bits.SVU_BLOCK_QTV == 1 || control_station.active_array_cmd[CONTROL_STATION_CMD_BLOCK_BS]) - { if (pause_detect_error(&count_err,TIME_WAIT_BLOCK_QTV_FROM_SVU,1)) edrk.errors.e7.bits.SVU_BLOCK_ON_QTV |= 1; - } - else - { - count_err = 0; - } } @@ -864,7 +740,7 @@ void detect_error_fan(void) edrk.errors.e5.bits.FAN |= 1; if (edrk.from_ing1.bits.VENTIL_ON == 0 && (edrk.to_ing.bits.NASOS_1_ON == 0 && edrk.to_ing.bits.NASOS_2_ON == 0)) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_FAN,0); } @@ -884,7 +760,7 @@ void detect_error_pre_ready_pump(void) if (edrk.from_ing1.bits.NASOS_NORMA == 1) { - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); edrk.warnings.e5.bits.PRE_READY_PUMP = 0; } } @@ -913,13 +789,13 @@ void detect_error_pump_1(void) if (edrk.from_ing1.bits.NASOS_ON == 0 && edrk.to_ing.bits.NASOS_1_ON==0 && edrk.SelectPump1_2==1) { // тут все ок - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_PUMP,0); } if (edrk.from_ing1.bits.NASOS_ON == 1 && edrk.to_ing.bits.NASOS_1_ON==1 && edrk.SelectPump1_2==1) { // тут все ок - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_PUMP,0); edrk.warnings.e5.bits.PUMP_1 = 0; } @@ -948,13 +824,13 @@ void detect_error_pump_2(void) if (edrk.from_ing1.bits.NASOS_ON == 0 && edrk.to_ing.bits.NASOS_2_ON==0 && edrk.SelectPump1_2==2) { // тут все ок - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_PUMP,0); } if (edrk.from_ing1.bits.NASOS_ON == 1 && edrk.to_ing.bits.NASOS_2_ON==1 && edrk.SelectPump1_2==2) { // тут все ок - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR_PUMP,0); edrk.warnings.e5.bits.PUMP_2 = 0; } } @@ -970,7 +846,7 @@ void detect_error_op_pit(void) edrk.errors.e5.bits.OP_PIT |= 1; if (edrk.from_ing1.bits.OP_PIT_NORMA == 1 ) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } /////////////////////////////////////////////// void detect_error_power_upc(void) @@ -982,7 +858,7 @@ void detect_error_power_upc(void) edrk.errors.e5.bits.POWER_UPC |= 1; if (edrk.from_ing1.bits.UPC_24V_NORMA == 1 ) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } /////////////////////////////////////////////// void detect_error_t_vipr(void) @@ -1007,7 +883,7 @@ void detect_error_ute4ka_water(void) if (edrk.from_ing1.bits.OHLAD_UTE4KA_WATER == 0 ) - count_err = 0; + pause_detect_error(&count_err,TIME_WAIT_ERROR,0); } /////////////////////////////////////////////// @@ -1055,55 +931,14 @@ void detect_error_sync_bus(void) // у этого БС синхросигнала нет, и у второго тоже нет, тогда авария if (sync_data.timeout_sync_signal && optical_read_data.data.cmd.bit.sync_line_detect==0 && edrk.ms.another_bs_maybe_on && optical_read_data.status==1) - { if (pause_detect_error(&count_err,TIME_WAIT_SYNC_SIGNAL,1)) edrk.errors.e1.bits.NO_INPUT_SYNC_SIGNAL |= 1; - } - else - count_err = 0; + } /////////////////////////////////////////////// -#pragma CODE_SECTION(detect_error_u_zpt_fast,".fast_run"); -int detect_error_u_zpt_fast(void) -{ - int err; - err = 0; - - - if (analog.iqU_1>=edrk.iqMAX_U_ZPT_Global) - edrk.errors.e0.bits.U_1_MAX |= 1; - - if (analog.iqU_2>=edrk.iqMAX_U_ZPT_Global) - edrk.errors.e0.bits.U_2_MAX |= 1; - - - if (analog.iqU_1>=edrk.iqMAX_U_ZPT) - edrk.errors.e0.bits.U_1_MAX |= 1; - - - if (analog.iqU_2>=edrk.iqMAX_U_ZPT) - edrk.errors.e0.bits.U_2_MAX |= 1; - - - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 1 - // && edrk.to_shema.bits.QTV_ON - ) - { - if (analog.iqU_1<=edrk.iqMIN_U_ZPT) - edrk.errors.e0.bits.U_1_MIN |= 1; - - if (analog.iqU_2<=edrk.iqMIN_U_ZPT) - edrk.errors.e0.bits.U_2_MIN |= 1; - } - - err = (edrk.errors.e0.bits.U_1_MAX || edrk.errors.e0.bits.U_2_MAX || edrk.errors.e0.bits.U_1_MIN || edrk.errors.e0.bits.U_2_MIN); - return err; - -} -/////////////////////////////////////////////// /////////////////////////////////////////////// int detect_error_u_zpt(void) { @@ -1121,9 +956,7 @@ int detect_error_u_zpt(void) } - if (edrk.iqMAX_U_ZPT>MINIMAL_LEVEL_ZAD_U && edrk.from_shema_filter.bits.QTV_ON_OFF == 1 - // && edrk.to_shema.bits.QTV_ON - ) + if (edrk.iqMAX_U_ZPT>MINIMAL_LEVEL_ZAD_U && edrk.from_shema.bits.QTV_ON_OFF == 1) { if (analog.iqU_1>=edrk.iqMAX_U_ZPT) edrk.errors.e0.bits.U_1_MAX |= 1; @@ -1133,9 +966,7 @@ int detect_error_u_zpt(void) edrk.errors.e0.bits.U_2_MAX |= 1; } - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 1 - //&& edrk.to_shema.bits.QTV_ON - ) + if (edrk.from_shema.bits.QTV_ON_OFF == 1) { if (analog.iqU_1<=edrk.iqMIN_U_ZPT) edrk.errors.e0.bits.U_1_MIN |= 1; @@ -1172,7 +1003,6 @@ int detect_error_u_zpt_on_predzaryad(void) } /////////////////////////////////////////////// -#pragma CODE_SECTION(detect_error_u_in,".fast_run"); int detect_error_u_in(void) { int err; @@ -1190,9 +1020,7 @@ int detect_error_u_in(void) edrk.errors.e0.bits.U_IN_MAX |= 1; } - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 1 && edrk.SumSbor - // && edrk.to_shema.bits.QTV_ON - ) + if (edrk.from_shema.bits.QTV_ON_OFF == 1 && edrk.SumSbor) { if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_QTV]==1) { @@ -1233,7 +1061,7 @@ int detect_error_u_in(void) } /////////////////////////////////////////////// -#define MAX_WAIT_AFTER_KVITIR 100//50 +#define MAX_WAIT_AFTER_KVITIR 50 void detect_error_all(void) { unsigned int pause_after_kvitir=0; @@ -1272,13 +1100,9 @@ void detect_error_all(void) detect_error_ground(); detect_error_ump(); - // для аварии в другой ПЧ исключаем аварию из этогоже ПЧ, иначе получаем кольцо. Аварии замыкаются! if (pause_after_kvitir) - { detect_error_from_knopka_avaria(); - detect_error_from_another_bs(); - } #if (_FLOOR6==1) @@ -1305,7 +1129,6 @@ void detect_error_all(void) edrk.warnings.e10.bits.WARNING_I_OUT_OVER_1_6_NOMINAL = out_I_over_1_6.overload_detected; // edrk.errors.e7.bits.ANOTHER_BS_ALARM |= optical_read_data.data.cmd.bit.alarm; - detect_error_sensor_rotor(); } @@ -1366,7 +1189,7 @@ void read_plane_errors(void) if (project.controller.read.errors.bit.pwm_wdog) edrk.errors.e9.bits.ERR_PWM_WDOG |= 1; -#if USE_TK_0 +#ifdef USE_TK_0 //af1 if (project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk0_ack || project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk0_current || @@ -1393,7 +1216,7 @@ void read_plane_errors(void) edrk.errors.e6.bits.UO3_KEYS |= 1; #endif -#if USE_TK_1 +#ifdef USE_TK_1 //af3 if (project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk0_ack || project.cds_tk[1].read.sbus.status_protect_current_ack.bit.tk0_current || @@ -1420,7 +1243,7 @@ void read_plane_errors(void) edrk.errors.e6.bits.UO5_KEYS |= 1; #endif -#if USE_TK_2 +#ifdef USE_TK_2 //af5 if (project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk0_ack || project.cds_tk[2].read.sbus.status_protect_current_ack.bit.tk0_current || @@ -1449,7 +1272,7 @@ void read_plane_errors(void) #endif -#if USE_TK_3 +#ifdef USE_TK_3 if (project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk0_ack || project.cds_tk[3].read.sbus.status_protect_current_ack.bit.tk0_current || @@ -1566,7 +1389,7 @@ void read_plane_errors(void) if (project.all_status_plates.in0 != component_Ready) edrk.errors.e3.bits.NOT_READY_IN_0 |= 1; #endif -#if USE_IN_1 +#if USE_IN_0 if (project.all_status_plates.in1 != component_Ready) edrk.errors.e3.bits.NOT_READY_IN_1 |= 1; #endif @@ -1603,4 +1426,3 @@ int get_common_state_overheat() { edrk.errors.e2.bits.T_UO7_MAX | edrk.errors.e2.bits.T_WATER_EXT_MAX | edrk.errors.e2.bits.T_WATER_INT_MAX; } - diff --git a/Inu/Src/main/detect_errors.h b/Inu/Src/main/detect_errors.h index 48e3126..9dae0c5 100644 --- a/Inu/Src/main/detect_errors.h +++ b/Inu/Src/main/detect_errors.h @@ -10,17 +10,12 @@ -#define TIME_WAIT_ERROR 20 // 2 sec -#define TIME_WAIT_ERROR_QTV 100 // 10 sec -#define TIME_WAIT_ERROR_CHARGE_ANSWER 60 // 6 sec -#define TIME_WAIT_ERROR_IZOL 50 //5 sec //200 // 20 sec -#define TIME_WAIT_ERROR_PUMP 100 // 10 sec -#define TIME_WAIT_ERROR_FAN 300 // 30 sec -#define TIME_WAIT_SENSOR_ROTOR_BREAK_ALL 200 // 20 sec -#define TIME_WAIT_SENSOR_ROTOR_BREAK_DIRECTION 10 // 1 sec -#define TIME_WAIT_SENSOR_ROTOR_BREAK_ONE_SENSOR 20 // 2 sec - - +#define TIME_WAIT_ERROR 20 // 2 sec +#define TIME_WAIT_ERROR_QTV 100 // 10 sec +#define TIME_WAIT_ERROR_CHARGE_ANSWER 60 // 6 sec +#define TIME_WAIT_ERROR_IZOL 200 // 20 sec +#define TIME_WAIT_ERROR_PUMP 100 // 10 sec +#define TIME_WAIT_ERROR_FAN 300 // 30 sec #define MINIMAL_LEVEL_ZAD_U 27962 // 10 V @@ -31,50 +26,5 @@ void detect_error_all(void); void read_plane_errors(void); int detect_error_u_zpt_on_predzaryad(void); int detect_error_u_in(void); -int detect_error_u_zpt_fast(void); - - -void detect_error_from_knopka_avaria(void); -void detect_error_ute4ka_water(void); -void detect_error_t_vipr(void); -void detect_error_power_upc(void); -void detect_error_op_pit(void); -void detect_error_p_water(void); -void detect_error_pump_2(void); -void detect_error_pump_1(void); -void detect_error_pre_ready_pump(void); -void detect_error_fan(void); -void detect_error_block_qtv_from_svu(void); - -void detect_error_predohr_vipr(void); -void detect_error_qtv(void); -void detect_error_pre_charge(void); -void detect_error_block_izol(void); -void detect_error_nagrev(void); -void detect_error_ground(void); -void detect_error_block_door(void); -void detect_error_optical_bus(void); -void detect_error_sync_bus(void); -int get_status_temper_acdrive_winding(int nc); -int get_status_temper_acdrive_winding_with_limits(int nc, int alarm, int abnormal); -int get_status_temper_acdrive_bear(int nc); -int get_status_temper_acdrive_bear_with_limits(int nc, int alarm, int abnormal); -int get_status_temper_air(int nc); -int get_status_temper_air_with_limits(int nc, int alarm, int abnormal); -int get_status_temper_u(int nc); -int get_status_temper_u_with_limits(int nc, int alarm, int abnormal); -int get_status_temper_water(int nc); -int get_status_p_water_max(void); -int get_status_p_water_min(int pump_on_off); -void detect_error_t_water(void); -void detect_error_t_air(void); -void detect_error_t_u(void); -void detect_error_acdrive_winding(void); - -int get_common_state_warning(void); -int get_common_state_overheat(void); -void detect_error_sensor_rotor(void); - - #endif /* SRC_MYLIBS_DETECT_ERRORS_H_ */ diff --git a/Inu/Src/main/detect_errors_adc.c b/Inu/Src/main/detect_errors_adc.c index 634ea2f..3d7df44 100644 --- a/Inu/Src/main/detect_errors_adc.c +++ b/Inu/Src/main/detect_errors_adc.c @@ -11,22 +11,18 @@ #include #include #include -#include "digital_filters.h" #include "IQmathLib.h" //ANALOG_PROTECT_LEVELS analog_protect_levels = ANALOG_PROTECT_LEVELS_DEFAULTS; -//#pragma DATA_SECTION(analog_protect,".fast_vars"); -#pragma DATA_SECTION(analog_protect,".slow_vars"); +#pragma DATA_SECTION(analog_protect,".fast_vars"); ANALOG_ADC_PROTECT analog_protect = ANALOG_ADC_PROTECT_DEFAULTS; -//#pragma DATA_SECTION(break_Iout_1_state,".fast_vars"); -#pragma DATA_SECTION(break_Iout_1_state,".slow_vars"); +#pragma DATA_SECTION(break_Iout_1_state,".fast_vars"); BREAK_PHASE_I break_Iout_1_state = BREAK_PHASE_I_DEFAULTS; -//#pragma DATA_SECTION(break_Iout_2_state,".fast_vars"); -#pragma DATA_SECTION(break_Iout_2_state,".slow_vars"); +#pragma DATA_SECTION(break_Iout_2_state,".fast_vars"); BREAK_PHASE_I break_Iout_2_state = BREAK_PHASE_I_DEFAULTS; int detect_error_Izpt(); @@ -38,9 +34,7 @@ void init_analog_protect_levels(void) { } #define AMPL_TO_RMS 0.709 - -//#define LEVEL_I_1_2_DIBALANCE 1118481 // 200 A -#define LEVEL_I_1_2_DIBALANCE 1677721 // 300 A +#define LEVEL_I_1_2_DIBALANCE 1118481 void init_protect_3_phase(void) { analog_protect.in_voltage[0].setup.levels.iqVal_module_max = edrk.iqMAX_U_IN; @@ -202,14 +196,13 @@ void detect_protect_adc(_iq teta_ch1, _iq teta_ch2) { edrk.errors.e0.bits.U_B2C2_MAX |= analog_protect.in_voltage[1].errors.bits.phase_V_max; edrk.errors.e0.bits.U_IN_MAX |= analog_protect.in_voltage[1].errors.bits.module_max; - edrk.warnings.e8.bits.U_IN_20_PROCENTS_HIGH = analog_protect.in_voltage[0].over_limit.bits.module_20_percent_hi || analog_protect.in_voltage[1].over_limit.bits.module_20_percent_hi; + edrk.warnings.e8.bits.U_IN_20_PROCENTS_HIGH = analog_protect.in_voltage[0].over_limit.bits.module_20_percent_hi; edrk.errors.e8.bits.U_IN_20_PROCENTS_HIGH |= analog_protect.in_voltage[0].errors.bits.module_20_percent_hi; + + edrk.warnings.e8.bits.U_IN_20_PROCENTS_HIGH = analog_protect.in_voltage[1].over_limit.bits.module_20_percent_hi; edrk.errors.e8.bits.U_IN_20_PROCENTS_HIGH |= analog_protect.in_voltage[1].errors.bits.module_20_percent_hi; - if (edrk.from_shema_filter.bits.QTV_ON_OFF == 1 - // && edrk.to_shema.bits.QTV_ON - ) - { + if (edrk.from_shema.bits.QTV_ON_OFF == 1) { // контроль напряжений только при включенном силовом автомате edrk.errors.e8.bits.U_IN_10_PROCENTS_LOW |= analog_protect.in_voltage[0].errors.bits.module_10_percent_low; @@ -218,21 +211,11 @@ void detect_protect_adc(_iq teta_ch1, _iq teta_ch2) { edrk.errors.e8.bits.U_IN_10_PROCENTS_LOW |= analog_protect.in_voltage[1].errors.bits.module_10_percent_low; edrk.errors.e8.bits.U_IN_20_PROCENTS_LOW |= analog_protect.in_voltage[1].errors.bits.module_20_percent_low; - edrk.warnings.e8.bits.U_IN_10_PROCENTS_LOW = pause_detect_error(&counter_in1_minus10, - TIME_DETECT_WARNING_U_PREDELS, - analog_protect.in_voltage[0].over_limit.bits.module_10_percent_low); + edrk.warnings.e8.bits.U_IN_10_PROCENTS_LOW = pause_detect_error(&counter_in1_minus10, TIME_DETECT_WARNING_U_PREDELS, analog_protect.in_voltage[0].over_limit.bits.module_10_percent_low); + edrk.warnings.e8.bits.U_IN_10_PROCENTS_LOW |= pause_detect_error(&counter_in2_minus10, TIME_DETECT_WARNING_U_PREDELS, analog_protect.in_voltage[1].over_limit.bits.module_10_percent_low); - edrk.warnings.e8.bits.U_IN_10_PROCENTS_LOW = pause_detect_error(&counter_in2_minus10, - TIME_DETECT_WARNING_U_PREDELS, - analog_protect.in_voltage[1].over_limit.bits.module_10_percent_low); - - edrk.warnings.e8.bits.U_IN_20_PROCENTS_LOW = pause_detect_error(&counter_in1_minus20, - TIME_DETECT_WARNING_U_PREDELS, - analog_protect.in_voltage[0].over_limit.bits.module_20_percent_low); - - edrk.warnings.e8.bits.U_IN_20_PROCENTS_LOW = pause_detect_error(&counter_in2_minus20, - TIME_DETECT_WARNING_U_PREDELS, - analog_protect.in_voltage[1].over_limit.bits.module_20_percent_low); + edrk.warnings.e8.bits.U_IN_20_PROCENTS_LOW = pause_detect_error(&counter_in1_minus20, TIME_DETECT_WARNING_U_PREDELS, analog_protect.in_voltage[0].over_limit.bits.module_20_percent_low); + edrk.warnings.e8.bits.U_IN_20_PROCENTS_LOW |= pause_detect_error(&counter_in2_minus20, TIME_DETECT_WARNING_U_PREDELS, analog_protect.in_voltage[1].over_limit.bits.module_20_percent_low); edrk.errors.e9.bits.DISBALANCE_Uin_1 |= analog_protect.in_voltage[0].errors.bits.system_asymmetry; edrk.errors.e9.bits.DISBALANCE_Uin_2 |= analog_protect.in_voltage[1].errors.bits.system_asymmetry; diff --git a/Inu/Src/main/detect_errors_adc.h b/Inu/Src/main/detect_errors_adc.h index 6aa850d..a76228b 100644 --- a/Inu/Src/main/detect_errors_adc.h +++ b/Inu/Src/main/detect_errors_adc.h @@ -33,8 +33,7 @@ typedef struct { #define ANALOG_ADC_PROTECT_DEFAULTS { \ {DETECT_PROTECT_3_PHASE_DEFAULTS,DETECT_PROTECT_3_PHASE_DEFAULTS},\ - {DETECT_PROTECT_3_PHASE_DEFAULTS,DETECT_PROTECT_3_PHASE_DEFAULTS},\ - 0,0 } + {DETECT_PROTECT_3_PHASE_DEFAULTS,DETECT_PROTECT_3_PHASE_DEFAULTS}} void init_analog_protect_levels(void); void detect_protect_adc (_iq teta_ch1, _iq teta_ch2); diff --git a/Inu/Src/main/detect_overload.c b/Inu/Src/main/detect_overload.c index fce38dd..191adaa 100644 --- a/Inu/Src/main/detect_overload.c +++ b/Inu/Src/main/detect_overload.c @@ -9,7 +9,6 @@ #include #include #include -#include "alg_simple_scalar.h" #include "IQmathLib.h" @@ -44,49 +43,32 @@ int calc_detect_overload(DETECT_OVERLOAD *v) { return v->overload_detected; } -#define LIMIT_DETECT_LEVEL 16273899 // 0.97 //15938355 //95% +#define LIMIT_DETECT_LEVEL 15938355 //95% void check_all_power_limits() { _iq level_I_nominal = 0; - //edrk.power_limit.bits.limit_by_temper = edrk.temper_limit_koeffs.code_status; + edrk.power_limit.bits.limit_by_temper = edrk.temper_limit_koeffs.code_status; - if (edrk.Go) - { - - level_I_nominal = _IQmpy(LIMIT_DETECT_LEVEL, edrk.zadanie.iq_Izad_rmp); - - if ((filter.iqIm > level_I_nominal) || - out_I_over_1_6.overload_detected) - { - edrk.power_limit.bits.limit_Iout = 1; - } else - { - edrk.power_limit.bits.limit_Iout = 0; - } - } - else + level_I_nominal = _IQmpy(LIMIT_DETECT_LEVEL, edrk.zadanie.iq_Izad_rmp); + if ((filter.iqIm_1 > level_I_nominal) || (filter.iqIm_1 > level_I_nominal) || + out_I_over_1_6.overload_detected) { + edrk.power_limit.bits.limit_Iout = 1; + } else { edrk.power_limit.bits.limit_Iout = 0; - -// if (edrk.from_uom.code>1) -// edrk.power_limit.bits.limit_UOM = 1; -// else -// edrk.power_limit.bits.limit_UOM = 0; - -//filter.PowerScalar + edrk.iq_power_kw_another_bs - if ( (edrk.iq_power_kw_full_filter_abs > _IQmpy(LIMIT_DETECT_LEVEL, edrk.zadanie.iq_limit_power_zad_rmp)) - || simple_scalar1.flag_decr_mzz_power - // Данный способ для скалярного управления, для FOC, возможно, нужна векторная мощность. - ) - { - edrk.power_limit.bits.limit_from_SVU = 1; } - else - { + +// edrk.power_limit.bits.limit_UOM = + + if ((filter.PowerScalar + edrk.iq_power_kw_another_bs) > + _IQmpy(LIMIT_DETECT_LEVEL, edrk.zadanie.iq_limit_power_zad_rmp) + // Данный способ для скалярного управления, для FOC, возможно, нужна векторная мощность. + ) { + edrk.power_limit.bits.limit_from_SVU = 1; + } else { edrk.power_limit.bits.limit_from_SVU = 0; } - } diff --git a/Inu/Src/main/edrk_main.c b/Inu/Src/main/edrk_main.c index c89a473..d6ae688 100644 --- a/Inu/Src/main/edrk_main.c +++ b/Inu/Src/main/edrk_main.c @@ -10,7 +10,7 @@ #include #include #include -//#include +#include #include #include #include @@ -30,20 +30,19 @@ #include #include #include - +#include "edrk_main.h" #include "mathlib.h" -#include "params_hwp.h" //#include "modbus_fill_table.h" #include "big_dsp_module.h" #include "control_station.h" #include "CAN_Setup.h" - +#include "global_time.h" #include "global_time.h" #include "IQmathLib.h" #include "mathlib.h" - +#include "mathlib.h" #include "modbus_table_v2.h" #include "oscil_can.h" #include "DSP281x_Examples.h" // DSP281x Examples Include File @@ -57,39 +56,24 @@ #include "sbor_shema.h" #include "alarm_log_can.h" #include "pwm_test_lines.h" -#include "master_slave.h" -#include "xp_write_xpwm_time.h" -#include "v_rotor_22220.h" -#include "log_to_memory.h" -#include "log_params.h" -#include "build_version.h" -#include "profile_interrupt.h" -#include "limit_power.h" -#include "pwm_logs.h" -#include "logs_hmi.h" -#include "alarm_log.h" -#include "can_protocol_ukss.h" -#include "ukss_tools.h" -#include "another_bs.h" -#include "temper_p_tools.h" -#include "digital_filters.h" -#include "pll_tools.h" -#include "ramp_zadanie_tools.h" -#include "uom_tools.h" -#include "synhro_tools.h" - -#if (_SIMULATE_AC==1) -#include "sim_model.h" -#endif /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// -//#pragma DATA_SECTION(ccc, ".slow_vars") -//int ccc[40] = {0,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1}; +#pragma DATA_SECTION(Unites2VPU, ".slow_vars") +int Unites2VPU[127]={0}; + +#pragma DATA_SECTION(Unites2Zadat4ik, ".slow_vars") +int Unites2Zadat4ik[127]={0}; + +#pragma DATA_SECTION(Unites2BKSSD, ".slow_vars") +int Unites2BKSSD[127]={0}; + +#pragma DATA_SECTION(Unites2UMU, ".slow_vars") +int Unites2UMU[127]={0}; #pragma DATA_SECTION(f, ".slow_vars") FLAG f = FLAG_DEFAULTS; @@ -102,8 +86,42 @@ unsigned int old_time_edrk1 = 0, old_time_edrk2 = 0, prev_flag_special_mode_rs = #pragma DATA_SECTION(edrk, ".slow_vars") EDRK edrk = EDRK_DEFAULT; +#pragma DATA_SECTION(pll1, ".slow_vars") +PLL_REC pll1 = PLL_REC_DEFAULT; + +#define U_LEVEL_ON_BLOCK_KEY 559240 // 100V +#define U_LEVEL_OFF_BLOCK_KEY 279620 // 50V +#define TEMPER_NAGREF_ON 5 +#define TEMPER_NAGREF_OFF 10 + +int vozb_on_off=0; + + +int vozb_plus=0; +int vozb_minus=0; + +#define MAX_TIME_SBOR 100 +#define MAX_TIME_RAZBOR 100 + + +#define VOZB_MAX_TIMER_ON 20 +#define VOZB_MAX_TIMER_OFF 20 + +#define QTV_MAX_TIMER_ON 20 +#define QTV_MAX_TIMER_OFF 20 + + +#define VOZB_ACP_IN project.adc[0].read.pbus.adc_value[2] +#define ING_ACP_IN_CUR_OBOROT project.adc[0].read.pbus.adc_value[0] +#define ING_ACP_IN_ZAD_VOZB project.adc[0].read.pbus.adc_value[1] + + +//#define DEC_ZAD_OBOROTS 1 +//#define INC_ZAD_OBOROTS 1 + +//#define MAX_ZAD_OBOROTS 150 //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// @@ -119,48 +137,391 @@ static unsigned int old_time_edrk3 = 0, prev_PROVOROT; if (!(detect_pause_milisec(100,&old_time_edrk3))) return; +// if (edrk.from_shema.bits.SVU) return; +// if (edrk.from_shema.bits.ZADA_DISPLAY) return; +// +// +// if (control_station.active_control_station[CONTROL_STATION_ZADATCHIK_CAN]) +// { +// +// if (edrk.from_zadat4ik.bits.MINUS) +// { +// if (edrk.W_from_ZADAT4IK>0) +// edrk.W_from_ZADAT4IK=edrk.W_from_ZADAT4IK-DEC_ZAD_OBOROTS; +// if (edrk.W_from_ZADAT4IK<0) +// edrk.W_from_ZADAT4IK=0; +// } +// +// if (edrk.from_zadat4ik.bits.PLUS) +// { +// if (edrk.W_from_ZADAT4IK=MAX_ZAD_OBOROTS) +// edrk.W_from_ZADAT4IK=MAX_ZAD_OBOROTS; +// } +// +// +// if (edrk.from_zadat4ik.bits.PROVOROT) +// { +// edrk.W_from_ZADAT4IK = 3; +// } +// +// if ((edrk.from_zadat4ik.bits.PROVOROT==0) && (prev_PROVOROT==1)) +// edrk.W_from_ZADAT4IK = 0; +// +// prev_PROVOROT = edrk.from_zadat4ik.bits.PROVOROT; +// } +// +// if (control_station.active_control_station[CONTROL_STATION_VPU_CAN]) +// { +// +// if (edrk.from_vpu.bits.MINUS) +// { +// if (edrk.W_from_VPU>0) +// edrk.W_from_VPU=edrk.W_from_VPU-DEC_ZAD_OBOROTS; +// if (edrk.W_from_VPU<0) +// edrk.W_from_VPU=0; +// } +// +// if (edrk.from_vpu.bits.PLUS) +// { +// if (edrk.W_from_VPU=MAX_ZAD_OBOROTS) +// edrk.W_from_VPU=MAX_ZAD_OBOROTS; +// } +// +// +// if (edrk.from_vpu.bits.PROVOROT) +// { +// edrk.W_from_VPU = 3; +// } +// +// if ((edrk.from_vpu.bits.PROVOROT==0) && (prev_PROVOROT==1)) +// edrk.W_from_VPU = 0; +// +// prev_PROVOROT = edrk.from_vpu.bits.PROVOROT; +// } + +} +//////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +//TODO: may be move to detect_errors.c +unsigned int pause_detect_error(unsigned int *c_err, unsigned int max_wait,unsigned int flag) +{ + if (flag) + { + if ((*c_err)>=max_wait) + { + return 1; + } + else + { + (*c_err)++; + return 0; + } + } + else + { + (*c_err) = 0; + return 0; + + } + + + } + +void update_ukss_setup(unsigned int pause) +{ + static unsigned int old_time_ukss1=0; + int real_mbox; + + + Unites2Zadat4ik[96] = 25; + Unites2Zadat4ik[97] = 100; + Unites2Zadat4ik[98] = 8; + + Unites2VPU[96] = 25; + Unites2VPU[97] = 100; + Unites2VPU[98] = 8; + + Unites2UMU[96] = 25; + Unites2UMU[97] = 100; + Unites2UMU[98] = 8; + + Unites2BKSSD[96] = 25; + Unites2BKSSD[97] = 100; + Unites2BKSSD[98] = 8; + + if (detect_pause_milisec(pause,&old_time_ukss1)) + { + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, ZADATCHIK_CAN); + + if (CAN_cycle_free(real_mbox)) + { + CAN_cycle_send( UNITS_TYPE_BOX, ZADATCHIK_CAN, 96, &Unites2Zadat4ik[96], 3, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, VPU_CAN); + + if (CAN_cycle_free(real_mbox)) + { + CAN_cycle_send( UNITS_TYPE_BOX, VPU_CAN, 96, &Unites2VPU[96], 3, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, UMU_CAN_DEVICE); + + if (CAN_cycle_free(real_mbox)) + { + CAN_cycle_send( UNITS_TYPE_BOX, UMU_CAN_DEVICE, 96, &Unites2UMU[96], 3, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, BKSSD_CAN_DEVICE); + + if (CAN_cycle_free(real_mbox)) + { + CAN_cycle_send( UNITS_TYPE_BOX, BKSSD_CAN_DEVICE, 96, &Unites2BKSSD[96], 3, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + } + +} + +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// обновлЯем задатчик и ВПУ +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// + +void update_ukss_can(unsigned int pause) +{ + int real_mbox; + int t1; + static unsigned int old_time_ukss2=0; + + + if (edrk.flag_second_PCH==0) + t1 = pause; + if (edrk.flag_second_PCH==1) + t1 = pause; + + + Unites2Zadat4ik[4] = edrk.to_zadat4ik.OBOROTS1.all; + Unites2Zadat4ik[5] = edrk.to_zadat4ik.OBOROTS2.all; + Unites2Zadat4ik[6] = edrk.to_zadat4ik.BIG_LAMS.all; + Unites2Zadat4ik[7] = edrk.to_zadat4ik.APL_LAMS0.all; + Unites2Zadat4ik[8] = 0; + + Unites2VPU[4] = edrk.to_vpu.OBOROTS1.all; + Unites2VPU[5] = edrk.to_vpu.OBOROTS2.all; + Unites2VPU[6] = edrk.to_vpu.BIG_LAMS.all; + Unites2VPU[7] = 0; + Unites2VPU[8] = 0; + + if (detect_pause_milisec(t1,&old_time_ukss2)) + { + +// real_mbox = get_real_out_mbox(UNITS_TYPE_BOX, ZADATCHIK_CAN); + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, ZADATCHIK_CAN); + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + if (edrk.flag_second_PCH==0) + CAN_cycle_send( UNITS_TYPE_BOX, ZADATCHIK_CAN, 4, &Unites2Zadat4ik[4], 5, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + else + CAN_cycle_send( UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xa, &Unites2Zadat4ik[4], 5, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + + +// +// +// if (CAN_FIFO_free(5)) +// { +// if (edrk.flag_second_PCH==0) +// { +// +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0x4, edrk.to_zadat4ik.OBOROTS1.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0x5, edrk.to_zadat4ik.OBOROTS2.all); +// +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0x6, edrk.to_zadat4ik.BIG_LAMS.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0x7, edrk.to_zadat4ik.APL_LAMS0.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0x8, 0); +// +// } +// else +// { +// +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xa, edrk.to_zadat4ik.OBOROTS1.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xb, edrk.to_zadat4ik.OBOROTS2.all); +// +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xc, edrk.to_zadat4ik.BIG_LAMS.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xd, edrk.to_zadat4ik.APL_LAMS0.all); +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK_CAN, 0xe, 0); +// +// } +// +// } + + +// real_mbox = get_real_out_mbox(UNITS_TYPE_BOX, VPU_CAN); + + real_mbox = get_real_out_mbox (UNITS_TYPE_BOX, VPU_CAN); + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + if (edrk.flag_second_PCH==0) + CAN_cycle_send( UNITS_TYPE_BOX, VPU_CAN, 4, &Unites2VPU[4], 4, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + else + CAN_cycle_send( UNITS_TYPE_BOX, VPU_CAN, 0xa, &Unites2VPU[4], 4, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL);// примерно 40 мсек. идет отправка всей посылки + } + +// if (CAN_FIFO_free(3)) +// { +// if (edrk.flag_second_PCH==0) +// { +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0x4, edrk.to_vpu.OBOROTS1.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0x5, edrk.to_vpu.OBOROTS2.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0x6, edrk.to_vpu.BIG_LAMS.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0x8, 0); +// } +// else +// { +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0xa, edrk.to_vpu.OBOROTS1.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0xb, edrk.to_vpu.OBOROTS2.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0xc, edrk.to_vpu.BIG_LAMS.all); +// CAN_word_send(UNITS_TYPE_BOX, VPU_CAN, 0xe, 0); +// } +// +// } + + + +// CAN_word_send(UNITS_TYPE_BOX, ZADATCHIK, 0x4, edrk.to_zadat4ik.APL_LAMS1.all); + } + +} + + +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// спец настройки для межблочного обмена БС1 БС2 по CAN +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// + +void init_can_box_between_bs1_bs2(void) +{ + // включаем реверс адресов только для одного БС + // имитируем ящик Unites какбы + // + if (edrk.flag_second_PCH==0) + { + unites_can_setup.revers_box[ANOTHER_BSU1_CAN_DEVICE] = 1; + } + + unites_can_setup.adr_detect_refresh[ZADATCHIK_CAN] = 16; + +} + +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// обновлЯем другой БСУ по CAN +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// + +void update_bsu_can(unsigned int pause) +{ + int real_mbox; + int t1; + +// if (edrk.flag_second_PCH==0) +// t1 = 125; +// if (edrk.flag_second_PCH==1) +// t1 = 150; + + SendAll2SecondBS(pause); + +} + +//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// +unsigned int counter_imit_rascepitel = 0; + +unsigned int imit_signals_rascepitel(unsigned int *counter, unsigned int max_pause, unsigned int s, unsigned int cmd_clear) +{ + if (cmd_clear==1) + { + (*counter) = 0; + return 0; + } + + if (s) + { + if ((*counter)>=max_pause) + return 1; + else + (*counter)++; + + return 0; + } + + if (s==0) + { + if ((*counter)==0) + return 0; + else + (*counter)--; + + return 1; + } + return 0; +} + +////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // считываем цифровые входы //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -#define RASCEPITEL_MANUAL_ALWAYS_ON_2 1 // 1 -#define TIME_ON_OFF_FOR_IMITATION_RASCEPITEL 50 // 5 сек. -#define TIME_FILTER_UMP_SIGNALS 5 // 0.5 сек -#define TIME_FILTER_ALL_SIGNALS 5 // 0.5 сек - - -#pragma DATA_SECTION(count_wait_filter, ".slow_vars") -unsigned int count_wait_filter[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; -unsigned int counter_imit_rascepitel = 0; +#define RASCEPITEL_MANUAL_ALWAYS_ON_2 1//1 +#define TIME_ON_OFF_FOR_IMITATION_RASCEPITEL 50 // 5 сек. void update_input_edrk(void) { static unsigned int flag_imit_rascepitel = 0; static int st1=0; - // ANOTHER PCH edrk.from_second_pch.bits.RASCEPITEL = !FROM_ING_ANOTHER_RASCEPITEL; edrk.from_second_pch.bits.MASTER = FROM_ING_ANOTHER_MASTER_PCH; + + +// ZADAT4IK + if (control_station.alive_control_station[CONTROL_STATION_ZADATCHIK_CAN]) + edrk.from_zadat4ik.all = Unites[ZADATCHIK_CAN][16]; + else + edrk.from_zadat4ik.all = 0; + + if (control_station.alive_control_station[CONTROL_STATION_VPU_CAN]) + edrk.from_vpu.all = Unites[VPU_CAN][16]; + else + edrk.from_vpu.all = 0; + // ING #if (_FLOOR6==1) if (st1==0) { - edrk.from_zadat4ik.all = 0; - edrk.from_vpu.all = 0; - edrk.from_ing1.bits.ALL_KNOPKA_AVARIA = 0;//!FROM_ALL_KNOPKA_AVARIA; edrk.from_ing1.bits.BLOCK_IZOL_AVARIA = 0;//!FROM_ING_BLOCK_IZOL_AVARIA; edrk.from_ing1.bits.BLOCK_IZOL_NORMA = 1;//!FROM_ING_BLOCK_IZOL_NORMA; - edrk.from_ing1.bits.LOCAL_REMOUTE = 1;//0;//!FROM_ING_LOCAL_REMOUTE; + edrk.from_ing1.bits.LOCAL_REMOUTE = 0;//!FROM_ING_LOCAL_REMOUTE; edrk.from_ing1.bits.NAGREV_ON = 1;//!FROM_ING_NAGREV_ON; edrk.from_ing1.bits.NASOS_NORMA = 1;//!FROM_ING_NASOS_NORMA; edrk.from_ing1.bits.NASOS_ON = 0;//!FROM_ING_NASOS_ON; @@ -211,32 +572,8 @@ void update_input_edrk(void) edrk.from_ing2.bits.SOST_ZAMKA = !edrk.to_ing.bits.BLOCK_KEY_OFF; - if (edrk.to_ing.bits.NASOS_2_ON || edrk.to_ing.bits.NASOS_1_ON) - { - edrk.from_ing1.bits.VENTIL_ON = 1; - edrk.from_ing1.bits.NASOS_ON = 1; - } - else - { - edrk.from_ing1.bits.VENTIL_ON = 0; - edrk.from_ing1.bits.NASOS_ON = 0; - } + #else - - - // ZADAT4IK - if (control_station.alive_control_station[CONTROL_STATION_ZADATCHIK_CAN]) - edrk.from_zadat4ik.all = Unites[ZADATCHIK_CAN][16]; - else - edrk.from_zadat4ik.all = 0; - - if (control_station.alive_control_station[CONTROL_STATION_VPU_CAN]) - edrk.from_vpu.all = Unites[VPU_CAN][16]; - else - edrk.from_vpu.all = 0; - - - edrk.from_ing1.bits.ALL_KNOPKA_AVARIA = !FROM_ALL_KNOPKA_AVARIA; edrk.from_ing1.bits.BLOCK_IZOL_AVARIA = !FROM_ING_BLOCK_IZOL_AVARIA; edrk.from_ing1.bits.BLOCK_IZOL_NORMA = !FROM_ING_BLOCK_IZOL_NORMA; @@ -279,109 +616,15 @@ void update_input_edrk(void) // SHEMA edrk.from_shema.bits.RAZBOR_SHEMA = FROM_BSU_RAZBOR_SHEMA; - edrk.from_shema.bits.SBOR_SHEMA = FROM_BSU_SBOR_SHEMA; - - if (edrk.from_shema.bits.RAZBOR_SHEMA==1 && edrk.from_shema.bits.SBOR_SHEMA) - { - // защита от замыкания и одновременного нажатия - edrk.from_shema.bits.RAZBOR_SHEMA = 0; - edrk.from_shema.bits.SBOR_SHEMA = 0; - } - edrk.from_shema_filter.bits.RAZBOR_SHEMA = filter_digital_input( edrk.from_shema_filter.bits.RAZBOR_SHEMA, - &count_wait_filter[0], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.RAZBOR_SHEMA); - - - edrk.from_shema_filter.bits.SBOR_SHEMA = filter_digital_input( edrk.from_shema_filter.bits.SBOR_SHEMA, - &count_wait_filter[1], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.SBOR_SHEMA); + edrk.from_shema.bits.SBOR_SHEMA = FROM_BSU_SBOR_SHEMA; edrk.from_shema.bits.ZADA_DISPLAY = !FROM_BSU_ZADA_DISPLAY; - edrk.from_shema_filter.bits.ZADA_DISPLAY = filter_digital_input( edrk.from_shema_filter.bits.ZADA_DISPLAY, - &count_wait_filter[2], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.ZADA_DISPLAY); - edrk.from_shema.bits.SVU = !FROM_BSU_SVU; - edrk.from_shema_filter.bits.SVU = filter_digital_input( edrk.from_shema_filter.bits.SVU, - &count_wait_filter[3], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.SVU); - - // edrk.from_shema.bits.KNOPKA_AVARIA = FROM_ALL_KNOPKA_AVARIA; edrk.from_shema.bits.QTV_ON_OFF = !FROM_SHEMA_QTV_ON_OFF; - edrk.from_shema_filter.bits.QTV_ON_OFF = filter_digital_input( edrk.from_shema_filter.bits.QTV_ON_OFF, - &count_wait_filter[4], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.QTV_ON_OFF); - - - - /// фильтрация FROM_SHEMA_UMP_ON_OFF -// edrk.local_ump_on_off = !FROM_SHEMA_UMP_ON_OFF; -// -// if (edrk.local_ump_on_off) -// { -// if (edrk.local_ump_on_off_count>=TIME_FILTER_UMP_SIGNALS) -// edrk.from_shema.bits.UMP_ON_OFF = 1; -// else -// edrk.local_ump_on_off_count++; -// } -// else -// { -// if (edrk.local_ump_on_off_count==0) -// edrk.from_shema.bits.UMP_ON_OFF = 0; -// else -// edrk.local_ump_on_off_count--; -// } -// -// edrk.from_shema.bits.UMP_ON_OFF = !FROM_SHEMA_UMP_ON_OFF; - edrk.from_shema_filter.bits.UMP_ON_OFF = filter_digital_input( edrk.from_shema_filter.bits.UMP_ON_OFF, - &count_wait_filter[5], - TIME_FILTER_UMP_SIGNALS, - edrk.from_shema.bits.UMP_ON_OFF); - - - - - - - /// фильтрация FROM_SHEMA_READY_UMP -// edrk.local_ready_ump = !FROM_SHEMA_READY_UMP; -// -// if (edrk.local_ready_ump) -// { -// if (edrk.local_ready_ump_count>=TIME_FILTER_UMP_SIGNALS) -// edrk.from_shema.bits.READY_UMP = 1; -// else -// edrk.local_ready_ump_count++; -// } -// else -// { -// if (edrk.local_ready_ump_count==0) -// edrk.from_shema.bits.READY_UMP = 0; -// else -// edrk.local_ready_ump_count--; -// } -// - edrk.from_shema.bits.READY_UMP = !FROM_SHEMA_READY_UMP; - edrk.from_shema_filter.bits.READY_UMP = filter_digital_input( edrk.from_shema_filter.bits.READY_UMP, - &count_wait_filter[6], - TIME_FILTER_UMP_SIGNALS, - edrk.from_shema.bits.READY_UMP); - - - edrk.from_shema.bits.SVU_BLOCK_QTV = !FROM_SVU_BLOCK_QTV; - edrk.from_shema_filter.bits.SVU_BLOCK_QTV = filter_digital_input( edrk.from_shema_filter.bits.SVU_BLOCK_QTV, - &count_wait_filter[7], - TIME_FILTER_ALL_SIGNALS, - edrk.from_shema.bits.SVU_BLOCK_QTV); #endif } @@ -476,15 +719,10 @@ void update_output_edrk(void) // TO_ING_RESET_BLOCK_IZOL = !edrk.to_ing.bits.RESET_BLOCK_IZOL; TO_ING_SMALL_LAMPA_AVARIA = edrk.to_ing.bits.SMALL_LAMPA_AVARIA; - if (edrk.disable_rascepitel_work) - { - } - else - { - TO_ING_RASCEPITEL_OFF = !edrk.to_ing.bits.RASCEPITEL_OFF; - TO_ING_RASCEPITEL_ON = !edrk.to_ing.bits.RASCEPITEL_ON; - } + TO_ING_RASCEPITEL_OFF = !edrk.to_ing.bits.RASCEPITEL_OFF; + TO_ING_RASCEPITEL_ON = !edrk.to_ing.bits.RASCEPITEL_ON; + // ANOTHER PCH TO_SECOND_PCH_MASTER = edrk.to_second_pch.bits.MASTER; @@ -499,6 +737,26 @@ void update_output_edrk(void) //#endif + if (control_station.active_array_cmd[CONTROL_STATION_CMD_CROSS_STEND_AUTOMATS]) + { +#if (MODE_QTV_UPRAVLENIE==1) + TO_SHEMA_QTV_ON_OFF = !edrk.to_shema.bits.CROSS_QTV_ON_OFF; +#endif + TO_ING_LAMPA_ZARYAD = !edrk.to_shema.bits.CROSS_QTV_ON_OFF; + if (edrk.to_ing.bits.BLOCK_KEY_OFF || edrk.to_shema.bits.CROSS_QTV_ON_OFF) + TO_ING_BLOCK_KEY_OFF = 0; + else + TO_ING_BLOCK_KEY_OFF = 1; +// TO_ING_BLOCK_KEY_OFF = !edrk.to_shema.bits.CROSS_QTV_ON_OFF; + + + TO_SHEMA_ENABLE_QTV = !edrk.to_shema.bits.CROSS_QTV_ON_OFF; + + TO_SHEMA_UMP_ON_OFF = !edrk.to_shema.bits.CROSS_UMP_ON_OFF; + } + else + { + TO_ING_LAMPA_ZARYAD = !edrk.Status_Ready.bits.Batt; TO_ING_ZARYAD_ON = !edrk.to_ing.bits.ZARYAD_ON; TO_ING_BLOCK_KEY_OFF = !edrk.to_ing.bits.BLOCK_KEY_OFF; @@ -516,7 +774,7 @@ void update_output_edrk(void) TO_SHEMA_ENABLE_QTV = !edrk.to_shema.bits.ENABLE_QTV; TO_SHEMA_UMP_ON_OFF = !edrk.to_shema.bits.UMP_ON_OFF; - + } @@ -551,6 +809,45 @@ void update_output_edrk(void) /////////////////////////////////////////////// /////////////////////////////////////////////// +/////////////////////////////////////////////// +void nagrev_auto_on_off(void) +{ + if (edrk.temper_edrk.max_real_int_temper_waterTEMPER_NAGREF_OFF) + edrk.to_ing.bits.NAGREV_OFF = 1; + +} +/////////////////////////////////////////////// +#define TIME_WAIT_OFF_BLOCK_KEY 100 +void auto_block_key_on_off(void) +{ +static unsigned int count_err = TIME_WAIT_OFF_BLOCK_KEY; + + if (filter.iqU_1_long >= U_LEVEL_ON_BLOCK_KEY || filter.iqU_2_long >= U_LEVEL_ON_BLOCK_KEY || edrk.SumSbor) + { + edrk.Status_Ready.bits.Batt = 1; + edrk.to_ing.bits.BLOCK_KEY_OFF = 0; + count_err = 0; + } + + if (filter.iqU_1_long <= U_LEVEL_OFF_BLOCK_KEY && filter.iqU_2_long <= U_LEVEL_OFF_BLOCK_KEY && edrk.SumSbor==0) + { + if (pause_detect_error(&count_err,TIME_WAIT_OFF_BLOCK_KEY,1)) + { + edrk.to_ing.bits.BLOCK_KEY_OFF = 1; + edrk.Status_Ready.bits.Batt = 0; + } + } + else + count_err = 0; + + +} + + +/////////////////////////////////////////////// /////////////////////////////////////////////// void update_lamp_alarm(void) { @@ -591,11 +888,11 @@ void update_lamp_alarm(void) /////////////////////////////////////////////// /////////////////////////////////////////////// -#define TIME_WAIT_RELE_QTV_ON 30 //2 sec -#define TIME_WAIT_RELE_QTV_OFF 30 //2 sec +#define TIME_WAIT_RELE_QTV_ON 20 //2 sec +#define TIME_WAIT_RELE_QTV_OFF 20 //2 sec #define TIME_WAIT_ANSWER_QTV_ON TIME_WAIT_ERROR_QTV //150 //15 sec -#define TIME_WAIT_ANSWER_QTV_OFF 50 //4 sec +#define TIME_WAIT_ANSWER_QTV_OFF 40 //4 sec /////////////////////////////////////////////// int qtv_on_off(unsigned int flag) @@ -633,7 +930,7 @@ static int prev_error = 0; edrk.to_shema.bits.ENABLE_QTV = 1; edrk.to_shema.bits.QTV_OFF = 1; - if ((pause_detect_error(&time_wait_rele_on_qtv,TIME_WAIT_RELE_QTV_ON,1)==0) && edrk.from_shema_filter.bits.QTV_ON_OFF==0) + if ((pause_detect_error(&time_wait_rele_on_qtv,TIME_WAIT_RELE_QTV_ON,1)==0) && edrk.from_shema.bits.QTV_ON_OFF==0) { #if (MODE_QTV_UPRAVLENIE==2) edrk.to_shema.bits.QTV_ON = 1; @@ -649,7 +946,7 @@ static int prev_error = 0; if (pause_detect_error(&time_wait_answer_on_qtv,TIME_WAIT_ANSWER_QTV_ON,1)==0) { - if (edrk.from_shema_filter.bits.QTV_ON_OFF==1) + if (edrk.from_shema.bits.QTV_ON_OFF==1) QTV_Ok = 1; } @@ -657,7 +954,7 @@ static int prev_error = 0; { // была команда на вкл, но сухой контакт не пришел - if (edrk.from_shema_filter.bits.QTV_ON_OFF==0) + if (edrk.from_shema.bits.QTV_ON_OFF==0) { #if (WORK_ON_STEND_D) if (pause_detect_error(&count_err_on,TIME_WAIT_ANSWER_QTV_ON,1)) @@ -701,7 +998,7 @@ static int prev_error = 0; } else { - if (edrk.from_shema_filter.bits.QTV_ON_OFF==1) + if (edrk.from_shema.bits.QTV_ON_OFF==1) edrk.errors.e6.bits.QTV_ERROR_NOT_ANSWER |= 1; } @@ -729,9 +1026,7 @@ void detect_kvitir_from_all(void) static int prev_kvitir=0; - edrk.Kvitir = control_station.active_array_cmd[CONTROL_STATION_CMD_CHECKBACK] - || edrk.from_ing2.bits.KEY_KVITIR - || edrk.from_zadat4ik.bits.KVITIR; + edrk.Kvitir = control_station.active_array_cmd[CONTROL_STATION_CMD_CHECKBACK] || edrk.from_ing2.bits.KEY_KVITIR; /* if (edrk.RemouteFromRS) @@ -811,7 +1106,13 @@ unsigned int get_ready_1(void) /////////////////////////////////////////////// /////////////////////////////////////////////// /////////////////////////////////////////////// +#define MAX_U_PROC_SMALL 2.5 //1.4 +#define MAX_U_PROC 1.3 //1.11 //1.4 +#define MIN_U_PROC 0.8 //0.7 +#define ADD_U_MAX_GLOBAL 200.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge +#define ADD_U_MAX_GLOBAL_SMALL 500.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge +#define LEVEL_DETECT_U_SMALL 1000.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge void set_zadanie_u_charge(void) @@ -824,13 +1125,13 @@ void set_zadanie_u_charge(void) if (edrk.zadanie.ZadanieU_Charge<=100) { edrk.iqMIN_U_ZPT = _IQ(-50.0/NORMA_ACP); - edrk.iqMIN_U_IN = _IQ(-50.0/NORMA_ACP); + edrk.iqMIN_U_IN = _IQ(-50.0/NORMA_ACP); } else { edrk.iqMIN_U_ZPT = _IQ(edrk.zadanie.ZadanieU_Charge*MIN_U_PROC/NORMA_ACP); - edrk.iqMIN_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge*MIN_U_PROC/NORMA_ACP); + edrk.iqMIN_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge*MIN_U_PROC/NORMA_ACP); } @@ -845,14 +1146,13 @@ void set_zadanie_u_charge(void) edrk.iqMAX_U_ZPT_Predzaryad = _IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); edrk.iqMAX_U_ZPT_Global = edrk.iqMAX_U_ZPT_Predzaryad + _IQ(ADD_U_MAX_GLOBAL/NORMA_ACP); // +200V - if (edrk.iqMAX_U_ZPT_Global>U_D_MAX_ERROR_GLOBAL) - edrk.iqMAX_U_ZPT_Global = U_D_MAX_ERROR_GLOBAL; + if (edrk.iqMAX_U_ZPT_Global>U_D_MAX_ERROR_GLOBAL_2800) + edrk.iqMAX_U_ZPT_Global = U_D_MAX_ERROR_GLOBAL_2800; } - edrk.iqMAX_U_ZPT = edrk.iqMAX_U_ZPT_Global;//_IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); + edrk.iqMAX_U_ZPT = _IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); edrk.iqMAX_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); - edrk.zadanie.iq_set_break_level = _IQ(NOMINAL_U_BREAK_LEVEL/NORMA_ACP); } @@ -863,17 +1163,313 @@ void set_zadanie_u_charge(void) /////////////////////////////////////////////// /////////////////////////////////////////////// +void test_send_alarm_log(int alarm_cmd) +{ + static unsigned int points_alarm_log = 1000; + // static unsigned int nchannel_alarm_log = 30; + static int prev_alarm_cmd = 0; + static int local_alarm_cmd = 0; + + + + if (alarm_cmd && prev_alarm_cmd==0 && alarm_log_can.stage==0) + { +// i_led2_on(); + + alarm_log_can.post_points = COUNT_SAVE_LOG_OFF;//100; // количество поставарийныйх записей + alarm_log_can.oscills = logpar.count_log_params_fast_log;//nchannel_alarm_log; // количество колонок + + alarm_log_can.global_enable = 1; + + alarm_log_can.start_adr_temp = (int *)0xc0000; // адрес для временного размещения копии лога, лог скопируется из циклического буфера в этот развернувшись. + + // alarm_log_can.finish_adr_temp = (int *)0xa0000; // адрес для временного размещения копии лога, лог скопируется из циклического буфера в этот развернувшись. + + alarm_log_can.start_adr_real_logs = (int *)START_ADDRESS_LOG; // адрес начала реальных логов в циклическом буфере + alarm_log_can.finish_adr_real_log = (int *)logpar.real_finish_addres_mem; // конец логов в циклическом буфере + + alarm_log_can.current_adr_real_log = (int *)logpar.addres_mem; + + + alarm_log_can.temp_points = points_alarm_log; // реальный размер циклическго буфера в точках. + // alarm_log_can.real_points = 1000; // нужный кусок для копии, данное количество скопируется из циклического буфера во временный лог. + + alarm_log_can.step = 450; // mks + local_alarm_cmd = alarm_cmd; +// alarm_log_can.status_alarm = alarm_cmd;//cmd_alarm_log; // код аварии + alarm_log_can.start = 0x1; + alarm_log_can.stop = 0x1; + alarm_log_can.copy2temp = 0x1; + + + alarm_log_can.clear(&alarm_log_can); +// alarm_log_can.send(&alarm_log_can); + +// i_led2_off(); + } + else + local_alarm_cmd = 0; + + alarm_log_can.status_alarm = local_alarm_cmd;//cmd_alarm_log; // код аварии + alarm_log_can.send(&alarm_log_can); + + if (alarm_log_can.stage) + { + i_led2_on_off(1); + } + else + { + i_led2_on_off(0); + } + + prev_alarm_cmd = alarm_cmd; + +} +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + +void run_edrk(void) +{ + // static unsigned int prev_SumSbor = 0, prev_AllStart = 0, prev_VozbudOnOff = 0, prev_SBOR_SHEMA_VPU = 0,prev_SBOR_SHEMA_RS=0, prev_SBOR_SHEMA_DISPLAY = 0; + + int current_active_control, ff =0; + static unsigned int filter_count_error_control_station_select_active = 0; + static int flag_enable_update_mpu = 1; + static unsigned int external_cmd_alarm_log = 0; + //static int ccc[40] = {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0}; + static int ccc[40] = {0,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1}; + static int prev_enable_pwm_test_lines=0; + + + if (f.Prepare || f.terminal_prepare) { + project.clear_errors_all_plates(); + } + + // slow_vector_update(); + + read_plane_errors(); + +// if (flag_enable_update_hmi) +// update_tables_HMI(); +// if (flag_enable_update_mpu) +// update_modbus_table(); +// modbusNetworkSharing(1); +// get_command_HMI(); + +// return; + +// i_led1_on_off(1); + if (edrk.flag_disable_pult_485==0) + modbusNetworkSharing(0); +// i_led1_on_off(0); + + if (!(detect_pause_milisec(100,&old_time_edrk2))) + return; + + if (ccc[0]) return; + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + // Дальше код запускается раз в 100 мсек. + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////// + + + // external_cmd_alarm_log = modbus_table_can_in[11].all; + // test_send_alarm_log(external_cmd_alarm_log); + + // modbusNetworkSharing(0); + + // i_led2_on_off(1); + + if (ccc[1]) modbusNetworkSharingCAN(); + + #if (ENABLE_CAN_SEND_TO_UKSS_FROM_MAIN) + // пишем в задатчик + if (ccc[2]) update_ukss_can(TIME_PAUSE_MODBUS_CAN_ZADATCHIK_VPU); + if (ccc[3]) update_ukss_setup(TIME_PAUSE_MODBUS_CAN_UKSS_SETUP); + #endif + + #if (ENABLE_CAN_SEND_TO_ANOTHER_BSU_FROM_MAIN) +// пишем в задатчик + if (ccc[4]) update_bsu_can(TIME_PAUSE_MODBUS_CAN_BS2BS); + #endif + + if (ccc[5]) check_all_power_limits(); + + if (ccc[6]) calc_p_water_edrk(); + if (ccc[7]) calc_temper_edrk(); + if (ccc[8]) calc_temper_acdrive(); + + // читаем цифр входы + if (ccc[9]) update_input_edrk(); + + if (ccc[10]) detect_kvitir_from_all(); + + if (ccc[11]) detect_error_all(); + + if (ccc[12]) calc_limit_overheat(); + + if (ccc[13]) calc_RMS_values_main(); + + if (ccc[14]) update_lamp_alarm(); + + if (ccc[15]) set_zadanie_u_charge(); + + if (ccc[16]) reinit_protect_I_and_U_settings(); + + if (ccc[17]) nagrev_auto_on_off(); + + if (ccc[18]) auto_block_key_on_off(); + + edrk.f_rotor_hz = _IQtoF(edrk.iq_f_rotor_hz) * NORMA_FROTOR; + edrk.oborots = fast_round(edrk.f_rotor_hz*60.0); + edrk.power_kw = _IQtoF(filter.PowerScalar) * NORMA_ACP * NORMA_ACP / 1000.0; + edrk.Status_Ready.bits.ready1 = get_ready_1(); + + if (ccc[19]) pump_control(); + + + if (control_station_select_active()) + { + + if (filter_count_error_control_station_select_active<30) + filter_count_error_control_station_select_active++; + else + edrk.errors.e7.bits.NOT_VALID_CONTROL_STATION |= 1; + } + else + filter_count_error_control_station_select_active = 0; + + current_active_control = get_current_station_control(); + + if (current_active_control=max_errors) + return 1; + else + (*counter)++; + + return 0; + } + + if (err==0) + { + if ((*counter)==0) + return 0; + else + (*counter)--; + + return 0; + } + return 0; +} + +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +#define MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS 30//20 +#define MAX_WAIT_READY1_DETECT_ALIVE_ANOTHER_BS 100 +#define MAX_WAIT_READY2_DETECT_ALIVE_ANOTHER_BS 70 //30 // должен быть больше чем MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +void detect_alive_another_bs(void) +{ + // static unsigned int count_wait_ready = 0; + static unsigned int prev_another_bs_maybe_on = 0; + static unsigned int prev_another_bs_maybe_on_after_ready1 = 0; + + + edrk.ms.err_signals.alive_can_to_another_bs = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,ANOTHER_BSU1_CAN_DEVICE)]; + edrk.ms.err_signals.alive_opt_bus_read = !project.cds_tk[3].optical_data_in.ready; + edrk.ms.err_signals.alive_opt_bus_write = !project.cds_tk[3].optical_data_out.ready; + edrk.ms.err_signals.alive_sync_line = !sync_data.global_flag_sync_1_2; + edrk.ms.err_signals.alive_sync_line_local = !sync_data.local_flag_sync_1_2; +// edrk.ms.err_signals.input_alarm_another_bs = edrk.from_ing1.bits. + // тут пока отключен канал. + // edrk.ms.err_signals.fast_optical_alarm = 0;//!project.cds_tk[3].read.sbus.status_tk_40pin.bit.tk5_ack; + edrk.ms.err_signals.another_rascepitel = edrk.from_second_pch.bits.RASCEPITEL; + + if (edrk.ms.err_signals.alive_can_to_another_bs + && (edrk.ms.err_signals.alive_opt_bus_read + || edrk.ms.err_signals.alive_opt_bus_write) + && edrk.ms.err_signals.alive_sync_line +// && edrk.ms.err_signals.fast_optical_alarm + ) + { + edrk.ms.another_bs_maybe_off = 1; + edrk.ms.another_bs_maybe_on = 0; + } + else + { + edrk.ms.another_bs_maybe_off = 0; + edrk.ms.another_bs_maybe_on = 1; + } + + // если связь восстановилась, то опять ждем некоторое время пока запустятся все остальные каналы связи. + if (prev_another_bs_maybe_on!=edrk.ms.another_bs_maybe_on && edrk.ms.another_bs_maybe_on) + { +// edrk.ms.count_time_wait_ready1 = 0; + edrk.ms.count_time_wait_ready2 = 0; + prev_another_bs_maybe_on_after_ready1 = 0; + clear_errors_master_slave(); + } + + + // + // выставляем флаг только через время MAX_WAIT_READY_DETECT_ALIVE_ANOTHER_BS + // + edrk.ms.ready1 = filter_err_count(&edrk.ms.count_time_wait_ready1, + MAX_WAIT_READY1_DETECT_ALIVE_ANOTHER_BS, + 1, + 0); + + if (edrk.Status_Ready.bits.ready5) + { + edrk.ms.ready2 = filter_err_count(&edrk.ms.count_time_wait_ready2, + MAX_WAIT_READY2_DETECT_ALIVE_ANOTHER_BS, + 1, + 0); + } + else + { + edrk.ms.count_time_wait_ready2 = 0; + edrk.ms.ready2 = 0; + } + +// edrk.ms.ready2 = edrk.Status_Ready.bits.ready5 && filter_err_count(&edrk.ms.count_time_wait_ready2, +// MAX_WAIT_READY2_DETECT_ALIVE_ANOTHER_BS, +// 1, +// 0); + + + + + + prev_another_bs_maybe_on = edrk.ms.another_bs_maybe_on; + + + // ждем пока пройдет некоторое время + if (edrk.ms.ready1==0) + { + + + edrk.ms.status = 1; + return; + } + + + // если связь была после edrk.ms.ready1==1, но вся пропала, даем ошибку + if (prev_another_bs_maybe_on_after_ready1!=edrk.ms.another_bs_maybe_on && edrk.ms.another_bs_maybe_on==0) + { + edrk.errors.e4.bits.ANOTHER_BS_POWER_OFF |= 1; + } + prev_another_bs_maybe_on_after_ready1 = edrk.ms.another_bs_maybe_on; + + + + + edrk.ms.err_lock_signals.alive_can_to_another_bs |= filter_err_count(&edrk.ms.errors_count.alive_can_to_another_bs, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.alive_can_to_another_bs, + 0); + + edrk.ms.err_lock_signals.alive_opt_bus_read |= filter_err_count(&edrk.ms.errors_count.alive_opt_bus_read, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.alive_opt_bus_read, + 0); + edrk.ms.err_lock_signals.alive_opt_bus_write |= filter_err_count(&edrk.ms.errors_count.alive_opt_bus_write, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.alive_opt_bus_write, + 0); + + edrk.ms.err_lock_signals.alive_sync_line = filter_err_count(&edrk.ms.errors_count.alive_sync_line, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.alive_sync_line, + 0); + + edrk.ms.err_lock_signals.alive_sync_line_local = filter_err_count(&edrk.ms.errors_count.alive_sync_line_local, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.alive_sync_line_local, + 0); + + edrk.ms.err_lock_signals.fast_optical_alarm |= filter_err_count(&edrk.ms.errors_count.fast_optical_alarm, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.fast_optical_alarm, + 0); + + edrk.ms.err_lock_signals.input_alarm_another_bs |= filter_err_count(&edrk.ms.errors_count.input_alarm_another_bs, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.input_alarm_another_bs, + 0); + + edrk.ms.err_lock_signals.another_rascepitel |= filter_err_count(&edrk.ms.errors_count.another_rascepitel, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.another_rascepitel, + 0); + + edrk.ms.err_lock_signals.input_master_slave |= filter_err_count(&edrk.ms.errors_count.input_master_slave, + MAX_ERRORS_DETECT_ALIVE_ANOTHER_BS, + edrk.ms.err_signals.input_master_slave, + 0); + + + if (edrk.ms.err_signals.alive_can_to_another_bs + && (edrk.ms.err_signals.alive_opt_bus_read + || edrk.ms.err_signals.alive_opt_bus_write) + && edrk.ms.err_signals.alive_sync_line + // && edrk.ms.err_signals.fast_optical_alarm + // && edrk.ms.err_signals.input_alarm_another_bs && +// && edrk.ms.err_signals.another_rascepitel == 0 +// && edrk.ms.err_signals.input_master_slave + ) + { + + if (edrk.ms.err_signals.another_rascepitel) + edrk.errors.e7.bits.ANOTHER_RASCEPITEL_ON |= 1; + +// edrk.ms.another_bs_maybe_off = 1; +// edrk.ms.another_bs_maybe_on = 0; + + edrk.warnings.e4.bits.ANOTHER_BS_POWER_OFF = 1; + // edrk.warnings.e4.bits.FAST_OPTICAL_ALARM = 1; + edrk.warnings.e7.bits.MASTER_SLAVE_SYNC = 1; + edrk.warnings.e7.bits.READ_OPTBUS = edrk.ms.err_signals.alive_opt_bus_read; + edrk.warnings.e7.bits.WRITE_OPTBUS = edrk.ms.err_signals.alive_opt_bus_write; + edrk.warnings.e7.bits.CAN2CAN_BS = 1; + + edrk.ms.status = 2; + + } + else + { + + edrk.warnings.e4.bits.ANOTHER_BS_POWER_OFF = 0; + +// + if (edrk.ms.err_lock_signals.alive_can_to_another_bs) + edrk.errors.e7.bits.CAN2CAN_BS |= 1; + else + edrk.warnings.e7.bits.CAN2CAN_BS = 0; +// + if (edrk.ms.err_lock_signals.alive_opt_bus_read) + edrk.errors.e7.bits.READ_OPTBUS |= 1; + else + edrk.warnings.e7.bits.READ_OPTBUS = 0; +// + if (edrk.ms.err_lock_signals.alive_opt_bus_write) + edrk.errors.e7.bits.WRITE_OPTBUS |= 1; + else + edrk.warnings.e7.bits.WRITE_OPTBUS = 0; +// + if (edrk.ms.err_lock_signals.alive_sync_line) + edrk.warnings.e7.bits.MASTER_SLAVE_SYNC = 1; + else + edrk.warnings.e7.bits.MASTER_SLAVE_SYNC = 0; +// +// if (edrk.ms.err_lock_signals.fast_optical_alarm) +// edrk.errors.e4.bits.FAST_OPTICAL_ALARM |= 1; +// else +// edrk.warnings.e4.bits.FAST_OPTICAL_ALARM = 0; + + + // edrk.ms.another_bs_maybe_on = 1; + // edrk.ms.another_bs_maybe_off = 0; + + if (edrk.ms.err_signals.alive_can_to_another_bs + || edrk.ms.err_signals.alive_opt_bus_read + || edrk.ms.err_signals.alive_opt_bus_write + || edrk.ms.err_signals.alive_sync_line + || edrk.ms.err_signals.fast_optical_alarm + ) + edrk.ms.status = 3; + else + edrk.ms.status = 4; + + } + + + + + +} + +////////////////////////////////////////////////////////// +unsigned int wait_synhro_optical_bus(void) +{ + static unsigned int cmd = 0; + static unsigned int count_wait_synhro = 0; + + +// +// switch(cmd) +// { +// 0 : if (optical_read_data.data.cmd.bit.wdog_tick == 0) +// cmd = 1; +// +// break; +// +// 1 : optical_write_data.data.cmd.bit.wdog_tick = 1; +// break; +// +// +// default: break +// } + + + + return 0; +} + +////////////////////////////////////////////////////////// +void clear_wait_synhro_optical_bus(void) +{ + + // optical_read_data.data.cmd.bit.wdog_tick = 0; + // optical_write_data.data.cmd.bit.wdog_tick = 0; + +} +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +#define MAX_COUNT_TRY_MASTER_BS1 200//40 //15 //5 +#define MAX_COUNT_TRY_MASTER_BS2 100//40 //15 //40 //20 +#define MAX_COUNT_WAIT_ANSWER_CONFIRM_MODE 20 + +#define MAX_COUNT_WAIT_SLAVE_TRY_MASTER 100 + + +#define SIZE_LOG_MASTER_SLAVE_STATUS 50 +#pragma DATA_SECTION(buf_log_master_slave_status,".slow_vars"); +unsigned int buf_log_master_slave_status[SIZE_LOG_MASTER_SLAVE_STATUS] = {0}; +//AUTO_MASTER_SLAVE_DATA buf2[SIZE_BUF1] = {0}; +//AUTO_MASTER_SLAVE_DATA buf3[SIZE_BUF1] = {0}; +//OPTICAL_BUS_DATA_LOW_CMD buf4[SIZE_BUF1] = {0}; +//OPTICAL_BUS_DATA_LOW_CMD buf5[SIZE_BUF1] = {0}; + + +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// + +void auto_select_master_slave(void) +{ + static unsigned int count_try_master = 0; + static unsigned int count_wait_answer_confirm_mode = 0; + static unsigned int count_wait_slave_try_master = 0; + unsigned int err_confirm_mode = 0; // ошибка подтверждения режима другим ПЧ + static unsigned int c_buf_log_master_slave_status = 0, prev_status = 0; + + + +// logs master_slave_status + if (edrk.auto_master_slave.status != prev_status) + { + c_buf_log_master_slave_status++; + if (c_buf_log_master_slave_status>=SIZE_LOG_MASTER_SLAVE_STATUS) + c_buf_log_master_slave_status = 0; + buf_log_master_slave_status[c_buf_log_master_slave_status] = edrk.auto_master_slave.status; + } + prev_status = edrk.auto_master_slave.status; +//end logs master_slave_status + + if (edrk.ms.ready2==0 && edrk.errors.e7.bits.AUTO_SET_MASTER==0) + { + edrk.auto_master_slave.remoute.all = 0; + edrk.auto_master_slave.local.all = 0; + edrk.auto_master_slave.prev_remoute.all = edrk.auto_master_slave.remoute.all; + edrk.auto_master_slave.prev_local.all = edrk.auto_master_slave.local.all; + + edrk.auto_master_slave.status = 1; + +// if (prev_ready!=edrk.ms.ready2) +// for (c_buf=0;c_buf=SIZE_BUF1) +// c_buf = 0; +// +// buf1[c_buf] = edrk.auto_master_slave.status; +// buf2[c_buf].all = edrk.auto_master_slave.local.all; +// buf3[c_buf].all = edrk.auto_master_slave.remoute.all; +// buf4[c_buf].all = optical_read_data.data.cmd.all; +// buf5[c_buf].all = optical_write_data.data.cmd.all; +// + + // сбросим счетчик времени перехода на мастер + if (edrk.auto_master_slave.local.bits.try_master==0 || + (edrk.auto_master_slave.prev_local.bits.try_master != edrk.auto_master_slave.local.bits.try_master && edrk.auto_master_slave.local.bits.try_master==1)) + count_try_master = 0; + + // если шина OPTICAL_BUS сдохла, выходим + if (edrk.errors.e7.bits.WRITE_OPTBUS==1 || edrk.errors.e7.bits.READ_OPTBUS==1 || + edrk.warnings.e7.bits.WRITE_OPTBUS==1 || edrk.warnings.e7.bits.READ_OPTBUS==1) + { + + if (edrk.errors.e7.bits.WRITE_OPTBUS==1 || edrk.errors.e7.bits.READ_OPTBUS==1) + { + // шина не работает, и тот ПЧ включен + // значит что-то случилось - выключаемся + + edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; + + edrk.auto_master_slave.remoute.bits.nothing = 1; + edrk.auto_master_slave.remoute.bits.master = 0; + edrk.auto_master_slave.remoute.bits.slave = 0; + edrk.auto_master_slave.remoute.bits.try_master = 0; + edrk.auto_master_slave.remoute.bits.try_slave = 0; + + + edrk.auto_master_slave.local.bits.master = 0; + edrk.auto_master_slave.local.bits.slave = 0; + edrk.auto_master_slave.local.bits.try_master = 0; + edrk.auto_master_slave.local.bits.try_slave = 0; + edrk.auto_master_slave.local.bits.nothing = 1; + + edrk.auto_master_slave.status = 10; + } + else + { + // шина не работает, и тот ПЧ выключен + // значит мы сразу мастер + edrk.warnings.e7.bits.AUTO_SET_MASTER = 1; + + edrk.auto_master_slave.remoute.bits.nothing = 1; + edrk.auto_master_slave.remoute.bits.master = 0; + edrk.auto_master_slave.remoute.bits.slave = 0; + edrk.auto_master_slave.remoute.bits.try_master = 0; + edrk.auto_master_slave.remoute.bits.try_slave = 0; + + + + edrk.auto_master_slave.local.bits.master = 1; + edrk.auto_master_slave.local.bits.slave = 0; + edrk.auto_master_slave.local.bits.try_master = 0; + edrk.auto_master_slave.local.bits.try_slave = 0; + edrk.auto_master_slave.local.bits.nothing = 1; + + edrk.auto_master_slave.status = 2; + } + + edrk.auto_master_slave.remoute.bits.sync_line_detect = 0; + edrk.auto_master_slave.remoute.bits.bus_off = 1; + edrk.auto_master_slave.remoute.bits.sync1_2 = 0; + + } + else + { + edrk.warnings.e7.bits.AUTO_SET_MASTER = 0; + + edrk.auto_master_slave.remoute.bits.bus_off = 0; + + // синхронизируем свои программы через OPTICAL_BUS + + if (wait_synhro_optical_bus()==1) + { + + edrk.auto_master_slave.status = 50; // wait synhro + + + } + else + { + + + edrk.auto_master_slave.remoute.bits.master = optical_read_data.data.cmd.bit.master; + edrk.auto_master_slave.remoute.bits.slave = optical_read_data.data.cmd.bit.slave; + edrk.auto_master_slave.remoute.bits.try_master = optical_read_data.data.cmd.bit.maybe_master; + edrk.auto_master_slave.remoute.bits.sync1_2 = optical_read_data.data.cmd.bit.sync_1_2; + edrk.auto_master_slave.remoute.bits.sync_line_detect = optical_read_data.data.cmd.bit.sync_line_detect; + edrk.auto_master_slave.remoute.bits.tick = optical_read_data.data.cmd.bit.wdog_tick; + + if (optical_read_data.data.cmd.bit.master==0 && optical_read_data.data.cmd.bit.slave==0) + edrk.auto_master_slave.remoute.bits.nothing = 1; + + + ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // 1 + + // тот ПЧ уже мастер + if (edrk.auto_master_slave.remoute.bits.master) + { + + // и этот ПЧ мастер почему-то? + if (edrk.auto_master_slave.local.bits.master) + { + edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; + edrk.auto_master_slave.status = 3; + } + else + { + // этот ПЧ еще не определился, поэтому переход на slave + if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0) + { + // edrk.auto_master_slave.local.bits.try_slave = 1; + // стали slave + edrk.auto_master_slave.local.bits.slave = 1; + // сняли свой запрос на мастера если он был + edrk.auto_master_slave.local.bits.try_master = 0; + edrk.auto_master_slave.status = 4; + } + else + { + edrk.auto_master_slave.status = 21; + } + } + } + else + ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // 2 + // тот ПЧ уже slave + + if (edrk.auto_master_slave.remoute.bits.slave) + { + + // и этот ПЧ slave почему-то? + if (edrk.auto_master_slave.local.bits.slave) + { + + // был переход из мастер в slave + if (edrk.auto_master_slave.prev_remoute.bits.slave==0) + { + if (edrk.Go) + { + // запущен ШИМ + edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; + edrk.auto_master_slave.status = 5; + } + else + { + // пробуем перехватить master + edrk.auto_master_slave.local.bits.try_master = 1; + edrk.auto_master_slave.status = 6; + } + } + else + { + edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; + edrk.auto_master_slave.status = 7; + } + + } + else + { + + // этот ПЧ еще не определился, поэтому запрашивает на master + if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.try_master==0) + { + if (edrk.flag_second_PCH==0) + edrk.auto_master_slave.local.bits.try_master = 1; + if (edrk.flag_second_PCH==1) + edrk.auto_master_slave.local.bits.try_master = 1; + + edrk.auto_master_slave.status = 8; + // edrk.auto_master_slave.local.bits.slave = 1; + } + else + // этот ПЧ уже в запросе на мастер, а тот ПЧ подтвердил в slave что он не против. + if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.try_master==1) + { + // стали мастером + edrk.auto_master_slave.local.bits.master = 1; + edrk.auto_master_slave.local.bits.try_master = 0; + edrk.auto_master_slave.status = 9; + // edrk.auto_master_slave.local.bits.slave = 1; + } + else + { + edrk.auto_master_slave.status = 22; + } + + } + } + else + ////////////////////////////////////////////////// + ////////////////////////////////////////////////// + // 3 + // тот ПЧ запрашивает переход на мастер + + if (edrk.auto_master_slave.remoute.bits.master==0 + && edrk.auto_master_slave.remoute.bits.slave==0 + && edrk.auto_master_slave.remoute.bits.try_master) + { + // а этот ПЧ slave + if (edrk.auto_master_slave.local.bits.slave) + { + // вроде не норм, остаемся slave + // тут надо подождать некотрое время, пока тот ПЧ не поймет что мы стали слейвом и перейдет из try_master в мастер + if (count_wait_slave_try_master=40) - level_go_main = 0; + } @@ -1670,6 +3260,242 @@ void edrk_go_main(void) ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// + +void init_ramp_all_zadanie(void) +{ + _iq rampafloat; + +// rmp_fzad + edrk.zadanie.rmp_fzad.RampLowLimit = _IQ(-MAX_ZADANIE_F/NORMA_FROTOR); //0 + edrk.zadanie.rmp_fzad.RampHighLimit = _IQ(MAX_ZADANIE_F/NORMA_FROTOR); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_F)); + edrk.zadanie.rmp_fzad.RampPlus = rampafloat; + edrk.zadanie.rmp_fzad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_fzad.DesiredInput = 0; + edrk.zadanie.rmp_fzad.Out = 0; + +// rmp_oborots_hz + edrk.zadanie.rmp_oborots_zad_hz.RampLowLimit = _IQ(MIN_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); //0 + edrk.zadanie.rmp_oborots_zad_hz.RampHighLimit = _IQ(MAX_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_OBOROTS_ROTOR)); + edrk.zadanie.rmp_oborots_zad_hz.RampPlus = rampafloat; + edrk.zadanie.rmp_oborots_zad_hz.RampMinus = -rampafloat; + + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + edrk.zadanie.rmp_oborots_zad_hz.Out = 0; + + +// + edrk.zadanie.rmp_Izad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_Izad.RampHighLimit = _IQ(MAX_ZADANIE_I_M/NORMA_ACP); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_I_M)); + edrk.zadanie.rmp_Izad.RampPlus = rampafloat; + edrk.zadanie.rmp_Izad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_Izad.DesiredInput = 0; + edrk.zadanie.rmp_Izad.Out = 0; + +// + edrk.zadanie.rmp_ZadanieU_Charge.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_ZadanieU_Charge.RampHighLimit = _IQ(MAX_ZADANIE_U_CHARGE/NORMA_ACP); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_U_CHARGE)); + edrk.zadanie.rmp_ZadanieU_Charge.RampPlus = rampafloat; + edrk.zadanie.rmp_ZadanieU_Charge.RampMinus = -rampafloat; + + edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = 0; + edrk.zadanie.rmp_ZadanieU_Charge.Out = 0; + + + +// + edrk.zadanie.rmp_k_u_disbalance.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_k_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_K_U_DISBALANCE); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_K_U_DISBALANCE)); + edrk.zadanie.rmp_k_u_disbalance.RampPlus = rampafloat; + edrk.zadanie.rmp_k_u_disbalance.RampMinus = -rampafloat; + + edrk.zadanie.rmp_k_u_disbalance.DesiredInput = 0; + edrk.zadanie.rmp_k_u_disbalance.Out = 0; + + +// + edrk.zadanie.rmp_kplus_u_disbalance.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_kplus_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_KPLUS_U_DISBALANCE); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_KPLUS_U_DISBALANCE)); + edrk.zadanie.rmp_kplus_u_disbalance.RampPlus = rampafloat; + edrk.zadanie.rmp_kplus_u_disbalance.RampMinus = -rampafloat; + + edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = 0; + edrk.zadanie.rmp_kplus_u_disbalance.Out = 0; + + + +// + edrk.zadanie.rmp_kzad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_kzad.RampHighLimit = _IQ(MAX_ZADANIE_K_M); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_K_M)); + edrk.zadanie.rmp_kzad.RampPlus = rampafloat; + edrk.zadanie.rmp_kzad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.Out = 0; + + + + + +// + edrk.zadanie.rmp_powers_zad.RampLowLimit = _IQ(MIN_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); //0 + edrk.zadanie.rmp_powers_zad.RampHighLimit = _IQ(MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_POWER)); + edrk.zadanie.rmp_powers_zad.RampPlus = rampafloat; + edrk.zadanie.rmp_powers_zad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_powers_zad.Out = 0; + +// + edrk.zadanie.rmp_limit_powers_zad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_limit_powers_zad.RampHighLimit = _IQ(MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); + + rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_POWER)); + edrk.zadanie.rmp_limit_powers_zad.RampPlus = rampafloat; + edrk.zadanie.rmp_limit_powers_zad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_limit_powers_zad.Out = 0; + +// + + +} + +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////// +#pragma CODE_SECTION(ramp_all_zadanie,".fast_run"); +void ramp_all_zadanie(int flag_set_zero) +{ + ////////////////////////////////////////////// + if (flag_set_zero==0) + edrk.zadanie.rmp_Izad.DesiredInput = edrk.zadanie.iq_Izad; + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_Izad.DesiredInput = 0; + edrk.zadanie.rmp_Izad.Out = 0; + } + else + edrk.zadanie.rmp_Izad.DesiredInput = 0; + + edrk.zadanie.rmp_Izad.calc(&edrk.zadanie.rmp_Izad); + edrk.zadanie.iq_Izad_rmp = edrk.zadanie.rmp_Izad.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = edrk.zadanie.iq_ZadanieU_Charge; + edrk.zadanie.rmp_ZadanieU_Charge.calc(&edrk.zadanie.rmp_ZadanieU_Charge); + edrk.zadanie.iq_ZadanieU_Charge_rmp = edrk.zadanie.rmp_ZadanieU_Charge.Out; + ////////////////////////////////////////////// + if (flag_set_zero==0) + edrk.zadanie.rmp_fzad.DesiredInput = edrk.zadanie.iq_fzad; + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_fzad.DesiredInput = 0; + edrk.zadanie.rmp_fzad.Out = 0; + } + else + edrk.zadanie.rmp_fzad.DesiredInput = 0; + + edrk.zadanie.rmp_fzad.calc(&edrk.zadanie.rmp_fzad); + edrk.zadanie.iq_fzad_rmp = edrk.zadanie.rmp_fzad.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_k_u_disbalance.DesiredInput = edrk.zadanie.iq_k_u_disbalance; + edrk.zadanie.rmp_k_u_disbalance.calc(&edrk.zadanie.rmp_k_u_disbalance); + edrk.zadanie.iq_k_u_disbalance_rmp = edrk.zadanie.rmp_k_u_disbalance.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = edrk.zadanie.iq_kplus_u_disbalance; + edrk.zadanie.rmp_kplus_u_disbalance.calc(&edrk.zadanie.rmp_kplus_u_disbalance); + edrk.zadanie.iq_kplus_u_disbalance_rmp = edrk.zadanie.rmp_kplus_u_disbalance.Out; + ////////////////////////////////////////////// + if (flag_set_zero==0) + edrk.zadanie.rmp_kzad.DesiredInput = edrk.zadanie.iq_kzad; + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.Out = 0; + } + else + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.calc(&edrk.zadanie.rmp_kzad); + edrk.zadanie.iq_kzad_rmp = edrk.zadanie.rmp_kzad.Out; + ////////////////////////////////////////////// + if (flag_set_zero==0) + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = edrk.zadanie.iq_oborots_zad_hz; + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + edrk.zadanie.rmp_oborots_zad_hz.Out = 0; + } + else + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + + edrk.zadanie.rmp_oborots_zad_hz.calc(&edrk.zadanie.rmp_oborots_zad_hz); + edrk.zadanie.iq_oborots_zad_hz_rmp = edrk.zadanie.rmp_oborots_zad_hz.Out; + + ////////////////////////////////////////////// + if (flag_set_zero==0) + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad; + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_limit_powers_zad.Out = 0; + } + else + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + + edrk.zadanie.rmp_limit_powers_zad.calc(&edrk.zadanie.rmp_limit_powers_zad); + edrk.zadanie.iq_limit_power_zad_rmp = edrk.zadanie.rmp_limit_powers_zad.Out; + + + + ////////////////////////////////////////////// + if (flag_set_zero==0) + { + if (edrk.zadanie.iq_power_zad>edrk.zadanie.iq_limit_power_zad_rmp) + edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad_rmp; + else + edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_power_zad; + } + else + if (flag_set_zero==2) + { + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_powers_zad.Out = 0; + } + else + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + + edrk.zadanie.rmp_powers_zad.calc(&edrk.zadanie.rmp_powers_zad); + edrk.zadanie.iq_power_zad_rmp = edrk.zadanie.rmp_powers_zad.Out; + + + + +} + +////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// //#pragma CODE_SECTION(get_start_ged_from_zadanie,".fast_run"); @@ -1688,22 +3514,11 @@ int get_start_ged_from_zadanie(void) // scalar oborots if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_OBOROTS) { - if (edrk.MasterSlave==MODE_SLAVE) - { - if (edrk.zadanie.iq_Izad_rmp!=0 - && edrk.zadanie.iq_limit_power_zad_rmp!=0) - return 1; - else - return 0; - } + if (edrk.zadanie.iq_oborots_zad_hz_rmp!=0 && edrk.zadanie.iq_Izad_rmp!=0 + && edrk.zadanie.iq_power_zad_rmp!=0 && edrk.zadanie.iq_limit_power_zad_rmp!=0) + return 1; else - { - if (edrk.zadanie.iq_oborots_zad_hz_rmp!=0 && edrk.zadanie.iq_Izad_rmp!=0 - && edrk.zadanie.iq_power_zad_rmp!=0 && edrk.zadanie.iq_limit_power_zad_rmp!=0) - return 1; - else - return 0; - } + return 0; } else // scalar power @@ -1743,18 +3558,134 @@ int get_start_ged_from_zadanie(void) } ////////////////////////////////////////////////////////// +void UpdateTableSecondBS(void) +{ + int cmd; + int i,k; + + Unites2SecondBS[0]++; + + Unites2SecondBS[1] = global_time.miliseconds; + Unites2SecondBS[2] = edrk.flag_second_PCH; + Unites2SecondBS[3] = (edrk.to_shema.bits.QTV_ON_OFF << 1) | (edrk.to_shema.bits.UMP_ON_OFF); + Unites2SecondBS[4] = edrk.SumSbor; + Unites2SecondBS[5] = edrk.int_koef_ogran_power; + Unites2SecondBS[6] = (int)edrk.power_kw; + Unites2SecondBS[7] = (int)edrk.active_post_upravl; + Unites2SecondBS[8] = (int)edrk.power_kw; + Unites2SecondBS[9] = edrk.Status_Ready.bits.ready1; + Unites2SecondBS[10] = edrk.Status_Ready.bits.ready_final; + Unites2SecondBS[11] = edrk.MasterSlave; + + Unites2SecondBS[12] = _IQtoF(vect_control.iqId_min) * NORMA_ACP; + + + for (i=0;i=minimal_detect_u || + if ( (filter.iqU_1_long>=minimal_detect_u || filter.iqU_2_long>=minimal_detect_u || - (prev_uzpt1-filter.iqU_1_long)>=delta_u || + prev_uzpt1-filter.iqU_1_long)>=delta_u || (prev_uzpt2-filter.iqU_2_long)>=delta_u ) { // напряжение еще падает @@ -1890,847 +3867,29 @@ void auto_detect_zero_u_zpt(void) } -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -// для инита переменных перед сбором схемы -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -void reinit_before_sbor(void) + +#pragma CODE_SECTION(calc_rms,".fast_run"); +_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal) { - static unsigned int prev_sbor = 0; + static _iq pi_pwm = _IQ(PI*NORMA_FROTOR/(FREQ_PWM/5.0)); + _iq cosw, sinw, wdt, y2, z1, z2, z3, y; - if (edrk.SumSbor && edrk.SumSbor!=prev_sbor ) - { - init_50hz_input_net50hz(); - init_all_limit_koeffs(); - } - prev_sbor = edrk.SumSbor; -} + wdt = _IQmpy(pi_pwm,freq_signal); + sinw = _IQsinPU(wdt); + cosw = _IQcosPU(wdt); -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// -#define MINIMAL_POWER_TO_DISPLAY 10 // минимум 10 кВт - -#define PAUSE_COMUNICATION 100 -void run_edrk(void) -{ - // static unsigned int prev_SumSbor = 0, prev_AllStart = 0, prev_VozbudOnOff = 0, prev_SBOR_SHEMA_VPU = 0,prev_SBOR_SHEMA_RS=0, prev_SBOR_SHEMA_DISPLAY = 0; - - int ff =0; - static unsigned int filter_count_error_control_station_select_active = 0; - static int flag_enable_update_mpu = 1; - static unsigned int external_cmd_alarm_log = 0; - static int prev_enable_pwm_test_lines=0; - int power_kw_full = 0; - - float max_oborots, local_oborots, local_power, max_power; - static float float_oborots = 0, koef_p1 = 0, koef_p2 = 0, koef_p3 = 27.391304347826086956521739130435; - - static unsigned int prev_rs_a_count_recive_ok = 0; - static unsigned int pause_comunication = PAUSE_COMUNICATION; - static unsigned int time_pause_modbus_can_zadatchik_vpu = TIME_PAUSE_MODBUS_CAN_ZADATCHIK_VPU; - static unsigned int time_pause_modbus_can_ukss_setup = TIME_PAUSE_MODBUS_CAN_UKSS_SETUP; - static unsigned int time_pause_modbus_can_bs2bs = TIME_PAUSE_MODBUS_CAN_BS2BS; - static int fa_0 = 1; - static int fa_1 = 1; - static int fa_2 = 1; - - static int prev_cmd_very_slow_start = 0; - - -// static float fff = 0; - - reinit_before_sbor(); - - if (edrk.SumSbor || edrk.Status_Ready.bits.ready_final) - { - disable_flag_special_mode_rs = 1; - } - else - disable_flag_special_mode_rs = 0; - - if (f.Prepare || f.terminal_prepare) { - project.clear_errors_all_plates(); - } - -// fff = my_satur_float(fff,MAX_ZADANIE_LIMIT_POWER, MIN_ZADANIE_LIMIT_POWER, 0); - // slow_vector_update(); - - read_plane_errors(); - -// if (flag_enable_update_hmi) -// update_tables_HMI(); -// if (flag_enable_update_mpu) -// update_modbus_table(); -// modbusNetworkSharing(1); -// get_command_HMI(); - -// return; - -// i_led1_on_off(1); - if (edrk.flag_disable_pult_485==0) - { - i_led2_on_off(1); - modbusNetworkSharing(0); - - } -// i_led1_on_off(0); - -// if (ccc[0]) -// { -// i_led2_on_off(0); -// return; -// } - - if (!(detect_pause_milisec(pause_comunication, &old_time_edrk2))) - return; - - - if (edrk.get_new_data_from_hmi2) - { - get_command_HMI(); - edrk.get_new_data_from_hmi2 = 0; - } - - - - //////////////////////////////////////////////////////// - //////////////////////////////////////////////////////// - // Дальше код запускается раз в 100 мсек. - //////////////////////////////////////////////////////// - //////////////////////////////////////////////////////// - //////////////////////////////////////////////////////// - - - // external_cmd_alarm_log = modbus_table_can_in[11].all; - // test_send_alarm_log(external_cmd_alarm_log); - - // modbusNetworkSharing(0); - - // i_led2_on_off(1); - - modbusNetworkSharingCAN(); - - #if (ENABLE_CAN_SEND_TO_UKSS_FROM_MAIN) - // пишем в задатчик - update_ukss_can(time_pause_modbus_can_zadatchik_vpu); - update_ukss_can_moment_kgnc(time_pause_modbus_can_zadatchik_vpu*3); - - - update_ukss_setup(time_pause_modbus_can_ukss_setup); - #endif - - #if (ENABLE_CAN_SEND_TO_ANOTHER_BSU_FROM_MAIN) -// пишем в задатчик - update_bsu_can(time_pause_modbus_can_bs2bs); - #endif - - check_all_power_limits(); - - calc_p_water_edrk(); - calc_temper_edrk(); - calc_temper_acdrive(); - - // читаем цифр входы - update_input_edrk(); - - detect_kvitir_from_all(); - - detect_error_all(); - - calc_limit_overheat(); - - calc_RMS_values_main(); - - update_lamp_alarm(); - - set_zadanie_u_charge(); - - reinit_protect_I_and_U_settings(); - - nagrev_auto_on_off(); - - auto_block_key_on_off(); - - - /////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - edrk.f_rotor_hz = _IQtoF(edrk.iq_f_rotor_hz) * NORMA_FROTOR; - - - - if (edrk.Status_Ready.bits.ImitationReady2) - { -// edrk.oborots = edrk.zadanie.oborots_zad; -// koef_p1 = 54.78260869565217391304347826087/(edrk.count_bs_work+1); -// koef_p2 = 54.78260869565217391304347826087/4; - - koef_p3 = 27.39130; - - if (control_station.active_array_cmd[CONTROL_STATION_CMD_ROTOR_POWER]==0) // по оборотам - { - - if (edrk.count_bs_work==0) - max_power = my_satur_float(edrk.zadanie.limit_power_zad, MAX_ZADANIE_POWER/2, MIN_ZADANIE_POWER/2, 0); - else - max_power = my_satur_float(edrk.zadanie.limit_power_zad, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER, 0); - - max_oborots = max_power/koef_p3; - if (edrk.count_bs_work==0) - max_oborots = my_satur_float(max_oborots,MAX_ZADANIE_OBOROTS_ROTOR/2,MIN_ZADANIE_OBOROTS_ROTOR/2, 0); - else - max_oborots = my_satur_float(max_oborots,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR, 0); - - local_oborots = fast_round(_IQtoF(edrk.zadanie.iq_oborots_zad_hz)*60.0*NORMA_FROTOR); - if (local_oborots>=0) - { - if (local_oborots>max_oborots) - local_oborots = max_oborots; - } - else - { - if (local_oborots<-max_oborots) - local_oborots = -max_oborots; - } - - float_oborots = zad_intensiv(1.0, 1.0, float_oborots, local_oborots); - - edrk.oborots = float_oborots; - edrk.power_kw = edrk.oborots * koef_p3/(edrk.count_bs_work+1); - - - - -// -// max_oborots = edrk.zadanie.limit_power_zad/koef_p2; -// max_oborots = my_satur_float(max_oborots,MAX_ZADANIE_OBOROTS_ROTOR,MIN_ZADANIE_OBOROTS_ROTOR, 0); -// -// local_oborots = fast_round(_IQtoF(edrk.zadanie.rmp_oborots_imitation_rmp)*60.0*NORMA_FROTOR); -// if (local_oborots>=0) -// { -// if (local_oborots>max_oborots) -// local_oborots = max_oborots; -// } -// else -// { -// if (local_oborots<-max_oborots) -// local_oborots = -max_oborots; -// } - - } - else - { - - local_power = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp) * NORMA_ACP * NORMA_ACP / 1000.0); - if (edrk.count_bs_work==0) - local_power = my_satur_float(local_power, MAX_ZADANIE_POWER/2, MIN_ZADANIE_POWER/2, 0); - else - local_power = my_satur_float(local_power, MAX_ZADANIE_POWER, MIN_ZADANIE_POWER, 0); - - local_oborots = local_power/koef_p3; - float_oborots = zad_intensiv(1.0, 1.0, float_oborots, local_oborots); - edrk.oborots = float_oborots; - edrk.power_kw = local_power/(edrk.count_bs_work+1);//edrk.oborots * koef_p3; - -// local_power = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp) * NORMA_ACP * NORMA_ACP / 1000.0); -// local_oborots = local_power/koef_p1; - } - - -// float_oborots = zad_intensiv(0.5, 0.5, float_oborots, local_oborots); -// edrk.oborots = float_oborots; -// -// if (edrk.oborots>=0) -// edrk.power_kw = edrk.oborots * koef_p2; -// else -// edrk.power_kw = edrk.oborots * koef_p2; - -// -// -// -// if (edrk.oborots>=0) -// edrk.power_kw = edrk.oborots * koef_p; -// else -// edrk.power_kw = edrk.oborots * (+koef_p); - } - else - { - edrk.oborots = fast_round(_IQtoF(WRotor.iqWRotorSumFilter3)*60.0*NORMA_FROTOR); -// local_power = fast_round(_IQtoF(filter.PowerScalarFilter2) * NORMA_ACP * NORMA_ACP / 1000.0); -// -// if (edrk.oborots>=0) -// edrk.power_kw = local_power; -// else -// edrk.power_kw = -local_power; - - edrk.power_kw = fast_round(_IQtoF(edrk.iq_power_kw_one_filter_znak) * NORMA_ACP * NORMA_ACP / 1000.0); - } - - power_kw_full = edrk.power_kw + edrk.power_kw_another_bs; - -// if (power_kw_full < MINIMAL_POWER_TO_DISPLAY) -// edrk.power_kw_full = 0; -// else - edrk.power_kw_full = power_kw_full; - /////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - - - edrk.Status_Ready.bits.ready1 = get_ready_1(); - - pump_control(); - - - if (control_station_select_active()) - { - - if (filter_count_error_control_station_select_active<30) - filter_count_error_control_station_select_active++; - else - edrk.errors.e7.bits.NOT_VALID_CONTROL_STATION |= 1; - } - else - filter_count_error_control_station_select_active = 0; - - edrk.current_active_control = get_current_station_control(); - - if (edrk.current_active_controlLEVEL_HWP_I_AF) level = LEVEL_HWP_I_AF; - if (level<0) level = 0; - - if (n_af == 0) - { - if (level != prev_level_all) - { - i_af_protect_d = convert_real_to_mv_hwp(2,level); - if (i_af_protect_d>1500) i_af_protect_d = 1500; // max 1500 mV - - update_maz_level_i_af(n_af, i_af_protect_d); - project.write_all_hwp(); - } - prev_level_all = level; - } -// else -// { -// if (level != prev_level_2) -// { -// i_af_protect_d = convert_real_to_mv_hwp(4,level); -// if (i_af_protect_d>1500) i_af_protect_d = 1500; // max 1500 mV -// -// update_maz_level_i_af(n_af, i_af_protect_d); -// project.write_all_hwp(); -// } -// prev_level_2 = level; -// -// } -} - - -void calc_count_build_revers(void) -{ - static unsigned int prev_b = 0, prev_r = 0; - - if (edrk.Status_Ready.bits.ImitationReady2) - { - detect_work_revers(((edrk.oborots>=0) ? 1 : -1), edrk.zadanie.iq_oborots_zad_hz_rmp, edrk.oborots); - } - else - detect_work_revers(WRotor.RotorDirectionSlow, edrk.zadanie.iq_oborots_zad_hz_rmp, WRotor.iqWRotorSumFilter2); - - if (edrk.count_revers != prev_r) - inc_count_revers(); - - if (edrk.count_sbor != prev_b) - inc_count_build(); - - prev_r = edrk.count_revers; - prev_b = edrk.count_sbor; - -} - - -void prepare_logger_pult(void) -{ - - edrk.pult_data.logger_params[0] = fast_round(_IQtoF(simple_scalar1.iq_decr_mzz_power_filter)*1000.0);//edrk.zadanie.oborots_zad; - edrk.pult_data.logger_params[1] = fast_round(_IQtoF(edrk.Kplus)*1000.0); - edrk.pult_data.logger_params[2] = fast_round(_IQtoF(pll1.vars.pll_Ud)*NORMA_ACP); - edrk.pult_data.logger_params[3] = fast_round(_IQtoF(edrk.f_stator)*NORMA_FROTOR*100.0); - edrk.pult_data.logger_params[4] = fast_round(_IQtoF(edrk.k_stator1)*10000.0); - edrk.pult_data.logger_params[5] = fast_round(_IQtoF(pll1.vars.pll_Uq)*NORMA_ACP); - edrk.pult_data.logger_params[6] = edrk.period_calc_pwm_int2; - edrk.pult_data.logger_params[7] = fast_round(_IQtoF(simple_scalar1.pidF.OutMax)*NORMA_ACP);//edrk.power_kw_full; - edrk.pult_data.logger_params[8] = edrk.Sbor_Mode; - edrk.pult_data.logger_params[9] = edrk.Stage_Sbor; - edrk.pult_data.logger_params[10] = fast_round(_IQtoF(edrk.Izad_out)*NORMA_ACP); - edrk.pult_data.logger_params[11] = edrk.period_calc_pwm_int1; - edrk.pult_data.logger_params[12] = fast_round(_IQtoF(simple_scalar1.pidF.Out)*NORMA_ACP); - edrk.pult_data.logger_params[13] = fast_round(_IQtoF(simple_scalar1.pidF.OutMin)*NORMA_ACP); - edrk.pult_data.logger_params[14] = fast_round(_IQtoF(simple_scalar1.pidPower.Out)*NORMA_ACP); - edrk.pult_data.logger_params[15] = fast_round(_IQtoF(simple_scalar1.pidPower.OutMax)*NORMA_ACP); - edrk.pult_data.logger_params[16] = fast_round(_IQtoF(simple_scalar1.pidF.Ref)*NORMA_FROTOR*1000.0);// //modbus_table_can_in[123].all;//Управление (По мощности, По оборотам) - edrk.pult_data.logger_params[17] = modbus_table_can_in[124].all;//Обороты (заданные) - edrk.pult_data.logger_params[18] = modbus_table_can_in[125].all;//Мощность (заданная) - edrk.pult_data.logger_params[19] = modbus_table_can_in[134].all;//запас мощности - edrk.pult_data.logger_params[20] = fast_round(_IQtoF(simple_scalar1.bpsi_curent)*NORMA_FROTOR*1000.0); - edrk.pult_data.logger_params[21] = fast_round(_IQtoF(edrk.from_uom.iq_level_value_kwt)*NORMA_ACP*NORMA_ACP/1000.0); - edrk.pult_data.logger_params[22] = fast_round(_IQtoF(simple_scalar1.iqKoefOgran)*1000.0);//fast_round(_IQtoF(rotor_22220.iqFout)*NORMA_FROTOR*1000.0); - edrk.pult_data.logger_params[23] = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0); //fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad)*NORMA_ACP*NORMA_ACP/1000.0); - edrk.pult_data.logger_params[24] = fast_round(_IQtoF(edrk.all_limit_koeffs.sum_limit)*1000.0); - edrk.pult_data.logger_params[25] = fast_round(_IQtoF(edrk.all_limit_koeffs.uom_limit)*1000.0); - edrk.pult_data.logger_params[26] = fast_round(_IQtoF(edrk.all_limit_koeffs.uin_freq_limit)*1000.0); - edrk.pult_data.logger_params[27] = fast_round(_IQtoF(simple_scalar1.pidF.Fdb)*NORMA_FROTOR*1000.0); // - - -} - - -int calc_auto_moto_pump(void) -{ - volatile long sum_minutes_pump1, sum_minutes_pump2, set_delta_minutes, cur_delta_minutes; - - - sum_minutes_pump1 = 0; - if (edrk.pult_data.data_from_pult.moto[12]>=0) - sum_minutes_pump1 += edrk.pult_data.data_from_pult.moto[12] * 1440; - if (edrk.pult_data.data_from_pult.moto[3]>=0) - sum_minutes_pump1 += edrk.pult_data.data_from_pult.moto[3]; - - sum_minutes_pump2 = 0; - if (edrk.pult_data.data_from_pult.moto[13]>=0) - sum_minutes_pump2 += edrk.pult_data.data_from_pult.moto[13] * 1440; - if (edrk.pult_data.data_from_pult.moto[4]>=0) - sum_minutes_pump2 += edrk.pult_data.data_from_pult.moto[4]; - - cur_delta_minutes = sum_minutes_pump1 - sum_minutes_pump2; - - set_delta_minutes = edrk.pult_data.data_to_pult.TimeToChangePump; - - if (set_delta_minutes==0) - { + if (cosw==0) return 0; - } + z1 = input_prev - _IQmpy(input,cosw); +// z2 = sinw; + z3 = _IQdiv(z1,sinw); - if (cur_delta_minutes>set_delta_minutes) - { - return 2; - } - else - if (cur_delta_minutes<-set_delta_minutes) - { - return 1; - } - else - if (edrk.pult_data.data_from_pult.LastWorkPump==0) - { - if (cur_delta_minutes>0) - { - return 1; - } - else - if (cur_delta_minutes<=0) - { - return 2; - } - else - return 0; - } - else - { - if (edrk.pult_data.data_from_pult.LastWorkPump == 1) - return 1; - else - if (edrk.pult_data.data_from_pult.LastWorkPump == 2) - return 2; - else - return 0; - } -// -// -// if (cur_delta_minutes>0) -// { -// //T1>T2 -// if (_IQabs(cur_delta_minutes) >= set_delta_minutes) -// { -// // T1+delta>T2 -// return 2; -// } -// else -// return 1; -// } -// else -// { -// //T2>T1 -// if (_IQabs(cur_delta_minutes) >= set_delta_minutes) -// { -// //T2+delta>T1 -// return 1; -// } -// else -// return 2; -// } - -// if (_IQabs(cur_delta_minutes) > set_delta_minutes) -// { -// if (cur_delta_minutes>) -// return 2; -// else -// return 1; -// -// -// } -// if (cur_delta_minutes>=0) -// { -// if (_IQabs(cur_delta_minutes) > set_delta_minutes) -// return 2; -// else -// return 1; -// } -// else -// { -// if (_IQabs(cur_delta_minutes) > set_delta_minutes) -// return 1; -// else -// return 2; -// } - + y2 = _IQmpy(input,input)+_IQmpy(z3,z3); +// cosw = _IQsin(); + y = _IQsqrt(y2); + return y; } - - -void read_can_error(void) -{ - EALLOW; - edrk.canes_reg = ECanaRegs.CANES.all; - edrk.canrec_reg = ECanaRegs.CANREC.all; - edrk.cantec_reg = ECanaRegs.CANTEC.all; - EDIS; - - cmd_clear_can_error(); - -} - - -void clear_can_error(void) -{ - // EALLOW; - - // ECanaRegs.CANES.all=0xffffffff; - InitCanSoft(); - - //EDIS; - -} - -void cmd_clear_can_error(void) -{ - static int prev_cmd_clear_can_error = 0; - - if (edrk.cmd_clear_can_error && prev_cmd_clear_can_error==0) - { - clear_can_error(); - } - prev_cmd_clear_can_error = edrk.cmd_clear_can_error; - -} - - -void check_temper_break(void) -{ - - if ( (edrk.break_tempers[0] > ABNORMAL_TEMPER_BREAK_INT) - || (edrk.break_tempers[1] > ABNORMAL_TEMPER_BREAK_INT) - || (edrk.break_tempers[2] > ABNORMAL_TEMPER_BREAK_INT) - || (edrk.break_tempers[3] > ABNORMAL_TEMPER_BREAK_INT) - ) - edrk.warnings.e9.bits.BREAK_TEMPER_WARNING = 1; - else - { - if ( (edrk.break_tempers[0] < ABNORMAL_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[1] < ABNORMAL_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[2] < ABNORMAL_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[3] < ABNORMAL_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - ) - edrk.warnings.e9.bits.BREAK_TEMPER_WARNING = 0; - } - - - if ( (edrk.break_tempers[0] > ALARM_TEMPER_BREAK_INT) - || (edrk.break_tempers[1] > ALARM_TEMPER_BREAK_INT) - || (edrk.break_tempers[2] > ALARM_TEMPER_BREAK_INT) - || (edrk.break_tempers[3] > ALARM_TEMPER_BREAK_INT) - ) - edrk.warnings.e9.bits.BREAK_TEMPER_ALARM = 1; - else - { - //DELTA_TEMPER_BREAK_INT - if ( (edrk.break_tempers[0] < ALARM_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[1] < ALARM_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[2] < ALARM_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - && (edrk.break_tempers[3] < ALARM_TEMPER_BREAK_INT-DELTA_TEMPER_BREAK_INT) - ) - edrk.warnings.e9.bits.BREAK_TEMPER_ALARM = 0; - } - -} - -#define TIME_FILTER_BREAKER_SIGNALS 10 - -void check_breaker_ged(void) -{ - static unsigned int count_wait_breaker = 0; - - edrk.warnings.e9.bits.BREAKER_GED_ON = filter_digital_input( edrk.warnings.e9.bits.BREAKER_GED_ON, - &count_wait_breaker, - TIME_FILTER_BREAKER_SIGNALS, - edrk.breaker_on); - -// if (edrk.breaker_on) -// edrk.warnings.e9.bits.BREAKER_GED_ON = 1; -// else -// edrk.warnings.e9.bits.BREAKER_GED_ON = 0; - -} diff --git a/Inu/Src/main/edrk_main.h b/Inu/Src/main/edrk_main.h index 435baca..12b9fe5 100644 --- a/Inu/Src/main/edrk_main.h +++ b/Inu/Src/main/edrk_main.h @@ -5,25 +5,16 @@ #include "IQmathLib.h" #include "rmp_cntl_v1.h" -#include "rmp_cntl_v2.h" - #include "alg_pll.h" -#define TIME_PAUSE_MODBUS_CAN_BS2BS 500 //900 //500 -#define TIME_PAUSE_MODBUS_CAN_ZADATCHIK_VPU 250 //100//100 -#define TIME_PAUSE_MODBUS_CAN_UKSS_SETUP 2500 // -#define TIME_PAUSE_MODBUS_CAN_MPU 1100 //500 -#define TIME_PAUSE_MODBUS_CAN_TERMINALS 2000 //1000 +#define TIME_PAUSE_MODBUS_CAN_BS2BS 500 +#define TIME_PAUSE_MODBUS_CAN_ZADATCHIK_VPU 100 +#define TIME_PAUSE_MODBUS_CAN_UKSS_SETUP 5000 +#define TIME_PAUSE_MODBUS_CAN_MPU 500 +#define TIME_PAUSE_MODBUS_CAN_TERMINALS 1000 #define TIME_PAUSE_MODBUS_CAN_OSCIL 5000 -//#define TIME_PAUSE_MODBUS_CAN_BS2BS 100//20//500 -//#define TIME_PAUSE_MODBUS_CAN_ZADATCHIK_VPU 250//20//100 -//#define TIME_PAUSE_MODBUS_CAN_UKSS_SETUP 5000 -//#define TIME_PAUSE_MODBUS_CAN_MPU 500//20//500 -//#define TIME_PAUSE_MODBUS_CAN_TERMINALS 1000 -//#define TIME_PAUSE_MODBUS_CAN_OSCIL 5000 - //#define TIME_PAUSE_MODBUS_CAN_TMS2TMS_VIPR 75 //500 @@ -143,22 +134,6 @@ enum }; -enum -{ - STAGE_SBOR_STATUS_NO_STATUS = 0, - STAGE_SBOR_STATUS_FIRST, - STAGE_SBOR_STATUS_PUMP, - STAGE_SBOR_STATUS_ZARYAD, - STAGE_SBOR_STATUS_UMP_ON, - STAGE_SBOR_STATUS_QTV, - STAGE_SBOR_STATUS_UMP_OFF, - STAGE_SBOR_STATUS_RASCEPITEL_1, - STAGE_SBOR_STATUS_RASCEPITEL_2, - STAGE_SBOR_STATUS_RASCEPITEL_3, - STAGE_SBOR_STATUS_RASCEPITEL_4, - STAGE_SBOR_STATUS_WAIT_READY_ANOTHER, - STAGE_SBOR_STATUS_FINISH -}; /* @@ -213,7 +188,6 @@ typedef struct float real_temper_air[4]; int real_int_temper_air[4]; int max_real_int_temper_air; - int min_real_int_temper_air; @@ -221,7 +195,7 @@ typedef struct } TEMPER_EDRK; #define TEMPER_EDRK_DEFAULT {{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},{0,0,0,0,0,0,0},0,\ {0,0},{0,0},{0,0},0,\ - {0,0,0,0},{0,0,0,0},{0,0,0,0},0,0\ + {0,0,0,0},{0,0,0,0},{0,0,0,0},0\ } @@ -540,15 +514,8 @@ typedef struct unsigned int ERR_PWM_WDOG :1; unsigned int ERR_INT_PWM_VERY_LONG : 1; - unsigned int SENSOR_ROTOR_1_BREAK : 1; - unsigned int SENSOR_ROTOR_2_BREAK : 1; - unsigned int SENSOR_ROTOR_1_2_BREAK : 1; - unsigned int SENSOR_ROTOR_BREAK_DIRECTION : 1; - - unsigned int BREAK_TEMPER_WARNING : 1; - unsigned int BREAK_TEMPER_ALARM : 1; - unsigned int BREAKER_GED_ON : 1; + unsigned int res: 7; } bits; } e9; @@ -718,8 +685,8 @@ typedef union { } bits; - } AUTO_MASTER_SLAVE_DATA; + //////////////////////////////////////////////////////// typedef union { unsigned int all; @@ -737,10 +704,11 @@ typedef union { unsigned int Batt: 1; unsigned int ImitationReady2: 1; - unsigned int MasterSlaveActive: 1; // выставим если есть master или slave - unsigned int preImitationReady2: 1; - unsigned int res:4; + unsigned int MasterSlaveActive: 1; // выставим если есть master или slave + + +// unsigned int res:6; } bits; } STATUS_READY; //////////////////////////////////////////////////////// @@ -865,14 +833,8 @@ typedef union { unsigned int PLUS: 1; unsigned int MINUS : 1; unsigned int PROVOROT :1 ; - - unsigned int UOM_READY_ACTIVE : 1; - unsigned int UOM_LIMIT_3 : 1; - unsigned int UOM_LIMIT_2 : 1; - unsigned int UOM_LIMIT_1 : 1; - - - unsigned int res:8; + unsigned int ACTIVE : 1; + unsigned int res:11; } bits; } FROM_ZADAT4IK; //////////////////////////////////////////////////////// @@ -913,14 +875,14 @@ typedef union { union { unsigned int all; struct { - unsigned int GOTOV1 : 1; - unsigned int GOTOV2 : 1; - unsigned int EMKOST : 1; //For 23550.3 and AVARIA moved up - unsigned int NEISPRAVNOST : 1; + unsigned int GOTOV1: 1; + unsigned int GOTOV2: 1; +// unsigned int EMKOST : 1; //For 23550.3 and AVARIA moved up + unsigned int AVARIA:1; + unsigned int NEISPRAVNOST :1 ; unsigned int PEREGREV : 1; unsigned int OGRAN_POWER : 1; - unsigned int AVARIA : 1; - unsigned int res:9; + unsigned int res:10; } bits; } BIG_LAMS; @@ -961,10 +923,6 @@ typedef union { } APL_LAMS_PCH; } TO_ZADAT4IK; - -#define TO_ZADAT4IK_DEFAULT {0,0,0,0,0} - - //////////////////////////////////////////////////////// typedef struct { @@ -989,18 +947,12 @@ typedef union { } BIG_LAMS; } TO_VPU; - -#define TO_VPU_DEFAULT {0,0,0} - //////////////////////////////////////////////////////// typedef struct { unsigned int level_value; unsigned int ready; unsigned int error; - unsigned int code; - _iq iq_level_value; - _iq iq_level_value_kwt; @@ -1068,17 +1020,12 @@ typedef struct { RMP_V1 rmp_k_u_disbalance; RMP_V1 rmp_kplus_u_disbalance; RMP_V1 rmp_Izad; - - RMP_V2 rmp_powers_zad; - - RMP_V2 rmp_limit_powers_zad; + RMP_V1 rmp_powers_zad; + RMP_V1 rmp_limit_powers_zad; RMP_V1 rmp_kzad; + RMP_V1 rmp_oborots_zad_hz; - RMP_V2 rmp_oborots_zad_hz; - RMP_V1 rmp_oborots_imitation; - - _iq rmp_oborots_imitation_rmp; float ZadanieU_Charge; @@ -1086,7 +1033,6 @@ typedef struct { _iq iq_ZadanieU_Charge_rmp; float oborots_zad; - float oborots_zad_hz; _iq iq_oborots_zad_hz; _iq iq_oborots_zad_hz_rmp; @@ -1119,154 +1065,37 @@ typedef struct { _iq iq_limit_power_zad; _iq iq_limit_power_zad_rmp; - _iq iq_set_break_level; - - float oborots_zad_no_dead_zone; - } ZADANIE; #define ZADANIE_DEFAULT { RMP_V1_DEFAULTS, RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,\ - RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,\ - RMP_V2_DEFAULTS,\ - RMP_V2_DEFAULTS,RMP_V1_DEFAULTS,\ - RMP_V2_DEFAULTS,\ - RMP_V1_DEFAULTS,\ - 0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0 , 0,0,0, 0,0} + RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,RMP_V1_DEFAULTS,\ + 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0 , 0,0,0} typedef union { struct { - unsigned int limit_by_temper:1; - unsigned int limit_Iout:1; - unsigned int limit_UOM:1; //Устройство ограничения мощности - unsigned int limit_from_SVU:1; - unsigned int limit_from_freq:1; - unsigned int limit_from_uom_fast:1; - unsigned int limit_moment:1; - - unsigned int res:9; + unsigned int limit_by_temper; + unsigned int limit_Iout; + unsigned int limit_UOM; //Устройство ограничения мощности + unsigned int limit_from_SVU; } bits; unsigned int all; } POWER_LIMIT; -#define POWER_LIMIT_DEFAULTS {0} +#define POWER_LIMIT_DEFAULTS {0,0,0,0} -typedef struct { - - _iq temper_limit; - _iq power_limit; - _iq moment_limit; - _iq uin_freq_limit; - _iq uom_limit; - - _iq local_temper_limit; - _iq local_power_limit; - _iq local_moment_limit; - _iq local_uin_freq_limit; - _iq local_uom_limit; - - _iq sum_limit; - _iq local_sum_limit; - int code_status; - -} ALL_LIMIT_KOEFFS; - -#define ALL_LIMIT_KOEFFS_DEFAULTS {0,0,0,0,0, 0,0,0,0,0, 0,0,0} - typedef struct { _iq power_units; _iq area; _iq water_int; _iq water_ext; _iq acdrive_windings; - _iq acdrive_bears; _iq sum_limit; int code_status; } TEMPERATURE_LIMIT_KOEFFS; -#define TEMPERATURE_LIMIT_KOEFFS_DEFAULTS {0,0,0,0,0, 0,CONST_IQ_1,0} - -#define COUNT_MOTO_PULT 18 - -typedef struct -{ - - int nPCH; - int TimeToChangePump; - - int count_revers; // кол-во реверсов - int count_build; // кол-во сборок схем - - int LastWorkPump; // какой был последний запущенный насос - - int moto[COUNT_MOTO_PULT]; - -} t_params_pult_ing_one; - -#define PARAMS_PULT_ING_ONE_DEFAULTS {-1,-1, -1,-1, 0, \ - {-1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1,-1,-1, -1,-1,-1 } } - -#define PARAMS_PULT_ING_TWO_DEFAULTS {0,0, 0,0, 0, \ - {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0 } } - -typedef struct -{ - int flagSaveDataPCH; - int flagSaveDataMoto; - int flagSaveSlowLogs; - int flagSaveParamLogs; - - int logger_params[28]; - - t_params_pult_ing_one data; - t_params_pult_ing_one data_from_pult; - t_params_pult_ing_one data_to_pult; - -// int nPCH_from_pult; -// int nPCH_to_pult; -// int nPCH; -// -// int TimeToChangePump_from_pult; -// int TimeToChangePump_to_pult; -// int TimeToChangePump; -// -// int moto_from_pult[COUNT_MOTO_PULT]; -// int mot_to_pult[COUNT_MOTO_PULT]; -// int moto[COUNT_MOTO_PULT]; -// -// int count_revers_from_pult; -// int count_revers_to_pult; - -} t_params_pult_ing; - -#define PARAMS_PULT_ING_DEFAULTS {0,0,0,0, \ - {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0}, \ - PARAMS_PULT_ING_TWO_DEFAULTS, \ - PARAMS_PULT_ING_ONE_DEFAULTS, \ - PARAMS_PULT_ING_ONE_DEFAULTS \ - } - - - - -typedef struct -{ - int log_what_memory; // Значение 0 - нет ни флешки, ни карты; - //Значение 1 - нет флешки, есть карта; - //Значение 2 - есть флешка, нет карты; - //Значение 3 - есть и флешка и карта; - int kvitir; // - int sbor; - int send_log; - int pump_mode; - int sdusb;// 0 - sd, 1 usb - -} t_pult_cmd_ing; - -#define PULT_CMD_ING_DEFAULTS 0,0,0,0,0,0 - - +#define TEMPERATURE_LIMIT_KOEFFS_DEFAULTS {0,0,0,0,0,0,0} //////////////////////////////////////////////////////// typedef struct @@ -1281,7 +1110,6 @@ typedef struct POWER_LIMIT power_limit; TEMPERATURE_LIMIT_KOEFFS temper_limit_koeffs; - ALL_LIMIT_KOEFFS all_limit_koeffs; MASTER_SLAVE_COM ms; @@ -1314,7 +1142,6 @@ typedef struct TO_SHEMA to_shema;//1 FROM_SHEMA from_shema;//1 - FROM_SHEMA from_shema_filter;//1 FROM_ZADAT4IK from_zadat4ik;//1 @@ -1336,7 +1163,7 @@ typedef struct TO_VPU to_vpu;//3 - FROM_UOM from_uom;//7 + FROM_UOM from_uom;//4 /////////////////////////////////////////////// unsigned int Discharge; @@ -1359,7 +1186,6 @@ typedef struct unsigned int prevGo; unsigned int Go; - unsigned int GoBreak; unsigned int GoWait; @@ -1367,8 +1193,6 @@ typedef struct int flag_block_zadanie; int StartGEDfromControl; int StartGEDfromZadanie; - int prevStartGEDfromZadanie; - int StartGED; int test_mode; int cmd_to_qtv;//20 @@ -1443,8 +1267,7 @@ typedef struct _iq iq_f_rotor_hz; float f_rotor_hz; int oborots; - int rotor_direction; - int power_kw; + float power_kw; // _iq iq_oborots; _iq Izad_out; @@ -1476,7 +1299,7 @@ typedef struct int warning; int overheat; - unsigned int MasterSlave; + unsigned MasterSlave; _iq master_theta; _iq master_Uzad; @@ -1508,14 +1331,10 @@ typedef struct int Ready1_another_bs; int Ready2_another_bs; - int ump_cmd_another_bs; - int qtv_cmd_another_bs; - int active_post_upravl; int active_post_upravl_another_bs; int MasterSlave_another_bs; - int freq_50hz_1; - int freq_50hz_2; + int freq_50hz; _iq test_rms_Iu; _iq test_rms_Ua; @@ -1537,168 +1356,62 @@ typedef struct int disable_rascepitel_work; int enable_pwm_test_lines; - int count_bs_work; - unsigned int run_to_pwm_async; - - int power_kw_full; - - int stop_logs_rs232; - int sbor_wait_ump1; - int sbor_wait_ump2; - int flag_enable_on_ump; - - int local_ump_on_off; - int local_ump_on_off_count; - int local_ready_ump; - int local_ready_ump_count; - - t_params_pult_ing pult_data; - - int logs_rotor; - - int stop_slow_log; - int t_slow_log; - int disable_limit_power_from_svu; - int disable_uom; - int disable_break_work; - - int flag_another_bs_first_ready12; - int flag_this_bs_first_ready12; - int enter_to_pump_stage; - - int buildYear; - int buildMonth; - int buildDay; - - int errors_another_bs_from_can; - - unsigned int count_sbor; - unsigned int count_revers; - unsigned int count_run; - - int flag_slow_in_main; - - t_pult_cmd_ing pult_cmd; - - int get_new_data_from_hmi2; - - _iq iq_freq_50hz; - - int imit_limit_freq; - int imit_limit_uom; - int set_limit_uom_50; - - _iq iq_power_kw_full_znak; - _iq iq_power_kw_one_znak; - - _iq iq_power_kw_full_filter_znak; - _iq iq_power_kw_one_filter_znak; - - _iq iq_power_kw_full_abs; - _iq iq_power_kw_one_abs; - - _iq iq_power_kw_full_filter_abs; - _iq iq_power_kw_one_filter_abs; - - unsigned int sum_count_err_read_opt_bus; - - int imit_save_slow_logs; - - int imit_send_alarm_log_pult; - - int current_active_control; - - // int data_to_message2[100]; //101 - unsigned long canes_reg; - unsigned long cantec_reg; // Transmit Error Counter - unsigned long canrec_reg; // Receive Error Counter - - int cmd_clear_can_error; - - int cmd_very_slow_start; - - int cmd_imit_low_isolation; - - - int breaker_on; - int break_tempers[4]; - - int cmd_disable_calc_km_on_slave; - - } EDRK; #define EDRK_DEFAULT { \ - ZADANIE_DEFAULT,\ - ZADANIE_FROM_ANOTHER_BS_DEFAULT,\ - TEMPER_EDRK_DEFAULT, \ - P_WATER_EDRK_DEFAULT, \ - ERRORS_EDRK_DEFAULT, \ - ERRORS_EDRK_DEFAULT, \ - TEMPER_ACDRIVE_DEFAULT, \ - POWER_LIMIT_DEFAULTS, \ - TEMPERATURE_LIMIT_KOEFFS_DEFAULTS, \ - ALL_LIMIT_KOEFFS_DEFAULTS, \ - MASTER_SLAVE_COM_DEFAULT, \ - 0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0, \ - 0,0,0,0, \ - 0,0,0, \ - 0,0,0,0,0,0,0, \ - \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0,0,0,0,0,0,0, 0,0, \ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ - 0,0,0,0, \ - PARAMS_PULT_ING_DEFAULTS, \ - 0,0,0,0,0,0,0,0, \ + ZADANIE_DEFAULT,\ + ZADANIE_FROM_ANOTHER_BS_DEFAULT,\ + TEMPER_EDRK_DEFAULT, P_WATER_EDRK_DEFAULT, \ + ERRORS_EDRK_DEFAULT, ERRORS_EDRK_DEFAULT,\ + TEMPER_ACDRIVE_DEFAULT,\ + POWER_LIMIT_DEFAULTS,\ + TEMPERATURE_LIMIT_KOEFFS_DEFAULTS,\ + MASTER_SLAVE_COM_DEFAULT,\ + 0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,\ + 0,0,0,0,\ 0,0,0,\ - 0, 0,0,0, 0, \ - PULT_CMD_ING_DEFAULTS, 0,0, 0,0,0, 0,0,0,0, 0,0,0,0, \ - 0, 0,0, 0, 0, \ - 0,0,0, 0, 0, 0, \ - 0, {0,0,0,0}, \ - 0 \ - } - + 0,0,0,0,\ + \ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0, 0,0,\ + 0,0,0,0,0,0,0,0,0,0,0,0 \ + } extern EDRK edrk; -extern PLL_REC pll1; -//float get_sensor_ing(void); -//float get_i_vozbud(void); -//float get_zad_vozbud(void); +float get_sensor_ing(void); +float get_i_vozbud(void); +float get_zad_vozbud(void); -//unsigned int convert_w_to_mA(float inp); +unsigned int convert_w_to_mA(float inp); void edrk_init(void); - void update_input_edrk(void); void update_output_edrk(void); +float get_amper_vozbud(void); -//float get_amper_vozbud(void); - -//void set_amper_vozbud(float set_curr, float cur_curr); +void set_amper_vozbud(float set_curr, float cur_curr); -//void write_dac(int ndac, int Value); +void write_dac(int ndac, int Value); void run_edrk(void); @@ -1707,52 +1420,63 @@ void run_edrk(void); void set_oborots_from_zadat4ik(void); void get_where_oborots(void); -//void update_errors(void); +void update_errors(void); +void calc_p_water_edrk(void); +unsigned int pause_detect_error(unsigned int *c_err, unsigned int max_wait,unsigned int flag); - -//unsigned int zaryad_on_off(unsigned int flag); +void nagrev_auto_on_off(void); +unsigned int zaryad_on_off(unsigned int flag); void update_lamp_alarm(void); +void auto_block_key_on_off(void); +void nagrev_auto_on_off(void); - - -//int get_status_temper_acdrive_winding(int nc); -//int get_status_temper_acdrive_bear(int nc); -//int get_status_temper_air(int nc); -//int get_status_temper_u(int nc); -//int get_status_temper_water(int nc); -//int get_status_p_water_max(void); -//int get_status_p_water_min(int pump_on_off); +int get_status_temper_acdrive_winding(int nc); +int get_status_temper_acdrive_bear(int nc); +int get_status_temper_air(int nc); +int get_status_temper_u(int nc); +int get_status_temper_water(int nc); +int get_status_p_water_max(void); +int get_status_p_water_min(int pump_on_off); void detect_kvitir_from_all(void); -//void set_status_pump_fan(void); +void set_status_pump_fan(void); int qtv_on_off(unsigned int flag); -///int detect_error_u_zpt(void); -//int detect_error_u_zpt_on_predzaryad(void); +int detect_error_u_zpt(void); +int detect_error_u_zpt_on_predzaryad(void); void set_zadanie_u_charge(void); +void update_ukss_can(unsigned int pause); +void update_ukss_setup(unsigned int pause); +void update_bsu_can(unsigned int pause); +void init_can_box_between_bs1_bs2(void); +unsigned int filter_err_count(unsigned int *counter, unsigned int max_errors, unsigned int err, unsigned int cmd); +void detect_alive_another_bs(void); +void auto_select_master_slave(void); +void clear_errors_master_slave(void); +void who_select_sync_signal(void); +void clear_wait_synhro_optical_bus(void); - - +unsigned int wait_synhro_optical_bus(void); void edrk_init_variables(void); @@ -1762,53 +1486,41 @@ void edrk_go_main(void); int get_start_ged_from_zadanie(void); +void ramp_all_zadanie(int flag_set_zero); +void init_ramp_all_zadanie(void); -//void UpdateTableSecondBS(void); +void UpdateTableSecondBS(void); unsigned int get_ready_1(void); -//int detect_zaryad_ump(void); +int detect_zaryad_ump(void); void cross_stend_automats(void); +void update_zadat4ik(void); void get_sumsbor_command(void); -//unsigned int read_cmd_sbor_from_bs(void); +unsigned int read_cmd_sbor_from_bs(void); -//void read_data_from_bs(void); +void read_data_from_bs(void); void check_change_post_upravl(void); int get_code_active_post_upravl(void); - +void get_freq_50hz(void); +void calc_pll_50hz(void); +void init_50hz_input_net50hz(void); void auto_detect_zero_u_zpt(void); -void run_can_from_mpu(void); -void set_new_level_i_protect(int n_af, int level); -void update_maz_level_i_af(int n_af, unsigned int new_maz_level); -void calc_count_build_revers(void); -int calc_auto_moto_pump(void); -void prepare_logger_pult(void); -void read_can_error(void); -void clear_can_error(void); -void cmd_clear_can_error(void); -void check_temper_break(void); -void check_breaker_ged(void); +_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal); - -//extern int ccc[40]; - -void reinit_before_sbor(void); -unsigned int toggle_status_lamp(unsigned int bb1, unsigned int flag); - - #endif diff --git a/Inu/Src2/551/main/not_use/log_to_mem.c b/Inu/Src/main/log_to_mem.c similarity index 92% rename from Inu/Src2/551/main/not_use/log_to_mem.c rename to Inu/Src/main/log_to_mem.c index 8a5c223..7f82796 100644 --- a/Inu/Src2/551/main/not_use/log_to_mem.c +++ b/Inu/Src/main/log_to_mem.c @@ -40,11 +40,27 @@ int no_write = 0; // int no_write_slow = 0; // Флаг, чтобы не писать (если что) #pragma CODE_SECTION(clear_logpar,".fast_run"); -void clear_logpar() -{ - int i; - for(i=0;ianalog_data.analog7_hi = HIBYTE(Data); Data = _IQtoF(filter.iqIm_2)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[3]; + reply_a->analog_data.analog8_lo = LOBYTE(Data); reply_a->analog_data.analog8_hi = HIBYTE(Data); @@ -168,31 +163,31 @@ void func_pack_answer_to_TMS(TMS_TO_TERMINAL_STRUCT *reply_a) reply_a->analog_data.analog11_lo = LOBYTE(Data); reply_a->analog_data.analog11_hi = HIBYTE(Data); - Data = (int) (edrk.temper_edrk.max_real_int_temper_air);//_IQtoF(edrk.f_stator)*F_STATOR_MAX;// +Data = (int) (edrk.temper_edrk.max_real_int_temper_air);//_IQtoF(edrk.f_stator)*F_STATOR_MAX;// reply_a->analog_data.analog12_lo = LOBYTE(Data); reply_a->analog_data.analog12_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP);//edrk.I_zad_vozbud;// +Data = fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP);//edrk.I_zad_vozbud;// reply_a->analog_data.analog13_lo = LOBYTE(Data); reply_a->analog_data.analog13_hi = HIBYTE(Data); - Data = edrk.zadanie.oborots_zad;//edrk.I_zad_vozbud_exp;// +Data = edrk.zadanie.oborots_zad;//edrk.I_zad_vozbud_exp;// reply_a->analog_data.analog14_lo = LOBYTE(Data); reply_a->analog_data.analog14_hi = HIBYTE(Data); - Data = edrk.zadanie.power_zad;//edrk.I_cur_vozbud;// +Data = edrk.zadanie.power_zad;//edrk.I_cur_vozbud;// reply_a->analog_data.analog15_lo = LOBYTE(Data); reply_a->analog_data.analog15_hi = HIBYTE(Data); - Data = edrk.zadanie.Izad;//edrk.I_cur_vozbud_exp;// +Data = edrk.zadanie.Izad;//edrk.I_cur_vozbud_exp;// reply_a->analog_data.analog16_lo = LOBYTE(Data); reply_a->analog_data.analog16_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(edrk.Kplus)*1000.0);//edrk.W_zad_mA;// +Data = fast_round(_IQtoF(edrk.Kplus)*1000.0);//edrk.W_zad_mA;// reply_a->analog_data.analog17_lo = LOBYTE(Data); reply_a->analog_data.analog17_hi = HIBYTE(Data); -Data = fast_round(edrk.freq_50hz_1/10.0);//edrk.Zadanie2VozbudING;// +Data = fast_round(edrk.freq_50hz/10.0);//edrk.Zadanie2VozbudING;// reply_a->analog_data.analog18_lo = LOBYTE(Data); reply_a->analog_data.analog18_hi = HIBYTE(Data); @@ -204,16 +199,15 @@ Data = fast_round(_IQtoF(edrk.k_stator1)*10000.0);// edrk.W_from_all; reply_a->analog_data.analog20_lo = LOBYTE(Data); reply_a->analog_data.analog20_hi = HIBYTE(Data); -Data = _IQtoF(vect_control.iqId1)*NORMA_ACP;//0;//_IQtoF(edrk.test_rms_Iu)*NORMA_ACP; //fast_round(_IQtoF(WRotor.iqWRotorImpulses1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY; +Data =_IQtoF(edrk.test_rms_Iu)*NORMA_ACP; //fast_round(_IQtoF(WRotor.iqWRotorImpulses1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY; reply_a->analog_data.analog21_lo = LOBYTE(Data); reply_a->analog_data.analog21_hi = HIBYTE(Data); -Data = _IQtoF(vect_control.iqIq1)*NORMA_ACP;// 0;//_IQtoF(edrk.test_rms_Ua)*NORMA_ACP;// fast_round(_IQtoF(WRotor.iqWRotorImpulses2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU; +Data =_IQtoF(edrk.test_rms_Ua)*NORMA_ACP;// fast_round(_IQtoF(WRotor.iqWRotorImpulses2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU; reply_a->analog_data.analog22_lo = LOBYTE(Data); reply_a->analog_data.analog22_hi = HIBYTE(Data); -//Data = fast_round(_IQtoF(WRotor.iqWRotorSumFilter3)*NORMA_FROTOR*100.0*60.0);//edrk.oborots;//fast_round(_IQtoF(WRotorPBus.iqAngle1F)*360.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses2;//edrk.W_from_ZADAT4IK; -Data = _IQtoF(WRotor.iqWRotorSumFilter) * NORMA_FROTOR*600.0;//edrk.oborots; +Data = edrk.oborots;//fast_round(_IQtoF(WRotorPBus.iqAngle1F)*360.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses2;//edrk.W_from_ZADAT4IK; reply_a->analog_data.analog23_lo = LOBYTE(Data); reply_a->analog_data.analog23_hi = HIBYTE(Data); @@ -222,12 +216,11 @@ Data = fast_round(edrk.f_rotor_hz*100.0);//fast_round(_IQtoF(WRotorPBus.iqAngle2 reply_a->analog_data.analog24_hi = HIBYTE(Data); //Data = _IQtoF(edrk.k_stator1)*10000;//; -Data = edrk.period_calc_pwm_int2;//fast_round(_IQtoF(rotor_22220.iqFdirty)*NORMA_FROTOR*1000.0); +Data = fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul1)*NORMA_FROTOR*1000.0); reply_a->analog_data.analog25_lo = LOBYTE(Data); reply_a->analog_data.analog25_hi = HIBYTE(Data); -Data = edrk.power_kw_full; //Мощность двигателя текущая кВт -//fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul2)*NORMA_FROTOR*1000.0); +Data = fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul2)*NORMA_FROTOR*1000.0); reply_a->analog_data.analog26_lo = LOBYTE(Data); reply_a->analog_data.analog26_hi = HIBYTE(Data); @@ -247,59 +240,56 @@ Data = edrk.period_calc_pwm_int1; reply_a->analog_data.analog30_lo = LOBYTE(Data); reply_a->analog_data.analog30_hi = HIBYTE(Data); - Data = (int)edrk.temper_acdrive.winding.max_real_int_temper; - reply_a->analog_data.analog31_lo = LOBYTE(Data); - reply_a->analog_data.analog31_hi = HIBYTE(Data); - Data = (int)edrk.temper_acdrive.bear.max_real_int_temper; - reply_a->analog_data.analog32_lo = LOBYTE(Data); - reply_a->analog_data.analog32_hi = HIBYTE(Data); - - Data = (int)(edrk.temper_edrk.real_int_temper_u[0]); - reply_a->analog_data.analog33_lo = LOBYTE(Data); - reply_a->analog_data.analog33_hi = HIBYTE(Data); + reply_a->analog_data.analog31_lo = LOBYTE(Data); + reply_a->analog_data.analog31_hi = HIBYTE(Data); Data = (int)(edrk.temper_edrk.real_int_temper_u[1]); + reply_a->analog_data.analog32_lo = LOBYTE(Data); + reply_a->analog_data.analog32_hi = HIBYTE(Data); + Data = (int)(edrk.temper_edrk.real_int_temper_u[2]); + reply_a->analog_data.analog33_lo = LOBYTE(Data); + reply_a->analog_data.analog33_hi = HIBYTE(Data); + Data = (int)(edrk.temper_edrk.real_int_temper_u[3]); reply_a->analog_data.analog34_lo = LOBYTE(Data); reply_a->analog_data.analog34_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_u[2]); + Data = (int)(edrk.temper_edrk.real_int_temper_u[4]); reply_a->analog_data.analog35_lo = LOBYTE(Data); reply_a->analog_data.analog35_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_u[3]); + Data = (int)(edrk.temper_edrk.real_int_temper_u[5]); reply_a->analog_data.analog36_lo = LOBYTE(Data); reply_a->analog_data.analog36_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_u[4]); + Data = (int)(edrk.temper_edrk.real_int_temper_u[6]); reply_a->analog_data.analog37_lo = LOBYTE(Data); reply_a->analog_data.analog37_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_u[5]); + Data = (int)(edrk.temper_edrk.real_int_temper_air[0]); reply_a->analog_data.analog38_lo = LOBYTE(Data); reply_a->analog_data.analog38_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_u[6]); + Data = (int)(edrk.temper_edrk.real_int_temper_air[1]); reply_a->analog_data.analog39_lo = LOBYTE(Data); reply_a->analog_data.analog39_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_air[0]); + Data = (int)(edrk.temper_edrk.real_int_temper_air[2]); reply_a->analog_data.analog40_lo = LOBYTE(Data); reply_a->analog_data.analog40_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_air[1]); - reply_a->analog_data.analog41_lo = LOBYTE(Data); - reply_a->analog_data.analog41_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_air[2]); - reply_a->analog_data.analog42_lo = LOBYTE(Data); - reply_a->analog_data.analog42_hi = HIBYTE(Data); Data = (int)(edrk.temper_edrk.real_int_temper_air[3]); + reply_a->analog_data.analog41_lo = LOBYTE(Data); + reply_a->analog_data.analog41_hi = HIBYTE(Data); + Data = (int)(edrk.temper_edrk.real_int_temper_water[0]); // external + reply_a->analog_data.analog42_lo = LOBYTE(Data); + reply_a->analog_data.analog42_hi = HIBYTE(Data); + Data = (int)(edrk.temper_edrk.real_int_temper_water[1]); // internal reply_a->analog_data.analog43_lo = LOBYTE(Data); reply_a->analog_data.analog43_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_water[0]); // external + Data = (int)edrk.temper_acdrive.winding.max_real_int_temper; reply_a->analog_data.analog44_lo = LOBYTE(Data); reply_a->analog_data.analog44_hi = HIBYTE(Data); - Data = (int)(edrk.temper_edrk.real_int_temper_water[1]); // internal + Data = (int)edrk.temper_acdrive.bear.max_real_int_temper; reply_a->analog_data.analog45_lo = LOBYTE(Data); reply_a->analog_data.analog45_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidF.OutMax)*NORMA_ACP);//edrk.auto_master_slave.prev_status;//fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP); + Data = edrk.auto_master_slave.prev_status;//fast_round(_IQtoF(edrk.zadanie.iq_ZadanieU_Charge_rmp)*NORMA_ACP); reply_a->analog_data.analog46_lo = LOBYTE(Data); reply_a->analog_data.analog46_hi = HIBYTE(Data); @@ -321,14 +311,15 @@ Data = edrk.period_calc_pwm_int1; reply_a->analog_data.analog51_lo = LOBYTE(Data); reply_a->analog_data.analog51_hi = HIBYTE(Data); - Data = _IQtoF(vect_control.iqId2)*NORMA_ACP;//0;//fast_round( _IQtoF(edrk.zadanie.iq_k_u_disbalance_rmp)*100.0); + Data = fast_round( _IQtoF(edrk.zadanie.iq_k_u_disbalance_rmp)*100.0); reply_a->analog_data.analog52_lo = LOBYTE(Data); reply_a->analog_data.analog52_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad_rmp)*NORMA_ACP*NORMA_ACP/1000.0); + Data = edrk.auto_master_slave.status;//fast_round(_IQtoF(edrk.zadanie.iq_kplus_u_disbalance_rmp)*1000.0); reply_a->analog_data.analog53_lo = LOBYTE(Data); reply_a->analog_data.analog53_hi = HIBYTE(Data); + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { Data = fast_round(_IQtoF(turns.pidFvect.Out)*NORMA_ACP); reply_a->analog_data.analog54_lo = LOBYTE(Data); @@ -344,7 +335,7 @@ Data = edrk.period_calc_pwm_int1; Data = fast_round(_IQtoF(simple_scalar1.pidF.Out)*NORMA_ACP); reply_a->analog_data.analog54_lo = LOBYTE(Data); reply_a->analog_data.analog54_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(simple_scalar1.pidF.OutMin)*NORMA_ACP); + Data = fast_round(_IQtoF(simple_scalar1.pidF.OutMax)*NORMA_ACP); reply_a->analog_data.analog55_lo = LOBYTE(Data); reply_a->analog_data.analog55_hi = HIBYTE(Data); Data =fast_round(_IQtoF(simple_scalar1.pidPower.Out)*NORMA_ACP); @@ -355,18 +346,13 @@ Data = edrk.period_calc_pwm_int1; reply_a->analog_data.analog57_lo = LOBYTE(Data); reply_a->analog_data.analog57_hi = HIBYTE(Data); - - - Data = fast_round(_IQtoF(simple_scalar1.Izad)*NORMA_ACP); reply_a->analog_data.analog58_lo = LOBYTE(Data); reply_a->analog_data.analog58_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(edrk.master_Iq)*NORMA_ACP); reply_a->analog_data.analog59_lo = LOBYTE(Data); reply_a->analog_data.analog59_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.mzz_zad_in2)*NORMA_ACP);//count_transmited++; + Data = fast_round(_IQtoF(simple_scalar1.mzz_zad)*NORMA_ACP);//count_transmited++; reply_a->analog_data.analog60_lo = LOBYTE(Data); reply_a->analog_data.analog60_hi = HIBYTE(Data); // @@ -386,153 +372,25 @@ Data = edrk.period_calc_pwm_int1; reply_a->analog_data.analog64_lo = LOBYTE(Data); reply_a->analog_data.analog64_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(simple_scalar1.pidPower.SatErr)*NORMA_ACP);//project.cds_tk[3].optical_data_in.local_count_error; + Data = project.cds_tk[3].optical_data_in.local_count_error; reply_a->analog_data.analog65_lo = LOBYTE(Data); reply_a->analog_data.analog65_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(simple_scalar1.pidPower.Fdb)*NORMA_ACP*NORMA_ACP/1000.0);//project.cds_tk[3].optical_data_out.local_count_error; + Data = project.cds_tk[3].optical_data_out.local_count_error; reply_a->analog_data.analog66_lo = LOBYTE(Data); reply_a->analog_data.analog66_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(simple_scalar1.pidPower.Ref)*NORMA_ACP*NORMA_ACP/1000.0);//////optical_read_data.count_error_wdog; + Data = optical_read_data.count_error_wdog; reply_a->analog_data.analog67_lo = LOBYTE(Data); reply_a->analog_data.analog67_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidPower.Up)*NORMA_ACP);//edrk.auto_master_slave.status;//fast_round(_IQtoF(edrk.zadanie.iq_kplus_u_disbalance_rmp)*1000.0); + Data = edrk.period_calc_pwm_int2; reply_a->analog_data.analog68_lo = LOBYTE(Data); reply_a->analog_data.analog68_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(pll1.vars.pll_Uq)*NORMA_ACP); - reply_a->analog_data.analog69_lo = LOBYTE(Data); - reply_a->analog_data.analog69_hi = HIBYTE(Data); - Data = fast_round(_IQtoF(pll1.vars.pll_Ud)*NORMA_ACP); - reply_a->analog_data.analog70_lo = LOBYTE(Data); - reply_a->analog_data.analog70_hi = HIBYTE(Data); - -Data = fast_round(_IQtoF(simple_scalar1.bpsi_curent)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog71_lo = LOBYTE(Data); - reply_a->analog_data.analog71_hi = HIBYTE(Data); - -Data = fast_round(_IQtoF(WRotor.iqWRotorSumFilter2)*NORMA_FROTOR*1000.0); //iqFlong - reply_a->analog_data.analog72_lo = LOBYTE(Data); - reply_a->analog_data.analog72_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorCalc1)*NORMA_FROTOR*1000.0); -Data = fast_round(_IQtoF(edrk.from_uom.iq_level_value_kwt)*NORMA_ACP*NORMA_ACP/1000.0);// ;//edrk.from_uom.level_value;//fast_round(_IQtoF(rotor_22220.iqFdirty)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog73_lo = LOBYTE(Data); - reply_a->analog_data.analog73_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorCalc2)*NORMA_FROTOR*1000.0); -Data = _IQtoF(vect_control.iqIq2)*NORMA_ACP;//0;//fast_round(_IQtoF(rotor_22220.iqF)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog74_lo = LOBYTE(Data); - reply_a->analog_data.analog74_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulsesBeforeRegul1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY; -Data = fast_round(_IQtoF(WRotor.iqWRotorSumFilter)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog75_lo = LOBYTE(Data); - reply_a->analog_data.analog75_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulsesBeforeRegul2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU; -Data = fast_round(_IQtoF(simple_scalar1.mzz_zad_int)*NORMA_ACP);//;//0;//fast_round(_IQtoF(rotor_22220.iqFlong)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog76_lo = LOBYTE(Data); - reply_a->analog_data.analog76_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulses1)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY; - Data = _IQtoF(simple_scalar1.Izad)*NORMA_ACP_RMS;// 0;//fast_round(_IQtoF(WRotor.iqWRotorSumRamp)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog77_lo = LOBYTE(Data); - reply_a->analog_data.analog77_hi = HIBYTE(Data); - -//Data = fast_round(_IQtoF(WRotor.iqWRotorImpulses2)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU; - Data = WRotor.RotorDirectionSlow; - reply_a->analog_data.analog78_lo = LOBYTE(Data); - reply_a->analog_data.analog78_hi = HIBYTE(Data); - -Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgran)*1000.0);//0;//fast_round(_IQtoF(WRotor.iqWRotorSum)*NORMA_FROTOR*1000.0);// edrk.W_from_DISPLAY; - reply_a->analog_data.analog79_lo = LOBYTE(Data); - reply_a->analog_data.analog79_hi = HIBYTE(Data); - -Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter)*NORMA_FROTOR*1000.0);//600.0*1000000000.0/WRotor.iqWRotorImpulses1;//edrk.W_from_SVU; - reply_a->analog_data.analog80_lo = LOBYTE(Data); - reply_a->analog_data.analog80_hi = HIBYTE(Data); - - Data = log_params.cur_volume_of_slow_log;//edrk.power_kw_full; //Мощность двигателя текущая кВт -// Data = (_IQtoF((analog.Power) * 9000.0)); //Мощность двигателя текущая кВт - //_IQtoF(analog.iqIin_1)*NORMA_ACP;//project.adc[0].read.pbus.adc_value[0]; - reply_a->analog_data.analog81_lo = LOBYTE(Data); - reply_a->analog_data.analog81_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad)*NORMA_ACP*NORMA_ACP/1000.0); - reply_a->analog_data.analog82_lo = LOBYTE(Data); - reply_a->analog_data.analog82_hi = HIBYTE(Data); - - Data = break_result_1;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog83_lo = LOBYTE(Data); - reply_a->analog_data.analog83_hi = HIBYTE(Data); - - Data = break_result_2;//WRotorPBus.RotorDirectionInstant; - reply_a->analog_data.analog84_lo = LOBYTE(Data); - reply_a->analog_data.analog84_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(edrk.all_limit_koeffs.sum_limit)*1000.0);//WRotorPBus.RotorDirectionCount; - reply_a->analog_data.analog85_lo = LOBYTE(Data); - reply_a->analog_data.analog85_hi = HIBYTE(Data); - - - Data = fast_round(_IQtoF(edrk.all_limit_koeffs.uom_limit)*1000.0);//WRotorPBus.RotorDirectionSlow2; - reply_a->analog_data.analog86_lo = LOBYTE(Data); - reply_a->analog_data.analog86_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(edrk.all_limit_koeffs.uin_freq_limit)*1000.0);//fast_round(_IQtoF(WRotor.iqWRotorSumRamp)*NORMA_FROTOR*1000.0); - reply_a->analog_data.analog87_lo = LOBYTE(Data); - reply_a->analog_data.analog87_hi = HIBYTE(Data); - - Data = _IQtoF(simple_scalar1.Im_regul)*NORMA_ACP_RMS;//(edrk.cantec_reg & 0xff);//edrk.pult_data.TimeToChangePump_from_pult;//0;//fast_round(_IQtoF(WRotor.iqWRotorCalc1Ramp)*NORMA_FROTOR*1000.0);;//WRotor.iqWRotorCalc1Ramp - reply_a->analog_data.analog88_lo = LOBYTE(Data); - reply_a->analog_data.analog88_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidPower.Ui)*NORMA_ACP);//(edrk.canrec_reg & 0xff);;//edrk.pult_data.nPCH_from_pult;//0;//fast_round(_IQtoF(WRotor.iqWRotorCalc2Ramp)*NORMA_FROTOR*1000.0);; - reply_a->analog_data.analog89_lo = LOBYTE(Data); - reply_a->analog_data.analog89_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidF.Fdb)*NORMA_FROTOR*1000.0);//(((unsigned long)edrk.canes_reg>>16) & 0x01ff); - reply_a->analog_data.analog90_lo = LOBYTE(Data); - reply_a->analog_data.analog90_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidF.Ref)*NORMA_FROTOR*1000.0);//(((unsigned long)edrk.canes_reg) & 0x3f); - reply_a->analog_data.analog91_lo = LOBYTE(Data); - reply_a->analog_data.analog91_hi = HIBYTE(Data); - - - Data = fast_round(_IQtoF(simple_scalar1.pidF.SatErr)*NORMA_ACP);//CanBusOffError;//0; - reply_a->analog_data.analog92_lo = LOBYTE(Data); - reply_a->analog_data.analog92_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidF.Ui)*NORMA_ACP);//CanTimeOutErrorTR;//0; - reply_a->analog_data.analog93_lo = LOBYTE(Data); - reply_a->analog_data.analog93_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.pidF.Up)*NORMA_ACP);//0; - reply_a->analog_data.analog94_lo = LOBYTE(Data); - reply_a->analog_data.analog94_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.iq_decr_mzz_power)*1000.0);//0;//simple_scalar1.k_ogr_n - reply_a->analog_data.analog95_lo = LOBYTE(Data); - reply_a->analog_data.analog95_hi = HIBYTE(Data); - - Data = fast_round(_IQtoF(simple_scalar1.iq_decr_mzz_power_filter)*1000.0);//fast_round(_IQtoF(edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus1)*NORMA_FROTOR*60.0*450.0*1000.0); - reply_a->analog_data.analog96_lo = LOBYTE(Data); - reply_a->analog_data.analog96_hi = HIBYTE(Data); - -// Data = 0; -// reply_a->analog_data.analog97_lo = LOBYTE(Data); -// reply_a->analog_data.analog97_hi = HIBYTE(Data); - - - - pByte = &reply_a->digit_data.byte01.byte_data; - for (i = 0; i < 59; i++) //zero all dig data + pByte = &reply_a->digit_data.byte01.byte_data; + for (i = 0; i < 44; i++) //zero all dig data { *(pByte + i) = 0; } @@ -573,11 +431,6 @@ Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_roun reply_a->digit_data.byte13.bit_data.bit2 = edrk.from_second_pch.bits.MASTER; reply_a->digit_data.byte13.bit_data.bit3 = edrk.from_second_pch.bits.RASCEPITEL; - reply_a->digit_data.byte13.bit_data.bit4 = edrk.warning; - reply_a->digit_data.byte13.bit_data.bit5 = edrk.overheat; - reply_a->digit_data.byte13.bit_data.bit6 = edrk.summ_errors; - reply_a->digit_data.byte13.bit_data.bit7 = edrk.Status_Ready.bits.ready_final; - // reply_a->digit_data.byte13.byte_data = edrk.errors.e6.all & 0xff; // reply->digit_data.byte14.byte_data = (edrk.errors.e6.all >> 8) & 0xff; @@ -717,12 +570,8 @@ Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_roun reply_a->digit_data.byte36.bit_data.bit1 = edrk.ms.ready1; reply_a->digit_data.byte36.bit_data.bit2 = edrk.ms.ready2; reply_a->digit_data.byte36.bit_data.bit3 = edrk.flag_wait_both_ready2; - reply_a->digit_data.byte36.bit_data.bit4 = edrk.Ready1_another_bs; - reply_a->digit_data.byte36.bit_data.bit5 = edrk.Ready2_another_bs; - reply_a->digit_data.byte36.bit_data.bit6 = edrk.flag_another_bs_first_ready12; - reply_a->digit_data.byte36.bit_data.bit7 = edrk.flag_this_bs_first_ready12; - - + reply_a->digit_data.byte36.bit_data.bit3 = edrk.flag_wait_both_ready2; + reply_a->digit_data.byte36.bit_data.bit3 = edrk.flag_wait_both_ready2; reply_a->digit_data.byte37.byte_data = edrk.errors.e8.all & 0xff; @@ -742,11 +591,6 @@ Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_roun reply_a->digit_data.byte40.bit_data.bit2 = edrk.StartGED; reply_a->digit_data.byte40.bit_data.bit3 = edrk.GoWait; - reply_a->digit_data.byte40.bit_data.bit4 = edrk.stop_logs_rs232; - reply_a->digit_data.byte40.bit_data.bit5 = edrk.stop_slow_log; - - reply_a->digit_data.byte40.bit_data.bit6 = edrk.disable_limit_power_from_svu; - reply_a->digit_data.byte40.bit_data.bit7 = edrk.disable_uom; reply_a->digit_data.byte41.byte_data = edrk.errors.e9.all & 0xff; reply_a->digit_data.byte42.byte_data = (edrk.errors.e9.all >> 8) & 0xff; @@ -792,116 +636,32 @@ Data = fast_round(_IQtoF(simple_scalar1.iqKoefOgranIzad)*1000.0);//0;//fast_roun // edrk.from_ing1.bits.RASCEPITEL_ON = FROM_ING_RASCEPITEL_ON_OFF; reply_a->digit_data.byte49.bit_data.bit6 = edrk.from_ing2.bits.SOST_ZAMKA; - reply_a->digit_data.byte49.bit_data.bit7 = edrk.from_shema_filter.bits.RAZBOR_SHEMA; + reply_a->digit_data.byte49.bit_data.bit7 = edrk.from_shema.bits.RAZBOR_SHEMA; // - reply_a->digit_data.byte50.bit_data.bit0 = edrk.from_shema_filter.bits.SBOR_SHEMA; + reply_a->digit_data.byte50.bit_data.bit0 = edrk.from_shema.bits.SBOR_SHEMA; - reply_a->digit_data.byte50.bit_data.bit1 = edrk.from_shema_filter.bits.ZADA_DISPLAY; - reply_a->digit_data.byte50.bit_data.bit2 = edrk.from_shema_filter.bits.SVU; + reply_a->digit_data.byte50.bit_data.bit1 = edrk.from_shema.bits.ZADA_DISPLAY; + reply_a->digit_data.byte50.bit_data.bit2 = edrk.from_shema.bits.SVU; // edrk.from_shema.bits.KNOPKA_AVARIA = FROM_ALL_KNOPKA_AVARIA; reply_a->digit_data.byte50.bit_data.bit3 = edrk.from_shema.bits.QTV_ON_OFF; - reply_a->digit_data.byte50.bit_data.bit4 = edrk.from_shema_filter.bits.UMP_ON_OFF; - reply_a->digit_data.byte50.bit_data.bit5 = edrk.from_shema_filter.bits.READY_UMP; + reply_a->digit_data.byte50.bit_data.bit4 = edrk.from_shema.bits.UMP_ON_OFF; + reply_a->digit_data.byte50.bit_data.bit5 = edrk.from_shema.bits.READY_UMP; reply_a->digit_data.byte50.bit_data.bit6 = edrk.from_shema.bits.SVU_BLOCK_QTV; - reply_a->digit_data.byte50.bit_data.bit7 = edrk.errors_another_bs_from_can; - // reply_a->digit_data.byte44.byte_data = 0; - reply_a->digit_data.byte51.bit_data.bit0 = inc_sensor.break_sensor1; - reply_a->digit_data.byte51.bit_data.bit1 = inc_sensor.break_sensor2; - reply_a->digit_data.byte51.bit_data.bit2 = pll1.output.flag_find_pll; - reply_a->digit_data.byte51.bit_data.bit3 = log_params.stop_log_slow; - reply_a->digit_data.byte51.bit_data.bit4 = log_params.stop_log_level_1; - reply_a->digit_data.byte51.bit_data.bit5 = log_params.stop_log_level_2; - reply_a->digit_data.byte51.bit_data.bit6 = log_params.stop_log_slow_level_1; - reply_a->digit_data.byte51.bit_data.bit7 = log_params.stop_log_slow_level_2; - - - - reply_a->digit_data.byte52.bit_data.bit0 = edrk.from_zadat4ik.bits.KVITIR; - reply_a->digit_data.byte52.bit_data.bit1 = edrk.from_zadat4ik.bits.PLUS; - reply_a->digit_data.byte52.bit_data.bit2 = edrk.from_zadat4ik.bits.MINUS; - reply_a->digit_data.byte52.bit_data.bit3 = edrk.from_zadat4ik.bits.PROVOROT; - reply_a->digit_data.byte52.bit_data.bit4 = edrk.from_zadat4ik.bits.UOM_READY_ACTIVE; - reply_a->digit_data.byte52.bit_data.bit5 = edrk.from_zadat4ik.bits.UOM_LIMIT_3; - reply_a->digit_data.byte52.bit_data.bit6 = edrk.from_zadat4ik.bits.UOM_LIMIT_2; - reply_a->digit_data.byte52.bit_data.bit7 = edrk.from_zadat4ik.bits.UOM_LIMIT_1; - - - - reply_a->digit_data.byte53.bit_data.bit0 = edrk.Run_UMP; - reply_a->digit_data.byte53.bit_data.bit1 = edrk.Status_UMP_Ok; - reply_a->digit_data.byte53.bit_data.bit2 = edrk.Zaryad_UMP_Ok; - reply_a->digit_data.byte53.bit_data.bit3 = edrk.cmd_to_ump; - reply_a->digit_data.byte53.bit_data.bit4 = edrk.sbor_wait_ump1; - reply_a->digit_data.byte53.bit_data.bit5 = edrk.sbor_wait_ump2; - reply_a->digit_data.byte53.bit_data.bit6 = edrk.flag_enable_on_ump; - - reply_a->digit_data.byte53.bit_data.bit7 = edrk.local_ump_on_off; - reply_a->digit_data.byte54.bit_data.bit0 = edrk.local_ready_ump; - -/// - reply_a->digit_data.byte54.bit_data.bit1 = (modbus_table_can_in[128].all) ? 1 : 0; //cmd_local_charge PCH 0 - reply_a->digit_data.byte54.bit_data.bit2 = (modbus_table_can_in[131].all) ? 1 : 0; //cmd_local_uncharge PCH 0 - - reply_a->digit_data.byte54.bit_data.bit3 = (modbus_table_can_in[129].all) ? 1 : 0; //cmd_local_charge PCH 1 - reply_a->digit_data.byte54.bit_data.bit4 = (modbus_table_can_in[132].all) ? 1 : 0; //cmd_local_uncharge PCH 1 - - reply_a->digit_data.byte54.bit_data.bit5 = edrk.from_shema_filter.bits.UMP_ON_OFF; - reply_a->digit_data.byte54.bit_data.bit6 = edrk.SumSbor; - - reply_a->digit_data.byte55.bit_data.bit0 = edrk.power_limit.bits.limit_Iout; - reply_a->digit_data.byte55.bit_data.bit1 = edrk.power_limit.bits.limit_UOM; - reply_a->digit_data.byte55.bit_data.bit2 = edrk.power_limit.bits.limit_by_temper; - reply_a->digit_data.byte55.bit_data.bit3 = edrk.power_limit.bits.limit_from_SVU; - reply_a->digit_data.byte55.bit_data.bit4 = edrk.power_limit.bits.limit_from_uom_fast; - reply_a->digit_data.byte55.bit_data.bit5 = edrk.power_limit.bits.limit_from_freq; - reply_a->digit_data.byte55.bit_data.bit6 = edrk.power_limit.bits.limit_moment; - reply_a->digit_data.byte55.bit_data.bit7 = simple_scalar1.flag_decr_mzz_power; - - - reply_a->digit_data.byte56.bit_data.bit0 = (edrk.pult_cmd.log_what_memory & 0x1) ? 1 : 0; - reply_a->digit_data.byte56.bit_data.bit1 = (edrk.pult_cmd.log_what_memory & 0x2) ? 1 : 0; - - reply_a->digit_data.byte56.bit_data.bit2 = edrk.pult_data.flagSaveDataMoto ? 1 : 0; - - reply_a->digit_data.byte56.bit_data.bit3 = (edrk.pult_data.flagSaveSlowLogs) ? 1 : 0; - reply_a->digit_data.byte56.bit_data.bit4 = edrk.pult_cmd.send_log ? 1 : 0; - - reply_a->digit_data.byte56.bit_data.bit5 = (log_to_HMI.send_log==1) ? 1 : 0; - reply_a->digit_data.byte56.bit_data.bit6 = (log_to_HMI.send_log==2) ? 1 : 0; - reply_a->digit_data.byte56.bit_data.bit7 = (log_to_HMI.send_log==3) ? 1 : 0; - -// - reply_a->digit_data.byte57.bit_data.bit0 = (edrk.break_tempers[0] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit1 = (edrk.break_tempers[1] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit2 = (edrk.break_tempers[2] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit3 = (edrk.break_tempers[3] > ABNORMAL_TEMPER_BREAK_INT) ? 1 : 0; - - reply_a->digit_data.byte57.bit_data.bit4 = (edrk.break_tempers[0] > ALARM_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit5 = (edrk.break_tempers[1] > ALARM_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit6 = (edrk.break_tempers[2] > ALARM_TEMPER_BREAK_INT) ? 1 : 0; - reply_a->digit_data.byte57.bit_data.bit7 = (edrk.break_tempers[3] > ALARM_TEMPER_BREAK_INT) ? 1 : 0; - - reply_a->digit_data.byte58.bit_data.bit0 = (edrk.breaker_on==1) ? 1 : 0; - - reply_a->digit_data.byte58.bit_data.bit1 = edrk.warnings.e9.bits.BREAK_TEMPER_WARNING; - reply_a->digit_data.byte58.bit_data.bit2 = edrk.warnings.e9.bits.BREAK_TEMPER_ALARM; - reply_a->digit_data.byte58.bit_data.bit3 = edrk.warnings.e9.bits.BREAKER_GED_ON; - - - -// reply_a->digit_data.byte57.byte_data = 0;//(((unsigned long)edrk.canes_reg>>16) & 0x0ff); -// reply_a->digit_data.byte58.byte_data = 0;//(((unsigned long)edrk.canes_reg) & 0x3f); - reply_a->digit_data.byte59.byte_data = 0;//(((unsigned long)edrk.canes_reg>>24) & 0x1); - reply_a->digit_data.byte60.byte_data = 0; - return; + + + + + + + return; } diff --git a/Inu/Src/main/message2test.c b/Inu/Src/main/message2test.c index fbcff9e..89fc6ef 100644 --- a/Inu/Src/main/message2test.c +++ b/Inu/Src/main/message2test.c @@ -13,8 +13,6 @@ #include "xp_project.h" #include "x_wdog.h" -#include "params_hwp.h" -#include "detect_errors.h" //XilinxV2 @@ -24,7 +22,7 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM { // онтрольнаy сумма unsigned int crc, DataOut, sinusImpulse, doubleImpulse,adc_plate; - int Data,Data1,Data2/*,bitt, DataAnalog1, DataAnalog2*/, tk0,tk1,tk2,tk3,period1,period2, period3; + int Data,Data1,Data2/*,bitt, DataAnalog1, DataAnalog2*/, tk0,tk1,tk2,tk3,period1,period2; //static int vs11,vs12,vs1; static int prev_Go = 0; @@ -33,12 +31,6 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM static int flag_prev_turn_on = 0; static int flag_prev_turn_off = 0; static int flag_prev_lamp_on_off = 0; - static int soft_off_enable = 0, soft_on_enable = 0; - static float tk_time_soft_off = 0; - static unsigned long tk_time_soft_off_d = 0; - static unsigned int i_af_protect_a = 0, i_af_protect_d = 0; - int enable_line_err = 0, disable_tk_soft_off, disable_protect_tk_soft_off; - stop_wdog(); @@ -54,16 +46,7 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM // f.RScount = SECOND*3; f.terminal_prepare = pcommand->digit_data.byte05.bit_data.bit1; - soft_off_enable = pcommand->digit_data.byte06.bit_data.bit0; - soft_on_enable = pcommand->digit_data.byte06.bit_data.bit1; -// edrk.direct_write_out = pcommand->digit_data.byte06.bit_data.bit2; - - disable_tk_soft_off = pcommand->digit_data.byte06.bit_data.bit3; - disable_protect_tk_soft_off = pcommand->digit_data.byte06.bit_data.bit4; - - enable_line_err = pcommand->digit_data.byte06.bit_data.bit5; - - // Записали все выходы + // "аписали все выходы #if (CHECK_IN_OUT_TERMINAL==1) @@ -89,9 +72,7 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM // write_dig_out(); - //calc_norm_ADC(0); - calc_norm_ADC_0(1); - calc_norm_ADC_1(1); + calc_norm_ADC(0); // проверка ключей tk0 = (pcommand->digit_data.byte01.byte_data); @@ -109,39 +90,6 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM Data = (Data2 + Data1*256); period2 = Data; - Data1 = pcommand->analog_data.analog3_hi; - Data2 = pcommand->analog_data.analog3_lo; - Data = (Data2 + Data1*256); - period3 = Data; - - Data1 = pcommand->analog_data.analog4_hi; - Data2 = pcommand->analog_data.analog4_lo; - Data = (Data2 + Data1*256); - // Data = 200; - tk_time_soft_off = Data*100.0; // mks*10->ns - if (tk_time_soft_off>1300000.0) - tk_time_soft_off = 1300000.0; - tk_time_soft_off_d = (unsigned long)(tk_time_soft_off / DIV_TIME_TK_SOFT_OFF); - - if (tk_time_soft_off_d>65535) - tk_time_soft_off_d = 65535; - - - Data1 = pcommand->analog_data.analog5_hi; - Data2 = pcommand->analog_data.analog5_lo; - Data = (Data2 + Data1*256); - i_af_protect_a = Data; - - if (i_af_protect_a>LEVEL_HWP_I_AF) i_af_protect_a = LEVEL_HWP_I_AF; - if (i_af_protect_a<10) i_af_protect_a = 10; - i_af_protect_d = convert_real_to_mv_hwp(4,i_af_protect_a); - if (i_af_protect_d>1500) i_af_protect_d = 1500; // max 1500 mV - - update_maz_level_i_af(0, i_af_protect_d); - project.read_all_hwp(); - - - if(pcommand->digit_data.byte05.bit_data.bit3 == 1) doubleImpulse = 1; else @@ -154,43 +102,8 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM if ((pcommand->digit_data.byte05.bit_data.bit0 == 1) && (prev_Go == 0)) { - if (pcommand->digit_data.byte05.bit_data.bit2 == 1) // при цикл импульсе предварительно даем квитирование - { - update_maz_level_i_af(0, 1500); - project.write_all_hwp(); - clear_errors(); - project.clear_errors_all_plates(); - update_maz_level_i_af(0, i_af_protect_d); - project.write_all_hwp(); - - } - - // test_tk_ak_one_impulse( tk0, tk1, tk2, tk3, period1, period2); -#if (USE_TK_0) - project.cds_tk[0].write.sbus.protect_error.bit.enable_soft_disconnect = !disable_tk_soft_off; - project.cds_tk[0].write.sbus.protect_error.bit.detect_soft_disconnect = !disable_protect_tk_soft_off; - project.cds_tk[0].write.sbus.protect_error.bit.enable_line_err = enable_line_err; - project.cds_tk[0].write.sbus.time_after_err = tk_time_soft_off_d;//(int)(tk_time_soft_off / DIV_TIME_TK_SOFT_OFF); -#endif -#if (USE_TK_1) - project.cds_tk[1].write.sbus.protect_error.bit.enable_soft_disconnect = !disable_tk_soft_off; - project.cds_tk[1].write.sbus.protect_error.bit.detect_soft_disconnect = !disable_protect_tk_soft_off; - project.cds_tk[1].write.sbus.protect_error.bit.enable_line_err = enable_line_err; - project.cds_tk[1].write.sbus.time_after_err = tk_time_soft_off_d;//(int)(tk_time_soft_off / DIV_TIME_TK_SOFT_OFF); -#endif -#if (USE_TK_3) - project.cds_tk[3].write.sbus.protect_error.bit.enable_soft_disconnect = !disable_tk_soft_off; - project.cds_tk[3].write.sbus.protect_error.bit.detect_soft_disconnect = !disable_protect_tk_soft_off; - project.cds_tk[3].write.sbus.protect_error.bit.enable_line_err = enable_line_err; - project.cds_tk[3].write.sbus.time_after_err = tk_time_soft_off_d;//(int)(tk_time_soft_off / DIV_TIME_TK_SOFT_OFF); -#endif - - - project.write_all_sbus(); - project.write_all_hwp(); - - test_tk_ak_one_impulse( tk0, tk1, tk2, tk3, period1, period2, period3, doubleImpulse, sinusImpulse, soft_off_enable, soft_on_enable); + test_tk_ak_one_impulse( tk0, tk1, tk2, tk3, period1, period2, doubleImpulse, sinusImpulse); } if ((pcommand->digit_data.byte05.bit_data.bit0 == 1) && @@ -206,19 +119,14 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM if (pcommand->digit_data.byte05.bit_data.bit1==1) { stop_wdog(); - update_maz_level_i_af(0, 1500); - project.write_all_hwp(); - clear_errors(); project.clear_errors_all_plates(); - update_maz_level_i_af(0, i_af_protect_d); - project.write_all_hwp(); + } } prev_Prepare = pcommand->digit_data.byte05.bit_data.bit1; if (pcommand->digit_data.byte05.bit_data.bit2 == 1) { - prev_Go = 0; // зациклили Go } @@ -372,46 +280,17 @@ void func_fill_answer_to_TMS_test(TMS_TO_TERMINAL_TEST_ALL_STRUCT* reply_ans, CM reply_test_all.analog_data.analog16_lo=LOBYTE(Data); reply_test_all.analog_data.analog16_hi=HIBYTE(Data); - - Data = _IQtoF(analog.iqU_1) * NORMA_ACP; - reply_ans->analog_data.analog17_lo=LOBYTE(Data); - reply_ans->analog_data.analog17_hi=HIBYTE(Data); - - Data = _IQtoF(analog.iqU_2) * NORMA_ACP; - reply_ans->analog_data.analog18_lo=LOBYTE(Data); - reply_ans->analog_data.analog18_hi=HIBYTE(Data); - - Data = project.cds_tk[0].read.sbus.time_err_tk_all.bit.tk_3210; +/* + Data = _IQtoF(analog.iqU_3) * NORMA_ACP; reply_ans->analog_data.analog19_lo=LOBYTE(Data); reply_ans->analog_data.analog19_hi=HIBYTE(Data); - Data = project.cds_tk[0].read.sbus.time_err_tk_all.bit.tk_7654; + Data = _IQtoF(analog.iqU_4) * NORMA_ACP; reply_ans->analog_data.analog20_lo=LOBYTE(Data); reply_ans->analog_data.analog20_hi=HIBYTE(Data); - Data = project.cds_tk[1].read.sbus.time_err_tk_all.bit.tk_3210; - reply_ans->analog_data.analog21_lo=LOBYTE(Data); - reply_ans->analog_data.analog21_hi=HIBYTE(Data); +*/ - Data = project.cds_tk[1].read.sbus.time_err_tk_all.bit.tk_7654; - reply_ans->analog_data.analog22_lo=LOBYTE(Data); - reply_ans->analog_data.analog22_hi=HIBYTE(Data); - - Data = project.cds_tk[2].read.sbus.time_err_tk_all.bit.tk_3210; - reply_ans->analog_data.analog23_lo=LOBYTE(Data); - reply_ans->analog_data.analog23_hi=HIBYTE(Data); - - Data = project.cds_tk[2].read.sbus.time_err_tk_all.bit.tk_7654; - reply_ans->analog_data.analog24_lo=LOBYTE(Data); - reply_ans->analog_data.analog24_hi=HIBYTE(Data); - -// Data = project.cds_tk[3].read.sbus.time_err_tk_all.bit.tk_3210; -// reply_ans->analog_data.analog25_lo=LOBYTE(Data); -// reply_ans->analog_data.analog25_hi=HIBYTE(Data); -// -// Data = project.cds_tk[3].read.sbus.time_err_tk_all.bit.tk_7654; -// reply_ans->analog_data.analog26_lo=LOBYTE(Data); -// reply_ans->analog_data.analog26_hi=HIBYTE(Data); reply_ans->digit_data.byte01.byte_data = 0; reply_ans->digit_data.byte02.byte_data = 0; @@ -514,16 +393,8 @@ reply_ans->digit_data.byte24.byte_data = 0; reply_ans->digit_data.byte19.bit_data.bit6 = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,UMU_CAN_DEVICE)]; //reply.digit_data.byte21.bit_data.bit7 = CAN_timeout[VPU1_CAN_DEVICE]; - reply_ans->digit_data.byte20.bit_data.bit0 = project.controller.read.errors.bit.er0_out; - reply_ans->digit_data.byte20.bit_data.bit1 = project.controller.read.errors.bit.er0_trig; - reply_ans->digit_data.byte20.bit_data.bit2 = project.controller.read.errors.bit.errHWP; - reply_ans->digit_data.byte20.bit_data.bit3 = project.controller.read.errors.bit.errHWP_trig; - reply_ans->digit_data.byte20.bit_data.bit4 = project.controller.read.errors.bit.error_pbus; - reply_ans->digit_data.byte20.bit_data.bit5 = project.controller.read.errors.bit.pwm_wdog; - reply_ans->digit_data.byte20.bit_data.bit6 = project.controller.read.errors.bit.status_er0; -// reply_ans->digit_data.byte20.bit_data.bit0 = project.controller.read.errors.bit.er0_out; -// reply_ans->digit_data.byte20.bit_data.bit0 = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,VPU_CAN)]; -// reply_ans->digit_data.byte20.bit_data.bit1 = CAN_timeout[get_real_in_mbox(MPU_TYPE_BOX,0)]; + reply_ans->digit_data.byte20.bit_data.bit0 = CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,VPU_CAN)]; + reply_ans->digit_data.byte20.bit_data.bit1 = CAN_timeout[get_real_in_mbox(MPU_TYPE_BOX,0)]; reply_ans->digit_data.byte20.bit_data.bit2 = 0;//READY_UKSS_6; reply_ans->digit_data.byte20.bit_data.bit3 = 0;//READY_UKSS_7; reply_ans->digit_data.byte20.bit_data.bit4 = 0;//READY_UKSS_8; @@ -565,82 +436,8 @@ reply_ans->digit_data.byte24.byte_data = 0; reply_ans->digit_data.byte23.byte_data=project.hwp[0].read.comp_s.minus.all & 0x00ff; reply_ans->digit_data.byte24.byte_data=((project.hwp[0].read.comp_s.minus.all >> 8) & 0x00ff); - reply_ans->digit_data.byte23.byte_data|=project.hwp[0].read.comp_s.plus.all & 0x00ff; - reply_ans->digit_data.byte24.byte_data|=((project.hwp[0].read.comp_s.plus.all >> 8) & 0x00ff); - -#if (USE_TK_0) - if (project.cds_tk[0].useit) - { -// reply_ans->digit_data.byte22.bit_data.bit0 = project.cds_tk[0].read.sbus.lock_status_error.bit.err0_in; - reply_ans->digit_data.byte25.bit_data.bit0 = project.cds_tk[0].read.sbus.lock_status_error.bit.err_hwp; - reply_ans->digit_data.byte25.bit_data.bit1 = project.cds_tk[0].read.sbus.lock_status_error.bit.err0_local; - reply_ans->digit_data.byte25.bit_data.bit2 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_7654; - reply_ans->digit_data.byte25.bit_data.bit3 = project.cds_tk[0].read.sbus.lock_status_error.bit.mintime_err_keys_3210; - reply_ans->digit_data.byte25.bit_data.bit4 = project.cds_tk[0].read.sbus.lock_status_error.bit.line_err_keys_7654; - reply_ans->digit_data.byte25.bit_data.bit5 = project.cds_tk[0].read.sbus.lock_status_error.bit.line_err_keys_3210; - reply_ans->digit_data.byte25.bit_data.bit6 = project.cds_tk[0].read.sbus.lock_status_error.bit.ErrorSoftShutdownFromErr0; - reply_ans->digit_data.byte25.bit_data.bit7 = project.cds_tk[0].read.sbus.lock_status_error.bit.ErrorSoftShutdownForbidComb; - } - else - reply_ans->digit_data.byte25.byte_data = 0; - -#else - reply_ans->digit_data.byte25.byte_data = 0; -#endif - -#if (USE_TK_1) - if (project.cds_tk[1].useit) - { - reply_ans->digit_data.byte26.bit_data.bit0 = project.cds_tk[1].read.sbus.lock_status_error.bit.err_hwp; - reply_ans->digit_data.byte26.bit_data.bit1 = project.cds_tk[1].read.sbus.lock_status_error.bit.err0_local; - reply_ans->digit_data.byte26.bit_data.bit2 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_7654; - reply_ans->digit_data.byte26.bit_data.bit3 = project.cds_tk[1].read.sbus.lock_status_error.bit.mintime_err_keys_3210; - reply_ans->digit_data.byte26.bit_data.bit4 = project.cds_tk[1].read.sbus.lock_status_error.bit.line_err_keys_7654; - reply_ans->digit_data.byte26.bit_data.bit5 = project.cds_tk[1].read.sbus.lock_status_error.bit.line_err_keys_3210; - reply_ans->digit_data.byte26.bit_data.bit6 = project.cds_tk[1].read.sbus.lock_status_error.bit.ErrorSoftShutdownFromErr0; - reply_ans->digit_data.byte26.bit_data.bit7 = project.cds_tk[1].read.sbus.lock_status_error.bit.ErrorSoftShutdownForbidComb; - } - else - reply_ans->digit_data.byte26.byte_data = 0; -#else - reply_ans->digit_data.byte26.byte_data = 0; -#endif - -#if (USE_TK_2) - if (project.cds_tk[2].useit) - { - reply_ans->digit_data.byte27.bit_data.bit0 = project.cds_tk[2].read.sbus.lock_status_error.bit.err_hwp; - reply_ans->digit_data.byte27.bit_data.bit1 = project.cds_tk[2].read.sbus.lock_status_error.bit.err0_local; - reply_ans->digit_data.byte27.bit_data.bit2 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_7654; - reply_ans->digit_data.byte27.bit_data.bit3 = project.cds_tk[2].read.sbus.lock_status_error.bit.mintime_err_keys_3210; - reply_ans->digit_data.byte27.bit_data.bit4 = project.cds_tk[2].read.sbus.lock_status_error.bit.line_err_keys_7654; - reply_ans->digit_data.byte27.bit_data.bit5 = project.cds_tk[2].read.sbus.lock_status_error.bit.line_err_keys_3210; - reply_ans->digit_data.byte27.bit_data.bit6 = project.cds_tk[2].read.sbus.lock_status_error.bit.ErrorSoftShutdownFromErr0; - reply_ans->digit_data.byte27.bit_data.bit7 = project.cds_tk[2].read.sbus.lock_status_error.bit.ErrorSoftShutdownForbidComb; - } - else - reply_ans->digit_data.byte27.byte_data = 0; -#else - reply_ans->digit_data.byte27.byte_data = 0; -#endif - -#if (USE_TK_3) - if (project.cds_tk[3].useit) - { - reply_ans->digit_data.byte28.bit_data.bit0 = project.cds_tk[3].read.sbus.lock_status_error.bit.err_hwp; - reply_ans->digit_data.byte28.bit_data.bit1 = project.cds_tk[3].read.sbus.lock_status_error.bit.err0_local; - reply_ans->digit_data.byte28.bit_data.bit2 = project.cds_tk[3].read.sbus.lock_status_error.bit.mintime_err_keys_7654; - reply_ans->digit_data.byte28.bit_data.bit3 = project.cds_tk[3].read.sbus.lock_status_error.bit.mintime_err_keys_3210; - reply_ans->digit_data.byte28.bit_data.bit4 = project.cds_tk[3].read.sbus.lock_status_error.bit.line_err_keys_7654; - reply_ans->digit_data.byte28.bit_data.bit5 = project.cds_tk[3].read.sbus.lock_status_error.bit.line_err_keys_3210; - reply_ans->digit_data.byte28.bit_data.bit6 = project.cds_tk[3].read.sbus.lock_status_error.bit.ErrorSoftShutdownFromErr0; - reply_ans->digit_data.byte28.bit_data.bit7 = project.cds_tk[3].read.sbus.lock_status_error.bit.ErrorSoftShutdownForbidComb; - } - else - reply_ans->digit_data.byte28.byte_data = 0; -#else - reply_ans->digit_data.byte28.byte_data = 0; -#endif + reply_ans->digit_data.byte23.byte_data|=project.hwp[0].read.comp_s.minus.all & 0x00ff; + reply_ans->digit_data.byte24.byte_data|=((project.hwp[0].read.comp_s.minus.all >> 8) & 0x00ff); /* diff --git a/Inu/Src/main/message_modbus.c b/Inu/Src/main/message_modbus.c index 024db30..a2cf9b0 100644 --- a/Inu/Src/main/message_modbus.c +++ b/Inu/Src/main/message_modbus.c @@ -22,10 +22,6 @@ #include #include -#include "pwm_test_lines.h" -#include "params.h" -#include "logs_hmi.h" - //#include "can_setup_21300.h" //#include "modbus_can.h" @@ -168,7 +164,6 @@ void write_all_data_to_mpu_can(int run_force, unsigned int pause) static int cur_position_buf_modbus16_can = 0, prev_send_to_can = 0; int real_mbox; - unsigned int i; real_mbox = get_real_out_mbox(MPU_TYPE_BOX, edrk.flag_second_PCH); @@ -240,13 +235,6 @@ void write_all_data_to_mpu_can(int run_force, unsigned int pause) // modbus_table_can_out[ADR_CAN_TEST_PLUS_ONE].all++; } - // сохраняем во временной памяти перед началом передачи всего массива чтобы данные не менялись во время передачи - if (cur_position_buf_modbus16_can == 0) - { - for (i=0;i= SIZE_MODBUS_TABLE) count_write_to_modbus_can = SIZE_MODBUS_TABLE - cur_position_buf_modbus16_can; else @@ -261,8 +249,7 @@ void write_all_data_to_mpu_can(int run_force, unsigned int pause) MPU_TYPE_BOX, edrk.flag_second_PCH, cur_position_buf_modbus16_can + 1, -// &modbus_table_can_out[cur_position_buf_modbus16_can].all, - &modbus_table_can_out_temp[cur_position_buf_modbus16_can].all, + &modbus_table_can_out[cur_position_buf_modbus16_can].all, count_write_to_modbus_can, CAN_BOX_STANDART_ADR, CAN_BOX_PRIORITY_NORMAL); cur_position_buf_modbus16_can = cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN; @@ -412,9 +399,6 @@ void test_alive_pult_485(void) } -#define MAX_COUNT_WORK_IN_LOG 150 - - int modbusNetworkSharing(int flag_update_only_hmi) { static unsigned int old_time = 0 , old_time_refresh = 0, time_pause = TIME_PAUSE_MODBUS_REMOUTE; @@ -426,13 +410,8 @@ int modbusNetworkSharing(int flag_update_only_hmi) static int run_pause = 1, flag_next = 0, prev_flag_next = 0; static int last_ok_cmd=0; static int flag_only_one_cmd=0; - static int status_ok = 1, status_err = 0, flag_work_rs_send_log = 0, count_free = 0, count_work_in_log = 0; -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_20_ON; -#endif - RS232_WorkingWith(0,1,0); // вкл тип запрос-ответ для системы тайминга @@ -456,123 +435,21 @@ int modbusNetworkSharing(int flag_update_only_hmi) final_code = 0; - - switch(status) - { - case 0: - - old_time = global_time.miliseconds; - status = 1; - if (time_pause==0) - status = 2; - - break; - case 1: - // if (numberInT==0) - // { - if (detect_pause_milisec(time_pause,&old_time)) - status = 2; - // } - // else - // status = 2; - - break; - case 2: - enable_send_cmd = 1; - control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0; - status = 3; - old_time_status_3 = global_time.miliseconds; - - break; - case 3: - // // если мы в передаче логов и там пустая команда без обмена по rs485 - // if (flag_work_rs_send_log) - // { - // status = 0; - // status_ok++; - // if (status_ok<0) status_ok=1; - // } - - // не было передач по rs485 значит и ловить тут нечего! - if (rs_b.RS_DataWillSend2 == 0 && enable_send_cmd == 0) - { - status = 0; - status_ok++; - count_free++; - } - else - if (rs_b.RS_DataReadyAnswerAnalyze) - { -// i_led2_on_off(0); - - control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0; - control_station.count_ok_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++; - rs_b.RS_DataReadyAnswerAnalyze = 0; - rs_b.RS_DataWillSend2 = 0; - status = 0; - - if (last_ok_cmd==4) // прошла readAnalogDataFromRemote() см ниже - { - edrk.get_new_data_from_hmi = 1;// можно забрать данные? - edrk.get_new_data_from_hmi2 = 1;// можно забрать данные? - } - final_code = last_ok_cmd;//numberInT+1; - - //status_err = 0; - status_ok++; - } - else - { - if ( (control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485]>control_station.setup_time_detect_active_resend_485[CONTROL_STATION_INGETEAM_PULT_RS485]) - || (detect_pause_milisec(time_pause_status_3,&old_time_status_3)) ) - { - resetup_mpu_rs(&rs_b); - control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0; - rs_b.RS_DataWillSend2 = 0; - status = 0; - control_station.count_error_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++; - status_err++;// = 1; - } - - } - - if (status_ok<0) status_ok=1; - - break; - case 4: - - break; - case 5: - - break; - case 6: - - break; - default: - break; - - - - } - -/* if (status==0) { old_time = global_time.miliseconds; status = 1; - if (time_pause==0) - status = 2; } if (status==1) { -// if (numberInT==0) -// { + if (numberInT==0) + { if (detect_pause_milisec(time_pause,&old_time)) status = 2; -// } -// else -// status = 2; + } + else + status = 2; } if (status==2) @@ -585,21 +462,6 @@ int modbusNetworkSharing(int flag_update_only_hmi) if (status==3) { - if (rs_b.RS_DataWillSend2 == 0) - { - - count_free++; - - } - - // если мы в передаче логов и там пустая команда без обмена по rs485 - if (flag_work_rs_send_log) - { - status = 0; - status_ok++; - if (status_ok<0) status_ok=1; - } - if (rs_b.RS_DataReadyAnswerAnalyze) { // i_led2_on_off(0); @@ -607,16 +469,11 @@ int modbusNetworkSharing(int flag_update_only_hmi) control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0; control_station.count_ok_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++; rs_b.RS_DataReadyAnswerAnalyze = 0; - rs_b.RS_DataWillSend2 = 0; status = 0; if (last_ok_cmd==4) // прошла readAnalogDataFromRemote() см ниже edrk.get_new_data_from_hmi = 1;// можно забрать данные? final_code = last_ok_cmd;//numberInT+1; - - //status_err = 0; - status_ok++; - if (status_ok<0) status_ok=1; } else { @@ -625,16 +482,14 @@ int modbusNetworkSharing(int flag_update_only_hmi) { resetup_mpu_rs(&rs_b); control_station.time_detect_answer_485[CONTROL_STATION_INGETEAM_PULT_RS485] = 0; - rs_b.RS_DataWillSend2 = 0; status = 0; control_station.count_error_modbus[CONTROL_STATION_INGETEAM_PULT_RS485]++; - status_err++;// = 1; } } } -*/ + // switch (status) // { // case 0 : status = 1; @@ -731,9 +586,7 @@ int modbusNetworkSharing(int flag_update_only_hmi) // - if (enable_send_cmd -// && (log_to_HMI.send_log == 0) - ) + if (enable_send_cmd && (log_to_HMI.send_log == 0)) { //i_led2_on_off(1); last_ok_cmd = numberInT; @@ -749,13 +602,11 @@ int modbusNetworkSharing(int flag_update_only_hmi) edrk.test++; numberInT++; - enable_send_cmd = 0; break; case 1: if ((flag_update_only_hmi==0) && (edrk.flag_enable_update_hmi)) -// if (edrk.flag_enable_update_hmi) update_tables_HMI_analog(); writeAnalogDataToRemote(); // 1 часть аналога @@ -766,7 +617,6 @@ int modbusNetworkSharing(int flag_update_only_hmi) // else numberInT++; - enable_send_cmd = 0; break; case 2: @@ -782,79 +632,39 @@ int modbusNetworkSharing(int flag_update_only_hmi) // else numberInT++; - enable_send_cmd = 0; break; case 3: readAnalogDataFromRemote(); // 1 часть numberInT++; - enable_send_cmd = 0; break; case 4: readAnalogDataFromRemote(); // 2 часть - if (log_to_HMI.send_log) - { + if (log_to_HMI.send_log == 1) numberInT++; - } else // пропускаем след команду numberInT = 0; - - enable_send_cmd = 0; - count_work_in_log = 0; // подготовка для логов break; case 5: - if (log_to_HMI.send_log) - { - time_pause = 2; - // ccc[0] = 1; - flag_work_rs_send_log = !sendLogToHMI(status_ok); - edrk.flag_slow_in_main = 1; - enable_send_cmd = 0; - - if (count_work_in_log>MAX_COUNT_WORK_IN_LOG) - { - count_work_in_log = 0; - numberInT = 0; // запускаем полный цикл - - } - else - { - count_work_in_log++; - // остаемся в этом цикле логов - } - - } - else - { - time_pause = TIME_PAUSE_MODBUS_REMOUTE; - // ccc[0] = 0; - numberInT = 0; - enable_send_cmd = 0; - edrk.flag_slow_in_main = 0; - } + sendLogToHMI(); + numberInT = 0; break; default: - enable_send_cmd = 0; break; } - + enable_send_cmd = 0; //i_led2_on_off(0); } - //sendLogToHMI(); - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) - PWM_LINES_TK_20_OFF; -#endif + sendLogToHMI(); if (flag_update_only_hmi) return final_code; @@ -870,19 +680,17 @@ int modbusNetworkSharingCAN(void) // static unsigned int old_time1 = 0 , time_pause1 = TIME_PAUSE_NETWORK_CAN1; // static unsigned int old_time2 = 0 , time_pause2 = TIME_PAUSE_NETWORK_CAN2; // static unsigned int old_time3 = 0 , time_pause3 = TIME_PAUSE_NETWORK_CAN3; - static unsigned int time_pause_modbus_can_terminals = TIME_PAUSE_MODBUS_CAN_TERMINALS; #if (ENABLE_CAN_SEND_TO_MPU_FROM_MAIN) // if (detect_pause_milisec(time_pause1,&old_time1)) - static unsigned int time_pause_modbus_can_mpu = TIME_PAUSE_MODBUS_CAN_MPU; - write_all_data_to_mpu_can(1, time_pause_modbus_can_mpu); + write_all_data_to_mpu_can(1, TIME_PAUSE_MODBUS_CAN_MPU); #endif #if (ENABLE_CAN_SEND_TO_TERMINAL_FROM_MAIN) // if (detect_pause_milisec(time_pause2,&old_time2)) - write_all_data_to_terminals_can(1, time_pause_modbus_can_terminals); + write_all_data_to_terminals_can(1, TIME_PAUSE_MODBUS_CAN_TERMINALS); #endif diff --git a/Inu/Src/main/message_modbus.h b/Inu/Src/main/message_modbus.h index 971e5a9..9aef0f2 100644 --- a/Inu/Src/main/message_modbus.h +++ b/Inu/Src/main/message_modbus.h @@ -15,7 +15,7 @@ // void ReceiveAnswerCommandModbus3(RS_DATA *rs_arr); #define TIME_PAUSE_MODBUS_MPU 250 //100//500 -#define TIME_PAUSE_MODBUS_REMOUTE 20 //100 //500 +#define TIME_PAUSE_MODBUS_REMOUTE 100 //500 #define TIME_PAUSE_NETWORK_CAN1 444 //500 #define TIME_PAUSE_NETWORK_CAN2 990 //500 @@ -30,11 +30,11 @@ #define SIZE_BUF_WRITE_TO_MODBUS16_VPU 100 // -#define SIZE_BUF_WRITE_TO_MODBUS16_REMOUTE 120 //100 // передача, размер в одной посылке аналог.части пульта БСУ, не больше SIZE_ANALOG_DATA_REMOUTE -#define SIZE_ANALOG_DATA_REMOUTE 240 //165 // передача, размер данных по аналоговой части пульта БСУ +#define SIZE_BUF_WRITE_TO_MODBUS16_REMOUTE 100 //100 // передача, размер в одной посылке аналог.части пульта БСУ, не больше SIZE_ANALOG_DATA_REMOUTE +#define SIZE_ANALOG_DATA_REMOUTE 200 //165 // передача, размер данных по аналоговой части пульта БСУ -#define SIZE_BUF_READ_FROM_MODBUS16_REMOUTE 120 //20//36 // прием, размер в одной посылке аналог.части пульта БСУ, не больше SIZE_ANALOG_DATA_FROM_MODBUS16_REMOUTE +#define SIZE_BUF_READ_FROM_MODBUS16_REMOUTE 100 //20//36 // прием, размер в одной посылке аналог.части пульта БСУ, не больше SIZE_ANALOG_DATA_FROM_MODBUS16_REMOUTE #define SIZE_ANALOG_DATA_FROM_MODBUS16_REMOUTE SIZE_ANALOG_DATA_REMOUTE //20//36 // прием, размер данных по аналоговой части пульта БСУ diff --git a/Inu/Src/main/modbus_hmi.c b/Inu/Src/main/modbus_hmi.c index f28cb25..11e0a9b 100644 --- a/Inu/Src/main/modbus_hmi.c +++ b/Inu/Src/main/modbus_hmi.c @@ -1,4 +1,4 @@ -#include "log_to_memory.h" +#include #include #include #include @@ -11,7 +11,6 @@ #include "DSP281x_Device.h" #include "MemoryFunctions.h" #include "RS_modbus_svu.h" -#include "log_params.h" #pragma DATA_SECTION(modbus_table_discret_in,".logs"); @@ -27,15 +26,17 @@ MODBUS_REG_STRUCT modbus_table_analog_in[SIZE_MODBUS_ANALOG_REMOUTE]; //regist //MODBUS_REG_STRUCT modbus_table_analog_out[700]; //registers 40001-49999 modbus RTU MODBUS_REG_STRUCT modbus_table_analog_out[SIZE_MODBUS_ANALOG_REMOUTE]; //registers 40001-49999 modbus RTU -//#pragma DATA_SECTION(modbus_table_analog_out2, ".logs"); -//MODBUS_REG_STRUCT modbus_table_analog_out[700]; //registers 40001-49999 modbus RTU -//MODBUS_REG_STRUCT modbus_table_analog_out2[SIZE_MODBUS_ANALOG_REMOUTE]; //registers 40001-49999 modbus RTU //unsigned int flag_waiting_answer = 1; //unsigned int flag_message_sent = 0; +#pragma DATA_SECTION(log_to_HMI, ".logs"); +Logs_with_modbus log_to_HMI = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static int writeLogsArray(); +static void prepareWriteLogsArray(void); +static void fillAnalogDataArrayForLogSend(int num_of_log); /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// @@ -53,14 +54,28 @@ void clear_table_remoute(void) { modbus_table_analog_in[i].all = 0; modbus_table_analog_out[i].all = 0; - //modbus_table_analog_out2[i].all = 0; } } +/////////////////////////////////////////////////// +/// +/////////////////////////////////////////////////// +void fillLogArea() { + unsigned int value = 0; + unsigned int *p_memory = (unsigned int*)LOG_START_ADRES; + long log_size = LOG_BUFFER_SIZE; + while (log_size-- > 0) { + *(p_memory++) = value; + value += 1; +// if (log_size % 8 == 0) { +// value += 1; +// } + } +} /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// @@ -180,9 +195,6 @@ int writeSingleAnalogOutputToRemote(unsigned int adres) return 0; } - - - /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// @@ -292,50 +304,6 @@ int readAnalogDataFromRemote() return succed; } - -int writeSingleAnalogDataToRemote(int from_adr, int count_wr) -{ - int succed = 0; - static unsigned int old_time = 0; - - static int count_write_to_modbus = 0; - static int cur_position_buf_modbus16 = 0; - - - ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); - - - if (!rs_b.flag_LEADING) - { - cur_position_buf_modbus16 = from_adr; - -// if (control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0) -// cur_position_buf_modbus16 = cur_position_buf_modbus16 + SIZE_BUF_WRITE_TO_MODBUS16_REMOUTE; -// -// if (cur_position_buf_modbus16 >= SIZE_ANALOG_DATA_REMOUTE) -// cur_position_buf_modbus16 = 0; - -// //Дырка в обмене. Пропускаем. -// if ((cur_position_buf_modbus16 > ADRESS_END_FIRST_BLOCK) && -// (cur_position_buf_modbus16 < ADRESS_START_PROTECTION_LEVELS)) { -// cur_position_buf_modbus16 = ADRESS_START_PROTECTION_LEVELS; -// } - - if ((cur_position_buf_modbus16 + count_wr) > SIZE_ANALOG_DATA_REMOUTE) - count_write_to_modbus = SIZE_ANALOG_DATA_REMOUTE - cur_position_buf_modbus16; - else - count_write_to_modbus = count_wr; - - ModbusRTUsend16(&rs_b, 2, - ADR_MODBUS_TABLE_REMOUTE + cur_position_buf_modbus16, - count_write_to_modbus); - - succed = 1; - } - return succed; -} - - /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// @@ -381,6 +349,159 @@ int writeAnalogDataToRemote() return succed; } +/////////////////////////////////////////////////// +/// +/////////////////////////////////////////////////// +int sendLogToHMI() +{ + int succed = 0; + unsigned int time_finish_transmitt = 0; + if (log_to_HMI.send_log == 0) + { + log_to_HMI.step = 0; + log_to_HMI.flag_data_received = 0; + log_to_HMI.flag_log_array_sent = 0; + log_to_HMI.log_size_sent = 0; + log_to_HMI.current_address = 0; + log_to_HMI.number_of_log = 0; + setRegisterDiscreteOutput(0, 522); + // control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + return 1; + } + + if (log_to_HMI.step == 0) + { + modbus_table_analog_out[3].all = logpar.count_log_params_fast_log; + + if (log_to_HMI.log_size_sent == 0 && + (writeSingleAnalogOutputToRemote(3) == 1)) + { + log_to_HMI.log_size_sent = 1; + succed = 1; + } else if (log_to_HMI.log_size_sent == 1) { + log_to_HMI.step = 1; + log_to_HMI.flag_log_array_sent = 0; + prepareWriteLogsArray(); + fillAnalogDataArrayForLogSend(log_to_HMI.number_of_log); + } + } + if (log_to_HMI.step == 1) { + if (log_to_HMI.flag_log_array_sent == 0) { + succed = writeLogsArray(log_to_HMI.number_of_log); + } else { + log_to_HMI.step = 2; + init_timer_milisec(&time_finish_transmitt); + } + } + if (log_to_HMI.step == 2) + { + if (detect_pause_milisec(1000, &time_finish_transmitt)) { + setRegisterDiscreteOutput(1, 522); + if (writeDiscreteDataToRemote() == 1) { + log_to_HMI.step = 3; + succed = 1; + } + } else { + succed = 1; + } + + } + if (log_to_HMI.step == 3) { + succed = readAnalogDataFromRemote(); + if (modbus_table_analog_in[8].all == 1) { + if (detect_pause_milisec(1000, &time_finish_transmitt)) { + log_to_HMI.step = 4; + } + } else { + init_timer_milisec(&time_finish_transmitt); + } + } + if (log_to_HMI.step == 4) { + setRegisterDiscreteOutput(0, 522); + if (writeDiscreteDataToRemote() == 1) { + log_to_HMI.step = 5; + succed = 1; + } + } + if (log_to_HMI.step == 5) { + succed = readAnalogDataFromRemote(); + if (modbus_table_analog_in[8].all == 0) { + if (detect_pause_milisec(1000, &time_finish_transmitt) && log_to_HMI.number_of_log < (logpar.count_log_params_fast_log - 1)) { + log_to_HMI.number_of_log += 1; + fillAnalogDataArrayForLogSend(log_to_HMI.number_of_log); + log_to_HMI.flag_log_array_sent = 0; + log_to_HMI.step = 1; + } else { + succed = 1; + } + } + } + + log_to_HMI.send_log = modbus_table_analog_in[7].all; +// control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + return succed; +} + +/////////////////////////////////////////////////// +/// +/////////////////////////////////////////////////// + +#define START_ARRAY_LOG_SEND 200 +#define END_ARRAY_LOG_SEND 699 +#define SIZE_ARRAY_LOG_SEND (END_ARRAY_LOG_SEND - START_ARRAY_LOG_SEND + 1) + +int writeLogsArray() +{ + unsigned long i = 0; + int succed = 0; + int *p_log_data = (int*)LOG_START_ADRES; + ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); + if (!rs_b.flag_LEADING) + { + ModbusRTUsend16(&rs_b, 2, + log_to_HMI.current_address, + log_to_HMI.count_write_to_modbus + 1); + + if (err_send_log_16 == 0) { //prev message without errors + log_to_HMI.current_address = log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16; + } + if (log_to_HMI.current_address > END_ARRAY_LOG_SEND) { + log_to_HMI.current_address = START_ARRAY_LOG_SEND; +// log_to_HMI.flag_end_of_log = 1; + log_to_HMI.flag_log_array_sent = 1; + } + if ((log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16) > END_ARRAY_LOG_SEND) { + log_to_HMI.count_write_to_modbus = END_ARRAY_LOG_SEND - log_to_HMI.current_address; + } else { + log_to_HMI.count_write_to_modbus = SIZE_BUF_WRITE_LOG_TO_MODBUS16; + } + + err_send_log_16 += 1; + succed = 1; + // control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + } + return succed; +} + +void prepareWriteLogsArray(void) { + log_to_HMI.start_log_address = logpar.addres_mem - logpar.count_log_params_fast_log * SIZE_ARRAY_LOG_SEND; + if (log_to_HMI.start_log_address < START_ADDRESS_LOG) { + log_to_HMI.start_log_address = END_ADDRESS_LOG - (START_ADDRESS_LOG - log_to_HMI.start_log_address); + } + log_to_HMI.log_address_step = logpar.count_log_params_fast_log; +} + +void fillAnalogDataArrayForLogSend(int num_of_log) { + int i = START_ARRAY_LOG_SEND; + unsigned long current_address = log_to_HMI.start_log_address + num_of_log; + for (i = START_ARRAY_LOG_SEND; i <= END_ARRAY_LOG_SEND; ++i) { + modbus_table_analog_out[i].all = ReadMemory(current_address); + current_address += log_to_HMI.log_address_step; + } + log_to_HMI.current_address = START_ARRAY_LOG_SEND; + log_to_HMI.count_write_to_modbus = SIZE_BUF_WRITE_LOG_TO_MODBUS16; +} + diff --git a/Inu/Src/main/modbus_hmi.h b/Inu/Src/main/modbus_hmi.h index 887b537..e14c37e 100644 --- a/Inu/Src/main/modbus_hmi.h +++ b/Inu/Src/main/modbus_hmi.h @@ -3,6 +3,24 @@ #include "modbus_struct.h" +typedef struct { + int send_log; + int new_send_log_checked; + int log_size_sent; +// int flag_ready_send_array; + int flag_data_received; + int flag_log_array_sent; + int flag_log_array_ready_sent; +// int flag_end_of_log; + int step; + int number_of_log; + unsigned long count_write_to_modbus; + unsigned long current_address; + unsigned long start_log_address; + int log_address_step; +} Logs_with_modbus; + +extern Logs_with_modbus log_to_HMI; int readDiscreteOutputsFromRemote(); int writeSigleDiscreteDataToRemote(unsigned int adres); @@ -10,22 +28,24 @@ int writeSingleAnalogOutputToRemote(unsigned int adres); int writeDiscreteDataToRemote(); int readAnalogDataFromRemote(); int writeAnalogDataToRemote(); -int writeSingleAnalogDataToRemote(int from_adr, int count_wr); - +int sendLogToHMI(); void setRegisterDiscreteOutput(int value, int adres); int getRegisterDiscreteOutput(int adres); - +void fillLogArea(); //TODO for testing only void clear_table_remoute(void); // clear table -#define ADRES_LOG_REGISTERS 100 +#define LOG_START_ADRES 0xA0000UL +#define LOG_END_ADRES 0xF0000UL +#define LOG_BUFFER_SIZE 0x50000UL //0x100UL +#define ADRES_LOG_REGISTERS 100 #define SIZE_MODBUS_TABLE_DISCRET_REMOUTE 36 #define SIZE_MODBUS_TABLE_DISCRET_BITS (SIZE_MODBUS_TABLE_DISCRET_REMOUTE * 16) -#define SIZE_MODBUS_ANALOG_REMOUTE 900 +#define SIZE_MODBUS_ANALOG_REMOUTE 700 extern MODBUS_REG_STRUCT modbus_table_analog_in[SIZE_MODBUS_ANALOG_REMOUTE]; diff --git a/Inu/Src/main/modbus_hmi_read.c b/Inu/Src/main/modbus_hmi_read.c index 9718943..acfe48a 100644 --- a/Inu/Src/main/modbus_hmi_read.c +++ b/Inu/Src/main/modbus_hmi_read.c @@ -11,9 +11,6 @@ #include -#define DELTA_ABNORMAL_P_WATER_MIN 50 -#define DELTA_ABNORMAL_P_WATER_MAX 100 - void parse_protect_levels_HMI() { if (modbus_table_analog_in[91].all > 0) { @@ -116,8 +113,7 @@ void parse_protect_levels_HMI() { protect_levels.abnormal_temper_water_ext = modbus_table_analog_in[124].all * 10; } if (modbus_table_analog_in[125].all > 0) { - protect_levels.alarm_p_water_min_int = modbus_table_analog_in[125].all * 10; - protect_levels.abnormal_p_water_min_int = protect_levels.alarm_p_water_min_int + DELTA_ABNORMAL_P_WATER_MIN; + protect_levels.alarm_p_water_min_int = modbus_table_analog_in[125].all * 100; } if (modbus_table_analog_in[126].all > 0) { protect_levels.alarm_temper_water_int = modbus_table_analog_in[126].all * 10; @@ -126,8 +122,7 @@ void parse_protect_levels_HMI() { protect_levels.alarm_temper_water_ext = modbus_table_analog_in[127].all * 10; } if (modbus_table_analog_in[128].all > 0) { - protect_levels.alarm_p_water_max_int = modbus_table_analog_in[128].all * 10; - protect_levels.abnormal_p_water_max_int = protect_levels.alarm_p_water_max_int - DELTA_ABNORMAL_P_WATER_MAX; + protect_levels.alarm_p_water_max_int = modbus_table_analog_in[128].all * 100; } if (modbus_table_analog_in[129].all > 0) { @@ -161,21 +156,18 @@ void parse_protect_levels_HMI() { if (modbus_table_analog_in[138].all > 0) { edrk.iqMIN_U_IN = _IQ(((float)modbus_table_analog_in[138].all) / NORMA_ACP); } - if (modbus_table_analog_in[139].all > 0) { edrk.iqMIN_U_ZPT = _IQ(((float)modbus_table_analog_in[139].all) / NORMA_ACP); } if (modbus_table_analog_in[140].all > 0) { edrk.iqMIN_U_ZPT = _IQ(((float)modbus_table_analog_in[140].all) / NORMA_ACP); } - if (modbus_table_analog_in[142].all > 0) { edrk.iqMAX_U_IN = _IQ(((float)modbus_table_analog_in[142].all) / NORMA_ACP); } if (modbus_table_analog_in[143].all > 0) { edrk.iqMAX_U_IN = _IQ(((float)modbus_table_analog_in[143].all) / NORMA_ACP); } - if (modbus_table_analog_in[144].all > 0) { edrk.iqMAX_U_ZPT = _IQ(((float)modbus_table_analog_in[144].all) / NORMA_ACP); } @@ -184,32 +176,32 @@ void parse_protect_levels_HMI() { } if (modbus_table_analog_in[146].all > 0) { - protect_levels.alarm_Izpt_max = modbus_table_analog_in[146].all; + protect_levels.alarm_Izpt_max = modbus_table_analog_out[146].all; } - if (modbus_table_analog_in[155].all > 0) { - protect_levels.alarm_Imax_U01 = modbus_table_analog_in[155].all; + if (modbus_table_analog_out[155].all > 0) { + protect_levels.alarm_Imax_U01 = modbus_table_analog_out[155].all; } - if (modbus_table_analog_in[156].all > 0) { - protect_levels.alarm_Imax_U02 = modbus_table_analog_in[156].all; + if (modbus_table_analog_out[156].all > 0) { + protect_levels.alarm_Imax_U02 = modbus_table_analog_out[156].all; } - if (modbus_table_analog_in[157].all > 0) { - protect_levels.alarm_Imax_U03 = modbus_table_analog_in[157].all; + if (modbus_table_analog_out[157].all > 0) { + protect_levels.alarm_Imax_U03 = modbus_table_analog_out[157].all; } - if (modbus_table_analog_in[158].all > 0) { - protect_levels.alarm_Imax_U04 = modbus_table_analog_in[158].all; + if (modbus_table_analog_out[158].all > 0) { + protect_levels.alarm_Imax_U04 = modbus_table_analog_out[158].all; } - if (modbus_table_analog_in[159].all > 0) { - protect_levels.alarm_Imax_U05 = modbus_table_analog_in[159].all; + if (modbus_table_analog_out[159].all > 0) { + protect_levels.alarm_Imax_U05 = modbus_table_analog_out[159].all; } - if (modbus_table_analog_in[160].all > 0) { - protect_levels.alarm_Imax_U06 = modbus_table_analog_in[160].all; + if (modbus_table_analog_out[160].all > 0) { + protect_levels.alarm_Imax_U06 = modbus_table_analog_out[160].all; } - if (modbus_table_analog_in[161].all > 0) { - protect_levels.alarm_Imax_U07 = modbus_table_analog_in[161].all; + if (modbus_table_analog_out[161].all > 0) { + protect_levels.alarm_Imax_U07 = modbus_table_analog_out[161].all; } - if (modbus_table_analog_in[162].all > 0) { - protect_levels.alarm_Iged_max = modbus_table_analog_in[162].all; + if (modbus_table_analog_out[162].all > 0) { + protect_levels.alarm_Iged_max = modbus_table_analog_out[162].all; } diff --git a/Inu/Src/main/modbus_hmi_update.c b/Inu/Src/main/modbus_hmi_update.c index 7c1e83c..cca9d5a 100644 --- a/Inu/Src/main/modbus_hmi_update.c +++ b/Inu/Src/main/modbus_hmi_update.c @@ -21,8 +21,6 @@ #include "global_time.h" #include "RS_Functions.h" #include "mathlib.h" -#include "logs_hmi.h" -#include "detect_errors.h" /* #include "mathlib.h" #include @@ -57,7 +55,7 @@ int razbor1 = 0; //30017 MotoHoursInvertorGoFault Моточасы в состоянии ""Ход с неисправностью"" (минуты) //30018 MotoHoursInvertorAlarm Моточасы в состоянии ""Авария"" (минуты) -#define COUNT_ANALOG_DATA_FROM_INGETEAM SIZE_ANALOG_DATA_REMOUTE //(18+1) +#define COUNT_ANALOG_DATA_FROM_INGETEAM 200 //(18+1) /////////////////////////////////////////////////// /// /////////////////////////////////////////////////// @@ -102,63 +100,7 @@ void func_unpack_answer_from_Ingeteam(unsigned int cc) void get_command_HMI(void) { - int i; - static int prev_send_log = -1; - - ///////////////// - ///////////////// - ///////////////// - - edrk.pult_cmd.kvitir = modbus_table_analog_in[1].all; - edrk.pult_cmd.sbor = modbus_table_analog_in[2].all; - edrk.pult_cmd.send_log = modbus_table_analog_in[7].all; - edrk.pult_cmd.pump_mode = modbus_table_analog_in[9].all; - - - // mode_pump = modbus_table_analog_in[9].all; - // 0 - auto on - rand pump - // 1 - auto on 1 pump - // 2 - auto on 2 pump - // 3 - manual on 1 pump - // 4 - manual on 2 pump - ////////////////////// - pumps.pump1_engine_minutes = modbus_table_analog_in[13].all; - pumps.pump2_engine_minutes = modbus_table_analog_in[14].all; - - - edrk.pult_data.data_from_pult.nPCH = modbus_table_analog_in[34].all; - edrk.pult_data.data_from_pult.TimeToChangePump = modbus_table_analog_in[164].all; - - edrk.pult_data.data_from_pult.count_build = modbus_table_analog_in[31].all; - edrk.pult_data.data_from_pult.count_revers = modbus_table_analog_in[32].all; - - edrk.pult_data.data_from_pult.LastWorkPump = modbus_table_analog_in[36].all; - - // - //Статус карты и флешки можно узнать в регистре 30033: - //Значение 0 - нет ни флешки, ни карты; - //Значение 1 - нет флешки, есть карта; - //Значение 2 - есть флешка, нет карты; - //Значение 3 - есть и флешка и карта; - - edrk.pult_cmd.log_what_memory = modbus_table_analog_in[33].all; - - - edrk.pult_cmd.sdusb = modbus_table_analog_in[35].all; - - - //moto - for (i=0;i=0 && prev_send_log != edrk.pult_cmd.send_log) - { - if (edrk.pult_cmd.send_log) - log_to_HMI.send_log = edrk.pult_cmd.send_log; + log_to_HMI.send_log = modbus_table_analog_in[7].all; - log_to_HMI.sdusb = edrk.pult_cmd.sdusb; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_MODE_PUMP] = modbus_table_analog_in[9].all; +// mode_pump = modbus_table_analog_in[9].all; + // 0 - auto on - rand pump + // 1 - auto on 1 pump + // 2 - auto on 2 pump + // 3 - manual on 1 pump + // 4 - manual on 2 pump +////////////////////// + pumps.pump1_engine_minutes = modbus_table_analog_in[13].all; + pumps.pump2_engine_minutes = modbus_table_analog_in[14].all; - } -// else -// log_to_HMI.send_log = 0; +/* + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_PUMP] = modbus_table_analog_in[188].all; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_QTV] = modbus_table_analog_in[189].all; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_UMP] = modbus_table_analog_in[190].all; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = modbus_table_analog_in[191].all; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = modbus_table_analog_in[180].all; + control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_GO] = !modbus_table_analog_in[192].all; +*/ - prev_send_log = edrk.pult_cmd.send_log; - - ///////////////// - ///////////////// - ///////////////// - - control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_MODE_PUMP] = edrk.pult_cmd.pump_mode; - - -// -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_PUMP] = modbus_table_analog_in[188].all; -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_QTV] = modbus_table_analog_in[189].all; -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_DISABLE_ON_UMP] = modbus_table_analog_in[190].all; -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = modbus_table_analog_in[191].all; -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = modbus_table_analog_in[180].all; -// control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_GO] = !modbus_table_analog_in[192].all; -// // control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_] = modbus_table_analog_in[188].all; - ///////////////// - ///////////////// - ///////////////// - ///////////////// - parse_protect_levels_HMI(); } @@ -297,7 +219,7 @@ void update_tables_HMI_on_inited(int perc_load) static int prev_edrk_KVITIR=0; int i,status; -// log_to_HMI.send_log = modbus_table_analog_in[7].all; + log_to_HMI.send_log = modbus_table_analog_in[7].all; //setRegisterDiscreteOutput(log_to_HMI.flag_log_array_ready_sent, 310); // LoadMode Read 00544 00544 Режим загрузки управляющего контроллера @@ -309,13 +231,6 @@ void update_tables_HMI_on_inited(int perc_load) // для моргание лампой обмена modbus_table_analog_out[4].all++; - - // build version - modbus_table_analog_out[219].all = edrk.buildYear; - modbus_table_analog_out[220].all = edrk.buildMonth; - modbus_table_analog_out[221].all = edrk.buildDay; - - } /////////////////////////////////////////////////// @@ -323,7 +238,6 @@ void update_tables_HMI_on_inited(int perc_load) /////////////////////////////////////////////////// void update_tables_HMI_discrete(void) { - int real_box; // тут надо квитирование замедлить!!! // if (edrk.from_display.bits.KVITIR) // setRegisterDiscreteOutput(edrk.from_display.bits.KVITIR, 301); @@ -343,8 +257,6 @@ void update_tables_HMI_discrete(void) setRegisterDiscreteOutput(edrk.StatusPump0, 518); setRegisterDiscreteOutput(edrk.StatusPump1, 519); - setRegisterDiscreteOutput(edrk.from_shema_filter.bits.SVU,524); - setRegisterDiscreteOutput(edrk.from_shema_filter.bits.ZADA_DISPLAY,525); // Местное_Дистанционное_управление_БС Read 00523 // Местное_Дистанционное_управление_БСУ Read 00524 // Обороты_задатчик_экран Read 00525 @@ -529,16 +441,10 @@ void update_tables_HMI_discrete(void) setRegisterDiscreteOutput(!control_station.alive_control_station[CONTROL_STATION_ZADATCHIK_CAN], 129); setRegisterDiscreteOutput(!control_station.alive_control_station[CONTROL_STATION_MPU_SVU_CAN], 130); // setRegisterDiscreteOutput(CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,UMU_CAN_DEVICE)], 131); Исключён из схемы - real_box = get_real_in_mbox(UNITS_TYPE_BOX,BKSSD_CAN_DEVICE); - if (real_box != -1) - setRegisterDiscreteOutput(CAN_timeout[real_box], 132); + setRegisterDiscreteOutput(CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,BKSSD_CAN_DEVICE)], 132); + setRegisterDiscreteOutput(CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,VPU_CAN)], 133); - real_box = get_real_in_mbox(UNITS_TYPE_BOX,VPU_CAN); - if (real_box != -1) - setRegisterDiscreteOutput(CAN_timeout[real_box], 133); - real_box = get_real_in_mbox(UNITS_TYPE_BOX,ANOTHER_BSU1_CAN_DEVICE); - if (real_box != -1) - setRegisterDiscreteOutput(CAN_timeout[real_box], 134); + setRegisterDiscreteOutput(CAN_timeout[get_real_in_mbox(UNITS_TYPE_BOX,ANOTHER_BSU1_CAN_DEVICE)], 134); setRegisterDiscreteOutput(edrk.errors.e7.bits.CAN2CAN_BS, 135); @@ -547,17 +453,8 @@ void update_tables_HMI_discrete(void) else setRegisterDiscreteOutput(edrk.warnings.e4.bits.ANOTHER_BS_POWER_OFF, 136); - setRegisterDiscreteOutput(edrk.errors.e7.bits.ANOTHER_BS_ALARM, 138); // ; edrk.errors.e4.bits.FAST_OPTICAL_ALARM - setRegisterDiscreteOutput(edrk.warnings.e7.bits.ANOTHER_BS_ALARM, 139);// ; edrk.warnings.e4.bits.FAST_OPTICAL_ALARM - - setRegisterDiscreteOutput(edrk.warnings.e7.bits.UMP_NOT_READY, 140); - - setRegisterDiscreteOutput(edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK, 141); - setRegisterDiscreteOutput(edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK, 142); - - setRegisterDiscreteOutput(edrk.errors.e9.bits.SENSOR_ROTOR_1_2_BREAK, 143); - - + setRegisterDiscreteOutput(edrk.errors.e4.bits.FAST_OPTICAL_ALARM, 138); + setRegisterDiscreteOutput(edrk.warnings.e4.bits.FAST_OPTICAL_ALARM, 139); /// setRegisterDiscreteOutput(project.cds_tk[0].read.sbus.status_protect_current_ack.bit.tk0_ack, 145);// @@ -649,13 +546,6 @@ void update_tables_HMI_discrete(void) setRegisterDiscreteOutput(edrk.warnings.e2.bits.T_AIR2_MAX, 205);// setRegisterDiscreteOutput(edrk.warnings.e2.bits.T_AIR3_MAX, 206);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_by_temper, 207);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_from_freq, 211);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_from_uom_fast, 212);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_from_SVU, 213);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_moment, 214);// - setRegisterDiscreteOutput(edrk.power_limit.bits.limit_Iout, 216);// - //////////////////// setRegisterDiscreteOutput(edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON, 209);// setRegisterDiscreteOutput(edrk.errors.e7.bits.ERROR_SBOR_SHEMA, 210);// @@ -842,35 +732,29 @@ void update_tables_HMI_discrete(void) setRegisterDiscreteOutput(edrk.warnings.e2.bits.P_WATER_INT_MAX, 371);// setRegisterDiscreteOutput(edrk.warnings.e2.bits.P_WATER_INT_MIN, 372);// - setRegisterDiscreteOutput(edrk.warnings.e5.bits.PUMP_1, 373);// - setRegisterDiscreteOutput(edrk.warnings.e5.bits.PUMP_2, 374);// //// - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_PUMP_ON_SBOR, 385); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_RESTART_PUMP_1_ON_SBOR, 386); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_RESTART_PUMP_2_ON_SBOR, 387); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_RESTART_PUMP_ALL_ON_SBOR, 388); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_PUMP_ON_SBOR, 385); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_RESTART_PUMP_1_ON_SBOR, 386); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_RESTART_PUMP_2_ON_SBOR, 387); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_RESTART_PUMP_ALL_ON_SBOR, 388); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_PRED_ZARYAD, 389); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_PRED_ZARYAD_AFTER, 390); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_READY_UMP_BEFORE_QTV, 391); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_STATUS_QTV, 392); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_PRED_ZARYAD, 389); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_PRED_ZARYAD_AFTER, 390); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_READY_UMP_BEFORE_QTV, 391); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_STATUS_QTV, 392); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_UMP_ON_AFTER, 393); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_UMP_NOT_ON, 394); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_UMP_NOT_OFF, 395); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_RASCEPITEL_WAIT_CMD, 396); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_UMP_ON_AFTER, 393); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_UMP_NOT_ON, 394); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_UMP_NOT_OFF, 395); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_RASCEPITEL_WAIT_CMD, 396); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_RASCEPITEL_ON_AFTER, 397); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_DISABLE_SBOR, 398); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_VERY_LONG_SBOR, 399); - setRegisterDiscreteOutput(edrk.errors.e11.bits.ERROR_CONTROLLER_BUS, 400); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_RASCEPITEL_ON_AFTER, 397); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_DISABLE_SBOR, 398); + setRegisterDiscreteOutput(edrk.warnings.e11.bits.ERROR_VERY_LONG_SBOR, 399); - setRegisterDiscreteOutput(edrk.warnings.e9.bits.BREAK_TEMPER_WARNING, 417);// - setRegisterDiscreteOutput(edrk.warnings.e9.bits.BREAK_TEMPER_ALARM, 418);// - setRegisterDiscreteOutput(edrk.warnings.e9.bits.BREAKER_GED_ON, 419);// ////////////////// @@ -884,7 +768,7 @@ void update_tables_HMI_discrete(void) // setRegisterDiscreteOutput(TODO Блокировка СВУ, 546);// setRegisterDiscreteOutput(!edrk.from_ing1.bits.UPC_24V_NORMA, 546);// setRegisterDiscreteOutput(edrk.from_ing2.bits.SOST_ZAMKA, 547);// - setRegisterDiscreteOutput(edrk.from_shema_filter.bits.READY_UMP, 548);// + setRegisterDiscreteOutput(edrk.from_shema.bits.READY_UMP, 548);// //////////////// @@ -893,13 +777,8 @@ void update_tables_HMI_discrete(void) } - void update_tables_HMI_analog(void) { - int power_kw_full; - int power_kw; - int oborots; - Inverter_state state; static int nn=0, ss=0, pl = 0; // static int prev_edrk_KVITIR=0; @@ -908,7 +787,7 @@ void update_tables_HMI_analog(void) hmi_watch_dog = !hmi_watch_dog; //was transmitted, need to change - //log_to_HMI.send_log = modbus_table_analog_in[7].all; + log_to_HMI.send_log = modbus_table_analog_in[7].all; //setRegisterDiscreteOutput(log_to_HMI.flag_log_array_ready_sent, 310); // setRegisterDiscreteOutput(ss, nn); @@ -928,6 +807,47 @@ void update_tables_HMI_analog(void) //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// + + +/* + state = f.Stop ? state_accident : + f.fault ? state_fault : + edrk.Go ? state_go : + f.Ready2 ? state_ready2 : + f.Assemble ? state_assemble : + f.Ready1 ? state_ready1 : + state_not_init; +*/ +// setStateHMI(state); +// setElementsColorsHMI(state); + +/* + f.Assemble = modbus_table_analog_in[2].all; + f.Mode = modbus_table_analog_in[3].all == 0 ? 1 : //turnovers + modbus_table_analog_in[3].all == 1 ? 2 : 0; //power + + setRegisterDiscreteOutput(f.Mode == 2 ? 1 : 0, 308); + + + if (modbus_table_analog_in[6].all == 1){ + f.p_zad = ((float)modbus_table_analog_in[4].all) * 1000.0; //convert to Watts + f.iq_p_zad = _IQ(f.p_zad / (float)NORMA_ACP / (float)NORMA_ACP); + f.fzad = (float)modbus_table_analog_in[5].all / 60.0; + f.iq_fzad = _IQ(f.fzad / NORMA_FROTOR); + setRegisterDiscreteOutput(1, 309); //Acknoledge to HMI + } else { + setRegisterDiscreteOutput(0, 309); + } + modbus_table_analog_out[46].all = _IQtoF((f.iq_p_zad)) * NORMA_ACP * NORMA_ACP / 1000.0; + modbus_table_analog_out[47].all = _IQtoF((f.iq_fzad)) * NORMA_FROTOR * 60; +// modbus_table_analog_out[48].all = _IQtoF((analog.iqW1 + analog.iqW2)) * NORMA_ACP * NORMA_ACP / 1000; + modbus_table_analog_out[49].all = _IQtoF((rotor.iqFout) * NORMA_FROTOR) * 60; + +*/ + +// modbus_table_analog_out[49].all = edrk.W_Ing; + + if (edrk.summ_errors) { modbus_table_analog_out[1].all = 6; // авариЯ @@ -936,11 +856,12 @@ void update_tables_HMI_analog(void) else { - if (edrk.SumSbor || edrk.Status_Ready.bits.ImitationReady2) + modbus_table_analog_out[2].all = 1; // green + + if (edrk.SumSbor) { if (edrk.Status_Ready.bits.ready_final) { - //modbus_table_analog_out[2].all = 1; // green if (edrk.Go) { modbus_table_analog_out[1].all = 3; // ход @@ -979,21 +900,6 @@ void update_tables_HMI_analog(void) // //modbus_table_analog_out[1].all = 5; // неисправность - if (modbus_table_analog_out[1].all == 1) - modbus_table_analog_out[2].all = 0; // gray - else - if (modbus_table_analog_out[1].all == 3 || - modbus_table_analog_out[1].all == 12 || - modbus_table_analog_out[1].all == 2) - modbus_table_analog_out[2].all = 1; // green - else - { - if (modbus_table_analog_out[2].all==0) - modbus_table_analog_out[2].all = 1; // green - else - modbus_table_analog_out[2].all = 0; // gray - } - } @@ -1006,7 +912,7 @@ void update_tables_HMI_analog(void) } else { - if (edrk.from_shema_filter.bits.QTV_ON_OFF) + if (edrk.from_shema.bits.QTV_ON_OFF) { modbus_table_analog_out[10].all = 1; modbus_table_analog_out[11].all = 1; @@ -1021,7 +927,7 @@ void update_tables_HMI_analog(void) if (edrk.from_ing1.bits.VIPR_PREDOHR_NORMA==1) { - if (edrk.from_shema_filter.bits.QTV_ON_OFF==1) + if (edrk.from_shema.bits.QTV_ON_OFF==1) modbus_table_analog_out[12].all = 1; else modbus_table_analog_out[12].all = 0; @@ -1091,14 +997,12 @@ void update_tables_HMI_analog(void) if (edrk.errors.e10.bits.T_ACDRIVE_WINDING_U1 || edrk.errors.e10.bits.T_ACDRIVE_WINDING_V1 || edrk.errors.e10.bits.T_ACDRIVE_WINDING_W1 || edrk.errors.e10.bits.T_ACDRIVE_WINDING_U2 || edrk.errors.e10.bits.T_ACDRIVE_WINDING_V2 || edrk.errors.e10.bits.T_ACDRIVE_WINDING_W2 || - edrk.errors.e7.bits.T_ACDRIVE_BEAR_MAX_DNE || edrk.errors.e9.bits.T_ACDRIVE_BEAR_MAX_NE) { + edrk.errors.e10.bits.T_ACDRIVE_WINDING_U1 || edrk.errors.e9.bits.T_ACDRIVE_BEAR_MAX_NE) { modbus_table_analog_out[20].all = 3; } else if (edrk.warnings.e10.bits.T_ACDRIVE_WINDING_U1 || edrk.warnings.e10.bits.T_ACDRIVE_WINDING_V1 || edrk.warnings.e10.bits.T_ACDRIVE_WINDING_W1 || edrk.warnings.e10.bits.T_ACDRIVE_WINDING_U2 || edrk.warnings.e10.bits.T_ACDRIVE_WINDING_V2 || edrk.warnings.e10.bits.T_ACDRIVE_WINDING_W2 || - edrk.warnings.e7.bits.T_ACDRIVE_BEAR_MAX_DNE || edrk.warnings.e9.bits.T_ACDRIVE_BEAR_MAX_NE - || edrk.power_limit.all - ) { + edrk.warnings.e10.bits.T_ACDRIVE_WINDING_U1 || edrk.warnings.e9.bits.T_ACDRIVE_BEAR_MAX_NE) { modbus_table_analog_out[20].all = 2; } else { modbus_table_analog_out[20].all = 1; @@ -1106,35 +1010,20 @@ void update_tables_HMI_analog(void) // ump state - if (edrk.from_ing1.bits.ZARYAD_ON || edrk.from_shema_filter.bits.UMP_ON_OFF) - { - modbus_table_analog_out[21].all = 1; //green - } + if (edrk.from_ing1.bits.ZARYAD_ON || edrk.from_shema.bits.UMP_ON_OFF) + modbus_table_analog_out[21].all = 1; else { if (edrk.errors.e7.bits.ERROR_SBOR_SHEMA || edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON || edrk.errors.e6.bits.ERROR_PRE_CHARGE_ANSWER || edrk.errors.e6.bits.ERROR_PRE_CHARGE_U || edrk.errors.e7.bits.UMP_NOT_READY) - modbus_table_analog_out[21].all = 3; // alarm + modbus_table_analog_out[21].all = 3; else - if (edrk.warnings.e7.bits.UMP_NOT_READY) - modbus_table_analog_out[21].all = 2; //fault - else - { - if (edrk.Stage_Sbor == STAGE_SBOR_STATUS_UMP_ON && edrk.SumSbor) - { - if (modbus_table_analog_out[21].all==0) - modbus_table_analog_out[21].all = 1; //green - else - modbus_table_analog_out[21].all = 0; //gray - } - else - modbus_table_analog_out[21].all = 0; - } + modbus_table_analog_out[21].all = 0; } - modbus_table_analog_out[30].all = fast_round_with_limiter(_IQtoF(filter.iqUin_m1)*NORMA_ACP/1.41, LIMITER_U_I_PULT); - modbus_table_analog_out[31].all = fast_round_with_limiter(_IQtoF(filter.iqUin_m2)*NORMA_ACP/1.41, LIMITER_U_I_PULT); + modbus_table_analog_out[30].all = fast_round(_IQtoF(filter.iqUin_m1)*NORMA_ACP/1.41); + modbus_table_analog_out[31].all = fast_round(_IQtoF(filter.iqUin_m2)*NORMA_ACP/1.41); // if (edrk.Status_Ready.bits.ready_final==0) // { @@ -1143,16 +1032,16 @@ void update_tables_HMI_analog(void) // } // else // { - modbus_table_analog_out[32].all = fast_round_with_limiter(_IQtoF(analog.iqIin_1)*NORMA_ACP, LIMITER_U_I_PULT); - modbus_table_analog_out[33].all = fast_round_with_limiter(_IQtoF(analog.iqIin_2)*NORMA_ACP, LIMITER_U_I_PULT); + modbus_table_analog_out[32].all = fast_round(_IQtoF(analog.iqIin_1)*NORMA_ACP); + modbus_table_analog_out[33].all = fast_round(_IQtoF(analog.iqIin_2)*NORMA_ACP); // } // modbus_table_analog_out[34].all = _IQtoF(filter.iqU_1_long)*NORMA_ACP; - modbus_table_analog_out[35].all = fast_round_with_limiter(_IQtoF(filter.iqU_2_long)*NORMA_ACP, LIMITER_U_I_PULT); - modbus_table_analog_out[34].all = fast_round_with_limiter(_IQtoF(filter.iqU_1_long)*NORMA_ACP, LIMITER_U_I_PULT); + modbus_table_analog_out[35].all = fast_round(_IQtoF(filter.iqU_2_long)*NORMA_ACP); + modbus_table_analog_out[34].all = fast_round(_IQtoF(filter.iqU_1_long)*NORMA_ACP); - modbus_table_analog_out[36].all = fast_round_with_limiter(_IQtoF(analog.iqIbreak_1+analog.iqIbreak_2)*NORMA_ACP, LIMITER_U_I_PULT);//Ibreak + modbus_table_analog_out[36].all = fast_round(_IQtoF(analog.iqIbreak_1)*NORMA_ACP + _IQtoF(analog.iqIbreak_2)*NORMA_ACP);//Ibreak @@ -1164,85 +1053,44 @@ void update_tables_HMI_analog(void) // modbus_table_analog_out[41].all = fast_round(_IQtoF(analog.iqIv_2_rms)*NORMA_ACP); // modbus_table_analog_out[42].all = fast_round(_IQtoF(analog.iqIw_2_rms)*NORMA_ACP); - modbus_table_analog_out[37].all = //fast_round(_IQtoF(filter.iqIm_1)*NORMA_ACP_RMS); - modbus_table_analog_out[38].all = //fast_round(_IQtoF(filter.iqIm_1)*NORMA_ACP_RMS); - modbus_table_analog_out[39].all = fast_round_with_limiter(_IQtoF(filter.iqIm_1)*NORMA_ACP_RMS, LIMITER_U_I_PULT); + modbus_table_analog_out[37].all = fast_round(_IQtoF(filter.iqIm_1)*NORMA_ACP); + modbus_table_analog_out[38].all = fast_round(_IQtoF(filter.iqIm_1)*NORMA_ACP); + modbus_table_analog_out[39].all = fast_round(_IQtoF(filter.iqIm_1)*NORMA_ACP); - modbus_table_analog_out[40].all = //fast_round(_IQtoF(filter.iqIm_2)*NORMA_ACP_RMS); - modbus_table_analog_out[41].all = //fast_round(_IQtoF(filter.iqIm_2)*NORMA_ACP_RMS); - modbus_table_analog_out[42].all = fast_round_with_limiter(_IQtoF(filter.iqIm_2)*NORMA_ACP_RMS, LIMITER_U_I_PULT); + modbus_table_analog_out[40].all = fast_round(_IQtoF(filter.iqIm_2)*NORMA_ACP); + modbus_table_analog_out[41].all = fast_round(_IQtoF(filter.iqIm_2)*NORMA_ACP); + modbus_table_analog_out[42].all = fast_round(_IQtoF(filter.iqIm_2)*NORMA_ACP); -// if (edrk.flag_second_PCH == 0) { -// modbus_table_analog_out[43].all = modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP_RMS); -// //modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP_RMS); -// } else { -// modbus_table_analog_out[43].all = modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP_RMS); -// //modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP_RMS); -// } - modbus_table_analog_out[43].all = modbus_table_analog_out[44].all = fast_round_with_limiter(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP_RMS, LIMITER_U_I_PULT); + if (edrk.flag_second_PCH == 0) { + modbus_table_analog_out[43].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP); + modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP); + } else { + modbus_table_analog_out[43].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP); + modbus_table_analog_out[44].all = fast_round(_IQtoF(filter.iqIm_1 + filter.iqIm_2)*NORMA_ACP); + } modbus_table_analog_out[45].all = 0; //edrk.I_zad_vozbud_exp; // modbus_table_analog_out[4].all = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_ROTOR]; // modbus_table_analog_out[5].all = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_POWER]; - -//#if (_FLOOR6__) -// power_kw_full = edrk.power_kw_full; -// power_kw = edrk.power_kw; -// oborots = edrk.oborots; -// -// if (edrk.oborots) -// oborots = edrk.oborots; -// else -// oborots = edrk.zadanie.oborots_zad; -// -// -// if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_SCALAR_OBOROTS -// || (edrk.Mode_ScalarVectorUFConst==ALG_MODE_FOC_OBOROTS) -// || (edrk.Mode_ScalarVectorUFConst==ALG_MODE_UF_CONST) -// ) // oborots -// { -// power_kw_full = (edrk.zadanie.oborots_zad)*50; -// power_kw = (edrk.zadanie.oborots_zad)*25; -// } -// else -// { -// oborots = edrk.zadanie.power_zad/25; -//// modbus_table_analog_out[48].all = abs(edrk.zadanie.power_zad); -// } -// -// -// -// -// -//#else - power_kw_full = fast_round_with_limiter(edrk.power_kw_full, LIMITER_U_I_PULT); - power_kw = edrk.power_kw; - oborots = edrk.oborots; -//#endif - - if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_UF_CONST) // UFCONST { - modbus_table_analog_out[47].all = 0;//fast_round(edrk.zadanie.fzad*100.0); //Обороты двигателя заданные + modbus_table_analog_out[47].all = fast_round(edrk.zadanie.fzad*100.0); //Обороты двигателя заданные modbus_table_analog_out[46].all = 0; //Мощность двигателя заданная } else if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_SCALAR_OBOROTS) // scalar oborots { modbus_table_analog_out[47].all = edrk.zadanie.oborots_zad; //Обороты двигателя заданные + modbus_table_analog_out[46].all = 0; //Мощность двигателя заданная - if (oborots>=0) - modbus_table_analog_out[46].all = power_kw_full; //Мощность вала текущая суммарная - else - modbus_table_analog_out[46].all = -power_kw_full; //Мощность двигателя заданная } else if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_SCALAR_POWER) // scalar power { - modbus_table_analog_out[47].all = oborots; //Обороты двигателя заданные + modbus_table_analog_out[47].all = 0; //Обороты двигателя заданные modbus_table_analog_out[46].all = edrk.zadanie.power_zad; //Мощность двигателя заданная } @@ -1250,93 +1098,57 @@ void update_tables_HMI_analog(void) if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_FOC_OBOROTS) // foc oborots { modbus_table_analog_out[47].all = edrk.zadanie.oborots_zad; //Обороты двигателя заданные - - if (oborots>=0) - modbus_table_analog_out[46].all = power_kw_full; //Мощность вала текущая суммарная - else - modbus_table_analog_out[46].all = -power_kw_full; //Мощность двигателя заданная - -// modbus_table_analog_out[46].all = 0; //Мощность двигателя заданная + modbus_table_analog_out[46].all = 0; //Мощность двигателя заданная } else if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_FOC_POWER) // foc power { - modbus_table_analog_out[47].all = oborots; //Обороты двигателя заданные + modbus_table_analog_out[47].all = 0; //Обороты двигателя заданные modbus_table_analog_out[46].all = edrk.zadanie.power_zad; //Мощность двигателя заданная } else { - modbus_table_analog_out[46].all = 0;//-1; //Мощность двигателя заданная - modbus_table_analog_out[47].all = 0;//-1; //Обороты двигателя заданные + modbus_table_analog_out[46].all = -1; //Мощность двигателя заданная + modbus_table_analog_out[47].all = -1; //Обороты двигателя заданные } + modbus_table_analog_out[48].all = edrk.power_kw; //Мощность двигателя текущая кВт - -//#if (_FLOOR6___) -// if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_SCALAR_OBOROTS -// || (edrk.Mode_ScalarVectorUFConst==ALG_MODE_FOC_OBOROTS) -// || (edrk.Mode_ScalarVectorUFConst==ALG_MODE_UF_CONST) -// ) // oborots -// { -// // имитация оборотов для теста -// if (edrk.oborots == 0) -// { -// if (edrk.zadanie.oborots_zad>0) -// modbus_table_analog_out[49].all = edrk.zadanie.oborots_zad - 1; -// else if (edrk.zadanie.oborots_zad<0) -// modbus_table_analog_out[49].all = edrk.zadanie.oborots_zad + 1; -// else -// modbus_table_analog_out[49].all = 0; -// -// } -// else -// { -// modbus_table_analog_out[49].all = edrk.oborots; // обороты текущие -// } -// -// if (edrk.zadanie.oborots_zad<0) -// modbus_table_analog_out[48].all = -(edrk.zadanie.oborots_zad)*25; //Мощность двигателя текущая кВт -// else -// modbus_table_analog_out[48].all = (edrk.zadanie.oborots_zad)*25; //Мощность двигателя текущая кВт -// -// } -// else -// { -// modbus_table_analog_out[49].all = edrk.zadanie.power_zad/25; -// modbus_table_analog_out[48].all = abs(edrk.zadanie.power_zad); -// } -// -// modbus_table_analog_out[5].all = abs(power_kw*2);//power_kw_full; //Мощность вала текущая суммарная -//#else - - modbus_table_analog_out[48].all = abs(power_kw); //Мощность двигателя текущая кВт - modbus_table_analog_out[49].all = oborots; // обороты текущие - modbus_table_analog_out[5].all = abs(power_kw_full); //Мощность вала текущая суммарная - modbus_table_analog_out[6].all = fast_round(_IQtoF(edrk.zadanie.iq_limit_power_zad_rmp)*NORMA_ACP*NORMA_ACP/1000.0);//abs(power_kw_full); //Мощность вала текущая суммарная -//#endif - - + if (edrk.Mode_ScalarVectorUFConst==ALG_MODE_UF_CONST) // UFCONST + { + modbus_table_analog_out[49].all = fast_round(_IQtoF(edrk.f_stator)*NORMA_FROTOR*100.0); +// modbus_table_analog_out[48].all = fast_round(_IQtoF((filter.Power) * NORMA_ACP * NORMA_ACP) / 1000.0); //Мощность двигателя текущая кВт + //fast_round(_IQtoF(edrk.k_stator1)*10000.0); //Мощность двигателя текущая + } + else + { + modbus_table_analog_out[49].all = edrk.oborots; // modbus_table_analog_out[48].all = fast_round(_IQtoF((filter.Power) * NORMA_ACP * NORMA_ACP) / 1000.0); //Мощность двигателя текущая кВт - - for (i=0;i<2;i++) - modbus_table_analog_out[50+i].all = fast_round_with_delta(modbus_table_analog_out[50+i].all, edrk.temper_edrk.real_int_temper_water[i]/10.0, 1); + } - modbus_table_analog_out[52].all = fast_round_with_delta(modbus_table_analog_out[52].all, edrk.p_water_edrk.filter_real_int_p_water[0]/10.0, 1); + modbus_table_analog_out[50].all = edrk.temper_edrk.real_int_temper_water[0]/10; + modbus_table_analog_out[51].all = edrk.temper_edrk.real_int_temper_water[1]/10; - for (i=0;i<6;i++) - modbus_table_analog_out[53+i].all = fast_round_with_delta(modbus_table_analog_out[53+i].all, edrk.temper_edrk.real_int_temper_u[1+i]/10.0, 1); + modbus_table_analog_out[52].all = edrk.p_water_edrk.filter_real_int_p_water[0]/10; - modbus_table_analog_out[59].all = fast_round_with_delta(modbus_table_analog_out[59].all, edrk.temper_edrk.real_int_temper_u[0]/10.0, 1); + modbus_table_analog_out[53].all = edrk.temper_edrk.real_int_temper_u[1]/10; + modbus_table_analog_out[54].all = edrk.temper_edrk.real_int_temper_u[2]/10; + modbus_table_analog_out[55].all = edrk.temper_edrk.real_int_temper_u[3]/10; + modbus_table_analog_out[56].all = edrk.temper_edrk.real_int_temper_u[4]/10; + modbus_table_analog_out[57].all = edrk.temper_edrk.real_int_temper_u[5]/10; + modbus_table_analog_out[58].all = edrk.temper_edrk.real_int_temper_u[6]/10; - for (i=0;i<4;i++) - modbus_table_analog_out[60+i].all = fast_round_with_delta(modbus_table_analog_out[60+i].all, edrk.temper_edrk.real_int_temper_air[i]/10.0, 1); + modbus_table_analog_out[59].all = edrk.temper_edrk.real_int_temper_u[0]/10; - modbus_table_analog_out[8].all = fast_round_with_delta(modbus_table_analog_out[8].all, edrk.temper_edrk.max_real_int_temper_u/10.0, 1); + modbus_table_analog_out[60].all = edrk.temper_edrk.real_int_temper_air[0]/10; + modbus_table_analog_out[61].all = edrk.temper_edrk.real_int_temper_air[1]/10; + modbus_table_analog_out[62].all = edrk.temper_edrk.real_int_temper_air[2]/10; + modbus_table_analog_out[63].all = edrk.temper_edrk.real_int_temper_air[3]/10; if (edrk.errors.e2.bits.T_AIR0_MAX) modbus_table_analog_out[64].all = 3; @@ -1386,16 +1198,17 @@ void update_tables_HMI_analog(void) else modbus_table_analog_out[68].all = 2; // master salve - for (i=0;i<6;i++) - modbus_table_analog_out[69+i].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[0+i]); - modbus_table_analog_out[9].all = fast_round(edrk.temper_acdrive.winding.max_real_int_temper/10.0); + modbus_table_analog_out[69].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[0]); + modbus_table_analog_out[70].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[1]); + modbus_table_analog_out[71].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[2]); + modbus_table_analog_out[72].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[3]); + modbus_table_analog_out[73].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[4]); + modbus_table_analog_out[74].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[5]); modbus_table_analog_out[75].all = fast_round(edrk.temper_acdrive.bear.filter_real_temper[0]); modbus_table_analog_out[76].all = fast_round(edrk.temper_acdrive.bear.filter_real_temper[1]); - modbus_table_analog_out[23].all = fast_round(edrk.temper_acdrive.bear.max_real_int_temper/10.0); - for (i=0;i<6;i++) { status = get_status_temper_acdrive_winding(i); @@ -1425,30 +1238,17 @@ void update_tables_HMI_analog(void) if (edrk.from_uom.ready==1) { if (edrk.from_uom.error) - modbus_table_analog_out[86].all = 1; // красный + modbus_table_analog_out[86].all = 1; else { - if (edrk.from_uom.level_value==0) - modbus_table_analog_out[86].all = 2; // зеленый - else - { - if (edrk.power_limit.bits.limit_UOM || edrk.power_limit.bits.limit_from_uom_fast) - { - // моргаем желтый-серый - if (modbus_table_analog_out[86].all==0) - modbus_table_analog_out[86].all = 3; //желтый - else - modbus_table_analog_out[86].all = 0; //gray - } - else - modbus_table_analog_out[86].all = 3; - - //modbus_table_analog_out[86].all = 3; // желтый - } + if (edrk.from_uom.level_value==100) + modbus_table_analog_out[86].all = 2; + else + modbus_table_analog_out[86].all = 3; } } else - modbus_table_analog_out[86].all = 0; // серый + modbus_table_analog_out[86].all = 0; // active control station @@ -1534,10 +1334,10 @@ void update_tables_HMI_analog(void) modbus_table_analog_out[123].all = protect_levels.abnormal_temper_water_int / 10; modbus_table_analog_out[124].all = protect_levels.abnormal_temper_water_ext / 10; - modbus_table_analog_out[125].all = protect_levels.alarm_p_water_min_int / 10; + modbus_table_analog_out[125].all = protect_levels.alarm_p_water_min_int / 100; modbus_table_analog_out[126].all = protect_levels.alarm_temper_water_int / 10; modbus_table_analog_out[127].all = protect_levels.alarm_temper_water_ext / 10; - modbus_table_analog_out[128].all = protect_levels.alarm_p_water_max_int / 10; + modbus_table_analog_out[128].all = protect_levels.alarm_p_water_max_int / 100; modbus_table_analog_out[129].all = protect_levels.abnormal_temper_air_int_01 / 10; modbus_table_analog_out[130].all = protect_levels.abnormal_temper_air_int_02 / 10; @@ -1548,27 +1348,12 @@ void update_tables_HMI_analog(void) modbus_table_analog_out[135].all = protect_levels.alarm_temper_air_int_03 / 10; modbus_table_analog_out[136].all = protect_levels.alarm_temper_air_int_04 / 10; -// toControllerAlarmMinUlineA1B1C1 30137 -// toControllerAlarmMinUlineA2B2C2 30138 -// toControllerAlarmMinUdcUP 30139 -// toControllerAlarmMinUdcDOWN 30140 -// toControllerAlarmMaxUlineA1B1C1 30142 -// toControllerAlarmMaxUlineA2B2C2 30143 -// toControllerAlarmMaxUdcUP 30144 -// toControllerAlarmMaxUdcDOWN 30145 - modbus_table_analog_out[137].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_minus20) * NORMA_ACP;//_IQtoF(edrk.iqMIN_U_IN) * NORMA_ACP; modbus_table_analog_out[138].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_minus20) * NORMA_ACP; - - modbus_table_analog_out[139].all = _IQtoF(edrk.iqMIN_U_ZPT) * NORMA_ACP; - modbus_table_analog_out[140].all = _IQtoF(edrk.iqMIN_U_ZPT) * NORMA_ACP; - - modbus_table_analog_out[142].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_plus20) * NORMA_ACP; - modbus_table_analog_out[143].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_plus20) * NORMA_ACP; - -// modbus_table_analog_out[141].all = //_IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; -// modbus_table_analog_out[140].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; - + modbus_table_analog_out[139].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_plus20) * NORMA_ACP; + modbus_table_analog_out[140].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_plus20) * NORMA_ACP; + modbus_table_analog_out[141].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; + modbus_table_analog_out[140].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; modbus_table_analog_out[144].all = _IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP; modbus_table_analog_out[145].all = _IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP; @@ -1583,90 +1368,10 @@ void update_tables_HMI_analog(void) modbus_table_analog_out[161].all = protect_levels.alarm_Imax_U07; modbus_table_analog_out[162].all = protect_levels.alarm_Iged_max; - - // save nPCH TimeToChangePump - modbus_table_analog_out[163].all = edrk.pult_data.data_to_pult.nPCH; - modbus_table_analog_out[154].all = edrk.pult_data.data_to_pult.TimeToChangePump; - - modbus_table_analog_out[222].all = edrk.pult_data.data_to_pult.count_build; - modbus_table_analog_out[223].all = edrk.pult_data.data_to_pult.count_revers; - - - - modbus_table_analog_out[197].all = edrk.pult_data.flagSaveDataPCH; - - - - - // build version - modbus_table_analog_out[219].all = edrk.buildYear; - modbus_table_analog_out[220].all = edrk.buildMonth; - modbus_table_analog_out[221].all = edrk.buildDay; - - //moto - for (i=0;i32760) - edrk.pult_data.data.count_build = 1; - - // edrk.pult_data.data_to_pult.count_build = edrk.pult_data.data.count_build; - // edrk.pult_data.data_to_pult.moto[21] = edrk.pult_data.data_to_pult.count_build; -} - - - -void inc_count_revers(void) -{ -// edrk.pult_data.data.count_revers = edrk.pult_data.data_from_pult.moto[22]; - - edrk.pult_data.data.count_revers++; - if (edrk.pult_data.data.count_revers>32760) - edrk.pult_data.data.count_revers = 1; - -// edrk.pult_data.data_to_pult.count_revers = edrk.pult_data.data.count_revers; - // edrk.pult_data.data_to_pult.moto[22] = edrk.pult_data.data_to_pult.count_revers - -} - - -void update_nPCH(void) -{ - - static int pause_w = 5, first_run = 1; // 10 сек задержка на прием данных от пульта - int flag_1 = 0, flag_2 = 0, i; - static int prev_active = 0; - - if (control_station.alive_control_station[CONTROL_STATION_INGETEAM_PULT_RS485]==0) - { - pause_w = 5; - } - - if (pause_w > 1) - { - pause_w--; -// if (edrk.pult_data.nPCH_from_pult) -// if (pause_w > 1) -// pause_w = 1; - prev_active = control_station.alive_control_station[CONTROL_STATION_INGETEAM_PULT_RS485]; - return; - } - - // проверка на -1 в пульте - // если в пульте -1 и мы только запустились, значит надо все обнулить - // иначе запоминаем то что в пульте - if (pause_w==1 && first_run) - { - //номер ПЧ - if (edrk.pult_data.data_from_pult.nPCH==-1) // нет инита - { - edrk.pult_data.data_to_pult.nPCH = edrk.pult_data.data.nPCH = 0; - } - else - edrk.pult_data.data_to_pult.nPCH = edrk.pult_data.data.nPCH = edrk.pult_data.data_from_pult.nPCH; - - //моточасы переключения с насоса на насос - if (edrk.pult_data.data_from_pult.TimeToChangePump == -1) // нет инита - edrk.pult_data.data_to_pult.TimeToChangePump = edrk.pult_data.data.TimeToChangePump = 0; - else - edrk.pult_data.data_to_pult.TimeToChangePump = edrk.pult_data.data.TimeToChangePump = edrk.pult_data.data_from_pult.TimeToChangePump; - - //моточасы + реверс + кол-во сборов - for (i=0;i=0) - { - edrk.pult_data.data_to_pult.nPCH = edrk.pult_data.data_from_pult.nPCH; - flag_1 = 1; - edrk.pult_data.data.nPCH = edrk.pult_data.data_from_pult.nPCH; - } - - // тут пульт выдал -1 значит он обновил прошивку - if (edrk.pult_data.data_from_pult.nPCH != edrk.pult_data.data.nPCH && edrk.pult_data.data_from_pult.nPCH == -1) - { - edrk.pult_data.data_to_pult.nPCH = edrk.pult_data.data.nPCH; - flag_1 = 1; - } - - - //моточасы переключения с насоса на насос - // ловим изменения от пульта - if (edrk.pult_data.data_from_pult.TimeToChangePump != edrk.pult_data.data.TimeToChangePump - && edrk.pult_data.data_from_pult.TimeToChangePump >= 0) - { - edrk.pult_data.data_to_pult.TimeToChangePump = edrk.pult_data.data_from_pult.TimeToChangePump; - flag_1 = 1; - edrk.pult_data.data.TimeToChangePump = edrk.pult_data.data_from_pult.TimeToChangePump; - } - - // тут пульт выдал -1 значит он обновил прошивку - if (edrk.pult_data.data_from_pult.TimeToChangePump != edrk.pult_data.data.TimeToChangePump - && edrk.pult_data.data_from_pult.TimeToChangePump == -1) - { - edrk.pult_data.data_to_pult.TimeToChangePump = edrk.pult_data.data.TimeToChangePump; - flag_1 = 1; - } - - // build - // тут пульт выдал -1 значит он обновил прошивку - if (edrk.pult_data.data_from_pult.count_build != edrk.pult_data.data.count_build - && edrk.pult_data.data_from_pult.count_build == -1) - { - edrk.pult_data.data_to_pult.count_build = edrk.pult_data.data.count_build; - flag_1 = 1; - } - - if (edrk.pult_data.data_from_pult.count_build != edrk.pult_data.data.count_build) - { - edrk.pult_data.data_to_pult.count_build = edrk.pult_data.data.count_build; - flag_1 = 1; - } - - // revers - // тут пульт выдал -1 значит он обновил прошивку - if (edrk.pult_data.data_from_pult.count_revers != edrk.pult_data.data.count_revers - && edrk.pult_data.data_from_pult.count_revers == -1) - { - edrk.pult_data.data_to_pult.count_revers = edrk.pult_data.data.count_revers; - flag_1 = 1; - } - - if (edrk.pult_data.data_from_pult.count_revers != edrk.pult_data.data.count_revers ) - { - edrk.pult_data.data_to_pult.count_revers = edrk.pult_data.data.count_revers; - flag_1 = 1; - } - // даем команду сохранить - edrk.pult_data.flagSaveDataPCH = flag_1; - - - // moto - for (i=0;i= 2) - to_store = 2; - else - if (edrk.pult_cmd.log_what_memory >= 1) - to_store = 1; - else - to_store = 0; - - //40198 - сохранения параметров системы (десятиминутный логер) на флешку (2), на карту (1), на карту+usb (3) - if (prev_cmd == 0 && cmd && to_store && flag_wait == 0) - { - edrk.pult_data.flagSaveSlowLogs = to_store; - flag_wait = 1; - time_wait_save_log = global_time.miliseconds; - } - - - if (flag_wait) - { - if (detect_pause_milisec(COUNT_WAIT_SAVE_LOG, &time_wait_save_log)) - { - flag_wait = 0; - flag_clear = 1; // даем команду на стирание - edrk.pult_data.flagSaveSlowLogs = 0; - time_wait_clear_log = global_time.miliseconds; - } - - } - else - { - - } - - - - - if (flag_clear) // стираем - { - edrk.pult_data.flagSaveSlowLogs = 100; - if (detect_pause_milisec(COUNT_WAIT_SAVE_LOG, &time_wait_clear_log)) - { - flag_wait = 0; - flag_clear = 0; - edrk.pult_data.flagSaveSlowLogs = 0; - } - - } - - //Статус карты и флешки можно узнать в регистре 30033: - -// Значение 0 - нет ни флешки, ни карты; -// Значение 1 - нет флешки, есть карта; -// Значение 2 - есть флешка, нет карты; -// Значение 3 - есть и флешка и карта; -} diff --git a/Inu/Src/main/modbus_hmi_update.h b/Inu/Src/main/modbus_hmi_update.h index 3ed0c05..8a322d9 100644 --- a/Inu/Src/main/modbus_hmi_update.h +++ b/Inu/Src/main/modbus_hmi_update.h @@ -1,16 +1,11 @@ #ifndef _HMI_UPDATE #define _HMI_UPDATE - -#define LIMITER_U_I_PULT 5.0 //10.0 - - typedef enum { state_not_init = 0, state_ready1 = 1, state_ready2, state_go, state_assemble, state_fault, state_accident } Inverter_state; void update_tables_HMI(void); -void update_logs_cmd_HMI(void); void update_tables_HMI_on_inited(int perc_load); void update_tables_HMI_analog(void); @@ -26,14 +21,4 @@ void func_unpack_answer_from_Ingeteam(unsigned int cc); extern int hmi_watch_dog; -void update_nPCH(void); - -void inc_count_build(void); -void inc_count_revers(void); - -void set_write_slow_logs(int cmd); - -void update_LoggerParams(void); - - #endif //_HMI_UPDATE diff --git a/Inu/Src/main/modbus_svu_update.c b/Inu/Src/main/modbus_svu_update.c index d9e6fe2..db94086 100644 --- a/Inu/Src/main/modbus_svu_update.c +++ b/Inu/Src/main/modbus_svu_update.c @@ -38,7 +38,7 @@ void update_svu_modbus_table(void) // modbus_table_can_out[4].all = Перегрузка ГЭД; modbus_table_can_out[5].all = edrk.Status_Ready.bits.Batt; modbus_table_can_out[6].all = edrk.from_ing1.bits.UPC_24V_NORMA | edrk.from_ing1.bits.OP_PIT_NORMA ? 0 : 1; - modbus_table_can_out[7].all = WRotor.RotorDirectionSlow >= 0 ? 0 : 1; + modbus_table_can_out[7].all = WRotorPBus.RotorDirection1 >= 0 ? 0 : 1; modbus_table_can_out[8].all = edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER || edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER ? 1 : 0; current_active_control = get_current_station_control(); @@ -46,7 +46,7 @@ void update_svu_modbus_table(void) current_active_control == CONTROL_STATION_MPU_KEY_CAN || current_active_control == CONTROL_STATION_MPU_KEY_RS485 ? 2 : current_active_control == CONTROL_STATION_ZADATCHIK_CAN ? 3 : current_active_control == CONTROL_STATION_VPU_CAN ? 4 : - current_active_control == CONTROL_STATION_MPU_SVU_CAN || current_active_control == CONTROL_STATION_MPU_SVU_RS485 ? 5 : + current_active_control == CONTROL_STATION_MPU_SVU_CAN || current_active_control == CONTROL_STATION_MPU_SVU_RS485 ? 4 : 0; modbus_table_can_out[10].all = edrk.errors.e2.bits.T_UO1_MAX || edrk.errors.e6.bits.UO1_KEYS ? 3 : edrk.warnings.e2.bits.T_UO1_MAX ? 2 : 1; @@ -64,32 +64,23 @@ void update_svu_modbus_table(void) edrk.warnings.e2.bits.T_UO7_MAX ? 2 : 1; modbus_table_can_out[17].all = edrk.Status_QTV_Ok;// edrk.from_shema.bits.QTV_ON_OFF; modbus_table_can_out[18].all = edrk.from_svu.bits.BLOCKED; - modbus_table_can_out[19].all = edrk.from_shema_filter.bits.UMP_ON_OFF; - modbus_table_can_out[20].all = edrk.from_shema_filter.bits.READY_UMP; + modbus_table_can_out[19].all = edrk.from_shema.bits.UMP_ON_OFF; + modbus_table_can_out[20].all = edrk.from_shema.bits.READY_UMP; modbus_table_can_out[21].all = edrk.from_ing1.bits.RASCEPITEL_ON; modbus_table_can_out[22].all = edrk.from_ing1.bits.UPC_24V_NORMA; modbus_table_can_out[23].all = edrk.from_ing1.bits.OHLAD_UTE4KA_WATER; modbus_table_can_out[24].all = edrk.from_ing2.bits.SOST_ZAMKA; - modbus_table_can_out[25].all = edrk.from_ing1.bits.ZARYAD_ON | edrk.from_shema_filter.bits.UMP_ON_OFF; //Видимо, заряда от внутреннего УМП не будет, добавил УМП намагничивания + modbus_table_can_out[25].all = edrk.from_ing1.bits.ZARYAD_ON | edrk.from_shema.bits.UMP_ON_OFF; //Видимо, заряда от внутреннего УМП не будет, добавил УМП намагничивания modbus_table_can_out[26].all = edrk.from_ing1.bits.VENTIL_ON; modbus_table_can_out[27].all = edrk.to_ing.bits.NASOS_1_ON == 1 && edrk.from_ing1.bits.NASOS_ON == 1 ? 1 : 0; modbus_table_can_out[28].all = edrk.to_ing.bits.NASOS_2_ON == 1 && edrk.from_ing1.bits.NASOS_ON == 1 ? 1 : 0; modbus_table_can_out[29].all = edrk.from_ing1.bits.NASOS_NORMA; modbus_table_can_out[30].all = edrk.from_ing1.bits.ZAZEML_ON; modbus_table_can_out[31].all = edrk.from_ing1.bits.NAGREV_ON; - modbus_table_can_out[32].all = edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ? 1 : 0; - modbus_table_can_out[33].all = edrk.errors.e5.bits.ERROR_ISOLATE == 0 && edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ? 0 : 1; + modbus_table_can_out[32].all = edrk.errors.e5.bits.ERROR_ISOLATE == 0 && edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 1 ? 0 : 1; + modbus_table_can_out[33].all = edrk.from_ing1.bits.BLOCK_IZOL_NORMA == 0 ? 1 : 0; modbus_table_can_out[34].all = edrk.from_ing1.bits.ALL_KNOPKA_AVARIA; - - if (edrk.MasterSlave == MODE_MASTER) - modbus_table_can_out[35].all = 1; - else - if (edrk.MasterSlave == MODE_SLAVE) - modbus_table_can_out[35].all = 0; - else - modbus_table_can_out[35].all = 2; // MODE_DONTKNOW - -// modbus_table_can_out[35].all = edrk.MasterSlave == MODE_MASTER ? 1 : 0; + modbus_table_can_out[35].all = edrk.MasterSlave == MODE_MASTER ? 1 : 0; modbus_table_can_out[36].all = edrk.from_ing1.bits.OP_PIT_NORMA & edrk.from_ing1.bits.UPC_24V_NORMA; modbus_table_can_out[37].all = optical_read_data.status == 1 && optical_write_data.status == 1 ? 1 : 0; modbus_table_can_out[38].all = edrk.warnings.e7.bits.MASTER_SLAVE_SYNC == 0 ? 1 : 0; @@ -136,12 +127,12 @@ void update_svu_modbus_table(void) modbus_table_can_out[71].all = fast_round(edrk.p_water_edrk.real_p_water[0]); modbus_table_can_out[72].all = fast_round(_IQtoF(edrk.zadanie.iq_oborots_zad_hz_rmp) * NORMA_FROTOR * 60); - modbus_table_can_out[73].all = edrk.oborots;// fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60); - modbus_table_can_out[74].all = edrk.oborots;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60); //Sensor 1 - modbus_table_can_out[75].all = edrk.oborots;//fast_round(_IQtoF(WRotor.iqWRotorSumFilter3) * NORMA_FROTOR * 60); //Sensor 1 + modbus_table_can_out[73].all = fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul1) * NORMA_FROTOR * 60); + modbus_table_can_out[74].all = fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul1) * NORMA_FROTOR * 60); //Sensor 1 + modbus_table_can_out[75].all = fast_round(_IQtoF(WRotor.iqWRotorCalcBeforeRegul1) * NORMA_FROTOR * 60); //Sensor 1 - modbus_table_can_out[76].all = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp) * NORMA_ACP * NORMA_ACP / 1000.0); - modbus_table_can_out[77].all = fabs(edrk.power_kw);// fast_round(_IQtoF(filter.PowerScalar) * NORMA_ACP* NORMA_ACP / 1000.0); + modbus_table_can_out[76].all = fast_round(_IQtoF(edrk.zadanie.iq_power_zad_rmp) * NORMA_ACP* NORMA_ACP / 1000.0); + modbus_table_can_out[77].all = fast_round(_IQtoF(filter.PowerScalar) * NORMA_ACP* NORMA_ACP / 1000.0); modbus_table_can_out[78].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[0]); modbus_table_can_out[79].all = fast_round(edrk.temper_acdrive.winding.filter_real_temper[1]); @@ -200,14 +191,10 @@ void update_svu_modbus_table(void) modbus_table_can_out[117].all = edrk.errors.e0.bits.U_IN_MIN; modbus_table_can_out[118].all = edrk.warnings.e0.bits.U_IN_MAX; modbus_table_can_out[119].all = edrk.errors.e0.bits.U_IN_MAX; - modbus_table_can_out[120].all = edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK; //TODO неисправность датчика оборотов - modbus_table_can_out[121].all = edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK; //TODO превышение допустимых оборотов + modbus_table_can_out[120].all = 0; //TODO неисправность датчика оборотов + modbus_table_can_out[121].all = 0; //TODO превышение допустимых оборотов modbus_table_can_out[122].all = edrk.Kvitir; - - modbus_table_can_out[137].all = edrk.pult_data.data_from_pult.moto[15]; - modbus_table_can_out[138].all = edrk.pult_data.data_from_pult.moto[6]; - update_errors_to_svu(); update_protect_levels_to_MPU(); @@ -215,79 +202,19 @@ void update_svu_modbus_table(void) } -#define MPU_ADRESS_CMD_START 122 // у нас -1 относительно нио14, 122 соответствует 123 у нио14 -#define MPU_ADRESS_CMD_END 144 //138 // - -#if (MPU_ADRESS_CMD_END>=SIZE_MODBUS_TABLE) -#define MPU_ADRESS_CMD_END (SIZE_MODBUS_TABLE-1) -#endif - - -#if (MPU_ADRESS_CMD_END - MPU_ADRESS_CMD_START +1 )>CONTROL_STATION_MAX_RAW_DATA -#define MPU_LENGTH_CMD CONTROL_STATION_MAX_RAW_DATA -#else -#define MPU_LENGTH_CMD (MPU_ADRESS_CMD_END - MPU_ADRESS_CMD_START + 1) -#endif -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// - -void unpack_answer_from_MPU_SVU_CAN_filter(unsigned int cc) -{ - unsigned int i = 0, j = 0, k, max_data; - - for (i = 0; i < MPU_LENGTH_CMD; i++) - { - max_data = 0;//control_station.raw_array_data_temp[cc][i][0].all; - //min_data = 0;//control_station.raw_array_data_temp[cc][i][0].all; - - for (j=0; j max_data) - max_data = control_station.raw_array_data_temp[cc][i][j].all; - } - - control_station.raw_array_data[cc][i].all = max_data; - - } - -} - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// +#define ADRESS_CMD_START 122 void unpack_answer_from_MPU_SVU_CAN(unsigned int cc) { - int i = 0, j = 0, k; -// static unsigned int prev_CAN_count_cycle_input_units = 0; - - if (control_station.prev_CAN_count_cycle_input_units[cc] != mpu_can_setup.CAN_count_cycle_input_units[0]) - { - k = control_station.count_raw_array_data_temp[cc]; - for (i = 0, j = 0; i < MPU_LENGTH_CMD && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++) - { - control_station.raw_array_data_temp[cc][j][k].all = modbus_table_can_in[MPU_ADRESS_CMD_START+i].all; - } - - control_station.count_raw_array_data_temp[cc]++; - if (control_station.count_raw_array_data_temp[cc]>=CONTROL_STATION_MAX_RAW_DATA_TEMP) - control_station.count_raw_array_data_temp[cc] = 0; - - control_station.prev_CAN_count_cycle_input_units[cc] = mpu_can_setup.CAN_count_cycle_input_units[0]; - } - - -// for (i = ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++) -// { -// control_station.raw_array_data[cc][j].all = modbus_table_can_in[i].all; -// } - - unpack_answer_from_MPU_SVU_CAN_filter(cc); + int i = 0, j = 0; + for (i = ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++) + control_station.raw_array_data[cc][j].all = modbus_table_can_in[i].all; } void unpack_answer_from_MPU_SVU_RS(unsigned int cc) { int i = 0, j = 0; - for (i = MPU_ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++) + for (i = ADRESS_CMD_START, j = 0; i < SIZE_MODBUS_TABLE && j < CONTROL_STATION_MAX_RAW_DATA; i++, j++) control_station.raw_array_data[cc][j].all = modbus_table_rs_in[i].all; } @@ -476,11 +403,7 @@ void update_errors_to_svu() { modbus_table_can_out[211].bit.bit12 = edrk.warnings.e2.bits.T_AIR2_MAX; modbus_table_can_out[211].bit.bit13 = edrk.warnings.e2.bits.T_AIR3_MAX; - if (edrk.power_limit.all) - modbus_table_can_out[211].bit.bit14 = 1; - else - modbus_table_can_out[211].bit.bit14 = 0; - + modbus_table_can_out[211].bit.bit14 = edrk.power_limit.all; modbus_table_can_out[211].bit.bit15 = edrk.warnings.e10.bits.WARNING_I_OUT_OVER_1_6_NOMINAL; modbus_table_can_out[212].bit.bit0 = edrk.errors.e5.bits.ERROR_PRE_CHARGE_ON; @@ -691,10 +614,10 @@ void update_protect_levels_to_MPU() { modbus_table_can_out[183].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_minus20) * NORMA_ACP;//_IQtoF(edrk.iqMIN_U_IN) * NORMA_ACP; modbus_table_can_out[184].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_minus20) * NORMA_ACP; modbus_table_can_out[185].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_plus20) * NORMA_ACP;//_IQtoF(edrk.iqMIN_U_ZPT) * NORMA_ACP; - modbus_table_can_out[186].all = _IQtoF(analog_protect.in_voltage[1].setup.levels.iqNominal_plus20) * NORMA_ACP; - modbus_table_can_out[187].all = //_IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; + modbus_table_can_out[186].all = _IQtoF(analog_protect.in_voltage[0].setup.levels.iqNominal_plus20) * NORMA_ACP; + modbus_table_can_out[187].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; modbus_table_can_out[188].all = _IQtoF(edrk.iqMAX_U_IN) * NORMA_ACP; - modbus_table_can_out[189].all = //_IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP; + modbus_table_can_out[189].all = _IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP; modbus_table_can_out[190].all = _IQtoF(edrk.iqMAX_U_ZPT) * NORMA_ACP; modbus_table_can_out[191].all = protect_levels.alarm_Izpt_max; diff --git a/Inu/Src/main/optical_bus.c b/Inu/Src/main/optical_bus.c index 22ae162..1194f3a 100644 --- a/Inu/Src/main/optical_bus.c +++ b/Inu/Src/main/optical_bus.c @@ -67,7 +67,7 @@ void optical_bus_update_data_write(void) } } - if (edrk.Status_Ready.bits.ready7 || (edrk.Status_Ready.bits.ready5 && edrk.Status_Ready.bits.ImitationReady2) ) + if (edrk.Status_Ready.bits.ready7) optical_write_data.data.cmd.bit.ready_cmd = CODE_READY_CMD_READY2; else if (edrk.SumSbor) @@ -79,7 +79,7 @@ void optical_bus_update_data_write(void) // optical_write_data.cmd.bit.slave = // // optical_write_data.cmd.bit.start_pwm = - optical_write_data.data.cmd.bit.statusQTV = edrk.from_shema_filter.bits.QTV_ON_OFF; + optical_write_data.data.cmd.bit.statusQTV = edrk.from_shema.bits.QTV_ON_OFF; // optical_write_data.cmd.bit.stop_pwm = optical_write_data.data.cmd.bit.sync_1_2 = sync_data.local_flag_sync_1_2; @@ -104,7 +104,6 @@ void optical_bus_update_data_write(void) #pragma CODE_SECTION(optical_bus_write,".fast_run"); void optical_bus_write(void) { -#if(USE_TK_3) // check error write PBUS OPTICAL BUS project.cds_tk[3].optical_bus_check_error_write(&project.cds_tk[3]); @@ -118,7 +117,7 @@ void optical_bus_write(void) project.cds_tk[3].optical_bus_write_data(&project.cds_tk[3]); -#endif + } @@ -256,9 +255,8 @@ void optical_bus_read(void) // check error write PBUS OPTICAL BUS // project.cds_tk[3].optical_bus_check_error_write(&project.cds_tk[3]); // read data from OPTICAL BUS -#if(USE_TK_3) project.cds_tk[3].read_pbus(&project.cds_tk[3]); -#endif + return; } @@ -266,9 +264,8 @@ void optical_bus_read(void) #pragma CODE_SECTION(optical_bus_read_clear_count_error,".fast_run"); void optical_bus_read_clear_count_error(void) { -#if(USE_TK_3) + project.cds_tk[3].optical_data_in.local_count_error = 0; -#endif return; } @@ -284,7 +281,7 @@ STATUS_DATA_READ_OPT_BUS optical_bus_get_status_and_read(void) // read data from OPTICAL BUS // project.cds_tk[3].read_pbus(&project.cds_tk[3]); -#if(USE_TK_3) + // check error read PBUS OPTICAL BUS project.cds_tk[3].optical_bus_check_error_read(&project.cds_tk[3]); @@ -329,9 +326,7 @@ STATUS_DATA_READ_OPT_BUS optical_bus_get_status_and_read(void) } -#else - status_read.all = 0; -#endif + return status_read; //нет данных или ошибки } diff --git a/Inu/Src/main/optical_bus.h b/Inu/Src/main/optical_bus.h index ce30d7c..cff6a18 100644 --- a/Inu/Src/main/optical_bus.h +++ b/Inu/Src/main/optical_bus.h @@ -87,14 +87,12 @@ typedef struct { unsigned int data_was_update_between_pwm_int; unsigned int error_wdog; unsigned int count_error_wdog; - unsigned int count_read_optical_bus_old_data; // счетчик времени сколько данные не обновлялись - // OPTICAL_BUS_CODE_STATUS code_status; } OPTICAL_BUS_DATA; -#define OPTICAL_BUS_DATA_DEFAULT {{0,0,0,0},{0,0,0,0},0,0,0,0,0,0,0,0} +#define OPTICAL_BUS_DATA_DEFAULT {{0,0,0,0},{0,0,0,0},0,0,0,0,0,0,0} extern OPTICAL_BUS_DATA optical_write_data; extern OPTICAL_BUS_DATA optical_read_data; diff --git a/Inu/Src/main/overheat_limit.c b/Inu/Src/main/overheat_limit.c index e2c2720..9e81fa7 100644 --- a/Inu/Src/main/overheat_limit.c +++ b/Inu/Src/main/overheat_limit.c @@ -12,13 +12,13 @@ #include "IQmathLib.h" #include "math_pi.h" -#include "limit_lib.h" + +_iq linear_decrease(float current, int alarm_level, int warnig_level); TEMPERATURE_LIMIT_KOEFFS temper_limit_koeffs = TEMPERATURE_LIMIT_KOEFFS_DEFAULTS; -void calc_limit_overheat() -{ +void calc_limit_overheat() { int *p_alarm, *p_abnormal; _iq sum_limit = CONST_IQ_1; _iq val; @@ -78,3 +78,16 @@ void calc_limit_overheat() edrk.temper_limit_koeffs.code_status = 0; } + +_iq linear_decrease(float current, int alarm_level, int warnig_level) { + float delta = current - warnig_level; + float max_delta = alarm_level - warnig_level; + if (delta <= 0 || max_delta <= 0) { + return CONST_IQ_1; + } else { + if (delta>max_delta) + return 0; + else + return CONST_IQ_1 - _IQ(delta / max_delta); + } +} diff --git a/Inu/Src/main/params.h b/Inu/Src/main/params.h index 7abc592..5960ad8 100644 --- a/Inu/Src/main/params.h +++ b/Inu/Src/main/params.h @@ -5,39 +5,20 @@ #if(_FLOOR6) -#define _ENABLE_PWM_LINES_FOR_TESTS 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS 1 -#else - -#define _ENABLE_PWM_LINES_FOR_TESTS 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 -#endif - - -#if(_FLOOR6) -#define MODE_DISABLE_ENABLE_WDOG 1 // 0 - wdog работает, 1 - запрещен -#else -#define MODE_DISABLE_ENABLE_WDOG 0 // 0 - wdog работает, 1 - запрещен #endif - +#define MODE_DISABLE_ENABLE_WDOG 0//1 #define CHECK_IN_OUT_TERMINAL 1 #define WORK_ON_STEND_D 0//1 +#define U_D_MAX_ERROR_GLOBAL_2800 15658734 // 2800V //////////////////////////////////////////////////////////////////// diff --git a/Inu/Src/main/params_alg.h b/Inu/Src/main/params_alg.h index 8529a80..a63360e 100644 --- a/Inu/Src/main/params_alg.h +++ b/Inu/Src/main/params_alg.h @@ -8,104 +8,59 @@ #ifndef SRC_MAIN_PARAMS_ALG_H_ #define SRC_MAIN_PARAMS_ALG_H_ -// разпрет расчета км на слейве, берем с мастера -#define DISABLE_CALC_KM_ON_SLAVE 0//1 -#define DISABLE_WORK_BREAK 0 // запрнтить работу с тормозными +#define MZZ_ADD_1 0.5 // 0.25 //0.5 интенсивнось набора момента за 1 мсек +#define MZZ_ADD_2 0.1 //0.05 //0.1 интенсивнось набора момента за 1 мсек +#define FZAD_ADD_MAX 0.08 //0.005 //0.08 интенсивнось набора fzad за 1 мсек +#define FZAD_DEC 0.0004 //интенсивнось спада fzad за 1 мсек -#define SENSOR_ALG_22220 1 -#define SENSOR_ALG_23550 2 +#define POWERZAD_ADD_MAX 0.08 //0.005 //0.08 интенсивнось набора fzad за 1 мсек +#define POWERZAD_DEC 0.0004 //интенсивнось спада fzad за 1 мсек + +#define POLUS 6 //6 // число пар полюсов +#define BPSI_NORMAL 0.2 //0.3 // скольжение константа +#define PROVOROT_F_HZ 0.2 // проворот +#define PROVOROT_OBOROTS 3 // проворот -#define SENSOR_ALG SENSOR_ALG_22220 -//#define SENSOR_ALG SENSOR_ALG_23550 +#define ADD_KP_DF (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) +#define ADD_KI_DF (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) +#define ADD_KP_DPOWER (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) +#define ADD_KI_DPOWER (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) -#define NOMINAL_U_ZARYAD 2520 // Задание напряжения заряда ЗПТ -#define NOMINAL_U_BREAK_LEVEL 2580 // начало работы тормозных + IQ_DELTA_U_START_RECUP=100V -#define NOMINAL_SET_IZAD 910 // ток от поста -#define NOMINAL_SET_K_U_DISBALANCE 40//20 // Задание К напряжения дисбаланса коэф. обратной связи по дисбалансу, надо >0 чтоб работал алгоритм -#define NOMINAL_SET_LIMIT_POWER 6300 // запас мощность от поста - - - - - -/////////////////////////////////////////////////////////////// -#define U_D_MAX_ERROR_GLOBAL IQ_I_U_VALUE_PLUS_2850 //U_D_MAX_ERROR_GLOBAL_2850 - -#define MAX_U_PROC_SMALL 2.5 //1.4 -#define MAX_U_PROC 1.1 //1.11 //1.4 -#define MIN_U_PROC 0.8 //0.7 - -#define ADD_U_MAX_GLOBAL 200.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge -#define ADD_U_MAX_GLOBAL_SMALL 500.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge -#define LEVEL_DETECT_U_SMALL 1000.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge - -#define KOEF_IM_ON_TORMOG 0.65// 0.75 // на сколько уменьшать возможную мощность при торможении -#define KOEF_IM_ON_TORMOG_WITH_MAX_TEMPER_BREAK 0.1// с перегревом томозных на сколько уменьшать возможную мощность при торможении - -/////////////////////////////////////////////////////////////// - - -#define MZZ_ADD_1 0.5 // 0.25 //0.5 интенсивнось набора момента за 1 мсек -#define MZZ_ADD_2 0.15 ///0.1 //0.05 //0.1 интенсивнось набора момента за 1 мсек -#define MZZ_ADD_3 0.25 //0.05 ///0.1 //0.05 //0.1 интенсивнось набора момента за 1 мсек - -#define FZAD_ADD_MAX 0.08 //0.005 //0.08 интенсивнось набора fzad за 1 мсек -#define FZAD_DEC 0.0004 //интенсивнось спада fzad за 1 мсек - -#define POWERZAD_ADD_MAX 0.08 //0.005 //0.08 интенсивнось набора fzad за 1 мсек -#define POWERZAD_DEC 0.0004 //интенсивнось спада fzad за 1 мсек - -#define POLUS 6 //6 // число пар полюсов -#define BPSI_NORMAL 0.22 //0.3 // скольжение константа -#define BPSI_MAXIMAL 0.35 //0.3 // скольжение константа -#define BPSI_MINIMAL 0.05 //0.3 // скольжение константа -#define PROVOROT_F_HZ 0.2 // проворот -#define PROVOROT_OBOROTS 10 // проворот - - -#define ADD_KP_DF (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) -#define ADD_KI_DF (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) - -#define ADD_KP_DPOWER (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) -#define ADD_KI_DPOWER (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) - -#define MIN_MZZ_FOR_DF 210 -#define MIN_MZZ_FOR_DPOWER 210 +#define MIN_MZZ_FOR_DF 210 +#define MIN_MZZ_FOR_DPOWER 210 //////////////////// -#define PID_KP_IM 0.036 //0.018 //0.0013// 0.018 //0.036 //0.018 //0.18 //0.095 // PID Kp -#define PID_KI_IM 0.32 // 0.16 //0.32 //0.16 //0.08//0.8//0.025 //0.08 // PID Ki -#define PID_KD_IM 0.0000 //*100 // PID Kd -#define PID_KC_IM 0.09 // PID Kc +#define PID_KP_IM 0.018 //0.0013// 0.018 //0.036 //0.018 //0.18 //0.095 // PID Kp +#define PID_KI_IM 0.08//0.8//0.025 //0.08 // PID Ki +#define PID_KD_IM 0.0000 //*100 // PID Kd +#define PID_KC_IM 0.09 // PID Kc -#define PID_KP_F 12.0//6.0//12.0 //6.0 //18 //12//6//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp -#define PID_KI_F 0.00020 //0.00010 // 0.008 // PID Ki -//#define PID_KI_F 0.00030 //0.00010 // 0.008 // PID Ki -#define PID_KD_F 0.000 //*100 PID Kd -#define PID_KC_F 0.00005//0.005 // PID Kc -//#define PID_KC_F 0.000 // PID Kc +#define PID_KP_F 18 //12//6//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp +#define PID_KI_F 0.00020 //0.00010 // 0.008 // PID Ki +//#define PID_KI_F 0.00030 //0.00010 // 0.008 // PID Ki +#define PID_KD_F 0.000 //*100 PID Kd +#define PID_KC_F 0.005 // PID Kc +//#define PID_KC_F 0.000 // PID Kc -#define PID_KP_POWER 9//3//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp -//#define PID_KI_F 0.00020 //0.00010 // 0.008 // PID Ki -#define PID_KI_POWER 0.00030 //0.00010 // 0.008 // PID Ki -#define PID_KD_POWER 0.000 //*100 PID Kd -#define PID_KC_POWER 0.0001 // PID Kc +#define PID_KP_POWER 9//3//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp +//#define PID_KI_F 0.00020 //0.00010 // 0.008 // PID Ki +#define PID_KI_POWER 0.00030 //0.00010 // 0.008 // PID Ki +#define PID_KD_POWER 0.000 //*100 PID Kd +#define PID_KC_POWER 0.005 // PID Kc /////////////////// // макс. k ограничено электроникой -#define K_STATOR_MAX 0.93 // 0.91 // для DEF_PERIOD_MIN_MKS = 60 мкс -#define K_STATOR_MIN 0.020 // 0.91 // для DEF_PERIOD_MIN_MKS = 60 мкс - +#define K_STATOR_MAX 0.85 // 0.91 // для DEF_PERIOD_MIN_MKS = 60 мкс //#define K_STATOR_MAX 0.89 //для DEF_PERIOD_MIN_MKS = 80 мкс @@ -115,101 +70,40 @@ #define MAX_ZADANIE_U_CHARGE 2800.0//1500.0 //V //#define MAX_ZADANIE_F_ROTOR 70 - -#define MAX_ZADANIE_OBOROTS_ROTOR 230.0 //340 //240 1000 //260.0 // +/- ob/min -#define MIN_ZADANIE_OBOROTS_ROTOR -230.0 //-180.0 //-230.0 // 1000 //260.0 // +/- ob/min - -#define MAX_1_ZADANIE_OBOROTS_ROTOR 120.0 //340 //240 1000 //260.0 // +/- ob/min -#define MIN_1_ZADANIE_OBOROTS_ROTOR -90.0 //-230.0 // 1000 //260.0 // +/- ob/min +#define MAX_ZADANIE_OBOROTS_ROTOR 230 //340 //240 1000 //260.0 // +/- ob/min +#define MIN_ZADANIE_OBOROTS_ROTOR 0 // 1000 //260.0 // +/- ob/min -#define DEAD_ZONE_ZADANIE_OBOROTS_ROTOR 10.0 +#define MAX_ZADANIE_I_M 1000.0// 1000.0 //750.0 // A -#define MAX_ZADANIE_I_M 950.0// 1000.0 //750.0 // A +#define MAX_ZADANIE_POWER 1000.0 // kWt +#define MIN_ZADANIE_POWER 0 // kWt -#define MAX_ZADANIE_POWER 6300.0 // kWt -#define MIN_ZADANIE_POWER -6300.0 // kWt - -#define MAX_1_ZADANIE_POWER 3000.0 // kWt -#define MIN_1_ZADANIE_POWER -3000.0 // kWt +#define MAX_ZADANIE_K_M 0.92 // A +#define MAX_ZADANIE_F 60.0 // Hz +#define MIN_ZADANIE_F 0.0 //60.0 // Hz -#define SUPER_MAX_ZADANIE_LIMIT_POWER 6500.0 // kWt - -#define MAX_ZADANIE_LIMIT_POWER 6300.0 // kWt -#define MAX_1_ZADANIE_LIMIT_POWER 2000.0 // kWt - -#define MIN_ZADANIE_LIMIT_POWER 100.0 // kWt -#define MIN_ZADANIE_LIMIT_POWER_FROM_SVU 50.0 // kWt -#define POWER_ZAPAS_FOR_UOM 5 //50 // доп запас для УОМ - -#define DEAD_ZONE_ZADANIE_POWER 50.0 // kWt -#define DEAD_ZONE_ZADANIE_LIMIT_POWER 50.0 // kWt +#define MAX_ZADANIE_K_U_DISBALANCE 2.0 //1.0 // k +#define MAX_ZADANIE_KPLUS_U_DISBALANCE 1.0 // k -#define MAX_ZADANIE_K_M K_STATOR_MAX // A -#define MAX_ZADANIE_F 30.0 // Hz -#define MIN_ZADANIE_F -30.0 //60.0 // Hz - - -#define MAX_ZADANIE_K_U_DISBALANCE 2.0 //1.0 // k -#define MAX_ZADANIE_KPLUS_U_DISBALANCE 1.0 // k - - - -#define T_NARAST_ZADANIE_F 5.0 // sec -#define T_NARAST_ZADANIE_OBOROTS_ROTOR 80.0 //20.0 //30.0 //15.0 // sec - -#define T1_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS 80.0 //20.0 //30.0 //15.0 // sec -#define T1_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS 40.0 //20.0 //30.0 //15.0 // sec - -#define T2_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS 80.0 //160.0 //20.0 //30.0 //15.0 // sec -#define T2_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS 40.0 //20.0 //30.0 //15.0 // sec - -#define T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS 600.0 //160.0 //20.0 //30.0 //15.0 // sec -#define T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS 600.0 //20.0 //30.0 //15.0 // sec - - - -#define T_NARAST_ZADANIE_K_M 15.0 // sec -#define T_NARAST_ZADANIE_I_M 15.0 // sec - -#define T1_NARAST_ZADANIE_POWER_PLUS 80.0 //30.0 // sec -#define T1_NARAST_ZADANIE_POWER_MINUS 30.0 //30.0 // sec -#define T2_NARAST_ZADANIE_POWER_PLUS 80.0 //30.0 // sec -#define T2_NARAST_ZADANIE_POWER_MINUS 30.0 //30.0 // sec - -#define T_NARAST_ZADANIE_LIMIT_POWER 5.0 //30.0 // sec - -#define T1_NARAST_ZADANIE_LIMIT_POWER_PLUS 30.0 //30.0 // sec -#define T1_NARAST_ZADANIE_LIMIT_POWER_MINUS 5.0 //30.0 // sec -#define T2_NARAST_ZADANIE_LIMIT_POWER_PLUS 80.0 //30.0 // sec -#define T2_NARAST_ZADANIE_LIMIT_POWER_MINUS 5.0 //30.0 // sec - - -#define T_NARAST_ZADANIE_U_CHARGE 2.0 // sec -#define T_NARAST_ZADANIE_K_U_DISBALANCE 15.0 // sec -#define T_NARAST_ZADANIE_KPLUS_U_DISBALANCE 15.0 // sec - -#define T_NARAST_ZADANIE_IMITATION_OBOROTS_ROTOR 30.0 // sec +#define T_NARAST_ZADANIE_F 15.0 // sec +#define T_NARAST_ZADANIE_OBOROTS_ROTOR 30.0 // sec +#define T_NARAST_ZADANIE_K_M 15.0 // sec +#define T_NARAST_ZADANIE_I_M 15.0 // sec +#define T_NARAST_ZADANIE_POWER 100.0 //30.0 // sec +#define T_NARAST_ZADANIE_U_CHARGE 30.0 // sec +#define T_NARAST_ZADANIE_K_U_DISBALANCE 15.0 // sec +#define T_NARAST_ZADANIE_KPLUS_U_DISBALANCE 15.0 // sec -#define ENABLE_DECR_MZZ_POWER_IZAD 1 -// запас мощности при задании мощности от СВУ -#define POWER_AIN_100KW 186413 -#define DELTA_LEVEL_POWER_AIN_DECR_MZZ_DEF (3*POWER_AIN_100KW) // 300 kW // 559240 //300 кВт//186413 //100kW // iqP = P (W) /3000/3000 * 2^24 // -#define MIN_DELTA_LEVEL_POWER_AIN_DECR_MZZ_DEF (5*POWER_AIN_100KW) // 500 kW -#define SMEWENIE_LEVEL_POWER_AIN_DECR_MZZ_DEF 0 //(1*POWER_AIN_100KW) // 100 kW - -// меняется от 1 - полный размах до 0 - нет ограничения -#define MAX_KOEF_OGRAN_POWER_LIMIT CONST_IQ_05 // 0.5 -#define EXP_FILTER_KOEF_OGRAN_POWER_LIMIT 4.40//2.22 // в секундах diff --git a/Inu/Src/main/params_bsu.h b/Inu/Src/main/params_bsu.h index a58cc2c..856731a 100644 --- a/Inu/Src/main/params_bsu.h +++ b/Inu/Src/main/params_bsu.h @@ -8,41 +8,19 @@ #ifndef SRC_MAIN_PARAMS_BSU_H_ #define SRC_MAIN_PARAMS_BSU_H_ -#include "iq_values_norma_f.h" -#include "iq_values_norma_iu.h" -#include "iq_values_norma_oborot.h" -#define TKAK_23550 1 -#define TKAK_EDRK 2 -#define TKAK_VERSION TKAK_23550 -//#define TKAK_VERSION TKAK_EDRK -// для 23550_sp2 -#define TK_DEAD_TIME_NS 25000 //25.0 //40.0 -#define TK_ACKN_TIME_NS 2200 -#define TK_MIN_TIME_NS 25000 //80.0 //35.0 // 15.0 //40.0 -#define TK_SOFT_OFF_TIME_NS 20000 //25.0 //40.0 - -#define DIV_TIME_TK_SOFT_OFF 20 // 20 nsec -> 1 bit -#define DIV_TIME_TK_DEAD 640 //0.16 // 160 nsec -> 1 bit -#define DIV_TIME_TK_MIN 640 //0.16 // 160 nsec -> 1 bit - -#define DIV_TIME_TK_ACKN 20 // 20 nsec -> 1 bit - - -// для эдрк sp2 #define TK_DEAD_TIME_MKS 25.0 //40.0 #define TK_ACKN_TIME_MKS 2.2 #define TK_MIN_TIME_MKS 25.0 // 15.0 //40.0 + #define DIV_TIME_TK 0.4 // 0.16 - - #define MAX_READ_SBUS 1 //10 @@ -78,21 +56,18 @@ ////////////////////// -#define ENABLE_ROTOR_SENSOR_ZERO_SIGNAL 0 -#define ENABLE_ROTOR_SENSOR_1_PM67 1 -#define ENABLE_ROTOR_SENSOR_2_PM67 0 - -#define ENABLE_ROTOR_SENSOR_1_PBUS 0//1 -#define ENABLE_ROTOR_SENSOR_2_PBUS 0//1 + +#define ENABLE_ROTOR_SENSOR_1 1 +#define ENABLE_ROTOR_SENSOR_2 0 -#if (ENABLE_ROTOR_SENSOR_1_PM67==1 && ENABLE_ROTOR_SENSOR_2_PM67==0) +#if (ENABLE_ROTOR_SENSOR_1==1 && ENABLE_ROTOR_SENSOR_2==0) // проброс 1-го датчика на вход 2-го #define ENABLE_COMBO_SENSOR_1_TO_2 1 #define ENABLE_COMBO_SENSOR_2_TO_1 0 #endif -#if (ENABLE_ROTOR_SENSOR_1_PM67==0 && ENABLE_ROTOR_SENSOR_2_PM67==1) +#if (ENABLE_ROTOR_SENSOR_1==0 && ENABLE_ROTOR_SENSOR_2==1) // проброс 2-го датчика на вход 1-го #define ENABLE_COMBO_SENSOR_2_TO_1 1 #define ENABLE_COMBO_SENSOR_1_TO_2 0 @@ -100,7 +75,7 @@ -#if (ENABLE_ROTOR_SENSOR_1_PM67==1 && ENABLE_ROTOR_SENSOR_2_PM67==1) +#if (ENABLE_ROTOR_SENSOR_1==1 && ENABLE_ROTOR_SENSOR_2==1) #define ENABLE_COMBO_SENSOR_1 0 #define ENABLE_COMBO_SENSOR_1 0 diff --git a/Inu/Src/main/params_hwp.h b/Inu/Src/main/params_hwp.h index d3ebed4..ca8eb14 100644 --- a/Inu/Src/main/params_hwp.h +++ b/Inu/Src/main/params_hwp.h @@ -1,9 +1,8 @@ #define LEVEL_HWP_U_ZPT 2900 //2800 // V 0-2900 V -#define LEVEL_HWP_I_AF 800 //700 // A 0-450A -#define LEVEL_HWP_I_ZPT 1600 // A 0-2000?? -#define LEVEL_HWP_U_ABC 3100 //2900 //2800 // V 0-2000V -#define LEVEL_HWP_I_BREAK 900 //750 // A 0-2000A +#define LEVEL_HWP_I_AF 600 // A 0-450A +#define LEVEL_HWP_I_ZPT 500 // A 0-2000?? +#define LEVEL_HWP_U_ABC 2900 //2800 // V 0-2000V +#define LEVEL_HWP_I_BREAK 750 // A 0-2000A -#define convert_real_to_mv_hwp(nc,value) ((float)value*(float)R_ADC[0][nc]/(float)K_LEM_ADC[0][nc]*10.0) diff --git a/Inu/Src/main/params_motor.h b/Inu/Src/main/params_motor.h index 1e8c030..77e2f45 100644 --- a/Inu/Src/main/params_motor.h +++ b/Inu/Src/main/params_motor.h @@ -20,12 +20,12 @@ #define COS_FI 0.87 // Level of nominal currents -#define I_OUT_NOMINAL_IQ 5033164// 900 A //8388608 ~ 1500A //5592405 ~ 1000A // 10066329 ~ 1800A +#define I_OUT_NOMINAL_IQ 10066329 //8388608 ~ 1500A //5592405 ~ 1000A // 10066329 ~ 1800A //11184811 ~ 2000A // 12482249 ~ 2232A // 6710886 ~ 1200A -#define I_OUT_NOMINAL 900 +#define I_OUT_NOMINAL 1800 -#define MOTOR_CURRENT_NOMINAL 650.0 //930.0 -#define MOTOR_CURRENT_MAX 900.00 //1489.0 +#define MOTOR_CURRENT_NOMINAL 650.0//930.0 +#define MOTOR_CURRENT_MAX 1000.00//1489.0 diff --git a/Inu/Src/main/params_norma.h b/Inu/Src/main/params_norma.h index 9c3e790..e4ccc0b 100644 --- a/Inu/Src/main/params_norma.h +++ b/Inu/Src/main/params_norma.h @@ -5,66 +5,17 @@ * Author: yura */ -#ifndef _PARAMS_NORMA_H_ -#define _PARAMS_NORMA_H_ +#ifndef SRC_MAIN_PARAMS_NORMA_H_ +#define SRC_MAIN_PARAMS_NORMA_H_ +#include -//////////////////////////////////////////////////// -#define NORMA_FROTOR_INT 20 -#define NORMA_ACP_INT 3000 -#define NORMA_ANGLE 360 -//////////////////////////////////////////////////// -//////////////////////////////////////////////////// -//#define NORMA_FROTOR 20.0 -//#define NORMA_ACP 3000.0 - -#define NORMA_FROTOR ((float)NORMA_FROTOR_INT) -#define NORMA_ACP ((float)NORMA_ACP_INT) - - -#define NORMA_MZZ_INT NORMA_ACP_INT -#define NORMA_MZZ ((float)NORMA_MZZ_INT) - -#define NORMA_I_U_INT NORMA_MZZ_INT - -//////////////////////////////////////////////////// -//////////////////////////////////////////////////// -//////////////////////////////////////////////////// - +#define NORMA_FROTOR 20.0 +#define NORMA_MZZ NORMA_ACP //#define F_STATOR_MAX NORMA_FROTOR // макс. скорость ограничена электроникой -#define NORMA_ACP_P 100.0 -#define NORMA_ACP_RMS 2127.66 - -#define NORMA_ACP_TEMPER_MILL_AMP 100.0 // - -#ifndef PROJECT_SHIP -#error Не установлен PROJECT_SHIP в predifine Name -#else - - -#if (PROJECT_SHIP == 1) -#define NORMA_ACP_TEMPER 100.0 // для 23550.1 -#endif - - -#if (PROJECT_SHIP == 2) -#define NORMA_ACP_TEMPER 200.0 // для 23550.3 -#endif - -#if (PROJECT_SHIP== 3) -#define NORMA_ACP_TEMPER 200.0 // для 23550.3 - -#endif - - -#endif - - - - -#endif /* _PARAMS_NORMA_H_ */ +#endif /* SRC_MAIN_PARAMS_NORMA_H_ */ diff --git a/Inu/Src/main/params_protect_adc.h b/Inu/Src/main/params_protect_adc.h index b5772bd..a059cf0 100644 --- a/Inu/Src/main/params_protect_adc.h +++ b/Inu/Src/main/params_protect_adc.h @@ -8,18 +8,16 @@ #ifndef SRC_MAIN_PARAMS_PROTECT_ADC_H_ #define SRC_MAIN_PARAMS_PROTECT_ADC_H_ #include -#include - -#define LEVEL_ADC_I_AF LEVEL_HWP_I_AF // A 0-450A -#define LEVEL_ADC_I_ZPT LEVEL_HWP_I_ZPT // A 0-2000?? -//#define LEVEL_ADC_U_ABC 1000 // V 0-2000V -#define LEVEL_ADC_I_BREAK LEVEL_HWP_I_BREAK // A 0-2000A -#define LEVEL_ADC_U_ZPT_MAX LEVEL_HWP_U_ZPT -#define LEVEL_ADC_U_ZPT_MIN 1800 -#define LEVEL_ADC_U_IN_MAX LEVEL_HWP_U_ABC -#define LEVEL_ADC_U_IN_MIN 1380 -#define LEVEL_ADC_I_OUT_MAX I_OUT_NOMINAL //(I_OUT_NOMINAL * 1.9) +#define LEVEL_ADC_I_AF 700 // A 0-450A +#define LEVEL_ADC_I_ZPT 500 // A 0-2000?? +#define LEVEL_ADC_U_ABC 1000 // V 0-2000V +#define LEVEL_ADC_I_BREAK 280 // A 0-2000A +#define LEVEL_ADC_U_ZPT_MAX 2900 +#define LEVEL_ADC_U_ZPT_MIN 1800 +#define LEVEL_ADC_U_IN_MAX 2250 +#define LEVEL_ADC_U_IN_MIN 1380 +#define LEVEL_ADC_I_OUT_MAX I_OUT_NOMINAL//(I_OUT_NOMINAL * 1.9) #endif /* SRC_MAIN_PARAMS_PROTECT_ADC_H_ */ diff --git a/Inu/Src/main/params_pwm24.h b/Inu/Src/main/params_pwm24.h index a2571a6..28319cf 100644 --- a/Inu/Src/main/params_pwm24.h +++ b/Inu/Src/main/params_pwm24.h @@ -9,13 +9,10 @@ #define SRC_MAIN_PARAMS_PWM24_H_ /////////////////////////////////////////////////////// -#if (_SIMULATE_AC==1) -#define FREQ_PWM 100 //450 //800 /* частота ШИМа */ //3138 // 2360//2477 // -#else -#define FREQ_PWM 450 //800 /* частота ШИМа */ //3138 // 2360//2477 // -#endif -#define DEF_PERIOD_MIN_MKS 60 // 80 //60 // берем минимальное время работы ключа = 2*TK_MIN_TIME_MKS = 30 с запасом +#define FREQ_PWM 450 //800 /* частота ШИМа */ //3138 // 2360//2477 // + +#define DEF_PERIOD_MIN_MKS 80 //60 // берем минимальное время работы ключа = 2*TK_MIN_TIME_MKS = 30 с запасом // + TK_DEAD_TIME_MKS + 5mks запас = 60 #define DEF_PERIOD_MIN_BR_XTICS 165 diff --git a/Inu/Src/main/params_temper_p.h b/Inu/Src/main/params_temper_p.h index 2864649..860dcb6 100644 --- a/Inu/Src/main/params_temper_p.h +++ b/Inu/Src/main/params_temper_p.h @@ -3,13 +3,6 @@ #define INDEX_T_WATER_INT 1 -#define ALARM_TEMPER_BREAK_INT 1100 -#define ABNORMAL_TEMPER_BREAK_INT 900 -#define DELTA_TEMPER_BREAK_INT 20 - - - - // koef to svu #define K_TEMPER_TO_SVU 10.0 #define K_P_WATER_TO_SVU 100.0 @@ -43,15 +36,15 @@ // air -#define ALARM_TEMPER_AIR_INT 450 -#define ABNORMAL_TEMPER_AIR_INT 400 +#define ALARM_TEMPER_AIR_INT 400 +#define ABNORMAL_TEMPER_AIR_INT 300 //ac drive -#define ALARM_TEMPER_ACDRIVE_WINDING 1300 -#define ABNORMAL_TEMPER_ACDRIVE_WINDING 1200 +#define ALARM_TEMPER_ACDRIVE_WINDING 1600 +#define ABNORMAL_TEMPER_ACDRIVE_WINDING 1500 -#define ALARM_TEMPER_ACDRIVE_BEAR 900 -#define ABNORMAL_TEMPER_ACDRIVE_BEAR 800 +#define ALARM_TEMPER_ACDRIVE_BEAR 1100 +#define ABNORMAL_TEMPER_ACDRIVE_BEAR 1000 #define ALARM_TEMPER_BSU 600 #define ABNORMAL_TEMPER_BSU 500 diff --git a/Inu/Src/main/project.c b/Inu/Src/main/project.c index a8fcec9..246cb86 100644 --- a/Inu/Src/main/project.c +++ b/Inu/Src/main/project.c @@ -28,171 +28,14 @@ - - - - -void tkak_init_plate(int k, int tkak0_off_protect, int tk_disable_output_a, int tk_disable_output_b) -{ - unsigned int t_ticks; - //tkak 0 - project.cds_tk[k].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup - - - if (k==3) - { -// project.cds_tk[k].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off - // тут у нас только тормозные - if (tkak0_off_protect==1) - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0x0000; // only break ack+cur - else - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0x0303; // only break ack+cur - -// project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x0003; // optical bus+break - project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00cf; // optical bus+break - -#if (TKAK_VERSION==TKAK_EDRK) - project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02); - project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK); - project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK); -#endif - -#if (TKAK_VERSION==TKAK_23550) - project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_NS/1000.0 / 0.02); - project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_NS/1000.0 / DIV_TIME_TK); - project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_NS/1000.0 / DIV_TIME_TK); -#endif - } - else - { - project.cds_tk[k].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off - - if (tk_disable_output_a==1 && tk_disable_output_b==1) - { - project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x0000; //mask key 1-use key,0-not use key - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0xff00; // cur+ack 1-on protect. - } - else - if (tk_disable_output_a==0 && tk_disable_output_b==1) - { - project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x000f; //mask key 1-use key,0-not use key - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0x0f0f; // cur+ack 1-on protect. - } - else - if (tk_disable_output_a==1 && tk_disable_output_b==0) - { - project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00f0; //mask key 1-use key,0-not use key - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0xf0f0; // cur+ack 1-on protect. - } - else - if (tk_disable_output_a==0 && tk_disable_output_b==0) - { - project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00ff; //mask key 1-use key,0-not use key - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0xffff; // cur+ack 1-on protect. - } - - if (tkak0_off_protect==1) - project.cds_tk[k].write.sbus.mask_protect_tk.all = 0x0000; // cur+ack 1-on protect. - - -#if (TKAK_VERSION==TKAK_EDRK) - project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02); - project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK); - project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK); -#endif - - -#if (TKAK_VERSION==TKAK_23550) - - -// TK_ACKN_TIME_NS - - t_ticks = (unsigned int)(TK_ACKN_TIME_NS / DIV_TIME_TK_ACKN); - -#if (TK_ACKN_TIME_NS>(DIV_TIME_TK_ACKN*255)) -#error "TK_ACKN_TIME_NS выше предела!" -#endif - project.cds_tk[k].write.sbus.ack_time.bit.time = (unsigned int)t_ticks; - - -// TK_MIN_TIME_NS - - t_ticks = (unsigned int)(TK_MIN_TIME_NS / DIV_TIME_TK_MIN); - -#if (TK_MIN_TIME_NS>(DIV_TIME_TK_MIN*255)) -#error "TK_MIN_TIME_NS выше предела!" -#endif - - project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (unsigned int)t_ticks; - - -//TK_DEAD_TIME_NS - - // минимальное значение для dead_time = 5 мкс, меньше - загрузится все равно 5 мкс - t_ticks = (unsigned int)(TK_DEAD_TIME_NS / DIV_TIME_TK_DEAD); - -#if (TK_DEAD_TIME_NS>(DIV_TIME_TK_DEAD*255)) -#error "TK_DEAD_TIME_MKS выше предела!" -#endif - project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (unsigned int)(t_ticks); - - -// TK_SOFT_OFF_TIME_NS - - t_ticks = (unsigned int)(TK_SOFT_OFF_TIME_NS / DIV_TIME_TK_SOFT_OFF); - -#if (TK_SOFT_OFF_TIME_NS>(DIV_TIME_TK_SOFT_OFF*65535)) -#error "TK_SOFT_OFF_TIME_MKS выше предела!" -#endif - project.cds_tk[k].write.sbus.time_after_err = (unsigned int)t_ticks; - -#endif - - - - - project.cds_tk[k].write.sbus.protect_error.bit.enable_soft_disconnect = 1; - project.cds_tk[k].write.sbus.protect_error.bit.detect_soft_disconnect = 0;//1; - - } - - if (tkak0_off_protect==1) - { - project.cds_tk[k].write.sbus.protect_error.bit.enable_err_power = 0; - project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch = 0; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err_hwp = 0; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err0_in = 0; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err_mintime = 0; - project.cds_tk[k].write.sbus.protect_error.bit.enable_line_err = 0; - project.cds_tk[k].write.sbus.protect_error.bit.enable_soft_disconnect = 0; - project.cds_tk[k].write.sbus.protect_error.bit.detect_soft_disconnect = 0; - } - else - { - - project.cds_tk[k].write.sbus.protect_error.bit.enable_err_power = 1; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err_hwp = 1; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err0_in = 1; - project.cds_tk[k].write.sbus.protect_error.bit.disable_err_mintime = 1; - project.cds_tk[k].write.sbus.protect_error.bit.enable_line_err = 1;//1;//0;//1; - - // на старых переходных платах этого сигнала нет! нужна перемыка! - if (project.cds_tk[k].type_cds_xilinx == TYPE_CDS_XILINX_SP6) - project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch = 0; - else - project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch = 1; - } - - -} - +#define convert_real_to_mv_hwp(nc,value) ((float)value*(float)R_ADC[0][nc]/(float)K_LEM_ADC[0][nc]*10.0) //////////////////////////////////////////////////////////////// // грузим настройки в перифер. платы и HWP //////////////////////////////////////////////////////////////// void project_prepare_config(void) { - int k = 0; + // write here setup for all plates // // @@ -221,15 +64,15 @@ void project_prepare_config(void) //Direction project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg2 = 1; // use -//#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) +#if (ENABLE_ROTOR_SENSOR_1==1) // sensor1 //SpeedS1_cnt project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg3 = 1; // use //SpeedS1_cnt90 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg4 = 1; // use -//#endif +#endif -//#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) +//#if (ENABLE_ROTOR_SENSOR_2==1) // sensor2 //SpeedS2_cnt project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg5 = 1; // use @@ -238,39 +81,38 @@ void project_prepare_config(void) //#endif //#if (TYPE_CDS_XILINX_IN_0==TYPE_CDS_XILINX_SP2) -// if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP2) + if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP2) //is Channel Alive -// project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg13 = 1; // use + project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg13 = 1; // use //#endif if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) { - #if (ENABLE_ROTOR_SENSOR_1_PBUS==1) + //#if (ENABLE_ROTOR_SENSOR_1==1) //Time since zero point S1 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg7 = 1; // use // Impulses since zero point Rising S1 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg8 = 1; // use //Impulses since zero point Falling S1 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg9 = 1; // use - #endif + //#endif - #if (ENABLE_ROTOR_SENSOR_2_PBUS==1) + //#if (ENABLE_ROTOR_SENSOR_2==1) //Time since zero point S2 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg10 = 1; // use // Impulses since zero point Rising S2 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg11 = 1; // use //Impulses since zero point Falling S2 project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg12 = 1; // use - #endif + //#endif //is Channel Alive project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg13 = 1; // use - + project.cds_in[0].status_serial_bus.max_read_error = MAX_READ_SBUS; } - project.cds_in[0].status_serial_bus.max_read_error = MAX_READ_SBUS; #endif @@ -344,21 +186,8 @@ void project_prepare_config(void) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// -#if (USE_TK_0) - tkak_init_plate(0, TKAK0_OFF_PROTECT, TK_DISABLE_OUTPUT_A1, TK_DISABLE_OUTPUT_B1); -#endif -#if (USE_TK_1) - tkak_init_plate(1, TKAK1_OFF_PROTECT, TK_DISABLE_OUTPUT_C1, TK_DISABLE_OUTPUT_A2); -#endif -#if (USE_TK_2) - tkak_init_plate(2, TKAK2_OFF_PROTECT, TK_DISABLE_OUTPUT_B2, TK_DISABLE_OUTPUT_C2); -#endif -#if (USE_TK_3) - tkak_init_plate(3, TKAK3_OFF_PROTECT, 0, 0); -#endif -/* #if (USE_TK_0) //tkak 0 project.cds_tk[0].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup @@ -401,7 +230,7 @@ void project_prepare_config(void) project.cds_tk[0].write.sbus.protect_error.bit.disable_err_hwp = 0; project.cds_tk[0].write.sbus.protect_error.bit.disable_err0_in = 0; project.cds_tk[0].write.sbus.protect_error.bit.disable_err_mintime = 0; - project.cds_tk[0].write.sbus.protect_error.bit.enable_line_err = 0; + project.cds_tk[0].write.sbus.protect_error.bit.enable_line_err = 1; #else @@ -466,7 +295,7 @@ void project_prepare_config(void) project.cds_tk[1].write.sbus.protect_error.bit.disable_err_hwp = 0; project.cds_tk[1].write.sbus.protect_error.bit.disable_err0_in = 0; project.cds_tk[1].write.sbus.protect_error.bit.disable_err_mintime = 0; - project.cds_tk[1].write.sbus.protect_error.bit.enable_line_err = 0; + project.cds_tk[1].write.sbus.protect_error.bit.enable_line_err = 1; #else project.cds_tk[1].write.sbus.protect_error.bit.enable_err_power = 1; @@ -528,7 +357,7 @@ void project_prepare_config(void) project.cds_tk[2].write.sbus.protect_error.bit.disable_err_hwp = 0; project.cds_tk[2].write.sbus.protect_error.bit.disable_err0_in = 0; project.cds_tk[2].write.sbus.protect_error.bit.disable_err_mintime = 0; - project.cds_tk[2].write.sbus.protect_error.bit.enable_line_err = 0; + project.cds_tk[2].write.sbus.protect_error.bit.enable_line_err = 1; #else @@ -576,7 +405,7 @@ void project_prepare_config(void) project.cds_tk[3].write.sbus.protect_error.bit.disable_err_hwp = 0; project.cds_tk[3].write.sbus.protect_error.bit.disable_err0_in = 0; project.cds_tk[3].write.sbus.protect_error.bit.disable_err_mintime = 0; - project.cds_tk[3].write.sbus.protect_error.bit.enable_line_err = 0; + project.cds_tk[3].write.sbus.protect_error.bit.enable_line_err = 1; #else @@ -596,7 +425,7 @@ void project_prepare_config(void) #endif #endif -*/ + ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// @@ -651,14 +480,7 @@ void project_prepare_config(void) // out1 project.cds_out[1].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup -#if (OUT1_OFF_PROTECT==1) - project.cds_out[1].write.sbus.protect_error.bit.disable_err0_in = 0; - project.cds_out[1].write.sbus.protect_error.bit.disable_err_hwp = 0; - project.cds_out[1].write.sbus.protect_error.bit.enable_err_power = 0; - project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 0; - -#else project.cds_out[1].write.sbus.protect_error.bit.enable_err_power = 1; project.cds_out[1].write.sbus.protect_error.bit.disable_err0_in = 1; project.cds_out[1].write.sbus.protect_error.bit.disable_err_hwp = 1; @@ -671,7 +493,6 @@ void project_prepare_config(void) project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 0; else project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 1; -#endif project.cds_out[1].write.sbus.enable_protect_out.all = 0x0000; @@ -733,20 +554,20 @@ void project_prepare_config(void) // первый датчик In1-прямой, In2-прямой90град. // на неиспользуемые пишем 0xf - project.cds_in[0].write.sbus.first_sensor.bit.direct_ch = 0x0; // in2 - project.cds_in[0].write.sbus.first_sensor.bit.direct_ch_90deg = 0x1; // in1 + project.cds_in[0].write.sbus.first_sensor.bit.direct_ch = 0x1; // in2 + project.cds_in[0].write.sbus.first_sensor.bit.direct_ch_90deg = 0x2; // in1 // эти отключены project.cds_in[0].write.sbus.first_sensor.bit.inv_ch = 0x0f; // in0 project.cds_in[0].write.sbus.first_sensor.bit.inv_ch_90deg = 0x0f; // in0 // как бы первый, но с перекрестом In2-прямой, In1-прямой90град. - project.cds_in[0].write.sbus.second_sensor.bit.direct_ch = 0x01; // in0 - project.cds_in[0].write.sbus.second_sensor.bit.direct_ch_90deg = 0x00; // in1 + project.cds_in[0].write.sbus.second_sensor.bit.direct_ch = 0x02; // in0 + project.cds_in[0].write.sbus.second_sensor.bit.direct_ch_90deg = 0x01; // in1 // эти отключены project.cds_in[0].write.sbus.second_sensor.bit.inv_ch = 0x0f; // in0 project.cds_in[0].write.sbus.second_sensor.bit.inv_ch_90deg = 0x0f; // in0 // метка нулЯ - project.cds_in[0].write.sbus.zero_sensors.bit.for_sensor1 = 0x02; // + project.cds_in[0].write.sbus.zero_sensors.bit.for_sensor1 = 0x0; // project.cds_in[0].write.sbus.zero_sensors.bit.for_sensor2 = 0x0f; // // включаем только одну метуку нулЯ project.cds_in[0].write.sbus.zero_sensors.bit.enable_sensor1 = 1; @@ -960,13 +781,13 @@ void project_prepare_config(void) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// //Incremental sensor_init -#if (ENABLE_ROTOR_SENSOR_1_PM67==1) +#if (ENABLE_ROTOR_SENSOR_1==1) inc_sensor.use_sensor1 = 1; #else inc_sensor.use_sensor1 = 0; #endif -#if (ENABLE_ROTOR_SENSOR_2_PM67==1) +#if (ENABLE_ROTOR_SENSOR_2==1) inc_sensor.use_sensor2 = 1; #else inc_sensor.use_sensor2 = 0; @@ -982,13 +803,7 @@ void project_prepare_config(void) inc_sensor.pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS; -// 23550 -// inc_sensor.pm67regs.write_comand_reg.bit.filter_sensitivity = 5; //0x0; //до 170 об.мин -// 22220 - inc_sensor.pm67regs.write_comand_reg.bit.filter_sensitivity = 300;//5; //0x0; //до 170 об.мин - - - + inc_sensor.pm67regs.write_comand_reg.bit.filter_sensitivity = 5; //0x0; //до 170 об.мин inc_sensor.set(&inc_sensor); //Rotation sensor_init diff --git a/Inu/Src/main/project_setup.h b/Inu/Src/main/project_setup.h index 4f3ec93..1f33685 100644 --- a/Inu/Src/main/project_setup.h +++ b/Inu/Src/main/project_setup.h @@ -43,7 +43,7 @@ // Настройка скоростей RS232 #define RS232_SPEED_A 57600//115200//57600 -#define RS232_SPEED_B 57600//115200//57600// +#define RS232_SPEED_B 57600//115200//57600//115200//57600// /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// @@ -123,20 +123,20 @@ #if (_FLOOR6_ADD==1) -#define USE_ADC_0 1 -#define USE_ADC_1 1 +//#define USE_ADC_0 1 +//#define USE_ADC_1 1 ////// -#define USE_IN_0 1 +//#define USE_IN_0 1 //// //#define USE_IN_1 1 //////// //#define USE_OUT_0 1 //////// //////// -#define USE_TK_0 1 -#define USE_TK_1 1 +//#define USE_TK_0 1 +//#define USE_TK_1 1 ////// -#define USE_TK_2 1 +//#define USE_TK_2 1 #define USE_TK_3 1 //#define USE_HWP_0 1 @@ -161,7 +161,6 @@ #define USE_TK_3 1 #define USE_HWP_0 1 -#define USE_HWP_1 1 #endif diff --git a/Inu/Src/main/protect_levels.h b/Inu/Src/main/protect_levels.h index b9bf78f..42ce895 100644 --- a/Inu/Src/main/protect_levels.h +++ b/Inu/Src/main/protect_levels.h @@ -111,7 +111,7 @@ typedef struct { LEVEL_ADC_U_IN_MAX,LEVEL_ADC_U_IN_MAX, LEVEL_ADC_U_IN_MIN,LEVEL_ADC_U_IN_MIN,\ LEVEL_ADC_U_ZPT_MAX,LEVEL_ADC_U_ZPT_MAX,LEVEL_ADC_U_ZPT_MIN,LEVEL_ADC_U_ZPT_MIN,\ LEVEL_ADC_I_ZPT,\ - LEVEL_ADC_I_BREAK, LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,\ + LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,LEVEL_ADC_I_AF,\ LEVEL_ADC_I_OUT_MAX} extern PROTECT_LEVELS protect_levels; diff --git a/Inu/Src/main/pump_control.c b/Inu/Src/main/pump_control.c index 212473c..c648d9a 100644 --- a/Inu/Src/main/pump_control.c +++ b/Inu/Src/main/pump_control.c @@ -9,8 +9,6 @@ #include #include "control_station.h" -#include "digital_filters.h" -#include "sbor_shema.h" #pragma DATA_SECTION(pumps, ".slow_vars") PUMP_CONTROL pumps = PUMP_CONTROL_DEFAULTS; @@ -77,15 +75,6 @@ void pump_control(void) pump_off_without_time_wait = 1; } - if (control_station.active_array_cmd[CONTROL_STATION_CMD_MODE_PUMP] == 6) - { -// edrk.SelectPump1_2 = 1; - pumps.SelectedPump1_2 = 0; - edrk.ManualStartPump = 1; - edrk.AutoStartPump = 0; - pump_off_without_time_wait = 1; - } - edrk.SumStartPump = edrk.AutoStartPump || edrk.ManualStartPump; turn_on_nasos_1_2(pump_off_without_time_wait); @@ -132,8 +121,7 @@ int fast_stop_pump=0; if ( edrk.SumStartPump==1 && edrk.errors.e5.bits.PRE_READY_PUMP == 0 && fast_stop_pump==0) { - if (pumps.SelectedPump1_2 == 0 /*&& edrk.ManualStartPump == 0*/) - { + if (pumps.SelectedPump1_2 == 0 && edrk.ManualStartPump == 0) { //Выбор насоса исходя из отработаного времени switch (select_pump()) { case 1: @@ -230,15 +218,13 @@ int select_pump() { int p_n = 0; if (pumps.lock_pump == 0) { - p_n = calc_auto_moto_pump(); - if (p_n == 0) - p_n = 1; + // if (pumps.pump1_engine_minutes > pumps.pump2_engine_minutes) { // p_n = 2; // } else { // p_n = 1; // } - + p_n = 1; } else { p_n = edrk.SelectPump1_2; } diff --git a/Inu/Src/main/pwm_test_lines.c b/Inu/Src/main/pwm_test_lines.c index ef24f64..f8e3b73 100644 --- a/Inu/Src/main/pwm_test_lines.c +++ b/Inu/Src/main/pwm_test_lines.c @@ -16,10 +16,10 @@ void pwm_test_lines_start(void) { cmd_pwm_test_lines = 0xffff; -// i_WriteMemory(ADR_TK_MASK_1, 0); + i_WriteMemory(ADR_TK_MASK_1, 0); + i_WriteMemory(ADR_PWM_DIRECT2,0xffff); + i_WriteMemory(ADR_PWM_DRIVE_MODE, 3); // on direct tk lines i_WriteMemory(ADR_PWM_DIRECT2,0xffff); -// i_WriteMemory(ADR_PWM_DRIVE_MODE, 3); // on direct tk lines -// i_WriteMemory(ADR_PWM_DIRECT2,0xffff); i_WriteMemory(ADR_TK_MASK_1, 0x0); //Turn on additional 16 tk lines } @@ -27,10 +27,8 @@ void pwm_test_lines_start(void) void pwm_test_lines_stop(void) { cmd_pwm_test_lines = 0xffff; - i_WriteMemory(ADR_TK_MASK_1, 0xffff); //Turn off additional 16 tk lines i_WriteMemory(ADR_PWM_DIRECT2,0xffff); - -// i_WriteMemory(ADR_PWM_DRIVE_MODE, 0); // off direct tk lines + i_WriteMemory(ADR_PWM_DRIVE_MODE, 0); // off direct tk lines } diff --git a/Inu/Src/main/sbor_shema.c b/Inu/Src/main/sbor_shema.c index 7157fd1..3a9fbc3 100644 --- a/Inu/Src/main/sbor_shema.c +++ b/Inu/Src/main/sbor_shema.c @@ -11,25 +11,17 @@ #include "adc_tools.h" #include "control_station.h" #include "control_station_project.h" -#include "digital_filters.h" -#include "detect_errors.h" - #define RASCEPITEL_MANUAL_ALWAYS_ON 0//1 /////////////////////////////////////////////// /////////////////////////////////////////////// -//#define IQ_MINIMAL_DELTA_RUN_CHARGE_1 559240 //100V -//#define IQ_MINIMAL_DELTA_RUN_CHARGE_2 1118480 //200V +#define IQ_MINIMAL_DELTA_RUN_CHARGE 279620 // 50V //559240 //100 V -//#define IQ_MINIMAL_DELTA_RUN_CHARGE 279620 // 50V -#define IQ_MINIMAL_DELTA_RUN_CHARGE_1 1118480// 200 V ///279620 // 50V -#define IQ_MINIMAL_DELTA_RUN_CHARGE_2 1118480// 200 V //279620 // 50V - -#define IQ_MINIMAL_DELTA_RUN_WORK 2796202 // 500V // 2236960 // 400V // 1677720 // 300 V // 559240 // 100V +#define IQ_MINIMAL_DELTA_RUN_WORK 1677720 // 300 V // 559240 // 100V #define IQ_MINIMAL_ZAD_U_CHARGE 55924 // 10V #define IQ_MAXIMAL_ZAD_U_CHARGE 14596177 // 2610V #define IQ_MINIMAL_DELTA_RUN_CHARGE2 139810 //25 V -#define TIME_WAIT_CHARGE_ON 300 //30 sec +#define TIME_WAIT_CHARGE_ON 100 //10 sec #define TIME_PAUSE_U_RISE 30 // 1 sec #define IQ_MINIMAL_RISE_U 55924 // 10V @@ -71,7 +63,7 @@ unsigned int zaryad_on_off(unsigned int flag) } // есть разбежка по банкам - if (_IQabs(filter.iqU_1_long-filter.iqU_2_long)>IQ_MINIMAL_DELTA_RUN_WORK) //IQ_MINIMAL_DELTA_RUN_CHARGE_1 + if (_IQabs(filter.iqU_1_long-filter.iqU_2_long)>IQ_MINIMAL_DELTA_RUN_CHARGE) { edrk.errors.e6.bits.ER_DISBAL_BATT |= 1; edrk.to_ing.bits.ZARYAD_ON = 0; @@ -83,8 +75,8 @@ unsigned int zaryad_on_off(unsigned int flag) // зарЯд норма и было включено, выключаем if ( edrk.from_ing1.bits.ZARYAD_ON && - (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_1) - || filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_1)) + (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge) + || filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge)) ) { restart_charge = 1; @@ -94,8 +86,8 @@ unsigned int zaryad_on_off(unsigned int flag) { //TODO !!! по сути повторяет предыдущий if. Удалить? if ( edrk.from_ing1.bits.ZARYAD_ON==0 && - (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2) - || filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) ) + (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE) + || filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) ) { restart_charge = 1; edrk.to_ing.bits.ZARYAD_ON = 0; @@ -103,8 +95,8 @@ unsigned int zaryad_on_off(unsigned int flag) else { // зарЯд меньше нужного, включаем. - if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) - && (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) ) + if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) + && (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) ) edrk.to_ing.bits.ZARYAD_ON = 1; } @@ -160,8 +152,8 @@ unsigned int zaryad_on_off(unsigned int flag) else//restart_charge==0 { // почему-то зарЯд стал меньше!!! - if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) - || (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) ) + if ( (filter.iqU_1_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) + || (filter.iqU_2_long<(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) ) edrk.errors.e6.bits.ERROR_PRE_CHARGE_U |= 1; } //restart_charge==0 @@ -175,11 +167,11 @@ unsigned int zaryad_on_off(unsigned int flag) prev_U2 = filter.iqU_2_long; } - if ( (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) - && (filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE_2)) + if ( (filter.iqU_1_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) + && (filter.iqU_2_long>=(edrk.zadanie.iq_ZadanieU_Charge-IQ_MINIMAL_DELTA_RUN_CHARGE)) && (_IQabs(filter.iqU_1_long-filter.iqU_2_long)=edrk.iqMIN_U_IN) && (filter.iqUin_m2>=edrk.iqMIN_U_IN) @@ -284,7 +276,7 @@ int detect_zaryad_ump(void) /////////////////////////////////////////////// /////////////////////////////////////////////// -#define TIME_WAIT_SBOR 8500 +#define TIME_WAIT_SBOR 2500 #define TIME_WAIT_ANSWER_NASOS 500 #define TIME_WAIT_OK_NASOS 50 @@ -300,10 +292,6 @@ void sbor_shema_pusk_nasos(unsigned int t_start, unsigned int t_finish) // пуск насоса if (edrk.Sbor_Mode == t_start) { - edrk.enter_to_pump_stage = 1; - // сбросили предупреждения по насосам, возможно и не правильно это! - edrk.warnings.e5.bits.PUMP_1 = edrk.warnings.e5.bits.PUMP_2 = 0; - if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_PUMP]==0) edrk.AutoStartPump = 1; @@ -317,7 +305,7 @@ void sbor_shema_pusk_nasos(unsigned int t_start, unsigned int t_finish) // ждем пуска насоса if (edrk.Sbor_Mode>t_start && edrk.Sbor_Mode>1) )) + if (edrk.Sbor_Mode==(t_start + (t_finish-t_start)>>1)) { @@ -427,7 +415,7 @@ void sbor_shema_pusk_zaryad(unsigned int t_start, unsigned int t_finish) if (edrk.Sbor_Mode>t_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && edrk.Sbor_Modet_start && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok)) { - edrk.Stage_Sbor = STAGE_SBOR_STATUS_FINISH; - edrk.SborFinishOk = 1; + edrk.Stage_Sbor = 11; + edrk.SborFinishOk = 1; // allow_discharge = 1; } @@ -876,8 +851,6 @@ void sbor_shema_wait_finish(unsigned int t_start, unsigned int t_finish) #define TIME_WAIT_ANSWER_UMP_ON 150 //15 sec #define TIME_WAIT_ANSWER_UMP_OFF 40 //4 sec -#define TIME_PAUSE_AFTER_GET_READY_UMP 50 // 5 sec - /////////////////////////////////////////////// int ump_on_off(unsigned int flag) { @@ -889,7 +862,7 @@ static unsigned int time_wait_answer_off_ump=0; int cmd_ump=0;//,cmd_p2=0; static int UMP_Ok = 0; -static int prev_error = 0, count_ready_upm = 0; //, flag_enable_on_ump = 0; +static int prev_error = 0; cmd_ump = 0; @@ -908,7 +881,6 @@ static int prev_error = 0, count_ready_upm = 0; //, flag_enable_on_ump = 0; edrk.cmd_to_ump = cmd_ump; - if (cmd_ump) { @@ -918,72 +890,44 @@ static int prev_error = 0, count_ready_upm = 0; //, flag_enable_on_ump = 0; // } // else - // ждем готовность! - if (edrk.from_shema_filter.bits.READY_UMP == 1) - { - // даем задержку TIME_PAUSE_AFTER_GET_READY_UMP - if (count_ready_upm50 && edrk.Sbor_Mode<250) +// { +// if (edrk.StatusPumpFanAll ) +// { +// edrk.Sbor_Mode = 250; +// } +// +// // насос не пустился +// if (edrk.Sbor_Mode>200 && edrk.StatusPumpFanAll==0) +// { +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Status_Sbor = 2; +// edrk.AutoStartPump = 0; +// } +// +// +// } +// + +// ///////////////////////////////////// +// // запуск заряда внутреннего +// if (edrk.Sbor_Mode == 250) +// { +// if (control_station.active_array_cmd[CONTROL_STATION_CMD_ENABLE_ON_CHARGE]==1) +// edrk.Run_Pred_Zaryad = 1; // запуск предзарЯда! +// } + +//// +// if (edrk.Sbor_Mode>=250 && edrk.StatusPumpFanAll==0 && edrk.SumStartPump) +// { +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Status_Sbor = 3; +// +// } + +// // ждем завершения работы предзаряда +// // тут предзарЯд должен уже закончить работу +// +// if (edrk.Sbor_Mode>250 && edrk.Sbor_Mode<900 && (edrk.Status_Charge || (control_station.active_array_cmd[CONTROL_STATION_CMD_ENABLE_ON_CHARGE]==0)) +// && edrk.from_ing1.bits.ZARYAD_ON==0 && edrk.StatusPumpFanAll) +// { +// edrk.Zaryad_OK = 1; +// edrk.Run_Pred_Zaryad = 0; +// +// edrk.Sbor_Mode = 900; +// } +// +// +// if (edrk.Sbor_Mode>850 && edrk.Zaryad_OK == 0) +// { +// edrk.Run_Pred_Zaryad = 0; +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Status_Sbor = 4; +// } +// + +//// включаем UMP +// if (edrk.Sbor_Mode==950 && edrk.Zaryad_OK == 1) +// { +// edrk.Run_UMP = 1; +// } +// +// if (edrk.Sbor_Mode>950 && edrk.Sbor_Mode>1250 && (edrk.Zaryad_OK == 1 && edrk.Status_UMP_Ok==1)) +// { +// edrk.Sbor_Mode=1250; +// } +// +// +// if (edrk.Sbor_Mode>1300 && (edrk.Zaryad_OK == 0 || edrk.Status_UMP_Ok==0)) +// { +// edrk.Run_UMP = 0; +// edrk.Run_Pred_Zaryad = 0; +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.errors.e7.bits.UMP_NOT_ANSWER |= 1; +// edrk.Run_QTV = 0; +// edrk.Status_Sbor = 9; +// } + + + +//////////////// + + +// +// +// if (edrk.Sbor_Mode==950 && edrk.Zaryad_OK == 1) +// { +//// if () +// edrk.Run_QTV = 1; +// } +// +// +// if (edrk.Sbor_Mode>960 && edrk.Sbor_Mode<1110 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) ) +// { +// edrk.Sbor_Mode = 1110; +// } +// +// if (edrk.Sbor_Mode>1100 && (edrk.Zaryad_OK == 0 || edrk.Status_QTV_Ok==0 )) +// { +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Run_QTV = 0; +// edrk.Status_Sbor = 5; +// } + + +// if (edrk.Sbor_Mode==1110 && edrk.Sbor_Mode<1250 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) && edrk.Status_Rascepitel_Ok==0) +// { +// // если другой БС не собран, замыкаем расцепитель +// if (optical_read_data.data.cmd.bit.ready_cmd != CODE_READY_CMD_READY2 ) +// { +// edrk.Run_Rascepitel = 1; +// edrk.Sbor_Mode = 1250; // перепрыгнули дальше +// } +// else +// edrk.RunZahvatRascepitel = 1; // просим другой БС сбросить обороты и разрешить подключение расцепителя +// } +//// +// if (edrk.Sbor_Mode>1120 && edrk.Sbor_Mode<1250 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) +// && edrk.RunZahvatRascepitel && edrk.Status_Rascepitel_Ok==0 && edrk.Run_Rascepitel==0) +// { +// // если другой БС не собран, замыкаем расцепитель +// // другой БС сбросил обороты если они были и снял ШИМ если был +// if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - можно включать расцепитель, свой включен +// { +// edrk.Run_Rascepitel = 1; +// edrk.Sbor_Mode = 1250; // перепрыгнули дальше +// +// } +// } + +// if (edrk.Sbor_Mode>1250 && edrk.Sbor_Mode<1350 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) +// && edrk.Status_Rascepitel_Ok==1 && edrk.Run_Rascepitel==1) +// { +// // дождались включения расцепителя и прыгнули дальше +// edrk.Sbor_Mode = 1350; // перепрыгнули дальше +// } +// +//// +// // по сигналу edrk.RunZahvatRascepitel должен тот БС сбросить обороты и подтвердить возможность включение расцепителя +// if (edrk.Sbor_Mode>1320 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) +// && edrk.RunZahvatRascepitel && edrk.Status_Rascepitel_Ok==0 && edrk.Run_Rascepitel==0) +// { +// // +//// if (optical_read_data.data.cmd.bit.rascepitel_cmd != CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON ) // 01 - можно включать расцепитель, свой включен +// { +// // не дождались подтверждения на включение своего расцепителя +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Run_QTV = 0; +// edrk.Status_Sbor = 7; +// edrk.errors.e1.bits.NO_CONFIRM_ON_RASCEPITEL |= 1; +// edrk.RunZahvatRascepitel = 0; +//// edrk.Run_Rascepitel = 0; +// } +// } + +// // тут ждем включения расцепителя +// if (edrk.Sbor_Mode>1350 && edrk.Sbor_Mode<1490 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 ) && edrk.Status_Rascepitel_Ok==1) +// { +// // Расцепитель включился! +// // можно перепрыгивать в конец +// edrk.Sbor_Mode = 1490; // перепрыгнули дальше +// edrk.RunZahvatRascepitel = 0; +// +//// edrk.Run_Rascepitel = 1; +// } +// +// +// +// +// +// if (edrk.Sbor_Mode>=1490 && (edrk.Zaryad_OK == 0 || edrk.Status_QTV_Ok==0 || edrk.Status_Rascepitel_Ok==0)) +// { +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.Run_QTV = 0; +//// edrk.Run_Rascepitel = 0; +// edrk.RunZahvatRascepitel = 0; +// edrk.Status_Sbor = 6; +// } +// + +// if (edrk.Sbor_Mode>1550 && edrk.Sbor_Mode<2000 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok)) +// { +// if (optical_read_data.data.cmd.bit.ready_cmd==CODE_READY_CMD_READY1TO2) // тот БС собирается еще +// { +// // ожидаем досбора второго БС +// // но расцепитель уже включился. +// if (optical_read_data.data.cmd.bit.rascepitel_cmd == CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON) +// edrk.Sbor_Mode = 2150; // перепрыгнули дальше +// +// } +// else +// { +// edrk.Sbor_Mode = 2150; // перепрыгнули дальше +// +// } +// +// } + +// +// if (edrk.Sbor_Mode>2100 && edrk.Sbor_Mode<2150 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok)) +// { +// if (optical_read_data.data.cmd.bit.ready_cmd==CODE_READY_CMD_READY1TO2) // тот БС собирается еще, но что-то долго он! +// { +// edrk.errors.e7.bits.ERROR_SBOR_SHEMA |= 1; +// edrk.errors.e1.bits.ANOTHER_BS_VERY_LONG_WAIT |= 1; +// edrk.Run_QTV = 0; +// // edrk.Run_Rascepitel = 0; +// edrk.RunZahvatRascepitel = 0; +// edrk.Status_Sbor = 8; +// } +// else +// { +// edrk.Sbor_Mode = 2150; // перепрыгнули дальше +// +// } +// +// +// } +// + + + +// +// if (edrk.Sbor_Mode>2150 && (edrk.Zaryad_OK == 1 && edrk.Status_QTV_Ok==1 && edrk.Status_Rascepitel_Ok)) +// { +// edrk.SborFinishOk = 1; +// // allow_discharge = 1; +// } +// +// +// if (edrk.Sbor_Mode>2200 && (edrk.SborFinishOk) ) +// { +// time_wait_sbor = 0; +// } +// else +// edrk.Sbor_Mode++; edrk.Razbor_Mode = 0; edrk.RazborNotFinish = 0; @@ -1402,8 +1550,6 @@ unsigned int sbor_shema(int mode) ///////////////////////////////////////////////////////// else { - first_run = 1; - edrk.enter_to_pump_stage = 0; // разбор схемы if (edrk.Razbor_Mode==0) edrk.RazborNotFinish = 1; @@ -1582,7 +1728,7 @@ unsigned int sbor_shema(int mode) edrk.Status_Charge = zaryad_on_off(edrk.Run_Pred_Zaryad); - if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_UMP]==1 || edrk.Status_Ready.bits.ImitationReady2) + if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_UMP]==1) { edrk.Status_UMP_Ok = edrk.Run_UMP; edrk.Zaryad_UMP_Ok = 1; @@ -1594,7 +1740,7 @@ unsigned int sbor_shema(int mode) edrk.Zaryad_UMP_Ok = detect_zaryad_ump(); } - if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_QTV]==1 || edrk.Status_Ready.bits.ImitationReady2) + if (control_station.active_array_cmd[CONTROL_STATION_CMD_DISABLE_ON_QTV]==1) { edrk.Status_QTV_Ok = edrk.Run_QTV; edrk.to_shema.bits.QTV_ON_OFF = 0; @@ -1671,94 +1817,12 @@ unsigned int sbor_shema(int mode) if (edrk.Status_Ready.bits.ready5==1 && edrk.Status_Ready.bits.ready6==1 && edrk.Status_Ready.bits.MasterSlaveActive) - { - if (edrk.Status_Ready.bits.ImitationReady2) - edrk.Status_Ready.bits.preImitationReady2 = 1; edrk.Status_Ready.bits.ready_final = 1; - } else - { edrk.Status_Ready.bits.ready_final = 0; - edrk.Status_Ready.bits.preImitationReady2 = 0; - } - - if (edrk.Status_Ready.bits.ready_final && prev_ready_final==0) - edrk.count_sbor++; - - prev_ready_final = edrk.Status_Ready.bits.ready_final; return (edrk.Sbor_Mode); } - - -unsigned int imit_signals_rascepitel(unsigned int *counter, unsigned int max_pause, unsigned int s, unsigned int cmd_clear) -{ - if (cmd_clear==1) - { - (*counter) = 0; - return 0; - } - - if (s) - { - if ((*counter)>=max_pause) - return 1; - else - (*counter)++; - - return 0; - } - - if (s==0) - { - if ((*counter)==0) - return 0; - else - (*counter)--; - - return 1; - } - return 0; -} - - -#define TIME_WAIT_OFF_BLOCK_KEY 100 -void auto_block_key_on_off(void) -{ - static unsigned int count_err = TIME_WAIT_OFF_BLOCK_KEY; - - if (edrk.SumSbor && edrk.enter_to_pump_stage) - { - edrk.Status_Ready.bits.Batt = 1; - edrk.to_ing.bits.BLOCK_KEY_OFF = 0; - count_err = 0; - } - - if (filter.iqU_1_long >= U_LEVEL_ON_BLOCK_KEY || filter.iqU_2_long >= U_LEVEL_ON_BLOCK_KEY) - { - edrk.Status_Ready.bits.Batt = 1; - edrk.to_ing.bits.BLOCK_KEY_OFF = 0; - count_err = 0; - } - - if (filter.iqU_1_long <= U_LEVEL_OFF_BLOCK_KEY && filter.iqU_2_long <= U_LEVEL_OFF_BLOCK_KEY && edrk.SumSbor==0) - { - if (pause_detect_error(&count_err,TIME_WAIT_OFF_BLOCK_KEY,1)) - { - edrk.to_ing.bits.BLOCK_KEY_OFF = 1; - edrk.Status_Ready.bits.Batt = 0; - } - } - else - count_err = 0; - - -} - - -/////////////////////////////////////////////// - - diff --git a/Inu/Src/main/sbor_shema.h b/Inu/Src/main/sbor_shema.h index fdde9ff..a066742 100644 --- a/Inu/Src/main/sbor_shema.h +++ b/Inu/Src/main/sbor_shema.h @@ -9,16 +9,7 @@ #define SRC_MAIN_SBOR_SHEMA_H_ -#define U_LEVEL_ON_BLOCK_KEY 559240 // 100V -#define U_LEVEL_OFF_BLOCK_KEY 279620 // 50V - unsigned int sbor_shema(int mode); void rascepitel_on_off(unsigned int flag, int *status_perehod, int *status_on_off, int *final_status_on_off); -void auto_block_key_on_off(void); - -unsigned int imit_signals_rascepitel(unsigned int *counter, unsigned int max_pause, unsigned int s, unsigned int cmd_clear); -void set_status_pump_fan(void); - - #endif /* SRC_MAIN_SBOR_SHEMA_H_ */ diff --git a/Inu/Src/main/sync_tools.c b/Inu/Src/main/sync_tools.c index ee9ee9d..aba233e 100644 --- a/Inu/Src/main/sync_tools.c +++ b/Inu/Src/main/sync_tools.c @@ -11,22 +11,17 @@ #include "Spartan2E_Adr.h" #include "Spartan2E_Functions.h" #include "TuneUpPlane.h" -#include "pwm_test_lines.h" -#include "xp_write_xpwm_time.h" -#include "profile_interrupt.h" #include "edrk_main.h" -#define SIZE_SYNC_BUF 20 +#define SIZE_SYNC_BUF 10 -//#pragma DATA_SECTION(logbuf_sync1,".fa"); -unsigned int logbuf_sync1[SIZE_SYNC_BUF]; -unsigned int c_logbuf_sync1=0; - -//unsigned int capnum0; -//unsigned int capnum1; -//unsigned int capnum2; -//unsigned int capnum3; +#pragma DATA_SECTION(logbuf_sync1,".logs"); +long logbuf_sync1[SIZE_SYNC_BUF]; +unsigned int capnum0; +unsigned int capnum1; +unsigned int capnum2; +unsigned int capnum3; int delta_capnum = 0; int delta_error = 0; //int level_find_sync_zero = LEVEL_FIND_SYNC_ZERO; @@ -35,109 +30,16 @@ unsigned int temp; unsigned int count_error_sync = 0; unsigned int count_timeout_sync = 0; -//unsigned int enable_profile_led1_sync = 1; -//unsigned int enable_profile_led2_sync = 0; +unsigned int enable_profile_led1_sync = 1; +unsigned int enable_profile_led2_sync = 0; SYNC_TOOLS_DATA sync_data=SYNC_TOOLS_DATA_DEFAULT; -#pragma CODE_SECTION(calculate_sync_detected,".fast_run2"); -void calculate_sync_detected(void) -{ - - - -// if (capnum0 > 1000) { -// return; -// } -// sync_data.level_find_sync_zero = LEVEL_FIND_SYNC_ZERO; - - delta_capnum = sync_data.capnum0 - sync_data.capnum1; - - if (delta_capnum > 0) //падает - { - sync_data.pwm_freq_plus_minus_zero = -1;//1; - - if (count_error_sync < MAX_COUNT_ERROR_SYNC) { - count_error_sync++; - count_error_sync++; - count_error_sync++; - } else - sync_data.local_flag_sync_1_2 = 0; - } - else - if (delta_capnum < 0) //растёт - { - - if (sync_data.capnum0 > sync_data.level_find_sync_zero) - { - delta_error = sync_data.capnum0 - sync_data.level_find_sync_zero; - - if (delta_error > 50) { - if (count_error_sync < MAX_COUNT_ERROR_SYNC) { - count_error_sync++; - count_error_sync++; - count_error_sync++; - } else - sync_data.local_flag_sync_1_2 = 0; - } else { - if (count_error_sync > 0) { - count_error_sync--; - } - if (count_error_sync == 0) - sync_data.local_flag_sync_1_2 = 1; - } - sync_data.pwm_freq_plus_minus_zero = 1; - } - else - if (sync_data.capnum0 < sync_data.level_find_sync_zero) - { - - delta_error = sync_data.level_find_sync_zero - sync_data.capnum0; - - if (delta_error > 50) { - if (count_error_sync < MAX_COUNT_ERROR_SYNC) { - count_error_sync++; - count_error_sync++; - count_error_sync++; - } else - sync_data.local_flag_sync_1_2 = 0; - } else { - if (count_error_sync > 0) { - count_error_sync--; - } - if (count_error_sync == 0) - sync_data.local_flag_sync_1_2 = 1; - } - - sync_data.pwm_freq_plus_minus_zero = -1; - - } - else - { - sync_data.pwm_freq_plus_minus_zero = 0; - sync_data.local_flag_sync_1_2 = 1; - count_error_sync = 0; - } - } else - sync_data.pwm_freq_plus_minus_zero = 0; - - sync_data.delta_error_sync = delta_error; - sync_data.delta_capnum = sync_data.capnum0 - sync_data.level_find_sync_zero; //delta_capnum; - sync_data.count_error_sync = count_error_sync; - - -} - - #pragma CODE_SECTION(sync_detected,".fast_run2"); void sync_detected(void) { -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_18_ON; -#endif - sync_data.latch_interrupt = 1; // stop_sync_interrupt(); @@ -148,31 +50,47 @@ void sync_detected(void) // EvbRegs.EVBIMRC.bit.CAP6INT = 0; // if (edrk.disable_interrupt_sync==0) - - -// WriteMemory(ADR_SAW_REQUEST, 0x8000); -// sync_data.capnum0 = ReadMemory(ADR_SAW_VALUE); - -// WriteMemory(ADR_SAW_REQUEST, 0x8000); -// sync_data.capnum0 = ReadMemory(ADR_SAW_VALUE); - - // pause_1000(1); + { + WriteMemory(ADR_SAW_REQUEST, 0x8000); + capnum0 = ReadMemory(ADR_SAW_VALUE); WriteMemory(ADR_SAW_REQUEST, 0x8000); - sync_data.capnum1 = ReadMemory(ADR_SAW_VALUE); + capnum0 = ReadMemory(ADR_SAW_VALUE); + + pause_1000(1); WriteMemory(ADR_SAW_REQUEST, 0x8000); - sync_data.capnum1 = ReadMemory(ADR_SAW_VALUE); + capnum1 = ReadMemory(ADR_SAW_VALUE); + + WriteMemory(ADR_SAW_REQUEST, 0x8000); + capnum1 = ReadMemory(ADR_SAW_VALUE); sync_data.count_timeout_sync = 0; sync_data.timeout_sync_signal = 0; + //i_led2_on_off(1); + // EALLOW; + // + // //use mask to clear EVAIFRA register + // EvbRegs.EVBIFRC.bit.CAP6INT = 1; - logbuf_sync1[c_logbuf_sync1++] = sync_data.capnum0; -// logbuf_sync1[c_logbuf_sync1++] = sync_data.capnum1; + // Acknowledge this interrupt to receive more interrupts from group 5 + // PieCtrlRegs.PIEACK.bit.ACK5 = 1; //???????CAP6 - if (c_logbuf_sync1==SIZE_SYNC_BUF) - c_logbuf_sync1=0; + // capnum3 = EvbRegs.CAP6FIFO; + asm(" NOP;"); + // asm(" NOP;"); + // asm(" NOP;"); + // asm(" NOP;"); + // + // if (EvbRegs.CAPFIFOB.bit.CAP6FIFO == 3) { + // capnum3 = EvbRegs.CAP6FIFO; + // capnum3 = EvbRegs.CAP6FIFO; + // capnum3 = EvbRegs.CAP6FIFO; + // } + // EDIS; + // EnableInterrupts(); + // return; if (sync_data.count_pause_ready < MAX_COUNT_PAUSE_READY) { sync_data.count_pause_ready++; @@ -180,13 +98,77 @@ void sync_detected(void) } else sync_data.sync_ready = 1; -//////////////////////////////////// + // if (capnum0 > 1000) { + // return; + // } + // sync_data.level_find_sync_zero = LEVEL_FIND_SYNC_ZERO; + delta_capnum = capnum0 - capnum1; - // calculate_sync_detected(); + if (delta_capnum > 0) //падает + { + sync_data.pwm_freq_plus_minus_zero = 1; + if (count_error_sync < MAX_COUNT_ERROR_SYNC) { + count_error_sync++; + count_error_sync++; + count_error_sync++; + } else + sync_data.local_flag_sync_1_2 = 0; + } else if (delta_capnum < 0) //растёт + { + if (capnum0 > sync_data.level_find_sync_zero) { + delta_error = capnum0 - sync_data.level_find_sync_zero; + if (delta_error > 50) { + if (count_error_sync < MAX_COUNT_ERROR_SYNC) { + count_error_sync++; + count_error_sync++; + count_error_sync++; + } else + sync_data.local_flag_sync_1_2 = 0; + } else { + if (count_error_sync > 0) { + count_error_sync--; + } + if (count_error_sync == 0) + sync_data.local_flag_sync_1_2 = 1; + } -// sync_data.capnum0 = capnum0; + sync_data.pwm_freq_plus_minus_zero = 1; + + } else if (capnum0 < sync_data.level_find_sync_zero) { + + delta_error = sync_data.level_find_sync_zero - capnum0; + + if (delta_error > 50) { + if (count_error_sync < MAX_COUNT_ERROR_SYNC) { + count_error_sync++; + count_error_sync++; + count_error_sync++; + } else + sync_data.local_flag_sync_1_2 = 0; + } else { + if (count_error_sync > 0) { + count_error_sync--; + } + if (count_error_sync == 0) + sync_data.local_flag_sync_1_2 = 1; + } + + sync_data.pwm_freq_plus_minus_zero = -1; + + } else { + sync_data.pwm_freq_plus_minus_zero = 0; + sync_data.local_flag_sync_1_2 = 1; + count_error_sync = 0; + } + } else + sync_data.pwm_freq_plus_minus_zero = 0; + + sync_data.delta_error_sync = delta_error; + sync_data.delta_capnum = capnum0 - sync_data.level_find_sync_zero; //delta_capnum; + sync_data.count_error_sync = count_error_sync; + sync_data.capnum0 = capnum0; @@ -195,7 +177,7 @@ void sync_detected(void) // EvbRegs.EVBIFRC.all = BIT2; // - + } // // Acknowledge interrupt to receive more interrupts from PIE group 5 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP5; @@ -253,11 +235,6 @@ void sync_detected(void) // PieCtrlRegs.PIEACK.all = PIEACK_GROUP5; sync_data.count_interrupts++; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_18_OFF; -#endif - } @@ -273,18 +250,15 @@ interrupt void Sync_handler(void) { PieCtrlRegs.PIEIER5.all &= MG57; // Set "group" priority PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts - WriteMemory(ADR_SAW_REQUEST, 0x8000); - sync_data.capnum0 = ReadMemory(ADR_SAW_VALUE); - stop_sync_interrupt_local(); // запретили прерывания, разрешим их по таймеру, чтоб избежать дребезга при плохой оптике. #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.sync) + if (enable_profile_led1_sync) i_led1_on_off_special(1); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.sync) + if (enable_profile_led2_sync) i_led2_on_off_special(1); #endif @@ -315,11 +289,11 @@ interrupt void Sync_handler(void) { PieCtrlRegs.PIEIER5.all = TempPIEIER; #if (_ENABLE_INTERRUPT_PROFILE_LED1) - if (profile_interrupt.for_led1.bits.sync) + if (enable_profile_led1_sync) i_led1_on_off_special(0); #endif #if (_ENABLE_INTERRUPT_PROFILE_LED2) - if (profile_interrupt.for_led2.bits.sync) + if (enable_profile_led2_sync) i_led2_on_off_special(0); #endif @@ -332,18 +306,10 @@ void setup_sync_int(void) { // EALLOW; - if (edrk.flag_second_PCH==1) - sync_data.level_find_sync_zero = xpwm_time.pwm_tics+5; - else - sync_data.level_find_sync_zero = LEVEL_FIND_SYNC_ZERO; - + sync_data.level_find_sync_zero = LEVEL_FIND_SYNC_ZERO; sync_data.timeout_sync_signal = 0; sync_data.count_timeout_sync = 0; -// sync_data.what_main_pch = 1; // Первый ПЧ -// sync_data.what_main_pch = 2; // Второй ПЧ - sync_data.what_main_pch = 0; // Любой ПЧ - ///////////////////////////////////////////// diff --git a/Inu/Src/main/sync_tools.h b/Inu/Src/main/sync_tools.h index e41ee87..a936c39 100644 --- a/Inu/Src/main/sync_tools.h +++ b/Inu/Src/main/sync_tools.h @@ -1,6 +1,6 @@ -#define LEVEL_FIND_SYNC_ZERO 10 //74 //24 +#define LEVEL_FIND_SYNC_ZERO 74 //24 #define MAX_COUNT_ERROR_SYNC 100 #define MAX_COUNT_TIMEOUT_SYNC 100 #define MAX_COUNT_PAUSE_READY 100 @@ -21,8 +21,7 @@ typedef struct { int delta_error_sync; int delta_capnum; int count_error_sync; - unsigned int capnum0; - unsigned int capnum1; + int capnum0; int PWMcounterVal; int local_flag_sync_1_2; @@ -34,8 +33,7 @@ typedef struct { int enable_do_sync; int latch_interrupt; int enabled_interrupt; - unsigned int count_interrupts; - unsigned int what_main_pch; + int count_interrupts; @@ -70,7 +68,7 @@ typedef struct { // } cmd; } SYNC_TOOLS_DATA; -#define SYNC_TOOLS_DATA_DEFAULT {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define SYNC_TOOLS_DATA_DEFAULT {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} extern SYNC_TOOLS_DATA sync_data; @@ -90,7 +88,7 @@ int get_status_sync_line(void); void clear_sync_error(void); void Sync_alg(void); -void calculate_sync_detected(void); + diff --git a/Inu/Src/main/tk_Test.c b/Inu/Src/main/tk_Test.c index fd5cc61..4f013e7 100644 --- a/Inu/Src/main/tk_Test.c +++ b/Inu/Src/main/tk_Test.c @@ -7,9 +7,8 @@ #include "MemoryFunctions.h" #include "Spartan2E_Adr.h" #include "x_wdog.h" -#include "project.h" -#pragma CODE_SECTION(pause_10,".fast_run"); + void pause_10(unsigned long t) { unsigned long i; @@ -28,21 +27,13 @@ void test_impulse(unsigned int impulse_channel,long impulse_time) i_WriteMemory(ADR_PWM_DIRECT,0xffff); } -#pragma CODE_SECTION(test_double_impulse,".fast_run"); -void test_double_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2,long impulse_time,long middle_impulse_time,long last_impulse_time, int soft_off_enable, int soft_on_enable) + +void test_double_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2,long impulse_time,long middle_impulse_time) { - project.disable_all_interrupt(); // i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2); // pause_10(middle_impulse_time); - if (soft_on_enable) - { - i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2); - pause_10(last_impulse_time); - } - i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_1); -// pause_10(impulse_time); pause_10(impulse_time); @@ -50,23 +41,12 @@ void test_double_impulse(unsigned int impulse_channel_1,unsigned int impulse_cha pause_10(middle_impulse_time); i_WriteMemory(ADR_PWM_DIRECT, impulse_channel_1); - pause_10(last_impulse_time); - - if (soft_off_enable) - { - i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2); - pause_10(last_impulse_time); - } - + pause_10(middle_impulse_time); i_WriteMemory(ADR_PWM_DIRECT,0xffff); - - project.enable_all_interrupt(); } void test_sin_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2, unsigned int impulse_channel_3, long impulse_time,long middle_impulse_time) { - project.disable_all_interrupt(); - i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2); pause_10(middle_impulse_time); @@ -81,14 +61,12 @@ void test_sin_impulse(unsigned int impulse_channel_1,unsigned int impulse_channe pause_10(impulse_time); i_WriteMemory(ADR_PWM_DIRECT,0xffff); - project.enable_all_interrupt(); } -void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int periodMiddle, int periodLast, int doubleImpulse, int sinImpulse, int soft_off_enable, int soft_on_enable) +void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int periodMiddle, int doubleImpulse, int sinImpulse) { - long p2 = 0, pM = 0, pL = 0; - float pf; + long p2 = 0, pM = 0; unsigned int tk0_0 = 0, tk0_1 = 0, tk0_2 = 0, tk0_3 = 0, tk0_4 = 0, tk0_5 = 0, tk0_6 = 0, tk0_7 = 0; unsigned int tk1_0 = 0, tk1_1 = 0, tk1_2 = 0, tk1_3 = 0, tk1_4 = 0, tk1_5 = 0, tk1_6 = 0, tk1_7 = 0; unsigned int tk2_0 = 0, tk2_1 = 0, tk2_2 = 0, tk2_3 = 0, tk2_4 = 0, tk2_5 = 0, tk2_6 = 0, tk2_7 = 0; @@ -114,25 +92,13 @@ void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int period=1; if (period>=1000) period=1000; - pf = (float)(period) *11.724;/// 2.8328173374613003095975232198142;//(periodMiddle)*12; - p2 = pf; -// p2=(period) * 19 / 10;//(period)*12; + p2=(period) * 19 / 10;//(period)*12; if (periodMiddle<=1) periodMiddle=1; if (periodMiddle>=1000) periodMiddle=1000; -// pM=(periodMiddle) * 19 / 10;//(periodMiddle)*12; - pf = (float)(periodMiddle)*11.724;// / 2.8328173374613003095975232198142;//(periodMiddle)*12; - pM = pf; - - if (periodLast<=1) - periodLast=1; - if (periodLast>=1000) - periodLast=1000; -// pM=(periodMiddle) * 19 / 10;//(periodMiddle)*12; - pf = (float)(periodLast)*11.724;// / 2.8328173374613003095975232198142;//(periodMiddle)*12; - pL = pf; + pM=(periodMiddle) * 19 / 10;//(periodMiddle)*12; @@ -222,55 +188,6 @@ void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int Dkey0 = 0xF9FF; Dkey1 = 0xF0FF; } - else if (tk0_0){ - Dkey0 = 0xfffe; - Dkey1 = 0xfffc; - } - else if (tk0_3){ - Dkey0 = 0xfffd; - Dkey1 = 0xfffc; - } - else if (tk0_4){ - Dkey0 = 0xfffb; - Dkey1 = 0xfff3; - } - else if (tk0_7){ - Dkey0 = 0xfff7; - Dkey1 = 0xfff3; - } - else if (tk1_0){ - Dkey0 = 0xffef; - Dkey1 = 0xffcf; - } - else if (tk1_3){ - Dkey0 = 0xffdf; - Dkey1 = 0xffcf; - } - else if (tk1_4){ - Dkey0 = 0xffbf; - Dkey1 = 0xff3f; - } - else if (tk1_7){ - Dkey0 = 0xff7f; - Dkey1 = 0xff3f; - } - else if (tk2_0){ - Dkey0 = 0xfeff; - Dkey1 = 0xfcff; - } - else if (tk2_3){ - Dkey0 = 0xfdff; - Dkey1 = 0xfcff; - } - else if (tk2_4){ - Dkey0 = 0xfbff; - Dkey1 = 0xf3ff; - } - else if (tk2_7){ - Dkey0 = 0xf7ff; - Dkey1 = 0xf3ff; - } - } else if(sinImpulse) { @@ -352,7 +269,7 @@ void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int } if(doubleImpulse) - test_double_impulse(Dkey0, Dkey1, p2, pM, pL, soft_off_enable, soft_on_enable); + test_double_impulse(Dkey0, Dkey1, p2, pM); else if(sinImpulse) test_sin_impulse(Dkey0, Dkey1, Dkey2, p2, pM); else diff --git a/Inu/Src/main/tk_Test.h b/Inu/Src/main/tk_Test.h index 2a44453..8f81e8c 100644 --- a/Inu/Src/main/tk_Test.h +++ b/Inu/Src/main/tk_Test.h @@ -4,8 +4,7 @@ -void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int periodMiddle, int periodLast, int doubleImpulse, int sinImpulse, int soft_off_enable, int soft_on_enable); -void test_double_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2,long impulse_time,long middle_impulse_time, long last_impulse_time, int soft_off_enable, int soft_on_enable); +void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int periodMiddle, int doubleImpulse, int sinImpulse); #endif diff --git a/Inu/Src/main/v_pwm24_v2.c b/Inu/Src/main/v_pwm24_v2.c index 147c2c9..be2314b 100644 --- a/Inu/Src/main/v_pwm24_v2.c +++ b/Inu/Src/main/v_pwm24_v2.c @@ -108,7 +108,7 @@ void start_PWM24(int O1, int O2) -void InitPWM_Variables(int n_pch) +void InitPWM_Variables(void) { // init_DQ_pid(); @@ -119,9 +119,9 @@ void InitPWM_Variables(int n_pch) ////////////// -// a.k = 0; -// a.k1 = 0; -// a.k2 = 0; + a.k = 0; + a.k1 = 0; + a.k2 = 0; alg_pwm24.k1 = 0; alg_pwm24.k2 = 0; @@ -160,20 +160,6 @@ void InitPWM_Variables(int n_pch) svgen_pwm24_2.pwm_minimal_impuls_zero_plus = svgen_pwm24_1.pwm_minimal_impuls_zero_plus; - if (n_pch==0) - { - svgen_pwm24_1.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_CBA; - svgen_pwm24_2.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_CBA; - } - else - { -// svgen_pwm24_1.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_ACB; // не пошло -// svgen_pwm24_2.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_ACB; - svgen_pwm24_1.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_BAC; - svgen_pwm24_2.phase_sequence = V_PWM24_PHASE_SEQ_REVERS_BAC; - } - - InitVariablesSvgen_Ing(xpwm_time.freq_pwm); } @@ -216,7 +202,6 @@ void InitXPWM(unsigned int freq_pwm) // период в тиках xpwm_time.pwm_tics = pwm_t; xpwm_time.freq_pwm = freq_pwm; - xpwm_time.half_pwm_tics = xpwm_time.pwm_tics >> 1; xpwm_time.one_or_two_interrupts_run = PWN_COUNT_RUN_PER_INTERRUPT; xpwm_time.init(&xpwm_time); @@ -624,129 +609,24 @@ void recalc_time_pwm_minimal_2_xilinx_pwm24(SVGEN_PWM24 *pwm24, } -#define WRITE_SWGEN_PWM_TIMES_VER 2//1 -#if (WRITE_SWGEN_PWM_TIMES_VER==1) #pragma CODE_SECTION(write_swgen_pwm_times,".fast_run2"); void write_swgen_pwm_times(unsigned int mode_reload) { - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_ABC) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - } + xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Ta_0; + xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Ta_1; + xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0; + xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1; + xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tc_0; + xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_ABC) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - } - - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_BCA) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - } - - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_BCA) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - } - - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_CAB) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - } - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_NORMAL_CAB) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - } - - // fix revers - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_BAC) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - } - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_BAC) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - } - - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_ACB) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - } - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_ACB) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - } - - if (svgen_pwm24_1.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_CBA) - { - xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0; - xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1; - xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0; - xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1; - xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0; - xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1; - } - if (svgen_pwm24_2.phase_sequence == V_PWM24_PHASE_SEQ_REVERS_CBA) - { - xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0; - xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1; - xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0; - xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1; - xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0; - xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1; - } + xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Ta_0; + xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Ta_1; + xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0; + xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1; + xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tc_0; + xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tc_1; xpwm_time.Tbr0_0 = break_result_1; xpwm_time.Tbr0_1 = break_result_2; @@ -756,81 +636,6 @@ void write_swgen_pwm_times(unsigned int mode_reload) xpwm_time.write_1_2_winding_break_times(&xpwm_time); } -#endif -/////////////////////////////////////////////////////// -// ver 2 -/////////////////////////////////////////////////////// -#if (WRITE_SWGEN_PWM_TIMES_VER==2) - -#pragma CODE_SECTION(set_pwm_times,".fast_run2"); -void set_pwm_times(unsigned int Ta0, unsigned int Ta1, unsigned int Tb0, unsigned int Tb1, unsigned int Tc0, unsigned int Tc1, unsigned int winding_num) -{ - if (winding_num == 0) - { - xpwm_time.Ta0_0 = Ta0; - xpwm_time.Ta0_1 = Ta1; - xpwm_time.Tb0_0 = Tb0; - xpwm_time.Tb0_1 = Tb1; - xpwm_time.Tc0_0 = Tc0; - xpwm_time.Tc0_1 = Tc1; - } - else - { - xpwm_time.Ta1_0 = Ta0; - xpwm_time.Ta1_1 = Ta1; - xpwm_time.Tb1_0 = Tb0; - xpwm_time.Tb1_1 = Tb1; - xpwm_time.Tc1_0 = Tc0; - xpwm_time.Tc1_1 = Tc1; - } -} - -#pragma CODE_SECTION(process_phase_sequence,".fast_run2"); -void process_phase_sequence(SVGEN_PWM24 svgen_pwm, unsigned int winding_num) -{ - switch (svgen_pwm.phase_sequence) - { - case V_PWM24_PHASE_SEQ_NORMAL_ABC: - set_pwm_times(svgen_pwm.Ta_0, svgen_pwm.Ta_1, svgen_pwm.Tb_0, svgen_pwm.Tb_1, svgen_pwm.Tc_0, svgen_pwm.Tc_1, winding_num); - break; - case V_PWM24_PHASE_SEQ_NORMAL_BCA: - set_pwm_times(svgen_pwm.Tb_0, svgen_pwm.Tb_1, svgen_pwm.Tc_0, svgen_pwm.Tc_1, svgen_pwm.Ta_0, svgen_pwm.Ta_1, winding_num); - break; - case V_PWM24_PHASE_SEQ_NORMAL_CAB: - set_pwm_times(svgen_pwm.Tc_0, svgen_pwm.Tc_1, svgen_pwm.Ta_0, svgen_pwm.Ta_1, svgen_pwm.Tb_0, svgen_pwm.Tb_1, winding_num); - break; - case V_PWM24_PHASE_SEQ_REVERS_BAC: - set_pwm_times(svgen_pwm.Tb_0, svgen_pwm.Tb_1, svgen_pwm.Ta_0, svgen_pwm.Ta_1, svgen_pwm.Tc_0, svgen_pwm.Tc_1, winding_num); - break; - case V_PWM24_PHASE_SEQ_REVERS_ACB: - set_pwm_times(svgen_pwm.Ta_0, svgen_pwm.Ta_1, svgen_pwm.Tc_0, svgen_pwm.Tc_1, svgen_pwm.Tb_0, svgen_pwm.Tb_1, winding_num); - break; - case V_PWM24_PHASE_SEQ_REVERS_CBA: - set_pwm_times(svgen_pwm.Tc_0, svgen_pwm.Tc_1, svgen_pwm.Tb_0, svgen_pwm.Tb_1, svgen_pwm.Ta_0, svgen_pwm.Ta_1, winding_num); - break; - } -} -#pragma CODE_SECTION(write_swgen_pwm_times,".fast_run2"); -void write_swgen_pwm_times(unsigned int mode_reload) -{ - process_phase_sequence(svgen_pwm24_1, 0); - process_phase_sequence(svgen_pwm24_2, 1); - - // fix breaks - xpwm_time.Tbr0_0 = break_result_1; - xpwm_time.Tbr0_1 = break_result_2; - xpwm_time.Tbr1_0 = 0; // break_result_3; - xpwm_time.Tbr1_1 = 0; // break_result_4; - xpwm_time.mode_reload = mode_reload; - - xpwm_time.write_1_2_winding_break_times(&xpwm_time); -} -#endif - - - - - @@ -889,12 +694,15 @@ void svgen_set_time_middle_keys_open(SVGEN_PWM24 *vt) /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// - +//unsigned int buf_m1[10]; +//unsigned int buf_m2[10]; +//unsigned int buf_m3[10]; #pragma CODE_SECTION(detect_level_interrupt,".fast_run"); -unsigned int detect_level_interrupt(int flag_second_PCH) +unsigned int detect_level_interrupt(void) { - unsigned int curr_period1, curr_period2, curr_period0; + unsigned int curr_period1,curr_period2,curr_period0; static unsigned int count_err_read_pwm_xilinx = 0; +// static unsigned int prev_where=0, c_err = 0, c_m=0; WriteMemory(ADR_SAW_REQUEST, 0x8000); @@ -904,45 +712,88 @@ unsigned int detect_level_interrupt(int flag_second_PCH) WriteMemory(ADR_SAW_REQUEST, 0x8000); curr_period2 = ReadMemory(ADR_SAW_VALUE); + +// if (curr_period1>=curr_period0) +// { +// if ((curr_period1-curr_period0)>=50) +// count_err_read_pwm_xilinx++; +// } +// else +// { +// if ((curr_period0-curr_period1)>=50) +// count_err_read_pwm_xilinx++; +// } + + xpwm_time.current_period = curr_period2; +// buf_m1[c_m]=xpwm_time.current_period; - // мы находимся в нижней части пилы? - if (xpwm_time.current_period(xpwm_time.pwm_tics/2)) xpwm_time.where_interrupt = PWM_HIGH_LEVEL_INTERRUPT; - xpwm_time.what_next_interrupt = PWM_LOW_LEVEL_INTERRUPT; - xpwm_time.do_sync_out = !(flag_second_PCH==0); - } -// по идее этот код выполнится при каких то очень больших расхождений в показаниях - if (curr_period2>curr_period1) // идем вверх по пиле + if (curr_period2>curr_period1) { - if ((curr_period2-curr_period1)>xpwm_time.half_pwm_tics)// очень большой разброс - { -// xpwm_time.what_next_interrupt = 1; - // возвращаем ошибку + if ((curr_period2-curr_period1)>(xpwm_time.pwm_tics/2)) return 1; - } } - else// идем вниз по пиле + else { - if ((curr_period1-curr_period2)>xpwm_time.half_pwm_tics)// очень большой разброс - { - // возвращаем ошибку + if ((curr_period1-curr_period2)>(xpwm_time.pwm_tics/2)) return 1; - } } - - // нет ошибок, ок! return 0; - +// buf_m2[c_m]=xpwm_time.where_interrupt; +// +// if (prev_where==xpwm_time.where_interrupt) +// { +// +// buf_m3[0]=xpwm_time.current_period; +// +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[1]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[2]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[3]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[4]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[5]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[6]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[7]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[8]=xpwm_time.current_period; +// i_WriteMemory(ADR_SAW_REQUEST, 0x8000); +// xpwm_time.current_period = i_ReadMemory(ADR_SAW_VALUE); +// buf_m3[9]=xpwm_time.current_period; +// +// c_err++; +// i_led2_toggle(); +// } +// +// if (c_err>500) +// c_err = 0; +// +// c_m++; +// if (c_m>=10) +// c_m=0; +// +// +// prev_where = xpwm_time.where_interrupt; } diff --git a/Inu/Src/main/v_pwm24_v2.h b/Inu/Src/main/v_pwm24_v2.h index fab0949..ab7eaef 100644 --- a/Inu/Src/main/v_pwm24_v2.h +++ b/Inu/Src/main/v_pwm24_v2.h @@ -19,15 +19,6 @@ enum { V_PWM24_PREV_PWM_CLOSE = 1, V_PWM24_PREV_PWM_WORK }; -enum { V_PWM24_PHASE_SEQ_NORMAL_ABC = 1, - V_PWM24_PHASE_SEQ_NORMAL_BCA, - V_PWM24_PHASE_SEQ_NORMAL_CAB, - V_PWM24_PHASE_SEQ_REVERS_ACB, - V_PWM24_PHASE_SEQ_REVERS_CBA, - V_PWM24_PHASE_SEQ_REVERS_BAC -}; - - typedef struct { _iq freq1; @@ -69,7 +60,6 @@ typedef struct { // _iq Gain; // Input: reference gain voltage (pu) // _iq Ib; // _iq Ic; unsigned int number_svgen; - unsigned int phase_sequence; // номер ПЧ для задания нужного направления чередования int prev_level; // предыдущее состояние ШИМа, для перехода из middle или close в рабочее unsigned int Tclosed_high; unsigned int Tclosed_saw_direct_0; @@ -101,7 +91,7 @@ typedef SVGEN_PWM24 *SVGEN_PWM24_handle; //#define SVGEN_PWM24_TIME_DEFAULTS { 0,0,0,0 } -#define SVGEN_PWM24_DEFAULTS { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define SVGEN_PWM24_DEFAULTS { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // (void (*)(unsigned int))svgen_pwm24_calc } //extern int ar_sa_a[3][4][7]; @@ -123,7 +113,7 @@ void write_swgen_pwm_times(unsigned int mode_reload); //void change_freq_pwm(_iq FreqMax, int freq_pwm_xtics, _iq XilinxFreq); -unsigned int detect_level_interrupt(int flag_second_PCH); +unsigned int detect_level_interrupt(void); void svgen_set_time_keys_closed(SVGEN_PWM24 *vt); @@ -145,7 +135,7 @@ void InitXPWM(unsigned int freq_pwm); void start_PWM24(int O1, int O2); -void InitPWM_Variables(int n_pch); + ////////////////////////////////////////////// diff --git a/Inu/Src/main/v_rotor.c b/Inu/Src/main/v_rotor.c index 0fe887c..3164252 100644 --- a/Inu/Src/main/v_rotor.c +++ b/Inu/Src/main/v_rotor.c @@ -1,1101 +1,724 @@ -#include "DSP281x_Examples.h" // DSP281x Examples Include File -#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File -#include "DSP281x_Device.h" // DSP281x Headerfile Include File -#include "IQmathLib.h" - -#include -#include - -#include "filter_v1.h" -#include "xp_cds_in.h" -#include "xp_inc_sensor.h" -#include "xp_project.h" -#include "params.h" -#include "pwm_test_lines.h" -#include "params_norma.h" -#include "mathlib.h" -#include "params_alg.h" - - - -#pragma DATA_SECTION(WRotor,".fast_vars"); -WRotorValues WRotor = WRotorValues_DEFAULTS; - -#if (SENSOR_ALG==SENSOR_ALG_23550) - -#pragma DATA_SECTION(WRotorPBus,".slow_vars"); -WRotorValuesAngle WRotorPBus = WRotorValuesAngle_DEFAULTS; - - -#pragma DATA_SECTION(rotor_error_update_count,".fast_vars"); -unsigned int rotor_error_update_count = 0; - - -#define SIZE_BUF_SENSOR_LOGS 32 -#pragma DATA_SECTION(sensor_1_zero,".slow_vars"); -unsigned int sensor_1_zero[6+4+8][SIZE_BUF_SENSOR_LOGS], count_sensor_1_zero=0; - -#endif - -_iq koefW = _IQ(0.05); //0.05 -_iq koefW2 = _IQ(0.01); //0.05 -_iq koefW3 = _IQ(0.002); //0.05 - - - - - - - -#if (SENSOR_ALG==SENSOR_ALG_23550) -/////////////////////////////////////////////////////////////// -void rotorInit(void) -{ - WRotorPBus.ModeAutoDiscret = 1; -} - - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -#define MAX_COUNT_OVERFULL_DISCRET 2250 -#define MAX_DIRECTION 4000 -#define MAX_DIRECTION_2 2000 -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -void RotorDirectionFilter(int RotorDirectionIn, int *RotorDirectionOut, int *RotorDirectionOut2, int *count_direction) -{ - -// static int count_direction = 0; -// static int count_direction_minus = 0; - - - if (RotorDirectionIn==0) - { - if (*count_direction>0) (*count_direction)--; - if (*count_direction<0) (*count_direction)++; -// if (count_direction_minus>0) count_direction_minus--; - } - else - if (RotorDirectionIn>0) - { - if (*count_direction0) count_direction_minus--; - } - else - { - if (*count_direction>-MAX_DIRECTION) (*count_direction)--; -// if (count_direction_plus>0) count_direction_plus--; - } - - - if (RotorDirectionIn==0) - *RotorDirectionOut = 0; - else - if (RotorDirectionIn>0) - *RotorDirectionOut = 1; - else - *RotorDirectionOut = -1; - - - if (*count_direction>MAX_DIRECTION_2) - *RotorDirectionOut2 = 1; - else - if (*count_direction<-MAX_DIRECTION_2) - *RotorDirectionOut2 = -1; - else - *RotorDirectionOut2 = 0; - - - -} -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -#define LEVEL_VALUE_SENSOR_OVERFULL 65535 -#define MAX_COUNT_ERROR_ANALISATOR_SENSOR_PBUS 4000 -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(AnalisatorRotorSensorPBus,".fast_run"); -int AnalisatorRotorSensorPBus(_iq d1, _iq d2, unsigned int *count_overfull_discret, unsigned int *count_zero_discret, _iq *prev_iqTimeRotor, - unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, - int modeS1, int modeS2, - int valid_sensor_direct, int valid_sensor_90, - unsigned int *error_count ) -{ - int flag_not_ready_rotor, flag_overfull_rotor; - _iq iqTimeRotor; - // discret0 = 2 mks -// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - // discret1 = 20 ns -// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - -// _iq iqWRotorSumm;//,iqWRotorCalc; - - static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. - static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. - static unsigned int discret; - - - if (valid_sensor_direct == 0) - d1 = 0; - if (valid_sensor_90 == 0) - d2 = 0; - - -// тут что-то пошло не так, была смена дискретизации по обоим каналам. - if (valid_sensor_direct == 0 && valid_sensor_90 == 0) - { - if (*error_count>1; - - - -// max OVERFULL - if (flag_overfull_rotor) - { - if (*count_overfull_discret0) - (*count_overfull_discret)--; - } - -// zero? - if (flag_not_ready_rotor) - { - if (*count_zero_discret0) - (*count_zero_discret)--; - } - -// real zero? - if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) - { - // ноль был слишком долго, значит точно ноль! - iqWRotorCalc = 0; - *prev_iqTimeRotor = 0; - iqTimeRotor = 0; - } - else - { - // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor - if (iqTimeRotor==0) - iqTimeRotor = *prev_iqTimeRotor; - } - *prev_iqTimeRotor = iqTimeRotor; - - - -// выбор нужного диапазона - if (WRotorPBus.ModeAutoDiscret==1) - { - if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) || (iqTimeRotor==0) ) - { - // тут или переполнение произошло или вдруг остановились, обороты=0 - // тогда включаем discret_out = 0 - if (discret_in == 1) // или тут надо испльзовать discret? - { - // discret был =1, переключаем на 0. - *discret_out = 0; - *count_overfull_discret = 0; // дали еще один шанс! - } - - } - else - { - // текущ. уровень discret==0 тогда... - if (discret==0 && iqTimeRotortime_level_discret_1to0 && iqTimeRotor!=65535) - *discret_out = 0; - } - } - - if (WRotorPBus.ModeAutoDiscret==2) - { - *discret_out = 0; - } - - if (WRotorPBus.ModeAutoDiscret==3) - { - *discret_out = 1; - } - - if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) ) - { - // тут уже точно в 0, т.к. слишком медленно идут импульсы! - *prev_iqTimeRotor = iqTimeRotor = 0; - } - - - - - if ((iqTimeRotor != 0)) // && (WRotorPBus.iqTimeRotor<65535) - { - if (discret==0) - *iqWRotorCalcBeforeRegul = KoefNorm_discret0 / iqTimeRotor; - if (discret==1) - *iqWRotorCalcBeforeRegul = KoefNorm_discret1 / iqTimeRotor; - - *iqWRotorCalc = exp_regul_iq(koefW, *iqWRotorCalc, *iqWRotorCalcBeforeRegul); - } - else - { - *iqWRotorCalc = 0; - *iqWRotorCalcBeforeRegul = 0; - } - - -// if (*iqWRotorCalc == 0) -// *RotorDirection = 0; - - - return 0; - -} -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - - -#pragma CODE_SECTION(RotorMeasurePBus,".fast_run"); -void RotorMeasurePBus(void) -{ - // discret0 = 2 mks -// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - // discret1 = 20 ns -// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - - static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. - static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. - - static long long KoefNorm_angle = 16384LL; //2^24/1024 -// volatile float MyVar0 = 0; - - unsigned int MyVar3 = 0; -// int direction1 = 0, direction2 = 0; - volatile unsigned int discret; - - static unsigned int discret_out1, discret_out2; - - static int count_full_oborots = 0; - static unsigned int count_overfull_discret1 = 0; - static unsigned int count_zero_discret1 = 0; - static unsigned int count_overfull_discret2 = 0; - static unsigned int count_zero_discret2 = 0; - - static unsigned int count_discret_to_1 = 0; - static unsigned int count_discret_to_0 = 0; - - static unsigned int c_error_pbus_1 = 0; - static unsigned int c_error_pbus_2 = 0; - - - static _iq prev_iqTimeRotor1 = 0, prev_iqTimeRotor2 = 0; - - _iq iqWRotorSumm = 0; - - int flag_not_ready_rotor1, flag_overfull_rotor1; - int flag_not_ready_rotor2, flag_overfull_rotor2; - - //i_led1_on_off(1); - - - - flag_not_ready_rotor1 = 0; - flag_overfull_rotor1 = 0; - flag_not_ready_rotor2 = 0; - flag_overfull_rotor2 = 0; - - - - discret = project.cds_in[0].read.sbus.enabled_channels.bit.discret; - if (project.cds_in[0].read.sbus.enabled_channels.bit.discret != project.cds_in[0].write.sbus.enabled_channels.bit.discret) - discret = 2; - - if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) - { - sensor_1_zero[0][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S1; - sensor_1_zero[1][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1; - sensor_1_zero[2][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1; - sensor_1_zero[3][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S2; - sensor_1_zero[4][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2; - sensor_1_zero[5][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2; - } - sensor_1_zero[6][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt; - sensor_1_zero[7][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt90; - sensor_1_zero[8][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt; - sensor_1_zero[9][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt90; - - sensor_1_zero[10][count_sensor_1_zero] = inc_sensor.data.Time1; - sensor_1_zero[11][count_sensor_1_zero] = inc_sensor.data.Impulses1; - sensor_1_zero[12][count_sensor_1_zero] = inc_sensor.data.CountZero1; - sensor_1_zero[13][count_sensor_1_zero] = inc_sensor.data.CountOne1; - - sensor_1_zero[14][count_sensor_1_zero] = inc_sensor.data.Time2; - sensor_1_zero[15][count_sensor_1_zero] = inc_sensor.data.Impulses2; - sensor_1_zero[16][count_sensor_1_zero] = inc_sensor.data.CountZero2; - sensor_1_zero[17][count_sensor_1_zero] = inc_sensor.data.CountOne2; - - count_sensor_1_zero++; - if (count_sensor_1_zero>=SIZE_BUF_SENSOR_LOGS) - { - count_sensor_1_zero = 0; - count_full_oborots++; - if (count_full_oborots>3) - count_full_oborots = 0; - } -/* - if (count_sensor_1_zero==904) - { - discret = 3; - } -*/ - -#if (ENABLE_ROTOR_SENSOR_ZERO_SIGNAL==1) - if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) - { - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) - WRotorPBus.iqWRotorRawAngle1F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1-32768; - WRotorPBus.iqWRotorRawAngle1R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1-32768; - WRotorPBus.iqAngle1F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1F; - WRotorPBus.iqAngle1R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1R; -#else - WRotorPBus.iqWRotorRawAngle1F = 0; - WRotorPBus.iqWRotorRawAngle1R = 0; - WRotorPBus.iqAngle1F = 0; - WRotorPBus.iqAngle1R = 0; -#endif - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) - WRotorPBus.iqWRotorRawAngle2F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2-32768; - WRotorPBus.iqWRotorRawAngle2R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2-32768; - WRotorPBus.iqAngle2F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2F; - WRotorPBus.iqAngle2R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2R; -#else - WRotorPBus.iqWRotorRawAngle2F = 0; - WRotorPBus.iqWRotorRawAngle2R = 0; - WRotorPBus.iqAngle2F = 0; - WRotorPBus.iqAngle2R = 0; -#endif - } - else - { - WRotorPBus.iqWRotorRawAngle1F = 0; - WRotorPBus.iqWRotorRawAngle1R = 0; - WRotorPBus.iqAngle1F = 0; - WRotorPBus.iqAngle1R = 0; - - WRotorPBus.iqWRotorRawAngle2F = 0; - WRotorPBus.iqWRotorRawAngle2R = 0; - WRotorPBus.iqAngle2F = 0; - WRotorPBus.iqAngle2R = 0; - - } -#endif - - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) - //************************************************************************************************** - MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw0 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw0 = 0; - } - - MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt90; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw1 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw1 = 0; - } -#else - WRotorPBus.iqWRotorRaw0 = 0; - WRotorPBus.iqWRotorRaw1 = 0; -#endif - - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) - //*************************************************************************************************** - MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw2 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw2 = 0; - } - - MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt90; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw3 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw3 = 0; - } -#else - WRotorPBus.iqWRotorRaw2 = 0; - WRotorPBus.iqWRotorRaw3 = 0; -#endif - - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) -// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90 ) - AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw0, WRotorPBus.iqWRotorRaw1, &count_overfull_discret1, &count_zero_discret1, - &prev_iqTimeRotor1, &discret_out1, project.cds_in[0].read.sbus.enabled_channels.bit.discret, - &WRotorPBus.iqWRotorCalcBeforeRegul1, &WRotorPBus.iqWRotorCalc1, - project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_90, - project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90, - &c_error_pbus_1 ); -#endif - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) -// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90 ) - AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw2, WRotorPBus.iqWRotorRaw3, &count_overfull_discret2, &count_zero_discret2, - &prev_iqTimeRotor2, &discret_out2, project.cds_in[0].read.sbus.enabled_channels.bit.discret, - &WRotorPBus.iqWRotorCalcBeforeRegul2, &WRotorPBus.iqWRotorCalc2, - project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_90, - project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90, - &c_error_pbus_2); -#endif - - - // RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow); - - - - if (discret_out1==1 || discret_out2==1) - { - project.cds_in[0].write.sbus.enabled_channels.bit.discret = 1; - count_discret_to_1++; - } - else - { - project.cds_in[0].write.sbus.enabled_channels.bit.discret = 0; - count_discret_to_0++; - } - - -} - - - - -#define MAX_COUNT_OVERFULL_DISCRET_2 150 -#pragma CODE_SECTION(RotorMeasure,".fast_run"); -void RotorMeasure(void) -{ - - // 600 Khz clock on every edge -// static long long KoefNorm = 53635601LL;//((600 000/6256/NORMA_WROTOR/2) * ((long)2 << 24)); //15 - NormaWRotor 782*8 = 6256 -// static long long KoefNormMS = 491520000LL;//((600 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 -// static long long KoefNormNS = 49152000000LL;//((60 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormMS = 122880000LL;//((600 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormNS = 12288000000LL;//((60 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormImpulses = 838860800000000LL;// (2^24 * 1000000000 / (Impulses(ns)) / NORMA_WROTOR - - static _iq max_value_rotor = _IQ(500.0/60.0/NORMA_FROTOR); - static _iq wrotor_add_ramp = _IQ(0.001/NORMA_FROTOR); - -// volatile float MyVar0 = 0; -// volatile unsigned int MyVar1 = 0; -// volatile unsigned int MyVar2 = 0; - unsigned int MyVar3; - - - inc_sensor.read_sensors(&inc_sensor); - - // flag_not_ready_rotor = 0; - -//************************************************************************************************** -// sensor 1 - - if (inc_sensor.use_sensor1) - { - MyVar3 = inc_sensor.data.CountOne1; -// MyVar3 = (unsigned long) rotation_sensor.in_plane.out.CountOne1; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_21_ON; -#endif - - WRotor.iqWRotorRaw0 = MyVar3; - } - else - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_21_OFF; -#endif - - WRotor.iqWRotorRaw0 = 0; - } - MyVar3 = inc_sensor.data.CountZero1; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_22_ON; -#endif - WRotor.iqWRotorRaw1 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_22_OFF; -#endif - WRotor.iqWRotorRaw1 = 0; - } - } - else - { - WRotor.iqWRotorRaw0 = 0; - WRotor.iqWRotorRaw1 = 0; - } - //logpar.uns_log0 = (Uint16)(my_var1); - //logpar.uns_log1 = (Uint16)(my_var2); - - // sensor 2 - if (inc_sensor.use_sensor2) - { - MyVar3 = inc_sensor.data.CountOne2; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_18_ON; -#endif - WRotor.iqWRotorRaw2 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_18_OFF; -#endif - WRotor.iqWRotorRaw2 = 0; - } - - MyVar3 = inc_sensor.data.CountZero2; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_23_ON; -#endif - WRotor.iqWRotorRaw3 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_23_OFF; -#endif - WRotor.iqWRotorRaw3 = 0; - } - } - else - { - WRotor.iqWRotorRaw2 = 0; - WRotor.iqWRotorRaw3 = 0; - } - -// if (WRotor.iqWRotorRaw0==0 && WRotor.iqWRotorRaw1==0 && WRotor.iqWRotorRaw2==0 && WRotor.iqWRotorRaw3==0) -// flag_not_ready_rotor = 1; - - if (WRotor.iqWRotorRaw0==0) - { - if (WRotor.count_zero_discret0==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0 = 0; - } - else - { - WRotor.iqWRotorRaw0 = WRotor.prev_iqWRotorRaw0; - WRotor.count_zero_discret0++; - } - } - else - { - WRotor.count_zero_discret0 = 0; - WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0; - } - - if (WRotor.iqWRotorRaw1==0) - { - if (WRotor.count_zero_discret1==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1 = 0; - } - else - { - WRotor.iqWRotorRaw1 = WRotor.prev_iqWRotorRaw1; - WRotor.count_zero_discret1++; - } - } - else - { - WRotor.count_zero_discret1 = 0; - WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1; - } - - if (WRotor.iqWRotorRaw2==0) - { - if (WRotor.count_zero_discret2==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2 = 0; - } - else - { - WRotor.iqWRotorRaw2 = WRotor.prev_iqWRotorRaw2; - WRotor.count_zero_discret2++; - } - } - else - { - WRotor.count_zero_discret2 = 0; - WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2; - } - - if (WRotor.iqWRotorRaw3==0) - { - if (WRotor.count_zero_discret3==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3 = 0; - } - else - { - WRotor.iqWRotorRaw3 = WRotor.prev_iqWRotorRaw3; - WRotor.count_zero_discret3++; - } - } - else - { - WRotor.count_zero_discret3 = 0; - WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3; - } - - - WRotor.iqTimeSensor1 = WRotor.iqWRotorRaw0 + WRotor.iqWRotorRaw1; - WRotor.iqTimeSensor2 = WRotor.iqWRotorRaw2 + WRotor.iqWRotorRaw3; - - // -// // zero? -// if (flag_not_ready_rotor) -// { -// if (*count_zero_discret0) -// (*count_zero_discret)--; -// } -// -// // real zero? -// if (count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) -// { -// // ноль был слишком долго, значит точно ноль! -// WRotor.iqTimeSensor1 = 0; -// WRotor.prev_iqTimeSensor1 = 0; -// } -// else -// { -// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor -// if (WRotor.iqTimeSensor1==0) -// WRotor.iqTimeSensor1 = WRotor.prev_iqTimeSensor1; -// } -// WRotor.prev_iqTimeSensor1 = WRotor.iqTimeSensor1; -// -// -// // max OVERFULL -// if (flag_overfull_rotor) -// { -// if (*count_overfull_discret0) -// (*count_overfull_discret)--; -// } -// -// // zero? -// if (flag_not_ready_rotor) -// { -// if (*count_zero_discret0) -// (*count_zero_discret)--; -// } -// -// // real zero? -// if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) -// { -// // ноль был слишком долго, значит точно ноль! -// iqWRotorCalc = 0; -// *prev_iqTimeRotor = 0; -// iqTimeRotor = 0; -// } -// else -// { -// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor -// if (iqTimeRotor==0) -// iqTimeRotor = *prev_iqTimeRotor; -// } -// *prev_iqTimeRotor = iqTimeRotor; -// -// -// - -/// - if (WRotor.iqTimeSensor1 != 0 && inc_sensor.use_sensor1) - { - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==0) - WRotor.iqWRotorCalcBeforeRegul1 = KoefNormMS / WRotor.iqTimeSensor1; - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==1) - WRotor.iqWRotorCalcBeforeRegul1 = KoefNormNS / WRotor.iqTimeSensor1; - - if (WRotor.iqWRotorCalcBeforeRegul1 > max_value_rotor) - { - WRotor.iqWRotorCalc1 = 0; - WRotor.iqWRotorCalcBeforeRegul1 = 0; - } - else - WRotor.iqWRotorCalc1 = exp_regul_iq(koefW, WRotor.iqWRotorCalc1, WRotor.iqWRotorCalcBeforeRegul1); - - ///// - if (WRotor.iqWRotorCalc1) - { - if (WRotor.iqPrevWRotorCalc1 != WRotor.iqWRotorCalc1) - { - WRotor.iqWRotorCalc1Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc1Ramp, WRotor.iqWRotorCalc1); - WRotor.iqPrevWRotorCalc1 = WRotor.iqWRotorCalc1; - } - } - else - { - WRotor.iqPrevWRotorCalc1 = 0; - WRotor.iqWRotorCalc1Ramp = 0; - } - //// - } - else - { - WRotor.iqWRotorCalc1 = 0; - WRotor.iqWRotorCalcBeforeRegul1 = 0; - } -/// - if (WRotor.iqTimeSensor2 != 0 && inc_sensor.use_sensor2) - { - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==0) - WRotor.iqWRotorCalcBeforeRegul2 = KoefNormMS / WRotor.iqTimeSensor2; - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==1) - WRotor.iqWRotorCalcBeforeRegul2 = KoefNormNS / WRotor.iqTimeSensor2; - - if (WRotor.iqWRotorCalcBeforeRegul2 > max_value_rotor) - { - WRotor.iqWRotorCalc2 = 0; - WRotor.iqWRotorCalcBeforeRegul2 = 0; - } - else - WRotor.iqWRotorCalc2 = exp_regul_iq(koefW, WRotor.iqWRotorCalc2, WRotor.iqWRotorCalcBeforeRegul2); - - - - ///// - if (WRotor.iqWRotorCalc2) - { - if (WRotor.iqPrevWRotorCalc2 != WRotor.iqWRotorCalc2) - { - WRotor.iqWRotorCalc2Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc2Ramp, WRotor.iqWRotorCalc2); - WRotor.iqPrevWRotorCalc2 = WRotor.iqWRotorCalc2; - } - } - else - { - WRotor.iqPrevWRotorCalc2 = 0; - WRotor.iqWRotorCalc2Ramp = 0; - } - //// - } - else - { - WRotor.iqWRotorCalc2 = 0; - WRotor.iqWRotorCalcBeforeRegul2 = 0; - } -/// - if (inc_sensor.data.TimeCalcFromImpulses1 && inc_sensor.use_sensor1) - WRotor.iqWRotorImpulsesBeforeRegul1 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses1 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); - else - WRotor.iqWRotorImpulsesBeforeRegul1 = 0; - - WRotor.iqWRotorImpulses1 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses1, WRotor.iqWRotorImpulsesBeforeRegul1); - - if (inc_sensor.data.TimeCalcFromImpulses2 && inc_sensor.use_sensor2) - WRotor.iqWRotorImpulsesBeforeRegul2 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses2 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); - else - WRotor.iqWRotorImpulsesBeforeRegul2 = 0; - - WRotor.iqWRotorImpulses2 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses2, WRotor.iqWRotorImpulsesBeforeRegul2); - - - // WRotor.iqWRotorCalcBeforeRegul = _IQdiv(WRotor.iqWRotorCalcBeforeRegul,IQ_CONST_3); -} - -#define LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS 50 // Oborot -void select_values_wrotor(void) -{ - static _iq level_switch_to_get_impulses_hz = _IQ(LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS/60.0/NORMA_FROTOR); - static unsigned int prev_RotorDirectionInstant = 0; - static unsigned int status_RotorRotation = 0; // есть вращение? - static _iq wrotor_add = _IQ(0.002/NORMA_FROTOR); - - - - - if (WRotor.iqWRotorCalc1>level_switch_to_get_impulses_hz - || WRotor.iqWRotorCalc2>level_switch_to_get_impulses_hz) - { - // уже большие обороты - if (WRotor.iqWRotorImpulses1 || WRotor.iqWRotorImpulses2) - { - if(WRotor.iqWRotorImpulses1>WRotor.iqWRotorImpulses2) - WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul2; - } - else - { - if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; - } - - - } - else - { - if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; - - } - - - // пропало направление -// if (prev_prev_RotorDirectionInstant && WRotorPBus.RotorDirectionSlow) -// if (WRotor.iqWRotorSum) -// { -// inc_sensor.break_direction = 1; -// } -// prev_prev_RotorDirectionInstant = WRotorPBus.RotorDirectionSlow; - - - -//// ошибка направления!!! -// if (WRotorPBus.RotorDirectionSlow==0) -// { -// if (WRotor.iqWRotorSum) -// inc_sensor.break_direction = 1; -// } -// else -// inc_sensor.break_direction = 0; - - -// if (WRotorPBus.RotorDirectionSlow==0) -// { -// // гоним в 0 обороты !!! ошибка направления!!! -// WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, 0); -// } -// else - - - WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, WRotor.iqWRotorSum*WRotorPBus.RotorDirectionSlow); - - WRotor.iqWRotorSumRamp = zad_intensiv_q(wrotor_add, wrotor_add, WRotor.iqWRotorSumRamp, WRotor.iqWRotorSumFilter); - - - WRotor.iqWRotorSumFilter2 = exp_regul_iq(koefW2, WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter); - WRotor.iqWRotorSumFilter3 = exp_regul_iq(koefW3, WRotor.iqWRotorSumFilter3, WRotor.iqWRotorSumFilter); - -} - - - -#pragma CODE_SECTION(RotorMeasure,".fast_run"); -void RotorMeasureDetectDirection(void) -{ - int direction1, direction2, sum_direct; - - direction1 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_CLOCKWISE ? 1 : - project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? -1 : - 0; - - direction2 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? 1 : - project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_CLOCKWISE ? -1 : - 0; - - sum_direct = (direction1 + direction2) > 0 ? 1 : - (direction1 + direction2) < 0 ? -1 : - 0; - - WRotorPBus.RotorDirectionInstant = sum_direct; - -} - - -/////////////////////////////////////////////////////////////// - -#endif - - - -/////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(update_rot_sensors,".fast_run"); -void update_rot_sensors(void) -{ - inc_sensor.update_sensors(&inc_sensor); -} -/////////////////////////////////////////////////////////////// +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File +#include "IQmathLib.h" + +#include +#include + +#include "filter_v1.h" +#include "xp_cds_in.h" +#include "xp_inc_sensor.h" +#include "xp_project.h" + + + + +#pragma DATA_SECTION(WRotor,".fast_vars"); +WRotorValues WRotor = WRotorValues_DEFAULTS; + +#pragma DATA_SECTION(WRotorPBus,".fast_vars"); +WRotorValuesAngle WRotorPBus = WRotorValuesAngle_DEFAULTS; + +#pragma DATA_SECTION(rotor_error_update_count,".fast_vars"); +unsigned int rotor_error_update_count = 0; + + +#define SIZE_BUF_SENSOR_LOGS 32 +#pragma DATA_SECTION(sensor_1_zero,".slow_vars"); +unsigned int sensor_1_zero[6+4+8][SIZE_BUF_SENSOR_LOGS], count_sensor_1_zero=0; + + +void rotorInit(void) +{ + WRotorPBus.ModeAutoDiscret = 1; +} + + +#pragma CODE_SECTION(update_rot_sensors,".fast_run"); +void update_rot_sensors(void) +{ + inc_sensor.update_sensors(&inc_sensor); +} + + +#define MAX_COUNT_OVERFULL_DISCRET 2250 +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// + +#define LEVEL_VALUE_SENSOR_OVERFULL 65535 +#define MAX_COUNT_ERROR_ANALISATOR_SENSOR_PBUS 4000 + +#pragma CODE_SECTION(AnalisatorRotorSensorPBus,".fast_run"); +int AnalisatorRotorSensorPBus(_iq d1, _iq d2, unsigned int *count_overfull_discret, unsigned int *count_zero_discret, _iq *prev_iqTimeRotor, + unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, + int *RotorDirection, + int modeS1, int modeS2, + int valid_sensor_direct, int valid_sensor_90, + unsigned int *error_count ) +{ + int flag_not_ready_rotor, flag_overfull_rotor; + _iq iqTimeRotor; + static _iq koefW = _IQ(0.05);//0.05 + // discret0 = 2 mks +// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + // discret1 = 20 ns +// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + +// _iq iqWRotorSumm;//,iqWRotorCalc; + + static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. + static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. + static unsigned int discret; + + + if (valid_sensor_direct == 0) + d1 = 0; + if (valid_sensor_90 == 0) + d2 = 0; + + +// тут что-то пошло не так, была смена дискретизации по обоим каналам. + if (valid_sensor_direct == 0 && valid_sensor_90 == 0) + { + if (*error_count>1; + + + +// max OVERFULL + if (flag_overfull_rotor) + { + if (*count_overfull_discret0) + (*count_overfull_discret)--; + } + +// zero? + if (flag_not_ready_rotor) + { + if (*count_zero_discret0) + (*count_zero_discret)--; + } + +// real zero? + if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) + { + // ноль был слишком долго, значит точно ноль! + iqWRotorCalc = 0; + *prev_iqTimeRotor = 0; + iqTimeRotor = 0; + } + else + { + // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor + if (iqTimeRotor==0) + iqTimeRotor = *prev_iqTimeRotor; + } + *prev_iqTimeRotor = iqTimeRotor; + + + +// выбор нужного диапазона + if (WRotorPBus.ModeAutoDiscret==1) + { + if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) || (iqTimeRotor==0) ) + { + // тут или переполнение произошло или вдруг остановились, обороты=0 + // тогда включаем discret_out = 0 + if (discret_in == 1) // или тут надо испльзовать discret? + { + // discret был =1, переключаем на 0. + *discret_out = 0; + *count_overfull_discret = 0; // дали еще один шанс! + } + + } + else + { + // текущ. уровень discret==0 тогда... + if (discret==0 && iqTimeRotortime_level_discret_1to0 && iqTimeRotor!=65535) + *discret_out = 0; + } + } + + if (WRotorPBus.ModeAutoDiscret==2) + { + *discret_out = 0; + } + + if (WRotorPBus.ModeAutoDiscret==3) + { + *discret_out = 1; + } + + if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) ) + { + // тут уже точно в 0, т.к. слишком медленно идут импульсы! + *prev_iqTimeRotor = iqTimeRotor = 0; + } + + + + + if ((iqTimeRotor != 0)) // && (WRotorPBus.iqTimeRotor<65535) + { + if (discret==0) + *iqWRotorCalcBeforeRegul = KoefNorm_discret0 / iqTimeRotor; + if (discret==1) + *iqWRotorCalcBeforeRegul = KoefNorm_discret1 / iqTimeRotor; + + *iqWRotorCalc = exp_regul_iq(koefW, *iqWRotorCalc, *iqWRotorCalcBeforeRegul); + } + else + { + *iqWRotorCalc = 0; + *iqWRotorCalcBeforeRegul = 0; + } + + + if (*iqWRotorCalc == 0) + *RotorDirection = 0; + + + return 0; + +} +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// + + +#pragma CODE_SECTION(RotorMeasurePBus,".fast_run"); +void RotorMeasurePBus(void) +{ + // discret0 = 2 mks +// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + // discret1 = 20 ns +// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + + static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. + static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. + + static long long KoefNorm_angle = 16384LL; //2^24/1024 + volatile float MyVar0 = 0; + + unsigned int MyVar3 = 0; + int direction1 = 0, direction2 = 0; + volatile unsigned int discret; + + static unsigned int discret_out1, discret_out2; + + static int count_full_oborots = 0; + static unsigned int count_overfull_discret1 = 0; + static unsigned int count_zero_discret1 = 0; + static unsigned int count_overfull_discret2 = 0; + static unsigned int count_zero_discret2 = 0; + + static unsigned int count_discret_to_1 = 0; + static unsigned int count_discret_to_0 = 0; + + static unsigned int c_error_pbus_1 = 0; + static unsigned int c_error_pbus_2 = 0; + + + static _iq prev_iqTimeRotor1 = 0, prev_iqTimeRotor2 = 0; + + _iq iqWRotorSumm = 0; + _iq koefW = _IQ(0.05);//0.05 + + int flag_not_ready_rotor1, flag_overfull_rotor1; + int flag_not_ready_rotor2, flag_overfull_rotor2; + + //i_led1_on_off(1); + + + + flag_not_ready_rotor1 = 0; + flag_overfull_rotor1 = 0; + flag_not_ready_rotor2 = 0; + flag_overfull_rotor2 = 0; + +#if(C_cds_in_number>=1) + project.cds_in[0].read_pbus(&project.cds_in[0]); +#endif + + discret = project.cds_in[0].read.sbus.enabled_channels.bit.discret; + if (project.cds_in[0].read.sbus.enabled_channels.bit.discret != project.cds_in[0].write.sbus.enabled_channels.bit.discret) + discret = 2; + + sensor_1_zero[0][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S1; + sensor_1_zero[1][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1; + sensor_1_zero[2][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1; + sensor_1_zero[3][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S2; + sensor_1_zero[4][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2; + sensor_1_zero[5][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2; + + sensor_1_zero[6][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt; + sensor_1_zero[7][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt90; + sensor_1_zero[8][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt; + sensor_1_zero[9][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt90; + + sensor_1_zero[10][count_sensor_1_zero] = inc_sensor.data.Time1; + sensor_1_zero[11][count_sensor_1_zero] = inc_sensor.data.Impulses1; + sensor_1_zero[12][count_sensor_1_zero] = inc_sensor.data.CountZero1; + sensor_1_zero[13][count_sensor_1_zero] = inc_sensor.data.CountOne1; + + sensor_1_zero[14][count_sensor_1_zero] = inc_sensor.data.Time2; + sensor_1_zero[15][count_sensor_1_zero] = inc_sensor.data.Impulses2; + sensor_1_zero[16][count_sensor_1_zero] = inc_sensor.data.CountZero2; + sensor_1_zero[17][count_sensor_1_zero] = inc_sensor.data.CountOne2; + + count_sensor_1_zero++; + if (count_sensor_1_zero>=SIZE_BUF_SENSOR_LOGS) + { + count_sensor_1_zero = 0; + count_full_oborots++; + if (count_full_oborots>3) + count_full_oborots = 0; + } +/* + if (count_sensor_1_zero==904) + { + discret = 3; + } +*/ +#if (ENABLE_ROTOR_SENSOR_1==1) + WRotorPBus.iqWRotorRawAngle1F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1-32768; + WRotorPBus.iqWRotorRawAngle1R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1-32768; + WRotorPBus.iqAngle1F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1F; + WRotorPBus.iqAngle1R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1R; +#else + WRotorPBus.iqWRotorRawAngle1F = 0; + WRotorPBus.iqWRotorRawAngle1R = 0; + WRotorPBus.iqAngle1F = 0; + WRotorPBus.iqAngle1R = 0; +#endif + +#if (ENABLE_ROTOR_SENSOR_2==1) + WRotorPBus.iqWRotorRawAngle2F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2-32768; + WRotorPBus.iqWRotorRawAngle2R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2-32768; + WRotorPBus.iqAngle2F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2F; + WRotorPBus.iqAngle2R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2R; +#else + WRotorPBus.iqWRotorRawAngle2F = 0; + WRotorPBus.iqWRotorRawAngle2R = 0; + WRotorPBus.iqAngle2F = 0; + WRotorPBus.iqAngle2R = 0; +#endif + + + + +#if (ENABLE_ROTOR_SENSOR_1==1) + //************************************************************************************************** + MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw0 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw0 = 0; + } + + MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt90; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw1 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw1 = 0; + } +#else + WRotorPBus.iqWRotorRaw0 = 0; + WRotorPBus.iqWRotorRaw1 = 0; +#endif + + +#if (ENABLE_ROTOR_SENSOR_2==1) + //*************************************************************************************************** + MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw2 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw2 = 0; + } + + MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt90; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw3 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw3 = 0; + } +#else + WRotorPBus.iqWRotorRaw2 = 0; + WRotorPBus.iqWRotorRaw3 = 0; +#endif + + +#if (ENABLE_ROTOR_SENSOR_1==1) +// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90 ) + AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw0, WRotorPBus.iqWRotorRaw1, &count_overfull_discret1, &count_zero_discret1, + &prev_iqTimeRotor1, &discret_out1, project.cds_in[0].read.sbus.enabled_channels.bit.discret, + &WRotorPBus.iqWRotorCalcBeforeRegul1, &WRotorPBus.iqWRotorCalc1, + &WRotorPBus.RotorDirection1, + project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_90, + project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90, + &c_error_pbus_1 ); +#endif + +#if (ENABLE_ROTOR_SENSOR_2==1) +// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90 ) + AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw2, WRotorPBus.iqWRotorRaw3, &count_overfull_discret2, &count_zero_discret2, + &prev_iqTimeRotor2, &discret_out2, project.cds_in[0].read.sbus.enabled_channels.bit.discret, + &WRotorPBus.iqWRotorCalcBeforeRegul2, &WRotorPBus.iqWRotorCalc2, + &WRotorPBus.RotorDirection2, + project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_90, + project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90, + &c_error_pbus_2); +#endif + + if (discret_out1==1 || discret_out2==1) + { + project.cds_in[0].write.sbus.enabled_channels.bit.discret = 1; + count_discret_to_1++; + } + else + { + project.cds_in[0].write.sbus.enabled_channels.bit.discret = 0; + count_discret_to_0++; + } + + +} + + + + + +#pragma CODE_SECTION(RotorMeasure,".fast_run"); +void RotorMeasure(void) +{ + + // 600 Khz clock on every edge +// static long long KoefNorm = 53635601LL;//((600 000/6256/NORMA_WROTOR/2) * ((long)2 << 24)); //15 - NormaWRotor 782*8 = 6256 +// static long long KoefNormMS = 491520000LL;//((600 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 +// static long long KoefNormNS = 49152000000LL;//((60 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormMS = 122880000LL;//((600 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormNS = 12288000000LL;//((60 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormImpulses = 838860800000000LL;// (2^24 * 1000000000 / (Impulses(ns)) / NORMA_WROTOR + + volatile float MyVar0 = 0; +// volatile unsigned int MyVar1 = 0; +// volatile unsigned int MyVar2 = 0; + unsigned int MyVar3 = 0; + int direction1 = 0, direction2 = 0; + _iq koefW = _IQ(0.05);//0.05 + + + inc_sensor.read_sensors(&inc_sensor); + +// rotation_sensor.read_sensors(&rotation_sensor); +// if(rotation_sensor.in_plane.read.regs.comand_reg.bit.update_registers) +// { +// rotor_error_update_count ++; +// } + +// WRotor.RotorDirection = (rotation_sensor.in_plane.out.direction1 + rotation_sensor.in_plane.out.direction2) > 0 ? 1 : +// (rotation_sensor.in_plane.out.direction1 + rotation_sensor.in_plane.out.direction2) < 0 ? -1 : +// 0; +// + + + // direction1 = rotation_sensor.in_plane.cds_in->read.pbus.direction_in.bit.dir0 == 2 ? 1 : + // rotation_sensor.in_plane.cds_in->read.pbus.direction_in.bit.dir0 == 1 ? -1 : +// 0; +// direction2 = rotation_sensor.in_plane.cds_in->read.pbus.direction_in.bit.dir1 == 2 ? 1 : +// rotation_sensor.in_plane.cds_in->read.pbus.direction_in.bit.dir1 == 1 ? -1 : +// 0; +// WRotor.RotorDirection = (direction1 + direction2) > 0 ? 1 : +// (direction1 + direction2) < 0 ? -1 : + // 0; + + + + + //************************************************************************************************** + // sensor 1 +// if((rotation_sensor.in_plane.out.CountOne1 <= 200) +// || rotation_sensor.in_plane.out.CountOne1 == 65535) +// { rotation_sensor.in_plane.out.CountOne1 = 0; } +// if((rotation_sensor.in_plane.out.CountZero1 <= 200) +// || rotation_sensor.in_plane.out.CountZero1 == 65535) +// { rotation_sensor.in_plane.out.CountZero1 = 0; } + + if (inc_sensor.use_sensor1) + { + MyVar3 = inc_sensor.data.CountOne1; +// MyVar3 = (unsigned long) rotation_sensor.in_plane.out.CountOne1; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotor.iqWRotorRaw0 = MyVar3; + // WRotor.iqWRotorRaw0 = KoefNorm / MyVar3; + // MyVar0 = 9590 / MyVar0;//100000 / MyVar0; // 100000 = 60MHz/Impulses, Balzam: Dents = 600, Impuls per dent = 1; Pr 162 : Dents = 782, Impuls per dent = 8 + // WRotor.iqWRotorRaw0 = _IQ(MyVar0/NORMA_WROTOR); + } + else + { + WRotor.iqWRotorRaw0 = 0; + } + +// MyVar3 = (unsigned long) rotation_sensor.in_plane.out.CountZero1; + MyVar3 = inc_sensor.data.CountZero1; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotor.iqWRotorRaw1 = MyVar3; + } + else + { + WRotor.iqWRotorRaw1 = 0; + } + } + else + { + WRotor.iqWRotorRaw0 = 0; + WRotor.iqWRotorRaw1 = 0; + } + //logpar.uns_log0 = (Uint16)(my_var1); + //logpar.uns_log1 = (Uint16)(my_var2); + + //*************************************************************************************************** + // sensor 2 +// if((rotation_sensor.in_plane.out.CountOne2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2) +// || rotation_sensor.in_plane.out.CountOne2 == 65535) +// { rotation_sensor.in_plane.out.CountOne2 = 0; } +// if((rotation_sensor.in_plane.out.CountZero2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2) +// || rotation_sensor.in_plane.out.CountZero2 == 65535) +// { rotation_sensor.in_plane.out.CountZero2 = 0; } + + if (inc_sensor.use_sensor2) + { + MyVar3 = inc_sensor.data.CountOne2; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotor.iqWRotorRaw2 = MyVar3; + } + else + { + WRotor.iqWRotorRaw2 = 0; + } + + MyVar3 = inc_sensor.data.CountZero2; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotor.iqWRotorRaw3 = MyVar3; + } + else + { + WRotor.iqWRotorRaw3 = 0; + } +// i_led1_on_off(0); + } + else + { + WRotor.iqWRotorRaw2 = 0; + WRotor.iqWRotorRaw3 = 0; + } + + + + WRotor.iqTimeSensor1 = WRotor.iqWRotorRaw0 + WRotor.iqWRotorRaw1; + WRotor.iqTimeSensor2 = WRotor.iqWRotorRaw2 + WRotor.iqWRotorRaw3; + + + if (WRotor.iqTimeSensor1 != 0 && inc_sensor.use_sensor1) + { + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==0) + WRotor.iqWRotorCalcBeforeRegul1 = KoefNormMS / WRotor.iqTimeSensor1; + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==1) + WRotor.iqWRotorCalcBeforeRegul1 = KoefNormNS / WRotor.iqTimeSensor1; + + WRotor.iqWRotorCalc1 = exp_regul_iq(koefW, WRotor.iqWRotorCalc1, WRotor.iqWRotorCalcBeforeRegul1); + } + else + { + WRotor.iqWRotorCalc1 = 0; + WRotor.iqWRotorCalcBeforeRegul1 = 0; + } + + if (WRotor.iqTimeSensor2 != 0 && inc_sensor.use_sensor2) + { + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==0) + WRotor.iqWRotorCalcBeforeRegul2 = KoefNormMS / WRotor.iqTimeSensor2; + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==1) + WRotor.iqWRotorCalcBeforeRegul2 = KoefNormNS / WRotor.iqTimeSensor2; + WRotor.iqWRotorCalc2 = exp_regul_iq(koefW, WRotor.iqWRotorCalc2, WRotor.iqWRotorCalcBeforeRegul2); + } + else + { + WRotor.iqWRotorCalc2 = 0; + WRotor.iqWRotorCalcBeforeRegul2 = 0; + } + + if (inc_sensor.data.TimeCalcFromImpulses1 && inc_sensor.use_sensor1) + WRotor.iqWRotorImpulses1 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses1 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); + else + WRotor.iqWRotorImpulses1 = 0; + + if (inc_sensor.data.TimeCalcFromImpulses2 && inc_sensor.use_sensor2) + WRotor.iqWRotorImpulses2 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses2 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); + else + WRotor.iqWRotorImpulses2 = 0; + + + + // WRotor.iqWRotorCalcBeforeRegul = _IQdiv(WRotor.iqWRotorCalcBeforeRegul,IQ_CONST_3); +// i_led1_on_off(0); + if (WRotor.iqWRotorCalc1 == 0 && inc_sensor.use_sensor1) + WRotor.RotorDirection1 = 0; + if (WRotor.iqWRotorCalc2 == 0 && inc_sensor.use_sensor2) + WRotor.RotorDirection2 = 0; + //wrotor.iq_wrotor_calc = 0; + //i_led2_on_off(0); + +} diff --git a/Inu/Src/main/v_rotor.h b/Inu/Src/main/v_rotor.h index aad2216..7141985 100644 --- a/Inu/Src/main/v_rotor.h +++ b/Inu/Src/main/v_rotor.h @@ -5,35 +5,16 @@ extern "C" { #endif -#include "params_bsu.h" - - -// датчик по часовой -#define ROTOR_SENSOR_CODE_CLOCKWISE 2 // по часовой -#define ROTOR_SENSOR_CODE_COUNTERCLOCKWISE 1 // против часовой - -// датчик против часовой -//#define ROTOR_SENSOR_CODE_CLOCKWISE 1 // по часовой -//#define ROTOR_SENSOR_CODE_COUNTERCLOCKWISE 2 // против часовой - - void update_rot_sensors(void); void RotorMeasure(void); void RotorMeasurePBus(void); void rotorInit(void); -void select_values_wrotor(void); - - -void RotorDirectionFilter(int RotorDirectionIn, int *RotorDirectionOut, int *RotorDirectionOut2, int *count_direction); - int AnalisatorRotorSensorPBus(_iq d1, _iq d2, unsigned int *count_overfull_discret, unsigned int *count_zero_discret, _iq *prev_iqTimeRotor, - unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, + unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, + int *RotorDirection, int modeS1, int modeS2, int valid_sensor_direct, int valid_sensor_90, - unsigned int *error_count); - -void RotorMeasureDetectDirection(void); - + unsigned int *error_count ); typedef struct { @@ -52,47 +33,23 @@ typedef struct _iq iqTimeSensor1; _iq iqTimeSensor2; - _iq prev_iqWRotorRaw0; - _iq prev_iqWRotorRaw1; - _iq prev_iqWRotorRaw2; - _iq prev_iqWRotorRaw3; - - unsigned int count_zero_discret0; - unsigned int count_zero_discret1; - unsigned int count_zero_discret2; - unsigned int count_zero_discret3; - - _iq iqWRotorCalc1; _iq iqWRotorCalcBeforeRegul1; _iq iqWRotorCalc2; _iq iqWRotorCalcBeforeRegul2; -// int RotorDirectionInstant; -// int RotorDirectionSlow; + int RotorDirection1; + int RotorDirection2; _iq iqWRotorImpulses1; _iq iqWRotorImpulsesBeforeRegul1; _iq iqWRotorImpulses2; _iq iqWRotorImpulsesBeforeRegul2; - _iq iqWRotorSum; - _iq iqWRotorSumFilter; - _iq iqWRotorSumFilter2; - _iq iqWRotorSumFilter3; - - _iq iqWRotorSumRamp; - - _iq iqWRotorCalc1Ramp; - _iq iqPrevWRotorCalc1; - _iq iqWRotorCalc2Ramp; - _iq iqPrevWRotorCalc2; - - int RotorDirectionSlow; } WRotorValues; -#define WRotorValues_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0, 0} +#define WRotorValues_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} typedef struct { @@ -101,6 +58,10 @@ typedef struct _iq iqWRotorRaw2; _iq iqWRotorRaw3; + _iq iqWRotorRawAngle1F; + _iq iqWRotorRawAngle1R; + _iq iqWRotorRawAngle2F; + _iq iqWRotorRawAngle2R; _iq iqWRotorFilter0; _iq iqWRotorFilter1; @@ -108,7 +69,7 @@ typedef struct _iq iqWRotorFilter3; _iq iqWRotorDelta; -// _iq iqWRotorCalcBeforeRegul; + _iq iqWRotorCalcBeforeRegul; _iq iqWRotorCalcBeforeRegul1; _iq iqWRotorCalcBeforeRegul2; @@ -121,40 +82,25 @@ typedef struct _iq iqWRotorCalc1; _iq iqWRotorCalc2; -// _iq iqWRotorCalc; + _iq iqWRotorCalc; int ModeAutoDiscret; - int RotorDirectionInstant; - int RotorDirectionSlow; - int RotorDirectionCount; - int RotorDirectionSlow2; + int RotorDirection1; + int RotorDirection2; + _iq iqAngle1F; + _iq iqAngle1R; + _iq iqAngle2F; + _iq iqAngle2R; -#if (ENABLE_ROTOR_SENSOR_ZERO_SIGNAL==1) - _iq iqWRotorRawAngle1F; - _iq iqWRotorRawAngle1R; - _iq iqWRotorRawAngle2F; - _iq iqWRotorRawAngle2R; - - _iq iqAngle1F; - _iq iqAngle1R; - - _iq iqAngle2F; - _iq iqAngle2R; - - _iq iqAngleCalc; - -#endif + _iq iqAngleCalc; } WRotorValuesAngle; -#if (ENABLE_ROTOR_SENSOR_ZERO_SIGNAL==1) -#define WRotorValuesAngle_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -#else -#define WRotorValuesAngle_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -#endif +#define WRotorValuesAngle_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + extern WRotorValues WRotor; extern WRotorValuesAngle WRotorPBus; @@ -167,7 +113,7 @@ extern WRotorValuesAngle WRotorPBus; //#define NORMA_WROTOR 15 #define IQ_WROTOR_MAX_MIN_DELTA 3744914286 //17920 - +#define NORMA_ANGLE 360 #define WRMP_COEF 0.001 // 0.24 Hz per sec diff --git a/Inu/Src/main/vector.h b/Inu/Src/main/vector.h index 25bc4f1..5dd6bad 100644 --- a/Inu/Src/main/vector.h +++ b/Inu/Src/main/vector.h @@ -221,12 +221,6 @@ typedef struct unsigned int count_wait_after_kvitir; - unsigned int flag_record_log; - unsigned int count_step_ram_off; - unsigned int count_start_impuls; - - int flag_send_alarm_log_to_MPU; - } FLAG; @@ -240,10 +234,10 @@ typedef struct 0,0,0,0,0,0,0,0,0,0,\ 0,0,0,0,0,0,0,0,0,0,\ 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0\ + 0,0\ } extern FLAG f; -//extern WINDING a; +extern WINDING a; #ifdef __cplusplus } diff --git a/Inu/Src/.vscode/c_cpp_properties.json b/Inu/Src2/.vscode/c_cpp_properties.json similarity index 100% rename from Inu/Src/.vscode/c_cpp_properties.json rename to Inu/Src2/.vscode/c_cpp_properties.json diff --git a/Inu/Src2/551/main/PWMTools.c b/Inu/Src2/551/main/PWMTools.c deleted file mode 100644 index b62f7b3..0000000 --- a/Inu/Src2/551/main/PWMTools.c +++ /dev/null @@ -1,2438 +0,0 @@ -#include -#include -#include -#include -#include -#include //22.06 -#include -#include -#include -#include -//#include -#include -#include -#include //22.06 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "f281xpwm.h" - -//#include "SpaceVectorPWM.h" -#include "CAN_Setup.h" -#include "global_time.h" -#include "IQmathLib.h" -#include "mathlib.h" -#include "oscil_can.h" -#include "rmp_cntl_v1.h" -#include "uf_alg_ing.h" -#include "vhzprof.h" -#include "vector_control.h" -#include "MemoryFunctions.h" -#include "RS_Functions.h" -#include "TuneUpPlane.h" -#include "xp_write_xpwm_time.h" -#include "pwm_test_lines.h" -#include "detect_errors.h" -#include "modbus_table_v2.h" -#include "params_alg.h" -#include "v_rotor_22220.h" -#include "log_to_memory.h" -#include "log_params.h" -#include "limit_power.h" -#include "pwm_logs.h" -#include "optical_bus_tools.h" -#include "ramp_zadanie_tools.h" -#include "pll_tools.h" - - -///////////////////////////////////// -#if (_SIMULATE_AC==1) -#include "sim_model.h" -#endif - -//#pragma DATA_SECTION(freq1,".fast_vars1"); -//_iq freq1; - -//#pragma DATA_SECTION(k1,".fast_vars1"); -//_iq k1 = 0; - -#define ENABLE_LOG_INTERRUPTS 0 //1 - - -#if (ENABLE_LOG_INTERRUPTS) - -#pragma DATA_SECTION(log_interrupts,".slow_vars"); -#define MAX_COUNT_LOG_INTERRUPTS 100 -unsigned int log_interrupts[MAX_COUNT_LOG_INTERRUPTS+2] = {0}; - - - - -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// - - -void add_log_interrupts(int cmd) -{ - static int count_log_interrupst = 0; - - if (count_log_interrupst>=MAX_COUNT_LOG_INTERRUPTS) - count_log_interrupst = 0; - - - log_interrupts[count_log_interrupst++] = cmd; - log_interrupts[count_log_interrupst++] = EvbRegs.T3CNT; - - -//#if (ENABLE_LOG_INTERRUPTS) -// add_log_interrupts(0); -//#endif - -} - -#endif //if (ENABLE_LOG_INTERRUPTS) - - - -#pragma DATA_SECTION(iq_U_1_save,".fast_vars1"); -_iq iq_U_1_save = 0; -#pragma DATA_SECTION(iq_U_2_save,".fast_vars1"); -_iq iq_U_2_save = 0; - - -unsigned int enable_calc_vector = 0; - - - -//WINDING winding1 = WINDING_DEFAULT; - -//#define COUNT_SAVE_LOG_OFF 50 //Сколько тактов ШИМ сохранЯетсЯ после остановки -#define COUNT_START_IMP 5 //10 - -#define CONST_005 838860 -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - - -#pragma CODE_SECTION(global_time_interrupt,".fast_run2"); -void global_time_interrupt(void) -{ - -// inc_RS_timeout_cicle(); -// inc_CAN_timeout_cicle(); - -#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_18_ON; -#endif - - if (edrk.disable_interrupt_timer3) - return; - -//i_led1_on_off(1); - - - if (sync_data.latch_interrupt && sync_data.enabled_interrupt) - { - // перезапуск прерывания тут! - // для исключения дребезга - start_sync_interrupt(); - } - -#if (ENABLE_LOG_INTERRUPTS) - add_log_interrupts(1); -#endif - - global_time.calc(&global_time); - -#if (ENABLE_LOG_INTERRUPTS) - add_log_interrupts(101); -#endif - -/* -static unsigned int oldest_time = 0, time_pause = TIME_PAUSE_MODBUS_REMOUTE; -control_station_test_alive_all_control(); - if (detect_pause_milisec(time_pause,&oldest_time)) - modbusNetworkSharing(0); - - RS232_WorkingWith(0,1); -*/ - - -//i_led1_on_off(0); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - // PWM_LINES_TK_18_OFF; -#endif -} - -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -//#define get_tics_timer_pwm2(k) {time_buf2[k] = (EvbRegs.T3CNT-start_tics_4timer);k++;} -//unsigned int time_buf2[10] = {0}; - - -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -#define PAUSE_INC_TIMEOUT_CICLE 10 // FREQPWM/10 -void pwm_inc_interrupt(void) -{ - static unsigned int t_inc = 0; - - if (t_inc>=PAUSE_INC_TIMEOUT_CICLE) - { - inc_RS_timeout_cicle(); - inc_CAN_timeout_cicle(); - t_inc = 0; - } - else - t_inc++; -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(pwm_analog_ext_interrupt,".fast_run2"); -void pwm_analog_ext_interrupt(void) -{ -// static int count_timer_buf2=0, start_tics_4timer = 0, c_rms = 0; -// static _iq prev_Iu=0, prev_Ua=0; - //static _iq iq_50hz_norma = _IQ(50.0/NORMA_FROTOR); - -// i_led2_on(); - - // подготовка подсчета времени работы в прерывании -// start_tics_4timer = EvaRegs.T1CNT; - -// count_timer_buf2 = 0; -// get_tics_timer_pwm2(count_timer_buf2); - - if (edrk.SumSbor == 1) { -// detect_protect_adc(uf_alg.tetta_bs, uf_alg.tetta_bs); - } - - - - calc_pll_50hz(); - -// -// if (c_rms>=9) -// { -// edrk.test_rms_Iu = calc_rms(analog.iqIu,prev_Iu,edrk. f_stator); -// edrk.test_rms_Ua = calc_rms(analog.iqUin_A1B1,prev_Ua, iq_50hz_norma); -// -// prev_Iu = analog.iqIu; -// prev_Ua = analog.iqUin_A1B1; -// c_rms = 0; -// } -// else -// c_rms++; - -// fill_RMS_buff_interrupt(uf_alg.tetta_bs, uf_alg.tetta_bs); - - // get_tics_timer_pwm2(count_timer_buf2); -// i_led2_off(); - - -// global_time.calc(&global_time); - -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - -inline void init_regulators() -{ -// if(f.Mode != 0) -// { -//// pwm_vector_model_titov(0, 0, /*rotor.iqW*/0, 0); -// } -} - -#define select_working_channels(go_a, go_b) {go_a = !f.Obmotka1; \ - go_b = !f.Obmotka2;} - -#define MAX_COUNT_WAIT_GO_0 FREQ_PWM // 1 сек. - - -#define PAUSE_ERROR_DETECT_UPDATE_OPTBUS_DATA 900// ((unsigned int)(1*FREQ_PWM*2)) // ~1sec //50 -#define MAX_TIMER_WAIT_SET_TO_ZERO_ZADANIE 27000 //((unsigned int)(30*FREQ_PWM*2)) // 60 sec -//#define MAX_TIMER_WAIT_BOTH_READY2 108000 //(120*FREQ_PWM*2) // 120 sec -#define MAX_TIMER_WAIT_BOTH_READY2 216000 //(120*FREQ_PWM*2) // 240 sec -#define MAX_TIMER_WAIT_MASTER_SLAVE 4500 // 5 sec - -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -//#define _ENABLE_PWM_LED2_PROFILE 1 - - -#if (_ENABLE_PWM_LED2_PROFILE) -unsigned int profile_pwm[30]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; -unsigned int pos_profile_pwm = 0; -#endif - -/////////////////////////////////////////////////////////////////// -#define _ENABLE_LOG_TICS_PWM 0//1 -#define _ENABLE_SLOW_PWM 0//1 -#define _ENABLE_INTERRUPT_PWM_LED2 0//1 - -#if (_ENABLE_LOG_TICS_PWM==1) - -static int c_run=0; -static int c_run_start=0; -static int i_log; - - -#pragma DATA_SECTION(time_buf,".slow_vars"); -#define MAX_COUNT_TIME_BUF 50 -int time_buf[MAX_COUNT_TIME_BUF] = {0}; - -//#define get_tics_timer_pwm(flag,k) {if (flag) {time_buf[k] = (unsigned int)(EvbRegs.T3CNT-start_tics_4timer);k++;}else{time_buf[k] = -1; k++;}} - -#define set_tics_timer_pwm(flag,k) { time_buf[k] = flag;k++; } - -//#define get_tics_timer_pwm(flag,k) if (flag) ? {time_buf[k] = (EvbRegs.T3CNT-start_tics_4timer);k++;} : {time_buf[k] = -1; k++;}; -static int count_timer_buf=0; - -#else - -#define get_tics_timer_pwm(flag) asm(" NOP;") -#define set_tics_timer_pwm(flag,k) asm(" NOP;") -//static int count_timer_buf=0; - -#endif - - -#if(_ENABLE_SLOW_PWM) -static int slow_pwm_pause = 0; -#endif - -unsigned int count_time_buf = 0; -int stop_count_time_buf=0; -unsigned int log_wait; - -unsigned int end_tics_4timer, start_tics_4timer; -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -#if (_ENABLE_LOG_TICS_PWM==1) -//#pragma CODE_SECTION(get_tics_timer_pwm,".fast_run"); -void get_tics_timer_pwm(unsigned int flag) -{ - unsigned int delta; - - if (flag) - { - delta = (unsigned int)(EvbRegs.T3CNT-start_tics_4timer); - if (count_timer_buf>=3) - time_buf[count_timer_buf] = delta - time_buf[count_timer_buf-2]; - else - time_buf[count_timer_buf] = delta; - time_buf[count_timer_buf] = time_buf[count_timer_buf]*33/1000; - count_timer_buf++; - } - else - { - time_buf[count_timer_buf] = -1; - count_timer_buf++; - } -} -#else - -#endif - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////// -// получаем данные с датчика оборотов -/////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(calc_rotors,".fast_run"); -void calc_rotors(int flag) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_17_ON; -#endif - - update_rot_sensors(); - - - - set_tics_timer_pwm(6,count_timer_buf); - get_tics_timer_pwm(flag); - - -#if(C_cds_in_number>=1) - project.cds_in[0].read_pbus(&project.cds_in[0]); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_17_OFF; -#endif - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_19_ON; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - RotorMeasureDetectDirection(); - RotorMeasure();// измеритель -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - Rotor_measure_22220(); - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_19_OFF; -#endif - - set_tics_timer_pwm(7,count_timer_buf); - get_tics_timer_pwm(flag); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_ON; -#endif - -// RotorMeasurePBus(); -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow, &WRotorPBus.RotorDirectionSlow2, &WRotorPBus.RotorDirectionCount); -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) - // 22220 - // nothing -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_ON; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - select_values_wrotor(); -#endif -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - select_values_wrotor_22220(); - -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_20_OFF; -#endif - - set_tics_timer_pwm(8,count_timer_buf); - get_tics_timer_pwm(flag); - -#endif //(C_cds_in_number>=1) - - - edrk.rotor_direction = WRotor.RotorDirectionSlow; - -#if(SENSOR_ALG==SENSOR_ALG_23550) -// 23550 - edrk.iq_f_rotor_hz = WRotor.iqWRotorSumFilter; -#endif - -#if(SENSOR_ALG==SENSOR_ALG_22220) -// 22220 - edrk.iq_f_rotor_hz = WRotor.iqWRotorSum; -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(calc_zadanie_rampa,".fast_run"); -void calc_zadanie_rampa(void) -{ -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_19_ON; -#endif - - - // подхват при смене режима - load_current_ramp_oborots_power(); - - if (edrk.StartGEDfromControl==0) - ramp_all_zadanie(2); // форсируем в ноль - else - if (edrk.flag_wait_set_to_zero_zadanie || edrk.flag_block_zadanie || edrk.Status_Ready.bits.ready_final==0 || /*edrk.StartGEDfromControl==0 ||*/ edrk.run_razbor_shema == 1) - ramp_all_zadanie(1); // стремим рампы в ноль, ка ктолько они доедут в ноль, то снимается edrk.StartGEDfromZadanie - else - ramp_all_zadanie(0); // тут все по штатному - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_19_OFF; -#endif - -} - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -#pragma CODE_SECTION(async_pwm_ext_interrupt,".fast_run2"); -void async_pwm_ext_interrupt(void) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_19_ON; -#endif - if (edrk.run_to_pwm_async) - { - PWM_interrupt(); - edrk.run_to_pwm_async = 0; - } - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_19_OFF; -#endif - -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -void run_detect_fast_error(void) -{ - - detect_error_u_zpt_fast(); - detect_error_u_in(); - -} -//////////////////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(PWM_interrupt_main,".fast_run"); -void PWM_interrupt_main(void) -{ - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_16_ON; -#endif - - norma_adc_nc(0); - - edrk.run_to_pwm_async = 1; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) - PWM_LINES_TK_16_OFF; -#endif - -} -//////////////////////////////////////////////////////////////////////////////// - - -#define MAX_COUNT_COUNTSTARTGEDFROMZADANIE FREQ_PWM //3000 // задержка в тактах появления единицы в edrk.StartGEDfromZadanie - - - -#pragma CODE_SECTION(PWM_interrupt,".fast_run"); -void PWM_interrupt(void) -{ - - static unsigned int pwm_run = 0; - static _iq Uzad1=0, Fzad=0, Uzad2=0, Izad_out = 0, Uzad_from_master = 0; - -// static int count_step_ram_off = 0; -// static int count_start_impuls = 0; - - static int prevGo = -1; - static volatile unsigned int go_a = 0; - static volatile unsigned int go_b = 0; - - static int prev_go_a = 0; - static int prev_go_b = 0; - - static _iq iq_U_1_prev = 0; - static _iq iq_U_2_prev = 0; - static unsigned int prev_timer = 0; - unsigned int cur_timer; - static unsigned int count_lost_interrupt=0; - static int en_rotor = 1;//1; - - static unsigned long timer_wait_set_to_zero_zadanie = 0; - static unsigned long timer_wait_both_ready2 = 0; - - static unsigned int prev_error_controller = 0,error_controller=0; - - static unsigned long time_delta = 0; - - static unsigned int run_calc_uf = 0, prev_run_calc_uf = 0, count_wait_go_0 = 0; - - int pwm_enable_calc_main = 0, pwm_up_down = 0, err_interr = 0, slow_error = 0; - - static unsigned int count_err_read_opt_bus = 0, prev_edrk_Kvitir = 0; - - static unsigned int count_wait_read_opt_bus = 0, old_count_ok = 0, data_ready_optbus = 0, count_ok_read_opt_bus = 0; - -// static T_cds_optical_bus_data_in buff[25]={0}; - static unsigned int flag_last_error_read_opt_bus = 0, sum_count_err_read_opt_bus1=0; - - static unsigned int count_read_slave = 0, flag1_change_moment_read_optbus = 0, flag2_change_moment_read_optbus = 0; - - static unsigned int count_updated_sbus = 0, prev_ManualDischarge = 0; - - static unsigned int prev_flag_detect_update_optbus_data=0, flag_detect_update_optbus_data = 0, pause_error_detect_update_optbus_data = 0; - static unsigned int timer_wait_to_master_slave = 0; - static unsigned int prev_master = 0; - - static int pwm_enable_calc_main_log = 1; - - static int what_pwm = 0; - - int localStartGEDfromZadanie; - static unsigned int countStartGEDfromZadanie = 0; - - -// OPTICAL_BUS_CODE_STATUS optbus_status = {0}; - static STATUS_DATA_READ_OPT_BUS optbus_status; - _iq wd; - -// if (edrk.disable_interrupt_sync==0) -// start_sync_interrupt(); - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_16_ON; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_16_ON; -#endif - - - -#if (_ENABLE_INTERRUPT_PWM_LED2) -i_led2_on_off(1); -#endif - - if (edrk.disable_interrupt_pwm) - { - pwm_inc_interrupt(); - return; - } - - if (flag_special_mode_rs==1) - { - calc_norm_ADC_0(1); - calc_norm_ADC_1(1); - pwm_inc_interrupt(); - - return; - } - -#if (_ENABLE_PWM_LED2_PROFILE) - pos_profile_pwm = 0; -#endif - - - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - -// if (xpwm_time.what_next_interrupt==PWM_LOW_LEVEL_INTERRUPT) -// { -//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) -// PWM_LINES_TK_17_ON; -//#endif -// -// i_sync_pin_on(); -// -// } -// else -// { -//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) -// PWM_LINES_TK_17_OFF; -//#endif -// -// i_sync_pin_off(); -// } - - - -//////////////// -//PWN_COUNT_RUN_PER_INTERRUPT PWM_TWICE_INTERRUPT_RUN - err_interr = detect_level_interrupt(edrk.flag_second_PCH); - - if (err_interr) - edrk.errors.e3.bits.ERR_INT_PWM_LONG |=1; - - if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) - pwm_up_down = 2; - else - if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT) - { - pwm_up_down = 0; - } - else - pwm_up_down = 1; - - // sync line - if (pwm_up_down==2 || pwm_up_down==0) - { -// what_pwm = 0; - // i_sync_pin_on(); - calculate_sync_detected(); - } - -///////////////// -#if (ENABLE_LOG_INTERRUPTS) - add_log_interrupts(3); -#endif - - -#if (_ENABLE_LOG_TICS_PWM==1) - - count_timer_buf = 0; - // optical_read_data.timer=0; -#endif - - -#if (_FLOOR6==0) -// if (edrk.Stop==0) -// i_led1_on_off(1); -#else - // i_led1_on_off(1); -#endif - - - edrk.into_pwm_interrupt = 1; - - // подготовка подсчета времени работы в прерывании - start_tics_4timer = EvbRegs.T3CNT; - cur_timer = global_time.pwm_tics; - if (prev_timer>cur_timer) - { - if ((prev_timer-cur_timer)<2) - { -// stop_pwm(); - edrk.count_lost_interrupt++; - } - } - else - { - if ((cur_timer==prev_timer) || (cur_timer-prev_timer)>2) - { -// stop_pwm(); - edrk.count_lost_interrupt++; - } - } - prev_timer = cur_timer; - // закончили подготовку подсчета времени работы в прерывании - - set_tics_timer_pwm(1,count_timer_buf); - get_tics_timer_pwm(1); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_17_ON; -#endif - -#if (_SIMULATE_AC==1) - calc_norm_ADC_0_sim(0); -#else - calc_norm_ADC_0(0); // читаем АЦП а norma была запущена в Pwm_main() -#endif - run_detect_fast_error(); //быстрые защиты - - - - ///////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////// - if (edrk.Kvitir==0 && prev_edrk_Kvitir==1) - { - count_err_read_opt_bus = 0; - edrk.sum_count_err_read_opt_bus = 0; - } - - set_tics_timer_pwm(2,count_timer_buf); - get_tics_timer_pwm(1); - - ////////////////////////////// -// inc_RS_timeout_cicle(); - //////////////////////////////// - //////////////////////////////////////////// - //////////////////////////////////////////// -// inc_CAN_timeout_cicle(); - //////////////////////////////////////////// - - if (edrk.ms.another_bs_maybe_on==1 && - (edrk.auto_master_slave.local.bits.master || edrk.auto_master_slave.local.bits.slave) ) - { - - flag_detect_update_optbus_data = 1; - - if (prev_flag_detect_update_optbus_data == 0) - pause_error_detect_update_optbus_data = 0; - - - count_updated_sbus = optical_read_data.data_was_update_between_pwm_int; - - // даем задержку PAUSE_ERROR_DETECT_UPDATE_OPTBUS_DATA после входа в обмен по OPT_BUS - // после которой начинаем ловить ошибки по своевременному обновлению данных по OPT_BUS - if (pause_error_detect_update_optbus_data=1) -// project.cds_in[0].read_pbus(&project.cds_in[0]); -//#endif - -#if(C_cds_in_number>=2) - project.cds_in[1].read_pbus(&project.cds_in[1]); -#endif - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_17_OFF; -#endif - - - - set_tics_timer_pwm(10,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - if (pwm_run == 1) - { - // зашли в прерывание но почему-то мы уже были тут, повторный заход? - soft_stop_x24_pwm_all(); - edrk.errors.e9.bits.ERR_INT_PWM_VERY_LONG |=1; - } - else - { - pwm_run = 1; - -// detect_I_M_overload(); -// if (edrk.from_rs.bits.ACTIVE) -// edrk.Go = edrk.StartGEDRS; - -// project_read_errors_controller(); // чтение ADR_ERRORS_TOTAL_INFO - - if ( (edrk.errors.e0.all) - || (edrk.errors.e1.all) - || (edrk.errors.e2.all) - || (edrk.errors.e3.all) - || (edrk.errors.e4.all) - || (edrk.errors.e5.all) - || (edrk.errors.e6.all) - || (edrk.errors.e7.all) - || (edrk.errors.e8.all) - || (edrk.errors.e9.all) - || (edrk.errors.e10.all) - || (edrk.errors.e11.all) - || (edrk.errors.e12.all) - ) - edrk.Stop |= 1; - else - edrk.Stop = 0; - - - - project.read_errors_controller(); - error_controller = (project.controller.read.errors.all | project.controller.read.errors_buses.bit.slave_addr_error | project.controller.read.errors_buses.bit.count_error_pbus); -// project.controller.read.errors.all = error_controller; - - - - if(error_controller && prev_error_controller==0) - { - edrk.errors.e11.bits.ERROR_CONTROLLER_BUS |= 1; - svgen_set_time_keys_closed(&svgen_pwm24_1); - svgen_set_time_keys_closed(&svgen_pwm24_2); - - write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); - -// xerror(main_er_ID(1),(void *)0); - } - prev_error_controller = error_controller;//project.controller.read.errors.all; - - - if (pwm_enable_calc_main==0)// заходим в расчет только раз за период шима - вторая часть - { - - if (en_rotor) - { -#if (_SIMULATE_AC==1) -// calc_rotors_sim(); -#else - calc_rotors(pwm_enable_calc_main_log); // получаем данные с датчика оборотов -#endif - - - - } - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - calc_zadanie_rampa(); - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - calc_norm_ADC_1(1); // замер температур - - calc_power_full(); - - calc_all_limit_koeffs(); - - } - - ///////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////// - - - if (pwm_enable_calc_main)// заходим в расчет только раз за период шима - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_18_ON; -#endif - - if (edrk.Obmotka1 == 0) - go_a = 1; - else - go_a = 0; - - if (edrk.Obmotka2 == 0) - go_b = 1; - else - go_b = 0; - - ////////////////////////// - - if (optical_read_data.data.cmd.bit.start_pwm && edrk.auto_master_slave.local.bits.slave ) - edrk.StartGEDfromSyncBus = 1; - else - edrk.StartGEDfromSyncBus = 0; - - edrk.master_Uzad = _IQ15toIQ( optical_read_data.data.pzad_or_wzad); - edrk.master_theta = _IQ12toIQ( optical_read_data.data.angle_pwm); - edrk.master_Izad = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); - edrk.master_Iq = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); - - set_tics_timer_pwm(11,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - ///////////////////////// - - if ((edrk.auto_master_slave.local.bits.slave==1 && edrk.auto_master_slave.local.bits.master==0) - || (edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.master==1) ) - { - - if (edrk.auto_master_slave.local.bits.master != prev_master) - timer_wait_to_master_slave = 0; - - // после выбора ждем еще некоторое время. - if (timer_wait_to_master_slave>MAX_TIMER_WAIT_MASTER_SLAVE) - { - edrk.Status_Ready.bits.MasterSlaveActive = 1; - - if (edrk.auto_master_slave.local.bits.master) - edrk.MasterSlave = MODE_MASTER; - else - edrk.MasterSlave = MODE_SLAVE; - } - else - { - edrk.Status_Ready.bits.MasterSlaveActive = 0; - edrk.MasterSlave = MODE_DONTKNOW; - timer_wait_to_master_slave++; - } - prev_master = edrk.auto_master_slave.local.bits.master; - } - else - { - - edrk.Status_Ready.bits.MasterSlaveActive = 0; - edrk.MasterSlave = MODE_DONTKNOW; - - timer_wait_to_master_slave = 0; - } - - - set_tics_timer_pwm(12,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { - if (edrk.MasterSlave == MODE_MASTER) { - if (get_start_ged_from_zadanie()) { - edrk.prepare_stop_PWM = 0; - //edrk.StartGEDfromZadanie = 1; - localStartGEDfromZadanie = 1; - } else { - edrk.prepare_stop_PWM = 1; - if (edrk.k_stator1 < 41943) { //335544 ~ 2% - //edrk.StartGEDfromZadanie = 0; - localStartGEDfromZadanie = 0; - } - } - } else { - if (get_start_ged_from_zadanie()) { - //edrk.StartGEDfromZadanie = 1; - localStartGEDfromZadanie = 1; - } else { - if (edrk.k_stator1 < 41943) { //335544 ~ 2% - //edrk.StartGEDfromZadanie = 0; - localStartGEDfromZadanie = 0; - } - } - edrk.prepare_stop_PWM = optical_read_data.data.cmd.bit.prepare_stop_PWM; - } - } else { - //edrk.StartGEDfromZadanie = - localStartGEDfromZadanie = get_start_ged_from_zadanie(); - } - - // задержка прохождения localStartGEDfromZadanie=1 в edrk.StartGEDfromZadanie - if (localStartGEDfromZadanie && edrk.prevStartGEDfromZadanie==0) - { - if (countStartGEDfromZadanieMAX_TIMER_WAIT_BOTH_READY2) - edrk.errors.e1.bits.VERY_LONG_BOTH_READY2 |= 1; - else - timer_wait_both_ready2++; - - } - else - timer_wait_both_ready2 = 0; - - - if (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON - && optical_read_data.data.cmd.bit.ready_cmd == CODE_READY_CMD_READY2) // тот расцепитель включен или включился и тот БС собрался - { - edrk.flag_block_zadanie = 0; - edrk.flag_wait_set_to_zero_zadanie = 0; - } - - if (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_OFF - && optical_read_data.data.cmd.bit.ready_cmd == CODE_READY_CMD_READY1) // тот расцепитель выключен и схема на том БС разобрана - { - edrk.flag_block_zadanie = 0; - edrk.flag_wait_set_to_zero_zadanie = 0; - } - - - if (edrk.StartGEDfromZadanie==0 && edrk.flag_block_zadanie - && (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_REQUEST_AND_THIS_OFF)) - // разрешаем другому БС завести расцепитель - edrk.you_can_on_rascepitel = 1; - - - if (edrk.flag_wait_set_to_zero_zadanie) - { - if (timer_wait_set_to_zero_zadanie>MAX_TIMER_WAIT_SET_TO_ZERO_ZADANIE) - { - // другой БС запросил включения своего расцепителя, мы сбросили обороты и ждали пока тот БС соберет свою схему - // но этого не произошло!!!! - edrk.errors.e1.bits.ANOTHER_BS_NOT_ON_RASCEPITEL |= 1; - - } - else - timer_wait_set_to_zero_zadanie++; - - } - else - timer_wait_set_to_zero_zadanie = 0; - - - // если ошибка подключения, то обнуляем запрос на подключение. - if (edrk.errors.e1.bits.ANOTHER_BS_NOT_ON_RASCEPITEL) - edrk.flag_wait_set_to_zero_zadanie = 0; - - - edrk.StartGED = ((edrk.StartGEDfromControl==1) && (edrk.StartGEDfromZadanie==1) && (edrk.flag_block_zadanie==0)); - - - if (edrk.MasterSlave == MODE_MASTER) - { - edrk.GoWait = ( (edrk.StartGED ) && (edrk.Stop == 0) - && (project.controller.read.errors.all==0) && - (slow_error==0) && - (edrk.Status_Ready.bits.ready_final) - && edrk.Status_Ready.bits.MasterSlaveActive - && edrk.warnings.e9.bits.BREAKER_GED_ON==0 - ); - } - else - if (edrk.MasterSlave == MODE_SLAVE) - { - edrk.GoWait = ( (edrk.StartGED && edrk.StartGEDfromSyncBus) && (edrk.Stop == 0) - && (project.controller.read.errors.all==0) && - (slow_error==0) && - (edrk.Status_Ready.bits.ready_final) - && edrk.Status_Ready.bits.MasterSlaveActive - ); - } - else - edrk.GoWait = 0; - - // if (edrk.GoWait==0 && edrk.Go == 0 && - - - // исключаем дребезг сигнала edrk.Go - if (edrk.GoWait) - { - if (count_wait_go_0>=MAX_COUNT_WAIT_GO_0) - edrk.Go = edrk.GoWait; - else - { - edrk.Go = 0; - edrk.errors.e7.bits.VERY_FAST_GO_0to1 |=1; // ошибка! слишком быстро пришел повторный edrk.Go!!! - } - } - else - { - if (edrk.Go) - count_wait_go_0 = 0; - - edrk.Go = 0; - if (count_wait_go_0=(MAX_COUNT_TIME_BUF-1)) - count_time_buf = 0; - - log_wait = 0; - if (edrk.MasterSlave == MODE_MASTER) - log_wait |= 0x1; - if (edrk.MasterSlave == MODE_SLAVE) - log_wait |= 0x2; - if (edrk.StartGED) - log_wait |= 0x4; - if (edrk.Stop) - log_wait |= 0x8; - if (edrk.Status_Ready.bits.ready_final) - log_wait |= 0x10; - if (edrk.Status_Ready.bits.MasterSlaveActive) - log_wait |= 0x20; - if (edrk.GoWait) - log_wait |= 0x40; - if (edrk.Go) - log_wait |= 0x80; - if (project.controller.read.errors.all==0) - log_wait |= 0x100; - if (slow_error) - log_wait |= 0x200; - if (edrk.StartGEDfromSyncBus) - log_wait |= 0x400; - - - time_buf[count_time_buf] = log_wait; - - if (edrk.errors.e7.bits.VERY_FAST_GO_0to1) - stop_count_time_buf = 1; - } -*/ -#endif - - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_GO) - if (edrk.StartGEDfromSyncBus) - { - PWM_LINES_TK_17_ON; - } - else - { - PWM_LINES_TK_17_OFF; - } - - if (edrk.StartGEDfromZadanie) - { - PWM_LINES_TK_18_ON; - } - else - { - PWM_LINES_TK_18_OFF; - } - if (edrk.flag_block_zadanie) - { - PWM_LINES_TK_19_ON; - } - else - { - PWM_LINES_TK_19_OFF; - } - - if (edrk.StartGEDfromControl) - { - PWM_LINES_TK_16_ON; - } - else - { - PWM_LINES_TK_16_OFF; - } - -#endif - - - - set_tics_timer_pwm(15,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - ////////////////////////////////// - ////////////////////////////////// - - if(edrk.Go == 1) - { - if (edrk.Go != prevGo) - { - edrk.count_run++; -// clear_mem(FAST_LOG); -// count_start_impuls = 0; -// count_step = 0; - f.count_step_ram_off = COUNT_SAVE_LOG_OFF; -// count_step_run = 0; - - // set_start_mem(FAST_LOG); - // set_start_mem(SLOW_LOG); - - // logpar.start_write_fast_log = 1; - - init_uf_const(); - init_simple_scalar(); - - Fzad = 0; - Uzad1 = 0; - Uzad2 = 0; - - clear_logpar(); - } - else - { - - if (f.count_start_impuls < COUNT_START_IMP) - { - f.count_start_impuls++; - } - else - { - f.count_start_impuls = COUNT_START_IMP; - - f.flag_record_log = 1; - enable_calc_vector = 1; - - } - - } - } - else // (edrk.Go == 0) - { - - if (f.count_step_ram_off > 0) - { - f.count_step_ram_off--; - f.flag_record_log = 1; - } else { - f.flag_record_log = 0; - } - - // ручной разряд - if (edrk.ManualDischarge && prev_ManualDischarge!=edrk.ManualDischarge) - edrk.Discharge = 1; - - prev_ManualDischarge =edrk.ManualDischarge; - - if (f.count_start_impuls == 0) - { - - if (edrk.Discharge || (edrk.ManualDischarge ) ) - { - break_resistor_managment_calc(); - soft_start_x24_break_1(); - } - else - { - - if (f.count_step_ram_off > 0) - { - break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); - // soft_start_x24_break_1(); - } - else - { - // это произойдет только на последнем такте выключения - soft_stop_x24_pwm_all(); - - } - } - - } - - set_tics_timer_pwm(16,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - if (f.count_start_impuls==COUNT_START_IMP) - { - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) - { - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } - - vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, - edrk.Mode_ScalarVectorUFConst, - edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, - edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, - &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, - 0, 1); - - test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, - filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.Uzad_to_slave); - analog.PowerFOC = edrk.P_to_master; - Fzad = vect_control.iqFstator; - Izad_out = edrk.Iq_to_slave; - } else { - test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, - 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, - 1, - edrk.Uzad_max, - edrk.master_theta, - edrk.master_Uzad, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.tetta_to_slave, - &edrk.Uzad_to_slave); - } - } - else - { - if (f.count_start_impuls==COUNT_START_IMP-1) - { - - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) - { - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } - - vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, - edrk.Mode_ScalarVectorUFConst, - edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, - edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, - &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, - 0, 1); - - test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, - filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.Uzad_to_slave); - analog.PowerFOC = edrk.P_to_master; - Fzad = vect_control.iqFstator; - Izad_out = edrk.Iq_to_slave; - } else { - test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, - 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, - 1, - edrk.Uzad_max, - edrk.master_theta, - edrk.master_Uzad, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.tetta_to_slave, - &edrk.Uzad_to_slave); - } - - } - else - { - if (f.count_start_impuls==COUNT_START_IMP-2) - { - // тут опять middle состояние перед выключением ключей -// svgen_set_time_keys_closed(&svgen_pwm24_1); -// svgen_set_time_keys_closed(&svgen_pwm24_2); - svgen_set_time_middle_keys_open(&svgen_pwm24_1); - svgen_set_time_middle_keys_open(&svgen_pwm24_2); - } - else - // а тут мы уже выключились - { - svgen_set_time_keys_closed(&svgen_pwm24_1); - svgen_set_time_keys_closed(&svgen_pwm24_2); - } - - Fzad = 0; - - } - } - - - if (f.count_start_impuls > 0) { - f.count_start_impuls -= 1; - } else { - f.count_start_impuls = 0; - } - enable_calc_vector = 0; - - - - Uzad1 = 0; - Uzad2 = 0; - - } // end if Go==1 - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_18_OFF; -#endif - - - } // end pwm_enable_calc_main one interrupt one period only - -/* - * - // if ((m.m0.bit.EnableGoA == 1) && (f.Obmotka1 == 0)) - - - // if ((m.m0.bit.EnableGoB == 1) && (f.Obmotka2 == 0)) - if (f.Obmotka2 == 0) - { - go_b = 1; - } - else - { - go_b = 0; - } - - if (go_a == 0 && prev_go_a != go_a) - { - //отключаем 1 обмотку - soft_stop_x24_pwm_1(); - } - - if (go_a == 1 && prev_go_a != go_a) - { - //включаем 1 обмотку - soft_start_x24_pwm_1(); - } - - if (go_b == 0 && prev_go_b != go_b) - { - //отключаем 2 обмотку - soft_stop_x24_pwm_2(); - } - - if (go_b == 1 && prev_go_b != go_b) - { - //включаем 2 обмотку - soft_start_x24_pwm_2(); - } - - prev_go_a = go_a; - prev_go_b = go_b; - * - * - */ - - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - - if (pwm_enable_calc_main) // заходим в расчет только раз за период шима - { - - - if (f.count_start_impuls==1 && edrk.Go==1) - { - // а тут мы еше не включились - svgen_set_time_keys_closed(&svgen_pwm24_1); - svgen_set_time_keys_closed(&svgen_pwm24_2); - // soft_start_x24_pwm_1_2(); - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } - vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, - edrk.Mode_ScalarVectorUFConst, - edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, - edrk.master_theta, edrk.master_Iq, edrk.P_from_slave, - &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, 1, edrk.prepare_stop_PWM); - } - } - - if (f.count_start_impuls==2 && edrk.Go==1) - { - // включаем ШИМ - if (go_a == 1 && go_b == 1) { - // start_pwm(); должен вызваться один раз за изменение edrk.Go - soft_start_x24_pwm_1_2(); - } else if (go_a == 1) { - soft_start_x24_pwm_1(); - } else if (go_b == 1) { - soft_start_x24_pwm_2(); - } - - // enable work break -#if (DISABLE_WORK_BREAK==1) - -#else -// if (edrk.disable_break_work==0) - { - soft_start_x24_break_1(); - } -#endif - - } // end if (count_start_impuls==5) - - - if (f.count_start_impuls==3 && edrk.Go==1) - { - // готовимся разрешить ШИМ - svgen_set_time_middle_keys_open(&svgen_pwm24_1); - svgen_set_time_middle_keys_open(&svgen_pwm24_2); - } - - - - if (f.count_start_impuls==4 && edrk.Go==1) - { - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) - { - -// void simple_scalar(int n_alg, int n_wind_pump, _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, _iq fzad_provorot, -// _iq iqIm_1, _iq iqIm_2, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, -// _iq *Fz, _iq *Uz1) - - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } - - vectorControlConstId(0, 0, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, - edrk.Mode_ScalarVectorUFConst, - edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, - edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, - &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, - 0, edrk.prepare_stop_PWM); - - test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, - filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.Uzad_to_slave); - Fzad = vect_control.iqFstator; - Izad_out = edrk.Iq_to_slave; - } else { - test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, - 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.master_theta, - edrk.master_Uzad, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); - - - simple_scalar(1,0, WRotor.RotorDirectionSlow, - WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter, - 0, - 0, - 0, edrk.iq_bpsi_normal, - 0, - // analog.iqU_1_long+analog.iqU_2_long, - edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, - 0, - edrk.zadanie.iq_power_zad_rmp, 0, - edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, - 0,0, edrk.count_bs_work+1, - &Fzad, &Uzad1, &Uzad2, &Izad_out); - } - - } - - if (f.count_start_impuls == COUNT_START_IMP && edrk.Go==1) - { - if (pwm_enable_calc_main) // заходим в расчет только раз за период шима - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_21_ON; -#endif - - - //break_resistor_recup_calc(edrk.zadanie.iq_ZadanieU_Charge); - break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); - - set_tics_timer_pwm(17,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - run_calc_uf = 1; - - // основная работа тут, ШИМ уже включен в middle - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_UF_CONST) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - uf_const(&Fzad,&Uzad1,&Uzad2); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - - test_calc_simple_dq_pwm24_Ing(Fzad, - Uzad1, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance, - edrk.zadanie.iq_k_u_disbalance, - filter.iqU_1_fast, - filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.master_theta, - edrk.master_Uzad, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, - &edrk.tetta_to_slave, - &edrk.Uzad_to_slave); -// rmp_freq.DesiredInput = alg_pwm24.freq1; -// rmp_freq.calc(&rmp_freq); -// Fzad = rmp_freq.Out; -// -// vhz1.Freq = Fzad; -// vhz1.calc(&vhz1); -// -// -// Uzad1 = alg_pwm24.k1; -// Uzad2 = alg_pwm24.k1; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - - // test_calc_pwm24(Uzad1, Uzad2, Fzad); - // analog_dq_calc_const(); - - } // end ALG_MODE_UF_CONST - else - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - simple_scalar(1, - 0, - WRotor.RotorDirectionSlow, - WRotor.iqWRotorSumFilter, //rotor_22220.iqFlong * rotor_22220.direct_rotor; - WRotor.iqWRotorSumFilter, //rotor_22220.iqFout * rotor_22220.direct_rotor; - //0, 0, - edrk.zadanie.iq_oborots_zad_hz_rmp, - edrk.all_limit_koeffs.sum_limit, - edrk.zadanie.iq_Izad_rmp, - edrk.iq_bpsi_normal, - analog.iqIm, -// analog.iqU_1_long+analog.iqU_2_long, - edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, - analog.iqIin_sum, - edrk.zadanie.iq_power_zad_rmp, - edrk.iq_power_kw_full_znak,//(filter.PowerScalar+edrk.iq_power_kw_another_bs), - edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, - edrk.master_Izad, - edrk.MasterSlave, - edrk.count_bs_work+1, - &Fzad, - &Uzad1, - &Uzad2, - &Izad_out); - - set_tics_timer_pwm(18,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - - - - if (edrk.cmd_disable_calc_km_on_slave) - Uzad_from_master = edrk.master_Uzad; - else - { -#if (DISABLE_CALC_KM_ON_SLAVE==1) - Uzad_from_master = edrk.master_Uzad; -#else - Uzad_from_master = Uzad1; -#endif - - } - - test_calc_simple_dq_pwm24_Ing(Fzad, Uzad1, edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance, edrk.zadanie.iq_k_u_disbalance, filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.master_theta, - Uzad_from_master, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - - set_tics_timer_pwm(19,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } - - analog_dq_calc_external(wd, uf_alg.tetta); - - } // end ALG_MODE_SCALAR_OBOROTS - else - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) - { - -// void simple_scalar(int n_alg, int n_wind_pump, _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, _iq fzad_provorot, -// _iq iqIm_1, _iq iqIm_2, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, -// _iq *Fz, _iq *Uz1) - - if (edrk.flag_second_PCH == 0) { - wd = uf_alg.winding_displacement_bs1; - } else { - wd = uf_alg.winding_displacement_bs2; - } -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, - edrk.Mode_ScalarVectorUFConst, - edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, - edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, - &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, - 0, edrk.prepare_stop_PWM); -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_ON; -#endif - - test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, - edrk.disable_alg_u_disbalance, - edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, - filter.iqU_1_fast, filter.iqU_2_fast, - 0, - edrk.Uzad_max, - edrk.MasterSlave, - edrk.flag_second_PCH, - &edrk.Kplus, &edrk.Uzad_to_slave); - - analog.PowerFOC = edrk.P_to_master; - Fzad = vect_control.iqFstator; - Izad_out = edrk.Iq_to_slave; - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_20_OFF; -#endif - } // end ALG_MODE_FOC_OBOROTS - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_21_OFF; -#endif - - } // end pwm_enable_calc_main - - } // end (count_start_impuls == COUNT_START_IMP && edrk.Go==1) - else - { - run_calc_uf = 0; - if (pwm_enable_calc_main) // заходим в расчет только раз за период шима - { - - } - svgen_pwm24_1.Ta_imp = 0; - svgen_pwm24_1.Tb_imp = 0; - svgen_pwm24_1.Tc_imp = 0; - svgen_pwm24_2.Ta_imp = 0; - svgen_pwm24_2.Tb_imp = 0; - svgen_pwm24_2.Tc_imp = 0; - - } // end else (count_start_impuls == COUNT_START_IMP && edrk.Go==1) - - prevGo = edrk.Go; - - - - ////////////////////////////////// - optical_write_data.data.cmd.bit.start_pwm = edrk.Go; - optical_write_data.data.cmd.bit.prepare_stop_PWM = edrk.prepare_stop_PWM; - - optical_write_data.data.angle_pwm = _IQtoIQ12(edrk.tetta_to_slave + vect_control.add_tetta); - optical_write_data.data.pzad_or_wzad = _IQtoIQ15(edrk.Uzad_to_slave); - optical_write_data.data.iq_zad_i_zad = _IQtoIQ15(edrk.Izad_out); - - optical_bus_update_data_write(); - - set_tics_timer_pwm(20,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - - if (edrk.ms.another_bs_maybe_on==1 && edrk.auto_master_slave.local.bits.master) - { - // i_led2_on(); - } - - ////////////////////////////////// - ////////////////////////////////// - - edrk.Izad_out = Izad_out; - - if (edrk.MasterSlave==MODE_SLAVE) - { - edrk.f_stator = Fzad; - edrk.k_stator1 = edrk.Uzad_to_slave;//Uzad1; - edrk.k_stator2 = edrk.Uzad_to_slave;//Uzad2; - - } - else - if (edrk.MasterSlave==MODE_MASTER) - { - edrk.f_stator = Fzad; - edrk.k_stator1 = edrk.Uzad_to_slave;//Uzad1; - edrk.k_stator2 = edrk.Uzad_to_slave; - } - else - { - edrk.f_stator = 0; - edrk.k_stator1 = 0; - edrk.k_stator2 = 0; - } - - } // end pwm_enable_calc_main - - - - - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - /////////////////////////////////////////// - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_22_ON; -#endif - - if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) - write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); - else - { - if (edrk.Go==1) - { - if (f.count_start_impuls==COUNT_START_IMP-1) - { - if (pwm_enable_calc_main) - write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_HIGH); - else - write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_LOW); - } - else -// if (pwm_enable_calc_main) - write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); - } - else - { - if (f.count_start_impuls==COUNT_START_IMP-3) - { - if (pwm_enable_calc_main) - write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_HIGH); - else - write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_LOW); - - } - else - write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); - } - - - - // if (pwm_enable_calc_main) - // prev_run_calc_uf = run_calc_uf; - - - - } -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_22_OFF; -#endif - - - set_tics_timer_pwm(21,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - - // test write oscil buf - - if ( pwm_enable_calc_main==0) // заходим в расчет только раз за период шима - { - - run_write_logs(); - - } - - - // i_led2_on(); - // - if (edrk.SumSbor == 1) { - detect_protect_adc(uf_alg.tetta_bs, uf_alg.tetta_bs); - //// get_tics_timer_pwm(pwm_enable_calc_main,count_timer_buf); - } - - // fill_RMS_buff_interrupt(uf_alg.tetta_bs, uf_alg.tetta_bs); - - set_tics_timer_pwm(24,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - - // out_I_over_1_6.calc(&out_I_over_1_6); - // i_led2_off(); - - - pwm_run = 0; - - - } // end if pwm_run==1 - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif - - if (pwm_enable_calc_main==0) // заходим в расчет только раз за период шима - { - - - // pwm_analog_ext_interrupt(); - -// inc_RS_timeout_cicle(); -// inc_CAN_timeout_cicle(); - -#if (_SIMULATE_AC==1) - sim_model_execute(); -#endif - - } - - pwm_analog_ext_interrupt(); - pwm_inc_interrupt(); - - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_ON; -#endif - - - - - set_tics_timer_pwm(25,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - - -#if (_ENABLE_SLOW_PWM) -// pause_1000(slow_pwm_pause); -#endif - - set_tics_timer_pwm(26,count_timer_buf); - get_tics_timer_pwm(pwm_enable_calc_main_log); - -///////////////////////////////////////////////// - // считаем время работы в прерывании - end_tics_4timer = EvbRegs.T3CNT; - - if (end_tics_4timer>start_tics_4timer) - { - time_delta = (end_tics_4timer - start_tics_4timer); - time_delta = time_delta * 33/1000; - if (pwm_enable_calc_main) - edrk.period_calc_pwm_int1 = time_delta;//(end_tics_4timer - start_tics_4timer)*33/1000; - else - edrk.period_calc_pwm_int2 = time_delta;//(end_tics_4timer - start_tics_4timer)*33/1000; - } - // закончили считать время работы в прерывании - ///////////////////////////////////////////////// - - // get_tics_timer_pwm(pwm_enable_calc_main,count_timer_buf); - - - - - -#if (_ENABLE_LOG_TICS_PWM==1) - - for (i_log=count_timer_buf;i_log=10000) - c_run=c_run_start; - else - c_run++; -#endif - -#if (ENABLE_LOG_INTERRUPTS) - add_log_interrupts(103); -#endif - - - -// i_sync_pin_off(); - edrk.into_pwm_interrupt = 0; - -#if (_ENABLE_INTERRUPT_PWM_LED2) -i_led2_on_off(0); -#endif - - - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - // PWM_LINES_TK_16_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_16_OFF; -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_16_OFF; -#endif - - -#if (_ENABLE_PWM_LED2_PROFILE) - i_led2_on_off(0); - if (pwm_enable_calc_main==0) - profile_pwm[pos_profile_pwm] = 2; -#endif - - -} -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// - - - -#pragma CODE_SECTION(fix_pwm_freq_synchro_ain,".fast_run"); -void fix_pwm_freq_synchro_ain(void) -{ - unsigned int new_freq; - static unsigned int delta_freq = 1; -// if (f.Sync_input_or_output == SYNC_INPUT) - { - sync_inc_error(); - - if (sync_data.disable_sync || sync_data.timeout_sync_signal == 1 || sync_data.enable_do_sync == 0) - { - - new_freq = xpwm_time.pwm_tics; - i_WriteMemory(ADR_PWM_PERIOD, new_freq); - - return; - } - - if (sync_data.pwm_freq_plus_minus_zero==1) - { - - - //Increment xtics - new_freq = xpwm_time.pwm_tics + delta_freq; - i_WriteMemory(ADR_PWM_PERIOD, new_freq); // Saw period in tics. 1 tic = 16.67 nsec - - // change_freq_pwm(VAR_FREQ_PWM_XTICS); - - - } - - if (sync_data.pwm_freq_plus_minus_zero==-1) - { - //4464 - //Decrement xtics - new_freq = xpwm_time.pwm_tics - delta_freq; - i_WriteMemory(ADR_PWM_PERIOD, new_freq); // Saw period in tics. 1 tic = 16.67 nsec - - // change_freq_pwm(VAR_FREQ_PWM_XTICS); - - } - - if (sync_data.pwm_freq_plus_minus_zero==0) - { - new_freq = xpwm_time.pwm_tics; - i_WriteMemory(ADR_PWM_PERIOD, new_freq); - // change_freq_pwm(VAR_FREQ_PWM_XTICS); - } - - } - - - -} - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// - -/* -void slow_vector_update() -{ - _iq iqKzad = 0; - - freq1 = _IQ (f.fzad/F_STATOR_MAX);//f.iqFRotorSetHz; - iqKzad = _IQ(f.kzad); - k1 = zad_intensiv_q(20000, 20000, k1, iqKzad); - -} -*/ - -void detect_work_revers(int direction, _iq fzad, _iq frot) -{ - static int prev_revers = 0; - int flag_revers; - // ограничение при рекуперации - if (direction == -1 && fzad > 0) - { - flag_revers = 1; - } - else - if (direction == 1 && fzad < 0) - { - flag_revers = 1; - } - else - { - flag_revers = 0; - } - - if (flag_revers && prev_revers==0) - edrk.count_revers++; - - prev_revers = flag_revers; - -} - - -void calc_power_full(void) -{ - _iq power_full_abs, power_one_abs, power_full_abs_f, power_one_abs_f; - - // - power_one_abs = _IQabs(filter.PowerScalar); - power_one_abs_f = _IQabs(filter.PowerScalarFilter2); - power_full_abs = power_one_abs + _IQabs(edrk.iq_power_kw_another_bs); - power_full_abs_f = power_one_abs_f + _IQabs(edrk.iq_power_kw_another_bs); - - if (edrk.oborots>=0) - { - edrk.iq_power_kw_full_znak = power_full_abs; - edrk.iq_power_kw_one_znak = power_one_abs; - edrk.iq_power_kw_full_filter_znak = power_full_abs_f; - edrk.iq_power_kw_one_filter_znak = power_one_abs_f; - } - else - { - edrk.iq_power_kw_full_znak = -power_full_abs; - edrk.iq_power_kw_one_znak = -power_one_abs; - edrk.iq_power_kw_full_filter_znak = -power_full_abs_f; - edrk.iq_power_kw_one_filter_znak = -power_one_abs_f; - } - - edrk.iq_power_kw_full_abs = power_full_abs; - edrk.iq_power_kw_one_abs = power_one_abs; - edrk.iq_power_kw_full_filter_abs = power_full_abs_f; - edrk.iq_power_kw_one_filter_abs = power_one_abs_f; - -} diff --git a/Inu/Src2/551/main/PWMTools.h b/Inu/Src2/551/main/PWMTools.h deleted file mode 100644 index 67f30b2..0000000 --- a/Inu/Src2/551/main/PWMTools.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef PWMTOOLS_H -#define PWMTOOLS_H -#include -#include - - -////////////////////////////////////////////////// -////////////////////////////////////////////////// -////////////////////////////////////////////////// - - -void InitPWM(void); -void PWM_interrupt(void); -void PWM_interrupt_main(void); - - - -void stop_wdog(void); -void start_wdog(void); - - -void global_time_interrupt(void); -void optical_bus_read_write_interrupt(void); -void pwm_analog_ext_interrupt(void); -void pwm_inc_interrupt(void); - -void fix_pwm_freq_synchro_ain(void); -void async_pwm_ext_interrupt(void); - - - -void calc_rotors(int flag); - -void detect_work_revers(int direction, _iq fzad, _iq frot); - -void calc_power_full(void); - - - -////////////////////////////////////////////////// -////////////////////////////////////////////////// -////////////////////////////////////////////////// -////////////////////////////////////////////////// - -extern PWMGEND pwmd; - -//extern int var_freq_pwm_xtics; -//extern int var_period_max_xtics; -//extern int var_period_min_xtics; - - - -#endif //PWMTOOLS_H - diff --git a/Inu/Src2/551/main/adc_tools.c b/Inu/Src2/551/main/adc_tools.c deleted file mode 100644 index 80b3b8d..0000000 --- a/Inu/Src2/551/main/adc_tools.c +++ /dev/null @@ -1,1412 +0,0 @@ -#include "DSP281x_Examples.h" // DSP281x Examples Include File -#include "DSP281x_Device.h" // DSP281x Headerfile Include File -#include "IQmathLib.h" - -#include -#include -#include -#include -#include - -#include "mathlib.h" -#include "filter_v1.h" -#include "xp_project.h" - -//#include "spartan_tools.h" - - - -//#define LOG_ACP_TO_BUF 1 - -#ifdef LOG_ACP_TO_BUF - -#define SIZE_BUF_LOG_ACP 500 -#pragma DATA_SECTION(BUF_ADC,".slow_vars") -int BUF_ADC[SIZE_BUF_LOG_ACP]; -#pragma DATA_SECTION(BUF_ADC_2,".slow_vars") -int BUF_ADC_2[SIZE_BUF_LOG_ACP]; - -#endif - - - -#if (USE_INTERNAL_ADC==1) - -#if(C_adc_number==1) -unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0,R_ADC_DEFAULT_INTERNAL }; -unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_INTERNAL}; -float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_INTERNAL}; -#endif -#if(C_adc_number==2) -unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1,R_ADC_DEFAULT_INTERNAL }; -unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_INTERNAL }; -float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_INTERNAL }; -#endif -#if(C_adc_number==3) -unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2,R_ADC_DEFAULT_INTERNAL }; -unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2, K_LEM_ADC_DEFAULT_INTERNAL }; -float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2, NORMA_ADC_DEFAULT_INTERNAL }; -#endif - -#else - -#if(C_adc_number==1) -#pragma DATA_SECTION(R_ADC,".slow_vars") -unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0 }; -#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") -unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0}; -#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") -float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0}; -#endif -#if(C_adc_number==2) -#pragma DATA_SECTION(R_ADC,".slow_vars") -unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1 }; -#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") -unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1 }; -#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") -float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1 }; -#endif -#if(C_adc_number==3) -#pragma DATA_SECTION(R_ADC,".slow_vars") -unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2 }; -#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") -unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2 }; -#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") -float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2 }; -#endif - -#endif - -//unsigned int const R_ADC_1[16] = R_ADC_DEFAULT_1; -//unsigned int const K_LEM_ADC_1[16] = K_LEM_ADC_DEFAULT_1; - - - - -#if (USE_INTERNAL_ADC==1) -int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; -#else - -#if(C_adc_number==1) -int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; -#endif -#if(C_adc_number==2) -int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; -#endif -#if(C_adc_number==3) -int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; -#endif - -#endif - - -#pragma DATA_SECTION(ADC_f,".fast_vars"); -int ADC_f[COUNT_ARR_ADC_BUF][16]; - -#pragma DATA_SECTION(ADC_fast,".fast_vars"); -int ADC_fast[COUNT_ARR_ADC_BUF][16][COUNT_ARR_ADC_BUF_FAST_POINT]; - - -#pragma DATA_SECTION(ADC_sf,".fast_vars"); -int ADC_sf[COUNT_ARR_ADC_BUF][16]; - -#pragma DATA_SECTION(analog,".fast_vars"); -ANALOG_VALUE analog = ANALOG_VALUE_DEFAULT; - -#pragma DATA_SECTION(filter,".fast_vars"); -ANALOG_VALUE filter = ANALOG_VALUE_DEFAULT; - -#pragma DATA_SECTION(analog_zero,".fast_vars"); -ANALOG_VALUE analog_zero = ANALOG_VALUE_DEFAULT; - - - -unsigned int const level_err_ADC_PLUS[16] = level_err_ADC_PLUS_default; -unsigned int const level_err_ADC_MINUS[16] = level_err_ADC_MINUS_default; - - -#pragma DATA_SECTION(err_adc_protect,".fast_vars"); -#pragma DATA_SECTION(mask_err_adc_protect,".fast_vars"); -ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF],mask_err_adc_protect[COUNT_ARR_ADC_BUF]; - - - -_iq koef_Im_filter=0; -_iq koef_Power_filter=0; -_iq koef_Power_filter2=0; - -#pragma DATA_SECTION(k_norm_ADC,".slow_vars") -_iq19 k_norm_ADC[COUNT_ARR_ADC_BUF][16]; - -#pragma DATA_SECTION(iq19_zero_ADC,".fast_vars"); -_iq19 iq19_zero_ADC[COUNT_ARR_ADC_BUF][16]; - - -#pragma DATA_SECTION(zero_ADC,".slow_vars") -int zero_ADC[COUNT_ARR_ADC_BUF][16]; - - -#pragma DATA_SECTION(iq19_k_norm_ADC,".fast_vars"); -_iq19 iq19_k_norm_ADC[COUNT_ARR_ADC_BUF][16]; - -#pragma DATA_SECTION(iq_norm_ADC,".fast_vars"); -_iq iq_norm_ADC[COUNT_ARR_ADC_BUF][16]; - -#pragma DATA_SECTION(iq_norm_ADC_sf,".fast_vars"); -_iq iq_norm_ADC_sf[COUNT_ARR_ADC_BUF][16]; - - -#pragma DATA_SECTION(koef_Uzpt_long_filter,".fast_vars"); -_iq koef_Uzpt_long_filter=0; - -#pragma DATA_SECTION(koef_Uzpt_fast_filter,".fast_vars"); -_iq koef_Uzpt_fast_filter=0; - -#pragma DATA_SECTION(koef_Uin_filter,".fast_vars"); -_iq koef_Uin_filter=0; - - -void fast_detect_protect_ACP(); -//void fast_read_all_adc_one(int cc); -//void fast_read_all_adc_more(void); - - -#if (USE_INTERNAL_ADC==1) -#pragma CODE_SECTION(adc_isr,".fast_run"); -interrupt void adc_isr(void) -{ -// unsigned char k; - static char l_ir=0; - static char step_acp=0; - -//i_led1_on_off(1); - -// i_led1_on_off(1); - - project.adc->read_pbus(&project.adc[0]); - - ADC_f[0][0] = project.adc[0].read.pbus.adc_value[0]; - ADC_f[0][1] = project.adc[0].read.pbus.adc_value[1]; - ADC_f[0][2] = project.adc[0].read.pbus.adc_value[2]; - ADC_f[0][3] = project.adc[0].read.pbus.adc_value[3]; - ADC_f[0][4] = project.adc[0].read.pbus.adc_value[4]; - ADC_f[0][5] = project.adc[0].read.pbus.adc_value[5]; - ADC_f[0][6] = project.adc[0].read.pbus.adc_value[6]; - ADC_f[0][7] = project.adc[0].read.pbus.adc_value[7]; - ADC_f[0][8] = project.adc[0].read.pbus.adc_value[8]; - ADC_f[0][9] = project.adc[0].read.pbus.adc_value[9]; - ADC_f[0][10] = project.adc[0].read.pbus.adc_value[10]; - ADC_f[0][11] = project.adc[0].read.pbus.adc_value[11]; - ADC_f[0][12] = project.adc[0].read.pbus.adc_value[12]; - ADC_f[0][13] = project.adc[0].read.pbus.adc_value[13]; - ADC_f[0][14] = project.adc[0].read.pbus.adc_value[14]; - ADC_f[0][15] = project.adc[0].read.pbus.adc_value[15]; - - - ADC_sf[0][0] += (ADC_f[0][0] - ADC_sf[0][0]) >> Shift_Filter; - ADC_sf[0][1] += (ADC_f[0][1] - ADC_sf[0][1]) >> Shift_Filter; - ADC_sf[0][2] += (ADC_f[0][2] - ADC_sf[0][2]) >> Shift_Filter; - ADC_sf[0][3] += (ADC_f[0][3] - ADC_sf[0][3]) >> Shift_Filter; - - -/* - - - if (ADC_sf[2][0]>ERR_LEVEL_ADC_PLUS || ADC_sf[2][0]ERR_LEVEL_ADC_PLUS || ADC_sf[2][1]ERR_LEVEL_ADC_PLUS || ADC_f[2]ERR_LEVEL_ADC_PLUS || ADC_sf[2][3]ERR_LEVEL_ADC_PLUS || ADC_f[8]ERR_LEVEL_ADC_PLUS || ADC_f[9]ERR_LEVEL_ADC_PLUS || ADC_f[10]ERR_LEVEL_ADC_PLUS_6 || ADC_f[2][11]maxU) maxU = buf_U1_3point[1]; -// if (buf_U1_3point[2]>maxU) maxU = buf_U1_3point[2]; -// -// if (buf_U1_3point[1]= component_Ready) - detect_zero_analog(i); - } - -// zero_ADC[1][2] = 2010;//1976; // uab -// zero_ADC[1][3] = 2010;//1989; // ubc -// zero_ADC[1][4] = 2010;//1994; // uca - - - zero_ADC[0][0]=zero_ADC[0][2];//2042;//1992;//1835; //uzpt - zero_ADC[0][1]=zero_ADC[0][2];//2042;//1992;//1835; //uzpt - - - -#if (COUNT_ARR_ADC_BUF>1) - zero_ADC[1][1]=zero_ADC[1][15]; - zero_ADC[1][2]=zero_ADC[1][15]; - zero_ADC[1][3]=zero_ADC[1][15]; - zero_ADC[1][4]=zero_ADC[1][15]; - zero_ADC[1][5]=zero_ADC[1][15]; - zero_ADC[1][6]=zero_ADC[1][15]; - zero_ADC[1][7]=zero_ADC[1][15]; - zero_ADC[1][8]=zero_ADC[1][15]; - zero_ADC[1][9]=zero_ADC[1][15]; - zero_ADC[1][10]=zero_ADC[1][15]; - zero_ADC[1][11]=zero_ADC[1][15]; - zero_ADC[1][12]=zero_ADC[1][15]; - zero_ADC[1][13]=zero_ADC[1][15]; - zero_ADC[1][14]=zero_ADC[1][15]; -#endif - - - for (k=0;k<16;k++) - { - for (i=0;i2200) || (zero_ADC[i][k]<1900)) - zero_ADC[i][k] = DEFAULT_ZERO_ADC; - } - } - - - - for (k=0;k<16;k++) - { - for (i=0;ierror_counts.adc_0) -// if (ADC_sf[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); - // if (ADC_sf[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); - } - } - - -} - -#if (USE_INTERNAL_ADC==1) -#pragma CODE_SECTION(fast_detect_protect_ACP_internal,".fast_run"); -void fast_detect_protect_ACP_internal(void) -{ - int k; - k=0; - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); - k=1; - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); - k=3; - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); - if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); - - -} -#endif - - -#pragma CODE_SECTION(fast_detect_protect_ACP,".fast_run"); -void fast_detect_protect_ACP() -{ - int i,k; - -// for (i=0;i<2;i++) - { -// if (project.adc[i].status == component_Ready) -#if(C_adc_number>=1) - i = 0; - for (k=0;k<14;k++) - { - if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); - if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); - } -#endif -#if(C_adc_number>=2) - i = 1; - for (k=2;k<5;k++) - { - if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); - if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); - } -#endif -#if(C_adc_number>=3) - i = 2; - for (k=0;k<15;k++) - { - if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); - if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); - } -#endif - - } - -} - -#pragma CODE_SECTION(norma_adc,".fast_run"); -inline _iq norma_adc(int plane, int chan) -{ -// return _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[n_norm] - ((long)ADC_sf[plane][chan]<<19) ),iq19_k_norm_ADC[n_norm])); - return _IQ19toIQ(_IQ19mpy((((long)ADC_f[plane][chan]<<19) - iq19_zero_ADC[plane][chan]),iq19_k_norm_ADC[plane][chan])); -} - - - -#if (USE_INTERNAL_ADC==1) -#pragma CODE_SECTION(norma_adc_internal_sf,".fast_run2"); -_iq norma_adc_internal_sf(int l) -{ - return _IQ19toIQ(_IQ19mpy((((long)ADC_sf[2][l]<<19) - iq19_zero_ADC[2][l]),iq19_k_norm_ADC[2][l])); -} -#endif - - -///////////////////////////////////////////////////////// -///////////////////////////////////////////////////////// -///////////////////////////////////////////////////////// -// -//#pragma CODE_SECTION(fast_read_all_adc_one,".fast_run"); -//void fast_read_all_adc_one(int cc) -//{ -// int i,k; -// int t; -// -// i_led1_on_off(1); -// -// project.adc[0].read_pbus(&project.adc[0]); -// -// for (k=0;k<16;k++) -// { -// t = project.adc[0].read.pbus.adc_value[k]; -// ADC_fast[0][k][cc] = t; -// -// // save max values -// if (t>ADC_fast[0][k][1] || cc==3) -// ADC_fast[0][k][1] = t; -// // save min values -// if (tflags.bit.error==0 ) -// { -// -// -// -// fast_read_all_adc_one(3); -// pause_1000(p); -// fast_read_all_adc_one(4); -// pause_1000(p); -// fast_read_all_adc_one(5); -// pause_1000(p); -// fast_read_all_adc_one(6); -// pause_1000(p); -// fast_read_all_adc_one(7); -// pause_1000(p); -// fast_read_all_adc_one(8); -// -// -// -// for (k=0;k<16;k++) -// { -// ADC_fast[0][k][0] = (-ADC_fast[0][k][1] - ADC_fast[0][k][2] + ADC_fast[0][k][3] + ADC_fast[0][k][4] -// +ADC_fast[0][k][5] + ADC_fast[0][k][6] + ADC_fast[0][k][7] + ADC_fast[0][k][8]) >> 2; // сумму делим на 4 -// } -// -// } -// else -// { -// for (k=0;k<16;k++) -// { -// ADC_fast[0][k][0] = 5000; // error -// } -// } -// -// -// if (project.adc[1].status == component_Ready -// && project.controller.read.errors.bit.error_pbus == 0 -// && project.controller.read.errors_buses.bit.slave_addr_error==0 -// && project.x_parallel_bus->flags.bit.error==0 ) -// { -// -// fast_read_all_adc_two(); -// } -// else -// { -// for (k=0;k<16;k++) -// { -// ADC_fast[1][k][0] = 5000; // error -// } -// } -// -//} - -///////////////////////////////////////////////////////// -// -//#pragma CODE_SECTION(norma_fast_adc,".fast_run"); -//void norma_fast_adc(void) -//{ -// int i,k; -//// int bb; -// -//#ifdef LOG_ACP_TO_BUF -// static int c_log=0; -// static int n_log_acp_p=0; -// static int n_log_acp_c=2; -// static int n_log_acp_p_2=0; -// static int n_log_acp_c_2=2; -// -//#endif -// -// for (i=0;iflags.bit.error==0 ) -// { -// for (k=0;k<16;k++) -// { -// iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_fast[i][k][0]<<19) ),iq19_k_norm_ADC[i][k])); -// } -// } -// else -// { -// for (k=0;k<16;k++) -// { -// iq_norm_ADC[i][k] = 0; -// } -// -// } -// -// } -// -//#ifdef LOG_ACP_TO_BUF -// if (c_log>=SIZE_BUF_LOG_ACP) -// c_log=0; -// BUF_ADC[c_log]=ADC_fast[n_log_acp_p][n_log_acp_c][0]; -// BUF_ADC_2[c_log]=ADC_fast[n_log_acp_p_2][n_log_acp_c_2][3]; -// c_log++; -//#endif -// -////i_led2_off(); -//} - -///////////////////////////////////////////////////////// - -/* -#pragma CODE_SECTION(norma_all_adc,".fast_run"); -void norma_all_adc(void) -{ - int i,k; -// int bb; -#ifdef LOG_ACP_TO_BUF - static int c_log=0; - static int n_log_acp_p=0; - static int n_log_acp_c=2; - static int n_log_acp_p_2=0; - static int n_log_acp_c_2=5; - -#endif - - for (i=0;iread_pbus(&project.adc[i]); - - if ( project.adc[i].status == component_Ready - && project.controller.read.errors.bit.error_pbus == 0 - && project.controller.read.errors_buses.bit.slave_addr_error==0 - && project.x_parallel_bus->flags.bit.error==0 ) - { - for (k=0;k<16;k++) - { - -// ADC_f[i][k] = (int)pr->data.adc[i].acc_short[k]; - -#ifdef ADC_READ_FROM_PARALLEL_BUS - ADC_f[i][k] = project.adc[i].read.pbus.adc_value[k]; - ADC_sf[i][k] += (((int)(ADC_f[i][k] - ADC_sf[i][k]))>>SDVIG_K_FILTER_S); -#else -// ADC_f[i][k] = project.adc[i].fpga.read.channels[k].value.acc_short;//iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[i][k] - ((long)project.adc[i].fpga.read.channels[k].value.acc_short<<19) ),iq19_k_norm_ADC[i][k])); -#endif - iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_f[i][k]<<19) ),iq19_k_norm_ADC[i][k])); -// iq_norm_ADC_sf[i][k] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[i][k] - ((long)ADC_sf[i][k]<<19) ),iq19_k_norm_ADC[i][k])); - } - } - else - { - for (k=0;k<16;k++) - { - ADC_f[i][k] = 5000;//DEFAULT_ZERO_ADC; - ADC_sf[i][k] = 5000;//DEFAULT_ZERO_ADC; - iq_norm_ADC[i][k] = 0; - } - - } - - } - -#ifdef LOG_ACP_TO_BUF - if (c_log>=SIZE_BUF_LOG_ACP) - c_log=0; - BUF_ADC[c_log]=ADC_f[n_log_acp_p][n_log_acp_c]; - BUF_ADC_2[c_log]=ADC_f[n_log_acp_p_2][n_log_acp_c_2]; - c_log++; -#endif - - -#if (USE_INTERNAL_ADC==1) - iq_norm_ADC[COUNT_ARR_ADC_BUF-1][0] = norma_adc_internal_sf(0); - iq_norm_ADC[COUNT_ARR_ADC_BUF-1][1] = norma_adc_internal_sf(1); - iq_norm_ADC[COUNT_ARR_ADC_BUF-1][3] = norma_adc_internal_sf(3); -#endif -//i_led2_off(); -} -*/ -//////////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(norma_adc_nc,".fast_run"); -void norma_adc_nc(int nc) -{ - int k; -// int bb; - - project.read_errors_controller(); - project.adc[nc].read_pbus(&project.adc[nc]); - - if ( project.adc[nc].status == component_Ready - && project.controller.read.errors.bit.error_pbus == 0 - && project.controller.read.errors_buses.bit.slave_addr_error==0 - && project.x_parallel_bus->flags.bit.error==0 ) - { - for (k=0;k<16;k++) - { - - ADC_f[nc][k] = project.adc[nc].read.pbus.adc_value[k]; - ADC_sf[nc][k] += (((int)(ADC_f[nc][k] - ADC_sf[nc][k]))>>SDVIG_K_FILTER_S); - iq_norm_ADC[nc][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[nc][k] + ((long)ADC_f[nc][k]<<19) ),iq19_k_norm_ADC[nc][k])); - } - } - else - { - for (k=0;k<16;k++) - { - ADC_f[nc][k] = 5000;//DEFAULT_ZERO_ADC; - ADC_sf[nc][k] = 5000;//DEFAULT_ZERO_ADC; - iq_norm_ADC[nc][k] = 0; - } - - } -} - -//////////////////////////////////////////////////////////////////// - - -#pragma CODE_SECTION(calc_norm_ADC_1,".fast_run"); -void calc_norm_ADC_1(int run_norma) -{ - _iq a1,a2,a3; - -#if (USE_ADC_1) - - if (run_norma) - norma_adc_nc(1); - - -#if (_FLOOR6==1) - - analog.T_U01 = - analog.T_U02 = - analog.T_U03 = - analog.T_U04 = - analog.T_U05 = - analog.T_U06 = - analog.T_U07 = - analog.T_Water_external = - analog.T_Water_internal = - - analog.P_Water_internal = - - analog.T_Air_01 = - analog.T_Air_02 = - analog.T_Air_03 = - analog.T_Air_04 = 0; - -#else - analog.T_U01 = iq_norm_ADC[1][1]; - analog.T_U02 = iq_norm_ADC[1][2]; - analog.T_U03 = iq_norm_ADC[1][3]; - analog.T_U04 = iq_norm_ADC[1][4]; - analog.T_U05 = iq_norm_ADC[1][5]; - analog.T_U06 = iq_norm_ADC[1][6]; - analog.T_U07 = iq_norm_ADC[1][7]; - analog.T_Water_external = iq_norm_ADC[1][9]; - analog.T_Water_internal = iq_norm_ADC[1][8]; - - analog.P_Water_internal = iq_norm_ADC[1][14]; - - analog.T_Air_01 = iq_norm_ADC[1][10]; - analog.T_Air_02 = iq_norm_ADC[1][11]; - analog.T_Air_03 = iq_norm_ADC[1][12]; - analog.T_Air_04 = iq_norm_ADC[1][13]; - - -#endif -#else - - analog.T_U01 = - analog.T_U02 = - analog.T_U03 = - analog.T_U04 = - analog.T_U05 = - analog.T_U06 = - analog.T_U07 = - analog.T_Water_external = - analog.T_Water_internal = - - analog.P_Water_internal = - - analog.T_Air_01 = - analog.T_Air_02 = - analog.T_Air_03 = - analog.T_Air_04 = 0; - -#endif -// analog.iqI_vozbud = iq_norm_ADC[1][13]; - -} - -//////////////////////////////////////////////////////////////////// -#pragma CODE_SECTION(calc_norm_ADC_0,".fast_run"); -void calc_norm_ADC_0(int run_norma) -{ - _iq a1,a2,a3; - -#if (USE_ADC_0) - - if (run_norma) - norma_adc_nc(0); - -#if (_FLOOR6) - analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit; - analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit; -#else - analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1; - analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2; -#endif - analog.iqIu_1 = iq_norm_ADC[0][2]; - analog.iqIv_1 = iq_norm_ADC[0][3]; - analog.iqIw_1 = iq_norm_ADC[0][4]; - - analog.iqIu_2 = iq_norm_ADC[0][5]; - analog.iqIv_2 = iq_norm_ADC[0][6]; - analog.iqIw_2 = iq_norm_ADC[0][7]; - - analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут - analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут - - analog.iqUin_A1B1 = iq_norm_ADC[0][10]; - -// два варианта подключения датчиков 23550.1 более правильный - по схеме -// 23550.1 - - analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1 - analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1 - -// 23550.3 bs1 bs2 - -// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3 -// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3 -// - analog.iqUin_B2C2 = iq_norm_ADC[0][13]; - - analog.iqIbreak_1 = iq_norm_ADC[0][14]; - analog.iqIbreak_2 = iq_norm_ADC[0][15]; - -#else - analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 = - analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 = - analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2 - = 0; -#endif - - analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1); - analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2); - - - - filter.iqU_1_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_1_long, analog.iqU_1); - filter.iqU_2_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_2_long, analog.iqU_2); - - -// analog.iqU_1_fast = filter_U1_3point(analog.iqU_1_fast); - filter.iqU_1_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_1_fast, analog.iqU_1); - filter.iqU_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_2_fast, analog.iqU_2); - - -// filter.iqUzpt_2_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqUzpt_2_2_fast, analog.iqUzpt_2_2); - - - -//15 - - - analog.iqIm_1 = im_calc(analog.iqIu_1, analog.iqIv_1, analog.iqIw_1); - analog.iqIm_2 = im_calc(analog.iqIu_2, analog.iqIv_2, analog.iqIw_2); - - analog.iqIu = analog.iqIu_1+analog.iqIu_2; - analog.iqIv = analog.iqIv_1+analog.iqIv_2; - analog.iqIw = analog.iqIw_1+analog.iqIw_2; - - analog.iqIm = im_calc(analog.iqIu, analog.iqIv, analog.iqIw); - - - analog.iqIin_sum = analog.iqIin_1+analog.iqIin_2; - -// analog.iqIm_3 = im_calc(analog.iqIa1_1_fir_n+analog.iqIa2_1_fir_n, analog.iqIb1_1_fir_n+analog.iqIb2_1_fir_n, analog.iqIc1_1_fir_n+analog.iqIc2_1_fir_n); - - analog.iqUin_m1 = im_calc(analog.iqUin_A1B1, analog.iqUin_B1C1, analog.iqUin_C1A1); - analog.iqUin_m2 = im_calc(analog.iqUin_A2B2, analog.iqUin_B2C2, analog.iqUin_C2A2); - -// analog.iqUin_m2 = im_calc(analog.UinA2, analog.UinB2, analog.UinC2); - - filter.iqUin_m1 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m1, analog.iqUin_m1); - filter.iqUin_m2 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m2, analog.iqUin_m2); - - - -// i_led1_on_off(0); -// i_led1_on_off(1); - -//1 - - filter.iqIm_1 = exp_regul_iq(koef_Im_filter, filter.iqIm_1, analog.iqIm_1); - filter.iqIm_2 = exp_regul_iq(koef_Im_filter, filter.iqIm_2, analog.iqIm_2); - filter.iqIm = exp_regul_iq(koef_Im_filter, filter.iqIm, analog.iqIm); - - filter.iqIin_sum = exp_regul_iq(koef_Im_filter, filter.iqIin_sum, analog.iqIin_sum); - -//3 -// filter_batter2_Iin.InpVarCurr = (analog.iqIin_1)-ZERO_I_IN; - // filter_batter2_Iin.calc(&filter_batter2_Iin); - -// filter.iqIin = _IQmpy(filter_batter2_Iin.Out,_IQ_09); - - - filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1); - filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2); - - a1 = analog.iqU_1+analog.iqU_2; - a2 = analog.iqIin_1; - a3 = _IQmpy(a1,a2); - analog.PowerScalar = a3; -// filter.Power = analog.iqU_1+analog.iqU_2; - filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar); - filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar); - -} - - - -#pragma DATA_SECTION(acp_zero,".slow_vars") -_iq19 acp_zero[16]; -#pragma DATA_SECTION(acp_summ,".slow_vars") -long acp_summ[16]; -/********************************************************************/ -/* Определение нулy показаний АЦП */ -/********************************************************************/ -void detect_zero_analog(int nc) -{ - long i,k; - - - _iq koef_zero_ADC_filter = _IQ19(0.00002/0.0003185); - - - for (k=0;k<16;k++) - { - acp_zero[k] = 0; - acp_summ[k] = 0; - } - - - - for (i=0; i=1) -#define R_ADC_DEFAULT_0 { 271, 271, 876, 876, 876, 876, 876, 876, 249, 249, 301, 301, 301, 301, 301, 301 } -#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 } -#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } -#endif - -#if(C_adc_number>=2) -#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 } -#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 } -#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_P, NORMA_ACP } -#endif - -#if(C_adc_number>=3) -#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 } -#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 } -#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } -#endif - -// 23550.1 - -//#if(C_adc_number>=1) -//#define R_ADC_DEFAULT_0 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 312, 312, 312, 312, 309, 309 } -//#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 } -//#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } -//#endif -// -//#if(C_adc_number>=2) -//#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 } -//#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 } -//#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_P, NORMA_ACP } -//#endif -// -//#if(C_adc_number>=3) -//#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 } -//#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 } -//#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } -//#endif - - - - -#if (USE_INTERNAL_ADC==1) -#define R_ADC_DEFAULT_INTERNAL { 100,100,100,100,100,100,100,100,1248,1248,1248,100,100,100,100,100 } -#define K_LEM_ADC_DEFAULT_INTERNAL { 30,30,30,30,10,10,10,10,621,621,621,100,10,10,10,10 } -#define NORMA_ADC_DEFAULT_INTERNAL { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } -#endif - - - - - -/* - //awa3 - //14 канал out1 - 0 - 11 кривые датчики - //15 канал out2 - 0 - 11 кривые датчики - //8 канал - 0 - 20 мА | 0 град - 200 град / линейный - 0V - 1.5V / 0 град - 200 град / линейный - //9 канал - 0 - 20 мА | 0 град - 200 град / линейный - 0V - 1.5V / 0 град - 200 град / линейный - - //10 канал - 0 - 20 мА | 0 град - 200 град / линейный - 0V - 1.5V / 0 град - 200 град / линейный - - //11 канал - 0 - 20 мА | 0 град - 200 град / линейный - 0V - 1.5V / 0 град - 200 град / линейный - //12 канал - 4 - 20 мА | 0 бар - 10 бар / линейный - 0.3V - 1.5V / 0 бар - 10 бар / линейный - - //13 канал - 4 - 20 мА | 0 бар - 10 бар / линейный - 0.3V - 1.5V / 0 бар - 10 бар / линейный -*/ - - -typedef union -{ - - struct - { - unsigned int c0_plus :1; /* 0 датчик+ */ - unsigned int c1_plus :1; /* 0 датчик+ */ - unsigned int c2_plus :1; /* 0 датчик+ */ - unsigned int c3_plus :1; /* 0 датчик+ */ - unsigned int c4_plus :1; /* 0 датчик+ */ - unsigned int c5_plus :1; /* 0 датчик+ */ - unsigned int c6_plus :1; /* 0 датчик+ */ - unsigned int c7_plus :1; /* 0 датчик+ */ - unsigned int c8_plus :1; /* 0 датчик+ */ - unsigned int c9_plus :1; /* 0 датчик+ */ - unsigned int c10_plus :1; /* 0 датчик+ */ - unsigned int c11_plus :1; /* 0 датчик+ */ - unsigned int c12_plus :1; /* 0 датчик+ */ - unsigned int c13_plus :1; /* 0 датчик+ */ - unsigned int c14_plus :1; /* 0 датчик+ */ - unsigned int c15_plus :1; /* 0 датчик+ */ - } bit; /* Ошибки побитно */ - unsigned long all; /* Ошибки вместе */ - -} ERR_ADC_PLUS_PROTECT; - - -typedef union -{ - - struct - { - unsigned int c0_minus :1; /* 0 датчик- */ - unsigned int c1_minus :1; /* 0 датчик- */ - unsigned int c2_minus :1; /* 0 датчик- */ - unsigned int c3_minus :1; /* 0 датчик- */ - unsigned int c4_minus :1; /* 0 датчик- */ - unsigned int c5_minus :1; /* 0 датчик- */ - unsigned int c6_minus :1; /* 0 датчик- */ - unsigned int c7_minus :1; /* 0 датчик- */ - unsigned int c8_minus :1; /* 0 датчик- */ - unsigned int c9_minus :1; /* 0 датчик- */ - unsigned int c10_minus :1; /* 0 датчик- */ - unsigned int c11_minus :1; /* 0 датчик- */ - unsigned int c12_minus :1; /* 0 датчик- */ - unsigned int c13_minus :1; /* 0 датчик- */ - unsigned int c14_minus :1; /* 0 датчик- */ - unsigned int c15_minus :1; /* 0 датчик- */ - - } bit; /* Ошибки побитно */ - unsigned int all; /* Ошибки вместе */ - -} ERR_ADC_MINUS_PROTECT; - - -typedef struct -{ - ERR_ADC_PLUS_PROTECT plus; - ERR_ADC_MINUS_PROTECT minus; -} ERR_ADC_PROTECT; - - -/* Глобальнаy структура значений токов и напрyжений АИН */ -typedef struct -{ - _iq iqU_1; - _iq iqU_2; - - _iq iqU_1_fast; - _iq iqU_2_fast; - - _iq iqU_1_long; - _iq iqU_2_long; - - _iq iqIu_1; - _iq iqIv_1; - _iq iqIw_1; - - _iq iqIu_2; - _iq iqIv_2; - _iq iqIw_2; - - _iq iqIu_1_rms; - _iq iqIv_1_rms; - _iq iqIw_1_rms; - - _iq iqIu_2_rms; - _iq iqIv_2_rms; - _iq iqIw_2_rms; - - _iq iqIu; - _iq iqIv; - _iq iqIw; - - _iq iqIin_1; - _iq iqIin_2; - - _iq iqUin_A1B1; - _iq iqUin_B1C1; - _iq iqUin_C1A1; - - _iq iqUin_A2B2; - _iq iqUin_B2C2; - _iq iqUin_C2A2; - - _iq iqUin_A1B1_rms; - _iq iqUin_B1C1_rms; - _iq iqUin_C1A1_rms; - - _iq iqUin_A2B2_rms; - _iq iqUin_B2C2_rms; - _iq iqUin_C2A2_rms; - - _iq iqUin_m1; - _iq iqUin_m2; - - _iq iqIbreak_1; - _iq iqIbreak_2; //39 - - _iq T_U01; - _iq T_U02; - _iq T_U03; - _iq T_U04; - _iq T_U05; - _iq T_U06; - _iq T_U07; - - _iq T_Water_external; - _iq T_Water_internal; - - _iq T_Air_01; - _iq T_Air_02; - _iq T_Air_03; - _iq T_Air_04; - - _iq P_Water_internal; //53 - - - _iq iqI_vozbud; - - _iq iqIin_sum; - - _iq iqIm_1; - _iq iqIm_2; - - _iq iqIm; - - - _iq iqM; - - _iq PowerScalar; - _iq PowerScalarFilter2; - _iq PowerFOC; - - _iq iqU_1_imit; //63 - - - /* - _iq iqUzpt_1_2; //uzpt1 bs2 - _iq iqUzpt_2_2; //uzpt2 bs2 - _iq iqUzpt_1_2_fast; //uzpt1 bs2 - _iq iqUzpt_2_2_fast; //uzpt2 bs2 - _iq iqUzpt_1_2_long; //uzpt1 bs2 - _iq iqUzpt_2_2_long; //uzpt2 bs2 - _iq iqIin_1_1; //Iin AF1 BS1 - _iq iqIin_2_1; //Iin AF2 BS1 - _iq iqIin_3_1; //Iin AF3 BS1 - _iq iqIin_4_1; //Iin AF4 BS1 - _iq iqIin_5_1; //Iin AF5 BS1 - _iq iqIin_6_1; //Iin AF6 BS1 - _iq iqIin_1_2; //Iin AF1 BS2 - _iq iqIin_2_2; //Iin AF2 BS2 - _iq iqIin_3_2; //Iin AF3 BS2 - _iq iqIin_4_2; //Iin AF4 BS2 - _iq iqIin_5_2; //Iin AF5 BS2 - _iq iqIin_6_2; //Iin AF6 BS2 - _iq iqUin_AB; //Входное линейное напрЯжение AB - _iq iqUin_BC; //Входное линейное напрЯжение BC - _iq iqUin_CA; //Входное линейное напрЯжение CA - _iq iqUin_AB_sf; //Входное линейное напрЯжение AB - _iq iqUin_BC_sf; //Входное линейное напрЯжение BC - _iq iqUin_CA_sf; //Входное линейное напрЯжение CA - _iq iqT_WATER_in; // Температура воды на входе ПЧ - _iq iqT_WATER_out; // Температура воды на выходе ПЧ - _iq iqT_AIR_in_up; // Температура воздуха на входе ПЧ (верх) - _iq iqT_AIR_in_down;// Температура воздуха на входе ПЧ (низ) - _iq iqP_WATER_in; // Давление воды на входе ПЧ - _iq iqP_WATER_out; // Давление воды на выходе ПЧ - - _iq iqT_BK1_BK12; // Текущее показание одного из датчиков BK1_BK12 - _iq iqT_BK13_BK24; // Текущее показание одного из датчиков BK13_BK24 - - _iq iqUin_m1; //Амплитуда Входное линейное напрЯжение - - - _iq iqIu_1_1; //Iu AF1 BS1 - _iq iqIu_1_2; //Iu AF2 BS1 - _iq iqIv_1_1; //Iv AF3 BS1 - _iq iqIv_1_2; //Iv AF4 BS1 - _iq iqIw_1_1; //Iw AF5 BS1 - _iq iqIw_1_2; //Iw AF6 BS1 - - - - _iq iqIu_2_1; //Iu AF1 BS2 - _iq iqIu_2_2; //Iu AF2 BS2 - _iq iqIv_2_1; //Iv AF3 BS2 - _iq iqIv_2_2; //Iv AF4 BS2 - _iq iqIw_2_1; //Iw AF5 BS2 - _iq iqIw_2_2; //Iw AF6 BS2 - - _iq iqIm_1; - _iq iqIm_2; - - _iq iqWexp; - _iq iqWout; - - _iq iqM; -*/ -} ANALOG_VALUE; - - -#define ANALOG_VALUE_DEFAULT {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0, 0} -/* Глобальнаy структура значений токов и напрyжений АИН */ - - -#define ERR_LEVEL_ADC_PLUS 3950 //+1270A //2950 // +650A //3467 // 3367 //3367 //3267 // 0xfff-0x29c -#define ERR_LEVEL_ADC_MINUS 150 //-1270A //1150 //-650A // 267 //367 - -#define ERR_LEVEL_ADC_PLUS_6 3800 //3783 //3623~1150 // 3462 ~ 1050 A // 3320 ~ 960A //3680 //3267 // 0xfff-0x29c -#define ERR_LEVEL_ADC_MINUS_6 1000 //267 //367 - -#define MIN_DETECT_UD_ZERO 2300 - - -#define level_err_ADC_PLUS_default {ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ - ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ - ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ - ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS} - -#define level_err_ADC_MINUS_default {ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ - ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ - ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ - ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS} - - -extern ANALOG_VALUE analog; -extern ANALOG_VALUE filter; -extern ANALOG_VALUE analog_zero; - -//void calc_norm_ADC(int fast); -void calc_norm_ADC_0(int run_norma); -void calc_norm_ADC_1(int run_norma); -void Init_Adc_Variables(void); -void norma_adc_nc(int nc); - - - -extern int ADC_f[COUNT_ARR_ADC_BUF][16]; -extern int zero_ADC[COUNT_ARR_ADC_BUF][16]; - -extern ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF],mask_err_adc_protect[COUNT_ARR_ADC_BUF]; - -extern unsigned int R_ADC[COUNT_ARR_ADC_BUF][16]; -extern unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16]; -extern float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16]; - -//void norma_all_adc(void); -extern _iq koef_Uzpt_long_filter, koef_Uzpt_fast_filter, koef_Uin_filter, koef_Im_filter, koef_Power_filter, koef_Power_filter2; - -void detect_zero_analog(int nc); - - -#if (USE_INTERNAL_ADC==1) - -void Init_Internal_Adc(void); - -#endif - - -#endif // end _ADC_TOOLS diff --git a/Inu/Src2/551/main/alarm_log.c b/Inu/Src2/551/main/alarm_log.c deleted file mode 100644 index 7dd9e2e..0000000 --- a/Inu/Src2/551/main/alarm_log.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * alarm_log.c - * - * Created on: 11 сент. 2024 г. - * Author: yura - */ - -#include "edrk_main.h" -#include "alarm_log_can.h" -#include "alarm_log.h" -#include "log_params.h" -#include "logs_hmi.h" -#include "global_time.h" - - -#define PAUSE_AUTO_SAVE_ALARM_LOG_SECONDS 20 // 20 sec -#define PAUSE_AUTO_STOP_ALARM_LOG_SECONDS 5 // 5 sec - -void send_alarm_log_pult(void) -{ - static int prev_imit_send_alarm_log_pult = 0; - int to_store = 0; - - static int flag_wait_alarm = 0, prev_Ready2 = 0, flag_store_log = 0, flag_store_log_prepare = 0, flag_auto_logs = 0, flag_stop_alarm = 0; - - static unsigned int pause_store_logs = 0, pause_stop_logs = 0; - - - - // имитация с терминалки - if (edrk.imit_send_alarm_log_pult && prev_imit_send_alarm_log_pult == 0) - flag_store_log = 1; - prev_imit_send_alarm_log_pult = edrk.imit_send_alarm_log_pult; - - - // авто логгирование аварийных логов на пульт - - - // схема собралась? значит ловим аварию - if (prev_Ready2==0 && edrk.Status_Ready.bits.ready_final) - { - flag_wait_alarm = 1; - flag_stop_alarm = 0; - } - - if (prev_Ready2==1 && edrk.Status_Ready.bits.ready_final==0) - { - // даем паузу, ждем ошибки - init_timer_sec(&pause_stop_logs); - - flag_stop_alarm = 1; - } - prev_Ready2 = edrk.Status_Ready.bits.ready_final; - - - //схема была собрана и появилась авария - if (flag_wait_alarm && edrk.summ_errors) - { - // можно сохраниться - flag_store_log_prepare = 1; - flag_wait_alarm = 0; - flag_stop_alarm = 0; - init_timer_sec(&pause_store_logs); - } - -// //схема была разобрана, но ошибок может и не быть -// if (flag_stop_alarm) -// { -// -// -// } - - // ошибок не появилось, прекращаем ждать - if (flag_stop_alarm && detect_pause_sec(PAUSE_AUTO_STOP_ALARM_LOG_SECONDS, &pause_stop_logs)) - { - flag_stop_alarm = 0; - flag_wait_alarm = 0; - } - - - if (flag_store_log_prepare) - { - flag_auto_logs = detect_pause_sec(PAUSE_AUTO_SAVE_ALARM_LOG_SECONDS, &pause_store_logs); - } - - if (flag_auto_logs) - { - flag_store_log_prepare = 0; - flag_auto_logs = 0; - // сохраняем - flag_store_log = 1; - - flag_wait_alarm = 0; - flag_stop_alarm = 0; - } - - - - - - - - // производим сброс логов на пульт - if (flag_store_log) - { - - if (edrk.pult_cmd.log_what_memory >= 2) - to_store = 2; - else - if (edrk.pult_cmd.log_what_memory >= 1) - to_store = 1; - else - to_store = 0; - - log_to_HMI.sdusb = to_store; - - - // если есть носители то сохраняем - if (log_to_HMI.sdusb) - { - log_to_HMI.send_log = 3; - } - - flag_store_log = 0; - - } - - - - -} - - -void test_send_alarm_log(int alarm_cmd) -{ - static unsigned int points_alarm_log = 1000; - // static unsigned int nchannel_alarm_log = 30; - static int prev_alarm_cmd = 0; - static int local_alarm_cmd = 0; - - - - if (alarm_cmd && prev_alarm_cmd==0 && alarm_log_can.stage==0) - { -// i_led2_on(); - - alarm_log_can.post_points = COUNT_SAVE_LOG_OFF;//100; // количество поставарийныйх записей - alarm_log_can.oscills = log_params.BlockSizeErr;//nchannel_alarm_log; // количество колонок - - alarm_log_can.global_enable = 1; - - alarm_log_can.start_adr_temp = (int *)0xc0000; // адрес для временного размещения копии лога, лог скопируется из циклического буфера в этот развернувшись. - - // alarm_log_can.finish_adr_temp = (int *)0xa0000; // адрес для временного размещения копии лога, лог скопируется из циклического буфера в этот развернувшись. - - alarm_log_can.start_adr_real_logs = (int *)log_params.start_address_log;//(int *)START_ADDRESS_LOG; // адрес начала реальных логов в циклическом буфере - alarm_log_can.finish_adr_real_log = (int *)log_params.end_address_log;//(int *)logpar.; // конец логов в циклическом буфере - - alarm_log_can.current_adr_real_log = (int *)log_params.addres_mem; - - - alarm_log_can.temp_points = points_alarm_log; // реальный размер циклическго буфера в точках. - // alarm_log_can.real_points = 1000; // нужный кусок для копии, данное количество скопируется из циклического буфера во временный лог. - - alarm_log_can.step = 450; // mks - local_alarm_cmd = alarm_cmd; -// alarm_log_can.status_alarm = alarm_cmd;//cmd_alarm_log; // код аварии - alarm_log_can.start = 0x1; - alarm_log_can.stop = 0x1; - alarm_log_can.copy2temp = 0x1; - - - alarm_log_can.clear(&alarm_log_can); -// alarm_log_can.send(&alarm_log_can); - -// i_led2_off(); - } - else - local_alarm_cmd = 0; - - alarm_log_can.status_alarm = local_alarm_cmd;//cmd_alarm_log; // код аварии - alarm_log_can.send(&alarm_log_can); - - if (alarm_log_can.stage) - { -// i_led2_on_off(1); - } - else - { -// i_led2_on_off(0); - } - - prev_alarm_cmd = alarm_cmd; - -} -//////////////////////////////////////////////////////////// diff --git a/Inu/Src2/551/main/alarm_log.h b/Inu/Src2/551/main/alarm_log.h deleted file mode 100644 index c8fef58..0000000 --- a/Inu/Src2/551/main/alarm_log.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * alarm_log.h - * - * Created on: 11 сент. 2024 г. - * Author: yura - */ - -#ifndef SRC_MAIN_ALARM_LOG_H_ -#define SRC_MAIN_ALARM_LOG_H_ - -void test_send_alarm_log(int alarm_cmd); -void send_alarm_log_pult(void); - - - -#endif /* SRC_MAIN_ALARM_LOG_H_ */ diff --git a/Inu/Src2/551/main/another_bs.c b/Inu/Src2/551/main/another_bs.c deleted file mode 100644 index 542df74..0000000 --- a/Inu/Src2/551/main/another_bs.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * another_bs.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include -#include "adc_tools.h" -#include "CAN_project.h" -#include "CAN_Setup.h" -#include "global_time.h" -#include "v_rotor.h" -#include "ukss_tools.h" -#include "another_bs.h" -#include "control_station_project.h" -#include "control_station.h" -#include "can_bs2bs.h" -#include "sync_tools.h" -#include "vector_control.h" -#include "master_slave.h" -#include "digital_filters.h" - - -////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////// -void read_data_from_bs(void) -{ - int g; - - if (control_station.alive_control_station[CONTROL_STATION_ANOTHER_BS]) - { - g = Unites[ANOTHER_BSU1_CAN_DEVICE][5]; - edrk.int_koef_ogran_power_another_bs = g; - edrk.iq_koef_ogran_power_another_bs = ((float)edrk.int_koef_ogran_power_another_bs); - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][6]; - edrk.power_kw_another_bs = g; - edrk.iq_power_kw_another_bs = _IQ(((float)edrk.power_kw_another_bs * 1000.0)/NORMA_ACP/NORMA_ACP); - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][7]; - edrk.active_post_upravl_another_bs = g; - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][9]; - edrk.Ready1_another_bs = g; - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][10]; - edrk.Ready2_another_bs = g; - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][11]; - edrk.MasterSlave_another_bs = g; - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][3] & 0x1; - edrk.ump_cmd_another_bs = g; - - g = (Unites[ANOTHER_BSU1_CAN_DEVICE][3] & 0x2) >> 1; - edrk.qtv_cmd_another_bs = g; - - g = Unites[ANOTHER_BSU1_CAN_DEVICE][13]; - edrk.errors_another_bs_from_can = g; - } - else - { - edrk.errors_another_bs_from_can = 0; - } - - -} - - -////////////////////////////////////////////////////////// -unsigned int read_cmd_sbor_from_bs(void) -{ - unsigned int g; - g = Unites[ANOTHER_BSU1_CAN_DEVICE][4]; - return g; - - -} - - - - -void UpdateTableSecondBS(void) -{ - int cmd; - int i,k; - - static unsigned int counter_sum_errors = 0; - - Unites2SecondBS[0]++; - - Unites2SecondBS[1] = global_time.miliseconds; - Unites2SecondBS[2] = edrk.flag_second_PCH; - Unites2SecondBS[3] = (edrk.to_shema.bits.QTV_ON_OFF << 1) | (edrk.to_shema.bits.UMP_ON_OFF); - Unites2SecondBS[4] = edrk.SumSbor; - Unites2SecondBS[5] = edrk.int_koef_ogran_power; - Unites2SecondBS[6] = (int)edrk.power_kw; - Unites2SecondBS[7] = (int)edrk.active_post_upravl; - Unites2SecondBS[8] = (int)edrk.power_kw; - Unites2SecondBS[9] = edrk.Status_Ready.bits.ready1; - Unites2SecondBS[10] = edrk.Status_Ready.bits.ready_final; - Unites2SecondBS[11] = edrk.MasterSlave; - - Unites2SecondBS[12] = _IQtoF(vect_control.iqId_min) * NORMA_ACP; - - Unites2SecondBS[13] = pause_detect_error(&counter_sum_errors, 10, edrk.summ_errors); - - - for (i=0;i=max_wait) - { - return 1; - } - else - { - (*c_plus)++; - return (prev_valus); - } - } - else - { - if ((*c_plus)==0) - { - return 0; - } - else - { - (*c_plus)--; - return (prev_valus); - } - } -} -/////////////////////////////////////////////////////////////////// -//TODO: may be move to detect_errors.c -unsigned int pause_detect_error(unsigned int *c_err, unsigned int max_wait,unsigned int flag) -{ - if (flag) - { - if ((*c_err)>=max_wait) - { - return 1; - } - else - { - (*c_err)++; - return 0; - } - } - else - { - (*c_err) = 0; - return 0; - - } - - - -} - - - -////////////////////////////////////////////////////////// - - - -unsigned int filter_err_count(unsigned int *counter, unsigned int max_errors, unsigned int err, unsigned int cmd) -{ - if (cmd==1) - { - (*counter) = 0; - return 0; - } - - if (err) - { - if ((*counter)>=max_errors) - return 1; - else - (*counter)++; - - return 0; - } - - if (err==0) - { - if ((*counter)==0) - return 0; - else - (*counter)--; - - return 0; - } - return 0; -} - - - diff --git a/Inu/Src2/551/main/digital_filters.h b/Inu/Src2/551/main/digital_filters.h deleted file mode 100644 index bc24cac..0000000 --- a/Inu/Src2/551/main/digital_filters.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * digital_filters.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_DIGITAL_FILTERS_H_ -#define SRC_MAIN_DIGITAL_FILTERS_H_ - -unsigned int filter_digital_input(unsigned int prev_valus, unsigned int *c_plus, unsigned int max_wait, unsigned int flag); - -unsigned int pause_detect_error(unsigned int *c_err, unsigned int max_wait,unsigned int flag); - - -unsigned int filter_err_count(unsigned int *counter, unsigned int max_errors, unsigned int err, unsigned int cmd); - - -#endif /* SRC_MAIN_DIGITAL_FILTERS_H_ */ diff --git a/Inu/Src2/551/main/limit_lib.c b/Inu/Src2/551/main/limit_lib.c deleted file mode 100644 index 859b644..0000000 --- a/Inu/Src2/551/main/limit_lib.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * limit_lib.c - * - * Created on: 15 авг. 2024 г. - * Author: yura - */ - - -#include "IQmathLib.h" -#include "math_pi.h" - - - -_iq linear_decrease(float current, int alarm_level, int warnig_level) { - float delta = current - warnig_level; - float max_delta = alarm_level - warnig_level; - if (delta <= 0 || max_delta <= 0) { - return CONST_IQ_1; - } else { - if (delta>max_delta) - return 0; - else - return CONST_IQ_1 - _IQ(delta / max_delta); - } -} - - - - - - - -_iq linear_decrease_iq(_iq current, _iq alarm_level, _iq warnig_level) -{ - _iq delta = current - warnig_level; - - _iq max_delta = alarm_level - warnig_level; - - if (delta <= 0 || max_delta <= 0) { - return CONST_IQ_1; - } else { - if (delta>=max_delta) - return 0; - else - return CONST_IQ_1 - _IQdiv(delta, max_delta); - } -} - - - diff --git a/Inu/Src2/551/main/limit_lib.h b/Inu/Src2/551/main/limit_lib.h deleted file mode 100644 index 3b1e6aa..0000000 --- a/Inu/Src2/551/main/limit_lib.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * limit_lib.h - * - * Created on: 15 авг. 2024 г. - * Author: yura - */ - -#ifndef SRC_MAIN_LIMIT_LIB_H_ -#define SRC_MAIN_LIMIT_LIB_H_ - -_iq linear_decrease(float current, int alarm_level, int warnig_level); - -_iq linear_decrease_iq(_iq current, _iq alarm_level, _iq warnig_level); - -#endif /* SRC_MAIN_LIMIT_LIB_H_ */ diff --git a/Inu/Src2/551/main/limit_power.c b/Inu/Src2/551/main/limit_power.c deleted file mode 100644 index 840019f..0000000 --- a/Inu/Src2/551/main/limit_power.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * limit_power.c - * - * Created on: 15 авг. 2024 г. - * Author: yura - */ - -#include "IQmathLib.h" - -#include -#include -#include -#include -#include -#include "mathlib.h" -#include "math_pi.h" - - -#include "limit_power.h" -#include "limit_lib.h" - -#include "pll_tools.h" - -#include "uom_tools.h" - - - - -#define KOEF_50HZ (FREQ_PWM*2.0*50.0/PI) -#define LEVEL_01HZ_IQ _IQ(10.0/KOEF_50HZ) // 0.1 HZ - -_iq level_50hz = _IQmpyI32(LEVEL_01HZ_IQ, 500); -_iq level_minimal_level_work_hz = _IQmpyI32(LEVEL_01HZ_IQ, 350); - -_iq delta_freq_test = 0; - - -//_iq level_01hz = _IQ(LEVEL_01HZ); - - -//#define LEVEL_50HZ (5000.0/KOEF_50HZ) // 50 HZ -//#define LEVEL_05HZ (50.0/KOEF_50HZ) // 50 HZ -// -//#define LEVEL_3HZ (300.0/KOEF_50HZ) // 50 HZ -//#define LEVEL_2HZ (200.0/KOEF_50HZ) // 50 HZ -//#define LEVEL_1HZ (100.0/KOEF_50HZ) // 50 HZ - - - -#define LEVEL1_FREQ_DECR 10 // 1.5 Hz от 49.0 -#define LEVEL2_FREQ_DECR 100 // 10 Hz до 40 -//#define LEVEL1_FREQ_DECR 15 // 1.5 Hz от 48.5 -//#define LEVEL2_FREQ_DECR 100 // 10 Hz до 40 - -#define PLUS_LIMIT_KOEFFS 0.0001 -#define MINUS_LIMIT_KOEFFS 0.05 - -#define MAX_COUNT_GO_UOM (FREQ_PWM*5) // 5 sec -#define SET_LIMIT_UOM 0.5 - -void calc_all_limit_koeffs(void) -{ - _iq sum_limit, delta_freq; - - static unsigned int prev_uom = 0; - static int flag_enable_go_uom = 0; - - - static _iq level1_freq_decr = _IQmpyI32(LEVEL_01HZ_IQ, LEVEL1_FREQ_DECR); - static _iq level2_freq_decr = _IQmpyI32(LEVEL_01HZ_IQ, LEVEL2_FREQ_DECR); - - static _iq iq_set_limit_uom = _IQ(SET_LIMIT_UOM); - static unsigned int count_go_uom = 0; - - static _iq iq_plus_limit_koeffs = _IQ(PLUS_LIMIT_KOEFFS); - static _iq iq_minus_limit_koeffs = _IQ(MINUS_LIMIT_KOEFFS); - - static long freq_test = 30; - //*LEVEL_01HZ_IQ; - static _iq minus_delta_freq_test = _IQdiv32(LEVEL_01HZ_IQ); // 0.1/32 - - - static int uom_test = 50; - static int prev_imit_limit_freq = 0, prev_imit_limit_uom = 0; - - static _iq iq_new_uom_level_kwt = 0; - - - update_uom(); - - // temper - edrk.all_limit_koeffs.local_temper_limit = edrk.temper_limit_koeffs.sum_limit; - - - // uin_freq - if (edrk.Status_Ready.bits.ready_final) //|| edrk.imit_limit_freq - { - - get_freq_50hz_iq(); - - // freq = LEVEL_50HZ - edrk.iq_freq_50hz; - - if (edrk.imit_limit_freq && prev_imit_limit_freq == 0) - delta_freq_test = _IQmpyI32(LEVEL_01HZ_IQ, freq_test); - - if (delta_freq_test>0) - { - if (delta_freq_test>0) - delta_freq_test -= minus_delta_freq_test; - if (delta_freq_test<0) - delta_freq_test = 0; - } - - if (edrk.iq_freq_50hz>level_minimal_level_work_hz) - { - edrk.all_limit_koeffs.local_uin_freq_limit = linear_decrease_iq( (level_50hz - edrk.iq_freq_50hz), - level2_freq_decr, level1_freq_decr); - } - else - edrk.all_limit_koeffs.local_uin_freq_limit = CONST_IQ_1; - } - else - { - edrk.all_limit_koeffs.local_uin_freq_limit = CONST_IQ_1; - } - prev_imit_limit_freq = edrk.imit_limit_freq; - - // - /// UOM - // - if (edrk.from_uom.ready || edrk.set_limit_uom_50) - { - if (edrk.set_limit_uom_50) - { - edrk.from_uom.level_value = uom_test; - } - - if (edrk.imit_limit_uom && prev_imit_limit_uom == 0) - edrk.from_uom.level_value++; - - - if (prev_uom!=edrk.from_uom.level_value && edrk.from_uom.level_value > prev_uom) - { - if (edrk.iq_power_kw_full_filter_abs > edrk.from_uom.iq_level_value_kwt) - flag_enable_go_uom = 1; - } - else - flag_enable_go_uom = 0; - - if (flag_enable_go_uom) - { - count_go_uom = MAX_COUNT_GO_UOM; - edrk.all_limit_koeffs.local_uom_limit = iq_set_limit_uom; // даем сброс - } - - if (count_go_uom) - { - // держим сброс - count_go_uom--; - } - else - edrk.all_limit_koeffs.local_uom_limit = CONST_IQ_1; // возвращаемся - - prev_uom = edrk.from_uom.level_value; - - } - else - { - - edrk.power_limit.bits.limit_from_uom_fast = 0; - edrk.all_limit_koeffs.uom_limit = CONST_IQ_1; - prev_uom = 0; - } - prev_imit_limit_uom = edrk.imit_limit_uom; - // if () - - - //// temper - edrk.all_limit_koeffs.temper_limit = zad_intensiv_q(iq_plus_limit_koeffs, iq_minus_limit_koeffs, - edrk.all_limit_koeffs.temper_limit, - edrk.all_limit_koeffs.local_temper_limit); - - edrk.power_limit.bits.limit_by_temper = (edrk.all_limit_koeffs.temper_limit -#include -#include -#include - -#include "control_station.h" -#include "global_time.h" -#include "modbus_table_v2.h" -#include "RS_modbus_pult.h" -#include "DSP281x_Device.h" -#include "MemoryFunctions.h" -#include "RS_modbus_svu.h" -#include "log_params.h" -#include "logs_hmi.h" -#include "edrk_main.h" - - -#pragma DATA_SECTION(log_to_HMI, ".logs"); -t_Logs_with_modbus log_to_HMI = LOGS_WITH_MODBUS_DEFAULTS; - - -#define COUNT_FAST_DATA 300//150 -#define COUNT_SLOW_DATA 300 - - - -/////////////////////////////////////////////////// -/// -/////////////////////////////////////////////////// -#define MAX_SIZE_LOGS_HMI_FULL (END_ADDRESS_LOGS - START_ADDRESS_LOG + 1) //262144 // 0x80000/2 -#define MAX_SIZE_LOGS_HMI_SMALL 10000 - -#define START_ARRAY_LOG_SEND 300 -#define END_ARRAY_LOG_SEND 899 -#define SIZE_ARRAY_LOG_SEND (END_ARRAY_LOG_SEND - START_ARRAY_LOG_SEND + 1) -#define SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE 120 - -int writeLogsArray(int flag_next) -{ - int succed = 0; - static unsigned int old_time = 0; - - static int count_write_to_modbus = 0; - static int cur_position_buf_modbus16 = 0; - - - - - - if (!rs_b.flag_LEADING) - { - - ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); - - if (control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] == 0) - { - if (log_to_HMI.flag_start_log_array_sent) - { - cur_position_buf_modbus16 = START_ARRAY_LOG_SEND; - log_to_HMI.flag_log_array_sended = 0; - } - else - { - if (flag_next) - cur_position_buf_modbus16 = cur_position_buf_modbus16 + SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; - } - - log_to_HMI.flag_start_log_array_sent = 0; - } - - if (cur_position_buf_modbus16 >= END_ARRAY_LOG_SEND) - { - // все передали уже? - cur_position_buf_modbus16 = START_ARRAY_LOG_SEND; - log_to_HMI.flag_log_array_sended = 1; - // log_to_HMI.flag_log_array_sent_process = 0; -// succed = 1; - return succed; - } - -// //Дырка в обмене. Пропускаем. -// if ((cur_position_buf_modbus16 > ADRESS_END_FIRST_BLOCK) && -// (cur_position_buf_modbus16 < ADRESS_START_PROTECTION_LEVELS)) { -// cur_position_buf_modbus16 = ADRESS_START_PROTECTION_LEVELS; -// } - - if ((cur_position_buf_modbus16 + SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE) > (END_ARRAY_LOG_SEND+1)) - count_write_to_modbus = END_ARRAY_LOG_SEND - cur_position_buf_modbus16 + 1; - else - count_write_to_modbus = SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; - - log_to_HMI.n_log_array_sended = (cur_position_buf_modbus16 - START_ARRAY_LOG_SEND)/100 + 1; - log_to_HMI.flag_log_array_sent_process++;// = 1; - - ModbusRTUsend16(&rs_b, 2, - ADR_MODBUS_TABLE_REMOUTE + cur_position_buf_modbus16, - count_write_to_modbus); - - - - // control_station.count_error_modbus_16[CONTROL_STATION_INGETEAM_PULT_RS485]++; - - // control_station.flag_message_sent[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; - succed = count_write_to_modbus; - } - return succed; - - - -/* - - unsigned long i = 0; - int succed = 0; - -// int *p_log_data = (int*)LOG_START_ADRES; - - ModbusRTUsetDataArrays(modbus_table_analog_in, modbus_table_analog_out); - if (!rs_b.flag_LEADING) - { - ModbusRTUsend16(&rs_b, 2, - log_to_HMI.current_address, - log_to_HMI.count_write_to_modbus + 1); - - if (err_send_log_16 == 0) { //prev message without errors - log_to_HMI.current_address = log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16; - } - if (log_to_HMI.current_address > END_ARRAY_LOG_SEND) { - log_to_HMI.current_address = START_ARRAY_LOG_SEND; -// log_to_HMI.flag_end_of_log = 1; - log_to_HMI.flag_log_array_sent = 1; - } - if ((log_to_HMI.current_address + SIZE_BUF_WRITE_LOG_TO_MODBUS16) > END_ARRAY_LOG_SEND) { - log_to_HMI.count_write_to_modbus = END_ARRAY_LOG_SEND - log_to_HMI.current_address; - } else { - log_to_HMI.count_write_to_modbus = SIZE_BUF_WRITE_LOG_TO_MODBUS16; - } - - err_send_log_16 += 1; - succed = 1; - - } - return succed; -*/ -} - -void prepareWriteLogsArray(void) { -// log_to_HMI.start_log_address = logpar.addres_mem - logpar.count_log_params_fast_log * SIZE_ARRAY_LOG_SEND; -// log_to_HMI.start_log_address = log_params.addres_mem - log_params.BlockSizeErr * SIZE_ARRAY_LOG_SEND; - - if (log_to_HMI.send_log == 1) - log_to_HMI.start_log_address = log_params.start_address_log_slow; - if (log_to_HMI.send_log == 2) - log_to_HMI.start_log_address = log_params.start_address_log; - if (log_to_HMI.send_log == 3) - log_to_HMI.start_log_address = 0;//log_params.start_address_log; - - // - log_to_HMI.max_size_logs_hmi; - -// if (log_to_HMI.start_log_address < log_params.start_address_log) { -// log_to_HMI.start_log_address = log_params.end_address_log - (log_params.start_address_log - log_to_HMI.start_log_address); -// } -// log_to_HMI.log_address_step = SIZE_ARRAY_LOG_SEND;//log_params.BlockSizeErr; -} - - -int fillAnalogDataArrayForLogSend(void) -{ - int i, k, n;// = START_ARRAY_LOG_SEND; - int c_data = 0, lb = 0, type_log; - volatile unsigned long local_pos = 0; - -// unsigned long current_address = log_to_HMI.start_log_address;// + num_of_log; - - k = 0; - n = 0; - for (i = START_ARRAY_LOG_SEND; i <= END_ARRAY_LOG_SEND; i++) { - -// if (log_to_HMI.count_write_to_modbus > log_to_HMI.max_size_logs_hmi) -// break; - - n = log_to_HMI.count_write_to_modbus/SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE; - - if (k>=SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE) - k = 0; - - if (k==0) - modbus_table_analog_out[i].all = LOWORD(log_to_HMI.count_write_to_modbus); - else - if (k==1) - modbus_table_analog_out[i].all = LOWORD(global_time.miliseconds); - else - if (k==2) - modbus_table_analog_out[i].all = HIWORD(log_to_HMI.start_log_address); - else - if (k==3) - modbus_table_analog_out[i].all = LOWORD(log_to_HMI.start_log_address); - else - if (k==SIZE_BUF_WRITE_LOGS_TO_MODBUS16_REMOUTE-1) - modbus_table_analog_out[i].all = log_to_HMI.tick_step; - else - { - if (log_to_HMI.count_write_to_modbus > log_to_HMI.max_size_logs_hmi) - modbus_table_analog_out[i].all = 0; - else - { -// modbus_table_analog_out[i].all = LOWORD(log_to_HMI.start_log_address); // это для теста - if (log_to_HMI.send_log==3) - { - if (log_to_HMI.start_log_address>=(COUNT_FAST_DATA*log_params.BlockSizeErr) ) - { - local_pos = log_to_HMI.max_size_logs_hmi - log_to_HMI.start_log_address;// - (COUNT_FAST_DATA*log_params.BlockSizeErr); - type_log = SLOW_LOG; - } - else - { - local_pos = log_to_HMI.max_size_logs_hmi - log_to_HMI.start_log_address - (COUNT_SLOW_DATA*log_params.BlockSizeErr); - type_log = FAST_LOG; - } - - modbus_table_analog_out[i].all = alarm_log_get_data(local_pos, type_log); - } - else - modbus_table_analog_out[i].all = ReadMemory(log_to_HMI.start_log_address); - - - - log_to_HMI.start_log_address += 1;//log_to_HMI.log_address_step; - log_to_HMI.count_write_to_modbus += 1; - - } - } - -// modbus_table_analog_out[i+1].all = HIWORD(log_to_HMI.start_log_address);//log_to_HMI.count_write_to_modbus;//ReadMemory(log_to_HMI.start_log_address); -// modbus_table_analog_out[i].all = LOWORD(global_time.miliseconds);//ReadMemory(log_to_HMI.start_log_address); -// modbus_table_analog_out[i+1].all = HIWORD(global_time.miliseconds);//log_to_HMI.count_write_to_modbus;//ReadMemory(log_to_HMI.start_log_address); - -// if (k>1 && k 0) { - *(p_memory++) = value; - value += 1; -// if (log_size % 8 == 0) { -// value += 1; -// } - } -} - - - - - - -int alarm_log_get_data(unsigned long pos, int type_log) -{ - //unsigned int i,k; - static volatile unsigned long cur_adr_log, end_log, start_log, addres_mem, temp_length, delta_adr;//clog //real_length - //int *adr_finish_temp, *adr_current; - - -// real_length = al->real_points * al->oscills; - // real_adr = al->start_adr_real_logs; - - if (type_log==FAST_LOG) - { - temp_length = log_params.BlockSizeErr; - cur_adr_log = log_params.addres_mem; - end_log = log_params.end_address_log; - start_log = log_params.start_address_log; - - } - - if (type_log==SLOW_LOG) - { - temp_length = log_params.BlockSizeSlow; - cur_adr_log = log_params.addres_mem_slow; - end_log = log_params.end_address_log_slow; - start_log = log_params.start_address_log_slow; - } - - // ищем точку в памяти - - - addres_mem = cur_adr_log - pos;//temp_length - - // перехали начло лога? - if (addres_memtemp_points * al->oscills; // сколько данных надо выерезать из лога - al->temp_log_ready = 0; - - - if (al->current_adr_real_log == al->start_adr_real_logs) // мы в начале, логов нету? - return; - - adr_current = al->current_adr_real_log; // выставили конец лога - adr_finish_temp = al->start_adr_temp + temp_length; // тут конец лога temp - // теперь начиная с конца adr_finish скопируем в temp_log - // с учетом того что мы копируем из циклического буфера в обычный, нужна развертка данных - for (clog=0; clog= al->start_adr_real_logs) ) - { - *adr_finish_temp = *adr_current; // скопирлвали данные - // едем назад - adr_current--; - } - else - *adr_finish_temp = 0; // а нету данных! - - // едем назад - adr_finish_temp--; - - // закольцевались? - if (adr_current < al->start_adr_real_logs) - { - if (al->finish_adr_real_log) // лог прокручивался? - adr_current = al->finish_adr_real_log; // перешли в конец. - else - adr_current = al->start_adr_real_logs - 1; - } - } - - al->temp_log_ready = 1; -*/ - -} - - - - diff --git a/Inu/Src2/551/main/logs_hmi.h b/Inu/Src2/551/main/logs_hmi.h deleted file mode 100644 index e7637f5..0000000 --- a/Inu/Src2/551/main/logs_hmi.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * logs_hmi.h - * - * Created on: 28 авг. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_LOGS_HMI_H_ -#define SRC_MAIN_LOGS_HMI_H_ - -#define _LOG_HMI_SMALL_TEST 0//1 - -#define PLACE_STORE_LOG_PULT_SD 1 //SD -#define PLACE_STORE_LOG_PULT_USB 2 //USB Flash - -typedef struct { - - int send_log; - -// int new_send_log_checked; - unsigned long log_size_sent; -// int flag_data_received; - - - -// unsigned int number_of_log; - unsigned long count_write_to_modbus; - -// unsigned long current_address; - unsigned long start_log_address; -// int log_address_step; - - int step; - int progress_bar; - int enable_progress_bar; - - int cleanLogs; - int tick_step; -// int tick_finish; - - int flag_log_array_sended; - int flag_start_log_array_sent; - - int flag_log_array_sent_process; - int count_data_in_buf; - unsigned long count_sended_to_pult; - - unsigned long max_size_logs_hmi; - - int tick_step2; - int tick_step3; - int tick_step4; - int tick_step5; - int n_log_array_sended; - - unsigned long max_size_logs_hmi_small; - unsigned long max_size_logs_hmi_full; - - int saveLogsToSDCard; - int ReportLogOut; - int sdusb; - -} t_Logs_with_modbus; - -#define LOGS_WITH_MODBUS_DEFAULTS {0,0,0,0,0, 0,0,0,0, 0,0,0,0,0, 0, 0,0,0,0,0, 0,0, 0,0,0} -extern t_Logs_with_modbus log_to_HMI; - - - - -#define LOG_START_ADRES 0xA0000UL -#define LOG_END_ADRES 0xF0000UL -#define LOG_BUFFER_SIZE 0x50000UL //0x100UL - -void fillLogArea(); //TODO for testing only - -int alarm_log_get_data(unsigned long pos, int type_log); - -int writeLogsArray(int flag_next); -static void prepareWriteLogsArray(void); -static int fillAnalogDataArrayForLogSend(void); -int sendLogToHMI(int status_ok); -void run_store_slow_logs(void); - - -#endif /* SRC_MAIN_LOGS_HMI_H_ */ diff --git a/Inu/Src2/551/main/master_slave.c b/Inu/Src2/551/main/master_slave.c deleted file mode 100644 index 4aa4297..0000000 --- a/Inu/Src2/551/main/master_slave.c +++ /dev/null @@ -1,586 +0,0 @@ -/* - * master_slave.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include -#include "synhro_tools.h" -#include "master_slave.h" - -////////////////////////////////////////////////////////// - -#pragma DATA_SECTION(buf_log_master_slave_status,".slow_vars"); -unsigned int buf_log_master_slave_status[SIZE_LOG_MASTER_SLAVE_STATUS] = {0}; -//AUTO_MASTER_SLAVE_DATA buf2[SIZE_BUF1] = {0}; -//AUTO_MASTER_SLAVE_DATA buf3[SIZE_BUF1] = {0}; -//OPTICAL_BUS_DATA_LOW_CMD buf4[SIZE_BUF1] = {0}; -//OPTICAL_BUS_DATA_LOW_CMD buf5[SIZE_BUF1] = {0}; - - -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// - -void auto_select_master_slave(void) -{ - static unsigned int count_try_master = 0; - static unsigned int count_wait_answer_confirm_mode = 0; - static unsigned int count_wait_slave_try_master = 0; - unsigned int err_confirm_mode = 0; // ошибка подтверждения режима другим ПЧ - static unsigned int c_buf_log_master_slave_status = 0, prev_status = 0; - - - -// logs master_slave_status - if (edrk.auto_master_slave.status != prev_status) - { - c_buf_log_master_slave_status++; - if (c_buf_log_master_slave_status>=SIZE_LOG_MASTER_SLAVE_STATUS) - c_buf_log_master_slave_status = 0; - buf_log_master_slave_status[c_buf_log_master_slave_status] = edrk.auto_master_slave.status; - } - prev_status = edrk.auto_master_slave.status; -//end logs master_slave_status - - if (edrk.ms.ready2==0 && edrk.errors.e7.bits.AUTO_SET_MASTER==0) - { - edrk.auto_master_slave.remoute.all = 0; - edrk.auto_master_slave.local.all = 0; - edrk.auto_master_slave.prev_remoute.all = edrk.auto_master_slave.remoute.all; - edrk.auto_master_slave.prev_local.all = edrk.auto_master_slave.local.all; - - edrk.auto_master_slave.status = 1; - -// if (prev_ready!=edrk.ms.ready2) -// for (c_buf=0;c_buf=SIZE_BUF1) -// c_buf = 0; -// -// buf1[c_buf] = edrk.auto_master_slave.status; -// buf2[c_buf].all = edrk.auto_master_slave.local.all; -// buf3[c_buf].all = edrk.auto_master_slave.remoute.all; -// buf4[c_buf].all = optical_read_data.data.cmd.all; -// buf5[c_buf].all = optical_write_data.data.cmd.all; -// - - // сбросим счетчик времени перехода на мастер - if (edrk.auto_master_slave.local.bits.try_master==0 || - (edrk.auto_master_slave.prev_local.bits.try_master != edrk.auto_master_slave.local.bits.try_master && edrk.auto_master_slave.local.bits.try_master==1)) - count_try_master = 0; - - // если шина OPTICAL_BUS сдохла, выходим - if (edrk.errors.e7.bits.WRITE_OPTBUS==1 || edrk.errors.e7.bits.READ_OPTBUS==1 || - edrk.warnings.e7.bits.WRITE_OPTBUS==1 || edrk.warnings.e7.bits.READ_OPTBUS==1) - { - - if (edrk.errors.e7.bits.WRITE_OPTBUS==1 || edrk.errors.e7.bits.READ_OPTBUS==1) - { - // шина не работает, и тот ПЧ включен - // значит что-то случилось - выключаемся - - edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; - - edrk.auto_master_slave.remoute.bits.nothing = 1; - edrk.auto_master_slave.remoute.bits.master = 0; - edrk.auto_master_slave.remoute.bits.slave = 0; - edrk.auto_master_slave.remoute.bits.try_master = 0; - edrk.auto_master_slave.remoute.bits.try_slave = 0; - - - edrk.auto_master_slave.local.bits.master = 0; - edrk.auto_master_slave.local.bits.slave = 0; - edrk.auto_master_slave.local.bits.try_master = 0; - edrk.auto_master_slave.local.bits.try_slave = 0; - edrk.auto_master_slave.local.bits.nothing = 1; - - edrk.auto_master_slave.status = 10; - } - else - { - // шина не работает, и тот ПЧ выключен - // значит мы сразу мастер - edrk.warnings.e7.bits.AUTO_SET_MASTER = 1; - - edrk.auto_master_slave.remoute.bits.nothing = 1; - edrk.auto_master_slave.remoute.bits.master = 0; - edrk.auto_master_slave.remoute.bits.slave = 0; - edrk.auto_master_slave.remoute.bits.try_master = 0; - edrk.auto_master_slave.remoute.bits.try_slave = 0; - - - - edrk.auto_master_slave.local.bits.master = 1; - edrk.auto_master_slave.local.bits.slave = 0; - edrk.auto_master_slave.local.bits.try_master = 0; - edrk.auto_master_slave.local.bits.try_slave = 0; - edrk.auto_master_slave.local.bits.nothing = 1; - - edrk.auto_master_slave.status = 2; - } - - edrk.auto_master_slave.remoute.bits.sync_line_detect = 0; - edrk.auto_master_slave.remoute.bits.bus_off = 1; - edrk.auto_master_slave.remoute.bits.sync1_2 = 0; - - } - else - { - edrk.warnings.e7.bits.AUTO_SET_MASTER = 0; - - edrk.auto_master_slave.remoute.bits.bus_off = 0; - - // синхронизируем свои программы через OPTICAL_BUS - - if (wait_synhro_optical_bus()==1) - { - - edrk.auto_master_slave.status = 50; // wait synhro - - - } - else - { - - - edrk.auto_master_slave.remoute.bits.master = optical_read_data.data.cmd.bit.master; - edrk.auto_master_slave.remoute.bits.slave = optical_read_data.data.cmd.bit.slave; - edrk.auto_master_slave.remoute.bits.try_master = optical_read_data.data.cmd.bit.maybe_master; - edrk.auto_master_slave.remoute.bits.sync1_2 = optical_read_data.data.cmd.bit.sync_1_2; - edrk.auto_master_slave.remoute.bits.sync_line_detect = optical_read_data.data.cmd.bit.sync_line_detect; - edrk.auto_master_slave.remoute.bits.tick = optical_read_data.data.cmd.bit.wdog_tick; - - if (optical_read_data.data.cmd.bit.master==0 && optical_read_data.data.cmd.bit.slave==0) - edrk.auto_master_slave.remoute.bits.nothing = 1; - - - ////////////////////////////////////////////////// - ////////////////////////////////////////////////// - // 1 - - // тот ПЧ уже мастер - if (edrk.auto_master_slave.remoute.bits.master) - { - - // и этот ПЧ мастер почему-то? - if (edrk.auto_master_slave.local.bits.master) - { - edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; - edrk.auto_master_slave.status = 3; - } - else - { - // этот ПЧ еще не определился, поэтому переход на slave - if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0) - { - // edrk.auto_master_slave.local.bits.try_slave = 1; - // стали slave - edrk.auto_master_slave.local.bits.slave = 1; - // сняли свой запрос на мастера если он был - edrk.auto_master_slave.local.bits.try_master = 0; - edrk.auto_master_slave.status = 4; - } - else - { - edrk.auto_master_slave.status = 21; - } - } - } - else - ////////////////////////////////////////////////// - ////////////////////////////////////////////////// - // 2 - // тот ПЧ уже slave - - if (edrk.auto_master_slave.remoute.bits.slave) - { - - // и этот ПЧ slave почему-то? - if (edrk.auto_master_slave.local.bits.slave) - { - - // был переход из мастер в slave - if (edrk.auto_master_slave.prev_remoute.bits.slave==0) - { - if (edrk.Go) - { - // запущен ШИМ - edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; - edrk.auto_master_slave.status = 5; - } - else - { - // пробуем перехватить master - edrk.auto_master_slave.local.bits.try_master = 1; - edrk.auto_master_slave.status = 6; - } - } - else - { - edrk.errors.e7.bits.AUTO_SET_MASTER |= 1; - edrk.auto_master_slave.status = 7; - } - - } - else - { - - // этот ПЧ еще не определился, поэтому запрашивает на master - if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.try_master==0) - { - if (edrk.flag_second_PCH==0) - edrk.auto_master_slave.local.bits.try_master = 1; - if (edrk.flag_second_PCH==1) - edrk.auto_master_slave.local.bits.try_master = 1; - - edrk.auto_master_slave.status = 8; - // edrk.auto_master_slave.local.bits.slave = 1; - } - else - // этот ПЧ уже в запросе на мастер, а тот ПЧ подтвердил в slave что он не против. - if (edrk.auto_master_slave.local.bits.master==0 && edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.try_master==1) - { - // стали мастером - edrk.auto_master_slave.local.bits.master = 1; - edrk.auto_master_slave.local.bits.try_master = 0; - edrk.auto_master_slave.status = 9; - // edrk.auto_master_slave.local.bits.slave = 1; - } - else - { - edrk.auto_master_slave.status = 22; - } - - } - } - else - ////////////////////////////////////////////////// - ////////////////////////////////////////////////// - // 3 - // тот ПЧ запрашивает переход на мастер - - if (edrk.auto_master_slave.remoute.bits.master==0 - && edrk.auto_master_slave.remoute.bits.slave==0 - && edrk.auto_master_slave.remoute.bits.try_master) - { - // а этот ПЧ slave - if (edrk.auto_master_slave.local.bits.slave) - { - // вроде не норм, остаемся slave - // тут надо подождать некотрое время, пока тот ПЧ не поймет что мы стали слейвом и перейдет из try_master в мастер - if (count_wait_slave_try_master -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "global_time.h" -#include "IQmathLib.h" -#include "oscil_can.h" -#include "uf_alg_ing.h" -#include "MemoryFunctions.h" -#include "RS_Functions.h" -#include "v_rotor_22220.h" -#include "log_to_memory.h" -#include "log_params.h" - - - - - -/////////////////////////////////////////////////////////////////// - - -#pragma CODE_SECTION(optical_bus_read_write_interrupt,".fast_run2"); -void optical_bus_read_write_interrupt(void) -{ - - - static unsigned int prev_error_read = 0, count_read_optical_bus_error = 0, count_read_optical_bus_old_data = 0; - static unsigned int max_count_read_old_data_optical_bus = 15; - static unsigned int flag_disable_resend = 0; - static unsigned int count_resend = 0, cc=0; -// static STATUS_DATA_READ_OPT_BUS buf_status[10]; - static STATUS_DATA_READ_OPT_BUS optbus_status; - static unsigned int tt=0; - static unsigned int cmd_wdog_sbus = 0, count_wait_wdog_sbus = 0, wdog_sbus = 0; - static int prepare_time = 0; - - - static unsigned int t_finish_optbus = 14, t_read_optbus = 6, t_write_optbus = 10, max_count_read_error_optical_bus = 15, max_count_read_wdog_optical_bus = 48; - static int cmd_optbus = 0; - - static int flag_enable_read=0, flag_finish_read = 0, flag_enable_write = 0, flag_finish_write = 0, count_wait_write = 0; - - if (prepare_time==0) - { - if (edrk.flag_second_PCH==0) - { - t_read_optbus = 6; - t_write_optbus = 8; - t_finish_optbus = 20; - } - - if (edrk.flag_second_PCH==1) - { - t_read_optbus = 12; - t_write_optbus = 14; - t_finish_optbus = 10; - } - prepare_time = 1; - } - - if (flag_special_mode_rs==1) - return; - - if (edrk.KvitirProcess) - return; - - if (edrk.disable_interrupt_timer2) - return; - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_17_ON; -#endif - -//i_led2_on_off(1); - - -//#if (ENABLE_LOG_INTERRUPTS) -// add_log_interrupts(2); -//#endif - - -// pause_1000(100); - if (optical_read_data.flag_clear) - { - // stage_1 = 0; - optical_read_data.timer = 0; - optical_read_data.flag_clear = 0; - optical_read_data.error_wdog = 0; -// count_wait_wdog_sbus = 0; - -// if (optical_read_data.data_was_update_between_pwm_int==0) -// sum_count_err_read_opt_bus++; -// -// optical_read_data.data_was_update_between_pwm_int = 0; - - // optical_read_data.data_was_update_between_pwm_int = 0; - cc = 0; - prev_error_read = 0; - } - - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - if (optical_read_data.timer==0) - { - PWM_LINES_TK_16_ON; - } - else - { - PWM_LINES_TK_16_OFF; - } -#endif - - - -// else - optical_read_data.timer++; - -// if (edrk.into_pwm_interrupt==1) -// { -// if (optical_read_data.timer>=2) -// { -// optical_read_data.timer--; -// optical_read_data.timer--; -// } -// flag_disable_resend = 0; -// count_resend = 0; -// -// } - -// -// -// -// if (stage_1==0) -// tt = t1; -// -// if (stage_1==1) -// tt = t2; - - if (edrk.ms.another_bs_maybe_on==1 && edrk.flag_second_PCH==0 /*edrk.auto_master_slave.local.bits.master*/ ) - { - - if (optical_read_data.data.cmd.bit.wdog_tick) - { - // i_led1_on(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_21_ON; -#endif - } - else - { - // i_led1_off(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_21_OFF; -#endif - - } - - optical_write_data.data.cmd.bit.wdog_tick = optical_read_data.data.cmd.bit.wdog_tick; - - if (optical_write_data.data.cmd.bit.wdog_tick) - { - // i_led2_on(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_22_ON; -#endif - - } - else - { - // i_led2_off(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_22_OFF; -#endif - } - - - - } - - - if (edrk.ms.another_bs_maybe_on==1 && edrk.flag_second_PCH==1 /*edrk.auto_master_slave.local.bits.slave*/ ) - { - - if (optical_write_data.data.cmd.bit.wdog_tick) - { - // i_led2_on(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_22_ON; -#endif - - } - else - { - // i_led2_off(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_22_OFF; -#endif - } - - - - if (optical_read_data.data.cmd.bit.wdog_tick) - { - // i_led1_on(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_21_ON; -#endif - } - else - { - // i_led1_off(); -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_21_OFF; -#endif - } - - - - - // пишем - optical_write_data.data.cmd.bit.wdog_tick = wdog_sbus; - if (cmd_wdog_sbus==0) - { -// optical_write_data.data.cmd.bit.wdog_tick = wdog_sbus; - count_wait_wdog_sbus = 0; - cmd_wdog_sbus++; - } - else - // ждем подтверждения - if (cmd_wdog_sbus==1) - { - if (optical_read_data.data.cmd.bit.wdog_tick == wdog_sbus) //&& prev_error_read==0 - { - // result_code_wdog_sbus = 1; - optical_read_data.count_error_wdog = count_wait_wdog_sbus; - count_wait_wdog_sbus = 0; - wdog_sbus = !wdog_sbus; - cmd_wdog_sbus = 0; - } - else - { - if (count_wait_wdog_sbus=t_finish_optbus) - cmd_optbus = 1; - break; - case 5: - break; - case 6: - break; - case 7: - break; - case 8: - break; - case 9: - break; - default: - break; - } -} - - - -if (edrk.flag_second_PCH==0) -{ - switch (cmd_optbus) - { - case 0 : if (optical_read_data.timer==t_write_optbus) - cmd_optbus = 1; - break; - - case 1: flag_enable_read = 0; - flag_finish_read = 0; - flag_enable_write = 1; - flag_finish_write = 0; - count_wait_write = TIME_WAIT_CMD_WRITE; - cmd_optbus = 2; - break; - - case 2: if (flag_enable_write==0) - { - if (count_wait_write) - { - count_wait_write--; - } - else - cmd_optbus = 3; - } - break; - case 3: flag_enable_read = 1; - flag_finish_read = 0; - flag_enable_write = 0; - flag_finish_write = 0; - count_wait_write = 0; - cmd_optbus = 4; - break; - - case 4: if (flag_finish_read) - { - //flag_enable_write = 1; - //count_wait_write = 2; - //cmd_optbus = 2; - flag_enable_read = 0; - flag_finish_read = 0; - flag_enable_write = 1; - flag_finish_write = 0; - count_wait_write = TIME_WAIT_CMD_WRITE; - cmd_optbus = 2; // минуем case 5: и case 1: - } - break; - - case 5: if (optical_read_data.timer>=t_finish_optbus) - cmd_optbus = 1; - break; - case 6: - break; - case 7: - break; - case 8: - break; - case 9: - break; - case 10: - break; - default: - break; - } -} -// if (optical_read_data.timer==t_read_optbus) -// flag_run_cycle = 1; -// -// if (flag_run_cycle==t_read_optbus) -// { -// flag_enable_read = 1; -// flag_finish_read = 0; -// flag_enable_write = 0; -// flag_finish_write = 0; -// flag_run_cycle = 0; -// } -// -// -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_18_OFF; -#endif - - if (flag_enable_read) - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_19_ON; -#endif - -#if(USE_TK_3) - project.cds_tk[3].read_pbus(&project.cds_tk[3]); -#endif - optbus_status = optical_bus_get_status_and_read(); - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_19_OFF; -#endif - cc++; - - if (optbus_status.bit.new_data_ready) - { - - prev_error_read = 0; - optical_read_data.count_read_optical_bus_old_data = 0; - - if (optical_read_data.data_was_update_between_pwm_int<10000) - optical_read_data.data_was_update_between_pwm_int += 1; - - count_read_optical_bus_error = 0; - flag_finish_read = 1; - flag_enable_read = 0; - } - - if (optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 ) - { - - prev_error_read = 1; - - if (count_read_optical_bus_error<=max_count_read_error_optical_bus) - count_read_optical_bus_error++; - else - { - optical_read_data.data.pzad_or_wzad = 0; - optical_read_data.data.angle_pwm = 0; - optical_read_data.data.iq_zad_i_zad = 0; - optical_read_data.data.cmd.all = 0; - flag_finish_read = 1; - } - } - - - if (optbus_status.bit.old_data) - { - -// prev_error_read = 1; - - flag_finish_read = 1; - - if (optical_read_data.count_read_optical_bus_old_data<=max_count_read_old_data_optical_bus) - optical_read_data.count_read_optical_bus_old_data++; - else - { - optical_read_data.data.pzad_or_wzad = 0; - optical_read_data.data.angle_pwm = 0; - optical_read_data.data.iq_zad_i_zad = 0; - optical_read_data.data.cmd.all = 0; - } - } - - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - if (optbus_status.bit.new_data_ready) - { - PWM_LINES_TK_18_ON; - } -#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12) - { - // PWM_LINES_TK_16_ON; - } -#endif - - } - -// -// -// if (flag_finish_read) -// { -// flag_enable_write = 1; -// count_wait_write = 10; -// } - - - if (flag_enable_write) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_20_ON; -#endif -#if(_ENABLE_PWM_LINES_FOR_TESTS) - static unsigned int ccc = 0; - ccc++; - optical_write_data.data.angle_pwm = ccc; -#endif - optical_bus_write(); - - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_20_OFF; -#endif - flag_enable_write = 0; - } -// -// if (count_wait_write) -// { -// count_wait_write--; -// } -// else -// flag_finish_write = 1; -// -// -// -//// read -// -// if (optical_read_data.timer==(t_read_optbus-1)) -// prev_error_read = 1; -// else -// if (optical_read_data.timer==t_read_optbus || prev_error_read==1) -// { -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_18_OFF; -//#endif -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_19_ON; -//#endif -// -// project.cds_tk[3].read_pbus(&project.cds_tk[3]); -// -// optbus_status = optical_bus_get_status_and_read(); -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_19_OFF; -//#endif -// cc++; -// -// if (optbus_status.bit.new_data_ready) -// { -// -// prev_error_read = 0; -// -// if (optical_read_data.data_was_update_between_pwm_int<10000) -// optical_read_data.data_was_update_between_pwm_int += 1; -// -// count_read_optical_bus_error = 0; -// } -// -// if (optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 ) -// { -// -// prev_error_read = 1; -// -// if (count_read_optical_bus_error<=max_count_read_error_optical_bus) -// count_read_optical_bus_error++; -// else -// { -// optical_read_data.data.pzad_or_wzad = 0; -// optical_read_data.data.angle_pwm = 0; -// optical_read_data.data.iq_zad_i_zad = 0; -//// optical_read_data.data.cmd.all = 0x40; // временно! alarm = 1 -// optical_read_data.data.cmd.all = 0; -// } -// } -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// if (optbus_status.bit.new_data_ready) -// { -// PWM_LINES_TK_18_ON; -// } -//#endif -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12) -// { -// // PWM_LINES_TK_16_ON; -// } -//#endif -// -// } -// -// -// -// -//// write -// -// if (optical_read_data.timer==t_write_optbus) -// { -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_20_ON; -//#endif -// -// optical_bus_write(); -// -// -//#if(_ENABLE_PWM_LINES_FOR_TESTS) -// PWM_LINES_TK_20_OFF; -//#endif -// } - - - -// finish - -// if (optical_read_data.timer>=t_finish_optbus) -// { -// optical_read_data.timer = 0; -// } - -// if (prev_error_read==0) -// i_led2_off(); - - -// if (optical_read_data.timer==t2) -// { -// -// // if (edrk.flag_second_PCH==0) -// stage_2 = 1; -// // else -// // stage_1 = 1; -// -// optical_read_data.timer = 0; -// } - -// if (optical_read_data.timer>=t3) -// { -// optical_read_data.timer = 0; -// } - - - - - -// -// if (stage_1==2 && prev_stage1!=stage_1) -// { -// // i_led2_on(); -//// if (flag_disable_resend==0) -//// { -// // if (edrk.ms.another_bs_maybe_on==1 && (edrk.auto_master_slave.local.bits.master ) ) -// -// // if (edrk.flag_second_PCH==0) -// { -// i_led2_on(); -// i_led2_off(); -// i_led2_on(); -// -// optical_bus_write(); -// } -//// else -//// { -//// i_led2_on(); -//// -//// optical_bus_read(); -//// optbus_status = optical_bus_get_status_and_read(); -//// buf_status[cc] = optbus_status; -//// cc++; -//// -//// if (optbus_status.bit.new_data_ready) -//// optical_read_data.data_was_update_between_pwm_int = 1; -//// -//// if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 -//// ) -//// { -//// i_led1_on(); -//// i_led1_off(); -//// -//// } -//// -//// } -// stage_1 = 0; -// } - -// if (stage_1==1 && prev_stage1!=stage_1) -// { -// -//// if (edrk.flag_second_PCH==1) -//// { -//// i_led2_on(); -//// i_led2_off(); -//// i_led2_on(); -//// -//// optical_bus_write(); -//// } -//// else -// // { -// i_led2_on(); -// -// optical_bus_read(); -// optbus_status = optical_bus_get_status_and_read(); -// buf_status[cc] = optbus_status; -// cc++; -// -// if (optbus_status.bit.new_data_ready) -// optical_read_data.data_was_update_between_pwm_int = 1; -// -// if (optbus_status.bit.receiver_busy || optbus_status.bit.receiver_error || optbus_status.bit.bad_status12 -// ) -// { -// i_led1_on(); -// i_led1_off(); -// -// } -// -// // } -// -// -// // stage_1 = 0; -// } - - // prev_stage1 = stage_1; - // } -// if (edrk.flag_second_PCH==1) -// { -// i_led2_off(); -// } - -//i_led2_on_off(0); - -//#if (ENABLE_LOG_INTERRUPTS) -// add_log_interrupts(102); -//#endif - -#if(_ENABLE_PWM_LINES_FOR_TESTS) - PWM_LINES_TK_17_OFF; -#endif - - -} -/////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// - - diff --git a/Inu/Src2/551/main/optical_bus_tools.h b/Inu/Src2/551/main/optical_bus_tools.h deleted file mode 100644 index 89c6bc6..0000000 --- a/Inu/Src2/551/main/optical_bus_tools.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * optical_bus_tools.h - * - * Created on: 19 авг. 2024 г. - * Author: user - */ - -#ifndef SRC_MAIN_OPTICAL_BUS_TOOLS_H_ -#define SRC_MAIN_OPTICAL_BUS_TOOLS_H_ - -void optical_bus_read_write_interrupt(void); - - -#endif /* SRC_MAIN_OPTICAL_BUS_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/params.h b/Inu/Src2/551/main/params.h deleted file mode 100644 index 7abc592..0000000 --- a/Inu/Src2/551/main/params.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef _PARAMS -#define _PARAMS - - -#if(_FLOOR6) - - -#define _ENABLE_PWM_LINES_FOR_TESTS 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 - -#else - -#define _ENABLE_PWM_LINES_FOR_TESTS 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0 -#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 -#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 -#endif - - -#if(_FLOOR6) -#define MODE_DISABLE_ENABLE_WDOG 1 // 0 - wdog работает, 1 - запрещен -#else -#define MODE_DISABLE_ENABLE_WDOG 0 // 0 - wdog работает, 1 - запрещен -#endif - - - - - - -#define CHECK_IN_OUT_TERMINAL 1 - -#define WORK_ON_STEND_D 0//1 - - - -//////////////////////////////////////////////////////////////////// -#ifndef MODE_DISABLE_ENABLE_WDOG -#define MODE_DISABLE_ENABLE_WDOG 0 -#endif - - -#ifndef CHECK_IN_OUT_TERMINAL -#define CHECK_IN_OUT_TERMINAL 0 -#endif - -#ifndef WORK_ON_STEND_D -#define WORK_ON_STEND_D 0 -#endif - - - -/*************************************************************************************/ -//#define BAN_ROTOR_REVERS_DIRECT 1 - -//#define TIME_PAUSE_ZADATCHIK 750//500 - -//#define TIME_SET_LINE_RELAY_FAN 3000 // времЯ подачи импульса на реле включение выключение вентилЯтора -//#define LEVEL_FAN_ON_TEMPER_ACDRIVE 1400 //уровень включениЯ вентилЯтора охлаждениЯ двигателЯ -//#define LEVEL_FAN_OFF_TEMPER_ACDRIVE 1200 //уровень выключениЯ вентилЯтора охлаждениЯ двигателЯ -//(должен быть меньше LEVEL_FAN_ON_TEMPER_ACDRIVE с запасом на гестирезис ~20 градусов ) -//#define TIME_SET_LINE_RELAY_FAN 3000 //времЯ подачи импульса на реле включение выключение вентилЯтора - -/* -#define MAX_TIME_DIRECT_ROTOR 5000 // макс. значение счетчика на определение направлениЯ вращениЯ -#define MIN_TIME_DIRECT_ROTOR -5000 // минимальное значение счетчика на определение направлениЯ вращениЯ - -#define LEVEL_FORWARD_TIME_DIRECT_ROTOR 4000 // значение счетчика которое считаетсЯ что направление вперед -#define LEVEL_BACK_TIME_DIRECT_ROTOR -4000 // значение счетчика которое считаетсЯ что направление назад - -#define MAX_TIME_ERROR_ROTOR 5000 // макс. значение счетчика на определение неисправности опреджелениЯ вращениЯ -#define MIN_TIME_ERROR_ROTOR 0 // мин. значение счетчика на определение неисправности опреджелениЯ вращениЯ - - -#define LEVEL_ON_ERROR_ROTOR 4000 // значение счетчика которое считаетсЯ что направление определЯетсЯ с ошибкой -#define LEVEL_OFF_ERROR_ROTOR 1000 // значение счетчика которое считаетсЯ что направление определЯетсЯ без ошибкой -*/ - - -/* -#define PID_KP_IM 0.018 //0.036 //0.018 //0.18 //0.095 // PID Kp -#define PID_KI_IM 0.08 // 0.008 // PID Ki -#define PID_KD_IM 0.0000 //100 // PID Kd -#define PID_KC_IM 0.09 // PID Kc - - -#define PID_KP_F 12//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp -#define PID_KI_F 0.00010 // 0.008 // PID Ki -#define PID_KD_F 0.000 //100 PID Kd -#define PID_KC_F 0.005 // PID Kc -//#define PID_KC_F 0.000 // PID Kc - -#define ADD_KP_DF (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) -#define ADD_KI_DF (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) -#define MAX_DELTA_pidF 2.0 -#define MIN_MZZ_FOR_DF 1761607 //(210/NORMA_MZZ) -*/ - -/* -#define Im_PREDEL 600 // предельный фазный ток при работе от сети -#define I_OUT_PREDEL -20 // предельный мин. ток потреблениy при работе от сети -#define U_IN_PREDEL 500 // предельное максимальное входное напрyжение при работе от сети - -#define IQ_NORMAL_CHARGE_UD_MAX 12163481 // 1450 V //13002342 // 1550 //_IQtoF(filter.iqU_1_long)*NORMA_ACP -#define IQ_NORMAL_CHARGE_UD_MIN 10066329 // 1200 V - - -#define U_D_MAX_ERROR_GLOBAL 17616076 // 2100 V //17196646 //2050V // 16777216 //2000V/2000*2^24 -#define U_D_MAX_ERROR 16777216 // 2000V //16357785 //1950V //15938355 //1900V/2000*2^24 - -//#define U_D_NORMA_MIN 3774873 // 450 V // 13421772 // 450 V 22.05.08 //1600V/2000*2^24 -//#define U_D_NORMA_MAX 15518924 // //15099494 //1850V/2000*2^24 - -#define U_D_MIN_ERROR 10905190 // 1300V/2000*2^24 - -#define I_IN_MAX_ERROR_GLOBAL 18454937 // 2200 A //16777216 //2000 A // 13421772 //1600 A //10905190 //1300 // 900A - -#define KOEFF_WROTOR_FILTER_SPARTAN 7//8 -#define MAX_DELTA_WROTOR_S_1_2 1 - -#define ENABLE_I_HDW_PROTECT_ON_GLOBAL 1 // разрешить отключать силовые автоматы по аппаратной токовой защите - -#define TIME_WAIT_CHARGE 2000 //5000 // 10000 -#define TIME_WAIT_CHARGE_OUT 15000 //15000 -#define TIME_SET_LINE_RELAY 10000 -#define TIME_SET_LINE_RELAY5 3000 -#define TIME_WAIT_LEVEL_QPU2 3000 -*/ - - -/* -///--------------------------- 22220 paremetrs -------------------///////// - -//////////////////////////////////////////////////////////////// -// Loaded capasitors level -#define V_CAPASITORS_LOADED_IQ 11184810 //13421772 ~ 2400V // 11184810 ~ 2000V -#define V_NOMINAL 15099494 //15099494 ~ 2700V - -// Level of nominal currents -#define I_OUT_NOMINAL_IQ 10066329 //8388608 ~ 1500A //5592405 ~ 1000A // 10066329 ~ 1800A - //11184811 ~ 2000A // 12482249 ~ 2232A // 6710886 ~ 1200A -#define I_ZPT_NOMINAL_IQ 6123683 //1095A - - - -#define NORMA_MZZ 3000 //5000 -//#define NORMA_ACP 3000 -#define DISABLE_TEST_TKAK_ON_START 1 -//#define MOTOR_STEND 1 - - -//#define FREQ_PWM 350 //401 //379 - -#ifdef MOTOR_STEND -#define POLUS 4 // число пар полюсов - -#define BPSI_NORMAL 0.9//0.7 //Hz -#define MAX_FZAD_FROM_SU 16.7 // Максимально возможно заданные обороты с ситемы ВУ Гц -#define MAX_FZAD_FROM_SU_OBOROT 1100 - -#else -#define POLUS 6 // число пар полюсов -#define BPSI_NORMAL 0.9 //Hz -#define MAX_FZAD_FROM_SU 16.7 // Максимально возможно заданные обороты с ситемы ВУ Гц -#define MAX_FZAD_FROM_SU_OBOROT 1650 -#define COS_FI 0.83 - -#endif -*/ - -#define KOEF_TEMPER_DECR_MZZ 2.0 - -#endif - - - diff --git a/Inu/Src2/551/main/pll_tools.c b/Inu/Src2/551/main/pll_tools.c deleted file mode 100644 index decc342..0000000 --- a/Inu/Src2/551/main/pll_tools.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * pll_tools.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include "adc_tools.h" -#include "limit_power.h" -#include "pll_tools.h" - - -//#pragma DATA_SECTION(pll1, ".slow_vars") -PLL_REC pll1 = PLL_REC_DEFAULT; - - - -void init_50hz_input_net50hz(void) -{ - - //1. ИнициализациЯ - - pll1.setup.freq_run_pll = (FREQ_RUN_PLL); // частота запуска расчета Гц. - pll1.setup.rotation_u_cba = 0;//0;//1; // чередование фаз: 0 - правильное A-B-C, 1 - неправильное A-C-B - - pll1.init(&pll1); // расчет и инициализациЯ внутренних переменных - - // Конец Инициализации - -} - -void calc_pll_50hz(void) -{ - - // передача данных в алгоритм. - pll1.input.Input_U_AB = analog.iqUin_A1B1; - pll1.input.Input_U_BC = analog.iqUin_B1C1; - pll1.input.Input_U_CA = analog.iqUin_C1A1; - - // расчет, запускать с частотой указанной в setup.freq_run_pll - pll1.calc_pll(&pll1); -// Конец расчета - - -} - - -void get_freq_50hz_float(void) -{ - float int_delta_freq_test; - // 3. Получение данных у нормальном виде. - - // получение данных о частотен сети в Гц*100. - // можно вызывать реже - только длЯ получения данных. - pll1.get_freq_float(&pll1); - - if (edrk.Status_Ready.bits.preImitationReady2) - edrk.freq_50hz_1 = 5001; - else - edrk.freq_50hz_1 = pll1.output.int_freq_net; - - if (delta_freq_test>0) - { - int_delta_freq_test = _IQtoF( delta_freq_test) * pll1.setup.freq_run_pll / PI * 50.00; // freq*100 - edrk.freq_50hz_1 -= int_delta_freq_test; - } - - // - - -} - -void get_freq_50hz_iq(void) -{ - - // 3. Получение данных у нормальном виде. - - // получение данных о частотен сети в Гц*100. - // можно вызывать реже - только длЯ получения данных. - pll1.get_freq_iq(&pll1); - - if (edrk.Status_Ready.bits.preImitationReady2) - edrk.iq_freq_50hz = level_50hz; - else - edrk.iq_freq_50hz = pll1.output.iq_freq_net; - - if (delta_freq_test>0) - edrk.iq_freq_50hz -= delta_freq_test; - - // - - -} - diff --git a/Inu/Src2/551/main/pll_tools.h b/Inu/Src2/551/main/pll_tools.h deleted file mode 100644 index 1659e90..0000000 --- a/Inu/Src2/551/main/pll_tools.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * pll_tools.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_PLL_TOOLS_H_ -#define SRC_MAIN_PLL_TOOLS_H_ - - -#define FREQ_RUN_PLL (2*FREQ_PWM) - - -void get_freq_50hz_float(void); -void get_freq_50hz_iq(void); -void calc_pll_50hz(void); -void init_50hz_input_net50hz(void); - -extern PLL_REC pll1; - -#endif /* SRC_MAIN_PLL_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/pwm_logs.c b/Inu/Src2/551/main/pwm_logs.c deleted file mode 100644 index 42ca3e7..0000000 --- a/Inu/Src2/551/main/pwm_logs.c +++ /dev/null @@ -1,476 +0,0 @@ -/* - * pwm_logs.c - * - * Created on: 19 авг. 2024 г. - * Author: user - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "global_time.h" -#include "IQmathLib.h" -#include "oscil_can.h" -#include "uf_alg_ing.h" -#include "MemoryFunctions.h" -#include "RS_Functions.h" -#include "v_rotor_22220.h" -#include "log_to_memory.h" -#include "log_params.h" -#include "logs_hmi.h" -#include "vector_control.h" - - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -#pragma CODE_SECTION(prepare_data_to_logs,".fast_run"); -unsigned int prepare_data_to_logs(void) -{ - logsdata.logs[0] = (int16) global_time.total_seconds10full;// = 0;//(int16)(_IQtoIQ15(Izad)); - logsdata.logs[1] = (int16) _IQtoIQ15(analog.iqIu_1); - logsdata.logs[2] = (int16) _IQtoIQ15(analog.iqIv_1); - logsdata.logs[3] = (int16) _IQtoIQ15(analog.iqIw_1); - - logsdata.logs[4] = (int16) _IQtoIQ15(analog.iqIu_2); - logsdata.logs[5] = (int16) _IQtoIQ15(analog.iqIv_2); - logsdata.logs[6] = (int16) _IQtoIQ15(analog.iqIw_2); - - logsdata.logs[7] = (int16) _IQtoIQ15(analog.iqUin_A1B1);// (int16) _IQtoIQ15(analog.iqUin_m1); - logsdata.logs[8] = (int16) _IQtoIQ15(analog.iqUin_A2B2);// (int16) _IQtoIQ15(analog.iqUin_m2); - - - logsdata.logs[9] = (int16) _IQtoIQ15(analog.iqU_1); - logsdata.logs[10] = (int16) _IQtoIQ15(analog.iqU_2);//11 - - logsdata.logs[11] = (int16) _IQtoIQ15(analog.iqIin_1); - logsdata.logs[12] = (int16) _IQtoIQ15(analog.iqIin_2); - - logsdata.logs[13] = (int16) _IQtoIQ15(analog.iqIm_1); - logsdata.logs[14] = (int16) _IQtoIQ15(analog.iqIm_2); - - logsdata.logs[15] = (int16) _IQtoIQ15(analog.iqIbreak_1);//(int16) _IQtoIQ15(filter.iqU_1_long); - logsdata.logs[16] = (int16) _IQtoIQ15(analog.iqIbreak_2);//(int16) _IQtoIQ15(filter.iqU_2_long); - - - logsdata.logs[17] = (int16)svgen_pwm24_1.Ta_0; - logsdata.logs[18] = (int16)svgen_pwm24_1.Ta_1; - logsdata.logs[19] = (int16)break_result_1; - logsdata.logs[20] = (int16)break_result_2; -// logpar.log21 = (int16)svgen_pwm24_1.Tb_1; -// logpar.log22 = (int16)svgen_pwm24_1.Tc_0; -// logpar.log23 = (int16)svgen_pwm24_1.Tc_1; //23 - - logsdata.logs[21] = (int16)(_IQtoIQ14(edrk.iq_power_kw_full_znak));// edrk.from_uom.iq_level_value_kwt - //(int16) _IQtoIQ15(rotor_22220.iqFdirty); - // - - logsdata.logs[22] = (int16) _IQtoIQ15(WRotor.iqWRotorSumFilter2); - logsdata.logs[23] = (int16) _IQtoIQ15(WRotor.iqWRotorSumFilter);//WRotor.iqWRotorSumFilter WRotor.iqWRotorSum - logsdata.logs[24] = (int16) _IQtoIQ15(simple_scalar1.iq_decr_mzz_power);//WRotor.iqWRotorSumFilter2 WRotor.iqWRotorSumFilter3 - - logsdata.logs[25] = (int16) edrk.from_uom.level_value;// (int16) _IQtoIQ15(WRotor.iqWRotorSumFilter); -// logpar.log25 = (int16) _IQtoIQ15(WRotor.iqWRotorSumFilter); -// logsdata.logs[25] = (int16) _IQtoIQ15(WRotor.iqWRotorSum); - - logsdata.logs[26] = (int16) edrk.power_limit.all;//_IQtoIQ15(pll1.vars.pll_Uq); - logsdata.logs[27] = (int16)(_IQtoIQ14(edrk.zadanie.iq_limit_power_zad));//(int16) _IQtoIQ15(pll1.vars.pll_Ud);//28 - - logsdata.logs[28] = (int16) _IQtoIQ12(edrk.master_theta);//29 - logsdata.logs[29] = (int16) _IQtoIQ15(edrk.master_Uzad);//30 - logsdata.logs[30] = (int16) _IQtoIQ14(edrk.f_stator); - logsdata.logs[31] = (int16) _IQtoIQ12(edrk.k_stator1); - - logsdata.logs[32] = optical_read_data.data.cmd.all; - logsdata.logs[33] = optical_read_data.data.pzad_or_wzad; - logsdata.logs[34] = optical_read_data.data.angle_pwm; - logsdata.logs[35] = optical_read_data.data.iq_zad_i_zad; - - logsdata.logs[36] = optical_write_data.data.cmd.all; - logsdata.logs[37] = optical_write_data.data.angle_pwm; - logsdata.logs[38] = optical_write_data.data.pzad_or_wzad; - logsdata.logs[39] = optical_write_data.data.iq_zad_i_zad; - - ///////////// - logsdata.logs[40] = (int16)(_IQtoIQ15(simple_scalar1.Izad)); - logsdata.logs[41] = (int16)(_IQtoIQ15(simple_scalar1.mzz_zad_in2));//(int16)(_IQtoIQ15(Uze_t1)); - logsdata.logs[42] = (int16)(_IQtoIQ15(simple_scalar1.pidF.OutMax)); - logsdata.logs[43] = (int16)(_IQtoIQ15(simple_scalar1.mzz_zad_int)); - logsdata.logs[44] = (int16)(_IQtoIQ15(simple_scalar1.Izad_from_master)); - - logsdata.logs[45] = (int16)(_IQtoIQ14(simple_scalar1.pidF.Fdb)); - logsdata.logs[46] = (int16)(_IQtoIQ14(simple_scalar1.pidF.Ref)); - logsdata.logs[47] = (int16)(_IQtoIQ14(simple_scalar1.pidF.Ui)); - logsdata.logs[48] = (int16)(_IQtoIQ14(simple_scalar1.pidF.Up)); - logsdata.logs[49] = (int16)(_IQtoIQ14(simple_scalar1.pidF.SatErr)); - logsdata.logs[50] = (int16)(_IQtoIQ14(simple_scalar1.pidF.Out)); - - logsdata.logs[51] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.Fdb)); - logsdata.logs[52] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.Ref)); - logsdata.logs[53] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.Ui)); - logsdata.logs[54] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.Up)); - logsdata.logs[55] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.SatErr)); - logsdata.logs[56] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.Out)); - - logsdata.logs[57] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Fdb)); - logsdata.logs[58] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Ref)); - logsdata.logs[59] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Ui)); - logsdata.logs[60] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Up)); - logsdata.logs[61] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.SatErr)); - logsdata.logs[62] = (int16)(_IQtoIQ15(simple_scalar1.pidIm1.Out)); - logsdata.logs[63] = (int16)(_IQtoIQ12(simple_scalar1.Uze_t1)); - - logsdata.logs[64] = (int16)(_IQtoIQ15(simple_scalar1.bpsi_curent)); - - logsdata.logs[65] = (int16)(_IQtoIQ14(simple_scalar1.iqKoefOgran)); - - logsdata.logs[66] = (int16)(_IQtoIQ14(simple_scalar1.Fz)); - logsdata.logs[67] = (int16) (_IQtoIQ15(simple_scalar1.iq_decr_mzz_power_filter));//rotor_22220.direct_rotor - - logsdata.logs[68] = (int16)(_IQtoIQ14(simple_scalar1.pidF.OutMin));//(int16)edrk.Status_Sbor; - logsdata.logs[69] = (int16)(_IQtoIQ14(simple_scalar1.pidPower.OutMax));//(int16)edrk.Stage_Sbor; - logsdata.logs[70] = (int16)(_IQtoIQ14(filter.iqUin_m1));//(int16)edrk.Sbor_Mode; - - logsdata.logs[71] = (int16)edrk.from_shema.all; - logsdata.logs[72] = (int16)(_IQtoIQ15(simple_scalar1.iqKoefOgranIzad));//(int16)edrk.from_shema_filter.all; -// - logsdata.logs[73] = (int16)(_IQtoIQ14(filter.iqUin_m2));//simple_scalar1.direction; - logsdata.logs[74] = (int16)(_IQtoIQ14(edrk.iq_power_kw_full_filter_znak));// - logsdata.logs[75] = (int16)(_IQtoIQ15(edrk.iq_freq_50hz));//edrk.iq_freq_50hz - logsdata.logs[76] = (int16)(_IQtoIQ15(simple_scalar1.mzz_zad_in1)); - - - - // can regs -// logsdata.logs[77] = (int16)(((unsigned long)edrk.canes_reg >> 16) & 0x1ff); -// logsdata.logs[78] = (int16)((unsigned long)edrk.canes_reg & 0x3f); -// -// logsdata.logs[79] = (int16)(edrk.cantec_reg & 0xff); -// logsdata.logs[80] = (int16)(edrk.canrec_reg & 0xff); - - logsdata.logs[77] = (int16)(_IQtoIQ14(uf_alg.Ud)); - logsdata.logs[78] = (int16)(_IQtoIQ14(uf_alg.Uq)); - logsdata.logs[79] = (int16)(_IQtoIQ14(edrk.all_limit_koeffs.uom_limit));//edrk.MasterSlave; - - logsdata.logs[80] = (int16)(_IQtoIQ14(edrk.Kplus)); - -// logsdata.logs[65] = (int16)(_IQtoIQ14(edrk.all_limit_koeffs.temper_limit)); - logsdata.logs[81] = (int16)(_IQtoIQ14(edrk.all_limit_koeffs.uin_freq_limit)); - - logsdata.logs[82] = (int16)(_IQtoIQ14(uf_alg.svgen_dq_Ta)); - logsdata.logs[83] = (int16)(_IQtoIQ14(uf_alg.svgen_dq_Tb)); - logsdata.logs[84] = (int16)(_IQtoIQ14(uf_alg.svgen_dq_Tc)); - - // uf_alg.tetta_bs - - // logsdata.logs[64] = (int16)(_IQtoIQ15()); - -// logsdata.logs[64] = (int16)(_IQtoIQ15()); - - logsdata.logs[85] = edrk.from_uom.digital_line.all; -// logsdata.logs[75] = edrk.errors.e2.all; -// logsdata.logs[76] = edrk.errors.e3.all; -// logsdata.logs[77] = edrk.errors.e4.all; -// logsdata.logs[78] = edrk.errors.e5.all; -// logsdata.logs[79] = edrk.errors.e6.all; -// logsdata.logs[80] = edrk.errors.e7.all; -// - - - - -// logsdata.logs[67] = (int16) _IQtoIQ15(WRotor.iqWRotorCalcBeforeRegul1); -// logsdata.logs[68] = (int16) _IQtoIQ15(WRotor.iqWRotorCalcBeforeRegul2); -// logsdata.logs[69] = (int16) _IQtoIQ15(WRotor.iqWRotorCalc1); - -// logsdata.logs[24] = (int16) _IQtoIQ15(WRotor.iqWRotorCalc2); - -// logsdata.logs[70] = (int16) _IQtoIQ15(WRotor.iqWRotorSumRamp); - -// logsdata.logs[72] = (int16) (WRotorPBus.RotorDirectionSlow); - // logsdata.logs[73] = (int16) (WRotorPBus.RotorDirectionSlow2); - // logsdata.logs[74] = (int16) (WRotorPBus.RotorDirectionInstant); //(int16) (WRotorPBus.); - -// logsdata.logs[75] = (int16) (WRotor.iqTimeSensor1); -// logsdata.logs[76] = (int16) (WRotor.iqTimeSensor2); -// -// logsdata.logs[77] = (int16) _IQtoIQ15(WRotor.iqWRotorCalc1Ramp); -// logsdata.logs[78] = (int16) _IQtoIQ15(WRotor.iqWRotorCalc2Ramp); -// -// logsdata.logs[79] = (int16) _IQtoIQ15(WRotor.iqPrevWRotorCalc1); -// logsdata.logs[80] = (int16) _IQtoIQ15(WRotor.iqPrevWRotorCalc2); - -// logsdata.logs[81] = (int16) modbus_table_can_in[124].all;//Обороты (заданные); -// logsdata.logs[82] = (int16) modbus_table_can_in[134].all;//запас мощности -// logsdata.logs[83] = (int16) modbus_table_can_in[125].all;//Мощность (заданная) -// -// logsdata.logs[84] = (int16) project.cds_in[0].read.pbus.data_in.all; -// logsdata.logs[85] = (int16) project.cds_in[1].read.pbus.data_in.all; - - logsdata.logs[86] = (int16) _IQtoIQ15(vect_control.iqId1); - logsdata.logs[87] = (int16) _IQtoIQ15(vect_control.iqIq1); - - logsdata.logs[88] = (int16) _IQtoIQ15(vect_control.iqId2); - logsdata.logs[89] = (int16) _IQtoIQ15(vect_control.iqIq2); - logsdata.logs[90] = 0; - - return 90; -} - - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////// - -#define PAUSE_SLOW_LOG 20 - -void save_slow_logs(int run, int t_slow) -{ - static int c_step=0; -// static int c_all = (FREQ_PWM>>2); // Раз в 0,125 с - static int c_all = (FREQ_PWM>>1); // Раз в 0,250 с - - static int prev_run=0; - static unsigned int c_pause=0; - - if (rs_a.RS_PrevCmd==CMD_RS232_UPLOAD) - return; - - if (run==0 && c_pause>=PAUSE_SLOW_LOG) - return; - - c_all = (FREQ_PWM>>(1+t_slow)); - - if (c_all<2) - c_all = 2; - - - if (c_step>=c_all) - { - test_mem_limit(SLOW_LOG, 1); - - // prepare_data_to_logs(); - - getSlowLogs(1); - c_step = 0; - - if (run==1) - c_pause = 0; - else - { - if (c_pause= 1)//1 - { - count_step_run++; - // i_led1_on_off(1); -// write_to_mem(FAST_LOG, (int16)count_step_run); - - getFastLogs(!f.Ciclelog); -// for (i_log=0;i_log<72;i_log++) -// write_to_mem(FAST_LOG, (int16) logsdata.logs[i_log]); - -// write_to_mem(FAST_LOG, (int16) logpar.log85); - - - -// if (logpar.start_write_fast_log) { -// get_log_params_count(); -// logpar.start_write_fast_log = 0; -// } - count_step = 0; - } - } - else { - if (f.Stop && log_params.log_saved_to_const_mem == 0) { - log_params.copy_log_to_const_memory = 1; - log_params.log_saved_to_const_mem = 1; - f.flag_send_alarm_log_to_MPU = 1; - } - } - - -#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) - PWM_LINES_TK_23_OFF; -#endif - - if (filter.iqU_1_long>edrk.iqMIN_U_ZPT || filter.iqU_2_long>edrk.iqMIN_U_ZPT) - local_enable_slow_log = 1; - else - local_enable_slow_log = 0; - - if (edrk.stop_logs_rs232 == 0 && edrk.stop_slow_log ==0 && log_to_HMI.send_log == 0) - save_slow_logs(edrk.Go || (local_enable_slow_log && edrk.Status_Ready.bits.ready_final==0), edrk.t_slow_log); -} -////////////////////////////////////////////////////////////////// - - - - diff --git a/Inu/Src2/551/main/pwm_logs.h b/Inu/Src2/551/main/pwm_logs.h deleted file mode 100644 index 8eb5f07..0000000 --- a/Inu/Src2/551/main/pwm_logs.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * pwm_logs.h - * - * Created on: 19 авг. 2024 г. - * Author: user - */ - -#ifndef SRC_MAIN_PWM_LOGS_H_ -#define SRC_MAIN_PWM_LOGS_H_ - -unsigned int prepare_data_to_logs(void); -void save_slow_logs(int run, int t_slow); -void run_write_logs(void); - - -#endif /* SRC_MAIN_PWM_LOGS_H_ */ diff --git a/Inu/Src2/551/main/ramp_zadanie_tools.c b/Inu/Src2/551/main/ramp_zadanie_tools.c deleted file mode 100644 index 61a6689..0000000 --- a/Inu/Src2/551/main/ramp_zadanie_tools.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * ramp_zadanie_tools.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - - - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include "ramp_zadanie_tools.h" -#include "v_rotor.h" - - - -void change_ramp_zadanie(void) -{ - _iq rampafloat, rampafloat_plus, rampafloat_minus; - - if (edrk.cmd_very_slow_start) - { - rampafloat_plus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS)); - edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus1 = rampafloat_plus; - edrk.zadanie.rmp_oborots_zad_hz.PosRampMinus1 = -rampafloat_minus; - - edrk.zadanie.rmp_oborots_zad_hz.NegRampPlus1 = rampafloat_minus; - edrk.zadanie.rmp_oborots_zad_hz.NegRampMinus1 = -rampafloat_plus; - -// rampafloat_plus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS)); -// rampafloat_minus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_SLOW_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS)); - edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus2 = rampafloat_plus; - edrk.zadanie.rmp_oborots_zad_hz.PosRampMinus2 = -rampafloat_minus; - - edrk.zadanie.rmp_oborots_zad_hz.NegRampPlus2 = rampafloat_minus; - edrk.zadanie.rmp_oborots_zad_hz.NegRampMinus2 = -rampafloat_plus; - } - else - { - rampafloat_plus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS)); - edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus1 = rampafloat_plus; - edrk.zadanie.rmp_oborots_zad_hz.PosRampMinus1 = -rampafloat_minus; - - edrk.zadanie.rmp_oborots_zad_hz.NegRampPlus1 = rampafloat_minus; - edrk.zadanie.rmp_oborots_zad_hz.NegRampMinus1 = -rampafloat_plus; - - rampafloat_plus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_OBOROTS_ROTOR_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_OBOROTS_ROTOR_MINUS)); - edrk.zadanie.rmp_oborots_zad_hz.PosRampPlus2 = rampafloat_plus; - edrk.zadanie.rmp_oborots_zad_hz.PosRampMinus2 = -rampafloat_minus; - - edrk.zadanie.rmp_oborots_zad_hz.NegRampPlus2 = rampafloat_minus; - edrk.zadanie.rmp_oborots_zad_hz.NegRampMinus2 = -rampafloat_plus; - - } - -} - -void init_ramp_all_zadanie(void) -{ - _iq rampafloat, rampafloat_plus, rampafloat_minus; - -//rmp_oborots_imitation - edrk.zadanie.rmp_oborots_imitation.RampLowLimit = _IQ(MIN_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); - edrk.zadanie.rmp_oborots_imitation.RampHighLimit = _IQ(MAX_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); - rampafloat = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_IMITATION_OBOROTS_ROTOR)); - edrk.zadanie.rmp_oborots_imitation.RampPlus = rampafloat; - edrk.zadanie.rmp_oborots_imitation.RampMinus = -rampafloat; - - edrk.zadanie.rmp_oborots_imitation.Out = 0; - edrk.zadanie.rmp_oborots_imitation.DesiredInput = 0; - -// rmp_fzad - edrk.zadanie.rmp_fzad.RampLowLimit = _IQ(-MAX_ZADANIE_F/NORMA_FROTOR); //0 - edrk.zadanie.rmp_fzad.RampHighLimit = _IQ(MAX_ZADANIE_F/NORMA_FROTOR); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_F)); - rampafloat = _IQ((MAX_ZADANIE_F/NORMA_FROTOR)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_F)); - edrk.zadanie.rmp_fzad.RampPlus = rampafloat; - edrk.zadanie.rmp_fzad.RampMinus = -rampafloat; - - edrk.zadanie.rmp_fzad.DesiredInput = 0; - edrk.zadanie.rmp_fzad.Out = 0; - -// rmp_oborots_hz - edrk.zadanie.rmp_oborots_zad_hz.RampLowLimit = _IQ(MIN_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); //0 - edrk.zadanie.rmp_oborots_zad_hz.RampHighLimit = _IQ(MAX_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); - - edrk.zadanie.rmp_oborots_zad_hz.RampLowLimit1 = _IQ(MIN_1_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); //0 - edrk.zadanie.rmp_oborots_zad_hz.RampHighLimit1 = _IQ(MAX_1_ZADANIE_OBOROTS_ROTOR/60.0/NORMA_FROTOR); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_OBOROTS_ROTOR)); -// rampafloat = _IQ((MAX_ZADANIE_OBOROTS_ROTOR/NORMA_FROTOR/60.0)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_OBOROTS_ROTOR)); -// edrk.zadanie.rmp_oborots_zad_hz.RampPlus = rampafloat; -// edrk.zadanie.rmp_oborots_zad_hz.RampMinus = -rampafloat; - - change_ramp_zadanie(); - - edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; - edrk.zadanie.rmp_oborots_zad_hz.Out = 0; - - -// - edrk.zadanie.rmp_Izad.RampLowLimit = _IQ(0); //0 - edrk.zadanie.rmp_Izad.RampHighLimit = _IQ(MAX_ZADANIE_I_M/NORMA_ACP); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_I_M)); - rampafloat = _IQ((MAX_ZADANIE_I_M/NORMA_ACP)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_I_M)); - edrk.zadanie.rmp_Izad.RampPlus = rampafloat; - edrk.zadanie.rmp_Izad.RampMinus = -rampafloat; - - edrk.zadanie.rmp_Izad.DesiredInput = 0; - edrk.zadanie.rmp_Izad.Out = 0; - -// - edrk.zadanie.rmp_ZadanieU_Charge.RampLowLimit = _IQ(0); //0 - edrk.zadanie.rmp_ZadanieU_Charge.RampHighLimit = _IQ(MAX_ZADANIE_U_CHARGE/NORMA_ACP); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_U_CHARGE)); - rampafloat = _IQ((MAX_ZADANIE_U_CHARGE/NORMA_ACP)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_U_CHARGE)); - edrk.zadanie.rmp_ZadanieU_Charge.RampPlus = rampafloat; - edrk.zadanie.rmp_ZadanieU_Charge.RampMinus = -rampafloat; - - edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = _IQ(NOMINAL_U_ZARYAD/NORMA_ACP); - edrk.zadanie.rmp_ZadanieU_Charge.Out = _IQ(NOMINAL_U_ZARYAD/NORMA_ACP); - - - -// - edrk.zadanie.rmp_k_u_disbalance.RampLowLimit = _IQ(0); //0 - edrk.zadanie.rmp_k_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_K_U_DISBALANCE); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_K_U_DISBALANCE)); - rampafloat = _IQ((MAX_ZADANIE_K_U_DISBALANCE)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_K_U_DISBALANCE)); - edrk.zadanie.rmp_k_u_disbalance.RampPlus = rampafloat; - edrk.zadanie.rmp_k_u_disbalance.RampMinus = -rampafloat; - - edrk.zadanie.rmp_k_u_disbalance.DesiredInput = 0; - edrk.zadanie.rmp_k_u_disbalance.Out = 0; - - -// - edrk.zadanie.rmp_kplus_u_disbalance.RampLowLimit = _IQ(0); //0 - edrk.zadanie.rmp_kplus_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_KPLUS_U_DISBALANCE); - -// rampafloat = _IQ(1.0/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_KPLUS_U_DISBALANCE)); - rampafloat = _IQ((MAX_ZADANIE_KPLUS_U_DISBALANCE)/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_KPLUS_U_DISBALANCE)); - edrk.zadanie.rmp_kplus_u_disbalance.RampPlus = rampafloat; - edrk.zadanie.rmp_kplus_u_disbalance.RampMinus = -rampafloat; - - edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = 0; - edrk.zadanie.rmp_kplus_u_disbalance.Out = 0; - - - -// - edrk.zadanie.rmp_kzad.RampLowLimit = _IQ(0); //0 - edrk.zadanie.rmp_kzad.RampHighLimit = _IQ(MAX_ZADANIE_K_M); - -// rampafloat = _IQ(1.0/(2.0*FREQ_PWM*T_NARAST_ZADANIE_K_M)); - rampafloat = _IQ((MAX_ZADANIE_K_M)/(2.0*FREQ_PWM*T_NARAST_ZADANIE_K_M)); - edrk.zadanie.rmp_kzad.RampPlus = rampafloat; - edrk.zadanie.rmp_kzad.RampMinus = -rampafloat; - - edrk.zadanie.rmp_kzad.DesiredInput = 0; - edrk.zadanie.rmp_kzad.Out = 0; - - -// - edrk.zadanie.rmp_powers_zad.RampLowLimit = _IQ(MIN_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); //0 - edrk.zadanie.rmp_powers_zad.RampHighLimit = _IQ(MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - - edrk.zadanie.rmp_powers_zad.RampLowLimit1 = _IQ(MIN_1_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - edrk.zadanie.rmp_powers_zad.RampHighLimit1 = _IQ(MAX_1_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - -// rampafloat = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_POWER)); -// edrk.zadanie.rmp_powers_zad.RampPlus = rampafloat; -// edrk.zadanie.rmp_powers_zad.RampMinus = -rampafloat; - - -//// - rampafloat_plus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_POWER_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_POWER_MINUS)); - - edrk.zadanie.rmp_powers_zad.PosRampPlus1 = rampafloat_plus; - edrk.zadanie.rmp_powers_zad.PosRampMinus1 = -rampafloat_minus; - - edrk.zadanie.rmp_powers_zad.NegRampPlus1 = rampafloat_minus; - edrk.zadanie.rmp_powers_zad.NegRampMinus1 = -rampafloat_plus; - - rampafloat_plus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_POWER_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_POWER_MINUS)); - - edrk.zadanie.rmp_powers_zad.PosRampPlus2 = rampafloat_plus; - edrk.zadanie.rmp_powers_zad.PosRampMinus2 = -rampafloat_minus; - - edrk.zadanie.rmp_powers_zad.NegRampPlus2 = rampafloat_minus; - edrk.zadanie.rmp_powers_zad.NegRampMinus2 = -rampafloat_plus; - -//// - - edrk.zadanie.rmp_powers_zad.DesiredInput = 0; - edrk.zadanie.rmp_powers_zad.Out = 0; - -// - - edrk.zadanie.rmp_limit_powers_zad.RampLowLimit = 0;//_IQ(0); //0 - edrk.zadanie.rmp_limit_powers_zad.RampHighLimit = _IQ(SUPER_MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - - edrk.zadanie.rmp_limit_powers_zad.RampLowLimit1 = 0; - edrk.zadanie.rmp_limit_powers_zad.RampHighLimit1 = _IQ(MAX_1_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - - rampafloat_plus = _IQ((SUPER_MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_LIMIT_POWER_PLUS)); - rampafloat_minus = _IQ((SUPER_MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T1_NARAST_ZADANIE_LIMIT_POWER_MINUS)); - - edrk.zadanie.rmp_limit_powers_zad.PosRampPlus1 = rampafloat_plus; - edrk.zadanie.rmp_limit_powers_zad.PosRampMinus1 = -rampafloat_minus; - - edrk.zadanie.rmp_limit_powers_zad.NegRampPlus1 = rampafloat_minus; - edrk.zadanie.rmp_limit_powers_zad.NegRampMinus1 = -rampafloat_plus; - - rampafloat_plus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_POWER_PLUS)); - rampafloat_minus = _IQ((MAX_ZADANIE_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T2_NARAST_ZADANIE_POWER_MINUS)); - - edrk.zadanie.rmp_limit_powers_zad.PosRampPlus2 = rampafloat_plus; - edrk.zadanie.rmp_limit_powers_zad.PosRampMinus2 = -rampafloat_minus; - - edrk.zadanie.rmp_limit_powers_zad.NegRampPlus2 = rampafloat_minus; - edrk.zadanie.rmp_limit_powers_zad.NegRampMinus2 = -rampafloat_plus; - -// rampafloat = _IQ((MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ))/(FREQ_RUN_RAMP*T_NARAST_ZADANIE_LIMIT_POWER)); - -// edrk.zadanie.rmp_limit_powers_zad.RampPlus = rampafloat; -// edrk.zadanie.rmp_limit_powers_zad.RampMinus = -rampafloat; - - edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; - edrk.zadanie.rmp_limit_powers_zad.Out = 0; - -// - - -} - -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// -#pragma CODE_SECTION(ramp_all_zadanie,".fast_run"); -void load_current_ramp_oborots_power(void) -{ - int mode=0; - static int prev_mode = 0; - - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || - edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_OBOROTS) - mode = 1; - - if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER || - edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER) - mode = 2; - - if (mode==1 && prev_mode==2) - { - // была мощность, а стали обороты - edrk.zadanie.rmp_oborots_zad_hz.Out = WRotor.iqWRotorSumFilter3; - //edrk.zadanie.iq_oborots_zad_hz = WRotor.iqWRotorSumFilter3; - } - - - if (mode==2 && prev_mode==1) - { - // были обороты, а стала мощность - edrk.zadanie.rmp_powers_zad.Out = edrk.iq_power_kw_one_filter_znak;//filter.PowerScalarFilter2; - } - - prev_mode = mode; - -} -////////////////////////////////////////////////////////// -#pragma CODE_SECTION(ramp_all_zadanie,".fast_run"); -void ramp_all_zadanie(int flag_set_zero) -{ - -// if (edrk.Status_Ready.bits.ImitationReady2) - { - edrk.zadanie.rmp_oborots_imitation.DesiredInput = edrk.zadanie.iq_oborots_zad_hz; - edrk.zadanie.rmp_oborots_imitation.calc(&edrk.zadanie.rmp_oborots_imitation); - edrk.zadanie.rmp_oborots_imitation_rmp = edrk.zadanie.rmp_oborots_imitation.Out; - } - ////////////////////////////////////////////// - if (flag_set_zero==0) - edrk.zadanie.rmp_Izad.DesiredInput = edrk.zadanie.iq_Izad; - else - if (flag_set_zero==2) - { - edrk.zadanie.rmp_Izad.DesiredInput = 0; - edrk.zadanie.rmp_Izad.Out = 0; - } - else - edrk.zadanie.rmp_Izad.DesiredInput = 0; - - edrk.zadanie.rmp_Izad.calc(&edrk.zadanie.rmp_Izad); - edrk.zadanie.iq_Izad_rmp = edrk.zadanie.rmp_Izad.Out; - ////////////////////////////////////////////// - edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = edrk.zadanie.iq_ZadanieU_Charge; - edrk.zadanie.rmp_ZadanieU_Charge.calc(&edrk.zadanie.rmp_ZadanieU_Charge); - edrk.zadanie.iq_ZadanieU_Charge_rmp = edrk.zadanie.rmp_ZadanieU_Charge.Out; - ////////////////////////////////////////////// - if (flag_set_zero==0) - edrk.zadanie.rmp_fzad.DesiredInput = edrk.zadanie.iq_fzad; - else - if (flag_set_zero==2) - { - edrk.zadanie.rmp_fzad.DesiredInput = 0; - edrk.zadanie.rmp_fzad.Out = 0; - } - else - edrk.zadanie.rmp_fzad.DesiredInput = 0; - - edrk.zadanie.rmp_fzad.calc(&edrk.zadanie.rmp_fzad); - edrk.zadanie.iq_fzad_rmp = edrk.zadanie.rmp_fzad.Out; - ////////////////////////////////////////////// - edrk.zadanie.rmp_k_u_disbalance.DesiredInput = edrk.zadanie.iq_k_u_disbalance; - edrk.zadanie.rmp_k_u_disbalance.calc(&edrk.zadanie.rmp_k_u_disbalance); - edrk.zadanie.iq_k_u_disbalance_rmp = edrk.zadanie.rmp_k_u_disbalance.Out; - ////////////////////////////////////////////// - edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = edrk.zadanie.iq_kplus_u_disbalance; - edrk.zadanie.rmp_kplus_u_disbalance.calc(&edrk.zadanie.rmp_kplus_u_disbalance); - edrk.zadanie.iq_kplus_u_disbalance_rmp = edrk.zadanie.rmp_kplus_u_disbalance.Out; - ////////////////////////////////////////////// - if (flag_set_zero==0) - edrk.zadanie.rmp_kzad.DesiredInput = edrk.zadanie.iq_kzad; - else - if (flag_set_zero==2) - { - edrk.zadanie.rmp_kzad.DesiredInput = 0; - edrk.zadanie.rmp_kzad.Out = 0; - } - else - edrk.zadanie.rmp_kzad.DesiredInput = 0; - edrk.zadanie.rmp_kzad.calc(&edrk.zadanie.rmp_kzad); - edrk.zadanie.iq_kzad_rmp = edrk.zadanie.rmp_kzad.Out; - ////////////////////////////////////////////// - if (flag_set_zero==0) - edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = edrk.zadanie.iq_oborots_zad_hz; - else - if (flag_set_zero==2) - { - edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; - edrk.zadanie.rmp_oborots_zad_hz.Out = 0; - } - else - edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; - - edrk.zadanie.rmp_oborots_zad_hz.calc(&edrk.zadanie.rmp_oborots_zad_hz); - edrk.zadanie.iq_oborots_zad_hz_rmp = edrk.zadanie.rmp_oborots_zad_hz.Out; - - ////////////////////////////////////////////// -// if (flag_set_zero==0) -// edrk.zadanie.rmp_limit_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad; -// else -// if (flag_set_zero==2) -// { -// edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; -// edrk.zadanie.rmp_limit_powers_zad.Out = 0; -// } -// else -// edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; - - edrk.zadanie.rmp_limit_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad; - edrk.zadanie.rmp_limit_powers_zad.calc(&edrk.zadanie.rmp_limit_powers_zad); - edrk.zadanie.iq_limit_power_zad_rmp = edrk.zadanie.rmp_limit_powers_zad.Out; - - - - ////////////////////////////////////////////// - if (flag_set_zero==0) - { - if (edrk.zadanie.iq_power_zad>=0) - { - if (edrk.zadanie.iq_power_zad>edrk.zadanie.iq_limit_power_zad_rmp) - edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad_rmp; - else - edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_power_zad; - } - else - { - if (edrk.zadanie.iq_power_zad<-edrk.zadanie.iq_limit_power_zad_rmp) - edrk.zadanie.rmp_powers_zad.DesiredInput = -edrk.zadanie.iq_limit_power_zad_rmp; - else - edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_power_zad; - } - - } - else - if (flag_set_zero==2) - { - edrk.zadanie.rmp_powers_zad.DesiredInput = 0; - edrk.zadanie.rmp_powers_zad.Out = 0; - } - else - edrk.zadanie.rmp_powers_zad.DesiredInput = 0; - - edrk.zadanie.rmp_powers_zad.calc(&edrk.zadanie.rmp_powers_zad); - edrk.zadanie.iq_power_zad_rmp = edrk.zadanie.rmp_powers_zad.Out; - -} - -////////////////////////////////////////////////////////// diff --git a/Inu/Src2/551/main/ramp_zadanie_tools.h b/Inu/Src2/551/main/ramp_zadanie_tools.h deleted file mode 100644 index c90acb6..0000000 --- a/Inu/Src2/551/main/ramp_zadanie_tools.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * ramp_zadanie_tools.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_RAMP_ZADANIE_TOOLS_H_ -#define SRC_MAIN_RAMP_ZADANIE_TOOLS_H_ - -#define FREQ_RUN_RAMP FREQ_PWM // (2.0*FREQ_PWM) - - -void ramp_all_zadanie(int flag_set_zero); -void change_ramp_zadanie(void); -void init_ramp_all_zadanie(void); -void load_current_ramp_oborots_power(void); - - -#endif /* SRC_MAIN_RAMP_ZADANIE_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/sim_model.c b/Inu/Src2/551/main/sim_model.c deleted file mode 100644 index a84fa72..0000000 --- a/Inu/Src2/551/main/sim_model.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * sim_model.c - * - * Created on: 30 окт. 2024 г. - * Author: yura - */ - -#if (_SIMULATE_AC==1) - -#ifdef __TI_COMPILER_VERSION__ -#pragma SET_DATA_SECTION(".slow_vars") -#endif - -//#include "math.h" - - -#include "V_MotorModel.h" -//#include "V_MotorParams.h" -//#include -#include "IQmathLib.h" -//#include "main.h" - -#include "v_pwm24_v2.h" -#include "edrk_main.h" -#include "params_norma.h" -#include "adc_tools.h" -#include "filter_v1.h" -#include "mathlib.h" -#include "v_rotor_22220.h" - -//Модели электродвигателей для отладки в режиме симулятора -//#pragma DATA_SECTION(sim_model, ".slow_vars") -TMotorModel sim_model = MOTOR_MODEL_DEFAULTS; - - - -void sim_model_init(void) -{ - - //model.motorInternals.udc = 540; //задается через словарь объектов - - sim_model.motorInternals.udc = 540; //задается через словарь объектов - sim_model.tpr = svgen_pwm24_1.Tclosed_high;//450; //период частоты ШИМ - sim_model.cmpr0 = svgen_pwm24_1.Tclosed_high/2; - sim_model.cmpr1 = svgen_pwm24_1.Tclosed_high/2; - sim_model.cmpr2 = svgen_pwm24_1.Tclosed_high/2; - sim_model.cmpr3 = svgen_pwm24_1.Tclosed_high/2; - - - sim_model.MotorParametersNum = 10;// - sim_model.dt = 0;//_IQ4mpy(_IQ4(150 / 4), pwm.DeadBand >> 20) >> 4; //величина мертвого времени - - //Вызов функции инициализации модели двигателя - sim_model.Init(&sim_model); //Модель двигателя - - - - sim_model.Init(&sim_model); - -} - -void sim_model_execute(void) -{ - //Передача текущих скважностей таймеров ШИМ в модель - sim_model.cmpr0 = svgen_pwm24_1.Ta_imp/2 + svgen_pwm24_1.Tclosed_high/2;//PWM0->CMPA_bit.CMPA; - sim_model.cmpr1 = svgen_pwm24_1.Tb_imp/2 + svgen_pwm24_1.Tclosed_high/2;//PWM1->CMPA_bit.CMPA; - sim_model.cmpr2 = svgen_pwm24_1.Tc_imp/2 + svgen_pwm24_1.Tclosed_high/2;;//PWM2->CMPA_bit.CMPA; - - sim_model.InvertorEna = edrk.Go;//Флаг разрешения работы инвертора - - //Вызов функции основного расчета модели двигателя - sim_model.Execute(&sim_model); - -} - - -void calc_norm_ADC_0_sim(int run_norma) -{ - _iq a1,a2,a3; - -#if (1) - -#if (_FLOOR6) - analog.iqU_1 = _IQ(sim_model.motorInternals.udc/NORMA_ACP/2.0);// iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit; - analog.iqU_2 = analog.iqU_1;//iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit; -#else - analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1; - analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2; -#endif - - analog.iqIu_1 = _IQ(sim_model.motorInternals.isPhaseA/NORMA_ACP/2.0); - analog.iqIv_1 = _IQ(sim_model.motorInternals.isPhaseB/NORMA_ACP/2.0); - analog.iqIw_1 = _IQ(sim_model.motorInternals.isPhaseC/NORMA_ACP/2.0); - - analog.iqIu_2 = analog.iqIu_1; - analog.iqIv_2 = analog.iqIv_1; - analog.iqIw_2 = analog.iqIw_1; - - analog.iqIin_1 = 0;//_IQ(sim_model.motorInternals.power/sim_model.motorInternals.udc/NORMA_ACP/2.0); //-iq_norm_ADC[0][9]; // датчик перевернут - analog.iqIin_2 = analog.iqIin_1;//-iq_norm_ADC[0][9]; // датчик перевернут - - analog.iqUin_A1B1 = 0;//iq_norm_ADC[0][10]; - -// два варианта подключения датчиков 23550.1 более правильный - по схеме -// 23550.1 - - analog.iqUin_B1C1 = 0;//iq_norm_ADC[0][11]; // 23550.1 - analog.iqUin_A2B2 = 0;//iq_norm_ADC[0][12]; // 23550.1 - -// 23550.3 bs1 bs2 - -// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3 -// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3 -// - analog.iqUin_B2C2 = 0;//iq_norm_ADC[0][13]; - - analog.iqIbreak_1 = 0;//iq_norm_ADC[0][14]; - analog.iqIbreak_2 = 0;//iq_norm_ADC[0][15]; - -#else - analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 = - analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 = - analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2 - = 0; -#endif - - analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1); - analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2); - - - - filter.iqU_1_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_1_long, analog.iqU_1); - filter.iqU_2_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_2_long, analog.iqU_2); - - -// analog.iqU_1_fast = filter_U1_3point(analog.iqU_1_fast); - filter.iqU_1_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_1_fast, analog.iqU_1); - filter.iqU_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_2_fast, analog.iqU_2); - - -// filter.iqUzpt_2_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqUzpt_2_2_fast, analog.iqUzpt_2_2); - - - -//15 - - - analog.iqIm_1 = im_calc(analog.iqIu_1, analog.iqIv_1, analog.iqIw_1); - analog.iqIm_2 = im_calc(analog.iqIu_2, analog.iqIv_2, analog.iqIw_2); - - analog.iqIu = analog.iqIu_1+analog.iqIu_2; - analog.iqIv = analog.iqIv_1+analog.iqIv_2; - analog.iqIw = analog.iqIw_1+analog.iqIw_2; - - analog.iqIm = im_calc(analog.iqIu, analog.iqIv, analog.iqIw); - - - analog.iqIin_sum = analog.iqIin_1+analog.iqIin_2; - -// analog.iqIm_3 = im_calc(analog.iqIa1_1_fir_n+analog.iqIa2_1_fir_n, analog.iqIb1_1_fir_n+analog.iqIb2_1_fir_n, analog.iqIc1_1_fir_n+analog.iqIc2_1_fir_n); - - analog.iqUin_m1 = im_calc(analog.iqUin_A1B1, analog.iqUin_B1C1, analog.iqUin_C1A1); - analog.iqUin_m2 = im_calc(analog.iqUin_A2B2, analog.iqUin_B2C2, analog.iqUin_C2A2); - -// analog.iqUin_m2 = im_calc(analog.UinA2, analog.UinB2, analog.UinC2); - - filter.iqUin_m1 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m1, analog.iqUin_m1); - filter.iqUin_m2 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m2, analog.iqUin_m2); - - - -// i_led1_on_off(0); -// i_led1_on_off(1); - -//1 - - filter.iqIm_1 = exp_regul_iq(koef_Im_filter, filter.iqIm_1, analog.iqIm_1); - filter.iqIm_2 = exp_regul_iq(koef_Im_filter, filter.iqIm_2, analog.iqIm_2); - filter.iqIm = exp_regul_iq(koef_Im_filter, filter.iqIm, analog.iqIm); - - filter.iqIin_sum = exp_regul_iq(koef_Im_filter, filter.iqIin_sum, analog.iqIin_sum); - -//3 -// filter_batter2_Iin.InpVarCurr = (analog.iqIin_1)-ZERO_I_IN; - // filter_batter2_Iin.calc(&filter_batter2_Iin); - -// filter.iqIin = _IQmpy(filter_batter2_Iin.Out,_IQ_09); - - - filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1); - filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2); - - a1 = analog.iqU_1+analog.iqU_2; - a2 = analog.iqIin_1; - a3 = _IQmpy(a1,a2); - analog.PowerScalar = a3; -// filter.Power = analog.iqU_1+analog.iqU_2; - filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar); - filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar); - -} - - - -void calc_rotors_sim(void) -{ - rotor_22220.direct_rotor = 1; - rotor_22220.iqF = _IQ(sim_model.motorInternals.omega_rpm/60.0/NORMA_FROTOR); - - - rotor_22220.iqFout = exp_regul_iq(koef_Wout_filter, rotor_22220.iqFout, rotor_22220.iqF); - rotor_22220.iqFlong = exp_regul_iq(koef_Wout_filter_long, rotor_22220.iqFlong, rotor_22220.iqF); - -} - - - -//#ifdef __TI_COMPILER_VERSION__ -//#pragma RESET_DATA_SECTION -//#endif - -#endif diff --git a/Inu/Src2/551/main/sim_model.h b/Inu/Src2/551/main/sim_model.h deleted file mode 100644 index 9a27c91..0000000 --- a/Inu/Src2/551/main/sim_model.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * sim_model.h - * - * Created on: 30 окт. 2024 г. - * Author: yura - */ - -#ifndef SRC_MAIN_SIM_MODEL_H_ -#define SRC_MAIN_SIM_MODEL_H_ - -#include "V_MotorModel.h" - -void sim_model_init(void); -void sim_model_execute(void); -void calc_norm_ADC_0_sim(int run_norma); -void calc_rotors_sim(void); - - -extern TMotorModel sim_model; - -#endif /* SRC_MAIN_SIM_MODEL_H_ */ diff --git a/Inu/Src2/551/main/synhro_tools.c b/Inu/Src2/551/main/synhro_tools.c deleted file mode 100644 index 47bbc5e..0000000 --- a/Inu/Src2/551/main/synhro_tools.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * synhro_tools.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - - - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include "optical_bus.h" -#include "sync_tools.h" - -////////////////////////////////////////////////////////// -unsigned int wait_synhro_optical_bus(void) -{ - static unsigned int cmd = 0; - static unsigned int count_wait_synhro = 0; - - -// -// switch(cmd) -// { -// 0 : if (optical_read_data.data.cmd.bit.wdog_tick == 0) -// cmd = 1; -// -// break; -// -// 1 : optical_write_data.data.cmd.bit.wdog_tick = 1; -// break; -// -// -// default: break -// } - - - - return 0; -} - -////////////////////////////////////////////////////////// -void clear_wait_synhro_optical_bus(void) -{ - - // optical_read_data.data.cmd.bit.wdog_tick = 0; - // optical_write_data.data.cmd.bit.wdog_tick = 0; - -} -////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////// -void who_select_sync_signal(void) -{ - - if (sync_data.what_main_pch) - { - if (sync_data.what_main_pch==2) - { - // принудительно всегда !!! - if (edrk.flag_second_PCH) - sync_data.enable_do_sync = 1; - else - sync_data.enable_do_sync = 0; - return; - } - - if (sync_data.what_main_pch==1) - { - // принудительно всегда !!! - if (edrk.flag_second_PCH) - sync_data.enable_do_sync = 0; - else - sync_data.enable_do_sync = 1; - return; - } - - } - -// if (optical_read_data.status == 1) - sync_data.global_flag_sync_1_2 = (sync_data.local_flag_sync_1_2 || optical_read_data.data.cmd.bit.sync_1_2); -// else - // sync_data.global_flag_sync_1_2 = (sync_data.local_flag_sync_1_2); - - - if (sync_data.timeout_sync_signal && optical_read_data.data.cmd.bit.sync_line_detect) - { - // этот БС не принимает синхро, а второй принимает, значит на этом отключаем синхронизацию - // синхронизируется тот борт сам. - - sync_data.enable_do_sync = 0; - - return; - } - - if (sync_data.timeout_sync_signal==0 && optical_read_data.data.cmd.bit.sync_line_detect==0) - { - // этот БС принимает синхро, а второй не принимает, значит на этом принудительно включаем синхронизацию - // синхронизируется этот борт сам. - - sync_data.enable_do_sync = 1; - - return; - } - - if (sync_data.sync_ready && sync_data.timeout_sync_signal==0 && optical_read_data.data.cmd.bit.sync_line_detect) - { - - - if (optical_read_data.data.cmd.bit.sync_1_2 && sync_data.enable_do_sync==0) - { - // уже есть синхрон, другой БС смог это сделать и он сам это сделал - - } - else - if (optical_read_data.data.cmd.bit.sync_1_2 && sync_data.enable_do_sync==1) - { - // уже есть синхрон, другой БС смог это сделать и он не сам это сделал, а от нас - - } - else - { - // нет синхронизации, значит выбираем кто это будет делать в автомате - // этот БС принимает синхро и второй принимает, значит синхронизация - // выбирается в зависимости от номера БС. - if (edrk.flag_second_PCH==0) - sync_data.enable_do_sync = 1; - else - sync_data.enable_do_sync = 0; - } - return; - } - -} - -////////////////////////////////////////////////////////// - diff --git a/Inu/Src2/551/main/synhro_tools.h b/Inu/Src2/551/main/synhro_tools.h deleted file mode 100644 index e6de9f1..0000000 --- a/Inu/Src2/551/main/synhro_tools.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * synhro_tools.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_SYNHRO_TOOLS_H_ -#define SRC_MAIN_SYNHRO_TOOLS_H_ - -void who_select_sync_signal(void); - -void clear_wait_synhro_optical_bus(void); - -unsigned int wait_synhro_optical_bus(void); -void clear_wait_synhro_optical_bus(void); - - -#endif /* SRC_MAIN_SYNHRO_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/temper_p_tools.c b/Inu/Src2/551/main/temper_p_tools.c deleted file mode 100644 index c6a773a..0000000 --- a/Inu/Src2/551/main/temper_p_tools.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * temper_p_tools.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - - - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include "adc_tools.h" - -#include "temper_p_tools.h" -/////////////////////////////////////////////// -void nagrev_auto_on_off(void) -{ - //min_real_int_temper_air - -// if (edrk.temper_edrk.max_real_int_temper_waterTEMPER_NAGREF_OFF) -// edrk.to_ing.bits.NAGREV_OFF = 1; - - if (edrk.temper_edrk.min_real_int_temper_airTEMPER_NAGREF_OFF_1 || edrk.temper_edrk.max_real_int_temper_air>TEMPER_NAGREF_OFF_2) - edrk.to_ing.bits.NAGREV_OFF = 1; - -} -/////////////////////////////////////////////// - - - -//#define koef_P_Water_filter 1600000 //0.095367431640625 -void calc_p_water_edrk(void) -{ - _iq iqtain,iq_temp; - static _iq koef_P_Water_filter = _IQ (0.1/2.0); // 5 сек фильтр - - edrk.p_water_edrk.adc_p_water[0] = ADC_f[1][14]; - - edrk.p_water_edrk.real_p_water[0] = (_IQtoF(analog.P_Water_internal) * NORMA_ACP_P - 4.0) / 1.6; - edrk.p_water_edrk.real_int_p_water[0] = edrk.p_water_edrk.real_p_water[0] * K_P_WATER_TO_SVU; - - - iqtain = _IQ(edrk.p_water_edrk.real_p_water[0]/100.0); - iq_temp = _IQ(edrk.p_water_edrk.filter_real_p_water[0]/100.0); - - if (edrk.p_water_edrk.flag_init_filter_temp[0]==0) - { - iq_temp = iqtain; - edrk.p_water_edrk.flag_init_filter_temp[0]=1; - } - -// iq_temp_engine[i] = exp_regul_iq(koef_Temper_ENGINE_filter, iq_temp_engine[i], iqtain); - - iq_temp += _IQmpy( (iqtain-iq_temp), koef_P_Water_filter); - edrk.p_water_edrk.filter_real_p_water[0] = _IQtoF(iq_temp)*100.0; - edrk.p_water_edrk.filter_real_int_p_water[0] = edrk.p_water_edrk.filter_real_p_water[0]*K_P_WATER_TO_SVU; - - - -} - -////////////////////////////////////////////////////////// - diff --git a/Inu/Src2/551/main/temper_p_tools.h b/Inu/Src2/551/main/temper_p_tools.h deleted file mode 100644 index d99cb89..0000000 --- a/Inu/Src2/551/main/temper_p_tools.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * temper_p_tools.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_TEMPER_P_TOOLS_H_ -#define SRC_MAIN_TEMPER_P_TOOLS_H_ - - -#define TEMPER_NAGREF_ON_1 120 -#define TEMPER_NAGREF_ON_2 200 - -#define TEMPER_NAGREF_OFF_1 170 -#define TEMPER_NAGREF_OFF_2 250 - -void nagrev_auto_on_off(void); -void calc_p_water_edrk(void); - - -#endif /* SRC_MAIN_TEMPER_P_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/ukss_tools.c b/Inu/Src2/551/main/ukss_tools.c deleted file mode 100644 index 097fc1e..0000000 --- a/Inu/Src2/551/main/ukss_tools.c +++ /dev/null @@ -1,605 +0,0 @@ -/* - * ukss_tools.c - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - - - -#include - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include -#include "adc_tools.h" -#include "CAN_project.h" -#include "CAN_Setup.h" -#include "global_time.h" -#include "v_rotor.h" -#include "ukss_tools.h" -#include "control_station_project.h" -#include "control_station.h" -#include "sync_tools.h" - - -#pragma DATA_SECTION(Unites2VPU, ".slow_vars") -int Unites2VPU[SIZE_UNITS_OUT]={0}; - -#pragma DATA_SECTION(Unites2Zadat4ik, ".slow_vars") -int Unites2Zadat4ik[SIZE_UNITS_OUT]={0}; - -#pragma DATA_SECTION(Unites2BKSSD, ".slow_vars") -int Unites2BKSSD[SIZE_UNITS_OUT]={0}; - -#pragma DATA_SECTION(Unites2UMU, ".slow_vars") -int Unites2UMU[SIZE_UNITS_OUT]={0}; - - - -void edrk_clear_cmd_ukss(void) -{ - int i; - - for (i=0;i - -#include -#include -#include -#include -#include -#include -#include "IQmathLib.h" -#include "mathlib.h" -#include "CAN_Setup.h" -#include "uom_tools.h" - - -#pragma DATA_SECTION(uom_levels, ".slow_vars") -int uom_levels[9] = {0, 0, 15, 30, 45, 60, 75, 90, 100}; -#pragma DATA_SECTION(iq_uom_levels, ".slow_vars") -_iq iq_uom_levels[9] = {_IQ(1.0), _IQ(1.0), _IQ(0.85), _IQ(0.7), _IQ(0.55), _IQ(0.4), _IQ(0.25), _IQ(0.1), _IQ(0.016)}; -void update_uom(void) -{ -// int index; - static _iq max_nominal_power = _IQ(MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - static _iq super_max_nominal_power = _IQ(SUPER_MAX_ZADANIE_LIMIT_POWER*1000.0/(NORMA_MZZ*NORMA_MZZ)); - - static unsigned int prev_CAN_count_cycle_input_units = 0, c_data = 0; - unsigned int cur_can_cycle; - - static FROM_ZADAT4IK zad = {0}, zad_w = {0}; - static unsigned int temp_code = 0 , temp_code1 = 0, temp_code2 = 0, temp_code3 = 0; - - - - cur_can_cycle = unites_can_setup.CAN_count_cycle_input_units[0]; - - if (prev_CAN_count_cycle_input_units != cur_can_cycle) - { - zad = edrk.from_zadat4ik; - - temp_code = (zad.bits.UOM_READY_ACTIVE & 0x1) + - (zad.bits.UOM_LIMIT_1 & 0x1) << 1 + - (zad.bits.UOM_LIMIT_2 & 0x1) << 2 + - (zad.bits.UOM_LIMIT_3 & 0x1) << 3 ; - - if (c_data == 0) - { - temp_code1 = temp_code; - c_data = 1; - } - else - if (c_data == 1) - { - temp_code2 = temp_code; - c_data = 2; - } - else - if (c_data == 2) - { - temp_code3 = temp_code; - c_data = 0; - } - - } - - prev_CAN_count_cycle_input_units = cur_can_cycle; - - if ((temp_code1 == temp_code2) && (temp_code2 == temp_code3)) - zad_w = zad; - - - edrk.from_uom.digital_line.bits.ready = zad_w.bits.UOM_READY_ACTIVE; - edrk.from_uom.digital_line.bits.level0 = zad_w.bits.UOM_LIMIT_1; - edrk.from_uom.digital_line.bits.level1 = zad_w.bits.UOM_LIMIT_2; - edrk.from_uom.digital_line.bits.level2 = zad_w.bits.UOM_LIMIT_3; - - - if (edrk.from_uom.digital_line.bits.ready && edrk.disable_uom==0) - { - edrk.from_uom.ready = 1; -//000 - 100 - if (edrk.from_uom.digital_line.bits.level0 == 0 && - edrk.from_uom.digital_line.bits.level1 == 0 && - edrk.from_uom.digital_line.bits.level2 == 0 ) - edrk.from_uom.code = 1; -//001 - 85 - if (edrk.from_uom.digital_line.bits.level0 == 1 && - edrk.from_uom.digital_line.bits.level1 == 0 && - edrk.from_uom.digital_line.bits.level2 == 0 ) - edrk.from_uom.code = 2; -//011 - 70 - if (edrk.from_uom.digital_line.bits.level0 == 1 && - edrk.from_uom.digital_line.bits.level1 == 1 && - edrk.from_uom.digital_line.bits.level2 == 0 ) - edrk.from_uom.code = 3; -//010 - 55 - if (edrk.from_uom.digital_line.bits.level0 == 0 && - edrk.from_uom.digital_line.bits.level1 == 1 && - edrk.from_uom.digital_line.bits.level2 == 0 ) - edrk.from_uom.code = 4; -//110 - 40 - if (edrk.from_uom.digital_line.bits.level0 == 0 && - edrk.from_uom.digital_line.bits.level1 == 1 && - edrk.from_uom.digital_line.bits.level2 == 1 ) - edrk.from_uom.code = 5; -//111 - 25 - if (edrk.from_uom.digital_line.bits.level0 == 1 && - edrk.from_uom.digital_line.bits.level1 == 1 && - edrk.from_uom.digital_line.bits.level2 == 1 ) - edrk.from_uom.code = 6; -//101 - 10 - if (edrk.from_uom.digital_line.bits.level0 == 1 && - edrk.from_uom.digital_line.bits.level1 == 0 && - edrk.from_uom.digital_line.bits.level2 == 1 ) - edrk.from_uom.code = 7; -//100 - 0 - if (edrk.from_uom.digital_line.bits.level0 == 0 && - edrk.from_uom.digital_line.bits.level1 == 0 && - edrk.from_uom.digital_line.bits.level2 == 1 ) - edrk.from_uom.code = 8; - } - else - { - edrk.from_uom.ready = 0; - edrk.from_uom.code = 0; - } - - edrk.from_uom.iq_level_value = iq_uom_levels[edrk.from_uom.code]; - - if (edrk.from_uom.code<=1) - edrk.from_uom.iq_level_value_kwt = super_max_nominal_power; - else - edrk.from_uom.iq_level_value_kwt = _IQmpy(max_nominal_power, - edrk.from_uom.iq_level_value); - - edrk.from_uom.level_value = uom_levels[edrk.from_uom.code]; - - - -} - -////////////////////////////////////////////////////////// diff --git a/Inu/Src2/551/main/uom_tools.h b/Inu/Src2/551/main/uom_tools.h deleted file mode 100644 index 134648f..0000000 --- a/Inu/Src2/551/main/uom_tools.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * uom_tools.h - * - * Created on: 13 нояб. 2024 г. - * Author: Evgeniy_Sokolov - */ - -#ifndef SRC_MAIN_UOM_TOOLS_H_ -#define SRC_MAIN_UOM_TOOLS_H_ - - -void update_uom(void); - - -#endif /* SRC_MAIN_UOM_TOOLS_H_ */ diff --git a/Inu/Src2/551/main/v_rotor_22220.c b/Inu/Src2/551/main/v_rotor_22220.c deleted file mode 100644 index c31de31..0000000 --- a/Inu/Src2/551/main/v_rotor_22220.c +++ /dev/null @@ -1,666 +0,0 @@ - -#include "DSP281x_Examples.h" // DSP281x Examples Include File -#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File -#include "DSP281x_Device.h" // DSP281x Headerfile Include File -#include "IQmathLib.h" - -#include "params_bsu.h" -#include "v_rotor.h" - -#include "filter_v1.h" -#include "xp_cds_in.h" - -#include "xp_inc_sensor.h" -#include "xp_project.h" -#include "params.h" - -//#include "pwm_test_lines.h" -#include "params_norma.h" -#include "edrk_main.h" -#include "params_pwm24.h" -#include "v_rotor_22220.h" - -#include "rmp_cntl_v1.h" -#include "mathlib.h" - - -//#define _ENABLE_PWM_LED2_PROFILE 1 - -#if (_ENABLE_PWM_LED2_PROFILE) -extern unsigned int profile_pwm[30]; -extern unsigned int pos_profile_pwm; -#endif - -// -//#pragma DATA_SECTION(buf1,".logs2") -//int buf1[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf2,".logs2") -//int buf2[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf3,".logs2") -//int buf3[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf4,".logs2") -//int buf4[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf5,".logs2") -//int buf5[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf6,".logs2") -//int buf6[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf7,".logs2") -//int buf7[SIZE_BUF_W]; -//#pragma DATA_SECTION(buf8,".logs2") -//int buf8[SIZE_BUF_W]; -// - -/////////////////////////////////////////////// -/////////////////////////////////////////////// -/////////////////////////////////////////////// -RMP_V1 rmp_wrot = RMP_V1_DEFAULTS; - -#pragma DATA_SECTION(rotor_22220,".fast_vars"); -ROTOR_VALUE_22220 rotor_22220 = ROTOR_VALUE_22220_DEFAULTS; - - -void rotorInit_22220(void) -{ - unsigned int i = 0, size = 0, *pint = 0; - - rmp_wrot.RampLowLimit = 0; - rmp_wrot.RampHighLimit = _IQ(1.0); - rmp_wrot.RampPlus = _IQ(0.0015/NORMA_FROTOR); - rmp_wrot.RampMinus = _IQ(-0.0015/NORMA_FROTOR); - rmp_wrot.DesiredInput = 0; - rmp_wrot.Out = 0; - - -// pint = (unsigned int*)&rotor; -// size = sizeof(rotor) / sizeof(unsigned int); -// for(i = 0; i < size; i++) -// { -// *(pint + i) = 0; -// } - -} - -_iq koef_Wout_filter = _IQ(0.2); //_IQ(0.15); -_iq koef_Wout_filter_long = _IQ(0.001);//_IQ(0.03); - -#define SIZE_BUF_F1 10 -#pragma DATA_SECTION(f1,".slow_vars") -static _iq f1[SIZE_BUF_F1]={0,0,0,0,0,0,0,0,0,0}; -#pragma DATA_SECTION(f1_int,".slow_vars") -static long f1_int[SIZE_BUF_F1]={0,0,0,0,0,0,0,0,0,0}; - -#pragma CODE_SECTION(clear_iqFsensors,".fast_run"); -void clear_iqFsensors(void) -{ - int i; - - for (i=0;i=(SIZE_BUF_W-1)) -// { -// flag_buf = 0; -// c_s = 0; -// } -// else -// c_s++; -// -// -// buf1[c_s] = inc_sensor.data.CountOne1;// rotation_sensor.in_plane.out.CountOne1; -// buf2[c_s] = inc_sensor.data.CountZero1;//rotation_sensor.in_plane.out.CountZero1; -// buf3[c_s] = inc_sensor.data.CountOne2;//rotation_sensor.in_plane.out.CountOne2; -// buf4[c_s] = inc_sensor.data.CountZero2;//rotation_sensor.in_plane.out.CountZero2; -// buf5[c_s] = direction1;//inc_sensor.data.;//(rotation_sensor.in_plane.out.direction1); -// buf6[c_s] = direction2;//(rotation_sensor.in_plane.out.direction2); -// buf7[c_s] = (project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1); -// buf8[c_s] = (project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2); -// -// } -// prev_flag_buf = flag_buf; - - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - - if(inc_sensor.use_sensor1) - { - if((inc_sensor.data.CountOne1 <= 200)// && !rotation_sensor.in_plane.out.counter_freq1) - || inc_sensor.data.CountOne1 == 65535) - { inc_sensor.data.CountOne1 = 0; } - if((inc_sensor.data.CountZero1 <= 200)// && !rotation_sensor.in_plane.out.counter_freq1) - || inc_sensor.data.CountZero1 == 65535) - { inc_sensor.data.CountZero1 = 0; } - - //Когда импульсов мало считаем по периоду - if (inc_sensor.data.Impulses1 < 5) { - - if(inc_sensor.data.CountOne1 && inc_sensor.data.CountZero1 ) - { - sum_count = (long)inc_sensor.data.CountOne1 + (long)inc_sensor.data.CountZero1; - - if (s_number3 2) - { - if (s_number 139810L)//10 rpm - { - if (inc_sensor.data.CountOne1 == 0 && inc_sensor.data.CountZero1 == 0 - && inc_sensor.data.Impulses1 == 0) { - sens1_err_count += 1; - } else { - sens1_err_count = 0; - } - if (sens1_err_count > 50) { - sens1_err_count = 50; - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 1; -// faults.faults4.bit.Speed_Datchik_1_Off |= 1; - } - } else { - sens1_err_count = 0; - edrk.warnings.e9.bits.SENSOR_ROTOR_1_BREAK = 0; - } - } - - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - -// logpar.log4 = rotation_sensor.in_plane.out.CountOne2; -// logpar.log20 = rotation_sensor.in_plane.out.CountZero2; - if(inc_sensor.use_sensor2) - { - if((inc_sensor.data.CountOne2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2) - || inc_sensor.data.CountOne2 == 65535) - { inc_sensor.data.CountOne2 = 0; } - if((inc_sensor.data.CountZero2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2) - || inc_sensor.data.CountZero2 == 65535) - { inc_sensor.data.CountZero2 = 0; } - - //Кодда импульсов мало, считаем по периоду - if (inc_sensor.data.Impulses2 < 5) { - - if(inc_sensor.data.CountOne2 && inc_sensor.data.CountZero2 ) - { - sum_count = (long)inc_sensor.data.CountOne2+(long)inc_sensor.data.CountZero2; - if (s_number3 2) - { - if (s_number 139810L)//10 rpm - { - if (inc_sensor.data.CountOne2 == 0 && inc_sensor.data.CountZero2 == 0 - && inc_sensor.data.Impulses2 == 0) { - sens2_err_count += 1; - } else { - sens2_err_count = 0; - } - if (sens2_err_count > 50) { - sens2_err_count = 50; -// faults.faults4.bit.Speed_Datchik_2_Off |= 1; - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 1; - } - } else { - sens2_err_count = 0; - edrk.warnings.e9.bits.SENSOR_ROTOR_2_BREAK = 0; - } - - } - - if(s_number > SENSORS_NUMBER_ONLY_IN) {s_number = SENSORS_NUMBER_ONLY_IN;} //TODO set SENSORS_NUMBER when tune angle measure - if(s_number > 3) - { - sort_F_array(rotor_22220.iqFsensors, s_number); - deltaF = rotor_22220.iqFout >> 2; - if(deltaF < 43000) // ~3 ob/min - { - deltaF = 43000; - } - i = 0; - begin_data = 0; - end_data = s_number; //TODO test, as usial - while(i < s_number) - { - if(_IQabs(rotor_22220.iqFout - rotor_22220.iqFsensors[i]) >= deltaF) - { - i++; - } - else - { - break; - } - } - if(i < s_number) { begin_data = i; } - else {begin_data = 0;} - while((i < s_number) && (_IQabs(rotor_22220.iqFout - rotor_22220.iqFsensors[i]) < deltaF)) - { - i++; - } - if(i <= SENSORS_NUMBER) - { - end_data = i; - } - else - { - end_data = SENSORS_NUMBER; - } - } - else - { - begin_data = 0; - end_data = s_number; - } - if (begin_data >= end_data) { //This part to prevent freeze of speed on some level if signal lost - begin_data = 0; - end_data = s_number; - } - // суммируем - for(i = begin_data; i < end_data; i++) - { - accumulator += rotor_22220.iqFsensors[i]; - } - // усредняем - if(end_data != begin_data) - { - rotor_22220.iqFdirty = accumulator / (end_data - begin_data); - prev_wrot_count = 0; - } - else - { - rotor_22220.iqFdirty = prev_wrot; - prev_wrot_count += 1; - } - -// logpar.log19 = (int16)(_IQtoIQ15(rotor.iqF)); -// rotor_22220.iqFdirty = rotor_22220.iqF; - - if (prev_wrot != rotor_22220.iqFdirty || rotor_22220.iqFdirty==0 ) - { - rmp_wrot.DesiredInput = rotor_22220.iqFdirty; - rmp_wrot.calc(&rmp_wrot); - rotor_22220.iqF = rmp_wrot.Out; - } - else - { - rotor_22220.iqF = rotor_22220.iqFdirty; - } - prev_wrot=rotor_22220.iqF; - - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - - //От зависаниЙа старого значениЙа. - if (prev_wrot_count > 10) { - prev_wrot = 0; - prev_wrot_count = 10; - } - - rotor_22220.iqFout = exp_regul_iq(koef_Wout_filter, rotor_22220.iqFout, rotor_22220.iqF); - rotor_22220.iqFlong = exp_regul_iq(koef_Wout_filter_long, rotor_22220.iqFlong, rotor_22220.iqF); - -#if (_ENABLE_PWM_LED2_PROFILE) - if (profile_pwm[pos_profile_pwm++]) - i_led2_on_off(1); - else - i_led2_on_off(0); -#endif - - - rotor_22220.direct_rotor_in1 = direction1;//rotation_sensor.in_plane.out.direction1; - -#if (_STEND_40MWT==1) - // меняем направление вращения для второго канала, т.к. на стенде туда завели инверсные каналы, а датчик физически один!!! - - rotor_22220.direct_rotor_in2 = -rotation_sensor.in_plane.out.direction2; - -#else - - rotor_22220.direct_rotor_in2 = direction2;//rotation_sensor.in_plane.out.direction2; - -#endif - // rotor.direct_rotor_angle = rotation_sensor.rotation_plane.out.direction; - - rotor_22220.error.sens_err1 = sens_err1; - rotor_22220.error.sens_err2 = sens_err2; - -// rotor.direct_rotor = (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) > 0 ? 1 : // + rotor.direct_rotor_angle -// (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) < 0 ? -1 : // + rotor.direct_rotor_angle -// 0; - if(rotor_22220.iqFout >139810L) //10ob/min - { - if((rotor_22220.direct_rotor_in1 + rotor_22220.direct_rotor_in2) > 0) - { - direct_accum++; - } - else if((rotor_22220.direct_rotor_in1 + rotor_22220.direct_rotor_in2) < 0) - { - direct_accum--; - } - else - { - if(direct_accum > 0) {direct_accum--;} - if(direct_accum < 0) {direct_accum++;} - } - if(direct_accum > 60) { direct_accum = 60; } - if(direct_accum < -60) { direct_accum = -60; } - rotor_22220.direct_rotor = direct_accum > 0 ? 1 : - direct_accum < 0 ? -1 : - 0; -// if (f.flag_second_PCH) { -// rotor.direct_rotor = - rotor.direct_rotor; -// } - } - else - { - rotor_22220.direct_rotor = (rotor_22220.direct_rotor_in1 + rotor_22220.direct_rotor_in2) > 0 ? 1 : // + rotor.direct_rotor_angle - (rotor_22220.direct_rotor_in1 + rotor_22220.direct_rotor_in2) < 0 ? -1 : // + rotor.direct_rotor_angle - 0; -// if (f.flag_second_PCH) { -// rotor.direct_rotor = - rotor.direct_rotor; -// } - direct_accum = rotor_22220.direct_rotor; - } - -// if(rotation_sensor.in_plane.write.regs.comand_reg.bit.set_sampling_time) //Импульсы короткие -// { -// rotation_sensor.in_plane.write.regs.comand_reg.bit.filter_sensitivity = 0x5C; -// } -// else //Импульсы длинные, фильтр усиливаем -// { -// rotation_sensor.in_plane.write.regs.comand_reg.bit.filter_sensitivity = 0xA8; -// } - if (s_number2 0; i--) - { - for(j = 1; j < size; j++) - { - if(array[j - 1] > array[j]) - { - tmp = array[j]; - array[j] = array[j - 1]; - array[j - 1] = tmp; - } - } - } -} - - -void select_values_wrotor_22220(void) -{ - // static _iq level_switch_to_get_impulses_hz = _IQ(LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS/60.0/NORMA_FROTOR); - static unsigned int prev_RotorDirectionInstant = 0; - static unsigned int status_RotorRotation = 0; // есть вращение? - static _iq wrotor_add = _IQ(0.002/NORMA_FROTOR); - - WRotor.RotorDirectionSlow = rotor_22220.direct_rotor; - WRotor.iqWRotorSum = rotor_22220.iqFout;// * rotor_22220.direct_rotor; - WRotor.iqWRotorSumFilter = rotor_22220.iqFout * rotor_22220.direct_rotor; - WRotor.iqWRotorSumFilter2 = rotor_22220.iqFlong * rotor_22220.direct_rotor; - WRotor.iqWRotorSumFilter3 = rotor_22220.iqFlong * rotor_22220.direct_rotor; - WRotor.iqWRotorSumRamp = zad_intensiv_q(wrotor_add, wrotor_add, WRotor.iqWRotorSumRamp, WRotor.iqWRotorSumFilter); - - -} diff --git a/Inu/Src2/551/main/v_rotor_22220.h b/Inu/Src2/551/main/v_rotor_22220.h deleted file mode 100644 index aec28c5..0000000 --- a/Inu/Src2/551/main/v_rotor_22220.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef V_ROTOR_22220_H -#define V_ROTOR_22220_H - -#define SIZE_BUF_W 100 //2000 - -/////// 22220.5 -#define SENSORS_NUMBER 10 -#define SENSORS_NUMBER_ONLY_IN 6 -//#define IMPULSES_PER_TURN (1LL << 13) //Old sensor -#define IMPULSES_PER_TURN 4096 //Lira sensor -//#define ANGLE_RESOLUTION (1LL << 18) //2^18 - -typedef struct -{ - int direct_rotor; - int direct_rotor_in1; - int direct_rotor_in2; - int direct_rotor_angle; - union { - unsigned int sens_err1:1; - unsigned int sens_err2:1; - unsigned int reserved:14; - } error; - - _iq iqFsensors[SENSORS_NUMBER]; - - - _iq iqFdirty; - _iq iqF; - _iq iqFout; - _iq iqFlong; - - _iq iqFrotFromOptica; - - unsigned int error_update_count; -} ROTOR_VALUE_22220; - -#define ROTOR_VALUE_22220_DEFAULTS {0,0,0,0,0, {0,0,0,0,0,0,0,0},0,0,0,0,0,0} - - -_iq counter_To_iqF2(long count, unsigned int freq_mode); -void sort_F_array(_iq *array, unsigned int size); -_iq impulses_To_iqF(unsigned int time, unsigned int impulses); //time mks. impulses count -void Rotor_measure_22220(void); -void rotorInit_22220(void); -void select_values_wrotor_22220(void); - -extern ROTOR_VALUE_22220 rotor_22220; - -extern _iq koef_Wout_filter, koef_Wout_filter_long; - - -#endif - diff --git a/Inu/Src2/551/main/vector.h b/Inu/Src2/551/main/vector.h deleted file mode 100644 index 25bc4f1..0000000 --- a/Inu/Src2/551/main/vector.h +++ /dev/null @@ -1,254 +0,0 @@ -/* - ???? ??? (?) 2006 ?. - - Processor: TMS320C32 - - Filename: vector_troll.h - - ??????? ?????????? ?????????y - - Edit date: 04-12-02 - - Function: - - Revisions: -*/ - - -#ifndef _VECTOR_SEV -#define _VECTOR_SEV - - -#ifdef __cplusplus - extern "C" { -#endif - - -#include "IQmathLib.h" -#include "x_basic_types.h" - -typedef struct -{ - float W; /* Угловау скороть ротора */ - float Angle; /* Угол положениу ротора */ - float Phi; /* Поправка к углу ротора */ - float k; /* Коэфф. модулЯции */ - float k1; /* Коэфф. модулЯции */ - float k2; /* Коэфф. модулЯции */ - float f; /* Частота статора */ - - _iq iqk; - _iq iqk1; - _iq iqk2; - _iq iqf; - - - -} WINDING; - -#define WINDING_DEFAULT {0,0,0,0,0,0,0,0,0,0,0} - - -typedef struct -{ - unsigned int Prepare; - unsigned int terminal_prepare; - unsigned int Test_Lamps; - unsigned int fault; - - - - unsigned int Stop; - unsigned int Mode; - unsigned int Revers; - unsigned int Is_Blocked; - - unsigned int Ready1; - unsigned int Ready2; - unsigned int Discharge; - unsigned int Assemble; - - unsigned int ErrorChannel1; - unsigned int ErrorChannel2; - unsigned int FaultChannel1; - unsigned int FaultChannel2; - - unsigned int Set_power; - - unsigned int Impuls; - - unsigned int Obmotka1; - unsigned int Obmotka2; -// unsigned int Down50; - - unsigned int I_over_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ???? - unsigned int Moment_over_1_6_noninal; //????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.6 ??? - unsigned int Moment_over_1_8_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.8 ??? - unsigned int DownToNominal; - unsigned int DownToNominalMoment; - unsigned int Down50Temperature; - unsigned int nominal_I_exceeded_counter; //??????? ??? ????????? ??????????? ??? - unsigned int nominal_M_exceeded_counter; //??????? ??? ????????? ??????????? ?????? - - unsigned int Up50; - unsigned int Ciclelog; - unsigned int Provorot; - unsigned int Bpsi; - unsigned int Piregul1; - unsigned int Piregul2; - unsigned int Startstoplog; - unsigned int Setspeed; - - unsigned int BWC_is_ON; - - unsigned int Setsdvigfaza; - unsigned int Off_piregul; - - unsigned int Restart; - unsigned int Log1_Log2; - - unsigned int Work_net; - unsigned int Mask_impuls; - unsigned int Impuls_width; - - - unsigned int Work; - - unsigned int Auto; - - unsigned int Uzad; - unsigned int Umin; - -// unsigned int RScount; - unsigned int vector_run; - unsigned int test_all_run; - - unsigned int decr_mzz_temp; -// unsigned int flag_decr_mzz_temp; - - unsigned int flag_Break_Resistor_Error; - unsigned int flag_local_control; //1 - local - unsigned int flag_leading; //??????? ?? ?????? - unsigned int flag_second_leading; //?????? ?? ?????? - unsigned int flag_distance; - unsigned int flag_kvitirovanie; - unsigned int flag_batary_loaded; - unsigned int flag_Pump_Is_On; - unsigned int power_units_doors_closed; - unsigned int power_units_doors_locked; - - unsigned int flag_decr_mzz_power; - - real decr_mzz_power; - _iq iq_decr_mzz_power; - - _iq iq_decr_mzz_voltage; - - real fzad; - real kzad; - real kzad_plus; -// real fzad_provorot; - real Sdvigfaza; -// real k_3garonica; -// _iq iq_k_3garonica; -// real bpsi_zad; - -// real Piregul1_p; -// real Piregul1_i; - -// real Piregul2_p; -// real Piregul2_i; - - - real mzz_zad; - real fr_zad; - real Power; - real p_zad; - - -// _iq iq_bpsi_zad; - _iq iq_mzz_zad; -// _iq iq_fzad_provorot; - _iq iq_fzad; - - _iq iq_p_zad; - - unsigned int flag_Enable_Prepare; - - - unsigned int status_MODE_WORK_SVU; - unsigned int status_MODE_WORK_MPU; - unsigned int status_MODE_WORK_VPU; -// unsigned int status_MODE_WORK_EVPU; - -// unsigned int filter_READY_UKSS_BV1; -// unsigned int filter_READY_UKSS_BV2; -// unsigned int filter_READY_UKSS_BI1; -// unsigned int filter_READY_UKSS_BI2; - unsigned int filter_READY_UMU; -// unsigned int filter_READY_UKSS_UKSI; - - unsigned int On_Power_QTV; - - unsigned int RS_MPU_ERROR; -// unsigned int CAN_MPU_ERROR; - -// unsigned int enable_fast_prepare; - -// unsigned int tau_break1; -// unsigned int tau_break2; - - unsigned int flag_tormog; - -// unsigned int GoPWM; - - int special_test_from_mpu; - - int MessageToCan1; - int MessageToCan2; - int flag_change_pwm_freq; - int flag_random_freq; - long tmp; - - - - - - -//optical bus data - unsigned int read_task_from_optical_bus; - - - - unsigned int count_wait_after_kvitir; - unsigned int flag_record_log; - unsigned int count_step_ram_off; - unsigned int count_start_impuls; - - int flag_send_alarm_log_to_MPU; - - -} FLAG; - -#define FLAG_DEFAULTS {\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0\ - } -extern FLAG f; -//extern WINDING a; - -#ifdef __cplusplus - } -#endif - -#endif /* _VECTOR_SEV */ - - diff --git a/Inu/Src2/N12_Libs/CAN_Setup.c b/Inu/Src2/N12_Libs/CAN_Setup.c new file mode 100644 index 0000000..e43a61c --- /dev/null +++ b/Inu/Src2/N12_Libs/CAN_Setup.c @@ -0,0 +1,2201 @@ +#include "CAN_Setup.h" // DSP281x Headerfile Include File + +#include "modbus_table_v2.h" +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "global_time.h" +#include "TuneUpPlane.h" +#include "profile_interrupt.h" + + + + +unsigned int CanTimeOutErrorTR = 0; +unsigned int CanBusOffError = 0; + + + +int enable_can_recive_after_units_box = 0; +int flag_enable_can_from_mpu=0; +int flag_enable_can_from_terminal=0; +long time_pause_enable_can_from_mpu=0; +long time_pause_enable_can_from_terminal=0; +int flag_disable_update_modbus_in_can_from_mpu=0; + +//unsigned long can_base_adr_terminal, can_base_adr_units, can_base_adr_mpu1, can_base_adr_alarm_log; + +//unsigned int enable_profile_led1_can = 1; +//unsigned int enable_profile_led2_can = 0; + +#pragma DATA_SECTION(cycle,".slow_vars") +CYCLE cycle[UNIT_QUA]; + + +#pragma DATA_SECTION(new_cycle_fifo,".slow_vars") +NEW_CYCLE_FIFO new_cycle_fifo; + +#pragma DATA_SECTION(fifo,".slow_vars") +#pragma DATA_SECTION(refo,".slow_vars") +FIFO fifo, refo; + + + + +#pragma DATA_SECTION(BUSY,".slow_vars") +int BUSY = 0; + + +#pragma DATA_SECTION(Unites, ".slow_vars") +int Unites[UNIT_QUA_UNITS][UNIT_LEN]; + +#pragma DATA_SECTION(TerminalUnites, ".slow_vars") +int TerminalUnites[TERMINAL_UNIT_QUA_UNITS][TERMINAL_UNIT_LEN]; + +#pragma DATA_SECTION(CanOpenUnites, ".slow_vars") +int CanOpenUnites[CANOPENUNIT_LEN]; + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + + +//#pragma DATA_SECTION(CAN_timeout,".slow_vars") +#pragma DATA_SECTION(CAN_timeout,".fast_vars") +// массив отсутсвия обмена с устройством +int CAN_timeout[UNIT_QUA]; +// +#pragma DATA_SECTION(CAN_request_sent,".slow_vars") +int CAN_request_sent[UNIT_QUA]; +// +#pragma DATA_SECTION(CAN_answer_wait,".slow_vars") +int CAN_answer_wait[UNIT_QUA]; +// +#pragma DATA_SECTION(CAN_no_answer,".slow_vars") +int CAN_no_answer[UNIT_QUA]; + +// как долго не обновлялись, по приходу любой посылки +#pragma DATA_SECTION(CAN_refresh_cicle,".slow_vars") +int CAN_refresh_cicle[UNIT_QUA]; +// время обновления всего массива +#pragma DATA_SECTION(CAN_count_cycle_input_units,".slow_vars") +int CAN_count_cycle_input_units[UNIT_QUA_UNITS]; + +#pragma DATA_SECTION(CAN_timeout_cicle,".fast_vars") +//#pragma DATA_SECTION(CAN_timeout_cicle, ".slow_vars") +// счетчик +unsigned int CAN_timeout_cicle[UNIT_QUA]; + + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +#pragma DATA_SECTION(unites_can_setup, ".slow_vars") +UNITES_CAN_SETUP unites_can_setup = UNITES_CAN_SETUP_DEFAULT; +#pragma DATA_SECTION(mpu_can_setup, ".slow_vars") +MPU_CAN_SETUP mpu_can_setup = MPU_CAN_SETUP_DEFAULT; +#pragma DATA_SECTION(terminal_can_setup, ".slow_vars") +TERMINAL_CAN_SETUP terminal_can_setup = TERMINAL_CAN_SETUP_DEFAULT; +#pragma DATA_SECTION(alarm_log_can_setup, ".slow_vars") +ALARM_LOG_CAN_SETUP alarm_log_can_setup = ALARM_LOG_CAN_SETUP_DEFAULT; + + +#pragma DATA_SECTION(mailboxs_can_setup, ".slow_vars") +MAILBOXS_CAN_SETUP mailboxs_can_setup = MAILBOXS_CAN_SETUP_DEFAULT; + +#pragma DATA_SECTION(canopen_can_setup, ".slow_vars") +CANOPEN_CAN_SETUP canopen_can_setup = CANOPEN_CAN_SETUP_DEFAULT; + + + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// +int init_units_can_boxs(UNITES_CAN_SETUP *p) +{ + int c,e; + + e=0; + for (c=0;cactive_box[c]) + { + p->adr_box[c+UNITS_NUMERATION_FROM_0_OR_1] = e; + + if (p->revers_box[c]) // Реверс бокс, меняем адреса для имитации Unites между разными TMS + { + p->can_in_mbox_adr[e] = p->can_base_adr + c; + p->can_out_mbox_adr[e] = p->can_base_adr + OFFSET_CAN_ADR_UNITS + c; + } + else + { + p->can_out_mbox_adr[e] = p->can_base_adr + c; + p->can_in_mbox_adr[e] = p->can_base_adr + OFFSET_CAN_ADR_UNITS + c; + } +// p->can_in_mbox_adr[e] = START_CAN_ADR_UNITS + c*2; +// p->can_out_mbox_adr[e] = START_CAN_ADR_UNITS + OFFSET_CAN_ADR_UNITS + c*2; + e++; + } + } + + p->max_number = e; + + + return e; +} + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +int init_canopen_can_boxs(CANOPEN_CAN_SETUP *p) +{ + int i; + +// p->max_number = 8; + for(i = 0; i < CANOPENUNIT_LEN; i++) + CanOpenUnites[i] = 0; + + return 1; +} + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +int init_mpu_can_boxs(MPU_CAN_SETUP *p ) +{ + int c,e; + + e = 0; + for (c=0;cactive_box[c]) + { + p->adr_box[c] = e; + p->can_out_mbox_adr[e] = p->can_base_adr + c; + p->can_in_mbox_adr[e] = p->can_base_adr + 0x10 + c; //OFFSET_CAN_ADR_MPU + e++; + } + } + + p->max_number = e; + + return e; +} + +///////////////////////////////////////////////////////// + +int init_terminal_can_boxs(TERMINAL_CAN_SETUP *p ) +{ + int c,e; + + e = 0; + for (c=0;cactive_box[c]) + { + p->adr_box[c] = e; + p->can_out_mbox_adr[e] = p->can_base_adr + c; + p->can_in_mbox_adr[e] = p->can_base_adr + 0x10 + c; //OFFSET_CAN_ADR_MPU + e++; + } + } + + p->max_number = e; + + return e; +} + + +///////////////////////////////////////////////////////// +int init_alarm_log_can_boxs(ALARM_LOG_CAN_SETUP *p ) +{ + int c,e; + + e = 0; + for (c=0;cactive_box[c]) + { + p->adr_box[c] = e; + p->can_out_mbox_adr[e] = p->can_base_adr + c; + p->can_in_mbox_adr[e] = p->can_base_adr + 0x10 + c; //OFFSET_CAN_ADR_MPU + e++; + } + } + + p->max_number = e; + + return e; +} + + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +void init_mailboxs_can( UNITES_CAN_SETUP *p_units, + MPU_CAN_SETUP *p_mpu, + TERMINAL_CAN_SETUP *p_terminal, + ALARM_LOG_CAN_SETUP *p_alarm_log, + CANOPEN_CAN_SETUP *p_canopen, + MAILBOXS_CAN_SETUP *p_mailboxs ) +{ + volatile int c,e,max_number_in,max_number_out; + + e = 0; + max_number_in = 0; + max_number_out = 0; + + if (p_units->max_number>0) + { + for (c=0;cmax_number;c++) + { + p_mailboxs->can_mbox_adr[e] = p_units->can_in_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_IN; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = UNITS_TYPE_BOX; + + p_units->adr_in_mbox[c] = e; + + max_number_in++; + e++; + + p_mailboxs->can_mbox_adr[e] = p_units->can_out_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_OUT; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = UNITS_TYPE_BOX; + + p_units->adr_out_mbox[c] = e; + + max_number_out++; + e++; + } + } + + if (p_mpu->max_number>0) + { + for (c=0;cmax_number;c++) + { + p_mailboxs->can_mbox_adr[e] = p_mpu->can_in_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_IN; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = MPU_TYPE_BOX; + + p_mpu->adr_in_mbox[c] = e; + + max_number_in++; + e++; + + p_mailboxs->can_mbox_adr[e] = p_mpu->can_out_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_OUT; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = MPU_TYPE_BOX; + + p_mpu->adr_out_mbox[c] = e; + + max_number_out++; + e++; + } + } + + if (p_terminal->max_number>0) + { + for (c=0;cmax_number;c++) + { + p_mailboxs->can_mbox_adr[e] = p_terminal->can_in_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_IN; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = TERMINAL_TYPE_BOX; + + p_terminal->adr_in_mbox[c] = e; + + max_number_in++; + e++; + + p_mailboxs->can_mbox_adr[e] = p_terminal->can_out_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_OUT; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = TERMINAL_TYPE_BOX; + + p_terminal->adr_out_mbox[c] = e; + + max_number_out++; + e++; + } + } + + + if (p_alarm_log->max_number>0) + { + for (c=0;cmax_number;c++) + { + p_mailboxs->can_mbox_adr[e] = p_alarm_log->can_in_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_IN; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = ALARM_LOG_TYPE_BOX; + + p_alarm_log->adr_in_mbox[c] = e; + + max_number_in++; + e++; + + p_mailboxs->can_mbox_adr[e] = p_alarm_log->can_out_mbox_adr[c] | 0x80000000; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_OUT; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = ALARM_LOG_TYPE_BOX; + + p_alarm_log->adr_out_mbox[c] = e; + + max_number_out++; + e++; + } + } + + + if (p_canopen->max_number>0) + { + for (c=0;cmax_number;c++) + { + p_mailboxs->can_mbox_adr[e] = p_canopen->can_in_mbox_adr[c]; + p_mailboxs->type_in_out_box[e] = CAN_BOX_TYPE_IN; + p_mailboxs->local_number_box[e] = c; + p_mailboxs->type_box[e] = CANOPEN_TYPE_BOX; + + p_canopen->adr_in_mbox[c] = e; + + max_number_in++; + e++; + } + } + + p_mailboxs->max_number_in = max_number_in; + p_mailboxs->max_number_out = max_number_out; +} + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +void init_all_mailboxs(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, unsigned long can_base_adr_alarm_log, unsigned long can_base_adr_terminal) +{ +// + unites_can_setup.can_base_adr = can_base_adr_units; + init_units_can_boxs(&unites_can_setup); +// + mpu_can_setup.can_base_adr = can_base_adr_mpu; + init_mpu_can_boxs(&mpu_can_setup); +// + terminal_can_setup.can_base_adr = can_base_adr_terminal; + init_terminal_can_boxs(&terminal_can_setup); +// + alarm_log_can_setup.can_base_adr = can_base_adr_alarm_log; + init_alarm_log_can_boxs(&alarm_log_can_setup); +// + init_canopen_can_boxs(&canopen_can_setup); +// + init_mailboxs_can(&unites_can_setup, &mpu_can_setup, &terminal_can_setup, &alarm_log_can_setup, &canopen_can_setup, &mailboxs_can_setup); + +} + + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + + + + +void reset_CAN_timeout_cicle(int box) +{ + CAN_timeout_cicle[box]=0; +} + + +#pragma CODE_SECTION(inc_CAN_timeout_cicle, ".fast_run2"); +void inc_CAN_timeout_cicle() +{ + unsigned int i, t_refresh; + static unsigned int old_time = 0; + + t_refresh = get_delta_milisec(&old_time, 1); + if (t_refresh>1000) + t_refresh = 1000; + + + for(i = 0; i < UNIT_QUA; i++) + { + if (CAN_timeout_cicle[i] < MAX_CAN_WAIT_TIMEOUT) + { + CAN_timeout_cicle[i] += t_refresh; + } + else + { + CAN_timeout[i] = 1; + CAN_refresh_cicle[i] = -1; + } + } +} + + + +void InitCan(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, unsigned long can_base_adr_alarm_log, unsigned long can_base_adr_terminal) +{ + struct ECAN_REGS ECanaShadow; + int i, c; + volatile struct MBOX *tmbox; + volatile Uint32 *tmoto; + + unsigned long canme_bits = 0; + unsigned long canmd_bits = 0; + unsigned long canmim_bits = 0; + + + init_all_mailboxs(can_base_adr_units, can_base_adr_mpu, can_base_adr_alarm_log, can_base_adr_terminal); + +// Configure CAN pins using GPIO regs here + EALLOW; + + GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1; + GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1; + +// Configure the eCAN RX and TX pins for eCAN transmissions + ECanaRegs.CANTIOC.all = 8; // only 3rd bit, TXFUNC, is significant + ECanaRegs.CANRIOC.all = 8; // only 3rd bit, RXFUNC, is significant + + +// Specify that 8 bits will be sent/received + for (c=0;c<32;c++) + { + tmbox = &ECanaMboxes.MBOX0 + c; + tmbox->MSGCTRL.all = 0x00000008; + } + +// Disable all Mailboxes +// Required before writing the MSGIDs + ECanaRegs.CANME.all = 0; + + canme_bits = 0; + canmd_bits = 0; + canmim_bits = 0; + + // receive+transive //Ura + for (c=0;c<32;c++) + { + + if (mailboxs_can_setup.can_mbox_adr[c]) + { + tmbox = &ECanaMboxes.MBOX0 + c; + if(mailboxs_can_setup.type_box[c] == UNITS_TYPE_BOX) + { +// tmbox->MSGID.bit.IDE = 0; +// tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; + tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; + } + else + { + if(mailboxs_can_setup.type_box[c] == CANOPEN_TYPE_BOX) + { + tmbox->MSGID.bit.IDE = 0; + tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; + //tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; + } + else + tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; + } + + canme_bits |= ((unsigned long)1<> 4) ) + return 3; + if (load_level_byte < (NEW_CYCLE_FIFO_LEN >> 2) ) + return 2; + if (load_level_byte < (NEW_CYCLE_FIFO_LEN >> 1) ) + return 1; + + return 0; +} +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +int new_cycle_fifo_load(int box, unsigned long adr, int * adr_from, unsigned long addr_to, unsigned long quant, int extended, int priority, int cmd_wait) +{ + unsigned int ind; + + if (((new_cycle_fifo.index_data - new_cycle_fifo.index_send)&NEW_CYCLE_FIFO_LEN_MASK)>=(NEW_CYCLE_FIFO_LEN_MASK-3)) + { + new_cycle_fifo.count_lost++; +// may_be_send_cycle_fifo(); // на всякий случай дернем передачу, вдруг мы не передаем почему-то, а массив забит! + return -1; // переполнили! + } + + if (new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].box==0) // тут чисто можно загружать + { + + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].box = box; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].adr = adr; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].adr_to = addr_to; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].adr_from = adr_from; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].quant = quant; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].extended = extended; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].priority = priority; + new_cycle_fifo.cycle_data[new_cycle_fifo.index_data].busy = 1; + + + // увеличиваем длину очереди для этого ящика + new_cycle_fifo.cycle_box[box]++; + + if (new_cycle_fifo.index_data == new_cycle_fifo.index_send) + { + // мы похоже ничего не передаем, индексы совпадают + // + + } + + // сдвигаем индекс + new_cycle_fifo.index_data++; + new_cycle_fifo.index_data &= NEW_CYCLE_FIFO_LEN_MASK; +// if (new_cycle_fifo.index_data>=NEW_CYCLE_FIFO_LEN) // перешли в ноль индекс +// new_cycle_fifo.index_data = 0; // перешли в ноль индекс + +// may_be_send_fifo(); +// if (cmd_wait==0) +// may_be_send_cycle_fifo(); + + return 1; // все ок! + } + else + { + new_cycle_fifo.count_lost++; + +// may_be_send_cycle_fifo(); // на всякий случай дернем передачу, вдруг мы не передаем почему-то, а массив забит! + return -1; // переполнили! + } + + +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + + +int CAN_FLY_free(int box) +{ + return !cycle[box].FLY; +} + + +int CAN_cycle_free(int box) +{ + int i; + +#if (CAN_PROTOCOL_VERSION==2) + + if (new_cycle_fifo.cycle_box[box] >= 200) + { + new_cycle_fifo.lost_box[box]++; + return 0; + } + else + return 1; + +#endif + +#if (CAN_PROTOCOL_VERSION==1) + return !cycle[box].busy; +#endif +} + +int CAN_cycle_full_free(int box, int statistics_flag) +{ + int i; + +#if (CAN_PROTOCOL_VERSION==2) + + if (new_cycle_fifo.cycle_box[box] != 0) + { + if (statistics_flag==CAN_BOX_STAT_ON) + new_cycle_fifo.lost_box[box]++; + return 0; + } + else + return 1; + +#endif + +#if (CAN_PROTOCOL_VERSION==1) + return !cycle[box].busy; +#endif +} +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +int CAN_FIFO_free(unsigned int quant) +{ +#if (CAN_PROTOCOL_VERSION==2) + return 0; +#endif + +#if (CAN_PROTOCOL_VERSION==1) + return ((FIFO_LEN-(unsigned int)fifo.adr)>quant); +#endif + +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + +void CAN_cycle_stop(int box) +{ + cycle[box].busy=0; +} + + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + + +#pragma CODE_SECTION(CAN_send2,".fast_run2"); +void CAN_send2(int box,unsigned long hiword, unsigned long loword) +{ + volatile struct MBOX *Mailbox; + unsigned long mask; + +// cycle[box].FLY = 1; + + new_cycle_fifo.flag_inter = 1; + + mask = ((unsigned long)1<MDH.all = hiword; + Mailbox->MDL.all = loword; + + + ECanaRegs.CANTRS.all = mask; + +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +/////////////////////////////////////////////// +int get_real_out_mbox(int type_box, int box) +{ + if (type_box==FREE_TYPE_BOX) + return -1; + + if (type_box==UNITS_TYPE_BOX) + { + if (box new_cycle_fifo.cycle_data[cur_send_index].priority) + && new_cycle_fifo.cycle_data[next_send_index].box) + { + // выделили данные с большим приоритетом + new_data = new_cycle_fifo.cycle_data[next_send_index]; + new_cycle_fifo.index_send--; + new_cycle_fifo.index_send &= NEW_CYCLE_FIFO_LEN_MASK; + // и записали их на самый верх и -1 + new_cycle_fifo.cycle_data[new_cycle_fifo.index_send] = new_data; + + new_cycle_fifo.cycle_data[next_send_index].box = 0; + new_cycle_fifo.cycle_data[next_send_index].busy = 0; + return; + + } + } while (next_send_index!=new_cycle_fifo.index_data); + + return; + + + + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(CAN_cycle_fifo_step,".fast_run1"); +int CAN_cycle_fifo_one_box(void) +{ + unsigned long hiword,loword,mask; + unsigned int * point; + unsigned int box=0, index; + + index = new_cycle_fifo.index_send; + // уже все передали? выходим... + if (index == new_cycle_fifo.index_data) + return 0; + // текущий слот передачи уже пуст... выходим. +// if (new_cycle_fifo.cycle_data[index].box==0) +// return; + + // проверка на завершение передачи данных, уже все передано, весь массив данных quant штук. + if(new_cycle_fifo.cycle_data[index].adr>=new_cycle_fifo.cycle_data[index].quant || new_cycle_fifo.cycle_data[index].box==0) + { + //уменьшаем длину очереди для этого ящика + if (new_cycle_fifo.cycle_data[index].box) + new_cycle_fifo.cycle_box[new_cycle_fifo.cycle_data[index].box]--; + // затираем переданные в new_fifo в слоте данных + new_cycle_fifo.cycle_data[index].busy = 0; + // очищаем данный слот передачи, нужно переходить к следующему + new_cycle_fifo.cycle_data[index].box = 0; + + // сдвигаем индекс + new_cycle_fifo.index_send++; + new_cycle_fifo.index_send &= NEW_CYCLE_FIFO_LEN_MASK; + + return 0; + } + + +// данные есть, передаем их + mask = 0xE000; + if(new_cycle_fifo.cycle_data[index].adr==new_cycle_fifo.cycle_data[index].quant-1) mask = 0x8000; + if(new_cycle_fifo.cycle_data[index].adr==new_cycle_fifo.cycle_data[index].quant-2) mask = 0xC000; + + point = (unsigned int *)&hiword; + + // адрес данных + if (new_cycle_fifo.cycle_data[index].extended == 0) + point[1] = mask | (new_cycle_fifo.cycle_data[index].adr_to + new_cycle_fifo.cycle_data[index].adr); + else + { + // расширение, для передачи большого массива, удаляем mask чтоб влез больший адрес. + point[1] = (new_cycle_fifo.cycle_data[index].adr_to + new_cycle_fifo.cycle_data[index].adr)/3L; // делим на 3 чтоб влез больший адрес в слово, получается 65535*3 = 196605 слов, максимальный размер передаваемого буфера при extended=1 + } + + // первое слово данный + point[0] = new_cycle_fifo.cycle_data[index].adr_from[new_cycle_fifo.cycle_data[index].adr]; + point = (unsigned int *)&loword; + // второе слово данный + point[1] = new_cycle_fifo.cycle_data[index].adr_from[new_cycle_fifo.cycle_data[index].adr+1]; + // третье слово данных + point[0] = new_cycle_fifo.cycle_data[index].adr_from[new_cycle_fifo.cycle_data[index].adr+2]; + + new_cycle_fifo.cycle_data[index].adr+=3; + + box = new_cycle_fifo.cycle_data[index].box; + + +#if (CAN_PROTOCOL_VERSION==2) + CAN_send2(box,hiword,loword); + //new_fifo_load(box,hiword,loword); +#endif + + + return 1; + +} +//////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// + +//#pragma CODE_SECTION(CAN_cycle_fifo_step,".fast_run1"); +int CAN_cycle_fifo_step(void) +{ + unsigned long hiword,loword,mask; + unsigned int * point; + unsigned int box=0, index; + + index = new_cycle_fifo.index_send; + // уже все передали? выходим... + if (index==new_cycle_fifo.index_data) + return 0; + // текущий слот передачи уже пуст... выходим. +// if (new_cycle_fifo.cycle_data[index].box==0) +// return; + + if (new_cycle_fifo.flag_inter==0) + { + realign_new_cycle_fifo_on_priority(); + CAN_cycle_fifo_one_box(); + + } + + + return 1; +} +//////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +#define CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK 333L //99 // кратное 3 надо делать +//#pragma CODE_SECTION(CAN_cycle_send,".fast_run2"); +void CAN_cycle_send(int type_box, int box, unsigned long Addr, int * Data, unsigned long quant, int extended, int priority) +{ + int real_mbox; + unsigned int old_time; + + real_mbox = get_real_out_mbox (type_box, box); + if (real_mbox<0) + return; + +#if (CAN_PROTOCOL_VERSION==1) + cycle[real_mbox].adr = 0; + cycle[real_mbox].adr_from = Data; + cycle[real_mbox].adr_to = Addr; + cycle[real_mbox].quant = quant; + cycle[real_mbox].busy = 1; + cycle[real_mbox].extended = extended; + + + CAN_cycle_step(real_mbox); +#endif + + +#if (CAN_PROTOCOL_VERSION==2) + if (priority==CAN_BOX_PRIORITY_LOW) + { + do + { +// if (get_new_cycle_fifo_load_level()<=2) + + if (quant>CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK) + { + if (new_cycle_fifo_load (real_mbox, 0, Data, Addr, CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK, extended, priority, 1) == 1) + { + quant -= CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK; + Data += CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK; + Addr += CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCK; + } + } + else + { + new_cycle_fifo_load (real_mbox, 0, Data, Addr, quant, extended, priority, 0); + quant = 0; + } + + } + while (quant>0); + +// + + } + else + new_cycle_fifo_load (real_mbox, 0, Data, Addr, quant, extended, priority, 0); + +#endif + +} +//////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// +// инкремен счетчика полных посылок для УКСС +//////////////////////////////////////////////////////////////// +void detect_time_refresh_units(int box, int adr) +{ + if (box>=UNIT_QUA_UNITS) + return; + + if (adr==unites_can_setup.adr_detect_refresh[box]) + { + //CAN_count_cycle_input_units[box]++; + if (box=MPU_UNIT_QUA_UNITS) + return; + + if (adr==mpu_can_setup.adr_detect_refresh[box]) + { + //CAN_count_cycle_input_units[box]++; + if (box> 16 ) & 0xffff; + CanOpenUnites[adr+1] = (h_word ) & 0xffff; + CanOpenUnites[adr+2] = (l_word >> 16 ) & 0xffff; + CanOpenUnites[adr+3] = (l_word ) & 0xffff; + } +} + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +void parse_data_from_mbox(unsigned int box, unsigned long hiword, + unsigned long loword) +{ + unsigned int bit[3], real_mbox; + int local_number_box; + int adr; + static int reply_box = 0; + static volatile int err=0; + + +//////////////////////////////////////////////////////////////////// +// CAN OPEN +//////////////////////////////////////////////////////////////////// + + if (mailboxs_can_setup.type_box[box] == CANOPEN_TYPE_BOX) + { +#ifdef BWC_CAN_FATEC + messageParserToUnites(box, hiword, loword); +#endif +#ifdef BWC_CAN_SIEMENS + messageParserToUnitesSiemens(box, hiword, loword); +#endif +#ifdef INGITIM_CAN_OPEN + messagePaserToUnitesIngitim(box, hiword, loword); +#endif +// messageParser(box, hiword, loword); + return; + } + + adr = hiword >> 16; + bit[0] = adr & 0x8000; + bit[1] = adr & 0x4000; + bit[2] = adr & 0x2000; + adr &= 0x1fff; +// ------------------------------------------------------------------------- +// Используетси стандартное CAN-сообщение, а 8 байт данных имеют следующий формат: +// | 3 бита маска данных | регистр (13 бит) | data1 | data2 | data3 | +// маска данных: [0|1] - обрабатывать ли соответствующее dataX +// регистр: начальный регистр с которым ведётсЯ работа +// при "записи" соотвественно: регистр=data1, регистр+1=data2, регистр+2=data3 +// при "чтении" соотвественно: читаетсЯ регистр, регистр+2, регистр+3 +// Всё это при условии, что все три бита маски = "1". +// ------------------------------------------------------------------------- + + +//////////////////////////////////////////////////////////////////// +//SMPU_CAN_DEVICE - специальный Ящик длЯ удаленной прошивки контроллера через МПУ ID = 0x80CEB0E1; +//////////////////////////////////////////////////////////////////// + +/* if (mailboxs_can_setup.type_box[box] == SMPU_TYPE_BOX) + { + if (adr==5 || adr==1) + { + run_cmd_super_can_5(adr,(unsigned int)((hiword ) & 0xffff),(unsigned int)((loword>>16) & 0xffff),(unsigned int)((loword) & 0xffff)); + } + else + ready_run_cmd_super_can(adr,(unsigned int)((hiword ) & 0xffff),(unsigned int)((loword>>16) & 0xffff),(unsigned int)((loword) & 0xffff)); + + return; + } + +*/ + +/////////////////////////////////////////////////////////////////// +//MPU +/////////////////////////////////////////////////////////////////// + + if (mailboxs_can_setup.type_box[box] == MPU_TYPE_BOX) + { + local_number_box = mailboxs_can_setup.local_number_box[box]; + if (local_number_box>=MPU_UNIT_QUA_UNITS) + return; + + if(bit[0]) + { + timer_pause_enable_can_from_mpu(); + if (adr0) + { + if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((hiword ) & 0xffff); + detect_time_refresh_mpu(local_number_box,adr-1); + } + adr++; + } + else + { + err++; + } + } + if(bit[1]) + { + timer_pause_enable_can_from_mpu(); + if (adr0) + { + if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword>>16) & 0xffff); + detect_time_refresh_mpu(local_number_box,adr-1); + } + adr++; + } + else + { + err++; + } + } + + if(bit[2]) + { + timer_pause_enable_can_from_mpu(); + if (adr0) + { + if (flag_enable_can_from_mpu && flag_disable_update_modbus_in_can_from_mpu==0) + modbus_table_can_in[adr-1].all = /*(unsigned int)*/((loword) & 0xffff); + detect_time_refresh_mpu(local_number_box,adr-1); + } + adr++; + } + else + { + err++; + } + } + real_mbox = get_real_in_mbox (MPU_TYPE_BOX, 0); + + return; + } + +/////////////////////////////////////////////////////////////////// +//TERMINAL +//////////////////////////////////////////////////////////////////// + + if (mailboxs_can_setup.type_box[box] == TERMINAL_TYPE_BOX) + { + local_number_box = mailboxs_can_setup.local_number_box[box]; + if (local_number_box>=TERMINAL_UNIT_QUA_UNITS) + return; + + if(bit[0]) + { + timer_pause_enable_can_from_terminal(); + if (adr=0) && flag_enable_can_from_terminal) + { + TerminalUnites[local_number_box][adr] = /*(unsigned int)*/((hiword ) & 0xffff); + } + adr++; + } + } + if(bit[1]) + { + timer_pause_enable_can_from_terminal(); + if (adr=0) && flag_enable_can_from_terminal) + { + TerminalUnites[local_number_box][adr] = /*(unsigned int)*/((loword>>16) & 0xffff); + } + adr++; + } + } + + if(bit[2]) + { + timer_pause_enable_can_from_terminal(); + if (adr=0) && flag_enable_can_from_terminal) + { + TerminalUnites[local_number_box][adr] = /*(unsigned int)*/((loword) & 0xffff); + } + adr++; + } + } + + return; + } + +//////////////////////////////////////////////////////////////////// +//UKSS +//////////////////////////////////////////////////////////////////// + if (mailboxs_can_setup.type_box[box] == UNITS_TYPE_BOX) + { + local_number_box = mailboxs_can_setup.local_number_box[box]; + + if (local_number_box>=UNIT_QUA_UNITS) + return; + + if(bit[0]) + { + if ( (adr=0) ) + { + Unites[local_number_box][adr] = (hiword ) & 0xffff; + detect_time_refresh_units(local_number_box,adr); + } + adr++; + } + + + if(bit[1]) + { + if ( (adr=0) ) + { + Unites[local_number_box][adr] = ((loword>>16) & 0xffff); + detect_time_refresh_units(local_number_box,adr); + } + adr++; + } + + if(bit[2]) + { + if ( (adr=0) ) + { + Unites[local_number_box][adr] = (loword ) & 0xffff; + detect_time_refresh_units(local_number_box,adr); + } + adr++; + } + + return; + } +} + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + +//#pragma CODE_SECTION(CAN_handler,".fast_run"); +interrupt void CAN_handler(void) +{ + volatile struct MBOX *Mailbox; + unsigned long hiword, loword, mask = 1; + int box,type_in_out_box, box_i; + + // Set interrupt priority: + volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all; + IER |= M_INT9; + IER &= MINT9; // Set "global" priority + + PieCtrlRegs.PIEIER9.all &= MG95; // Set "group" priority + PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.can) + i_led1_on_off_special(1); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.can) + i_led2_on_off_special(1); +#endif + + EINT; + + box = ECanaRegs.CANGIF0.bit.MIV0; + + mask <<= box; + + type_in_out_box = mailboxs_can_setup.type_in_out_box[box]; + + if(type_in_out_box == CAN_BOX_TYPE_OUT) + { + cycle[box].FLY=0; +// new_cycle_fifo.flag_inter = 0; + + ECanaRegs.CANTA.all = mask; + ECanaRegs.CANAA.all = mask; + +#ifdef SUPER_CAN + if(box == SMPU_CAN_DEVICE_TRANSMIT) // SMPU_CAN_DEVICE_TRANSMIT - ID = 0x80CEB0F1; + { + loword = Mailbox->MDL.all; + hiword = Mailbox->MDH.all; + adr = (hiword >> 16) & 0x1FFF; + if(adr == 5) // + { + flag_send_mess_super_can = 1; + } + } +#endif + +#if (CAN_PROTOCOL_VERSION==1) + if(!BUSY && fifo.adr && !cycle[fifo.pak[fifo.adr-1].box].FLY) + { + BUSY=1; + fifo.adr--; + CAN_send( fifo.pak[fifo.adr].box, + fifo.pak[fifo.adr].hiword, + fifo.pak[fifo.adr].loword); + BUSY=0; + } + else if(refo.adr && !cycle[refo.pak[refo.adr-1].box].FLY) + { + refo.adr--; + CAN_send( refo.pak[refo.adr].box, + refo.pak[refo.adr].hiword, + refo.pak[refo.adr].loword); + } + + if(cycle[box].busy) // 26.01.2011 Dimas + CAN_cycle_step(box); // 26.01.2011 Dimas +#endif + + + + +#if (CAN_PROTOCOL_VERSION==2) + + new_cycle_fifo.flag_inter = CAN_cycle_fifo_one_box();//CAN_cycle_fifo_step(new_cycle_fifo.index_send); + +// // передаем что накопилось в буфере +// new_fifo_unload(); +// +// // смотрим есть ли данные в цепочке ящика передачи для этого ящика что закончил передачу +// if(cycle[box].busy) // +// CAN_cycle_step(box); // +// +// +// if(cycle[box].busy==0) // +// { +// // а тут смотрим есть ли данные в цепочке других ящиков +// for (box_i=0;box_iMDL.all; + hiword = Mailbox->MDH.all; + + if (enable_can_recive_after_units_box) + { + parse_data_from_mbox(box, hiword, loword); + } + + CAN_timeout[box]=0; // сбросили ошибку таймаута по приему + CAN_refresh_cicle[box]=CAN_timeout_cicle[box]; + CAN_timeout_cicle[box]=0; + +// led2_toggle(); + } + +//#if (CAN_PROTOCOL_VERSION==2) +//// // передаем что накопилось в буфере +//// new_fifo_unload(); +//// +// // а тут смотрим есть ли данные в цепочке других ящиков +// for (box_i=0;box_i=TIME_PAUSE_CAN_FROM_TERMINAL) + { + time_pause_enable_can_from_terminal=TIME_PAUSE_CAN_FROM_TERMINAL; + flag_enable_can_from_terminal = 1; + } + +} + + +void timer_pause_enable_can_from_mpu(void) +{ + time_pause_enable_can_from_mpu++; + if (time_pause_enable_can_from_mpu>=TIME_PAUSE_CAN_FROM_MPU) + { + time_pause_enable_can_from_mpu=TIME_PAUSE_CAN_FROM_MPU; + flag_enable_can_from_mpu = 1; + } + +} + +unsigned int test_can_live_mpu(void) +{ + if (CAN_timeout[get_real_out_mbox(MPU_TYPE_BOX,0)]==0) + return 1; + else + return 0; +} + + +unsigned int test_can_live_terminal(int n) +{ + if (CAN_timeout[get_real_out_mbox(TERMINAL_TYPE_BOX,n)]==0) + return 1; + else + return 0; +} + + + +void InitCanSoft(void) +{ + struct ECAN_REGS ECanaShadow; + int i, c; + volatile struct MBOX *tmbox; + volatile Uint32 *tmoto; + + unsigned long canme_bits = 0; + unsigned long canmd_bits = 0; + unsigned long canmim_bits = 0; + + +// Configure CAN pins using GPIO regs here + EALLOW; + +// GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1; +// GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1; + +// Configure the eCAN RX and TX pins for eCAN transmissions +// ECanaRegs.CANTIOC.all = 8; // only 3rd bit, TXFUNC, is significant +// ECanaRegs.CANRIOC.all = 8; // only 3rd bit, RXFUNC, is significant + + +// Specify that 8 bits will be sent/received +// for (c=0;c<32;c++) +// { +// tmbox = &ECanaMboxes.MBOX0 + c; +// tmbox->MSGCTRL.all = 0x00000008; +// } + +// Disable all Mailboxes +// Required before writing the MSGIDs +// ECanaRegs.CANME.all = 0; + + canme_bits = 0; + canmd_bits = 0; + canmim_bits = 0; + + // receive+transive //Ura + for (c=0;c<32;c++) + { + + if (mailboxs_can_setup.can_mbox_adr[c]) + { +// tmbox = &ECanaMboxes.MBOX0 + c; +// if(mailboxs_can_setup.type_box[c] == UNITS_TYPE_BOX) +// { +//// tmbox->MSGID.bit.IDE = 0; +//// tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; +// tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; +// } +// else +// { +// if(mailboxs_can_setup.type_box[c] == CANOPEN_TYPE_BOX) +// { +// tmbox->MSGID.bit.IDE = 0; +// tmbox->MSGID.bit.STDMSGID = mailboxs_can_setup.can_mbox_adr[c]; +// //tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; +// } +// else +// tmbox->MSGID.all = mailboxs_can_setup.can_mbox_adr[c]; +// } + + canme_bits |= ((unsigned long)1< + +#include "word_structurs.h" +#include "DSP281x_Device.h" + +#define MAX_COUNT_UNITES_TERMINAL 4 // фикс +#define MAX_COUNT_UNITES_UKSS 16 // фикс +#define MAX_COUNT_UNITES_MPU 4 // фикс +#define MAX_COUNT_UNITES_ALARM_LOG 2 // фикс + +//////////////////////////////////////// + +#define CAN_ADR_TERMINAL_DEFAULT 0x00EEEE01 +#define START_CAN_ADR_UNITS_DEFAULT 0x00235500 +#define CAN_ADR_MPU_DEFAULT 0x00CEB0E1 +#define CAN_ADR_ALARM_LOG_DEFAULT 0x0BCDEF01 + + +//////////////////////////////////////// +// подсчет кол-ва блоков MPU +// должны быть активированы в CAN_project.c +//////////////////////////////////////// + +#ifndef USE_MPU_0 +#define USE_MPU_0 0 +#endif + +#ifndef USE_MPU_1 +#define USE_MPU_1 0 +#endif + +#ifndef USE_MPU_2 +#define USE_MPU_2 0 +#endif + +#ifndef USE_MPU_3 +#define USE_MPU_3 0 +#endif + + + +#define MPU_UNIT_QUA_UNITS ( USE_MPU_0 + USE_MPU_1 \ + + USE_MPU_2 + USE_MPU_3 \ + ) //кол-во ящиков для MPU_CAN + + + + + +/////////////////////////////////////////// +// кол-во ящиков для TERMINAL_CAN +/////////////////////////////////////////// + +//////////////////////////////////////// +// подсчет кол-ва блоков TERMINAL +// должны быть активированы в CAN_project.c +//////////////////////////////////////// +#ifndef USE_TERMINAL_1_OSCIL +#define USE_TERMINAL_1_OSCIL 0 +#endif + +#ifndef USE_TERMINAL_1_CMD +#define USE_TERMINAL_1_CMD 0 +#endif + +#ifndef USE_TERMINAL_2_OSCIL +#define USE_TERMINAL_2_OSCIL 0 +#endif + +#ifndef USE_TERMINAL_2_CMD +#define USE_TERMINAL_2_CMD 0 +#endif + + + +#define TERMINAL_UNIT_QUA_UNITS ( USE_TERMINAL_1_OSCIL + USE_TERMINAL_1_CMD \ + + USE_TERMINAL_2_OSCIL + USE_TERMINAL_2_CMD \ + ) //кол-во ящиков для TERMINAL_CAN + + +//////////////////////////////////////// +// подсчет кол-ва блоков ALARM_LOG +// должны быть активированы в CAN_project.c +//////////////////////////////////////// + +#ifndef USE_ALARM_LOG_0 +#define USE_ALARM_LOG_0 0 +#endif + +#ifndef USE_ALARM_LOG_1 +#define USE_ALARM_LOG_1 0 +#endif + + + +#define ALARM_LOG_UNIT_QUA_UNITS ( USE_ALARM_LOG_0 + USE_ALARM_LOG_1 \ + ) //кол-во ящиков для ALARM_LOG_CAN + + + + + + +//////////////////////////////////////// +// подсчет кол-ва блоков ukss +// должны быть активированы в CAN_project.c +//////////////////////////////////////// + +#ifndef USE_UKSS_0 +#define USE_UKSS_0 0 +#endif + +#ifndef USE_UKSS_1 +#define USE_UKSS_1 0 +#endif + +#ifndef USE_UKSS_2 +#define USE_UKSS_2 0 +#endif + +#ifndef USE_UKSS_3 +#define USE_UKSS_3 0 +#endif + +#ifndef USE_UKSS_4 +#define USE_UKSS_4 0 +#endif + +#ifndef USE_UKSS_5 +#define USE_UKSS_5 0 +#endif + +#ifndef USE_UKSS_6 +#define USE_UKSS_6 0 +#endif + +#ifndef USE_UKSS_7 +#define USE_UKSS_7 0 +#endif + +#ifndef USE_UKSS_8 +#define USE_UKSS_8 0 +#endif + +#ifndef USE_UKSS_9 +#define USE_UKSS_9 0 +#endif + +#ifndef USE_UKSS_10 +#define USE_UKSS_10 0 +#endif + +#ifndef USE_UKSS_11 +#define USE_UKSS_11 0 +#endif + +#ifndef USE_UKSS_12 +#define USE_UKSS_12 0 +#endif + +#ifndef USE_UKSS_13 +#define USE_UKSS_13 0 +#endif + +#ifndef USE_UKSS_14 +#define USE_UKSS_14 0 +#endif + +#ifndef USE_UKSS_15 +#define USE_UKSS_15 0 +#endif + + +#ifndef USE_R_B_0 +#define USE_R_B_0 0 +#endif +#ifndef USE_R_B_1 +#define USE_R_B_1 0 +#endif +#ifndef USE_R_B_2 +#define USE_R_B_2 0 +#endif +#ifndef USE_R_B_3 +#define USE_R_B_3 0 +#endif +#ifndef USE_R_B_4 +#define USE_R_B_4 0 +#endif +#ifndef USE_R_B_5 +#define USE_R_B_5 0 +#endif +#ifndef USE_R_B_6 +#define USE_R_B_6 0 +#endif +#ifndef USE_R_B_7 +#define USE_R_B_7 0 +#endif +#ifndef USE_R_B_8 +#define USE_R_B_8 0 +#endif +#ifndef USE_R_B_9 +#define USE_R_B_9 0 +#endif +#ifndef USE_R_B_10 +#define USE_R_B_10 0 +#endif +#ifndef USE_R_B_11 +#define USE_R_B_11 0 +#endif +#ifndef USE_R_B_12 +#define USE_R_B_12 0 +#endif +#ifndef USE_R_B_13 +#define USE_R_B_13 0 +#endif +#ifndef USE_R_B_14 +#define USE_R_B_14 0 +#endif +#ifndef USE_R_B_15 +#define USE_R_B_15 0 +#endif + + +#define UNIT_QUA_UNITS ( USE_UKSS_0 + USE_UKSS_1 \ + + USE_UKSS_2 + USE_UKSS_3 \ + + USE_UKSS_4 + USE_UKSS_5 \ + + USE_UKSS_6 + USE_UKSS_7 \ + + USE_UKSS_8 + USE_UKSS_9 \ + + USE_UKSS_10 + USE_UKSS_11 \ + + USE_UKSS_12 + USE_UKSS_13 \ + + USE_UKSS_14 + USE_UKSS_15) // 2 //3//8 //количество CAN устройств передающих в системе CANMODBUS - кол-во Unites + +/////////////////////////////////////////// +// настройки CAN_Open +/////////////////////////////////////////// + +#ifdef INGITIM_CAN_OPEN + #define MBOX0_CANOPEN 0x00000013 //0x180 t1PDO1 + #define MBOX1_CANOPEN 0x0000018d //0x280 t2PDO1 + #define MBOX2_CANOPEN 0x000000c5 //0x380 t3PDO1 + #define MBOX3_CANOPEN 0x12000000 //0x480 t4PDO1 + #define MBOX4_CANOPEN 0x16000000 //0x580 t4PDO1 + #define MBOX5_CANOPEN 0x1a000000 //0x680 t4PDO1 + +#define CANOPEN_CAN_SETUP_DEFAULT { {MBOX0_CANOPEN,MBOX1_CANOPEN,MBOX2_CANOPEN,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + 3} + +#endif + + +#ifdef BWC_CAN_FATEC + #define MBOX0_CANOPEN 0x08040000 //201; 010 0000 0001 + #define MBOX1_CANOPEN 0x0C040000 //301; 011 0000 0001 + #define MBOX2_CANOPEN 0x10040000 //401; 100 0000 0001 + #define MBOX3_CANOPEN 0x14040000 //501; 101 0000 0001 + #define MBOX4_CANOPEN 0x08080000 //202; 010 0000 0010 + #define MBOX5_CANOPEN 0x0C080000 //302; 011 0000 0010 + #define MBOX6_CANOPEN 0x10080000 //402; 100 0000 0010 + #define MBOX7_CANOPEN 0x14080000 //502; 101 0000 0010 + +#define CANOPEN_CAN_SETUP_DEFAULT { {MBOX0_CANOPEN,MBOX1_CANOPEN,MBOX2_CANOPEN,MBOX3_CANOPEN,MBOX4_CANOPEN,MBOX5_CANOPEN,MBOX6_CANOPEN,MBOX7_CANOPEN,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,1,2,3,4,5,6,7,-1,-1,-1,-1,-1,-1,-1,-1}, \ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + 0} + +#endif + +#ifdef BWC_CAN_SIEMENS + #define MBOX0_CANOPEN 0x00040000 // 0x08040000 //201; 010 0000 0001 + #define MBOX1_CANOPEN 0x00080000 //301; 011 0000 0001 + +#define CANOPEN_CAN_SETUP_DEFAULT { {MBOX0_CANOPEN,MBOX1_CANOPEN,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,1,2,3,4,5,6,7,-1,-1,-1,-1,-1,-1,-1,-1}, \ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + 0} +#endif + + +#ifndef CANOPEN_CAN_SETUP_DEFAULT +#define CANOPEN_CAN_SETUP_DEFAULT { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, \ + 0} +#endif + + +///////////////////////////////////////////////////////////////////// + + + + + +extern int CAN_input_data[]; +extern int CAN_output_data[]; +extern int* CAN_output; + +extern int flag_enable_can_from_mpu; + + +///////////////////////////////////////////////////////////////////// + + +#define UNIT_QUA 32 //12 // ­  количество CAN устройств в системе - Ящиков + + + +#define TERMINAL_UNIT_LEN 128 +#define UNIT_LEN 128 +#define FIFO_LEN 10 +#define NEW_FIFO_LEN 128 +#define NEW_CYCLE_FIFO_LEN 256 +#define NEW_CYCLE_FIFO_LEN_MASK (NEW_CYCLE_FIFO_LEN-1) + + + + +//////////////////////////////////////////////////// +//////////////////////////////////////////////////// +//////////////////////////////////////////////////// + +typedef struct +{ + int * adr_from; + unsigned int adr_to; + unsigned int adr; + unsigned int quant; + int busy; + int FLY; + int extended; + +} CYCLE; + + +typedef struct +{ + int * adr_from; + unsigned long adr_to; + unsigned long adr; + unsigned long quant; + int busy; + int FLY; + int extended; + int box; + int priority; + unsigned int quant_block; + +} NEW_CYCLE_DATA; + +typedef struct +{ + int box; + long hiword; + long loword; + +} PACK; + + + +typedef struct +{ + int adr; + PACK pak[FIFO_LEN]; + +}FIFO; + + +typedef struct +{ + int index_data; // текущий индекс при загрузке данными + int index_send; // текущий индекс при передаче + int flag_inter; // мы ждем сброса в прерывании + unsigned int count_lost; // количество потерь + unsigned int count_load; // загрузка массива + unsigned int count_free; // свобода массива + NEW_CYCLE_DATA cycle_data[NEW_CYCLE_FIFO_LEN]; + int cycle_box[UNIT_QUA]; + int lost_box[UNIT_QUA]; + + +}NEW_CYCLE_FIFO; + +////////////////////////////////////// +////////////////////////////////////// +////////////////////////////////////// + +#define USE_BOX 1 +#define NOT_USE_BOX 0 + +#define CAN_BOX_TYPE_IN 1 +#define CAN_BOX_TYPE_OUT 2 + + +#define FREE_TYPE_BOX 0 +#define UNITS_TYPE_BOX 1 +#define MPU_TYPE_BOX 2 +#define CANOPEN_TYPE_BOX 3 +#define SMPU_TYPE_BOX 4 +#define TERMINAL_TYPE_BOX 5 +#define ALARM_LOG_TYPE_BOX 6 + +///////////////////////////////////////////////////////////////////// + +#define CAN_BOX_PRIORITY_NORMAL 0 +#define CAN_BOX_PRIORITY_LOW -1 +#define CAN_BOX_PRIORITY_HIGH 1 + +///////////////////////////////////////////////////////////////////// +#define CAN_BOX_EXTENDED_ADR 1 +#define CAN_BOX_STANDART_ADR 0 +///////////////////////////////////////////////////////////////////// +#define CAN_BOX_STAT_ON 1 +#define CAN_BOX_STAT_OFF 0 +///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// + +typedef struct { + long can_in_mbox_adr[16]; + long can_out_mbox_adr[16]; + int adr_box[16]; + int adr_in_mbox[16]; + + int max_number; + +} CANOPEN_CAN_SETUP; + +///////////////////////////////////////////////////////////////////// +typedef struct { + long can_mbox_adr[32]; +// long can_out_mbox_adr[16]; + int type_box[32]; + int local_number_box[32]; + int type_in_out_box[32]; + + int max_number_in; + int max_number_out; + +} MAILBOXS_CAN_SETUP; + +#define MAILBOXS_CAN_SETUP_DEFAULT { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, \ + 0, \ + 0} + + +///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// + + +typedef struct { + unsigned long can_base_adr; + long can_in_mbox_adr[MAX_COUNT_UNITES_UKSS]; + long can_out_mbox_adr[MAX_COUNT_UNITES_UKSS]; + int adr_box[MAX_COUNT_UNITES_UKSS+1]; + int adr_in_mbox[MAX_COUNT_UNITES_UKSS+1]; + int adr_out_mbox[MAX_COUNT_UNITES_UKSS+1]; + + int active_box[MAX_COUNT_UNITES_UKSS]; + int adr_detect_refresh[MAX_COUNT_UNITES_UKSS]; + int revers_box[MAX_COUNT_UNITES_UKSS]; + + unsigned int CAN_count_cycle_input_units[MAX_COUNT_UNITES_UKSS]; + + int max_number; + +} UNITES_CAN_SETUP; + +///////////////////////////////////////////////////////////////////// + +typedef struct { + unsigned long can_base_adr; + long can_in_mbox_adr[MAX_COUNT_UNITES_MPU]; + long can_out_mbox_adr[MAX_COUNT_UNITES_MPU]; + int adr_box[MAX_COUNT_UNITES_MPU]; + + int adr_in_mbox[MAX_COUNT_UNITES_MPU]; + int adr_out_mbox[MAX_COUNT_UNITES_MPU]; + + int active_box[MAX_COUNT_UNITES_MPU]; + + unsigned int CAN_count_cycle_input_units[MAX_COUNT_UNITES_MPU]; + + + int adr_detect_refresh[MAX_COUNT_UNITES_MPU]; + + int max_number; + +} MPU_CAN_SETUP; + +///////////////////////////////////////////////////////////////////// + +typedef struct { + unsigned long can_base_adr; + long can_in_mbox_adr[MAX_COUNT_UNITES_TERMINAL]; + long can_out_mbox_adr[MAX_COUNT_UNITES_TERMINAL]; + int adr_box[MAX_COUNT_UNITES_TERMINAL]; + + int adr_in_mbox[MAX_COUNT_UNITES_TERMINAL]; + int adr_out_mbox[MAX_COUNT_UNITES_TERMINAL]; + + int active_box[MAX_COUNT_UNITES_TERMINAL]; + + unsigned int CAN_count_cycle_input_units[MAX_COUNT_UNITES_TERMINAL]; + + int max_number; + +} TERMINAL_CAN_SETUP; + +//////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// + +typedef struct { + unsigned long can_base_adr; + long can_in_mbox_adr[MAX_COUNT_UNITES_ALARM_LOG]; + long can_out_mbox_adr[MAX_COUNT_UNITES_ALARM_LOG]; + int adr_box[MAX_COUNT_UNITES_ALARM_LOG]; + + int adr_in_mbox[MAX_COUNT_UNITES_ALARM_LOG]; + int adr_out_mbox[MAX_COUNT_UNITES_ALARM_LOG]; + + int active_box[MAX_COUNT_UNITES_ALARM_LOG]; + + unsigned int CAN_count_cycle_input_units[MAX_COUNT_UNITES_ALARM_LOG]; + + int max_number; + +} ALARM_LOG_CAN_SETUP; + +//////////////////////////////////////////////////////////////////////////////// +#define _UNITS_DEFAULT_ZERO {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +#define _UNITS_DEFAULT_MINUS_ONE {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} + +#define UNITES_CAN_SETUP_DEFAULT { START_CAN_ADR_UNITS_DEFAULT, _UNITS_DEFAULT_ZERO, \ + _UNITS_DEFAULT_ZERO, \ + _UNITS_DEFAULT_MINUS_ONE, \ + _UNITS_DEFAULT_MINUS_ONE, \ + _UNITS_DEFAULT_MINUS_ONE, \ + {USE_UKSS_0,USE_UKSS_1,USE_UKSS_2,USE_UKSS_3,USE_UKSS_4,USE_UKSS_5, \ + USE_UKSS_6,USE_UKSS_7,USE_UKSS_8,USE_UKSS_9,USE_UKSS_10, \ + USE_UKSS_11,USE_UKSS_12,USE_UKSS_13,USE_UKSS_14,USE_UKSS_15}, \ + _UNITS_DEFAULT_ZERO, \ + {USE_R_B_0,USE_R_B_1,USE_R_B_2,USE_R_B_3,USE_R_B_4,USE_R_B_5,USE_R_B_6,USE_R_B_7,USE_R_B_8, \ + USE_R_B_9,USE_R_B_10,USE_R_B_11,USE_R_B_12,USE_R_B_13,USE_R_B_14,USE_R_B_15}, \ + _UNITS_DEFAULT_ZERO, \ + 0} + +///////////////////////////////////////////////////////////////////// + +#define _MPU_DEFAULT_ZERO {0,0,0,0} +#define _MPU_DEFAULT_MINUS_ONE {-1,-1,-1,-1} + +#define MPU_CAN_SETUP_DEFAULT { CAN_ADR_MPU_DEFAULT, _MPU_DEFAULT_ZERO, \ + _MPU_DEFAULT_ZERO, \ + _MPU_DEFAULT_MINUS_ONE, \ + _MPU_DEFAULT_MINUS_ONE, \ + _MPU_DEFAULT_MINUS_ONE, \ + {USE_MPU_0,USE_MPU_1,USE_MPU_2,USE_MPU_3}, \ + _MPU_DEFAULT_ZERO, \ + _MPU_DEFAULT_ZERO, \ + 0} + +//-------------------------------------------------------------------------------// + +#define _TERMINAL_DEFAULT_ZERO {0,0,0,0} +#define _TERMINAL_DEFAULT_MINUS_ONE {-1,-1,-1,-1} + +#define TERMINAL_CAN_SETUP_DEFAULT {CAN_ADR_TERMINAL_DEFAULT, _TERMINAL_DEFAULT_ZERO, \ + _TERMINAL_DEFAULT_ZERO, \ + _TERMINAL_DEFAULT_MINUS_ONE, \ + _TERMINAL_DEFAULT_MINUS_ONE, \ + _TERMINAL_DEFAULT_MINUS_ONE, \ + {USE_TERMINAL_1_OSCIL,USE_TERMINAL_1_CMD,USE_TERMINAL_2_OSCIL,USE_TERMINAL_2_CMD}, \ + _TERMINAL_DEFAULT_ZERO, \ + 0} +//-------------------------------------------------------------------------------// +#define _ALARM_LOG_DEFAULT_ZERO {0,0} +#define _ALARM_LOG_DEFAULT_MINUS_ONE {-1,-1} + +#define ALARM_LOG_CAN_SETUP_DEFAULT {CAN_ADR_ALARM_LOG_DEFAULT, _ALARM_LOG_DEFAULT_ZERO, \ + _ALARM_LOG_DEFAULT_ZERO, \ + _ALARM_LOG_DEFAULT_MINUS_ONE, \ + _ALARM_LOG_DEFAULT_MINUS_ONE, \ + _ALARM_LOG_DEFAULT_MINUS_ONE, \ + {USE_ALARM_LOG_0,USE_ALARM_LOG_1}, \ + _ALARM_LOG_DEFAULT_ZERO, \ + 0} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +typedef struct { + WORD_INT2BITS_STRUCT buf[TERMINAL_UNIT_LEN]; +} TERMINAL_UNITES_STRUCT; +//// +typedef TERMINAL_UNITES_STRUCT *TERMINAL_UNITES_STRUCT_handle; +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + + +extern int TerminalUnites[TERMINAL_UNIT_QUA_UNITS][TERMINAL_UNIT_LEN]; + +extern int Unites[UNIT_QUA_UNITS][UNIT_LEN]; + + +//////////////////////////////////////////////////////////////////////////////// +extern CYCLE cycle[]; // 26.01.2011 Dimas + + +extern NEW_CYCLE_FIFO new_cycle_fifo; + +extern int CanOpenUnites[CANOPENUNIT_LEN]; + +//add yura +extern MAILBOXS_CAN_SETUP mailboxs_can_setup; + +extern FIFO fifo; + +extern int CAN_timeout[]; +extern int CAN_request_sent[]; +extern unsigned int CAN_timeout_cicle[]; + + +////////////////////////////////////////////////// +////////////////////////////////////////////////// +int init_units_can_boxs(UNITES_CAN_SETUP *p); +int init_canopen_can_boxs(CANOPEN_CAN_SETUP *p); +int init_mpu_can_boxs(MPU_CAN_SETUP *p ); +int init_terminal_can_boxs(TERMINAL_CAN_SETUP *p ); +int init_alarm_log_can_boxs(ALARM_LOG_CAN_SETUP *p ); +////////////////////////////////////////////////// + +void init_mailboxs_can( UNITES_CAN_SETUP *p_units, + MPU_CAN_SETUP *p_mpu, + TERMINAL_CAN_SETUP *p_terminal, + ALARM_LOG_CAN_SETUP *p_alarm_log, + CANOPEN_CAN_SETUP *p_canopen, + MAILBOXS_CAN_SETUP *p_mailboxs + ); + + +void init_all_mailboxs(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, unsigned long can_base_adr_alarm_log, unsigned long can_base_adr_terminal); + + + + +void InitCan(unsigned long can_base_adr_units, unsigned long can_base_adr_mpu, unsigned long can_base_adr_alarm_log, unsigned long can_base_adr_terminal); + + +//void CAN_send(int box, unsigned long hiword, unsigned long loword); +//void CAN_word_send(int type_box, int box, int Addr, int Data); +//void CAN_array_send(int type_box, int box, int Addr, int * Data); + +void CAN_cycle_send(int type_box, int box, unsigned long Addr, int * Data, unsigned long quant, int extended, int priority); + +//void FIFO_send(int box, unsigned long hiword, unsigned long loword); + +//int CAN_FLY_free(int box); +//int CAN_FIFO_free(unsigned int quant); + +int CAN_cycle_free(int box); +int CAN_cycle_full_free(int box, int statistics_flag); + +//void CAN_cycle_stop(int box); + + +//void CAN_cycle_step(int box); + + +void CAN_request(unsigned int addr, unsigned int quant); +void CAN_assign(unsigned int addr, unsigned int quant); + + +void reset_CAN_timeout_cicle(int box); +void inc_CAN_timeout_cicle(); + +unsigned int test_can_live_mpu(void); +unsigned int test_can_live_terminal(int n); +void InitCanSoft(void); + +void timer_pause_enable_can_from_mpu(void); +void timer_pause_enable_can_from_terminal(void); +void read_manch_can(void); +void write_manch_can(void); +void detect_time_refresh_units(int box, int adr); +void detect_time_refresh_mpu(int box, int adr); + + + +void parse_data_from_mbox(unsigned int box, unsigned long hiword, + unsigned long loword); + + +int get_real_out_mbox(int type_box, int box); +int get_real_in_mbox(int type_box, int box); + + + +void messagePaserToUnitesIngitim(int box, unsigned long h_word, unsigned long l_word); + + + + +////////////////// +void new_fifo_calc_load(void); +int new_fifo_load(int box,unsigned long hiword, unsigned long loword); + +int new_cycle_fifo_load(int box, unsigned long adr, int * adr_from, unsigned long addr_to, unsigned long quant, int extended, int priority, int cmd_wait); + +int get_new_cycle_fifo_load_level(void); + + +void CAN_send2(int box,unsigned long hiword, unsigned long loword); +int CAN_cycle_fifo_step(void); +int CAN_cycle_fifo_one_box(void); + +////////////////// +int CAN_may_be_send_cycle_fifo(void); + +void stop_can_interrupt(void); +void start_can_interrupt(void); + + +//// Prototype statements for functions found within this file. +interrupt void CAN_handler(void); +interrupt void CAN_reset_err(void); + + + +extern UNITES_CAN_SETUP unites_can_setup; +extern MPU_CAN_SETUP mpu_can_setup; + + +extern unsigned int CanTimeOutErrorTR; +extern unsigned int CanBusOffError; + +#endif // _CAN_SETUP + diff --git a/Inu/Src2/N12_Libs/RS_modbus_pult.h b/Inu/Src2/N12_Libs/RS_modbus_pult.h new file mode 100644 index 0000000..a1f7ce9 --- /dev/null +++ b/Inu/Src2/N12_Libs/RS_modbus_pult.h @@ -0,0 +1,31 @@ +#ifndef _RS_MODBUS_PULT_H +#define _RS_MODBUS_PULT_H + +#include "modbus_struct.h" +#include "RS_Functions.h" + +void ModbusRTUsend1(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_bits); +void ModbusRTUreceiveAnswer1(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUreceive3(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend3(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start,unsigned int count_word); +void ModbusRTUreceiveAnswer3(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend4(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_word); +void ModbusRTUreceiveAnswer4(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUreceive4(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend5(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start); +void ModbusRTUreceiveAnswer5(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend6(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start); +void ModbusRTUreceiveAnswer6(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend15(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start,unsigned int count_bits); +void ModbusRTUreceiveAnswer15(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUreceive15(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsend16(RS_DATA_STRUCT *rs_arr,int adr_contr, unsigned int adr_start,unsigned int count_words); +void ModbusRTUreceive16(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUreceiveAnswer16(RS_DATA_STRUCT *RS232_Arr); +void ModbusRTUsetDataArrays(MODBUS_REG_STRUCT *array_in, MODBUS_REG_STRUCT *array_out); +void ModbusRTUsetDiscretDataArray(MODBUS_REG_STRUCT *discrete_in, MODBUS_REG_STRUCT *discrete_out); + +extern int flag_wait_anwer_cmd1; + +#endif + diff --git a/Inu/Src2/N12_Libs/RS_modbus_pultl.c b/Inu/Src2/N12_Libs/RS_modbus_pultl.c new file mode 100644 index 0000000..0aa6313 --- /dev/null +++ b/Inu/Src2/N12_Libs/RS_modbus_pultl.c @@ -0,0 +1,1013 @@ +#include + +#include "control_station.h" +#include "modbus_table_v2.h" +#include "options_table.h" +#include "RS_modbus_pult.h" +#include "DSP281x_Device.h" +#include "CRC_Functions.h" +#include "RS_Functions.h" +#include "RS_modbus_svu.h" + + + +//#pragma DATA_SECTION(p_analog_data_in, ".logs"); +MODBUS_REG_STRUCT *p_analog_data_in; + +//#pragma DATA_SECTION(p_analog_data_out, ".logs"); +MODBUS_REG_STRUCT *p_analog_data_out; + +//#pragma DATA_SECTION(p_discrete_data_out, ".logs"); +MODBUS_REG_STRUCT *p_discrete_data_out; + +//#pragma DATA_SECTION(p_discrete_data_in, ".logs"); +MODBUS_REG_STRUCT *p_discrete_data_in; + +static int adres_wait_answer_cmd1 = 0; +static int count_registers_wait_answer = 0; + +void ModbusRTUsetDataArrays(MODBUS_REG_STRUCT *array_in, MODBUS_REG_STRUCT *array_out) +{ + p_analog_data_in = array_in; + p_analog_data_out = array_out; +} + +void ModbusRTUsetDiscretDataArray(MODBUS_REG_STRUCT *discrete_in, MODBUS_REG_STRUCT *discrete_out) +{ + p_discrete_data_in = discrete_in; + p_discrete_data_out = discrete_out; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/***************************************************************/ +/***************************************************************/ +/* Отправка запроса данных по протоколу ModBus - команда 1 + Чтение Ячеек данных Digital Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend1(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_bits) +{ + // КонтрольнаЯ сумма + unsigned int crc; + unsigned int count_data_bytes; + + count_data_bytes = (count_bits % 8) == 0 ? count_bits / 8 : count_bits / 8 + 1; + + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_1; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = HIBYTE(count_bits); + rs_arr->buffer[5] = LOBYTE(count_bits); + + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, 6); + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + + RS_Send(rs_arr, rs_arr->buffer, 10); + + + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + + RS_Len[CMD_RS232_MODBUS_1] = 5 + count_data_bytes; + count_registers_wait_answer = count_bits; + adres_wait_answer_cmd1 = adr_start; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Ответ с данными по протоколу ModBus - команда 1 + Чтение Ячеек данных Digital Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceiveAnswer1(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int first_word, end_byte_number, count_data_bytes, current_register, last_register; + unsigned int displacement_start, displacement, displacement_end, bits_in_last_byte, byte, mask = 0, mask_start, mask_end; + unsigned int i = 0, b = 0, buffer_position = 0, j = 0; +// unsigned char byte_buffer[SIZE_MODBUS_TABLE_DISCRET * 2]; + + /* получили начальный адрес чтениЯ. */ + first_word = (adres_wait_answer_cmd1 % 16 == 0) && (adres_wait_answer_cmd1 != 0) + ? adres_wait_answer_cmd1 / 16 + 1 + : adres_wait_answer_cmd1 / 16; + displacement_start = adres_wait_answer_cmd1 % 16; + displacement = adres_wait_answer_cmd1 % 16; + count_data_bytes = RS232_Arr->RS_Header[2]; + current_register = adres_wait_answer_cmd1; + last_register = adres_wait_answer_cmd1 + count_registers_wait_answer; + displacement_end = last_register % 16; + ///////////////////////////////////////////////// + + mask = 0; + mask_start = 0; + mask_end = 0; + for (i = 0; i < displacement_start; ++i) + { + mask_start |= 1 << i; + mask_end |= 1 << i; + } + mask_start = ~mask_start; + displacement = displacement_start; + for (i = 0; i < count_data_bytes; ++i) + { + byte = RS232_Arr->RS_Header[3 + i]; + mask = 0; + if ((last_register - current_register) > 8) { + mask = 0xFF; + } else { + for (j = 0; j < (last_register - current_register); ++j) { + mask |= 1 << j; + } + } + if (displacement < 8) + { + //mask = mask << displacement; + p_discrete_data_out[first_word].all &= ~(mask << displacement); + p_discrete_data_out[first_word].all |= (byte & mask) << displacement; + } else { + mask_start = (mask << displacement) & 0xFF00; + p_discrete_data_out[first_word].all &= ~mask_start; + p_discrete_data_out[first_word].all |= (byte & mask) << displacement; + mask_end = (mask >> (16 - displacement)) & 0xFF; + p_discrete_data_out[first_word].all &= ~mask_end; + p_discrete_data_out[first_word + 1].all |= (byte & mask) >> (16 - displacement); + } + + + displacement += 8; + if (displacement >= 16) { + displacement -= 16; + first_word += 1; + } + current_register += 8; + + } + + RS_SetControllerLeading(RS232_Arr, false); + RS_SetAdrAnswerController(RS232_Arr, 0); + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +/***************************************************************/ +/***************************************************************/ +/* Запрос данных от мастера по протоколу ModBus - команда 3 + Чтение Ячеек данных Analog Input Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceive3(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, Address_MB, Length_MB, i /*, Data*/; + // int buf_out[200]; + + /* получили начальный адрес чтениy. */ + Address_MB = (RS232_Arr->RS_Header[2] << 8) | RS232_Arr->RS_Header[3]; + + /* получили количество слов данных */ + Length_MB = (RS232_Arr->RS_Header[4] << 8) | RS232_Arr->RS_Header[5]; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + + // f.RScount = SECOND*3; + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_3; + RS232_Arr->buffer[2] = Length_MB * 2; + + for (i = 0; i < Length_MB; i++) + { + if (Address_MB >= ADR_MODBUS_TABLE && Address_MB < 0xe00) + { +// RS232_Arr->buffer[3 + i * 2] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.HB; +// RS232_Arr->buffer[3 + i * 2 + 1] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.LB; + RS232_Arr->buffer[3 + i * 2] = p_analog_data_out[Address_MB + i].byte.HB; + RS232_Arr->buffer[3 + i * 2 + 1] = p_analog_data_out[Address_MB + i].byte.LB; + } + + if (Address_MB >= 0xe00 && Address_MB < 0xf00) + { + RS232_Arr->buffer[3 + i * 2] = options_controller[Address_MB - 0xe00 + i].byte.HB; + RS232_Arr->buffer[3 + i * 2 + 1] = options_controller[Address_MB - 0xe00 + i].byte.LB; + } + } + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, Length_MB * 2 + 3); + + RS232_Arr->buffer[Length_MB * 2 + 3] = LOBYTE(crc); + RS232_Arr->buffer[Length_MB * 2 + 4] = HIBYTE(crc); + + RS232_Arr->buffer[Length_MB * 2 + 5] = 0; + RS232_Arr->buffer[Length_MB * 2 + 6] = 0; +// RS232_Arr->RS_DataWillSend = 1; + RS_Send(RS232_Arr, RS232_Arr->buffer, Length_MB * 2 + 7); + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Отправка запроса данных по протоколу ModBus - команда 3 + Чтение Ячеек данных Analog Input Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend3(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_word) +{ + // КонтрольнаЯ сумма + unsigned int crc; //, Address_MB, Length_MB, i, Data; + // int buf_out[200]; + // int buf_in[200]; + + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_3; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = 0; + rs_arr->buffer[5] = LOBYTE(count_word); + + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, 6); + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + + RS_Send(rs_arr, rs_arr->buffer, 10); + + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + + RS_Len[CMD_RS232_MODBUS_3] = 5 + count_word * 2; + + adr_read_from_modbus3 = adr_start; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Ответ с данными по протоколу ModBus - команда 3 + Чтение Ячеек данных Analog Input Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceiveAnswer3(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int Address_MB, Length_MB, i; + MODBUS_REG_STRUCT elementData; + + /* получили начальный адрес чтениЯ. */ + Address_MB = adr_read_from_modbus3; + + /* получили количество слов данных */ + Length_MB = RS232_Arr->RS_Header[2] >> 1; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + + for (i = 0; i < Length_MB; i++) + { + elementData.byte.HB = RS232_Arr->RS_Header[3 + i * 2]; + elementData.byte.LB = RS232_Arr->RS_Header[3 + i * 2 + 1]; +// p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].all = elementData.all; + if ((Address_MB + i)buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_4; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = 0; + rs_arr->buffer[5] = LOBYTE(count_word); + + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, 6); + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + + RS_Send(rs_arr, rs_arr->buffer, 10); + + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + + RS_Len[CMD_RS232_MODBUS_4] = 5 + count_word * 2; + + adr_read_from_modbus3 = adr_start; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Ответ с данными по протоколу ModBus - команда 4 + Чтение Ячеек данных Analog Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceiveAnswer4(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int Address_MB, Length_MB, i; + static unsigned int prev_Address_MB = 0; + + MODBUS_REG_STRUCT elementData; + + /* получили начальный адрес чтениЯ. */ + Address_MB = adr_read_from_modbus3; + + /* получили количество слов данных */ + Length_MB = RS232_Arr->RS_Header[2] >> 1; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + + for (i = 0; i < Length_MB; i++) + { + elementData.byte.HB = RS232_Arr->RS_Header[3 + i * 2]; + elementData.byte.LB = RS232_Arr->RS_Header[3 + i * 2 + 1]; +// p_analog_data_in[Address_MB - ADR_MODBUS_TABLE + i].all = elementData.all; + if ((Address_MB + i)RS_DataReadyFullUpdate = 1; + + prev_Address_MB = Address_MB; + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Запрос данных от мастера по протоколу ModBus - команда 4 + Чтение Ячеек данных Analog Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceive4(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, Address_MB, Length_MB, i /*, Data*/; + // int buf_out[200]; + + /* получили начальный адрес чтениy. */ + Address_MB = (RS232_Arr->RS_Header[2] << 8) | RS232_Arr->RS_Header[3]; + + /* получили количество слов данных */ + Length_MB = (RS232_Arr->RS_Header[4] << 8) | RS232_Arr->RS_Header[5]; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + + // f.RScount = SECOND*3; + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_4; + RS232_Arr->buffer[2] = Length_MB * 2; + + for (i = 0; i < Length_MB; i++) + { + if (Address_MB >= ADR_MODBUS_TABLE && Address_MB < 0xe00) + { +// RS232_Arr->buffer[3 + i * 2] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.HB; +// RS232_Arr->buffer[3 + i * 2 + 1] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.LB; + RS232_Arr->buffer[3 + i * 2] = p_analog_data_out[Address_MB + i].byte.HB; + RS232_Arr->buffer[3 + i * 2 + 1] = p_analog_data_out[Address_MB + i].byte.LB; + } + + if (Address_MB >= 0xe00 && Address_MB < 0xf00) + { + RS232_Arr->buffer[3 + i * 2] = options_controller[Address_MB - 0xe00 + i].byte.HB; + RS232_Arr->buffer[3 + i * 2 + 1] = options_controller[Address_MB - 0xe00 + i].byte.LB; + } + } + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, Length_MB * 2 + 3); + + RS232_Arr->buffer[Length_MB * 2 + 3] = LOBYTE(crc); + RS232_Arr->buffer[Length_MB * 2 + 4] = HIBYTE(crc); + + RS232_Arr->buffer[Length_MB * 2 + 5] = 0; + RS232_Arr->buffer[Length_MB * 2 + 6] = 0; +// RS232_Arr->RS_DataWillSend = 1; + RS_Send(RS232_Arr, RS232_Arr->buffer, Length_MB * 2 + 7); + + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +/***************************************************************/ +/***************************************************************/ +/* Отправка запроса данных по протоколу ModBus - команда 5 + Чтение Ячеек данных Analog Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend5(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start) +{ + // КонтрольнаЯ сумма + unsigned int crc; + unsigned int byte_number; + unsigned int bit_number; + byte_number = adr_start / 16; + bit_number = adr_start % 16; + + + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_5; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + if ((p_discrete_data_out[byte_number].all >> bit_number) & 1) { + rs_arr->buffer[4] = 0xFF; + rs_arr->buffer[5] = 0; + } else { + rs_arr->buffer[4] = 0; + rs_arr->buffer[5] = 0; + } + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, 6); + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + RS_Send(rs_arr, rs_arr->buffer, 10); + + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + + RS_Len[CMD_RS232_MODBUS_5] = 8; + + adr_read_from_modbus3 = adr_start; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/****************************************************************/ +/****************************************************************/ +/* Ответ с данными по протоколу ModBus - команда 5 + Запись Ячееки данных Digital Output Holding Registers */ +/****************************************************************/ +/****************************************************************/ +void ModbusRTUreceiveAnswer5(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int Address_MB, Length_MB, i; + MODBUS_REG_STRUCT elementData; + + /* получили начальный адрес чтениЯ. */ + Address_MB = adr_read_from_modbus3; + + /* получили количество слов данных */ + Length_MB = RS232_Arr->RS_Header[2] >> 1; + + RS_SetControllerLeading(RS232_Arr, false); + RS_SetAdrAnswerController(RS232_Arr, 0); + + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +/***************************************************************/ +/***************************************************************/ +/* Отправка запроса данных по протоколу ModBus - команда 6 + запись Ячееки данных Analog Output Holding Registers */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend6(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start) +{ + // КонтрольнаЯ сумма + unsigned int crc; //, Address_MB, Length_MB, i, Data; + // int buf_out[200]; + // int buf_in[200]; + + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_6; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = HIBYTE(p_analog_data_out[adr_start].all); + rs_arr->buffer[5] = LOBYTE(p_analog_data_out[adr_start].all); + + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, 6); + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + + RS_Send(rs_arr, rs_arr->buffer, 10); +// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + + RS_Len[CMD_RS232_MODBUS_6] = 8; + + adr_read_from_modbus3 = adr_start; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/****************************************************************/ +/****************************************************************/ +/* Ответ с данными по протоколу ModBus - команда 6 + Чтение Ячеек данных Analog Output Holding Registers */ +/****************************************************************/ +/****************************************************************/ +void ModbusRTUreceiveAnswer6(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int Address_MB, Length_MB, i; + MODBUS_REG_STRUCT elementData; + + /* получили начальный адрес чтениЯ. */ + Address_MB = adr_read_from_modbus3; + + /* получили количество слов данных */ + Length_MB = RS232_Arr->RS_Header[2] >> 1; + + RS_SetControllerLeading(RS232_Arr, false); + RS_SetAdrAnswerController(RS232_Arr, 0); + + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +/***************************************************************/ +/***************************************************************/ +/* Отправка запроса данных по протоколу ModBus - команда 15 + Запись дискретных данных данных Discrete Output Coils */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend15(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_bits) +{ + // КонтрольнаЯ сумма + unsigned int crc; + unsigned int start_byte_number, end_byte_number, count_data_bytes; + unsigned int displacement_start, bits_in_last_byte, mask_start, mask_end; + unsigned int i = 0; + +// char byte_buffer[SIZE_MODBUS_TABLE_DISCRET * 2]; + + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_15; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = HIBYTE(count_bits); + rs_arr->buffer[5] = LOBYTE(count_bits); + + start_byte_number = adr_start / 8; + end_byte_number = (adr_start + (count_bits - 1)) / 8; + count_data_bytes = (count_bits % 8) == 0 ? count_bits / 8 + : count_bits / 8 + 1; + rs_arr->buffer[6] = count_data_bytes; + + displacement_start = adr_start % 8; + bits_in_last_byte = count_bits % 8; + if (bits_in_last_byte == 0) { bits_in_last_byte = 0xFF; } + + mask_start = 0; + for(i = 0; (i < (8 - displacement_start)) && (i < 8); i++) { + mask_start |= (1 << (7 - i)); + } + + mask_end = 0; + for(i = 0; (i < bits_in_last_byte) && (i < 8); i++) { + mask_end |= (1 << i); + } + + for (i = 0; i < count_data_bytes; i++) + { + if (i < count_data_bytes - 1) { + rs_arr->buffer[7 + i] = 0; + if (((i + start_byte_number) & 1) == 0) + { + rs_arr->buffer[7 + i] |= + (p_discrete_data_out[(i + start_byte_number) / 2].all >> displacement_start) & 0xFF; + } + if (((i + start_byte_number) & 1) == 1) + { + rs_arr->buffer[7 + i] |= + (((p_discrete_data_out[(i + start_byte_number) / 2].all >> 8) & mask_start) >> displacement_start); + rs_arr->buffer[7 + i] |= + (((p_discrete_data_out[(i + start_byte_number) / 2 + 1].all) & ~mask_start) << (8 - displacement_start)); + } + } else { + rs_arr->buffer[7 + i] = 0; + if (((i + start_byte_number) & 1) == 0) + { + rs_arr->buffer[7 + i] |= + ((p_discrete_data_out[(i + start_byte_number) / 2].all) >> displacement_start) & mask_end; + } + if (((i + start_byte_number) & 1) == 1) + { + rs_arr->buffer[7 + i] |= + (((p_discrete_data_out[(i + start_byte_number) / 2].all >> 8) & mask_start) >> displacement_start); + rs_arr->buffer[7 + i] |= + (((p_discrete_data_out[(i + start_byte_number) / 2 + 1].all) & ~mask_start) << (8 - displacement_start)) & mask_end; + } + } + } + + crc = 0xffff; + crc = GetCRC16_IBM(crc, rs_arr->buffer, count_data_bytes + 7); + rs_arr->buffer[count_data_bytes + 7] = LOBYTE(crc); + rs_arr->buffer[count_data_bytes + 8] = HIBYTE(crc); + + rs_arr->buffer[count_data_bytes + 9] = 0; + rs_arr->buffer[count_data_bytes + 10] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + +// RS_Send(rs_arr, rs_arr->buffer, (count_data_bytes + 10 + 2)); + RS_Send(rs_arr, rs_arr->buffer, (count_data_bytes + 10)); +// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + /* ждем ответа */ + if (adr_contr > 0 && adr_contr < 0xff) + { + RS_Len[CMD_RS232_MODBUS_15] = 8; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } + + return; +} + +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/* Ответ на передачу данных по протоколу ModBus - команда 15 + Запись дискретных данных Discrete Output Coils */ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceiveAnswer15(RS_DATA_STRUCT *RS232_Arr) +{ + RS_SetAdrAnswerController(RS232_Arr, 0); + RS_SetControllerLeading(RS232_Arr, false); + +} + +/***************************************************************/ +/***************************************************************/ +/* Получение данных от мастера по протоколу ModBus - команда 15 + Запись дискретных данных данных Discrete Output Coils */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceive15(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, register_address, array_address, length, byte_count, quantity; + unsigned int d_word, mask_start, mask_end; + unsigned int i1, i2, i; + unsigned int word_number, displacement_start, displacement_end; + + /* получили начальный адрес чтениy. */ + register_address = RS232_Arr->RS_Header[3] | (RS232_Arr->RS_Header[2] << 8); + array_address = register_address / 16; + /* получили quantity. */ + quantity = RS232_Arr->RS_Header[5] | ( RS232_Arr->RS_Header[4] << 8); + + /* получили количество байт данных */ + byte_count = RS232_Arr->RS_Header[6]; + + length = (byte_count & 0x1) ? (byte_count >> 1) + 1 : (byte_count >> 1); + + word_number = register_address / 16; + displacement_end = register_address % 16; + displacement_start = 16 - displacement_end; + mask_start = 0; + for(i = 0; (i < displacement_end) && (i < 15); i++) { + mask_start |= (1 << i); + } + mask_end = 0; + for(i = 0; (i < displacement_start) && (i < 15); i++) { + mask_end |= (1 << (15 - i)); + } + for (i = 0; i < length; i++) + { +// if (register_address >= ADR_MODBUS_TABLE && Address_MB < 0xe00) + if (register_address < 0xe00) + { + d_word = (RS232_Arr->buffer[7 + i * 2] << 8) | RS232_Arr->RS_Header[7 + i * 2 + 1]; + p_discrete_data_out[array_address + i].all &= mask_start; + p_discrete_data_out[array_address + i].all |= (d_word >> displacement_start) | mask_start; + if(i < length - 1) { + p_discrete_data_out[array_address + i].all &= mask_end; + p_discrete_data_out[array_address + i].all |= (d_word << displacement_end) | mask_end; + } + } + } + + ///////////////////////////////////////////////// + // Отсылка + // Посчитали контрольную сумму перед самой посылкой + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_15; + RS232_Arr->buffer[2] = HIBYTE(register_address); + RS232_Arr->buffer[3] = LOBYTE(register_address); + RS232_Arr->buffer[4] = HIBYTE(quantity); + RS232_Arr->buffer[5] = LOBYTE(quantity); + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, 6); + + RS232_Arr->buffer[6] = LOBYTE(crc); + RS232_Arr->buffer[7] = HIBYTE(crc); + + RS232_Arr->buffer[8] = 0; + RS232_Arr->buffer[9] = 0; +// RS232_Arr->RS_DataWillSend = 1; + RS_Send(RS232_Arr, RS232_Arr->buffer, 10); + + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// + +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/* Передача данных по протоколу ModBus - команда 16 + Передача данных */ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUsend16(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start, unsigned int count_word) +{ + + // КонтрольнаЯ сумма + unsigned int crc, Address_MB, i; //, Length_MB; //, Bytecnt_MB, Data1,Data2; + // int Data, digital, ust_I, ust_Time; + + //Length_MB = count_word; + Address_MB = adr_start; + // Отсылка + // Посчитали контрольную сумму перед самой посылкой + + rs_arr->buffer[0] = adr_contr; + rs_arr->buffer[1] = CMD_RS232_MODBUS_16; + + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + + rs_arr->buffer[4] = HIBYTE(count_word); + rs_arr->buffer[5] = LOBYTE(count_word); + + rs_arr->buffer[6] = LOBYTE(count_word * 2); + + for (i = 0; i < count_word; i++) + { +// rs_arr->buffer[7 + i * 2] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.HB; +// rs_arr->buffer[7 + i * 2 + 1] = p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.LB; + rs_arr->buffer[7 + i * 2] = p_analog_data_out[Address_MB + i].byte.HB; + rs_arr->buffer[7 + i * 2 + 1] = p_analog_data_out[Address_MB + i].byte.LB; + } + + crc = 0xffff; + // crc = get_crc_ccitt(crc, rs_arr->buffer, Length_MB*2+7); + crc = GetCRC16_IBM(crc, rs_arr->buffer, (unsigned long)(count_word * 2 + 7)); + + rs_arr->buffer[count_word * 2 + 7] = LOBYTE(crc); + rs_arr->buffer[count_word * 2 + 8] = HIBYTE(crc); + + rs_arr->buffer[count_word * 2 + 9] = 0; + rs_arr->buffer[count_word * 2 + 10] = 0; + + rs_arr->RS_DataWillSend = 1; + rs_arr->RS_DataWillSend2 = 1; + + RS_Send(rs_arr, rs_arr->buffer, (count_word * 2 + 10)); +// control_station.flag_waiting_answer[CONTROL_STATION_INGETEAM_PULT_RS485] = 1; + + // ждем ответа + if (adr_contr > 0 && adr_contr < 0xff) + { + //rs_arr->RS_Length = -1; + RS_Len[CMD_RS232_MODBUS_16] = 8; + RS_SetControllerLeading(rs_arr, true); + RS_SetAdrAnswerController(rs_arr, adr_contr); + } +} + +/***************************************************************/ +/***************************************************************/ +/* Получение данных от мастера по протоколу ModBus - команда 16 + Передача данных */ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceive16(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, Address_MB, Length_MB, Bytecnt_MB, i /*, Data1,Data2,Quantity*/; + int /*Data,*/ i1, i2; + + /* получили начальный адрес чтениy. */ + Address_MB = RS232_Arr->RS_Header[3] | (RS232_Arr->RS_Header[2] << 8); + + /* получили quantity. */ + //Quantity = RS232_Arr->RS_Header[5] | ( RS232_Arr->RS_Header[4] << 8); + + /* получили количество байт данных */ + // Length_MB = (RS232_Arr->RS_Header[4] << 8 ) | RS232_Arr->RS_Header[5]; + + Bytecnt_MB = RS232_Arr->RS_Header[6]; + + Length_MB = Bytecnt_MB >> 1; + + for (i = 0; i < Length_MB; i++) + { + if (Address_MB >= ADR_MODBUS_TABLE && Address_MB < 0xe00) + { +// p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.HB = RS232_Arr->buffer[3 + i * 2]; +// p_analog_data_out[Address_MB - ADR_MODBUS_TABLE + i].byte.LB = RS232_Arr->buffer[3 + i * 2 + 1]; + p_analog_data_out[Address_MB + i].byte.HB = RS232_Arr->buffer[3 + i * 2]; + p_analog_data_out[Address_MB + i].byte.LB = RS232_Arr->buffer[3 + i * 2 + 1]; + } + + if (Address_MB >= 0xe00 && Address_MB < 0xf00) + { + options_controller[Address_MB - 0xe00 + i].byte.HB = RS232_Arr->RS_Header[7 + i * 2]; + options_controller[Address_MB - 0xe00 + i].byte.LB = RS232_Arr->RS_Header[7 + i * 2 + 1]; + } + } + + if (Address_MB >= 0xe00 && Address_MB < 0xf00) + { + i1 = options_controller[0].all; + i2 = options_controller[1].all; + store_data_flash(options_controller, sizeof(options_controller)); + SetCntrlAddr(i1, i2); /* Установка адреса контроллера */ + } + + ///////////////////////////////////////////////// + // Отсылка + // Посчитали контрольную сумму перед самой посылкой + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_16; + RS232_Arr->buffer[2] = HIBYTE(Address_MB); + RS232_Arr->buffer[3] = LOBYTE(Address_MB); + RS232_Arr->buffer[4] = 0; + RS232_Arr->buffer[5] = 2; + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, 6); + + RS232_Arr->buffer[6] = LOBYTE(crc); + RS232_Arr->buffer[7] = HIBYTE(crc); + + RS232_Arr->buffer[8] = 0; + RS232_Arr->buffer[9] = 0; +// RS232_Arr->RS_DataWillSend = 1; + RS_Send(RS232_Arr, RS232_Arr->buffer, 10); + + return; +} + +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/* Ответ на передачу данных по протоколу ModBus - команда 16 + Передача данных */ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +void ModbusRTUreceiveAnswer16(RS_DATA_STRUCT *RS232_Arr) +{ + // КонтрольнаЯ сумма + unsigned int Address_MB; //, crc, Length_MB, Bytecnt_MB/*, i, Data1,Data2*/; + //int Data, digital, ust_I, ust_Time; + + /* получили начальный адрес чтениЯ. */ +// Address_MB = RS232_Arr->RS_Header[3] | ( RS232_Arr->RS_Header[2] << 8); +// if (Address_MB == ADRES_LOG_REGISTERS) { +// } + err_send_log_16 = 0; + + /* получили количество слов данных */ + //Length_MB = (RS232_Arr->RS_Header[4] << 8 ) | RS232_Arr->RS_Header[5]; + + //Bytecnt_MB = RS232_Arr->RS_Header[6]; + + RS_SetAdrAnswerController(RS232_Arr, 0); + RS_SetControllerLeading(RS232_Arr, false); + + err_modbus16 = 0; + return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Inu/Src2/N12_Libs/alarm_log_can.c b/Inu/Src2/N12_Libs/alarm_log_can.c new file mode 100644 index 0000000..551b992 --- /dev/null +++ b/Inu/Src2/N12_Libs/alarm_log_can.c @@ -0,0 +1,543 @@ +/* + * oscil_can.c + * + * Created on: 24 мая 2020 г. + * Author: yura + */ + +#include "alarm_log_can.h" + +#include "CAN_Setup.h" +#include "global_time.h" +#include "CRC_Functions.h" + + +#pragma DATA_SECTION(alarm_log_can, ".slow_vars") +ALARM_LOG_CAN alarm_log_can = ALARM_LOG_CAN_CAN_DEFAULTS; + + + +//int oscil_buffer[OSCIL_CAN_NUMBER_CHANNEL][OSCIL_CAN_NUMBER_POINTS]; + + + +void alarm_log_clear_buffer(ALARM_LOG_CAN_handle al) +{ + unsigned int i,k; +/* + for (i=0;ioscil_buffer[i][k] = 0; + + for (i=0;itemp_oscil_buffer[i][k] = 0; + + + oc->current_position = 0; + // oc->enable_rewrite = 1; +*/ +} + +int compress_size = 0; +void alarm_log_compress_temp_buffer(ALARM_LOG_CAN_handle al) +{ + + +// compress_size = fastlz_compress_level(1, al->start_adr_real_logs, 100, al->start_adr_temp); +// compress_size = lzf_compress(al->start_adr_real_logs, 2000, al->start_adr_temp, 2000); + + +} + + +void alarm_log_copy_temp_buffer(ALARM_LOG_CAN_handle al) +{ + unsigned int i,k; + unsigned long clog, temp_length;//real_length + int *adr_finish_temp, *adr_current; + + +// real_length = al->real_points * al->oscills; + // real_adr = al->start_adr_real_logs; + + temp_length = al->temp_points * al->oscills; // сколько данных надо выерезать из лога + al->temp_log_ready = 0; + + + if (al->current_adr_real_log == al->start_adr_real_logs) // мы в начале, логов нету? + return; + + adr_current = al->current_adr_real_log; // выставили конец лога + adr_finish_temp = al->start_adr_temp + temp_length; // тут конец лога temp + // теперь начиная с конца adr_finish скопируем в temp_log + // с учетом того что мы копируем из циклического буфера в обычный, нужна развертка данных + for (clog=0; clog= al->start_adr_real_logs) ) + { + *adr_finish_temp = *adr_current; // скопирлвали данные + // едем назад + adr_current--; + } + else + *adr_finish_temp = 0; // а нету данных! + + // едем назад + adr_finish_temp--; + + // закольцевались? + if (adr_current < al->start_adr_real_logs) + { + if (al->finish_adr_real_log) // лог прокручивался? + adr_current = al->finish_adr_real_log; // перешли в конец. + else + adr_current = al->start_adr_real_logs - 1; + } + } + + al->temp_log_ready = 1; + +/* + for (i=0;ioscil_buffer[i][k] = 0; + + for (i=0;itemp_oscil_buffer[i][k] = 0; + + + oc->current_position = 0; + // oc->enable_rewrite = 1; +*/ + +} + + + +//#define CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCKS 3330L// 9999L + +void alarm_log_send_buffer(ALARM_LOG_CAN_handle al) +{ + static unsigned int old_time = 0; + // static int prev_send_to_can = 0; + static unsigned long old_t = 0; + unsigned int i; + int real_mbox; + static int flag_send_buf = 0; + static unsigned long quant_local = 0; + static unsigned long addr_to = 0; + static int *start_adr; + static unsigned int k = 0; + + +// if (flag_send_buf) +// { +// +// +// +// return; +// } + + + if (al->global_enable==0) + return; + + real_mbox = get_real_out_mbox(ALARM_LOG_TYPE_BOX, ALARM_LOG_NUMBER_BOX_IN_CAN); + + if (al->stage==1) + { + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + (unsigned long)(0xfffc*3L), + &(al->cmd_fffc[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + (unsigned long)(0xfffd*3L), + &(al->cmd_fffd[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + (unsigned long)(0xfffe*3L), + &(al->cmd_fffe[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + al->stage = 2; + + quant_local = ((unsigned long)al->oscills * (unsigned long)al->temp_points); + al->progress_can = quant_local; + addr_to = 0; + start_adr = al->start_adr_temp; + + + } + + + return; + } + + + if (al->stage==2) + { + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF) && (get_new_cycle_fifo_load_level()<=2) ) + { +// if ((unsigned long)quant_local>(unsigned long)CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCKS) +// { +// k++; +// } + + al->progress_can = quant_local; + if ((unsigned long)quant_local > al->can_max_size_one_block) + { + + al->crc16 = GetCRC16_IBM( al->crc16, (unsigned int *)start_adr, al->can_max_size_one_block); + + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + addr_to, + start_adr, al->can_max_size_one_block , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + start_adr += al->can_max_size_one_block; + quant_local -= al->can_max_size_one_block; + addr_to += al->can_max_size_one_block; + + } + else + { + al->crc16 = GetCRC16_IBM_v2( al->crc16, (unsigned int *)start_adr, ((unsigned long)quant_local) ); + + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + addr_to, + start_adr, ((unsigned long)quant_local) , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + al->stage = 3; + quant_local = 0; + } + + } + + + return; + } + + + if (al->stage==3) + { + al->cmd_ffff[1] = al->crc16; // CRC16 + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF)) + { + al->progress_can = 0; + + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + (unsigned long)(0xffff*3L), + &(al->cmd_ffff[0]), 3 , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + al->stage = 100; + k--; + } + + + return; + } + + + if (al->stage==4) + { + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF)) + { + CAN_cycle_send( + ALARM_LOG_TYPE_BOX, + ALARM_LOG_NUMBER_BOX_IN_CAN, + (unsigned long)(0xfffc*3L), + &(al->cmd_fffc[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + al->stage = 100; + k--; + } + + + return; + } + + + if (al->stage==100) + { + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + // prev_send_to_can = 1; + al->stage = 0; + al->timer_send = (global_time.miliseconds - old_t); + } + + return; + } + +// была команда на отправку посылки и она еще не ушла, тогда сбрасываем счетчик времени паузы между посылками, +// т.е. OSCIL_TIME_WAIT между концом отправки посылки и новой посылки. + +// if (prev_send_to_can && CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF)==0) +// { +// old_time = (unsigned int)global_time.miliseconds; +// return; +// } +////// +// if (prev_send_to_can) +// { +// +// } +////// +// prev_send_to_can = 0; + + + if ((al->prev_status_alarm != al->status_alarm) && al->status_alarm) + { + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + + al->prepare_data_can(al); + + if (al->copy2temp) + { + al->copy_temp_buffer(al); +// alarm_log_compress_temp_buffer(al); + if (al->temp_log_ready == 1) + { + old_t = global_time.miliseconds; + al->stage = 1; + } + else + { + old_t = global_time.miliseconds; + al->stage = 4; // передаем пустое сообщение - это ошибка, данных нет! + + } + + } + else + { + old_t = global_time.miliseconds; + al->stage = 4; // передаем пустое сообщение - это ошибка, данных нет! + + } + + +// flag_send_buf = 1; + + +// CAN_cycle_send( +// ALARM_LOG_TYPE_BOX, +// ALARM_LOG_NUMBER_BOX_IN_CAN, +// 0xfffc, +// &(al->cmd_fffc[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); +// +// CAN_cycle_send( +// ALARM_LOG_TYPE_BOX, +// ALARM_LOG_NUMBER_BOX_IN_CAN, +// 0xfffd, +// &(al->cmd_fffd[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); +// +// CAN_cycle_send( +// ALARM_LOG_TYPE_BOX, +// ALARM_LOG_NUMBER_BOX_IN_CAN, +// 0xfffe, +// &(al->cmd_fffe[0]), 3, CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); +// al->stage = 1; +// +// CAN_cycle_send( +// ALARM_LOG_TYPE_BOX, +// ALARM_LOG_NUMBER_BOX_IN_CAN, +// 0, +// al->start_adr, ((unsigned long)al->oscills * (unsigned long)al->points) , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); +// al->stage = 2; +// +// CAN_cycle_send( +// ALARM_LOG_TYPE_BOX, +// ALARM_LOG_NUMBER_BOX_IN_CAN, +// 0xffff, +// &(al->cmd_ffff[0]), 3 , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); +// al->stage = 0; +// +// +// prev_send_to_can = 1; + + } + } + al->prev_status_alarm = al->status_alarm; + + + +/* + + oc->global_enable = TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x1; + oc->send_after_cmd = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x2) >> 1; + oc->cmd_send = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x4) >> 2; + oc->stop_update_on_error = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x8) >> 3; + oc->stop_update_on_stop_pwm = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x10) >> 4; + + TerminalUnites[oc->number_can_box_terminal_oscil][0] &= ~0x4; // clear cmd_send + + oc->number_ch = TerminalUnites[oc->number_can_box_terminal_oscil][1]; + oc->number_points = TerminalUnites[oc->number_can_box_terminal_oscil][2]; + oc->step = TerminalUnites[oc->number_can_box_terminal_oscil][3]; + + + if (oc->global_enable==0) + return; + + real_mbox = get_real_out_mbox(TERMINAL_TYPE_BOX, oc->number_can_box_terminal_oscil); + + // была команда на отправку посылки и она еще не ушла, тогда србасываем счетчик времени паузы между посылками, + // т.е. OSCIL_TIME_WAIT между концом отправки посылки и новой посылки. + if (prev_send_to_can && CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF)==0) + { + old_time = (unsigned int)global_time.miliseconds; + return; + } + prev_send_to_can = 0; + + if (oc->send_after_cmd==0) + { + if (!detect_pause_milisec(OSCIL_TIME_WAIT,&old_time)) + return; + } + + + if ( (oc->send_after_cmd==0 || (oc->send_after_cmd==1 && oc->cmd_send==1 ) ) ) + { + + oc->cmd_send = 0; // clear cmd + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + + // oc->enable_rewrite = 0; + + + old_t = oc->current_position;// +// old_t = global_time.microseconds; + + oc->prepare_data_can(oc); + +// oc->timer_send = (global_time.microseconds - old_t); + oc->timer_send = (oc->current_position - old_t); + + flag_send_buf = 1; + + CAN_cycle_send( + TERMINAL_TYPE_BOX, + oc->number_can_box_terminal_oscil, + 0, + &(oc->temp_oscil_buffer[0][0]), (oc->number_ch * oc->number_points) , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + prev_send_to_can = 1; + // while (CAN_cycle_free(real_mbox)==0); + +// oc->timer_send = (global_time.microseconds - old_t)/100; + + + oc->enable_rewrite = 1; + + +// if (cur_position_buf_modbus16_can >= SIZE_MODBUS_TABLE) +// { +// cur_position_buf_modbus16_can = 0; +//// modbus_table_can_out[ADR_CAN_TEST_PLUS_ONE].all++; +// } +// +// if ((cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN) >= SIZE_MODBUS_TABLE) +// count_write_to_modbus_can = SIZE_MODBUS_TABLE - cur_position_buf_modbus16_can; +// else +// count_write_to_modbus_can = SIZE_BUF_WRITE_TO_MODBUS16_CAN; +// +// if (CAN_cycle_free(real_mbox)) +// { +// CAN_cycle_send( +// MPU_TYPE_BOX, +// edrk.flag_second_PCH, +// cur_position_buf_modbus16_can + 1, +// &modbus_table_can_out[cur_position_buf_modbus16_can].all, +// count_write_to_modbus_can, 0); +// +// cur_position_buf_modbus16_can = cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN; +// } +// +// + + + + + + } + } +*/ + +} + + + +#pragma CODE_SECTION(alarm_log_prepare_data_can,".fast_run"); +void alarm_log_prepare_data_can(ALARM_LOG_CAN_handle al) +{ + unsigned int old_position, t_position; + int i, k; +// unsigned int crc; + + al->crc16 = 0xffff; +// crc = GetCRC16_IBM( crc, (unsigned int *)al->start_adr_temp, al->temp_points*al->oscills); + +// al->crc16 = crc; + + al->cmd_fffc[0] = 0x1234; + al->cmd_fffc[1] = 0x5678; + al->cmd_fffc[2] = 0x9abc; + + al->cmd_fffd[0] = al->post_points; + al->cmd_fffd[1] = al->step; + al->cmd_fffd[2] = 0x7777; + + al->cmd_fffe[0] = al->start; // START + al->cmd_fffe[1] = al->oscills; + al->cmd_fffe[2] = al->temp_points; + + al->cmd_ffff[0] = al->stop; // STOP + al->cmd_ffff[1] = al->crc16; // CRC16 + al->cmd_ffff[2] = 0x3333; + + + + /* + old_position = oc->current_position; + + for (i=0;i=0;k--) + { + if (t_position==0) + { + t_position = (OSCIL_CAN_NUMBER_POINTS+OSCIL_CAN_NUMBER_POINTS_ADD)-1; + } + else + t_position = t_position - 1; + + oc->temp_oscil_buffer[i][k] = oc->oscil_buffer[i][t_position]; + + } + + } +*/ + + return; +} + diff --git a/Inu/Src2/N12_Libs/alarm_log_can.h b/Inu/Src2/N12_Libs/alarm_log_can.h new file mode 100644 index 0000000..59ff998 --- /dev/null +++ b/Inu/Src2/N12_Libs/alarm_log_can.h @@ -0,0 +1,135 @@ +/* + * oscil_can.h + * + * Created on: 24 мая 2020 г. + * Author: yura + */ + +#ifndef SRC_LIBS_NIO12_ALARM_LOG_CAN_H_ +#define SRC_LIBS_NIO12_ALARM_LOG_CAN_H_ + +#define CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCKS 195L //3330L // 9999L + + +#define ALARM_LOG_NUMBER_BOX_IN_CAN 0 + +#define ALARM_LOG_CODE_STATUS_LOG_STOP 1 // Лог остановлен +#define ALARM_LOG_CODE_STATUS_LOG_RUN 2 // Лог идет... +#define ALARM_LOG_CODE_STATUS_LOG_RUN_TO_STOP 3 // Лог идет, но идет дозапись, скоро остановится. + + +/* +#define OSCIL_CAN_NUMBER_CHANNEL 32 // максимальное возможное кол-во каналов для буфера +#define OSCIL_CAN_NUMBER_POINTS 500 // максимальное возможное кол-во точек для буфера (для одного канала) +#define OSCIL_TIME_WAIT 5000 // период посылки всего массива в CAN (млсек) +#define OSCIL_CAN_NUMBER_POINTS_ADD 100 // запас точек при выполнении функции копирования рабочего буфера во временный. oscil_buffer->temp_oscil_buffer + +#define OSCIL_CAN_NUMBER_POINTS_AFTER_STOP 100 // сколько точек записывать после остановки записи буфера по аварии или шиму +*/ + + +typedef struct { + unsigned int global_enable; // разрешение передачи логов + unsigned int copy2temp; // копировать логи в temp перед передачей + unsigned int stage; + + int cmd_fffc[3]; + int cmd_fffd[3]; + int cmd_fffe[3]; + int cmd_ffff[3]; + + unsigned int post_points; // кол-во точек после аварии + unsigned int step; // шаг одной точки, мксек + unsigned int start; // код команды START + unsigned int oscills; // кол-во каналов - колонок + + unsigned long real_points; // всего кол-во точек, полный размер данных получим = points*oscills + // нужный кусок для копии, данное количество скопируется из циклического буфера во временный лог. + + unsigned int stop; // код команды START + unsigned int crc16; // crc16 данных + + int *start_adr_real_logs; // начало массива данных, до копирования + // адрес начала реальных логов в циклическом буфере + + int *start_adr_temp; // начало массива данных, после копирования + // адрес для временного размещения копии лога, лог скопируется из циклического буфера в этот развернувшись. + + int *finish_adr_real_log; // окончание блока логов, до копирования + // конец логов в циклическом буфере + + int *current_adr_real_log; // указатель на адрес где остановилвсь запись логов в циклическом буфере + + // int *finish_adr_temp; // конец лога в temp буфере + unsigned long temp_points; // всего кол-во точек, полный размер данных получим = temp_points*oscills + // реальный размер циклическго буфера в точках. + + unsigned long progress_can; // обратный счетчик, сколько осталось передать + unsigned int prev_status_alarm; // пред. состояние status_alarm + unsigned int status_alarm; // код аварии, лог автоматически передается при изменении этого статуса из 0->1 + + unsigned int timer_send; // время передачи всего блока + + unsigned int temp_log_ready; // готовность данных temp для считывания по CAN + + unsigned long can_max_size_one_block; // размер одного блока передаваемого за раз, надо кратное 3. + + void (*clear)(); // Clear buffers + void (*send)(); // Send buffers + void (*copy_temp_buffer)(); // Copy work buffers to temp buffers + void (*prepare_data_can)(); // Предварительная подготовка перед передачей + +} ALARM_LOG_CAN; + +typedef ALARM_LOG_CAN *ALARM_LOG_CAN_handle; + + + +#define ALARM_LOG_CAN_CAN_DEFAULTS { \ + 0, \ + 0, \ + 0, \ + {0,0,0}, \ + {0,0,0}, \ + {0,0,0}, \ + {0,0,0}, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + CAN_BOX_PRIORITY_LOW_MAX_SIZE_BLOCKS, \ + alarm_log_clear_buffer, \ + alarm_log_send_buffer, \ + alarm_log_copy_temp_buffer, \ + alarm_log_prepare_data_can \ +} + + + + +void alarm_log_clear_buffer(ALARM_LOG_CAN_handle); +void alarm_log_send_buffer(ALARM_LOG_CAN_handle); +//void alarm_log_next_position(ALARM_LOG_CAN_handle); +void alarm_log_prepare_data_can(ALARM_LOG_CAN_handle); +void alarm_log_copy_temp_buffer(ALARM_LOG_CAN_handle); + + + +extern ALARM_LOG_CAN alarm_log_can; + +#endif /* SRC_LIBS_NIO12_ALARM_LOG_CAN_H_ */ + + diff --git a/Inu/Src2/N12_Libs/big_dsp_module.c b/Inu/Src2/N12_Libs/big_dsp_module.c new file mode 100644 index 0000000..8688f17 --- /dev/null +++ b/Inu/Src2/N12_Libs/big_dsp_module.c @@ -0,0 +1,26 @@ +//#define XLOW_FREQUENCY_MODE + + +#include "big_dsp_module.h" + +#include "DSP281x_Device.h" // DSP281x Headerfile Include File +#include "DSP281x_Examples.h" // DSP281x Examples Include File + + + +void setup_adr_pcb_controller() + +{ + EALLOW; + GpioMuxRegs.GPBMUX.bit.TDIRB_GPIOB11=0; + GpioMuxRegs.GPBDIR.bit.GPIOB11=0; + EDIS; +} + + +int get_adr_pcb_controller() +{ + return !GpioDataRegs.GPBDAT.bit.GPIOB11; +} + + diff --git a/Inu/Src2/N12_Libs/big_dsp_module.h b/Inu/Src2/N12_Libs/big_dsp_module.h new file mode 100644 index 0000000..f7d068f --- /dev/null +++ b/Inu/Src2/N12_Libs/big_dsp_module.h @@ -0,0 +1,19 @@ +#ifndef _BIGDSPMODULE +#define _BIGDSPMODULE + + + +#ifdef __cplusplus + extern "C" { +#endif + + +void setup_adr_pcb_controller(); +int get_adr_pcb_controller(); + + +#ifdef __cplusplus + } +#endif + +#endif /* _BIGDSPMODULE */ diff --git a/Inu/Src2/N12_Libs/build_version.c b/Inu/Src2/N12_Libs/build_version.c new file mode 100644 index 0000000..147f0c1 --- /dev/null +++ b/Inu/Src2/N12_Libs/build_version.c @@ -0,0 +1,24 @@ +/* + * build_version.c + * + * Created on: 17 янв. 2022 г. + * Author: yura + */ + + +#include "build_version.h" + + + +float build_data_f = BUILD_DATA; +float build_time_f = BUILD_TIME; + +int build_data_i = (BUILD_DATA*1000); +int build_time_i = (BUILD_TIME*1000); + +int build_year = BUILD_YEAR; +int build_month = BUILD_MONTH; +int build_day = BUILD_DAY; + + + diff --git a/Inu/Src2/N12_Libs/build_version.h b/Inu/Src2/N12_Libs/build_version.h new file mode 100644 index 0000000..1100fb0 --- /dev/null +++ b/Inu/Src2/N12_Libs/build_version.h @@ -0,0 +1,30 @@ +/* + * build_version.h + * + * Created on: 17 янв. 2022 г. + * Author: yura + */ + +#ifndef SRC_N12_LIBS_BUILD_VERSION_H_ +#define SRC_N12_LIBS_BUILD_VERSION_H_ + + +#ifndef BUILD_DATA +#define BUILD_DATA 22.00 +#endif + +#ifndef BUILD_TIME +#define BUILD_TIME 00.01 +#endif + +extern float build_data_f; +extern float build_time_f; +extern int build_data_i; +extern int build_time_i; + + +extern int build_year, build_month, build_day; + + + +#endif /* SRC_N12_LIBS_BUILD_VERSION_H_ */ diff --git a/Inu/Src2/N12_Libs/control_station.c b/Inu/Src2/N12_Libs/control_station.c new file mode 100644 index 0000000..58b9cf8 --- /dev/null +++ b/Inu/Src2/N12_Libs/control_station.c @@ -0,0 +1,194 @@ +/* + * control_station.c + * + * Created on: 1 июн. 2020 г. + * Author: Yura + */ + + +#include "control_station.h" + +#include "global_time.h" + + +#pragma DATA_SECTION(control_station, ".slow_vars") +CONTROL_STATION control_station = CONTROL_STATION_DEFAULTS; +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + +void control_station_clear(CONTROL_STATION_handle cs) +{ + int i,k,j; + + for (i=0;icount_error_modbus[i] = 0; + cs->count_ok_modbus[i] = 0; + + + + cs->flag_waiting_answer[i] = 0; + cs->flag_message_sent[i] = 0; + cs->active_control_station[i] = 0; + cs->alive_control_station[i] = 0; + + for (k=0;karray_cmd[i][k] = 0; + + cs->detect_get_data_control_station[i] = 0; + cs->period_detect_active[i] = 0; + + cs->setup_time_detect_active[i] = CONTROL_STATION_SETUP_TIME_DETECT_ACTIVE; + cs->setup_time_detect_active_resend_485[i] = CONTROL_STATION_SETUP_TIME_DETECT_ACTIVE_RESEND_485; + cs->setup_time_send_cmd_after_off[i] = CONTROL_STATION_SETUP_TIME_SEND_CMD_AFTER_OFF; + + cs->time_detect_active[i] = 0; + cs->time_detect_answer_485[i] = 0; + + for (k=0;kraw_array_data[i][k].all = 0; + for (j=0;jraw_array_data_temp[i][k][j].all = 0; + } + + cs->flag_refresh_array[i] = 0; + + cs->prev_CAN_count_cycle_input_units[i] = 0; + cs->count_raw_array_data_temp[i] = 0; + + } + + for (k=0;kactive_array_cmd[k] = 0; +} + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + +void control_station_update_timers(CONTROL_STATION_handle cs) +{ + static unsigned int old_time = 0; + volatile int i; + + + if (!detect_pause_milisec(CONTROL_STATION_TIME_WAIT,&old_time)) + return; + + + for (i=0;iflag_message_sent[i] == 1) + (cs->time_detect_answer_485[i])++; + +// cs->time_detect_answer_485[i] = 0; + + + + + if (cs->detect_get_data_control_station[i]) + { + cs->period_detect_active[i] = cs->time_detect_active[i]; + cs->time_detect_active[i] = 0; + cs->detect_get_data_control_station[i] = 0; + cs->alive_control_station[i] = 1; + } + else + { + + if (cs->time_detect_active[i]>=cs->setup_time_detect_active[i]) + { + cs->alive_control_station[i] = 0; // тут сдох + cs->period_detect_active[i] = 0; +// cs->flag_message_sent[i] = 0; + cs->time_detect_active[i] = cs->setup_time_detect_active[i]+1; + } + else + { + cs->time_detect_active[i]++; + +// if (cs->flag_message_sent[i]) +// { +// if (cs->flag_waiting_answer[i]) +// cs->time_detect_active[i]++; +// else +// { +// cs->time_detect_active[i] = 0; +// } +// } +// else +// cs->time_detect_active[i]++; + } + + } + + + } + + + +} + + + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + +void control_station_detect_active_station(CONTROL_STATION_handle cs) +{ + + + + + + +} + + + + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + + + + + + + + diff --git a/Inu/Src2/N12_Libs/control_station.h b/Inu/Src2/N12_Libs/control_station.h new file mode 100644 index 0000000..a40ee94 --- /dev/null +++ b/Inu/Src2/N12_Libs/control_station.h @@ -0,0 +1,134 @@ +/* + * control_station.h + * + * Created on: 1 июн. 2020 г. + * Author: Vladislav + */ + +#ifndef SRC_LIBS_NIO12_CONTROL_STATION_H_ +#define SRC_LIBS_NIO12_CONTROL_STATION_H_ + +#include // грузим внешние настройки проекта + +#include "word_structurs.h" + + +////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////// + + +#define COUNT_CONTROL_STATION CONTROL_STATION_LAST // кол-во постов управления +//#define COUNT_CMD_ARR_CONTROL_STATION CONTROL_STATION_LAST // кол-во постов управления + +////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////// + + +#define CONTROL_STATION_TIME_WAIT 250//500 // период опроса мсек + +#define CONTROL_STATION_SETUP_TIME_DETECT_ACTIVE 18//12//6 // в тиках от CONTROL_STATION_TIME_WAIT +#define CONTROL_STATION_SETUP_TIME_DETECT_ACTIVE_RESEND_485 2 // в тиках от CONTROL_STATION_TIME_WAIT +#define CONTROL_STATION_SETUP_TIME_SEND_CMD_AFTER_OFF 5 // в тиках от CONTROL_STATION_TIME_WAIT + +#define CONTROL_STATION_MAX_RAW_DATA 256 //128 // максимальное кол-во данных для сырых данных полученных от постов +#define CONTROL_STATION_MAX_RAW_DATA_TEMP 3 //128 // сколько данных храним для временного буфера + +////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////// + +typedef struct { + + unsigned int time_detect_active[COUNT_CONTROL_STATION]; // текущий таймер для пропадании связи, сбрасывается при наличии связи + unsigned int period_detect_active[COUNT_CONTROL_STATION]; // период обмена с постом + unsigned int time_detect_answer_485[COUNT_CONTROL_STATION]; // текущий таймер для ожидания ответа по Modbus + + unsigned int setup_time_detect_active[COUNT_CONTROL_STATION]; // время до сброса при пропадании связи + unsigned int setup_time_detect_active_resend_485[COUNT_CONTROL_STATION]; // время до сброса при пропадании связи, должен быть меньше setup_time_detect_active + unsigned int setup_time_send_cmd_after_off[COUNT_CONTROL_STATION]; // время задержки на переключение команд, например на Go. Чтоб не было дребезга на вкл/выкл. + + unsigned int active_control_station[COUNT_CONTROL_STATION]; // активный пост управления, возможно их может быть несколько одновременно? + + unsigned int detect_get_data_control_station[COUNT_CONTROL_STATION]; // если есть обмен с постом, то выставляем тут флаг, он сбросится при update_timers + + + unsigned int alive_control_station[COUNT_CONTROL_STATION]; // флаг о том что связь с постом есть + + + int array_cmd[COUNT_CONTROL_STATION][CONTROL_STATION_CMD_LAST]; // массив данных полученных от каждого из постов, данные после parse + int active_array_cmd[CONTROL_STATION_CMD_LAST]; // массив данных актуальных для автивного поста, данные после parse + + WORD_UINT2BITS_STRUCT raw_array_data[COUNT_CONTROL_STATION][CONTROL_STATION_MAX_RAW_DATA]; // сырой массив данных полученных от каждого из постов, без parse. + WORD_UINT2BITS_STRUCT raw_array_data_temp[COUNT_CONTROL_STATION][CONTROL_STATION_MAX_RAW_DATA][CONTROL_STATION_MAX_RAW_DATA_TEMP]; // временный сырой массив данных полученных от каждого из постов, без parse. + + unsigned int flag_message_sent[COUNT_CONTROL_STATION]; // флаг на ожидание ответа по системе запрос-ответ + unsigned int flag_waiting_answer[COUNT_CONTROL_STATION]; // ожидать ли ответ по системе запрос-ответ + + unsigned int count_ok_modbus[COUNT_CONTROL_STATION]; // счетчик ошибок по команде modbus 15 + unsigned int count_error_modbus[COUNT_CONTROL_STATION]; // счетчик ошибок по команде modbus 15 + + unsigned int flag_refresh_array[COUNT_CONTROL_STATION]; // флаг на ожидание обновления данных от modbus + +/* + unsigned int cmd_go_from_control_station[COUNT_CONTROL_STATION]; // cmd_go от поста пуск/стоп ШИМа + unsigned int set_izad_from_control_station[COUNT_CONTROL_STATION]; // ток от поста + unsigned int set_rotor_from_control_station[COUNT_CONTROL_STATION]; // обороты от поста + unsigned int cmd_charge_from_control_station[COUNT_CONTROL_STATION]; // сбор схемы от поста + unsigned int cmd_uncharge_from_control_station[COUNT_CONTROL_STATION]; // разбор схемы от поста + unsigned int cmd_checkback_from_control_station[COUNT_CONTROL_STATION]; // квитирование от поста + unsigned int cmd_test_leds_from_control_station[COUNT_CONTROL_STATION]; // тест ламп от поста +*/ + unsigned int prev_CAN_count_cycle_input_units[COUNT_CONTROL_STATION]; // пред кол-во обновлений из CAN + unsigned int count_raw_array_data_temp[COUNT_CONTROL_STATION]; // индекс перебора по CONTROL_STATION_MAX_RAW_DATA_TEMP + + void (*clear)(); // Clear buffers + void (*update_timers)(); // Обнуляем таймеры на постах с которыми есть обмен + void (*detect_active_station)(); // определяем какой пост активен + +} CONTROL_STATION; + +typedef CONTROL_STATION *CONTROL_STATION_handle; + + + +#define CONTROL_STATION_DEFAULTS { \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + {0}, \ + control_station_clear, \ + control_station_update_timers, \ + control_station_detect_active_station \ +} + + + + +void control_station_clear(CONTROL_STATION_handle); +void control_station_update_timers(CONTROL_STATION_handle); +void control_station_detect_active_station(CONTROL_STATION_handle); + + + + +extern CONTROL_STATION control_station; + + + +#endif /* SRC_LIBS_NIO12_CONTROL_STATION_H_ */ diff --git a/Inu/Src2/N12_Libs/filter_v1.c b/Inu/Src2/N12_Libs/filter_v1.c new file mode 100644 index 0000000..5a8d337 --- /dev/null +++ b/Inu/Src2/N12_Libs/filter_v1.c @@ -0,0 +1,367 @@ +#include "IQmathLib.h" +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File + + +#include "filter_v1.h" + + +//#include "filter.h" +//#include "myfir16.h" + + +/* +#define IIR16_COEFF {\ + -10304,25264,4493,8986,4493} + +#define IIR16_ISF 1298 +#define IIR16_NBIQ 1 +#define IIR16_QFMAT 14 + + + +#define FIR16_COEFF_50_75HZ {\ + 4927,-1568135,-2289592,-2814717,-2881240,-2030268,471,3407677,7601571,11730182,\ + 14023990,12910061,6880988,-4194369,-19136408,-34799420,-46792491,-49938254,-39649165,-12779469,\ + 30867456,88408033,153681876,218365909,273219549,309985256} + + + + +#define FIR16_COEFF_58 {\ + 1165,2622601,2884733,3409000,4129869,5178410,6489088,8127441,10093469,12387172,\ + 15008553,17957610,21168811,24707691,28443180,32375278,36438450,40567161,44761411,48890130,\ + 53018853,56885437,60620954,64028796,67108963,69861455,72155199,73924660,75300908,76087336,\ + } + + + + +#define FIR16_COEFF_WROTOR {\ + 316,1245500,1245499,1245499,1245498,1311034,1376569,1376568,1442103,1507637,\ + 1573172,1638706,1769776,1835310,1966380,2031914,2162984,2294053,2425123,2556192,\ + 2752797,2883866,3080471,3211539,3408144,3604749,3801353,3997957,4194562,4391166,\ + 4653306,4849910,5112050,5308653,5570793,5832933,6095072,6357212,6619351,6881491,\ + 7143630,7471306,7733445,7995584,8323260,8585399,8913074,9240749,9502889,9830564,\ + 10158239,10420379,10748054,11075729,11337869,11665544,11993219,12320895,12583034,12910710,\ + 13238386,13500525,13828201,14090341,14418017,14680157,15007833,15269973,15532113,15859790,\ + 16121930,16384071,16646211,16908352,17104957,17367098,17629239,17825844,18022449,18284591,\ + 18481196,18677802,18874407,19071013,19202083,19398689,19529759,19660830,19791900,19922971,\ + 20054041,20185112,20250647,20381718,20447253,20512789,20578324,20578323,20643859,20643859,\ + 20709395} + + +*/ + +/* Filter Symbolic Constants */ +//#define FIR_ORDER_58 58 + + + +//#define FIR_ORDER_50_75HZ 50 + + + +//#define FIR16_COEFF {\ +// 16519,532422588} + + +/* Filter Symbolic Constants */ +//#define FIR_ORDER 2 + + + + + +/* Create an Instance of FIRFILT_GEN module and place the object in "firfilt" section */ +//#pragma DATA_SECTION(fir, "firfilt"); +//FIR16 fir = FIR16_DEFAULTS; +//FIR16 fir_58 = FIR16_DEFAULTS; +//FIR16 fir_wrotor = FIR16_DEFAULTS; + +//FIR16 fir_50_75hz_0 = FIR16_DEFAULTS; +/* +FIR16 fir_50_75hz_1 = FIR16_DEFAULTS; +FIR16 fir_50_75hz_2 = FIR16_DEFAULTS; +FIR16 fir_50_75hz_3 = FIR16_DEFAULTS; +FIR16 fir_50_75hz_4 = FIR16_DEFAULTS; +FIR16 fir_50_75hz_5 = FIR16_DEFAULTS; +*/ + + + +/* Define the Delay buffer for the 50th order filterfilter and place it in "firldb" section */ +//#pragma DATA_SECTION(dbuffer_fir,"firldb"); +//long dbuffer_fir[(FIR_ORDER+2)/2]; + +//long dbuffer_fir_50_75hz_0[(FIR_ORDER_50_75HZ+2)/2]; +/*long dbuffer_fir_50_75hz_1[(FIR_ORDER_50_75HZ+2)/2]; +long dbuffer_fir_50_75hz_2[(FIR_ORDER_50_75HZ+2)/2]; +long dbuffer_fir_50_75hz_3[(FIR_ORDER_50_75HZ+2)/2]; +long dbuffer_fir_50_75hz_4[(FIR_ORDER_50_75HZ+2)/2]; +long dbuffer_fir_50_75hz_5[(FIR_ORDER_50_75HZ+2)/2]; + */ + + + + + + +//#pragma DATA_SECTION(dbuffer_fir_58,"firldb"); +//long dbuffer_fir_58[(FIR_ORDER_58+2)/2]; + +//#pragma DATA_SECTION(dbuffer_fir_wrotor,"firldb"); + + + +/* Define Constant Co-efficient Array and place the +.constant section in ROM memory */ + +//long const coeff_fir[(FIR_ORDER+2)/2]= FIR16_COEFF; +//long const coeff_fir_58[(FIR_ORDER_58+2)/2]= FIR16_COEFF_58; + + + + + +//long const coeff_fir_50_75hz_0[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +/*long const coeff_fir_50_75hz_1[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +long const coeff_fir_50_75hz_2[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +long const coeff_fir_50_75hz_3[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +long const coeff_fir_50_75hz_4[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +long const coeff_fir_50_75hz_5[(FIR_ORDER_50_75HZ+2)/2]= FIR16_COEFF_50_75HZ; +*/ + + +/* Finter Input and Output Variables */ + + + +/* Create an Instance of IIR5BIQD16 module and place the object in "iirfilt" section */ +//#pragma DATA_SECTION(iir, "iirfilt"); +//IIR5BIQ16 iir = IIR5BIQ16_DEFAULTS; + +/* ============================================================================= +Modify the delay buffer size to comensurate with the no of biquads in the filter +Size of the Delay buffer=2*nbiq +==============================================================================*/ +/* Define the Delay buffer for the cascaded 6 biquad IIR filter and place it in "iirfilt" section */ +//#pragma DATA_SECTION(dbuffer_iir,"iirfilt"); +//int dbuffer_iir[2*IIR16_NBIQ]; + + +/* ============================================================================= +Modify the array size and symbolic constant to suit your filter requiremnt. +Size of the coefficient array=5*nbiq +==============================================================================*/ +/* Define the Delay buffer for the cascaded 6 biquad IIR filter and place it in "iirfilt" section */ + +//const int coeff_iir[5*IIR16_NBIQ]=IIR16_COEFF; + + +/* +void init_my_filter_fir() +{ + +// FIR Generic Filter Initialisation + fir.order=FIR_ORDER; + fir.dbuffer_ptr=dbuffer_fir; + fir.coeff_ptr=(long *)coeff_fir; + fir.init(&fir); +} + + +void init_my_filter_fir_50_75hz() +{ + +// FIR Generic Filter Initialisation + fir_50_75hz_0.order=FIR_ORDER_50_75HZ; + fir_50_75hz_0.dbuffer_ptr=dbuffer_fir_50_75hz_0; + fir_50_75hz_0.coeff_ptr=(long *)coeff_fir_50_75hz_0; + fir_50_75hz_0.init(&fir_50_75hz_0); + +} + + + + +//#pragma CODE_SECTION(calc_my_filter_fir,".fast_run"); +int calc_my_filter_fir(int xn) +{ +int yn; + +// xn=sgen.out; + fir.input=xn; + fir.calc(&fir); + yn=fir.output; + return yn; +} + + + +void init_my_filter_fir_58() +{ + +// FIR Generic Filter Initialisation + fir_58.order=FIR_ORDER_58; + fir_58.dbuffer_ptr=dbuffer_fir_58; + fir_58.coeff_ptr=(long *)coeff_fir_58; + fir_58.init(&fir_58); +} + + + + +//#pragma CODE_SECTION(calc_my_filter_fir_58,".fast_run"); +int calc_my_filter_fir_58(int xn) +{ +int yn; + +// xn=sgen.out; + fir_58.input=xn; + fir_58.calc(&fir_58); + yn=fir_58.output; + return yn; +} + + + + + + + +void calc_my_filter_fir_50_75hz(_iq xn_0,_iq xn_1,_iq xn_2,_iq xn_3,_iq xn_4,_iq xn_5, + _iq *yn_0,_iq *yn_1,_iq *yn_2,_iq *yn_3,_iq *yn_4,_iq *yn_5) +{ + fir_50_75hz_0.input=_IQtoIQ15(xn_0); + fir_50_75hz_0.calc(&fir_50_75hz_0); + *yn_0=_IQ15toIQ(fir_50_75hz_0.output); +} + + + +void init_my_filter_iir() +{ + +// IIR Filter Initialisation + iir.dbuffer_ptr=dbuffer_iir; + iir.coeff_ptr=(int *)coeff_iir; + iir.qfmat=IIR16_QFMAT; + iir.nbiq=IIR16_NBIQ; + iir.isf=IIR16_ISF; + iir.init(&iir); +} + + +//#pragma CODE_SECTION(calc_my_filter_iir,".fast_run"); +int calc_my_filter_iir(int xn) +{ +int yn; + +// xn=sgen.out; + iir.input=xn; + iir.calc(&iir); + yn=iir.output; + return yn; +} + +*/ + +#pragma CODE_SECTION(exp_regul_iq19,".fast_run"); +_iq19 exp_regul_iq19(_iq19 k_exp_regul, _iq19 InpVarCurr, _iq19 InpVarInstant) +{ + _iq19 t1; + + t1 = (InpVarCurr + _IQ19mpy( (InpVarInstant-InpVarCurr), k_exp_regul)); + return t1; +} + + +#pragma CODE_SECTION(exp_regul_iq,".fast_run"); +// +// Tсек = Tпериод/k_exp_regul +// +_iq exp_regul_iq(_iq k_exp_regul, _iq InpVarFiltered, _iq InpVarInstant) +{ + _iq t1; + t1 = (InpVarFiltered + _IQmpy( (InpVarInstant-InpVarFiltered), k_exp_regul)); + return t1; +} + +#pragma CODE_SECTION(exp_regul_iq,".fast_run"); +void exp_regul_iq_fast(_iq k_exp_regul, _iq *InpVarCurr, _iq InpVarInstant) +{ + _iq t1; + volatile _iq t2,t3,t4; + + + t2 = (InpVarInstant- *InpVarCurr); + t3 = _IQmpy( t2, k_exp_regul); + t4 = *InpVarCurr + t3; + t1 = t4; + *InpVarCurr = t1; +// t1 = (InpVarCurr + _IQmpy( (InpVarInstant-InpVarCurr), k_exp_regul)); +// return t1; +} + + + + + +/* + +_iq18 filter_1p(_iq18 predx,_iq18 predy, _iq18 inpx) +{ + _iq18 t1; + + t1 = _IQ18mpy(k1_filter_1p_fast,(predx+inpx))+_IQ18mpy(k2_filter_1p_fast,predy); + return t1; +} + + +*/ + +/* + +void init_filter_batter2() +{ + u_filter_batter2[0]=0; + u_filter_batter2[1]=0; + u_filter_batter2[2]=0; + + i_filter_batter2[0]=0; + i_filter_batter2[1]=0; + i_filter_batter2[2]=0; + + k_filter_batter2[0]=_IQ(K1_FILTER_BATTER2_3HZ); + k_filter_batter2[1]=_IQ(K2_FILTER_BATTER2_3HZ); + k_filter_batter2[2]=_IQ(K3_FILTER_BATTER2_3HZ ); + +} + + + + +//#pragma CODE_SECTION(filter_batter2,".fast_run"); +_iq filter_batter2(_iq InpVarCurr) +{ +_iq y; + + y = _IQmpy(k_filter_batter2[0],( InpVarCurr + _IQmpyI32(i_filter_batter2[0],2) + i_filter_batter2[1] ) ) + + _IQmpy(k_filter_batter2[1], u_filter_batter2[0]) + _IQmpy(k_filter_batter2[2], u_filter_batter2[1]); + + u_filter_batter2[1]=u_filter_batter2[0]; + u_filter_batter2[0]=y; + + i_filter_batter2[1]=i_filter_batter2[0]; + i_filter_batter2[0]=InpVarCurr; + return y; + +} + + +*/ + + + + diff --git a/Inu/Src2/main/my_filter.h b/Inu/Src2/N12_Libs/filter_v1.h similarity index 89% rename from Inu/Src2/main/my_filter.h rename to Inu/Src2/N12_Libs/filter_v1.h index cb8b6d3..6ca43e9 100644 --- a/Inu/Src2/main/my_filter.h +++ b/Inu/Src2/N12_Libs/filter_v1.h @@ -54,7 +54,7 @@ int calc_my_filter_iir(int xn); _iq19 exp_regul_iq19(_iq19 k_exp_regul, _iq19 InpVarCurr, _iq19 InpVarInstant); -_iq exp_regul_iq(_iq k_exp_regul, _iq InpVarCurr, _iq InpVarInstant); +_iq exp_regul_iq(_iq k_exp_regul, _iq InpVarFiltered, _iq InpVarInstant); @@ -64,9 +64,6 @@ _iq18 filter_1p(_iq18 predx,_iq18 predy, _iq18 inpx); void exp_regul_iq_fast(_iq k_exp_regul, _iq *InpVarCurr, _iq InpVarInstant); -_iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant); - - #ifdef __cplusplus } diff --git a/Inu/Src2/N12_Libs/global_time.c b/Inu/Src2/N12_Libs/global_time.c new file mode 100644 index 0000000..a5db6ef --- /dev/null +++ b/Inu/Src2/N12_Libs/global_time.c @@ -0,0 +1,149 @@ +#include "global_time.h" + + +GLOBAL_TIME global_time = GLOBAL_TIME_DEFAULTS; + + +void init_global_time_struct(unsigned int freq_pwm) +{ + global_time.total_seconds = 0; + global_time.total_seconds10 = 0; + global_time.total_seconds10full = 0; + global_time.microseconds = 0; + global_time.microseconds_temp = 0; + global_time.pwm_tics = 0; + global_time.miliseconds = 0; + global_time.miliseconds_long = 0; + global_time.seconds = 0; + global_time.minuts = 0; + global_time.hours = 0; + global_time.freq_pwm_hz = freq_pwm; + global_time.microseconds_add = 1000000L / global_time.freq_pwm_hz; +} + +#pragma CODE_SECTION(global_time_calc,".fast_run2"); +void global_time_calc(GLOBAL_TIME_handle gt) +{ + unsigned int miliseconds_temp = 0; + static unsigned int miliseconds_temp10 = 0; + + gt->pwm_tics++; + gt->microseconds += gt->microseconds_add; + gt->microseconds_temp += gt->microseconds_add; + + if (gt->microseconds_temp>=1000) + { + if (gt->microseconds_temp>=2000) + { + miliseconds_temp = gt->microseconds_temp/1000; + gt->microseconds_temp -= miliseconds_temp*1000; + } + else + { + miliseconds_temp = 1; + gt->microseconds_temp -= 1000; + } + } + +// gt->miliseconds = gt->microseconds / 1000; + + gt->miliseconds += miliseconds_temp; + miliseconds_temp10 += miliseconds_temp; + + if(gt->pwm_tics == gt->freq_pwm_hz) + { + gt->total_seconds++; + gt->total_seconds10 += 10; + + gt->seconds++; + gt->pwm_tics = 0; + miliseconds_temp10 = 0; + + if(gt->seconds == 60) + { + gt->minuts++; + gt->seconds = 0; + + if(gt->minuts == 60) + { + gt->hours++; + gt->minuts = 0; + } + } + } + + //gt->total_seconds10 += 10; + gt->total_seconds10full = gt->total_seconds10 + miliseconds_temp10/100; +} + + +void init_timer_sec(unsigned int *start_time) +{ + *start_time = global_time.total_seconds; +} + +void init_timer_milisec(unsigned int *start_time) +{ + *start_time = global_time.miliseconds; +} + +int detect_pause_sec(unsigned int wait_pause, unsigned int *old_time) +{ + unsigned long delta; + + if(global_time.total_seconds >= *old_time) + { + delta = (unsigned int)((unsigned int)global_time.total_seconds - *old_time); + } + else + { + delta = (unsigned int)((unsigned int)global_time.total_seconds + (0xFFFFUL - *old_time)); + } + + if (delta>=wait_pause) + { + *old_time = (unsigned int)global_time.total_seconds; + return 1; + } + else + return 0; +} + +int detect_pause_milisec(unsigned int wait_pause, unsigned int *old_time) +{ + unsigned long delta; + if(global_time.miliseconds >= *old_time) + { + delta = (unsigned int)((unsigned int)global_time.miliseconds - *old_time); + } + else + { + delta = (unsigned int)((unsigned int)global_time.miliseconds + (0xFFFFUL - *old_time)); + } + + if (delta>=wait_pause) + { + *old_time = (unsigned int)global_time.miliseconds; + return 1; + } + else + return 0; +} + +unsigned int get_delta_milisec(unsigned int *old_time, unsigned int upd) +{ + unsigned long delta; + + if(global_time.miliseconds >= *old_time) + { + delta = (unsigned int)((unsigned int)global_time.miliseconds - *old_time); + } + else + { + delta = (unsigned int)((unsigned int)global_time.miliseconds + (0xFFFFUL - *old_time)); + } + if (upd) + *old_time = (unsigned int)global_time.miliseconds; + + return delta; +} diff --git a/Inu/Src2/N12_Libs/global_time.h b/Inu/Src2/N12_Libs/global_time.h new file mode 100644 index 0000000..f4f4e2c --- /dev/null +++ b/Inu/Src2/N12_Libs/global_time.h @@ -0,0 +1,58 @@ +#ifndef _GLOBAL_TIME +#define _GLOBAL_TIME + +typedef struct { + unsigned long total_seconds; //Всего секунд с момента включениЯ + unsigned long total_seconds10; //Всего секунд с момента включениЯ с десятыми + unsigned long total_seconds10full; //Всего секунд с момента включениЯ с десятыми + unsigned long microseconds; + unsigned int microseconds_temp; + + unsigned int miliseconds; //??? + unsigned long miliseconds_long; //??? + unsigned int pwm_tics; + unsigned int seconds; + unsigned int minuts; + unsigned int hours; + unsigned int freq_pwm_hz; + unsigned int microseconds_add; + void (*calc)(); //Считает в прерывании ШИМ'а +} GLOBAL_TIME; + +typedef GLOBAL_TIME *GLOBAL_TIME_handle; + +void global_time_calc(GLOBAL_TIME_handle); +void init_global_time_struct(unsigned int freq_pwm); + +/*----------------------------------------------------------------------------- +Default initalizer for the GLOBAL_TIME object. +-----------------------------------------------------------------------------*/ +#define GLOBAL_TIME_DEFAULTS { 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + global_time_calc \ +} +/*------------------------------------------------------------------------------ +Prototypes for the functions in global_time.c +------------------------------------------------------------------------------*/ + + +extern GLOBAL_TIME global_time; + +void init_timer_sec(unsigned int *start_time); //Инициализирует переменную, времЯ старта в секундах +void init_timer_milisec(unsigned int *start_time); //Инициализирует переменную, времЯ старта в милисекундах +int detect_pause_sec(unsigned int wait_pause, unsigned int *old_time); //пауза в секундах +int detect_pause_milisec(unsigned int wait_pause, unsigned int *old_time); //Пауза в милисекундах (не более 60000млсек) +unsigned int get_delta_milisec(unsigned int *old_time, unsigned int upd); // вернули сколько времени прошло от времени old_time ; upd=1 - обновить old_time - текущим + +#endif //_GLOBAL_TIME diff --git a/Inu/Src/N12_Libs/iq_values_norma_f.h b/Inu/Src2/N12_Libs/iq_values_norma_f.h similarity index 100% rename from Inu/Src/N12_Libs/iq_values_norma_f.h rename to Inu/Src2/N12_Libs/iq_values_norma_f.h diff --git a/Inu/Src/N12_Libs/iq_values_norma_iu.h b/Inu/Src2/N12_Libs/iq_values_norma_iu.h similarity index 100% rename from Inu/Src/N12_Libs/iq_values_norma_iu.h rename to Inu/Src2/N12_Libs/iq_values_norma_iu.h diff --git a/Inu/Src/N12_Libs/iq_values_norma_oborot.h b/Inu/Src2/N12_Libs/iq_values_norma_oborot.h similarity index 100% rename from Inu/Src/N12_Libs/iq_values_norma_oborot.h rename to Inu/Src2/N12_Libs/iq_values_norma_oborot.h diff --git a/Inu/Src/N12_Libs/log_params.c b/Inu/Src2/N12_Libs/log_params.c similarity index 100% rename from Inu/Src/N12_Libs/log_params.c rename to Inu/Src2/N12_Libs/log_params.c diff --git a/Inu/Src/N12_Libs/log_params.h b/Inu/Src2/N12_Libs/log_params.h similarity index 100% rename from Inu/Src/N12_Libs/log_params.h rename to Inu/Src2/N12_Libs/log_params.h diff --git a/Inu/Src/N12_Libs/log_to_memory.c b/Inu/Src2/N12_Libs/log_to_memory.c similarity index 100% rename from Inu/Src/N12_Libs/log_to_memory.c rename to Inu/Src2/N12_Libs/log_to_memory.c diff --git a/Inu/Src/N12_Libs/log_to_memory.h b/Inu/Src2/N12_Libs/log_to_memory.h similarity index 100% rename from Inu/Src/N12_Libs/log_to_memory.h rename to Inu/Src2/N12_Libs/log_to_memory.h diff --git a/Inu/Src2/N12_Libs/math_pi.h b/Inu/Src2/N12_Libs/math_pi.h new file mode 100644 index 0000000..a12ecd2 --- /dev/null +++ b/Inu/Src2/N12_Libs/math_pi.h @@ -0,0 +1,50 @@ +/* + * math_pi.h + * + * Created on: 6 нояб. 2020 г. + * Author: stud + */ + +#ifndef SRC_LIBS_NIO12_MATH_PI_H_ +#define SRC_LIBS_NIO12_MATH_PI_H_ + + +#define CONST_SQRT3 29058990 //1.7320508075688772935274463415059 = sqrt(3) +#define CONST_SQRT3_2 14529495 //1.7320508075688772935274463415059/2=0.8660254 = sqrt(3)/2 +#define CONST_IQ_1 16777216 //1 + + +#define CONST_IQ_2 33554432 //2 + + + +#define CONST_IQ_01 1677721 //0.1 +#define CONST_IQ_02 3355442 //0.2 +#define CONST_IQ_03 5033163 //0.3 +#define CONST_IQ_04 6710884 //0.4 +#define CONST_IQ_05 8388608 //0.5 + +#define CONST_IQ_06 10066329 //0.6 +#define CONST_IQ_07 11744051 //0.7 +#define CONST_IQ_08 13421772 //0.8 +#define CONST_IQ_09 15099494 //0.9 + + +#define CONST_IQ_PI6 8784530 //30 +#define CONST_IQ_PI3 17569060 // 60 +#define CONST_IQ_PI05 26353589 // 90 +#define CONST_IQ_PI 52707178 // 180 +//#define CONST_IQ_OUR1 35664138 // +#define CONST_IQ_2PI 105414357 // 360 +#define CONST_IQ_120G 35138119 // 120 grad +#define CONST_IQ_3 50331648 // 3 + +//#define IQ_ALFA_SATURATION1 15099494//16441671//15099494 +//#define IQ_ALFA_SATURATION2 1677721//16441671//15099494 + + +#define PI 3.1415926535897932384626433832795 + + + +#endif /* SRC_LIBS_NIO12_MATH_PI_H_ */ diff --git a/Inu/Src2/N12_Libs/mathlib.c b/Inu/Src2/N12_Libs/mathlib.c new file mode 100644 index 0000000..b8d401c --- /dev/null +++ b/Inu/Src2/N12_Libs/mathlib.c @@ -0,0 +1,437 @@ +/* + + ЦНИИ СЭТ (с) 2002 г. + + Processor: TMS320C32 + + Filename: vector_troll.h + + СИСТЕМА ВЕКТОРНОГО УПРАВЛЕНИy + + Edit date: 04-12-02 + + Function: + + Revisions: +*/ +#include "IQmathLib.h" + +#include "DSP281x_Device.h" // DSP281x Headerfile Include File +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include +#include "mathlib.h" + +#include "params_norma.h" +#include "math_pi.h" +#include "params_pwm24.h" +#include +#include "params_norma.h" + +_iq SQRT_32 = _IQ(0.8660254037844); +_iq CONST_23 = _IQ(2.0/3.0); +_iq CONST_15 = _IQ(1.5); + + + + +#define real float + +float my_satur_float(float Input, float Positive, float Negative, float DeadZone) +{ + if (fabs(DeadZone)>0.000001 && Input>-DeadZone && Input=Positive) Input=Positive; + else + if (Input<=Negative) Input=Negative; + + return Input; +} + +int my_satur_int(int Input, int Positive, int Negative, int DeadZone) +{ + if (DeadZone!=0 && Input>-DeadZone && Input=Positive) Input=Positive; + else + if (Input<=Negative) Input=Negative; + + return Input; +} + +long my_satur_long(long Input, long Positive, long Negative, long DeadZone) +{ + + if (DeadZone!=0 && Input>-DeadZone && Input=Positive) Input=Positive; + else + if (Input<=Negative) Input=Negative; + + return Input; +} +/* + + +real pid_regul(real Kp_regul, real Tperiod_regul, real Minimum, real Maximum, + real yk, real *uk1, real *yk1, real *yzad, real *ek, real *ek1, real *ek2, + real d0, real d1, real d2) +{ + real uk; + + + *ek = - yk + *yzad; + uk = *uk1 + Kp_regul * ( d0 * *ek + d1 * *ek1 + d2 * *ek2 ); + + if (uk>Maximum) uk=Maximum; + if (ukMaximum) uk=Maximum; + if (ukMaximum) *VarIntegral=Maximum; + if (*VarIntegralMaximum) VarOut=Maximum; + if (VarOutStepP) || (deltaVar<-StepN)) + { + if (deltaVar>0) InpVarCurr += StepP; + else InpVarCurr -= StepN; + } + else + InpVarCurr=InpVarInstant; + + + VarOut = InpVarCurr; + return VarOut; +} + +#pragma CODE_SECTION(zad_intensiv_q,".fast_run"); +_iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant) +{ + _iq deltaVar, VarOut; + + deltaVar = InpVarInstant-InpVarCurr; + + if ((deltaVar>StepP) || (deltaVar<-StepN)) + { + if (deltaVar>0) InpVarCurr += StepP; + else InpVarCurr -= StepN; + } + else + InpVarCurr=InpVarInstant; + + + VarOut = InpVarCurr; + return VarOut; + + +} + + + + + + +real pi_regul3(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, real Maximum, + real InpVar, real *InpVarPrev, real *OutVarPrev) +{ + real VarOut; + + + VarOut = Kp_regul*(ki_regul/Kp_regul*Tperiod_regul/2.0+1)*InpVar + Kp_regul*(ki_regul/Kp_regul*Tperiod_regul/2.0-1) * (*InpVarPrev) + *OutVarPrev; + + if (VarOut>Maximum) VarOut=Maximum; + if (VarOutMaximum) VarOut=Maximum; + if (VarOutdata_array == 0) return 0; + for (i = 0; i < v->size_array; ++i) { + summ_squares += _IQmpy(v->data_array[i], v->data_array[i]); + } + return _IQsqrt(summ_squares / v->size_array); +} + +//_iq calc_rms_array_var_period(RMS_CALC_ARRAY_THINNING *v) { +// _iq summ_squares = 0; +// int i = 0; +// int count_elem = 0; +// if (v->signal_period > v->size_array) { +// v->signal_period = v->size_array; +// } +// count_elem = v->signal_period; +// i = v->last_elem_position; +// while (count_elem > 0) { +// summ_squares += _IQmpy(v->data_array[i], v->data_array[i]); +// i -= 1; +// if (i < 0) { i = v->size_array - 1; } +// count_elem -= 1; +// +// } +// v->Out_rms = _IQsqrt(summ_squares / v->signal_period); +// return v->Out_rms; +//} + +_iq calc_rms_array_var_period_IQ15(RMS_CALC_ARRAY_THINNING *v) { + _iq16 summ_squares = 0; + int i = 0; + int count_elem = 0; + if (v->data_array == 0) { + return 0; + } + if (v->signal_period > v->size_array) { + v->signal_period = v->size_array; + } + count_elem = v->signal_period; + i = v->last_elem_position; + while (count_elem > 0) { + summ_squares += 0;//_IQ15mpy(v->data_array[i], v->data_array[i]); + i -= 1; + if (i < 0) { i = v->size_array - 1; } + count_elem -= 1; + + } + v->Out_rms =_IQ15toIQ(_IQ15sqrt(summ_squares / v->signal_period)); + return v->Out_rms; +} + +float fast_round(float x) +{ + float d; + long i; + + + i = (long)x; + + if (x<0) + { + d = i - x; + if (d>=0.5) + i = i - 1; + } + else + { + d = x - i; + if (d>=0.5) + i = i + 1; + } + return (float)i; + +} + +float fast_round_with_delta(float prev, float x, float delta) +{ + float d; + long i; + + + i = (long)x; + + if (x<0) + { + d = i - x; + if (d>=0.5) + i = i - 1; + } + else + { + d = x - i; + if (d>=0.5) + i = i + 1; + } + + if (fabs(prev-x)>=delta) + return (float)i; + else + return (float)prev; + +} + + +float fast_round_with_limiter(float x, float lim) +{ + float d; + long i; + + + if (fabs(x)<=lim) + return 0; + + i = (long)x; + + if (x<0) + { + d = i - x; + if (d>=0.5) + i = i - 1; + } + else + { + d = x - i; + if (d>=0.5) + i = i + 1; + } + return (float)i; + +} + + +#pragma CODE_SECTION(calc_rms,".fast_run"); +_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal) +{ + static _iq pi_pwm = _IQ(PI*NORMA_FROTOR/(FREQ_PWM/5.0)); + + _iq cosw, sinw, wdt, y2, z1, z2, z3, y; + + wdt = _IQmpy(pi_pwm,freq_signal); + sinw = _IQsinPU(wdt); + cosw = _IQcosPU(wdt); + + if (cosw==0) + return 0; + + z1 = input_prev - _IQmpy(input,cosw); +// z2 = sinw; + z3 = _IQdiv(z1,sinw); + + y2 = _IQmpy(input,input)+_IQmpy(z3,z3); + +// cosw = _IQsin(); + + y = _IQsqrt(y2); + return y; +} + + + diff --git a/Inu/Src2/N12_Libs/mathlib.h b/Inu/Src2/N12_Libs/mathlib.h new file mode 100644 index 0000000..2910690 --- /dev/null +++ b/Inu/Src2/N12_Libs/mathlib.h @@ -0,0 +1,81 @@ + +#ifndef _MATHLIB +#define _MATHLIB + +#include "IQmathLib.h" + + +/* + +real pi_regul(real Kp_regul, real Tintegral_regul, real Tperiod_regul, + real Minimum, real Maximum, real InpVar, real *VarIntegral); + +real exp_regul(real Tperiod_regul, real Texp_regul, real InpVarCurr, real InpVarInstant); + + + +real pid_regul2(real Kp_regul, real Tperiod_regul, real Minimum, real Maximum, + real yk, real *uk1, real *yk1, real *yk2, real *yzad, + real d0, real d1, real d2); + +real pid_regul(real Kp_regul, real Tperiod_regul, real Minimum, real Maximum, + real yk, real *uk1, real *yk1, real *yzad, real *ek, real *ek1, real *ek2, + real d0, real d1, real d2); + +real pi_regul3(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, real Maximum, + real InpVar, real *InpVarPrev, real *OutVarPrev); + +real pi_regul4(real Kp_regul, real ki_regul, real Tperiod_regul, real Minimum, real Maximum, + real InpVar, real *InpVarPrev, real *OutVarPrev); + +*/ +float zad_intensiv(float StepP, float StepN, float InpVarCurr, float InpVarInstant); + +_iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant); +_iq im_calc( _iq ia, _iq ib, _iq ic); + +float exp_regul(float Tperiod_regul, float Texp_regul, float InpVarCurr, float InpVarInstant); + + + +float my_satur_float(float Input, float Positive, float Negative, float DeadZone); + +int my_satur_int(int Input, int Positive, int Negative, int DeadZone); +long my_satur_long(long Input, long Positive, long Negative, long DeadZone); + + + + +#define exp_regul_fast(Tperiod_regul,Texp_regul,InpVarCurr,InpVarInstant) (InpVarCurr + Tperiod_regul*(InpVarInstant-InpVarCurr)/Texp_regul) + +typedef struct { + _iq *data_array; + int size_array; + _iq (*calc)(); +} RMS_CALC_ARRAY; + +#define RMS_CALC_DEFAULTS { 0,0, calc_rms_array_simple} + +_iq calc_rms_array_simple(RMS_CALC_ARRAY *v); + +typedef struct { + _iq16 *data_array; + int size_array; + int last_elem_position; + int signal_period; + _iq Out_rms; + _iq (*calc)(); +} RMS_CALC_ARRAY_THINNING; + +#define RMS_CALC_THINNING_DEFAULTS { 0,0,0,0,0, calc_rms_array_var_period_IQ15} + +_iq calc_rms_array_var_period(RMS_CALC_ARRAY_THINNING *v); +_iq calc_rms_array_var_period_IQ15(RMS_CALC_ARRAY_THINNING *v); +float fast_round(float x); +float fast_round_with_limiter(float x, float lim); +float fast_round_with_delta(float prev, float x, float delta); + +_iq calc_rms(_iq input, _iq input_prev, _iq freq_signal); + +#endif + diff --git a/Inu/Src2/N12_Libs/modbus_table_v2.c b/Inu/Src2/N12_Libs/modbus_table_v2.c new file mode 100644 index 0000000..0ccb1ef --- /dev/null +++ b/Inu/Src2/N12_Libs/modbus_table_v2.c @@ -0,0 +1,89 @@ +#include "modbus_table_v2.h" + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File +#include "RS_Functions.h" +#include "xp_project.h" +//#include "modbus_fill_table.h" +//#include "adc_tools.h" +//#include "can_setup.h" +//#include "isolation.h" +//#include "rotation_speed.h" + +// #include "IQmathLib.h" +//#include "errors.h" +//#include "params.h" +//#include "can_watercool.h" +// #include "doors_control.h" + +#pragma DATA_SECTION(modbus_table_rs_in,".logs"); +MODBUS_REG_STRUCT modbus_table_rs_in[SIZE_MODBUS_TABLE]; + + +#pragma DATA_SECTION(modbus_table_rs_out,".logs"); +MODBUS_REG_STRUCT modbus_table_rs_out[SIZE_MODBUS_TABLE]; + + +#pragma DATA_SECTION(modbus_table_can_in,".logs"); +MODBUS_REG_STRUCT modbus_table_can_in[SIZE_MODBUS_TABLE]; + + +#pragma DATA_SECTION(modbus_table_can_out,".logs"); +MODBUS_REG_STRUCT modbus_table_can_out[SIZE_MODBUS_TABLE]; + +#pragma DATA_SECTION(modbus_table_can_out_temp,".logs"); +MODBUS_REG_STRUCT modbus_table_can_out_temp[SIZE_MODBUS_TABLE]; + + + +void clear_modbus_table_in() +{ +int i; + + for (i=0;i 0x180000) || ((Address2+LengthW) > 0x180000) ) + { + return 1; + } + + RunFlashData(Address1,Address2,LengthW, &cerr, &repl, &count_ok ); + + + return 0; + +} + + diff --git a/Inu/Src2/N12_Libs/options_table.h b/Inu/Src2/N12_Libs/options_table.h new file mode 100644 index 0000000..8447a55 --- /dev/null +++ b/Inu/Src2/N12_Libs/options_table.h @@ -0,0 +1,17 @@ +#ifndef _OPTIONS_TABLE_H +#define _OPTIONS_TABLE_H + +#include "modbus_struct.h" + +#define ADR_STORE_OPTION_TO_FLASH 0x16000 + + +#define SIZE_OPTIONS_TABLE 200 + + +extern MODBUS_REG_STRUCT options_controller[SIZE_OPTIONS_TABLE]; + +int store_data_flash(MODBUS_REG_STRUCT *modbus_t, unsigned int size); + + +#endif // end _OPTIONS_TABLE_H diff --git a/Inu/Src2/N12_Libs/oscil_can.c b/Inu/Src2/N12_Libs/oscil_can.c new file mode 100644 index 0000000..47bcb39 --- /dev/null +++ b/Inu/Src2/N12_Libs/oscil_can.c @@ -0,0 +1,293 @@ +/* + * oscil_can.c + * + * Created on: 24 мая 2020 г. + * Author: yura + */ + +#include "oscil_can.h" + +#include "CAN_Setup.h" +#include "global_time.h" + + + +#pragma DATA_SECTION(oscil_can, ".slow_vars") +OSCIL_CAN oscil_can = OSCIL_CAN_DEFAULTS; + + + +//int oscil_buffer[OSCIL_CAN_NUMBER_CHANNEL][OSCIL_CAN_NUMBER_POINTS]; + + + +void oscil_clear_buffer(OSCIL_CAN_handle oc) +{ + unsigned int i,k; + + for (i=0;ioscil_buffer[i][k] = 0; + + for (i=0;itemp_oscil_buffer[i][k] = 0; + + + oc->current_position = 0; + // oc->enable_rewrite = 1; + +} + + +void oscil_send_buffer(OSCIL_CAN_handle oc) +{ + static unsigned int old_time = 0; + static int prev_send_to_can = 0; + unsigned long old_t; + unsigned int i; + int real_mbox; + static int flag_send_buf = 0; + + +// if (flag_send_buf) +// { +// +// +// +// return; +// } + + + + oc->global_enable = TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x1; + oc->send_after_cmd = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x2) >> 1; + oc->cmd_send = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x4) >> 2; + oc->stop_update_on_error = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x8) >> 3; + oc->stop_update_on_stop_pwm = (TerminalUnites[oc->number_can_box_terminal_oscil][0] & 0x10) >> 4; + + TerminalUnites[oc->number_can_box_terminal_oscil][0] &= ~0x4; // clear cmd_send + + oc->number_ch = TerminalUnites[oc->number_can_box_terminal_oscil][1]; + oc->number_points = TerminalUnites[oc->number_can_box_terminal_oscil][2]; + oc->step = TerminalUnites[oc->number_can_box_terminal_oscil][3]; + + + if (oc->global_enable==0) + return; + + real_mbox = get_real_out_mbox(TERMINAL_TYPE_BOX, oc->number_can_box_terminal_oscil); + + // была команда на отправку посылки и она еще не ушла, тогда србасываем счетчик времени паузы между посылками, + // т.е. OSCIL_TIME_WAIT между концом отправки посылки и новой посылки. + if (prev_send_to_can && CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_OFF)==0) + { + old_time = (unsigned int)global_time.miliseconds; + return; + } + prev_send_to_can = 0; + + if (oc->send_after_cmd==0) + { + if (!detect_pause_milisec(OSCIL_TIME_WAIT,&old_time)) + return; + } + + + if ( (oc->send_after_cmd==0 || (oc->send_after_cmd==1 && oc->cmd_send==1 ) ) ) + { + + oc->cmd_send = 0; // clear cmd + + if (CAN_cycle_full_free(real_mbox,CAN_BOX_STAT_ON)) + { + + // oc->enable_rewrite = 0; + + + old_t = oc->current_position;// +// old_t = global_time.microseconds; + + oc->prepare_data_can(oc); + +// oc->timer_send = (global_time.microseconds - old_t); + oc->timer_send = (oc->current_position - old_t); + + flag_send_buf = 1; + + CAN_cycle_send( + TERMINAL_TYPE_BOX, + oc->number_can_box_terminal_oscil, + 0, + &(oc->temp_oscil_buffer[0][0]), (oc->number_ch * oc->number_points) , CAN_BOX_EXTENDED_ADR, CAN_BOX_PRIORITY_LOW ); + + prev_send_to_can = 1; + // while (CAN_cycle_free(real_mbox)==0); + +// oc->timer_send = (global_time.microseconds - old_t)/100; + + + oc->enable_rewrite = 1; + + +// if (cur_position_buf_modbus16_can >= SIZE_MODBUS_TABLE) +// { +// cur_position_buf_modbus16_can = 0; +//// modbus_table_can_out[ADR_CAN_TEST_PLUS_ONE].all++; +// } +// +// if ((cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN) >= SIZE_MODBUS_TABLE) +// count_write_to_modbus_can = SIZE_MODBUS_TABLE - cur_position_buf_modbus16_can; +// else +// count_write_to_modbus_can = SIZE_BUF_WRITE_TO_MODBUS16_CAN; +// +// if (CAN_cycle_free(real_mbox)) +// { +// CAN_cycle_send( +// MPU_TYPE_BOX, +// edrk.flag_second_PCH, +// cur_position_buf_modbus16_can + 1, +// &modbus_table_can_out[cur_position_buf_modbus16_can].all, +// count_write_to_modbus_can, 0); +// +// cur_position_buf_modbus16_can = cur_position_buf_modbus16_can + SIZE_BUF_WRITE_TO_MODBUS16_CAN; +// } +// +// + + + + + + } + } + + +} + + +//#pragma CODE_SECTION(oscil_next_position,".fast_run"); +void oscil_next_position(OSCIL_CAN_handle oc) +{ + static int prev_status_pwm = 0; + static int prev_status_error = 0; + static int cmd_stop_after_stop_pwm = 0; + static int cmd_stop_after_stop_error = 0; + + static int count_write_after_stop = 0; + + static int prev_stop_update_on_stop_pwm = 0; + static int prev_stop_update_on_stop_error = 0; + +////////// + if (oc->stop_update_on_error) + { + if (oc->status_error && prev_status_error==0) + { + // после выставления ошибки мы тормозим лог + count_write_after_stop = OSCIL_CAN_NUMBER_POINTS_AFTER_STOP; + cmd_stop_after_stop_error = 1; + } + + if (oc->status_error==0 && prev_status_error) + { + // после сброса ошибок мы запускаем лог. + cmd_stop_after_stop_error = 0; + } + + } + else + cmd_stop_after_stop_error = 0; + +//////////// + + if (oc->stop_update_on_stop_pwm==1 && prev_stop_update_on_stop_pwm==0) + { + // после включения настройки onPWM мы тормозим лог если он записывался. + cmd_stop_after_stop_pwm = 1; + } + + if (oc->stop_update_on_stop_pwm) + { + if (oc->status_pwm==0 && prev_status_pwm) + { + // после выключения PWM мы тормозим лог если он записывался. + count_write_after_stop = OSCIL_CAN_NUMBER_POINTS_AFTER_STOP; + cmd_stop_after_stop_pwm = 1; + } + + if (oc->status_pwm && prev_status_pwm==0) + { + // после включения PWM мы запускаем лог. + cmd_stop_after_stop_pwm = 0; + } + } + else + cmd_stop_after_stop_pwm = 0; + + prev_stop_update_on_stop_pwm = oc->stop_update_on_stop_pwm; + prev_stop_update_on_stop_error = oc->stop_update_on_error; + prev_status_error = oc->status_error; + prev_status_pwm = oc->status_pwm; +//////////// + + + + oc->current_step++; + if (oc->current_step>=oc->step) + { + oc->current_step = 0; + + if (cmd_stop_after_stop_error || cmd_stop_after_stop_pwm) + { + if (count_write_after_stop) + { + count_write_after_stop--; + oc->current_position++; + oc->code_status_log = OSCIL_CODE_STATUS_LOG_RUN_TO_STOP; + } + else + oc->code_status_log = OSCIL_CODE_STATUS_LOG_STOP; + } + else + { + oc->current_position++; + oc->code_status_log = OSCIL_CODE_STATUS_LOG_RUN; + } + + if (oc->current_position==(OSCIL_CAN_NUMBER_POINTS+OSCIL_CAN_NUMBER_POINTS_ADD)) + oc->current_position = 0; + } + + +} + + +#pragma CODE_SECTION(oscil_prepare_data_can,".fast_run"); +void oscil_prepare_data_can(OSCIL_CAN_handle oc) +{ + unsigned int old_position, t_position; + int i, k; + + + old_position = oc->current_position; + + for (i=0;i=0;k--) + { + if (t_position==0) + { + t_position = (OSCIL_CAN_NUMBER_POINTS+OSCIL_CAN_NUMBER_POINTS_ADD)-1; + } + else + t_position = t_position - 1; + + oc->temp_oscil_buffer[i][k] = oc->oscil_buffer[i][t_position]; + + } + + } + +} diff --git a/Inu/Src2/N12_Libs/oscil_can.h b/Inu/Src2/N12_Libs/oscil_can.h new file mode 100644 index 0000000..bb55f46 --- /dev/null +++ b/Inu/Src2/N12_Libs/oscil_can.h @@ -0,0 +1,103 @@ +/* + * oscil_can.h + * + * Created on: 24 мая 2020 г. + * Author: yura + */ + +#ifndef SRC_LIBS_NIO12_OSCIL_CAN_H_ +#define SRC_LIBS_NIO12_OSCIL_CAN_H_ + + +#define OSCIL_CODE_STATUS_LOG_STOP 1 // Лог остановлен +#define OSCIL_CODE_STATUS_LOG_RUN 2 // Лог идет... +#define OSCIL_CODE_STATUS_LOG_RUN_TO_STOP 3 // Лог идет, но идет дозапись, скоро остановится. + + + +#define OSCIL_CAN_NUMBER_CHANNEL 32 // максимальное возможное кол-во каналов для буфера +#define OSCIL_CAN_NUMBER_POINTS 500 // максимальное возможное кол-во точек для буфера (для одного канала) +#define OSCIL_TIME_WAIT 5000 // период посылки всего массива в CAN (млсек) +#define OSCIL_CAN_NUMBER_POINTS_ADD 100 // запас точек при выполнении функции копирования рабочего буфера во временный. oscil_buffer->temp_oscil_buffer + +#define OSCIL_CAN_NUMBER_POINTS_AFTER_STOP 100 // сколько точек записывать после остановки записи буфера по аварии или шиму + + + +typedef struct { + int oscil_buffer[OSCIL_CAN_NUMBER_CHANNEL][OSCIL_CAN_NUMBER_POINTS+OSCIL_CAN_NUMBER_POINTS_ADD]; + int temp_oscil_buffer[OSCIL_CAN_NUMBER_CHANNEL][OSCIL_CAN_NUMBER_POINTS]; + unsigned int global_enable; + unsigned int number_ch; + unsigned int number_points; + unsigned int step; + unsigned int send_after_cmd; + unsigned int cmd_send; + unsigned int current_step; + unsigned int enable_rewrite; + unsigned int current_position; + unsigned int timer_send; + unsigned int code_status_log; + + unsigned int status_error; // статус аварии 0-нет аварии/1- есть + unsigned int status_pwm; // статус ШИМа 0-Шим не запущен/1-запущен + + unsigned int stop_update_on_error; // остановим обновление буфера по аварии + unsigned int stop_update_on_stop_pwm; // остановим обновление буфера по стопу ШИМа + + + int number_can_box_terminal_oscil; + int number_can_box_terminal_cmd; + unsigned int pause_can; // пауза между посылками CAN + + + void (*clear)(); // Clear buffers + void (*send)(); // Send buffers + void (*set_next_position)(); // Set next position in buffers + void (*prepare_data_can)(); // Set next position in buffers + +} OSCIL_CAN; + +typedef OSCIL_CAN *OSCIL_CAN_handle; + + + +#define OSCIL_CAN_DEFAULTS { {0},{0}, \ + 0, \ + OSCIL_CAN_NUMBER_CHANNEL, \ + OSCIL_CAN_NUMBER_POINTS, \ + 1, \ + 0, \ + 0, \ + 0, \ + 1, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 1, \ + 1, \ + 0,0, \ + OSCIL_TIME_WAIT, \ + oscil_clear_buffer, \ + oscil_send_buffer, \ + oscil_next_position, \ + oscil_prepare_data_can \ +} + + + + +void oscil_clear_buffer(OSCIL_CAN_handle); +void oscil_send_buffer(OSCIL_CAN_handle); +void oscil_next_position(OSCIL_CAN_handle); +void oscil_prepare_data_can(OSCIL_CAN_handle); + + + +extern OSCIL_CAN oscil_can; + +#endif /* SRC_LIBS_NIO12_OSCIL_CAN_H_ */ + + diff --git a/Inu/Src2/N12_Libs/params_protect.h b/Inu/Src2/N12_Libs/params_protect.h new file mode 100644 index 0000000..d85c625 --- /dev/null +++ b/Inu/Src2/N12_Libs/params_protect.h @@ -0,0 +1,63 @@ +#ifndef PARAMS_H +#define PARAMS_H + +//////////////////////////////////////////////////////////////// +// Loaded capasitors level +#define V_CAPASITORS_LOADED_IQ 11184810 //13421772 ~ 2400V // 11184810 ~ 2000V +#define V_NOMINAL 15099494 //15099494 ~ 2700V + +// Level of nominal current and maximum current +#define I_OUT_NOMINAL_IQ 9777761 //6431266 ~ 1150A //2796202 ~ 500A //By TU 1240A RMS - 1748A ~ 9777761 IQ +#define I_OUT_LIMIT_IQ 8388608 //8388608 ~ 1500A //5592405 ~ 1000A // 4473924 ~ 800A //1.5*In - 2622A ~ 14666642 IQ + //11184811 ~ 2000A // 12482249 ~ 2232A // 6710886 ~ 1200A + +// Input voltage levels for protection +#define V_IN_PLUS_20 (2340) +#define V_IN_PLUS_25 2650 //2450 +#define V_IN_MINUS_20 (1560) +#define V_IN_MINUS_25 1462 + + +//ACP program errors level +#define ERR_LEVEL_ADC_PLUS 3950 //+1270A //2950 // +650A //3467 // 3367 //3367 //3267 // 0xfff-0x29c +#define ERR_LEVEL_ADC_MINUS 150 //-1270A //1150 //-650A // 267 //367 +#define ERR_LEVEL_ADC_PLUS_6 650 //875 ~ 2500V //650 ~ 3000B // 740 ~ 2800B // +#define ERR_LEVEL_ADC_MINUS_6 1205 //1775V ~ 1205 +#define ERR_LEVEL_I_FAZA_PLUS 594 //1760A ~ 1058 //2000A ~ 924 //843 ~ 2100A // 594 ~ 2500A +#define ERR_LEVEL_I_FAZA_MINUS 3496 //1760A ~ 3031 //2000A ~ 3166 //3226 ~2100A // 3496 ~ 2500A +#define ERR_LEVEL_I_ZPT_PLUS 520 //520 ~ 1500A +#define ERR_LEVEL_BREAK_REZ 858 //858 ~ 800A +#define MIN_DETECT_UD_ZERO 2300 + +#define ERR_LEVEL_ADC_PLUS_6_ON_GO_IQ 16777216 //3000V // 16217975 //2900V +#define ERR_LEVEL_ADC_PLUS_6_IQ 16777216 //3000V //15658734 //2800V + +// Temperature protection levels +#define TEMPERATURE_LIMIT 600 //Area temperature +#define TEMPERATURE_WARNING 500 +#define TEMPERATURE_WATER_LIMIT 500 //Water temeperature +#define TEMPERATURE_WATER_WARNING 450 +#define TEMPERATURE_WATER_FAZA_LIMIT 500 //Water temperature on phase output +#define TEMPERATURE_WATER_FAZA_WARNING 450 +#define TEMPERATURE_WATER_SNABBER_RESISTORS_LIMIT 500 +#define TEMPERATURE_WATER_SNABBER_RESISTORS_WARNING 450 +#define TEMPERATURE_WATER_DROSSEL_LIMIT 600 //Output drossel water limits +#define TEMPERATURE_WATER_DROSSEL_WARNING 500 +#define TEMPERATURE_WATER_DIODS_LIMIT 500 //water temperature at rectifier outlet +#define TEMPERATURE_WATER_DIODS_WARNING 450 +#define TEMPERATURE_WATER_CHOPPER_LIMIT 500 +#define TEMPERATURE_WATER_CHOPPER_WARNING 450 +#define TEMPERATURE_REZISTORS_LIMIT_BV 600 //temperature on coolers of input filter resistors +#define TEMPERATURE_REZISTORS_WARNING_BV 500 +#define TEMPERATURE_REZISTORS_LIMIT_BI 500 //temperature on the coolers of the output filter resistors +#define TEMPERATURE_REZISTORS_WARNING_BI 450 +#define TEMPERATURE_INPUT_BSO_DN20 500 +#define TEMPERATURE_INPUT_BSO_DN100 500 +#define TEMPERATURE_OUTPUT_BSO_DN20 400 +#define TEMPERATURE_OUTPUT_BSO_DN100 400 +//////////////////////////////////// +#define TEMPERATURE_AREA_DATCHIK_ERROR -100 + + + +#endif //PARAMS_H \ No newline at end of file diff --git a/Inu/Src2/main/pid_reg3.c b/Inu/Src2/N12_Libs/pid_reg3.c similarity index 60% rename from Inu/Src2/main/pid_reg3.c rename to Inu/Src2/N12_Libs/pid_reg3.c index 4cc46c1..39502f5 100644 --- a/Inu/Src2/main/pid_reg3.c +++ b/Inu/Src2/N12_Libs/pid_reg3.c @@ -12,11 +12,10 @@ 04-15-2005 Version 3.20 -------------------------------------------------------------------------------------*/ -#include "IQmathLib.h" // Include header for IQmath library -// Don't forget to set a proper GLOBAL_Q in "IQmathLib.h" file -//#include "dmctype.h" #include "pid_reg3.h" +#include "IQmathLib.h" // Include header for IQmath library + #define IQ_100 1677721600 #pragma CODE_SECTION(pid_reg3_calc,".fast_run"); @@ -63,45 +62,3 @@ _iq Ud2; } -#pragma CODE_SECTION(pid_reg3_calc,".fast_run"); -void pid_reg3_undependent_calc(PIDREG3 *v) -{ -_iq Ud2; - // Compute the error - v->Err = v->Ref - v->Fdb; - - // Compute the proportional output - v->Up = _IQmpy(v->Kp,v->Err); - - // Compute the integral output - v->Ui = v->Ui + _IQmpy(v->Ki,v->Err) + _IQmpy(v->Kc,v->SatErr); -/* - // Saturate the integral output - if (v->Ui > v->OutMax) - v->Ui = v->OutMax; - else if (v->Ui < v->OutMin) - v->Ui = v->OutMin; -*/ - // Compute the derivative output - Ud2 = v->Up - v->Up1;// _IQmpy(IQ_100,(v->Up - v->Up1)); - v->Ud = _IQmpy(v->Kd,Ud2); - - - // Compute the pre-saturated output - v->OutPreSat = v->Up + v->Ui + v->Ud; - - // Saturate the output - if (v->OutPreSat > v->OutMax) - v->Out = v->OutMax; - else if (v->OutPreSat < v->OutMin) - v->Out = v->OutMin; - else - v->Out = v->OutPreSat; - - // Compute the saturate difference - v->SatErr = v->Out - v->OutPreSat; - - // Update the previous proportional output - v->Up1 = v->Up; - -} diff --git a/Inu/Src2/main/pid_reg3.h b/Inu/Src2/N12_Libs/pid_reg3.h similarity index 80% rename from Inu/Src2/main/pid_reg3.h rename to Inu/Src2/N12_Libs/pid_reg3.h index 20b68c6..d7b882c 100644 --- a/Inu/Src2/main/pid_reg3.h +++ b/Inu/Src2/N12_Libs/pid_reg3.h @@ -15,7 +15,7 @@ function prototypes for the PIDREG3. #ifndef __PIDREG3_H__ #define __PIDREG3_H__ -#include "IQmathlib.h" +#include "IQmathLib.h" //#include "dmctype.h" typedef struct { _iq Ref; // Input: Reference input @@ -59,29 +59,10 @@ Default initalizer for the PIDREG3 object. 0, \ (void (*)(PIDREG3_handle))pid_reg3_calc } -#define PIDREG3_UNDEPENDENT_DEFAULTS { 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(PIDREG3_handle))pid_reg3_undependent_calc } - /*------------------------------------------------------------------------------ Prototypes for the functions in PIDREG3.C ------------------------------------------------------------------------------*/ void pid_reg3_calc(PIDREG3_handle); -void pid_reg3_undependent_calc(PIDREG3 *v); #endif // __PIDREG3_H__ diff --git a/Inu/Src2/N12_Libs/rmp_cntl_v1.c b/Inu/Src2/N12_Libs/rmp_cntl_v1.c new file mode 100644 index 0000000..b99ffbc --- /dev/null +++ b/Inu/Src2/N12_Libs/rmp_cntl_v1.c @@ -0,0 +1,51 @@ +/*===================================================================================== + File name: RMP3CNTL.C (IQ version) + + Originator: Digital Control Systems Group + Texas Instruments + + Description: The ramp3 down control + +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +-------------------------------------------------------------------------------------*/ +#include "dmctype.h" +#include "IQmathLib.h" // Include header for IQmath library + +#include "rmp_cntl_v1.h" + + +#pragma CODE_SECTION(rmp_cntl_v1_calc,".fast_run"); +void rmp_cntl_v1_calc(RMP_V1 *v) +{ + _iq tmp; + + tmp = v->DesiredInput - v->Out; + + if (tmp > (_iq)v->RampPlus) + { + //v->RampDoneFlag = 0; + v->Out += v->RampPlus; + if (v->Out > v->RampHighLimit) + v->Out = v->RampHighLimit; + } + else + { + if (tmp < (_iq)v->RampMinus) + { + //v->RampDoneFlag = 0; + v->Out += (_iq)v->RampMinus; + if (v->Out < v->RampLowLimit) + v->Out = v->RampLowLimit; + } + else + { + v->Out = v->DesiredInput; + //v->RampDoneFlag = 0x7FFFFFFF; + } + } +} + + diff --git a/Inu/Src2/N12_Libs/rmp_cntl_v1.h b/Inu/Src2/N12_Libs/rmp_cntl_v1.h new file mode 100644 index 0000000..71a576c --- /dev/null +++ b/Inu/Src2/N12_Libs/rmp_cntl_v1.h @@ -0,0 +1,48 @@ +/* ================================================================================= +File name: RMP3CNTL.H (IQ version) + +Originator: Digital Control Systems Group + Texas Instruments + +Description: +Header file containing constants, data type definitions, and +function prototypes for the RMP3 module. +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +------------------------------------------------------------------------------*/ +#ifndef __RMP_CNTL_V1_H__ +#define __RMP_CNTL_V1_H__ + +typedef struct { _iq DesiredInput; // Input: Desired ramp input (Q0) - independently with global Q + _iq RampPlus; // Parameter: Ramp3 delay expressed in no of sampling period (Q0) - independently with global Q + _iq RampMinus; // Variable: Counter for rmp3 delay (Q0) - independently with global Q + _iq Out; // Output: Ramp3 output (Q0) - independently with global Q + _iq RampLowLimit; // Parameter: Minimum ramp output (Q0) - independently with global Q + _iq RampHighLimit; // Parameter: Minimum ramp output (Q0) - independently with global Q + //Uint32 RampDoneFlag; // Output: Flag output (Q0) - independently with global Q + void (*calc)(); // Pointer to calculation function + } RMP_V1; + +typedef RMP_V1 *RMP_V1_handle; +/*----------------------------------------------------------------------------- +Default initalizer for the RMP3 object. +-----------------------------------------------------------------------------*/ +#define RMP_V1_DEFAULTS { 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0x00000050, \ + (void (*)())rmp_cntl_v1_calc } + +/*------------------------------------------------------------------------------ +Prototypes for the functions in RMP3CNTL.C +------------------------------------------------------------------------------*/ +void rmp_cntl_v1_calc(RMP_V1_handle); + + + +#endif // __RMP3_CNTL_H__ + diff --git a/Inu/Src/N12_Libs/rmp_cntl_v2.c b/Inu/Src2/N12_Libs/rmp_cntl_v2.c similarity index 100% rename from Inu/Src/N12_Libs/rmp_cntl_v2.c rename to Inu/Src2/N12_Libs/rmp_cntl_v2.c diff --git a/Inu/Src/N12_Libs/rmp_cntl_v2.h b/Inu/Src2/N12_Libs/rmp_cntl_v2.h similarity index 100% rename from Inu/Src/N12_Libs/rmp_cntl_v2.h rename to Inu/Src2/N12_Libs/rmp_cntl_v2.h diff --git a/Inu/Src2/main/svgen_dq.h b/Inu/Src2/N12_Libs/svgen_dq.h similarity index 100% rename from Inu/Src2/main/svgen_dq.h rename to Inu/Src2/N12_Libs/svgen_dq.h diff --git a/Inu/Src2/main/svgen_dq_v2.c b/Inu/Src2/N12_Libs/svgen_dq_v2.c similarity index 82% rename from Inu/Src2/main/svgen_dq_v2.c rename to Inu/Src2/N12_Libs/svgen_dq_v2.c index cb8b85c..6176b1c 100644 --- a/Inu/Src2/main/svgen_dq_v2.c +++ b/Inu/Src2/N12_Libs/svgen_dq_v2.c @@ -12,14 +12,16 @@ 04-15-2005 Version 3.20 -------------------------------------------------------------------------------------*/ -#include "IQmathLib.h" // Include header for IQmath library -// Don't forget to set a proper GLOBAL_Q in "IQmathLib.h" file #include "dmctype.h" +#include "IQmathLib.h" // Include header for IQmath library +#include "math_pi.h" #include "svgen_dq.h" _iq iq_max = _IQ(1.0)-1; -// #pragma CODE_SECTION(svgendq_calc,".fast_run2"); + + +//#pragma CODE_SECTION(svgendq_calc,".fast_run2"); void svgendq_calc(SVGENDQ *v) { _iq Va,Vb,Vc,t1,t2,temp_sv1,temp_sv2; @@ -27,7 +29,7 @@ void svgendq_calc(SVGENDQ *v) Sector = 0; \ temp_sv1=_IQdiv2(v->Ubeta); /*divide by 2*/ \ - temp_sv2=_IQmpy(_IQ(0.8660254),v->Ualpha); /* 0.8660254 = sqrt(3)/2*/ \ + temp_sv2=_IQmpy(CONST_SQRT3_2,v->Ualpha); /* 0.8660254 = sqrt(3)/2*/ \ // Inverse clarke transformation Va = v->Ubeta; \ @@ -49,15 +51,15 @@ void svgendq_calc(SVGENDQ *v) if (Sector==0) // Sector 0: this is special case for (Ualpha,Ubeta) = (0,0) { - v->Ta = _IQ(0.5); - v->Tb = _IQ(0.5); - v->Tc = _IQ(0.5); + v->Ta = CONST_IQ_05; + v->Tb = CONST_IQ_05; + v->Tc = CONST_IQ_05; } if (Sector==1) // Sector 1: t1=Z and t2=Y (abc ---> Tb,Ta,Tc) { t1 = Vc; t2 = Vb; - v->Tb = _IQdiv2((_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2 + v->Tb = _IQdiv2((CONST_IQ_1-t1-t2)); // tbon = (1-t1-t2)/2 v->Ta = v->Tb+t1; // taon = tbon+t1 v->Tc = v->Ta+t2; // tcon = taon+t2 } @@ -65,7 +67,7 @@ void svgendq_calc(SVGENDQ *v) { t1 = Vb; t2 = -Va; - v->Ta = _IQdiv2((_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2 + v->Ta = _IQdiv2((CONST_IQ_1-t1-t2)); // taon = (1-t1-t2)/2 v->Tc = v->Ta+t1; // tcon = taon+t1 v->Tb = v->Tc+t2; // tbon = tcon+t2 } @@ -73,7 +75,7 @@ void svgendq_calc(SVGENDQ *v) { t1 = -Vc; t2 = Va; - v->Ta = _IQdiv2((_IQ(1)-t1-t2)); // taon = (1-t1-t2)/2 + v->Ta = _IQdiv2((CONST_IQ_1-t1-t2)); // taon = (1-t1-t2)/2 v->Tb = v->Ta+t1; // tbon = taon+t1 v->Tc = v->Tb+t2; // tcon = tbon+t2 } @@ -81,7 +83,7 @@ void svgendq_calc(SVGENDQ *v) { t1 = -Va; t2 = Vc; - v->Tc = _IQdiv2((_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2 + v->Tc = _IQdiv2((CONST_IQ_1-t1-t2)); // tcon = (1-t1-t2)/2 v->Tb = v->Tc+t1; // tbon = tcon+t1 v->Ta = v->Tb+t2; // taon = tbon+t2 } @@ -89,7 +91,7 @@ void svgendq_calc(SVGENDQ *v) { t1 = Va; t2 = -Vb; - v->Tb = _IQdiv2((_IQ(1)-t1-t2)); // tbon = (1-t1-t2)/2 + v->Tb = _IQdiv2((CONST_IQ_1-t1-t2)); // tbon = (1-t1-t2)/2 v->Tc = v->Tb+t1; // tcon = tbon+t1 v->Ta = v->Tc+t2; // taon = tcon+t2 } @@ -97,15 +99,15 @@ void svgendq_calc(SVGENDQ *v) { t1 = -Vb; t2 = -Vc; - v->Tc = _IQdiv2((_IQ(1)-t1-t2)); // tcon = (1-t1-t2)/2 + v->Tc = _IQdiv2((CONST_IQ_1-t1-t2)); // tcon = (1-t1-t2)/2 v->Ta = v->Tc+t1; // taon = tcon+t1 v->Tb = v->Ta+t2; // tbon = taon+t2 } // Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1)) - v->Ta = _IQmpy2(v->Ta - _IQ(0.5)); - v->Tb = _IQmpy2(v->Tb - _IQ(0.5)); - v->Tc = _IQmpy2(v->Tc - _IQ(0.5)); + v->Ta = _IQmpy2(v->Ta - CONST_IQ_05); + v->Tb = _IQmpy2(v->Tb - CONST_IQ_05); + v->Tc = _IQmpy2(v->Tc - CONST_IQ_05); if (v->Ta > iq_max) v->Ta = iq_max; if (v->Tb > iq_max) v->Tb = iq_max; diff --git a/Inu/Src2/N12_Libs/svgen_mf.c b/Inu/Src2/N12_Libs/svgen_mf.c new file mode 100644 index 0000000..3570aa9 --- /dev/null +++ b/Inu/Src2/N12_Libs/svgen_mf.c @@ -0,0 +1,164 @@ +/*===================================================================================== + File name: SVGEN_MF.C (IQ version) + + Originator: Digital Control Systems Group + Texas Instruments + + Description: Space-vector PWM generation based on magnitude and frequency components + +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +-------------------------------------------------------------------------------------*/ +#include "IQmathLib.h" // Include header for IQmath library +#include "dmctype.h" + + +#include "svgen_mf.h" + +#include + + +static _iq iq1_0=_IQ(1.0); +static _iq iq6_0=_IQ(6.0); +static _iq iq0_5=_IQ(0.5); +static _iq iq2_0=_IQ(2.0); + +static _iq iq3_0=_IQ(3.0); +static _iq iq4_0=_IQ(4.0); +static _iq iq5_0=_IQ(5.0); + + +//#pragma CODE_SECTION(svgenmf_calc,".fast_run"); +void svgenmf_calc(SVGENMF *v) +{ + _iq StepAngle,EntryOld,dx,dy; + _iq T = iq1_0;//_IQ(1.0); + + // Normalise the freq input to appropriate step angle + // Here, 1 pu. = 60 degree +//#ifdef DOUBLE_UPDATE_PWM +// StepAngle = (_IQmpy(v->Freq,v->FreqMax))>>1; // decrise step /2 for double update +//#else + StepAngle = _IQmpy(v->Freq,v->FreqMax); // normal step +//#endif + + // Calculate new angle alpha + EntryOld = v->NewEntry; + + v->Full_Alpha = v->Full_Alpha + StepAngle; + + if (v->Full_Alpha < 0) + v->Full_Alpha = v->Full_Alpha+iq6_0; + + if (v->Full_Alpha >= iq6_0) + v->Full_Alpha = v->Full_Alpha-iq6_0; + + + //new sector detect + if (v->Full_Alpha >= iq5_0) + { + v->SectorPointer=5; + v->Alpha = v->Full_Alpha-iq5_0; + } + else + if (v->Full_Alpha >= iq4_0) + { + v->SectorPointer=4; + v->Alpha = v->Full_Alpha-iq4_0; + } + else + if (v->Full_Alpha >= iq3_0) + { + v->SectorPointer=3; + v->Alpha = v->Full_Alpha-iq3_0; + } + else + if (v->Full_Alpha >= iq2_0) + { + v->SectorPointer=2; + v->Alpha = v->Full_Alpha-iq2_0; + } + else + if (v->Full_Alpha >= iq1_0) + { + v->SectorPointer=1; + v->Alpha = v->Full_Alpha-iq1_0; + } + else + { + v->SectorPointer=0; + v->Alpha = v->Full_Alpha; + } + + +// v->Alpha = v->Alpha + StepAngle; +// if (v->Alpha >= iq1_0) +// v->Alpha = v->Alpha-iq1_0; + + + v->NewEntry = v->Alpha; + + dy = _IQsin(_IQmpy(v->NewEntry,PI_THIRD)); // dy = sin(NewEntry) + dx = _IQsin(PI_THIRD-_IQmpy(v->NewEntry,PI_THIRD)); // dx = sin(60-NewEntry) + + // Determine which sector +// if (v->NewEntry-EntryOld<0) +// { +// if (v->SectorPointer==5) +// v->SectorPointer = 0; +// else +// v->SectorPointer = v->SectorPointer + 1; +// } + + if (v->SectorPointer==0) // Sector 1 calculations - a,b,c --> a,b,c + { + v->Ta = _IQmpy(iq0_5,(T-dx-dy)); + v->Tb = v->Ta + dx; + v->Tc = T - v->Ta; + } + else if (v->SectorPointer==1) // Sector 2 calculations - a,b,c --> b,a,c & dx <--> dy + { + v->Tb = _IQmpy(iq0_5,(T-dx-dy)); + v->Ta = v->Tb + dy; + v->Tc = T - v->Tb; + } + else if (v->SectorPointer==2) // Sector 3 calculations - a,b,c --> b,c,a + { + v->Tb = _IQmpy(iq0_5,(T-dx-dy)); + v->Tc = v->Tb + dx; + v->Ta = T - v->Tb; + } + else if (v->SectorPointer==3) // Sector 4 calculations - a,b,c --> c,b,a & dx <--> dy + { + v->Tc = _IQmpy(iq0_5,(T-dx-dy)); + v->Tb = v->Tc + dy; + v->Ta = T - v->Tc; + } + else if (v->SectorPointer==4) // Sector 5 calculations - a,b,c --> c,a,b + { + v->Tc = _IQmpy(iq0_5,(T-dx-dy)); + v->Ta = v->Tc + dx; + v->Tb = T - v->Tc; + } + else if (v->SectorPointer==5) // Sector 6 calculations - a,b,c --> a,c,b & dx <--> dy + { + v->Ta = _IQmpy(iq0_5,(T-dx-dy)); + v->Tc = v->Ta + dy; + v->Tb = T - v->Ta; + } + +// Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1)) +// Then, multiply with a gain and add an offset. + v->Ta = _IQmpy(iq2_0,(v->Ta-iq0_5)); + v->Ta = _IQmpy(v->Gain,v->Ta) + v->Offset; + + v->Tb = _IQmpy(iq2_0,(v->Tb-iq0_5)); + v->Tb = _IQmpy(v->Gain,v->Tb) + v->Offset; + + v->Tc = _IQmpy(iq2_0,(v->Tc-iq0_5)); + v->Tc = _IQmpy(v->Gain,v->Tc) + v->Offset; + +} + diff --git a/Inu/Src2/N12_Libs/svgen_mf.h b/Inu/Src2/N12_Libs/svgen_mf.h new file mode 100644 index 0000000..d7188ef --- /dev/null +++ b/Inu/Src2/N12_Libs/svgen_mf.h @@ -0,0 +1,46 @@ +/* ================================================================================= +File name: SVGEN_MF.H (IQ version) + +Originator: Digital Control Systems Group + Texas Instruments + +Description: +Header file containing constants, data type definitions, and +function prototypes for the SVGEN_MF. +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +------------------------------------------------------------------------------*/ +#ifndef __SVGEN_MF_H__ +#define __SVGEN_MF_H__ + +typedef struct { _iq Gain; // Input: reference gain voltage (pu) + _iq Offset; // Input: reference offset voltage (pu) + _iq Freq; // Input: reference frequency (pu) + _iq FreqMax; // Parameter: Maximum step angle = 6*base_freq*T (pu) + _iq Alpha; // History: Sector angle (pu) + _iq Full_Alpha; + _iq NewEntry; // History: Sine (angular) look-up pointer (pu) + Uint32 SectorPointer; // History: Sector number (Q0) - independently with global Q + _iq Ta; // Output: reference phase-a switching function (pu) + _iq Tb; // Output: reference phase-b switching function (pu) + _iq Tc; // Output: reference phase-c switching function (pu) + void (*calc)(); // Pointer to calculation function + } SVGENMF; + +typedef SVGENMF *SVGENMF_handle; +/*----------------------------------------------------------------------------- +Default initalizer for the SVGENMF object. +-----------------------------------------------------------------------------*/ +#define SVGENMF_DEFAULTS { 0,0,0,0,0,0,0,0,0,0,0, \ + (void (*)(Uint32))svgenmf_calc } + +#define PI_THIRD _IQ(1.04719755119660) // This is 60 degree +/*------------------------------------------------------------------------------ +Prototypes for the functions in SVGEN_MF.C +------------------------------------------------------------------------------*/ +void svgenmf_calc(SVGENMF_handle); + +#endif // __SVGEN_MF_H__ + diff --git a/Inu/Src2/N12_Libs/uf_alg_ing.c b/Inu/Src2/N12_Libs/uf_alg_ing.c new file mode 100644 index 0000000..378b2c2 --- /dev/null +++ b/Inu/Src2/N12_Libs/uf_alg_ing.c @@ -0,0 +1,736 @@ +/* + * uf_alg_ing.c + * + * Created on: 10 февр. 2020 г. + * Author: yura + */ + + + +#include "IQmathLib.h" +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File + + + +#include "uf_alg_ing.h" + +#include +#include +#include +#include +#include +#include + +#include "math_pi.h" +#include "svgen_dq.h" +#include "svgen_mf.h" +#include "dq_to_alphabeta_cos.h" +#include "params_norma.h" + + + +//#pragma DATA_SECTION(svgen_mf1,".fast_vars"); +SVGENMF svgen_mf1 = SVGENMF_DEFAULTS; + +//#pragma DATA_SECTION(svgen_mf2,".fast_vars"); +//SVGENMF svgen_mf2 = SVGENMF_DEFAULTS; + + +//#pragma DATA_SECTION(svgen_dq_1,".fast_vars"); +SVGENDQ svgen_dq_1 = SVGENDQ_DEFAULTS; +//#pragma DATA_SECTION(svgen_dq_2,".fast_vars"); +//SVGENDQ svgen_dq_2 = SVGENDQ_DEFAULTS; + + +UF_ALG_VALUE uf_alg = UF_ALG_VALUE_DEFAULT; + +void InitVariablesSvgen_Ing(unsigned int freq) +{ + + + + svgen_dq_1.Ualpha = 0; + svgen_dq_1.Ubeta = 0; + + // svgen_dq_2.Ualpha = 0; + // svgen_dq_2.Ubeta = 0; + + uf_alg.hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / freq ); // один раз за такт ШИМа +// uf_alg.hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / freq /2.0 ); // два раза за такт ШИМа + + + + +// Initialize the SVGEN_MF module +// svgen_mf1.FreqMax = _IQ(6*NORMA_FROTOR/freq); +// svgen_mf2.FreqMax = _IQ(6*NORMA_FROTOR/freq); +// +// +// svgen_mf2.Offset=_IQ(0); +// svgen_mf1.Offset=_IQ(0); + + init_alpha_Ing(0); + + +} + + + + + + + + +void init_alpha_Ing(unsigned int master_slave) +{ + + + uf_alg.winding_displacement_bs1 = 0; + uf_alg.winding_displacement_bs2 = 0; + + +// power_ain1.init(&power_ain1); +// power_ain2.init(&power_ain2); + +// svgen_mf1.NewEntry = 0;//_IQ(0.5); +// svgen_mf2.NewEntry = 0; + +// svgen_mf1.SectorPointer = 0; +// svgen_mf2.SectorPointer = 0; + +//сдвиг по умолчанию 0 градусов +// svgen_mf1.Alpha = _IQ(0); +// svgen_mf2.Alpha = _IQ(0); + +// +// +// + +#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_30_PLUS) +// 30 град. сдвиг + // тут не радианы, а нормированные к 60 град=1. +// svgen_mf1.Alpha = _IQ(0.5); +// svgen_mf2.Alpha = _IQ(0); +// +// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; +// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; + + // тут радианы + uf_alg.winding_displacement_bs1 = CONST_IQ_PI6; //_IQ(0.5); + uf_alg.winding_displacement_bs2 = 0; + +#else + + +#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_30_MINUS) +// -30 град. сдвиг + // тут не радианы, а нормированные к 60 град=1. +// svgen_mf1.Alpha = _IQ(0); +// svgen_mf2.Alpha = _IQ(0.5); +// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; +// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; +// + // тут радианы + uf_alg.winding_displacement_bs2 = CONST_IQ_PI6; // _IQ(0.5); + uf_alg.winding_displacement_bs1 = 0; + +#else + +#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_ZERO) +// 0 град. сдвиг +// svgen_mf1.Alpha = _IQ(0); +// svgen_mf2.Alpha = _IQ(0); +// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; +// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; + + uf_alg.winding_displacement_bs1 = 0; + uf_alg.winding_displacement_bs2 = 0; + +#else + #error "!!!ОШИБКА!!! Не определен SETUP_SDVIG_OBMOTKI в params_motor.h!!!" + + +#endif + +#endif + +#endif + + + + +} + +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(uf_disbalance_uzpt,".fast_run"); +void uf_disbalance_uzpt(_iq Uzad_uf1, unsigned int disable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, + _iq Uzad_max, + _iq *Kplus_out) +{ + _iq pwm_t,delta_U,Uplus,Uminus; + volatile _iq Kplus; + static _iq u1=0,u2=0; + static _iq delta_U_minimal = _IQ (25.0/NORMA_ACP); + + volatile _iq KplusMax; + + +// change_pwm_freq(Fzad_uf); + + + Uplus = U_2;//filter.iqU_2_fast; // тут Uplus берет от U2 т.к. тут знак "-" скорее всего не учитываетЯ где-то + Uminus = U_1;//filter.iqU_1_fast; + + delta_U = Uplus - Uminus; + + if (_IQabs(delta_U) < delta_U_minimal) + delta_U = 0; + + if (disable_alg_u_disbalance==0) + { + if (kplus_u_disbalance!=0) // если мы задали извне, то его и используем, это для теста. + { + Kplus = kplus_u_disbalance; + } + else + { + if (delta_U != 0) + { + Kplus = _IQmpy(k_u_disbalance, _IQmpy(Uzad_uf1, (_IQdiv( (Uplus-Uminus), (Uplus+Uminus) )) ) );//CONST_1 + _IQmpy(k_u_disbalance, _IQmpy(Uzad_uf1, ( _IQdiv(_IQmpy(CONST_2,Uplus),(Uplus+Uminus)) - CONST_1 ) ) ); + } + else + { + Kplus = 0; + } + } + } + else + { +// Uplus = 0; +// Uminus = 0; +// delta_U = 0; + Kplus = 0; + } + + KplusMax = _IQmpy(Uzad_uf1,CONST_IQ_05); + + if (Kplus>=KplusMax) + { + Kplus = KplusMax; + } + + if (Kplus<=-KplusMax) + { + Kplus = -KplusMax; + } + + + *Kplus_out = Kplus; + + +} +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////// + + + + +//////////////////////////////////////////////////////////////////////////// +// kplus_u_disbalance должен быть равен = 0, если не ноль, то это тест +// enable_alg_u_disbalance - разрешить работу алгоритма разбаланса +// k_u_disbalance - коэф. силы алгоритма разбаланса. +//////////////////////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(uf_const_f_24_Ing,".fast_run"); +void uf_const_f_24_Ing(_iq Fzad_uf1,_iq Fzad_uf2,_iq Uzad_uf1, _iq Uzad_uf2, + unsigned int enable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, unsigned int flag_km_0, + _iq Uzad_max, + _iq *Kplus_out) +{ + + _iq pwm_t,delta_U,Uplus,Uminus; + _iq Kplus; + static _iq u1=0,u2=0; + + volatile _iq KplusMax; + + + uf_disbalance_uzpt(Uzad_uf1, enable_alg_u_disbalance, kplus_u_disbalance, k_u_disbalance, U_1, U_2, Uzad_max, &Kplus); +// change_pwm_freq(Fzad_uf); + + *Kplus_out = Kplus; + + +///////////////////////////////////////// + svgen_mf1.Gain = _IQsat(Uzad_uf1,Uzad_max,0); // Pass inputs to svgen_mf1 + svgen_mf1.Freq = Fzad_uf1; // Pass inputs to svgen_mf1 + +// svgen_mf2.Gain = _IQsat(Uzad_uf2,Uzad_max,0);; // Pass inputs to svgen_mf1 +// svgen_mf2.Freq = Fzad_uf2; // Pass inputs to svgen_mf1 + + svgen_mf1.calc(&svgen_mf1); // Call compute function for svgen_mf1 + // svgen_mf2.calc(&svgen_mf2); // Call compute function for svgen_mf2 + ///////////////////////////////////////// + + + + + + + + + /* + logpar.log1 = (int16)(_IQtoIQ15(Uzad_uf1)); + logpar.log2 = (int16)(_IQtoIQ15(Fzad_uf1)); + logpar.log3 = (int16)((svgen_pwm24_1.Ta_0)); + logpar.log4 = (int16)((svgen_pwm24_1.Ta_1)); + logpar.log5 = (int16)(_IQtoIQ15(svgen_mf1.Ta)); + logpar.log6 = (int16)(_IQtoIQ15(_IQdiv(Kplus,CONST_IQ_10))); + logpar.log7 = (int16)(_IQtoIQ15(_IQdiv(Kminus,CONST_IQ_10))); + logpar.log8 = (int16)(_IQtoIQ15(Uplus)); + logpar.log9 = (int16)(_IQtoIQ15(Uminus)); + +*/ +// 1 +// a + pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Ta, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Ta_0, &svgen_pwm24_1.Ta_1, &svgen_pwm24_1.Ta_imp, pwm_t); +// b + pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Tb, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Tb_0, &svgen_pwm24_1.Tb_1, &svgen_pwm24_1.Tb_imp,pwm_t); +// c + pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Tc, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Tc_0, &svgen_pwm24_1.Tc_1, &svgen_pwm24_1.Tc_imp,pwm_t); + +// 2 + svgen_pwm24_2.Ta_0 = svgen_pwm24_1.Ta_0; + svgen_pwm24_2.Ta_1 = svgen_pwm24_1.Ta_1; + svgen_pwm24_2.Tb_0 = svgen_pwm24_1.Tb_0; + svgen_pwm24_2.Tb_1 = svgen_pwm24_1.Tb_1; + svgen_pwm24_2.Tc_0 = svgen_pwm24_1.Tc_0; + svgen_pwm24_2.Tc_1 = svgen_pwm24_1.Tc_1; + +// a +// pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Ta, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Ta_0, &svgen_pwm24_2.Ta_1, &svgen_pwm24_2.Ta_imp,pwm_t); +//// b +// pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Tb, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Tb_0, &svgen_pwm24_2.Tb_1, &svgen_pwm24_2.Tb_imp,pwm_t); +//// c2 +// pwm_t = correct_balance_uzpt_pwm24 (svgen_mf1.Tc, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Tc_0, &svgen_pwm24_2.Tc_1, &svgen_pwm24_2.Tc_imp,pwm_t); +// + +//// + if (flag_km_0) + { + svgen_pwm24_1.prev_level = V_PWM24_PREV_PWM_WORK_KM0; + svgen_pwm24_2.prev_level = V_PWM24_PREV_PWM_WORK_KM0; + } + else + { + svgen_pwm24_1.prev_level = V_PWM24_PREV_PWM_WORK; + svgen_pwm24_2.prev_level = V_PWM24_PREV_PWM_WORK; + } + + + +///////// +///////// + +// logpar.log10 = (int16)((svgen_pwm24_1.Ta_0)); +// logpar.log11 = (int16)((svgen_pwm24_1.Ta_1)); + + + +} + + +//////////////////////////////////////////////////////////// +#pragma CODE_SECTION(test_calc_simple_dq_pwm24_Ing,".v_24pwm_run"); +void test_calc_simple_dq_pwm24_Ing(_iq Fzad_uf1, + _iq Uzad_uf1, + unsigned int disable_alg_u_disbalance, + _iq kplus_u_disbalance, + _iq k_u_disbalance, + _iq U_1, + _iq U_2, + unsigned int flag_km_0, + _iq Uzad_max, + _iq master_tetta, + _iq master_Uzad_uf1, + unsigned int master, + unsigned int n_bs, + _iq *Kplus_out, + _iq *tetta_out, + _iq *Uzad_out +) +{ +// static _iq hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / FREQ_PWM / 2.0); +// static _iq tetta = 0; + _iq pwm_t; + _iq Kplus; + _iq Ud = 0; + _iq Uq = 0; + _iq add_tetta = 0; + + DQ_TO_ALPHABETA dq_to_ab = DQ_TO_ALPHABETA_DEFAULTS; + + //////////////////////////////////////// + + uf_disbalance_uzpt(Uzad_uf1, disable_alg_u_disbalance, kplus_u_disbalance, k_u_disbalance, + U_1, U_2, + Uzad_max, + &Kplus); + + + //////////////////////////////////////// + + + //////////////////////////////////////// + //////////////////////////////////////// + if (master==MODE_MASTER) + { + // мы master + add_tetta = _IQmpy(Fzad_uf1, uf_alg.hz_to_angle); + uf_alg.tetta += add_tetta; + Ud = 0; + Uq = _IQsat(Uzad_uf1,Uzad_max,0); + } + else + if (master==MODE_SLAVE) + { + // мы slave + add_tetta = 0; + uf_alg.tetta = master_tetta; + Ud = 0; + Uq = _IQsat(master_Uzad_uf1,Uzad_max,0); + } + else + { + // мы непонятно кто! + Ud = 0; + Uq = 0; + add_tetta = 0; + uf_alg.tetta = 0; + } + //////////////////////////////////////// + //////////////////////////////////////// + + + + uf_alg.Ud = Ud; + uf_alg.Uq = Uq; + + if (uf_alg.tetta > CONST_IQ_2PI) + { + uf_alg.tetta -= CONST_IQ_2PI; + } + + if (uf_alg.tetta < 0) + { + uf_alg.tetta += CONST_IQ_2PI; + } + + if (n_bs==0) + uf_alg.tetta_bs = uf_alg.tetta + uf_alg.winding_displacement_bs1; + else + uf_alg.tetta_bs = uf_alg.tetta + uf_alg.winding_displacement_bs2; + + dq_to_ab.Tetta = uf_alg.tetta_bs; + //////////////////////////////////////// + //////////////////////////////////////// + + dq_to_ab.Ud = Ud; + dq_to_ab.Uq = Uq; + dq_to_ab.calc2(&dq_to_ab); + + svgen_dq_1.Ualpha = dq_to_ab.Ualpha; + svgen_dq_1.Ubeta = dq_to_ab.Ubeta; + //////////////////////////////////////// + + uf_alg.Ualpha = dq_to_ab.Ualpha; + uf_alg.Ubeta = dq_to_ab.Ubeta; + //////////////////////////////////////// + + +// svgen_dq_1.Ualpha = 0; +// svgen_dq_1.Ubeta = 0; + + svgen_dq_1.calc(&svgen_dq_1); + + uf_alg.svgen_dq_Ta = svgen_dq_1.Ta; + uf_alg.svgen_dq_Tb = svgen_dq_1.Tb; + uf_alg.svgen_dq_Tc = svgen_dq_1.Tc; + //////////////////////////////////////// + + +// dq_to_ab.Tetta = uf_alg.tetta; +// dq_to_ab.Ud = Ud; +// dq_to_ab.Uq = Uq; +// dq_to_ab.calc2(&dq_to_ab); +// +// svgen_dq_2.Ualpha = dq_to_ab.Ualpha; +// svgen_dq_2.Ubeta = dq_to_ab.Ubeta; +// +// svgen_dq_2.calc(&svgen_dq_2); + +// 1 +// a + pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Ta, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Ta_0, &svgen_pwm24_1.Ta_1, &svgen_pwm24_1.Ta_imp, pwm_t); +// b + pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Tb, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Tb_0, &svgen_pwm24_1.Tb_1, &svgen_pwm24_1.Tb_imp,pwm_t); +// c + pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Tc, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_1, &svgen_pwm24_1.Tc_0, &svgen_pwm24_1.Tc_1, &svgen_pwm24_1.Tc_imp,pwm_t); + +// 2 аналогично 1 т.к. тут парал. работа в Ingeteam + svgen_pwm24_2.Ta_0 = svgen_pwm24_1.Ta_0; + svgen_pwm24_2.Ta_1 = svgen_pwm24_1.Ta_1; + svgen_pwm24_2.Tb_0 = svgen_pwm24_1.Tb_0; + svgen_pwm24_2.Tb_1 = svgen_pwm24_1.Tb_1; + svgen_pwm24_2.Tc_0 = svgen_pwm24_1.Tc_0; + svgen_pwm24_2.Tc_1 = svgen_pwm24_1.Tc_1; + +// +//// a +// pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Ta, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Ta_0, &svgen_pwm24_2.Ta_1, &svgen_pwm24_2.Ta_imp,pwm_t); +//// b +// pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Tb, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Tb_0, &svgen_pwm24_2.Tb_1, &svgen_pwm24_2.Tb_imp,pwm_t); +//// c2 +// pwm_t = correct_balance_uzpt_pwm24 (svgen_dq_1.Tc, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24 (&svgen_pwm24_2, &svgen_pwm24_2.Tc_0, &svgen_pwm24_2.Tc_1, &svgen_pwm24_2.Tc_imp,pwm_t); + + //////////////////////////////////////// + //////////////////////////////////////// + +//// + if (flag_km_0) + { + svgen_pwm24_1.prev_level = V_PWM24_PREV_PWM_WORK_KM0; + svgen_pwm24_2.prev_level = V_PWM24_PREV_PWM_WORK_KM0; + } + else + { + svgen_pwm24_1.prev_level = V_PWM24_PREV_PWM_WORK; + svgen_pwm24_2.prev_level = V_PWM24_PREV_PWM_WORK; + } + + //////////////////////////////////////// + //////////////////////////////////////// + + +// logpar.log1 = (int16)(_IQtoIQ15(uz1)); +// logpar.log2 = (int16)(_IQtoIQ15(fz1)); +// logpar.log3 = (int16)(_IQtoIQ15(Ud)); +// logpar.log4 = (int16)(_IQtoIQ15(Uq)); +// logpar.log5 = (int16)(_IQtoIQ15(svgen_dq_1.Ualpha)); +// logpar.log6 = (int16)(_IQtoIQ15(svgen_dq_1.Ubeta)); +// logpar.log7 = (int16)(_IQtoIQ15(svgen_dq_1.Ta)); +// logpar.log8 = (int16)(_IQtoIQ15(svgen_dq_1.Tb)); +// logpar.log9 = (int16)(_IQtoIQ15(svgen_dq_1.Tc)); +// logpar.log10 = (int16)(_IQtoIQ12(analog.tetta)); +// logpar.log11 = (int16)(svgen_pwm24_1.Ta_0.Ti); +// logpar.log12 = (int16)((svgen_pwm24_1.Ta_1.Ti)); +// logpar.log13 = (int16)(svgen_pwm24_1.Tb_0.Ti); +// logpar.log14 = (int16)((svgen_pwm24_1.Tb_1.Ti)); +// logpar.log15 = (int16)(svgen_pwm24_1.Tc_0.Ti); +// logpar.log16 = (int16)((svgen_pwm24_1.Tc_1.Ti)); + + +// svgen_pwm24_1.calc(&svgen_pwm24_1); +// svgen_pwm24_2.calc(&svgen_pwm24_2); + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +// set_predel_dshim24_simple0(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// +// set_predel_dshim24_simple0(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// +// set_predel_dshim24_simple0(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// +// set_predel_dshim24_simple0(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// +// set_predel_dshim24_simple0(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// +// set_predel_dshim24_simple0(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); +// set_predel_dshim24_simple1(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); + + + *Uzad_out = Uq; + + if (master==MODE_MASTER) + *tetta_out = uf_alg.tetta + add_tetta; // еще сдвигаемся, т.к. в slave придет с задержкой на один такт шима или на два? + else + *tetta_out = uf_alg.tetta; + + *Kplus_out = Kplus; + +} + +#pragma CODE_SECTION(test_calc_vect_dq_pwm24_Ing,".v_24pwm_run"); +void test_calc_vect_dq_pwm24_Ing(_iq Theta_zad,_iq Ud_zad, _iq Uq_zad, + unsigned int disable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, unsigned int flag_km_0, + _iq Uzad_max, + unsigned int master, + unsigned int n_bs, + _iq *Kplus_out, + _iq *Uzad_out ) +{ + _iq Kplus; + _iq Ud = 0; + _iq Uq = 0; + _iq Umod = 0; + _iq pwm_t; + + DQ_TO_ALPHABETA dq_to_ab = DQ_TO_ALPHABETA_DEFAULTS; + + static _iq max_Km = _IQ(MAX_ZADANIE_K_M); + static _iq max_Km_square = _IQ(MAX_ZADANIE_K_M * MAX_ZADANIE_K_M); + + //////////////////////////////////////// + Umod = _IQsqrt(_IQmpy(Ud_zad, Ud_zad) + _IQmpy(Uq_zad, Uq_zad)); + if (Umod > max_Km) { + Uq_zad = _IQsqrt(max_Km_square - _IQmpy(Ud_zad, Ud_zad)); + } + Umod = _IQsqrt(_IQmpy(Ud_zad, Ud_zad) + _IQmpy(Uq_zad, Uq_zad)); + + uf_disbalance_uzpt(Umod, disable_alg_u_disbalance, kplus_u_disbalance, + k_u_disbalance, U_1, U_2, Uzad_max, &Kplus); + *Kplus_out = Kplus; + + *Uzad_out = Umod; + //////////////////////////////////////// + //////////////////////////////////////// + if (master == MODE_MASTER) + { + // мы master + uf_alg.tetta = Theta_zad; + Ud = Ud_zad; + Uq = Uq_zad; //_IQsat(Uzad_uf1,Uzad_max,0); + } + else if (master == MODE_SLAVE) + { + // мы slave + uf_alg.tetta = Theta_zad; + Ud = Ud_zad; + Uq = Uq_zad; //_IQsat(master_Uzad_uf1,Uzad_max,0); + } + else + { + // мы непонятно кто! + Ud = 0; + Uq = 0; + uf_alg.tetta = 0; + } + //////////////////////////////////////// + //////////////////////////////////////// + + uf_alg.Ud = Ud; + uf_alg.Uq = Uq; + + if (uf_alg.tetta > CONST_IQ_2PI) + { + uf_alg.tetta -= CONST_IQ_2PI; + } + + if (uf_alg.tetta < 0) + { + uf_alg.tetta += CONST_IQ_2PI; + } + + if (n_bs == 0) + uf_alg.tetta_bs = uf_alg.tetta + uf_alg.winding_displacement_bs1; + else + uf_alg.tetta_bs = uf_alg.tetta + uf_alg.winding_displacement_bs2; + + dq_to_ab.Tetta = uf_alg.tetta_bs; + dq_to_ab.Ud = Ud; + dq_to_ab.Uq = Uq; + dq_to_ab.calc2(&dq_to_ab); + + svgen_dq_1.Ualpha = dq_to_ab.Ualpha; + svgen_dq_1.Ubeta = dq_to_ab.Ubeta; + //////////////////////////////////////// + + uf_alg.Ualpha = dq_to_ab.Ualpha; + uf_alg.Ubeta = dq_to_ab.Ubeta; + + svgen_dq_1.calc(&svgen_dq_1); + + uf_alg.svgen_dq_Ta = svgen_dq_1.Ta; + uf_alg.svgen_dq_Tb = svgen_dq_1.Tb; + uf_alg.svgen_dq_Tc = svgen_dq_1.Tc; + +// 1 +// a + pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Ta, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_1, &svgen_pwm24_1.Ta_0, + &svgen_pwm24_1.Ta_1, + &svgen_pwm24_1.Ta_imp, pwm_t); +// b + pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Tb, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_1, &svgen_pwm24_1.Tb_0, + &svgen_pwm24_1.Tb_1, + &svgen_pwm24_1.Tb_imp, pwm_t); +// c + pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Tc, Kplus); + recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_1, &svgen_pwm24_1.Tc_0, + &svgen_pwm24_1.Tc_1, + &svgen_pwm24_1.Tc_imp, pwm_t); + +// 2 аналогично 1 т.к. тут парал. работа в Ingeteam + + svgen_pwm24_2.Ta_0 = svgen_pwm24_1.Ta_0; + svgen_pwm24_2.Ta_1 = svgen_pwm24_1.Ta_1; + svgen_pwm24_2.Tb_0 = svgen_pwm24_1.Tb_0; + svgen_pwm24_2.Tb_1 = svgen_pwm24_1.Tb_1; + svgen_pwm24_2.Tc_0 = svgen_pwm24_1.Tc_0; + svgen_pwm24_2.Tc_1 = svgen_pwm24_1.Tc_1; + + + +//// a +// pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Ta, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_2, &svgen_pwm24_2.Ta_0, +// &svgen_pwm24_2.Ta_1, +// &svgen_pwm24_2.Ta_imp, pwm_t); +//// b +// pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Tb, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_2, &svgen_pwm24_2.Tb_0, +// &svgen_pwm24_2.Tb_1, +// &svgen_pwm24_2.Tb_imp, pwm_t); +//// c2 +// pwm_t = correct_balance_uzpt_pwm24(svgen_dq_1.Tc, Kplus); +// recalc_time_pwm_minimal_2_xilinx_pwm24(&svgen_pwm24_2, &svgen_pwm24_2.Tc_0, +// &svgen_pwm24_2.Tc_1, +// &svgen_pwm24_2.Tc_imp, pwm_t); + + //////////////////////////////////////// + //////////////////////////////////////// + + +} + + + diff --git a/Inu/Src2/N12_Libs/uf_alg_ing.h b/Inu/Src2/N12_Libs/uf_alg_ing.h new file mode 100644 index 0000000..209d9ce --- /dev/null +++ b/Inu/Src2/N12_Libs/uf_alg_ing.h @@ -0,0 +1,93 @@ +/* + * uf_alg.h + * + * Created on: 10 февр. 2020 г. + * Author: yura + */ + +#ifndef _UF_ALG_ING_H_ +#define _UF_ALG_ING_H_ + +#include "svgen_mf.h" + + +#define CONST_IQ_05 8388608 //0.5 +#define CONST_IQ_1 16777216 //1.0 + + + +/* ГлобальнаЯ структура UF ALG */ +typedef struct +{ + + _iq tetta; + _iq tetta_bs; + + + _iq winding_displacement_bs1; + _iq winding_displacement_bs2; + + _iq hz_to_angle; + _iq Kplus; + + _iq Ud; + _iq Uq; + + _iq Ualpha; + _iq Ubeta; + + _iq svgen_dq_Ta; + _iq svgen_dq_Tb; + _iq svgen_dq_Tc; + + +} UF_ALG_VALUE; + + + + +#define UF_ALG_VALUE_DEFAULT {0,0,0,0,0,0,0,0,0,0,0,0,0} + + + +extern UF_ALG_VALUE uf_alg ; + +extern SVGENMF svgen_mf1; +extern SVGENMF svgen_mf2; + + +//void uf_const_f(_iq Fzad_uf1,_iq Fzad_uf2,_iq Uzad_uf1, _iq Uzad_uf2, int Revers,unsigned int enable_alg_u_disbalance); + +void uf_const_f_24_Ing(_iq Fzad_uf1,_iq Fzad_uf2,_iq Uzad_uf1, _iq Uzad_uf2, unsigned int enable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, unsigned int flag_km_0, + _iq Uzad_max, + _iq *Kplus_out); + +void uf_disbalance_uzpt(_iq Uzad_uf1, unsigned int disable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, + _iq Uzad_max, + _iq *Kplus_out); + +void init_alpha_Ing(unsigned int bs); +void InitVariablesSvgen_Ing(unsigned int freq); +void test_calc_simple_dq_pwm24_Ing(_iq Fzad_uf1,_iq Uzad_uf1, unsigned int disable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, unsigned int flag_km_0, + _iq Uzad_max, + _iq master_tetta, + _iq master_Uzad_uf1, + unsigned int master, + unsigned int n_bs, + _iq *Kplus_out, + _iq *tetta_out, + _iq *Uzad_out); + +void test_calc_vect_dq_pwm24_Ing(_iq Theta_zad,_iq Ud_zad, _iq Uq_zad, + unsigned int disable_alg_u_disbalance, _iq kplus_u_disbalance, _iq k_u_disbalance, + _iq U_1, _iq U_2, unsigned int flag_km_0, + _iq Uzad_max, + unsigned int master, + unsigned int n_bs, + _iq *Kplus_out, + _iq *Uzad_out); + +#endif /* _UF_ALG_H_ */ diff --git a/Inu/Src2/N12_Libs/vhzprof.c b/Inu/Src2/N12_Libs/vhzprof.c new file mode 100644 index 0000000..ba76a40 --- /dev/null +++ b/Inu/Src2/N12_Libs/vhzprof.c @@ -0,0 +1,45 @@ +/*===================================================================================== + File name: VHZPROF.C (IQ version) + + Originator: Digital Control Systems Group + Texas Instruments + + Description: V/f Profile for Scalar Control of Induction Motor + +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +-------------------------------------------------------------------------------------*/ +#include "IQmathLib.h" // Include header for IQmath library + +#include "vhzprof.h" + +#include "math.h" // Include math libs + +#include "dmctype.h" +//#include + +void vhz_prof_calc(VHZPROF *v) +{ + _iq VfSlope, AbsFreq; + +// Take absolute frequency to allow the operation of both rotational directions + AbsFreq = labs(v->Freq); + + if (AbsFreq <= v->LowFreq) + // Compute output voltage in profile #1 + v->VoltOut = v->VoltMin; + else if ((AbsFreq > v->LowFreq)&(AbsFreq <= v->HighFreq)) + { + // Compute slope of V/f profile + VfSlope = _IQdiv((v->VoltMax - v->VoltMin),(v->HighFreq - v->LowFreq)); + // Compute output voltage in profile #2 + v->VoltOut = v->VoltMin + _IQmpy(VfSlope,(AbsFreq-v->LowFreq)); + } + else if ((AbsFreq > v->HighFreq)&(AbsFreq < v->FreqMax)) + // Compute output voltage in profile #3 + v->VoltOut = v->VoltMax; +} + + diff --git a/Inu/Src2/N12_Libs/vhzprof.h b/Inu/Src2/N12_Libs/vhzprof.h new file mode 100644 index 0000000..a1326df --- /dev/null +++ b/Inu/Src2/N12_Libs/vhzprof.h @@ -0,0 +1,41 @@ +/* ================================================================================= +File name: VHZ_PROF.H (IQ version) + +Originator: Digital Control Systems Group + Texas Instruments + +Description: +Header file containing constants, data type definitions, and +function prototypes for the VHZPROF. +===================================================================================== + History: +------------------------------------------------------------------------------------- + 04-15-2005 Version 3.20 +------------------------------------------------------------------------------*/ +#ifndef __VHZ_PROF_H__ +#define __VHZ_PROF_H__ + +typedef struct { _iq Freq; // Input: Input Frequency (pu) + _iq VoltOut; // Output: Output voltage (pu) + _iq LowFreq; // Parameter: Low Frequency (pu) + _iq HighFreq; // Parameter: High Frequency at rated voltage (pu) + _iq FreqMax; // Parameter: Maximum Frequency (pu) + _iq VoltMax; // Parameter: Rated voltage (pu) + _iq VoltMin; // Parameter: Voltage at low Frequency range (pu) + void (*calc)(); // Pointer to calculation function + } VHZPROF; + +typedef VHZPROF *VHZPROF_handle; +/*----------------------------------------------------------------------------- +Default initalizer for the VHZPROF object. +-----------------------------------------------------------------------------*/ +#define VHZPROF_DEFAULTS { 0,0, \ + 0,0,0,0,0, \ + (void (*)(Uint32))vhz_prof_calc } + +/*------------------------------------------------------------------------------ +Prototypes for the functions in VHZ_PROF.C +------------------------------------------------------------------------------*/ +void vhz_prof_calc(VHZPROF_handle); + +#endif // __VHZ_PROF_H__ diff --git a/Inu/Src2/main/word_structurs.h b/Inu/Src2/N12_Libs/word_structurs.h similarity index 93% rename from Inu/Src2/main/word_structurs.h rename to Inu/Src2/N12_Libs/word_structurs.h index d94d243..7d67dfa 100644 --- a/Inu/Src2/main/word_structurs.h +++ b/Inu/Src2/N12_Libs/word_structurs.h @@ -5,8 +5,8 @@ * Author: Yura */ -#ifndef SRC_MYLIBS_WORD_STRUCTURS_H_ -#define SRC_MYLIBS_WORD_STRUCTURS_H_ +#ifndef SRC_LIBS_NIO12_WORD_STRUCTURS_H_ +#define SRC_LIBS_NIO12_WORD_STRUCTURS_H_ //////////////////////////////////////////////////////////////////////////////// typedef union @@ -61,4 +61,4 @@ typedef union -#endif /* SRC_MYLIBS_WORD_STRUCTURS_H_ */ +#endif /* SRC_LIBS_NIO12_WORD_STRUCTURS_H_ */ diff --git a/Inu/Src2/551/VectorControl/abc_to_alphabeta.c b/Inu/Src2/N12_VectorControl/abc_to_alphabeta.c similarity index 100% rename from Inu/Src2/551/VectorControl/abc_to_alphabeta.c rename to Inu/Src2/N12_VectorControl/abc_to_alphabeta.c diff --git a/Inu/Src2/551/VectorControl/abc_to_alphabeta.h b/Inu/Src2/N12_VectorControl/abc_to_alphabeta.h similarity index 100% rename from Inu/Src2/551/VectorControl/abc_to_alphabeta.h rename to Inu/Src2/N12_VectorControl/abc_to_alphabeta.h diff --git a/Inu/Src2/551/VectorControl/abc_to_dq.c b/Inu/Src2/N12_VectorControl/abc_to_dq.c similarity index 100% rename from Inu/Src2/551/VectorControl/abc_to_dq.c rename to Inu/Src2/N12_VectorControl/abc_to_dq.c diff --git a/Inu/Src2/551/VectorControl/abc_to_dq.h b/Inu/Src2/N12_VectorControl/abc_to_dq.h similarity index 100% rename from Inu/Src2/551/VectorControl/abc_to_dq.h rename to Inu/Src2/N12_VectorControl/abc_to_dq.h diff --git a/Inu/Src2/551/VectorControl/alg_pll.c b/Inu/Src2/N12_VectorControl/alg_pll.c similarity index 100% rename from Inu/Src2/551/VectorControl/alg_pll.c rename to Inu/Src2/N12_VectorControl/alg_pll.c diff --git a/Inu/Src2/551/VectorControl/alg_pll.h b/Inu/Src2/N12_VectorControl/alg_pll.h similarity index 100% rename from Inu/Src2/551/VectorControl/alg_pll.h rename to Inu/Src2/N12_VectorControl/alg_pll.h diff --git a/Inu/Src2/551/VectorControl/alphabeta_to_dq.c b/Inu/Src2/N12_VectorControl/alphabeta_to_dq.c similarity index 100% rename from Inu/Src2/551/VectorControl/alphabeta_to_dq.c rename to Inu/Src2/N12_VectorControl/alphabeta_to_dq.c diff --git a/Inu/Src2/551/VectorControl/alphabeta_to_dq.h b/Inu/Src2/N12_VectorControl/alphabeta_to_dq.h similarity index 100% rename from Inu/Src2/551/VectorControl/alphabeta_to_dq.h rename to Inu/Src2/N12_VectorControl/alphabeta_to_dq.h diff --git a/Inu/Src2/551/VectorControl/dq_to_alphabeta_cos.c b/Inu/Src2/N12_VectorControl/dq_to_alphabeta_cos.c similarity index 100% rename from Inu/Src2/551/VectorControl/dq_to_alphabeta_cos.c rename to Inu/Src2/N12_VectorControl/dq_to_alphabeta_cos.c diff --git a/Inu/Src2/551/VectorControl/dq_to_alphabeta_cos.h b/Inu/Src2/N12_VectorControl/dq_to_alphabeta_cos.h similarity index 100% rename from Inu/Src2/551/VectorControl/dq_to_alphabeta_cos.h rename to Inu/Src2/N12_VectorControl/dq_to_alphabeta_cos.h diff --git a/Inu/Src2/551/VectorControl/params_pll.h b/Inu/Src2/N12_VectorControl/params_pll.h similarity index 100% rename from Inu/Src2/551/VectorControl/params_pll.h rename to Inu/Src2/N12_VectorControl/params_pll.h diff --git a/Inu/Src2/551/VectorControl/regul_power.c b/Inu/Src2/N12_VectorControl/regul_power.c similarity index 100% rename from Inu/Src2/551/VectorControl/regul_power.c rename to Inu/Src2/N12_VectorControl/regul_power.c diff --git a/Inu/Src2/551/VectorControl/regul_power.h b/Inu/Src2/N12_VectorControl/regul_power.h similarity index 100% rename from Inu/Src2/551/VectorControl/regul_power.h rename to Inu/Src2/N12_VectorControl/regul_power.h diff --git a/Inu/Src2/551/VectorControl/regul_turns.c b/Inu/Src2/N12_VectorControl/regul_turns.c similarity index 100% rename from Inu/Src2/551/VectorControl/regul_turns.c rename to Inu/Src2/N12_VectorControl/regul_turns.c diff --git a/Inu/Src2/551/VectorControl/regul_turns.h b/Inu/Src2/N12_VectorControl/regul_turns.h similarity index 100% rename from Inu/Src2/551/VectorControl/regul_turns.h rename to Inu/Src2/N12_VectorControl/regul_turns.h diff --git a/Inu/Src2/551/VectorControl/smooth.c b/Inu/Src2/N12_VectorControl/smooth.c similarity index 100% rename from Inu/Src2/551/VectorControl/smooth.c rename to Inu/Src2/N12_VectorControl/smooth.c diff --git a/Inu/Src2/551/VectorControl/smooth.h b/Inu/Src2/N12_VectorControl/smooth.h similarity index 100% rename from Inu/Src2/551/VectorControl/smooth.h rename to Inu/Src2/N12_VectorControl/smooth.h diff --git a/Inu/Src2/551/VectorControl/teta_calc.c b/Inu/Src2/N12_VectorControl/teta_calc.c similarity index 100% rename from Inu/Src2/551/VectorControl/teta_calc.c rename to Inu/Src2/N12_VectorControl/teta_calc.c diff --git a/Inu/Src2/551/VectorControl/teta_calc.h b/Inu/Src2/N12_VectorControl/teta_calc.h similarity index 100% rename from Inu/Src2/551/VectorControl/teta_calc.h rename to Inu/Src2/N12_VectorControl/teta_calc.h diff --git a/Inu/Src2/551/VectorControl/vector_control.c b/Inu/Src2/N12_VectorControl/vector_control.c similarity index 100% rename from Inu/Src2/551/VectorControl/vector_control.c rename to Inu/Src2/N12_VectorControl/vector_control.c diff --git a/Inu/Src2/551/VectorControl/vector_control.h b/Inu/Src2/N12_VectorControl/vector_control.h similarity index 100% rename from Inu/Src2/551/VectorControl/vector_control.h rename to Inu/Src2/N12_VectorControl/vector_control.h diff --git a/Inu/Src2/N12_Xilinx/CRC_Functions.c b/Inu/Src2/N12_Xilinx/CRC_Functions.c new file mode 100644 index 0000000..3d75514 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/CRC_Functions.c @@ -0,0 +1,143 @@ +#include "CRC_Functions.h" +#pragma DATA_SECTION(crc_16_tab, ".slow_vars") +WORD crc_16_tab[] = { + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, + 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, + 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, + 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, + 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, + 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, + 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, + 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, + 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, + 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, + 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, + 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, + 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, + 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, + 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, + 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, + 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, + 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, + 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, + 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, + 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, + 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, + 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, + 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, + 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, + 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, + 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, + 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040 +}; + +unsigned char GetCRC8_Dallas1_WireReverse(unsigned char *DataArrIn, unsigned int DataLength) +{ + unsigned char i, Data = 0, CRC = 0, CheckBit; + unsigned int ByteCnt = 0; + + do + { + Data = DataArrIn[ByteCnt]; + for(i = 0; i < 8; i++) + { + CheckBit = CRC ^ Data; + CheckBit &= 1; + CRC >>= 1; + Data >>= 1; + if(CheckBit == 1) CRC ^= 0x8C; + } + ByteCnt++; + } + while(ByteCnt < DataLength); + + return CRC; +} + +unsigned char GetCRC8_Dallas1_Wire(unsigned char *DataArrIn, unsigned int DataLength) +{ + unsigned char CRC = 0x00; + unsigned int i; + + while (DataLength--) + { + CRC ^= *(DataArrIn++); + + for (i = 0; i < 8; i++) CRC = (CRC & 0x80 ? (CRC << 1) ^ 0x31 : CRC << 1) & 0x00FF; + } + + return CRC; +} + +unsigned int GetCRC16_IBM(unsigned int crc, unsigned int *buf, unsigned int size) +{ + + while(size--) + { + crc = (crc >> 8) ^ crc_16_tab[ (crc ^ *buf++) & 0xff ]; + crc = crc & 0xffff; + } + + return (crc & 0xffff); +} + + +unsigned int GetCRC16_IBM_v2(unsigned int crc, unsigned int *buf, unsigned int size) +{ + unsigned int xor = 0; + + + while(size--) + { +// crc = (crc >> 8) ^ crc_16_tab[ (crc ^ *buf++) & 0xff ]; +// crc = crc & 0xffff; + + xor = ((*buf++) ^ crc) & 0xff; + crc >>= 8; + crc ^= crc_16_tab[xor]; + } + + return (crc & 0xffff); +} + + +unsigned int GetCRC16_B(unsigned int crc,unsigned int *buf,unsigned long size ) +{ + +unsigned int x, dword, byte; +unsigned long i; + + + + for (i = 0; i < size; i++) + { + x = i % 2; + + dword = buf[i/2]; +// dword = *buf; + + + if (x == 0) + { + byte = ((dword >> 8)&0xFF); + } + + if (x == 1) + { + byte = (dword & 0xFF); + } + + crc = (crc >> 8) ^ crc_16_tab[ (crc ^ (byte) ) & 0xff ]; + crc = crc & 0xffff; + +// crc = crc + ((byte) & 0xff); + + } + + return (crc & 0xffff); +} + diff --git a/Inu/Src2/N12_Xilinx/CRC_Functions.h b/Inu/Src2/N12_Xilinx/CRC_Functions.h new file mode 100644 index 0000000..be01c01 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/CRC_Functions.h @@ -0,0 +1,12 @@ +#ifndef _CRC_FUNCTIONS_H +#define _CRC_FUNCTIONS_H + +typedef unsigned short WORD; + +unsigned int GetCRC16_IBM(unsigned int crc, unsigned int *buf, unsigned int size); +unsigned int GetCRC16_B(unsigned int crc,unsigned int *buf,unsigned long size); +unsigned char GetCRC8_Dallas1_WireReverse(unsigned char *DataArrIn, unsigned int DataLength); +unsigned char GetCRC8_Dallas1_Wire(unsigned char *DataArrIn, unsigned int DataLength); +unsigned int GetCRC16_IBM_v2(unsigned int crc, unsigned int *buf, unsigned int size); + +#endif diff --git a/Inu/Src2/N12_Xilinx/MemoryFunctions.c b/Inu/Src2/N12_Xilinx/MemoryFunctions.c new file mode 100644 index 0000000..69b195c --- /dev/null +++ b/Inu/Src2/N12_Xilinx/MemoryFunctions.c @@ -0,0 +1,325 @@ +#include "MemoryFunctions.h" + + +#define START_ADR_FLASH 0x100000 + +void write_xmemory(unsigned long addr, unsigned int data); +unsigned int flash_read_word(unsigned long adr); +void flash_reset(); + +unsigned char flash_toggle_bit(long adr) +{ + unsigned int dq1,dq2,tog,tim; + unsigned long cicle; + + cicle=0; + dq1 = flash_read_word(adr); + do + { + dq2= flash_read_word(adr); + tog = (dq1 & 0x40) + ( dq2 & 0x40); + if (tog!=0x40) + return 0; + dq1=dq2; + tim=dq2 & 0x20; + cicle++; + } while ((cicle!=26553500) && (tim==0)); + dq1 = flash_read_word(adr); + dq2 = flash_read_word(adr); + tog = (dq1 & 0x40) + ( dq2 & 0x40); + if (tog!=0x40) + return 0; + + flash_reset(); + return 1; + +} + +#pragma CODE_SECTION(ReadMemory,".fast_run"); +unsigned int ReadMemory(unsigned long addr) +{ + return (*(volatile int *)(addr)); +} + +#pragma CODE_SECTION(WriteMemory,".fast_run"); +void WriteMemory(unsigned long addr, unsigned int data) +{ + (*(volatile int *)( addr )) = data; +} + +unsigned char flash_erase_sector(unsigned long adr) +{ + write_xmemory(0x555,0xaa); + write_xmemory(0x2aa,0x55); + write_xmemory(0x555,0x80); + write_xmemory(0x555,0xaa); + write_xmemory(0x2aa,0x55); + write_xmemory(adr,0x30); + + return flash_toggle_bit(adr); +} + +#pragma CODE_SECTION(write_xmemory,".fast_run"); +void write_xmemory(unsigned long addr, unsigned int data) +{ + (*(volatile int *)(START_ADR_FLASH+addr)) = data; +} + +#pragma CODE_SECTION(read_xmemory,".fast_run"); +unsigned int read_xmemory(unsigned long addr) +{ + return (*(volatile int *)(START_ADR_FLASH+addr)); +} + +unsigned int flash_read_word(unsigned long adr) +{ + return read_xmemory(adr); +} + +void flash_reset() +{ + write_xmemory(0,0xf0); +} + +unsigned int flash_write_word(unsigned long adr, unsigned int dat) +{ + unsigned int dq=0xffff; + + if (dat!=dq) + { + write_xmemory(0x555,0xaa ); + write_xmemory(0x2aa,0x55 ); + write_xmemory(0x555,0xa0 ); + write_xmemory(adr,dat); + dq=flash_toggle_bit(adr); + dq=flash_read_word(adr); + } + return (dq==dat); +} + + +unsigned int RunFlashData(unsigned long AdrFrom, unsigned long AdrTo, unsigned long Length, + unsigned int *cerr_out, unsigned int *repl_out, unsigned int *count_ok_out) +{ + + + unsigned long adr_start,adr_end,f_s,f_e; + int i; + static char flash_tab[] = { + 32,32,32,32,32,32,32,32,32,32,32,32,32,32,16,4,4,8 + }; + + unsigned int d1,d2, d3, cerr=0, repl = 0, count_ok = 0; + unsigned long adr_out,adr_in, adr_out_s; + + *cerr_out = 0; + *repl_out = 0; + *count_ok_out = 0; + + + + flash_reset(); + + i=0; + adr_start=AdrTo-START_ADR_FLASH; + adr_end=adr_start+Length; + + + f_s=0; + f_e=0; + + for (i=0;i<16;i++) + { + f_s=f_e; + f_e=f_s+(unsigned long)flash_tab[i]*1024; + + if ( f_s<=adr_start && f_e>adr_start ) flash_erase_sector(f_s); + if ( f_s>adr_start && f_eadr_end ) flash_erase_sector(f_s); + } + + +// i=flash_erase_sector(0x20000); +// i=flash_erase_sector(0x28000); +// i=flash_erase_sector(0x30000); +// i=flash_erase_sector(0x38000); + + + if (i!=0) + { + // error + // delay_loop(); + } + + //check clear flash? + adr_out_s=AdrTo-START_ADR_FLASH; + cerr=0; + adr_in=AdrFrom; + for (adr_out = 0; adr_out < Length; adr_out++) + { + d1=flash_read_word(adr_out+adr_out_s); + if (d1!=0xffff) + { + cerr++; + } + } + + if (cerr) + { + *cerr_out = cerr; + *repl_out = 0; + *count_ok_out = 0; + return RETURN_FLASHED_NOT_CLEAR_1; + } + // end check clear flash + + + // пишем во flash + adr_out_s = AdrTo-START_ADR_FLASH; + cerr = 0; + adr_in = AdrFrom; + + + for (adr_out = 0; adr_out < Length; adr_out++) + { + + d1=flash_read_word(adr_out+adr_out_s); + d3=ReadMemory(adr_in); + adr_in++; + + if (d1==0xffff) // память чистая? + { + + flash_write_word(adr_out+adr_out_s,d3); + + d2=flash_read_word(adr_out+adr_out_s); + + if (d2!=d3) + { + // вторая попытка + repl++; + + if (d2==0xffff) + { + flash_write_word(adr_out+adr_out_s,d3); + d2=flash_read_word(adr_out+adr_out_s); + + if (d2!=d3) + { + cerr++; + + *cerr_out = cerr; + *repl_out = repl; + *count_ok_out = count_ok; + return RETURN_FLASHED_ERROR_AFTER_REPL; + } + else + count_ok++; + } + else + { + // что-то записалось, но с ошибкой, надо бы опять стирать сектор + cerr++; + *cerr_out = cerr; + *repl_out = repl; + *count_ok_out = count_ok; + return RETURN_FLASHED_ERROR_BEFORE_REPL_NOT_CLEAR; + } + + } + else + count_ok++; + + } + else + { + //не стерта почему-то! ошибка! + cerr++; + *cerr_out = cerr; + *repl_out = repl; + *count_ok_out = count_ok; + return RETURN_FLASHED_NOT_CLEAR_2; + } + + } + + *cerr_out = cerr; + *repl_out = repl; + *count_ok_out = count_ok; + + + if (cerr) + return RETURN_FLASHED_ERROR; + + return RETURN_FLASHED_OK; + + + + +} + + + +unsigned int VerifyFlashData(unsigned long AdrFrom, unsigned long AdrTo, unsigned long Length, + unsigned int *cerr_out, unsigned int *repl_out, unsigned int *count_ok_out) +{ + + + unsigned long adr_start,adr_end,f_s,f_e; + int i; + + volatile unsigned int d1,d2, d3, cerr=0, repl = 0, count_ok = 0; + unsigned long adr_out,adr_in, adr_out_s; + + *cerr_out = 0; + *repl_out = 0; + *count_ok_out = 0; + + i=0; + adr_start=AdrTo-START_ADR_FLASH; + adr_end=adr_start+Length; + + + f_s=0; + f_e=0; + + + // test flash + adr_out_s = AdrTo-START_ADR_FLASH; + cerr = 0; + adr_in = AdrFrom; + + + for (adr_out = 0; adr_out < Length; adr_out++) + { + + d1=flash_read_word(adr_out+adr_out_s); + d3=ReadMemory(adr_in); + adr_in++; + + repl++; + + if (d1!=d3) + { + cerr++; + } + else + count_ok++; + + } + + + *cerr_out = cerr; + *repl_out = count_ok; + *count_ok_out = count_ok; + + + if (cerr) + return RETURN_FLASHED_ERROR; + + return RETURN_FLASHED_OK; + +} + + + diff --git a/Inu/Src2/N12_Xilinx/MemoryFunctions.h b/Inu/Src2/N12_Xilinx/MemoryFunctions.h new file mode 100644 index 0000000..365f2d6 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/MemoryFunctions.h @@ -0,0 +1,36 @@ +#ifndef _MEMORY_FUNCTIONS_H +#define _MEMORY_FUNCTIONS_H + + +enum {RETURN_FLASHED_OK=0, + RETURN_FLASHED_NOT_CLEAR_1, + RETURN_FLASHED_NOT_CLEAR_2, + RETURN_FLASHED_ERROR_AFTER_REPL, + RETURN_FLASHED_ERROR_BEFORE_REPL_NOT_CLEAR, + RETURN_FLASHED_ERROR +}; + +//#include "RS_Functions_modbus.h" + +void WriteMemory(unsigned long addr, unsigned int data); +unsigned int ReadMemory(unsigned long addr); + + +//unsigned int RunFlashData(unsigned long AdrFrom,unsigned long AdrTo, unsigned long Length); +unsigned int RunFlashData(unsigned long AdrFrom, unsigned long AdrTo, unsigned long Length, + unsigned int *cerr_out, unsigned int *repl_out, unsigned int *count_ok_out); + +unsigned int VerifyFlashData(unsigned long AdrFrom, unsigned long AdrTo, unsigned long Length, + unsigned int *cerr_out, unsigned int *repl_out, unsigned int *count_ok_out); + + + +#define i_ReadMemory(addr) ReadMemory(addr) +#define i_WriteMemory(addr,data) WriteMemory(addr,data) + + +//#define i_ReadMemory(addr) (*(volatile int *)(addr)) +//#define i_WriteMemory(addr,data) { (*(volatile int *)( addr )) = data; } + + +#endif diff --git a/Inu/Src2/N12_Xilinx/RS_Function_terminal.c b/Inu/Src2/N12_Xilinx/RS_Function_terminal.c new file mode 100644 index 0000000..99f38e5 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_Function_terminal.c @@ -0,0 +1,98 @@ +/* + * RS_Function_terminal.c + * + * Created on: 12 нояб. 2020 г. + * Author: stud + */ + +#include "RS_Function_terminal.h" + +#include +#include + +#include "modbus_table_v2.h" +#include "options_table.h" +#include "DSP281x_Device.h" +#include "CRC_Functions.h" +#include "MemoryFunctions.h" +#include "RS_Functions.h" + + + + + +#pragma DATA_SECTION(reply, ".slow_vars") +TMS_TO_TERMINAL_STRUCT reply = TMS_TO_TERMINAL_STRUCT_DEFAULT; +#pragma DATA_SECTION(reply_test_all, ".slow_vars") +TMS_TO_TERMINAL_TEST_ALL_STRUCT reply_test_all = TMS_TO_TERMINAL_TEST_ALL_STRUCT_DEFAULT; + + + + +void ReceiveCommandTestAll(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int crc; +// int Data,Data1,Data2,Data3, Data4, DataM, tk1,tk2,tk3,tk0,period = 0, periodMiddle = 0, DataAnalog1, DataAnalog2, doubleImpulse, sinusImpulse; +// static unsigned int prevImp; + // const указатель на структуру стандартной команды + CMD_TO_TMS_TEST_ALL_STRUCT* pcommand = (CMD_TO_TMS_TEST_ALL_STRUCT *)(RS232_Arr->RS_Header); + + + + // настроили на буфер приема +// *(TMS_TO_TERMINAL_TEST_ALL_STRUCT*)RS232_Arr->buffer = reply_test_all; /* ?еобходимы легкие приведениy */ + + + // ответ, выводим данные в терминалку + reply_test_all.head.Address = RS232_Arr->addr_recive;//CNTRL_ADDR; + reply_test_all.head.Number = CMD_RS232_TEST_ALL; + + + + func_fill_answer_to_TMS_test(&reply_test_all, pcommand); + + + *(TMS_TO_TERMINAL_TEST_ALL_STRUCT*)RS232_Arr->buffer = reply_test_all; /* Необходимы легкие приведениЯ */ + + crc = 0xffff; + crc = GetCRC16_IBM( crc, RS232_Arr->buffer, sizeof(TMS_TO_TERMINAL_TEST_ALL_STRUCT)-3); + + reply_test_all.crc_lo = LOBYTE(crc); + reply_test_all.crc_hi = HIBYTE(crc); + + // -копируем в буфер длy верности + *(TMS_TO_TERMINAL_TEST_ALL_STRUCT*)RS232_Arr->buffer = reply_test_all; // ?еобходимы легкие приведениy + RS_Send(RS232_Arr,RS232_Arr->buffer, sizeof(TMS_TO_TERMINAL_TEST_ALL_STRUCT)+1); + + return; +} + +void ReceiveCommand(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int crc; + + // const указатель на структуру стандартной команды + // настроили на буфер приема + //CMD_TO_TMS* const pcommand = (CMD_TO_TMS *)(RS232_Arr->RS_Header); + CMD_TO_TMS_STRUCT* pcommand = (CMD_TO_TMS_STRUCT *)(RS232_Arr->RS_Header); + // ответ, выводим данные в терминалку + reply.head.Address = RS232_Arr->addr_recive;//CNTRL_ADDR; + reply.head.Number = CMD_RS232_STD; + +// func_fill_answer_to_TMS(&reply, pcommand); + func_unpack_answer_from_TMS_RS232(pcommand); + func_pack_answer_to_TMS(&reply); + + *(TMS_TO_TERMINAL_STRUCT*)RS232_Arr->buffer = reply; // Необходимы легкие приведениy + + crc = 0xffff; + crc = GetCRC16_IBM( crc, RS232_Arr->buffer, sizeof(TMS_TO_TERMINAL_STRUCT)-3); + + reply.crc_lo = LOBYTE(crc); + reply.crc_hi = HIBYTE(crc); + + // Скопируем в буфер длy верности + *(TMS_TO_TERMINAL_STRUCT*)RS232_Arr->buffer = reply; // Необходимы легкие приведениy + RS_Send(RS232_Arr,RS232_Arr->buffer, sizeof(TMS_TO_TERMINAL_STRUCT)+1); + return; +} diff --git a/Inu/Src2/N12_Xilinx/RS_Function_terminal.h b/Inu/Src2/N12_Xilinx/RS_Function_terminal.h new file mode 100644 index 0000000..13c9485 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_Function_terminal.h @@ -0,0 +1,605 @@ +/* + * RS_Function_terminal.h + * + * Created on: 12 нояб. 2020 г. + * Author: stud + */ + +#ifndef SRC_XILINX_NIO12_RS_FUNCTION_TERMINAL_H_ +#define SRC_XILINX_NIO12_RS_FUNCTION_TERMINAL_H_ + +#include "RS_Functions.h" + + +typedef struct +{ + CHAR analog1_lo; // младший байт заданной скорости + CHAR analog1_hi; // старший байт заданной скорости + CHAR analog2_lo; // младший байт заданной скорости + CHAR analog2_hi; // старший байт заданной скорости + CHAR analog3_lo; // младший байт заданной скорости + CHAR analog3_hi; // старший байт заданной скорости + //Добавлено длЯ Ледокола + CHAR analog4_lo; // младший байт заданной скорости + CHAR analog4_hi; // старший байт заданной скорости + CHAR analog5_lo; // младший байт заданной скорости + CHAR analog5_hi; // старший байт заданной скорости + CHAR analog6_lo; // младший байт заданной скорости + CHAR analog6_hi; // старший байт заданной скорости + +// + CHAR analog7_lo; // младший байт заданной скорости + CHAR analog7_hi; // старший байт заданной скорости + CHAR analog8_lo; // младший байт заданной скорости + CHAR analog8_hi; // старший байт заданной скорости + CHAR analog9_lo; // младший байт заданной скорости + CHAR analog9_hi; // старший байт заданной скорости + CHAR analog10_lo; // младший байт заданной скорости + CHAR analog10_hi; // старший байт заданной скорости + CHAR analog11_lo; // младший байт заданной скорости + CHAR analog11_hi; // старший байт заданной скорости + CHAR analog12_lo; // младший байт заданной скорости + CHAR analog12_hi; // старший байт заданной скорости + CHAR analog13_lo; // младший байт заданной скорости + CHAR analog13_hi; // старший байт заданной скорости + CHAR analog14_lo; // младший байт заданной скорости + CHAR analog14_hi; // старший байт заданной скорости + CHAR analog15_lo; // младший байт заданной скорости + CHAR analog15_hi; // старший байт заданной скорости + + +} CMD_ANALOG_DATA_STRUCT; + +typedef union +{ + struct + { + unsigned int bit0: 1; + unsigned int bit1: 1; + unsigned int bit2: 1; + unsigned int bit3: 1; + unsigned int bit4: 1; + unsigned int bit5: 1; + unsigned int bit6: 1; + unsigned int bit7: 1; + } bit_data; // Дискретные величины посылки побитно + CHAR byte_data; // Дискретные величины посылки вместе +} CMD_DIGIT_BYTE_STRUCT; // Дискретные величины + +typedef struct +{ + CMD_DIGIT_BYTE_STRUCT Byte01; + CMD_DIGIT_BYTE_STRUCT Byte02; + CMD_DIGIT_BYTE_STRUCT Byte03; + CMD_DIGIT_BYTE_STRUCT Byte04; + + CMD_DIGIT_BYTE_STRUCT Byte05; + CMD_DIGIT_BYTE_STRUCT Byte06; + +} CMD_DIGIT_DATA_STRUCT; + +typedef struct +{ + CHAR Address; // Адрес контроллера + CHAR Number; // Номер команды +} CMD_TMS_HEAD_STRUCT; + +typedef struct +{ + // Заголовок + CMD_TMS_HEAD_STRUCT head; + + // Аналоговые величины + CMD_ANALOG_DATA_STRUCT analog_data; + + // Цифровые значениy + CMD_DIGIT_DATA_STRUCT digit_data; + + // Контрольнаy сумма + CHAR crc_lo; + CHAR crc_hi; + + // Дополнительный байт + CHAR add_byte; +} CMD_TO_TMS_STRUCT; + +typedef struct +{ + CHAR Address; // Адрес контроллера + CHAR Number; // Номер команды +} CMD_TMS_HEAD_TEST_ALL_STRUCT; + +typedef struct +{ + CHAR analog1_lo; // младший байт заданной скорости + CHAR analog1_hi; // старший байт заданной скорости + CHAR analog2_lo; // младший байт заданной скорости + CHAR analog2_hi; // старший байт заданной скорости + CHAR analog3_lo; // младший байт заданной скорости + CHAR analog3_hi; // старший байт заданной скорости + CHAR analog4_lo; // младший байт заданной скорости + CHAR analog4_hi; // старший байт заданной скорости + CHAR analog5_lo; // младший байт заданной скорости + CHAR analog5_hi; // старший байт заданной скорости + +} CMD_ANALOG_DATA_TEST_ALL_STRUCT; + +typedef struct +{ + CMD_DIGIT_BYTE_STRUCT byte01; + CMD_DIGIT_BYTE_STRUCT byte02; + + CMD_DIGIT_BYTE_STRUCT byte03; + CMD_DIGIT_BYTE_STRUCT byte04; + + CMD_DIGIT_BYTE_STRUCT byte05; + CMD_DIGIT_BYTE_STRUCT byte06; + + CMD_DIGIT_BYTE_STRUCT byte07; + CMD_DIGIT_BYTE_STRUCT byte08; + + CMD_DIGIT_BYTE_STRUCT byte09; + CMD_DIGIT_BYTE_STRUCT byte10; + + CMD_DIGIT_BYTE_STRUCT byte11; + CMD_DIGIT_BYTE_STRUCT byte12; +} CMD_DIGIT_DATA_TEST_ALL_STRUCT; + +typedef struct +{ + // Заголовок + CMD_TMS_HEAD_TEST_ALL_STRUCT head; + + // Аналоговые величины + CMD_ANALOG_DATA_TEST_ALL_STRUCT analog_data; + + // Цифровые значениy + CMD_DIGIT_DATA_TEST_ALL_STRUCT digit_data; + + // Контрольнаy сумма + CHAR crc_lo; + CHAR crc_hi; + + // Дополнительный байт + CHAR add_byte; +} CMD_TO_TMS_TEST_ALL_STRUCT; + + +typedef struct +{ + CMD_DIGIT_BYTE_STRUCT byte01; + CMD_DIGIT_BYTE_STRUCT byte02; + CMD_DIGIT_BYTE_STRUCT byte03; + CMD_DIGIT_BYTE_STRUCT byte04; + CMD_DIGIT_BYTE_STRUCT byte05; + CMD_DIGIT_BYTE_STRUCT byte06; + CMD_DIGIT_BYTE_STRUCT byte07; + CMD_DIGIT_BYTE_STRUCT byte08; + CMD_DIGIT_BYTE_STRUCT byte09; + CMD_DIGIT_BYTE_STRUCT byte10; + CMD_DIGIT_BYTE_STRUCT byte11; + CMD_DIGIT_BYTE_STRUCT byte12; + + CMD_DIGIT_BYTE_STRUCT byte13; + CMD_DIGIT_BYTE_STRUCT byte14; + CMD_DIGIT_BYTE_STRUCT byte15; + CMD_DIGIT_BYTE_STRUCT byte16; + CMD_DIGIT_BYTE_STRUCT byte17; + CMD_DIGIT_BYTE_STRUCT byte18; + CMD_DIGIT_BYTE_STRUCT byte19; + CMD_DIGIT_BYTE_STRUCT byte20; + CMD_DIGIT_BYTE_STRUCT byte21; + CMD_DIGIT_BYTE_STRUCT byte22; + CMD_DIGIT_BYTE_STRUCT byte23; + CMD_DIGIT_BYTE_STRUCT byte24; + CMD_DIGIT_BYTE_STRUCT byte25; + CMD_DIGIT_BYTE_STRUCT byte26; + CMD_DIGIT_BYTE_STRUCT byte27; + CMD_DIGIT_BYTE_STRUCT byte28; + + CMD_DIGIT_BYTE_STRUCT byte29; + CMD_DIGIT_BYTE_STRUCT byte30; + CMD_DIGIT_BYTE_STRUCT byte31; + CMD_DIGIT_BYTE_STRUCT byte32; + CMD_DIGIT_BYTE_STRUCT byte33; + CMD_DIGIT_BYTE_STRUCT byte34; + CMD_DIGIT_BYTE_STRUCT byte35; + CMD_DIGIT_BYTE_STRUCT byte36; + CMD_DIGIT_BYTE_STRUCT byte37; + CMD_DIGIT_BYTE_STRUCT byte38; + CMD_DIGIT_BYTE_STRUCT byte39; + CMD_DIGIT_BYTE_STRUCT byte40; + CMD_DIGIT_BYTE_STRUCT byte41; + CMD_DIGIT_BYTE_STRUCT byte42; + CMD_DIGIT_BYTE_STRUCT byte43; + CMD_DIGIT_BYTE_STRUCT byte44; + + CMD_DIGIT_BYTE_STRUCT byte45; + CMD_DIGIT_BYTE_STRUCT byte46; + CMD_DIGIT_BYTE_STRUCT byte47; + CMD_DIGIT_BYTE_STRUCT byte48; + CMD_DIGIT_BYTE_STRUCT byte49; + CMD_DIGIT_BYTE_STRUCT byte50; + + CMD_DIGIT_BYTE_STRUCT byte51; + CMD_DIGIT_BYTE_STRUCT byte52; + + CMD_DIGIT_BYTE_STRUCT byte53; + CMD_DIGIT_BYTE_STRUCT byte54; + + CMD_DIGIT_BYTE_STRUCT byte55; + CMD_DIGIT_BYTE_STRUCT byte56; + + CMD_DIGIT_BYTE_STRUCT byte57; + CMD_DIGIT_BYTE_STRUCT byte58; + CMD_DIGIT_BYTE_STRUCT byte59; + CMD_DIGIT_BYTE_STRUCT byte60; + +} ANS_DIGIT_DATA_TO_TERMINAL_STRUCT; // Дискретные величины посылки от СУ + +typedef struct +{ + CHAR analog1_lo; + CHAR analog1_hi; + CHAR analog2_lo; + CHAR analog2_hi; + CHAR analog3_lo; + CHAR analog3_hi; + CHAR analog4_lo; + CHAR analog4_hi; + CHAR analog5_lo; + CHAR analog5_hi; + CHAR analog6_lo; + CHAR analog6_hi; + CHAR analog7_lo; + CHAR analog7_hi; + CHAR analog8_lo; + CHAR analog8_hi; + CHAR analog9_lo; + CHAR analog9_hi; + + CHAR analog10_lo; + CHAR analog10_hi; + CHAR analog11_lo; + CHAR analog11_hi; + CHAR analog12_lo; + CHAR analog12_hi; + CHAR analog13_lo; + CHAR analog13_hi; + CHAR analog14_lo; + CHAR analog14_hi; + CHAR analog15_lo; + CHAR analog15_hi; + CHAR analog16_lo; + CHAR analog16_hi; + CHAR analog17_lo; + CHAR analog17_hi; + CHAR analog18_lo; + CHAR analog18_hi; + CHAR analog19_lo; + CHAR analog19_hi; + + CHAR analog20_lo; + CHAR analog20_hi; + CHAR analog21_lo; + CHAR analog21_hi; + CHAR analog22_lo; + CHAR analog22_hi; + CHAR analog23_lo; + CHAR analog23_hi; + CHAR analog24_lo; + CHAR analog24_hi; + + + CHAR analog25_lo; + CHAR analog25_hi; + CHAR analog26_lo; + CHAR analog26_hi; + CHAR analog27_lo; + CHAR analog27_hi; + CHAR analog28_lo; + CHAR analog28_hi; + CHAR analog29_lo; + CHAR analog29_hi; + CHAR analog30_lo; + CHAR analog30_hi; + + CHAR analog31_lo; + CHAR analog31_hi; + CHAR analog32_lo; + CHAR analog32_hi; + CHAR analog33_lo; + CHAR analog33_hi; + CHAR analog34_lo; + CHAR analog34_hi; + CHAR analog35_lo; + CHAR analog35_hi; + CHAR analog36_lo; + CHAR analog36_hi; + CHAR analog37_lo; + CHAR analog37_hi; + CHAR analog38_lo; + CHAR analog38_hi; + CHAR analog39_lo; + CHAR analog39_hi; + CHAR analog40_lo; + CHAR analog40_hi; + + CHAR analog41_lo; + CHAR analog41_hi; + CHAR analog42_lo; + CHAR analog42_hi; + CHAR analog43_lo; + CHAR analog43_hi; + CHAR analog44_lo; + CHAR analog44_hi; + CHAR analog45_lo; + CHAR analog45_hi; + CHAR analog46_lo; + CHAR analog46_hi; + CHAR analog47_lo; + CHAR analog47_hi; + CHAR analog48_lo; + CHAR analog48_hi; + CHAR analog49_lo; + CHAR analog49_hi; + CHAR analog50_lo; + CHAR analog50_hi; + + CHAR analog51_lo; + CHAR analog51_hi; + CHAR analog52_lo; + CHAR analog52_hi; + CHAR analog53_lo; + CHAR analog53_hi; + CHAR analog54_lo; + CHAR analog54_hi; + CHAR analog55_lo; + CHAR analog55_hi; + CHAR analog56_lo; + CHAR analog56_hi; + CHAR analog57_lo; + CHAR analog57_hi; + CHAR analog58_lo; + CHAR analog58_hi; + CHAR analog59_lo; + CHAR analog59_hi; + CHAR analog60_lo; + CHAR analog60_hi; + + CHAR analog61_lo; + CHAR analog61_hi; + CHAR analog62_lo; + CHAR analog62_hi; + CHAR analog63_lo; + CHAR analog63_hi; + CHAR analog64_lo; + CHAR analog64_hi; + CHAR analog65_lo; + CHAR analog65_hi; + CHAR analog66_lo; + CHAR analog66_hi; + CHAR analog67_lo; + CHAR analog67_hi; + CHAR analog68_lo; + CHAR analog68_hi; + + CHAR analog69_lo; + CHAR analog69_hi; + CHAR analog70_lo; + CHAR analog70_hi; + CHAR analog71_lo; + CHAR analog71_hi; + CHAR analog72_lo; + CHAR analog72_hi; + CHAR analog73_lo; + CHAR analog73_hi; + CHAR analog74_lo; + CHAR analog74_hi; + CHAR analog75_lo; + CHAR analog75_hi; + CHAR analog76_lo; + CHAR analog76_hi; + CHAR analog77_lo; + CHAR analog77_hi; + CHAR analog78_lo; + CHAR analog78_hi; + CHAR analog79_lo; + CHAR analog79_hi; + CHAR analog80_lo; + CHAR analog80_hi; + + CHAR analog81_lo; + CHAR analog81_hi; + CHAR analog82_lo; + CHAR analog82_hi; + CHAR analog83_lo; + CHAR analog83_hi; + CHAR analog84_lo; + CHAR analog84_hi; + + CHAR analog85_lo; + CHAR analog85_hi; + CHAR analog86_lo; + CHAR analog86_hi; + CHAR analog87_lo; + CHAR analog87_hi; + CHAR analog88_lo; + CHAR analog88_hi; + CHAR analog89_lo; + CHAR analog89_hi; + + CHAR analog90_lo; + CHAR analog90_hi; + CHAR analog91_lo; + CHAR analog91_hi; + CHAR analog92_lo; + CHAR analog92_hi; + CHAR analog93_lo; + CHAR analog93_hi; + CHAR analog94_lo; + CHAR analog94_hi; + + CHAR analog95_lo; + CHAR analog95_hi; + CHAR analog96_lo; + CHAR analog96_hi; + + +} TMS_ANALOG_DATA_STRUCT; + +typedef struct +{ + // Заголовок + CMD_TMS_HEAD_STRUCT head; + + // Цифровые значениy + ANS_DIGIT_DATA_TO_TERMINAL_STRUCT digit_data; + + // Аналоговые величины + TMS_ANALOG_DATA_STRUCT analog_data; + + // Контрольнаy сумма + CHAR crc_lo; + CHAR crc_hi; + + // Дополнительный байт + CHAR add_byte; + +} TMS_TO_TERMINAL_STRUCT; + +#define TMS_TO_TERMINAL_STRUCT_DEFAULT {{0}, {0}, {0}, 0, 0, 0} + +typedef struct +{ + CMD_DIGIT_BYTE_STRUCT byte01; + CMD_DIGIT_BYTE_STRUCT byte02; + CMD_DIGIT_BYTE_STRUCT byte03; + CMD_DIGIT_BYTE_STRUCT byte04; + CMD_DIGIT_BYTE_STRUCT byte05; + CMD_DIGIT_BYTE_STRUCT byte06; + CMD_DIGIT_BYTE_STRUCT byte07; + CMD_DIGIT_BYTE_STRUCT byte08; + CMD_DIGIT_BYTE_STRUCT byte09; + CMD_DIGIT_BYTE_STRUCT byte10; + CMD_DIGIT_BYTE_STRUCT byte11; + CMD_DIGIT_BYTE_STRUCT byte12; + + CMD_DIGIT_BYTE_STRUCT byte13; + CMD_DIGIT_BYTE_STRUCT byte14; + CMD_DIGIT_BYTE_STRUCT byte15; + CMD_DIGIT_BYTE_STRUCT byte16; + CMD_DIGIT_BYTE_STRUCT byte17; + CMD_DIGIT_BYTE_STRUCT byte18; + CMD_DIGIT_BYTE_STRUCT byte19; + CMD_DIGIT_BYTE_STRUCT byte20; + CMD_DIGIT_BYTE_STRUCT byte21; + CMD_DIGIT_BYTE_STRUCT byte22; + CMD_DIGIT_BYTE_STRUCT byte23; + CMD_DIGIT_BYTE_STRUCT byte24; + + CMD_DIGIT_BYTE_STRUCT byte25; + CMD_DIGIT_BYTE_STRUCT byte26; + CMD_DIGIT_BYTE_STRUCT byte27; + CMD_DIGIT_BYTE_STRUCT byte28; + CMD_DIGIT_BYTE_STRUCT byte29; + CMD_DIGIT_BYTE_STRUCT byte30; + CMD_DIGIT_BYTE_STRUCT byte31; + CMD_DIGIT_BYTE_STRUCT byte32; + CMD_DIGIT_BYTE_STRUCT byte33; + CMD_DIGIT_BYTE_STRUCT byte34; + +} ANS_DIGIT_DATA_TO_TERMINAL_TEST_ALL_STRUCT; + +typedef struct +{ + CHAR analog1_lo; + CHAR analog1_hi; + CHAR analog2_lo; + CHAR analog2_hi; + CHAR analog3_lo; + CHAR analog3_hi; + CHAR analog4_lo; + CHAR analog4_hi; + CHAR analog5_lo; + CHAR analog5_hi; + CHAR analog6_lo; + CHAR analog6_hi; + CHAR analog7_lo; + CHAR analog7_hi; + CHAR analog8_lo; + CHAR analog8_hi; + CHAR analog9_lo; + CHAR analog9_hi; + + CHAR analog10_lo; + CHAR analog10_hi; + CHAR analog11_lo; + CHAR analog11_hi; + CHAR analog12_lo; + CHAR analog12_hi; + CHAR analog13_lo; + CHAR analog13_hi; + CHAR analog14_lo; + CHAR analog14_hi; + CHAR analog15_lo; + CHAR analog15_hi; + CHAR analog16_lo; + CHAR analog16_hi; + CHAR analog17_lo; + CHAR analog17_hi; + CHAR analog18_lo; + CHAR analog18_hi; + CHAR analog19_lo; + CHAR analog19_hi; + + CHAR analog20_lo; + CHAR analog20_hi; + CHAR analog21_lo; + CHAR analog21_hi; + CHAR analog22_lo; + CHAR analog22_hi; + CHAR analog23_lo; + CHAR analog23_hi; + CHAR analog24_lo; + CHAR analog24_hi; + +} TMS_ANALOG_DATA_TEST_ALL_STRUCT; + +typedef struct +{ + // Заголовок + CMD_TMS_HEAD_TEST_ALL_STRUCT head; + + // Цифровые значениy + ANS_DIGIT_DATA_TO_TERMINAL_TEST_ALL_STRUCT digit_data; + + // Аналоговые величины + TMS_ANALOG_DATA_TEST_ALL_STRUCT analog_data; + + // Контрольнаy сумма + CHAR crc_lo; + CHAR crc_hi; + + // Дополнительный байт + CHAR add_byte; + + //Указатель на массив данных из TMS +// unsigned int pcommand; + + //Функциу формированиу ответа +// void (*fill_answer)(); + +} TMS_TO_TERMINAL_TEST_ALL_STRUCT; + +void ReceiveCommandTestAll(RS_DATA_STRUCT *RS232_Arr); +void ReceiveCommand(RS_DATA_STRUCT *RS232_Arr); + + +extern TMS_TO_TERMINAL_TEST_ALL_STRUCT reply_test_all; +extern TMS_TO_TERMINAL_STRUCT reply; + + + + +#endif /* SRC_XILINX_NIO12_RS_FUNCTION_TERMINAL_H_ */ diff --git a/Inu/Src2/N12_Xilinx/RS_Functions.c b/Inu/Src2/N12_Xilinx/RS_Functions.c new file mode 100644 index 0000000..0057622 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_Functions.c @@ -0,0 +1,2639 @@ +#include "params.h" +#include "global_time.h" +#include "RS_Functions.h" + +#include +#if (USE_TEST_TERMINAL) +#include "RS_Function_terminal.h" +#endif + +#if (USE_MODBUS_TABLE_SVU) +#include "RS_modbus_svu.h" +#endif + +#if (USE_MODBUS_TABLE_PULT) +#include "RS_modbus_pult.h" +#endif + +#include "CRC_Functions.h" +#include "TuneUpPlane.h" //светодиодик + +#include "pwm_test_lines.h" +#include "profile_interrupt.h" + + +#define _ENABLE_INTERRUPT_RS232_LED2 0//1 + + +#define _USE_RS_FIFO 1 + +#define RS232_SPEED 57600//115200 + +#define COM_1 0 //1 +#define COM_2 1 //2 +//#define SIZE_MODBUS_TABLE 334 +//#define ADR_MODBUS_TABLE 0x0001 + +#define BM_CHAR32 0 +#define TIME_WAIT_RS232_BYTE_OUT 2000 + +#define ADDR_FOR_ALL_DEF 0x4 +#define ADR_FOR_SPECIAL 0x100 +#define BM_PACKED 1 + +#define ADDR_UNIVERSAL_DEF 10 + +#define REC_BLOC_BEGIN 0xa0000 +#define REC_BLOC_END 0xeffff + +#define SelectNothing() WriteOper(1, 1, 1, 1) + +#define SCIa_TX_IntClear() SciaRegs.SCIFFTX.bit.TXINTCLR = 1 +#define SCIb_TX_IntClear() ScibRegs.SCIFFTX.bit.TXINTCLR = 1 + +#define IncCountMode28() WriteOper(1, 1, 0, 0) + + +#define SCIa_RX_IntClear() {SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;} +#define SCIb_RX_IntClear() {ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; ScibRegs.SCIFFRX.bit.RXFFINTCLR=1;} + + +#define SCIa_SW_Reset() {SciaRegs.SCICTL1.bit.SWRESET=0; SciaRegs.SCICTL1.bit.SWRESET=1;} +#define SCIb_SW_Reset() {ScibRegs.SCICTL1.bit.SWRESET=0; ScibRegs.SCICTL1.bit.SWRESET=1;} + + +//#define SCIb_Get() ScibRegs.SCIRXBUF.bit.RXDT + +#define SelectReset28() WriteOper(1, 1, 1, 0) +#define SelectReset28_ForLoad67() WriteOper(0, 0, 1, 0) + +//#define enableUARTInt_A() SciaRegs.SCICTL2.all = 2 // recive +//#define enableUARTInt_B() ScibRegs.SCICTL2.all = 2 // recive + +//#define EnableUART_IntW_A() SciaRegs.SCICTL2.all = 1 // transmit +//#define EnableUART_IntW_B() ScibRegs.SCICTL2.all = 1 // transmit + +//#define SCIa_OK() SciaRegs.SCICTL2.bit.TXEMPTY +//#define SCIb_OK() ScibRegs.SCICTL2.bit.TXEMPTY + +//#define SCIa_Wait4OK() while(!SCIa_OK()) +#define SCIa_Send(a) SciaRegs.SCITXBUF = (unsigned char)a + +//#define SCIb_Wait4OK() while(!SCIb_OK()) +#define SCIb_Send(a) ScibRegs.SCITXBUF = (unsigned char)a + + + +#define SCIa_Get() SciaRegs.SCIRXBUF.bit.RXDT + +#define SCIa_RX_Error() SciaRegs.SCIRXST.bit.RXERROR +#define SCIb_RX_Error() SciaRegs.SCIRXST.bit.RXERROR + + +#define SetLoad28_FromResetInternalFlash() \ + SelectNothing(); \ + IncCountMode28(); + +const int CNTRL_ADDR_UNIVERSAL = ADDR_UNIVERSAL_DEF; + +//RS_DATA_STRUCT RS232_A, RS232_B; +#pragma DATA_SECTION(rs_a, ".slow_vars") +#pragma DATA_SECTION(rs_b, ".slow_vars") +RS_DATA_STRUCT rs_a = RS_DATA_STRUCT_DEFAULT, rs_b = RS_DATA_STRUCT_DEFAULT; + +#pragma DATA_SECTION(RS_Len, ".slow_vars") +unsigned int RS_Len[RS_LEN_CMD] = {0}; + + +//MODBUS_REG_STRUCT modbus_table_rs_in[SIZE_MODBUS_TABLE]; +//MODBUS_REG_STRUCT modbus_table_rs_out[SIZE_MODBUS_TABLE]; + +char size_cmd15 = 1; +char size_cmd16 = 1; + +//unsigned int enable_profile_led1_rsa = 1; +//unsigned int enable_profile_led1_rsb = 1; +//unsigned int enable_profile_led2_rsa = 0; +//unsigned int enable_profile_led2_rsb = 0; + + + +int CNTRL_ADDR = 1; + +int ADDR_FOR_ALL = ADDR_FOR_ALL_DEF; + +float KmodTerm = 0.0, freqTerm = 0.0; + +int flag_special_mode_rs = 0; +int disable_flag_special_mode_rs = 0; + + + +void RS_Wait4OK_TXRDY(char commnumber); + +void Answer(RS_DATA_STRUCT *RS232_Arr,int n); + +void EnableUART_Int_RX(char commnumber); +void EnableUART_Int_TX(char commnumber); + +void RS_LineToReceive(char commnumber); +void RS_SetLineMode(char commnumber, int bit, char parity, int stop); +void RS_SetBitMode(RS_DATA_STRUCT *RS232_Arr, int n); +void clear_timer_rs_live(RS_DATA_STRUCT *rs_arr); +void clear_timer_rs_live_mpu(RS_DATA_STRUCT *rs_arr); +void SCI_Send(char commnumber, char bs); +void RS_Wait4OK(char commnumber); +void RS_LineToSend(char commnumber); +void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr); +//int RS232_BSend(RS_DATA_STRUCT *RS232_Arr,unsigned int *pBuf, unsigned long len); + + +void EnableReceiveRS485(void) +{ +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_19_ON; +#endif + + GpioDataRegs.GPBDAT.bit.GPIOB14 = 1; +} + +void EnableSendRS485(void) +{ + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_19_OFF; +#endif + + GpioDataRegs.GPBDAT.bit.GPIOB14 = 0; +} + + +void T_Flash(RS_DATA_STRUCT *RS232_Arr) +{ + volatile unsigned long Address1,Address2; + volatile unsigned long Length, LengthW; + unsigned int cerr, repl, count_ok, return_code; + + if(!RS232_Arr->BS_LoadOK) + { + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + return; + } + + Address1 = RS232_Arr->RS_Header[5] & 0xFF; + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + Address2 = RS232_Arr->RS_Header[9] & 0xFF; + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[8] & 0xFF); + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[7] & 0xFF); + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[6] & 0xFF); + + Length = RS232_Arr->RS_Header[13] & 0xFF; + Length = (Length<<8) | (RS232_Arr->RS_Header[12] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[11] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[10] & 0xFF); + + LengthW = Length/2; + if (LengthW*2 0x180000) || ((Address2+LengthW) > 0x180000) ) + { + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + return; + } + + return_code = RunFlashData(Address1,Address2, LengthW, &cerr, &repl, &count_ok ); + if (return_code==0) + Answer(RS232_Arr,CMD_RS232_TFLASH); + else + { + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + return; + } + + + return; +} + +void Upload(RS_DATA_STRUCT *RS232_Arr) +{ + int32 Address, Length, crc; + + Address = RS232_Arr->RS_Header[5] & 0xFF; + Address = (Address<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + Length = RS232_Arr->RS_Header[9] & 0xFF; + Length = (Length<<8) | (RS232_Arr->RS_Header[8] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[7] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[6] & 0xFF); + + +// RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; +// RS232_Arr->buffer[1] = CMD_RS232_UPLOAD; + RS232_Arr->buffer_stage1[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer_stage1[1] = CMD_RS232_UPLOAD; + + crc = 0xffff; + crc = GetCRC16_IBM( crc, RS232_Arr->buffer_stage1, 2); + crc = GetCRC16_B( crc, (unsigned int *)Address, Length); + + RS232_Arr->RS_SLength_stage1 = 2; /* Настраиваем переменные */ + RS232_Arr->pRS_SendPtr_stage1 = RS232_Arr->buffer_stage1; + RS232_Arr->RS_SendBlockMode_stage1 = BM_CHAR32; + + RS232_Arr->RS_SLength_stage2 = Length; /* Настраиваем переменные */ + RS232_Arr->pRS_SendPtr_stage2 = (unsigned int*)Address; + RS232_Arr->RS_SendBlockMode_stage2 = BM_PACKED; + + +// RS_Send(RS232_Arr,RS232_Arr->buffer, 2); // <=2 байт по флагу + +// RS232_Arr->buffer[0] = CMD_RS232_UPLOAD; +// RS_Send(RS232_Arr,RS232_Arr->buffer, 1); // <=2 байт по флагу +// while (RS232_Arr->RS_OnTransmitedData); + +// RS_Wait4OK(RS232_Arr->commnumber); + + +// RS232_BSend(RS232_Arr,(unsigned int*)Address, Length); +// RS_Wait4OK(RS232_Arr->commnumber); +// while (RS232_Arr->RS_OnTransmitedData); + + RS232_Arr->buffer[0] = LOBYTE(crc); + RS232_Arr->buffer[1] = HIBYTE(crc); + RS232_Arr->buffer[2] = 0; + RS232_Arr->buffer[3] = 0; + + RS232_Arr->cmd_tx_stage = 2; + RS_Send(RS232_Arr,RS232_Arr->buffer, 4); + +// RS232_Send_Staged(RS232_Arr,(unsigned int*)Address, Length); + +// RS_Send(RS232_Arr,RS232_Arr->buffer, 4+2); + +} + +void SetupArrCmdLength() +{ +int i; + + for (i=0;itime_wait_rs_out = (p)->time_wait_rs_out_mpu = (p)->time_wait_rs_lost = 0; + + +void SCI_SwReset(char commnumber) +{ + + switch (commnumber) + { + case COM_1: + SciaRegs.SCICTL1.bit.SWRESET=0; // Relinquish SCI from Reset + SciaRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset + + break; + case COM_2: + ScibRegs.SCICTL1.bit.SWRESET=0; // Relinquish SCI from Reset + ScibRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset + break; + } + + +} + +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + +//static int buf_fifo_rsa[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; +//static int buf_fifo_rsb[17]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}; + +static int buf_fifo_rs_ab[2][17]={ {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0} }; + +#pragma CODE_SECTION(my_test_rs,".fast_run2"); +int my_test_rs(int comn) +{ + int cc=0; + + cc = 0; + if (comn==COM_1) + { + while ((SciaRegs.SCIFFRX.bit.RXFIFST != 0) ) + { + buf_fifo_rs_ab[comn][cc++] = SciaRegs.SCIRXBUF.bit.RXDT; + if (cc>=17) cc = 0; + } + return cc; + } + else + { + while ((ScibRegs.SCIFFRX.bit.RXFIFST != 0) ) + { + buf_fifo_rs_ab[comn][cc++] = ScibRegs.SCIRXBUF.bit.RXDT; + if (cc>=17) cc = 0; + } + return cc; + } + +} + +/////////////// +//#pragma CODE_SECTION(RS_RXA_Handler_fast,".fast_run2"); +void RS_RXA_Handler_fast(RS_DATA_STRUCT *RS232_Arr) +{ + char Rc; + char RS232_BytePtr; + int cc1, cc2,cn; + +//i_led2_on_off(1); + + + ClearTimerRS_Live(RS232_Arr); + + cn = RS232_Arr->commnumber; + cc1 = my_test_rs(cn); + cc2 = 0; + for(;;) // 'goto' это не оператор Языка С + { + if (cn==COM_1) + { + if (SciaRegs.SCIRXST.bit.RXERROR) + { +// Rc = SciaRegs.SCIRXBUF.all; + (RS232_Arr->count_recive_rxerror)++; + RS232_Arr->do_resetup_rs = 1; + } + if (SciaRegs.SCIRXST.bit.RXWAKE) + { + Rc = SciaRegs.SCIRXBUF.all; + } + } + else + { + + if (ScibRegs.SCIRXST.bit.RXERROR) + { +// Rc = SciaRegs.SCIRXBUF.all; + (RS232_Arr->count_recive_rxerror)++; + RS232_Arr->do_resetup_rs = 1; + } + if (ScibRegs.SCIRXST.bit.RXWAKE) + { + Rc = ScibRegs.SCIRXBUF.all; + } + } + + +// if (!SciaRegs.SCIRXST.bit.RXRDY) + if (cc1 == 0) +// if ((SciaRegs.SCIFFRX.bit.RXFIFST == 0) ) + { +// PieCtrlRegs.PIEACK.bit.ACK9 |= 1; +// SCI_RX_IntClear(RS232_Arr->commnumber); +// SciaRegs.SCIFFRX.bit.RXFFINTCLR = 1; +//i_led2_on_off(0); + return; // кстати это единственный выход из прерываниЯ + } +//i_led2_on_off(1); + /* есть ли ошибки? */ +// if (SciaRegs.SCIRXST.bit.RXERROR) +// { +// Rc = SciaRegs.SCIRXBUF.all;//SciaRegs.SCIRXBUF.bit.RXDT;//RS_Get(RS232_Arr->commnumber); // Читаем символ в любом случае +// continue; +// } + cc1--; + +// if (cn==COM_1) + Rc = buf_fifo_rs_ab[cn][cc2];//SciaRegs.SCIRXBUF.all;// SciaRegs.SCIRXBUF.bit.RXDT;//RS_Get(RS232_Arr->commnumber); // Читаем символ в любом случае +// else +// Rc = buf_fifo_rsb[cc2]; + cc2++; + + (RS232_Arr->count_recive_bytes_all)++; +//i_led2_on_off(0); + + if(RS232_Arr->RS_DataReady) + { + continue; // Не забрали данные + } + + if (RS232_Arr->RS_Flag9bit==1) // длЯ RS485???????? + { + // Инициализируем переменные и флаги + RS232_Arr->RS_FlagBegin = true; // Ждем заголовок + RS232_Arr->RS_RecvLen = 0; + RS232_Arr->RS_FlagSkiping = false; + RS232_Arr->RS_HeaderCnt = 0; + RS232_Arr->RS_Cmd = 0; + } +//i_led2_on_off(1); + if(RS232_Arr->RS_FlagSkiping) + { + (RS232_Arr->count_recive_bytes_skipped)++; + continue; // Не нам + } + + if (RS232_Arr->RS_FlagBegin) // Заголовок + { + if (RS232_Arr->RS_HeaderCnt==0) // Адрес контроллера или стандартнаЯ команда + { +//i_led2_on_off(0); + if( (Rc == CNTRL_ADDR_UNIVERSAL) || (Rc == CNTRL_ADDR && CNTRL_ADDR!=0) || ((Rc == RS232_Arr->addr_answer) && RS232_Arr->flag_LEADING) + || ((Rc == ADDR_FOR_ALL && ADDR_FOR_ALL!=0) && !RS232_Arr->flag_LEADING)) + { + RS232_Arr->addr_recive=Rc; // запомнили адрес по которому нас запросили + RS232_Arr->RS_Header[RS232_Arr->RS_HeaderCnt++] = Rc; // Первый байт +// ClearTimerRS_Live(RS232_Arr); + + RS_SetBitMode(RS232_Arr,8); // перестроились в 8-бит режим + } + else + { +//i_led1_toggle(); + RS232_Arr->RS_FlagSkiping = true; // Не нашему контроллеру + RS232_Arr->RS_FlagBegin = false; // остались в 9-бит режиме + (RS232_Arr->count_recive_cmd_skipped)++; +//i_led1_on_off(0); + } +//i_led2_on_off(1); + } + else + { +//i_led2_on_off(0);i_led2_on_off(1); +// ClearTimerRS_Live(RS232_Arr); + + RS232_Arr->RS_Header[RS232_Arr->RS_HeaderCnt++] = Rc; // Второй байт и т.д. + + if (RS232_Arr->RS_HeaderCnt == 7 && !RS232_Arr->flag_LEADING) + { + switch (RS232_Arr->RS_Cmd) { + case CMD_RS232_MODBUS_16: + RS_Len[CMD_RS232_MODBUS_16] = (10+Rc); break; + case CMD_RS232_MODBUS_15: + RS_Len[CMD_RS232_MODBUS_15] = (10+Rc); break; + } + } + +//i_led2_on_off(0);i_led2_on_off(1); + + // если второй байт - это команда + if (RS232_Arr->RS_HeaderCnt == 2) + { + RS232_Arr->RS_Cmd = Rc; + // Проверка длины посылки + // CMD_LOAD - младшаЯ на данный момент + // CMD_STD_ANS - старшаЯ на данный момент +// if ((RS232_Arr->RS_Cmd < 0 /*CMD_RS232_MODBUS_3*/) || (RS232_Arr->RS_Cmd > CMD_RS232_STD_ANS) || (RS_Len[RS232_Arr->RS_Cmd]<3)) + if ((RS232_Arr->RS_Cmd > CMD_RS232_STD_ANS) || (RS_Len[RS232_Arr->RS_Cmd]<3)) + { + RS_SetBitMode(RS232_Arr,9); // Получили все перестроились в 9-бит длЯ RS485? + RS232_Arr->RS_HeaderCnt = 0; // Потому что команда не та + RS232_Arr->RS_FlagBegin = true; + RS232_Arr->RS_FlagSkiping = false; + RS232_Arr->RS_Cmd=0; + (RS232_Arr->count_recive_bad)++; + continue; + } + if(RS232_Arr->RS_Cmd == 4) { + asm(" NOP "); + } + if (RS232_Arr->RS_Cmd == CMD_RS232_LOAD) { // ДлЯ этой команды заголовок очень короткий + RS232_Arr->RS_FlagBegin = false;// дальше идут данные + RS232_Arr->count_recive_bytes_all = 0;// временно, для отладки + } + } +//i_led2_on_off(0); + if( (RS232_Arr->RS_HeaderCnt >= (int)RS_Len[RS232_Arr->RS_Cmd]) || + (RS232_Arr->RS_HeaderCnt >= (int)sizeof(RS232_Arr->RS_Header))) + { // Получили заголовок + RS_SetBitMode(RS232_Arr,9); // Получили все перестроились в 9-бит длЯ RS485? + RS232_Arr->RS_FlagBegin = false; + RS232_Arr->RS_FlagSkiping = true; + RS232_Arr->RS_DataReady = true; + RS232_Arr->RS_Cmd=0; + (RS232_Arr->count_recive_dirty)++; + } +//i_led2_on_off(1); + } + +//i_led2_on_off(0); + + } + else // Поток данных + { + if(RS232_Arr->pRS_RecvPtr<(unsigned int *)REC_BLOC_BEGIN || RS232_Arr->pRS_RecvPtr>(unsigned int *)REC_BLOC_END) + RS232_Arr->pRS_RecvPtr = (unsigned int *)REC_BLOC_BEGIN; // На программу надейсЯ, а сам не плошай + + if(RS232_Arr->RS_PrevCmd != CMD_RS232_INITLOAD) + { + (RS232_Arr->count_recive_bad)++; + continue; // Мы здесь оказались по какой-то чудовищной ошибке + } + + if(RS232_Arr->RS_DataReady) // Если данные в основном цикле не забраны, + { // то пропускаем следующую посылку + RS232_Arr->RS_FlagSkiping = true; // Игнорируем до следующего заголовка + (RS232_Arr->count_recive_cmd_skipped)++; + continue; + } + + RS232_BytePtr = RS232_Arr->RS_RecvLen++ % 2; + if(RS232_BytePtr) *RS232_Arr->pRS_RecvPtr++ |= Rc; // Получили слово + else *RS232_Arr->pRS_RecvPtr = Rc<<8; + + if(RS232_Arr->RS_Length <= RS232_Arr->RS_RecvLen) // Конец посылки + { + RS232_Arr->RS_PrevCmd = RS232_Arr->RS_Header[1] = CMD_RS232_LOAD; + RS_SetBitMode(RS232_Arr,9); // Получили все данные перестроились в 9-бит длЯ RS485? + RS232_Arr->RS_FlagSkiping = true; // Игнорируем до следующего заголовка + RS232_Arr->RS_DataReady = true; // Флаг в основной цикл - данные получены + (RS232_Arr->count_recive_dirty)++; + } + } + } +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +int get_free_rs_fifo_tx(char commnumber) +{ + if(commnumber==COM_1) + { + return (16 - SciaRegs.SCIFFTX.bit.TXFFST-1); + } + else + { + return (16 - ScibRegs.SCIFFTX.bit.TXFFST-1); + } +} +/////////////////////////////////////////////////////////// +void RS_TX_Handler(RS_DATA_STRUCT *RS232_Arr) +{ + char RS232_BytePtr; + unsigned int final_flag=0, free_fifo; + unsigned int i; + + static unsigned int max_s_b = 1; // посылаем по max_s_b штук + unsigned int final_free_fifo=0; + +// if(RS232_Arr->RS_SendBlockMode == BM_CHAR32) +// { + free_fifo = get_free_rs_fifo_tx(RS232_Arr->commnumber); + ClearTimerRS_Live(RS232_Arr); + + if (free_fifo>=max_s_b) + free_fifo=max_s_b; // посылаем по max_s_b штук + + for (i=0;icmd_tx_stage) + { + case 2: //stage1 + if (RS232_Arr->RS_SendLen >= RS232_Arr->RS_SLength_stage1) + { + RS232_Arr->cmd_tx_stage = 1; + RS232_Arr->RS_SendLen = 0; + // break; + } + else + { + if(RS232_Arr->RS_SendBlockMode_stage1 != BM_CHAR32) + { + RS232_BytePtr = (RS232_Arr->RS_SendLen) % 2; + if(RS232_BytePtr) SCI_Send(RS232_Arr->commnumber, LOBYTE( *(RS232_Arr->pRS_SendPtr_stage1++) )); + else SCI_Send(RS232_Arr->commnumber, HIBYTE( *RS232_Arr->pRS_SendPtr_stage1 )); + } + else + SCI_Send(RS232_Arr->commnumber,*(RS232_Arr->pRS_SendPtr_stage1++)); + + (RS232_Arr->RS_SendLen)++; + break; + } + break; + + case 1: //stage2 + if (RS232_Arr->RS_SendLen >= RS232_Arr->RS_SLength_stage2) + { + RS232_Arr->cmd_tx_stage = 0; + RS232_Arr->RS_SendLen = 0; + // break; + } + else + { + if(RS232_Arr->RS_SendBlockMode_stage2 != BM_CHAR32) + { + RS232_BytePtr = (RS232_Arr->RS_SendLen) % 2; + if(RS232_BytePtr) SCI_Send(RS232_Arr->commnumber, LOBYTE( *(RS232_Arr->pRS_SendPtr_stage2++) )); + else SCI_Send(RS232_Arr->commnumber, HIBYTE( *RS232_Arr->pRS_SendPtr_stage2 )); + } + else + SCI_Send(RS232_Arr->commnumber,*(RS232_Arr->pRS_SendPtr_stage2++)); + + (RS232_Arr->RS_SendLen)++; + break; + } + break; + + + case 0: + //stage 0 + if (RS232_Arr->RS_SendLen >= RS232_Arr->RS_SLength) + { + final_flag = 1; + break; + } + else + { + if(RS232_Arr->RS_SendBlockMode != BM_CHAR32) + { + RS232_BytePtr = (RS232_Arr->RS_SendLen) % 2; + if(RS232_BytePtr) SCI_Send(RS232_Arr->commnumber, LOBYTE( *(RS232_Arr->pRS_SendPtr++) )); + else SCI_Send(RS232_Arr->commnumber, HIBYTE( *RS232_Arr->pRS_SendPtr )); + } + else + SCI_Send(RS232_Arr->commnumber,*(RS232_Arr->pRS_SendPtr++)); + + (RS232_Arr->RS_SendLen)++; + } + break; + default : + break; + } + if (final_flag) + break; + } + + if (final_flag) + { + + final_free_fifo = get_free_rs_fifo_tx(RS232_Arr->commnumber); + + if (final_free_fifo>=15) // все уехали? буфер чист? + { + if(RS232_Arr->RS_SendBlockMode == BM_CHAR32) + { +// if (max_s_b>1) +// RS_Wait4OK(RS232_Arr->commnumber); + + RS_SetBitMode(RS232_Arr,9); /* Передали все перестроились в 9-бит длЯ RS485?*/ + RS_LineToReceive(RS232_Arr->commnumber); /* режим приема RS485 */ + + RS232_Arr->flag_TIMEOUT_to_Send=false; /* сбросили флаг ожиданиЯ таймаута */ + } + + if (RS232_Arr->RS_DataWillSend) + RS232_Arr->RS_DataSended = 1; + RS232_Arr->RS_DataWillSend = 0; + + EnableUART_Int_RX(RS232_Arr->commnumber); /* Запрещаем прерываниЯ по передаче */ + } + } + +} +// + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(RSA_TX_Handler,".fast_run2"); +interrupt void RSA_TX_Handler(void) +{ + // Set interrupt priority: + volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all; + IER |= M_INT9; + IER &= MINT9; // Set "global" priority + PieCtrlRegs.PIEIER9.all &= MG92; // Set "group" priority + PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(1); +#endif + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsa) + i_led1_on_off_special(1); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsa) + i_led2_on_off_special(1); +#endif + + + + EINT; + + +// i_led2_on_off(1); + + // Insert ISR Code here....... + RS_TX_Handler(&rs_a); + +// i_led2_on_off(0); + + // Next line for debug only (remove after inserting ISR Code): +// ESTOP0; + SCIa_TX_IntClear(); +// SciaRegs.SCIFFTX.bit.TXINTCLR=1; // Clear SCI Interrupt flag + PieCtrlRegs.PIEACK.all |= BIT8; // Issue PIE ACK + + + // Restore registers saved: + DINT; + PieCtrlRegs.PIEIER9.all = TempPIEIER; + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsa) + i_led1_on_off_special(0); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsa) + i_led2_on_off_special(0); +#endif + + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(0); +#endif + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(RSB_TX_Handler,".fast_run2"); +interrupt void RSB_TX_Handler(void) +{ + // Set interrupt priority: + volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all; + IER |= M_INT9; + IER &= MINT9; // Set "global" priority + PieCtrlRegs.PIEIER9.all &= MG94; // Set "group" priority + PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_16_ON; +#endif + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(1); +#endif + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsb) + i_led1_on_off_special(1); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsb) + i_led2_on_off_special(1); +#endif + + EINT; + + // i_led2_on_off(1); + + // Insert ISR Code here....... + RS_TX_Handler(&rs_b); + +// i_led2_on_off(0); + + // Next line for debug only (remove after inserting ISR Code): +// ESTOP0; + SCIb_TX_IntClear(); +// SciaRegs.SCIFFTX.bit.TXINTCLR=1; // Clear SCI Interrupt flag + PieCtrlRegs.PIEACK.all |= BIT8; // Issue PIE ACK + + + // Restore registers saved: + DINT; + PieCtrlRegs.PIEIER9.all = TempPIEIER; + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsb) + i_led1_on_off_special(0); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsb) + i_led2_on_off_special(0); +#endif + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(0); +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_16_OFF; +#endif + + +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(RSA_RX_Handler,".fast_run2"); +interrupt void RSA_RX_Handler(void) +{ + // Set interrupt priority: + volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all; + IER |= M_INT9; + IER &= MINT9; // Set "global" priority + PieCtrlRegs.PIEIER9.all &= MG91; // Set "group" priority + PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(1); +#endif + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsa) + i_led1_on_off_special(1); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsa) + i_led2_on_off_special(1); +#endif + + EINT; + // i_led1_on_off(1); + + + // Insert ISR Code here....... + // ClearTimerRS_Live(&rs_a); + +// i_led2_on_off(0); + //RS_RX_Handler(&rs_a); + RS_RXA_Handler_fast(&rs_a); + // my_test_rs(); + + // Next line for debug only (remove after inserting ISR Code): +// ESTOP0; +// i_led2_on_off(0); + // i_led1_on_off(0); + + SCIa_RX_IntClear(); + +// SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag +// SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag + + PieCtrlRegs.PIEACK.all |= BIT8; + // Restore registers saved: + DINT; + PieCtrlRegs.PIEIER9.all = TempPIEIER; + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsa) + i_led1_on_off_special(0); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsa) + i_led2_on_off_special(0); +#endif + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(0); +#endif + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +//#pragma CODE_SECTION(RSB_RX_Handler,".fast_run2"); +interrupt void RSB_RX_Handler(void) +{ + // Set interrupt priority: + volatile Uint16 TempPIEIER = PieCtrlRegs.PIEIER9.all; + IER |= M_INT9; + IER &= MINT9; // Set "global" priority + PieCtrlRegs.PIEIER9.all &= MG93; // Set "group" priority + PieCtrlRegs.PIEACK.all = 0xFFFF; // Enable PIE interrupts + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_17_ON; +#endif + + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(1); +#endif + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsb) + i_led1_on_off_special(1); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsb) + i_led2_on_off_special(1); +#endif + + EINT; + + // i_led1_on_off(1); + // Insert ISR Code here....... + //ClearTimerRS_Live(&rs_b); + RS_RXA_Handler_fast(&rs_b); + // i_led1_on_off(0); + + // Next line for debug only (remove after inserting ISR Code): +// ESTOP0; + SCIb_RX_IntClear(); + + PieCtrlRegs.PIEACK.all |= BIT8; + // Restore registers saved: + DINT; + PieCtrlRegs.PIEIER9.all = TempPIEIER; + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.rsb) + i_led1_on_off_special(0); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.rsb) + i_led2_on_off_special(0); +#endif + +#if (_ENABLE_INTERRUPT_RS232_LED2) +i_led2_on_off(0); +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_17_OFF; +#endif + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +////////////////////////////////////////////////////// +/// +////////////////////////////////////////////////////// +void RS_LineToSend(char commnumber) +{ +/* Режим передачи RS485. Здесь не нужен, + поскольку RS485 только на канале B.*/ +// addr_xilinx(TR485) = 0xffffffff; + +// SCIa_RX_Int_disable(); // запрет прерываний на прием +// SCIa_TX_Int_enable(); // разрешение прерываний на передачу + if (commnumber==COM_1) + { +// ScibRegs.SCICTL1.bit.RXENA=0; + SciaRegs.SCICTL1.bit.RXENA=0; +// SciaRegs.SCICTL1.bit.TXENA=1; + } + else + { + EnableSendRS485(); + ScibRegs.SCICTL1.bit.RXENA=0; +// ScibRegs.SCICTL1.bit.TXENA=1; + } + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void RS_LineToReceive(char commnumber) +{ +/* Режим приема RS485. Здесь не нужен, + поскольку RS485 только на канале B.*/ +// addr_xilinx(TR485) = 0x0; + +// SCIa_RX_Int_enable(); // разрешение прерываний на прием +// SCIa_TX_Int_disable(); // запрет прерываний на передачу + + if (commnumber==COM_1) + { + SCIa_RX_IntClear(); + } + else + { + EnableReceiveRS485(); + +// pause_1000(100); + + SCIb_RX_IntClear(); +// SCIb_TX_IntClear(); // clear TX FIFO interrupts + +// my_test_rs(commnumber); + // SCIb_RX_IntClear(); +// SCIb_TX_IntClear(); // clear TX FIFO interrupts + + } +// pause_1000(1000); + EnableUART_Int_RX(commnumber); /* разрешение прерываний UART на прием */ +// my_test_rs(commnumber); + + if (commnumber==COM_1) + { +// SCIa_RX_IntClear(); + SciaRegs.SCICTL1.bit.RXENA=1; + } + else + { +// SCIb_RX_IntClear(); + ScibRegs.SCICTL1.bit.RXENA=1; + } + + +} + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +static void RS_SetLineSpeed(char commnumber,unsigned long speed) +{ +float SciBaud; + + SciBaud = ((float)LSPCLK/(speed*8.0))-1.0; + + if((SciBaud-(unsigned int)SciBaud)>0.5) SciBaud++; + + + if(commnumber==COM_1) + { + SciaRegs.SCIHBAUD = HIBYTE((int)SciBaud); + SciaRegs.SCILBAUD = LOBYTE((int)SciBaud); + } + + if(commnumber==COM_2) + { + ScibRegs.SCIHBAUD = HIBYTE((int)SciBaud); + ScibRegs.SCILBAUD = LOBYTE((int)SciBaud); + } + + +} + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////// +/// +////////////////////////////////////////////////////// +void EnableUART_Int_RX(char commnumber) +{ +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_18_ON; +#endif + + switch (commnumber) + { + case COM_1: //SciaRegs.SCICTL2.bit.RXBKINTENA = 0;//1; //enableUARTInt_A(); + SciaRegs.SCIFFRX.bit.RXFFIENA = 1; +// SciaRegs.SCICTL2.bit.TXINTENA = 1; + SciaRegs.SCIFFTX.bit.TXFFIENA = 0; + rs_a.RS_OnTransmitedData = 0; + SciaRegs.SCICTL1.bit.RXENA = 1; + SciaRegs.SCICTL1.bit.TXENA = 0; + break; + + case COM_2: //ScibRegs.SCICTL2.bit.RXBKINTENA = 0;//1; //enableUARTInt_A(); + ScibRegs.SCIFFRX.bit.RXFFIENA = 1; +// SciaRegs.SCICTL2.bit.TXINTENA = 1; + ScibRegs.SCIFFTX.bit.TXFFIENA = 0; + rs_b.RS_OnTransmitedData = 0; + ScibRegs.SCICTL1.bit.RXENA = 1; + ScibRegs.SCICTL1.bit.TXENA = 0; + + break; + } + +} + +////////////////////////////////////////////////////// +/// +////////////////////////////////////////////////////// +void EnableUART_Int_TX(char commnumber) +{ + +#if(_ENABLE_PWM_LINES_FOR_TESTS_RS) + PWM_LINES_TK_18_OFF; +#endif + + switch (commnumber) + { + case COM_1: rs_a.RS_OnTransmitedData = 1; + //SciaRegs.SCICTL2.bit.RXBKINTENA = 0; + SciaRegs.SCIFFRX.bit.RXFFIENA = 0; +// SciaRegs.SCICTL2.bit.TXINTENA = 1; + SciaRegs.SCIFFTX.bit.TXFFIENA = 1;//EnableUART_IntW_A(); + SciaRegs.SCICTL1.bit.RXENA = 0; + SciaRegs.SCICTL1.bit.TXENA = 1; + break; + + case COM_2: rs_b.RS_OnTransmitedData = 1; + //ScibRegs.SCICTL2.bit.RXBKINTENA = 0; + ScibRegs.SCIFFRX.bit.RXFFIENA = 0; +// SciaRegs.SCICTL2.bit.TXINTENA = 1; + ScibRegs.SCIFFTX.bit.TXFFIENA = 1;//EnableUART_IntW_A(); + ScibRegs.SCICTL1.bit.RXENA = 0; + ScibRegs.SCICTL1.bit.TXENA = 1; + break; + } +} + + + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +void RS_SetAdrAnswerController(RS_DATA_STRUCT *RS232_Arr,int set_addr_answer) +{ + RS232_Arr->addr_answer = set_addr_answer; /* Флаг режима контроллера (по умолчанию ведомый)*/ +} + +void RS_SetControllerLeading(RS_DATA_STRUCT *RS232_Arr,int bool) +{ + RS232_Arr->flag_LEADING = bool; /* Флаг режима контроллера (по умолчанию ведомый)*/ +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void RS_SetLineMode(char commnumber, int bit, char parity, int stop) +{ +/* +SCICCR - SCI Communication Control Register +Bit Bit Name Designation Functions +2–0 SCI CHAR2–0 SCICHAR Select the character (data) length (one to eight bits). +3 ADDR/IDLE MODE ADDRIDLE_MODE The idle-line mode (0) is usually used for normal communications because the address-bit mode adds an extra bit to the frame. The idle-line mode does not add this extra bit and is compatible with RS-232 type communications. +4 LOOP BACK ENABLE LOOPBKENA This bit enables (1) the Loop Back test mode where the Tx pin is internally connected to the Rx pin. +5 PARITY ENABLE PARITYENA Enables the parity function if set to 1, or disables the parity function if cleared to 0. +6 EVEN/ODD PARITY PARITY If parity is enabled, selects odd parity if cleared to 0 or even parity if set to 1. +7 STOP BITS STOPBITS Determines the number of stop bits transmitted—one stop bit if cleared to 0 or two stop bits if set to 1. +*/ + + if (commnumber==COM_1) + { + if(bit>0 && bit<9) SciaRegs.SCICCR.bit.SCICHAR = bit-1; + + switch(parity) + { + case 'N': SciaRegs.SCICCR.bit.PARITYENA = 0; + break; + case 'O': SciaRegs.SCICCR.bit.PARITYENA = 1; + SciaRegs.SCICCR.bit.PARITY = 0; + break; + case 'E': SciaRegs.SCICCR.bit.PARITYENA = 1; + SciaRegs.SCICCR.bit.PARITY = 1; + break; + } + + if (stop==1) SciaRegs.SCICCR.bit.STOPBITS = 0; + if (stop==2) SciaRegs.SCICCR.bit.STOPBITS = 1; + + SciaRegs.SCICCR.bit.LOOPBKENA = 0; //0 + SciaRegs.SCICCR.bit.ADDRIDLE_MODE = 0; + } + + if (commnumber==COM_2) + { + if(bit>0 && bit<9) ScibRegs.SCICCR.bit.SCICHAR = bit-1; + + switch(parity) + { + case 'N': ScibRegs.SCICCR.bit.PARITYENA = 0; + break; + case 'O': ScibRegs.SCICCR.bit.PARITYENA = 1; + ScibRegs.SCICCR.bit.PARITY = 0; + break; + case 'E': ScibRegs.SCICCR.bit.PARITYENA = 1; + ScibRegs.SCICCR.bit.PARITY = 1; + break; + } + + if (stop==1) ScibRegs.SCICCR.bit.STOPBITS = 0; + if (stop==2) ScibRegs.SCICCR.bit.STOPBITS = 1; + + ScibRegs.SCICCR.bit.LOOPBKENA = 0; //0 + ScibRegs.SCICCR.bit.ADDRIDLE_MODE = 0; + } + + +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void RS_SetBitMode(RS_DATA_STRUCT *RS232_Arr, int n) +{ + if(n == 8) + { + RS_SetLineMode(RS232_Arr->commnumber,8,'N',1); /* режим линии */ + RS232_Arr->RS_Flag9bit=0; + } + if(n == 9) + { + RS_SetLineMode(RS232_Arr->commnumber,8,'N',1); /* режим линии */ + RS232_Arr->RS_Flag9bit=1; + RS232_Arr->cmd_tx_stage = 0; + } + + +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void clear_timer_rs_live(RS_DATA_STRUCT *rs_arr) { + ClearTimerRS_Live(rs_arr); +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void clear_timer_rs_live_mpu(RS_DATA_STRUCT *rs_arr) { + rs_arr->time_wait_rs_out_mpu = 0; +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void resetup_rs(RS_DATA_STRUCT *rs_arr) { + + RS_LineToReceive(rs_arr->commnumber); // режим приема RS485 + RS_SetBitMode(rs_arr, 9); + RS_SetControllerLeading(rs_arr, false); + ClearTimerRS_Live(rs_arr); +// return -1; +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void resetup_mpu_rs(RS_DATA_STRUCT *rs_arr) { + + +// RS_SetControllerLeading(rs_arr,false); + +// RS_LineToReceive(commnumber); // режим приема RS485 + +// RS_SetBitMode(&rs_b,9); +// rs_b.RS_PrevCmd = 0; // не было никаких команд + + ////// + + if (rs_arr->commnumber==COM_1) + SCIa_SW_Reset() + else + SCIb_SW_Reset(); + + + + RS_LineToReceive(rs_arr->commnumber); // режим приема RS485 + RS_SetBitMode(rs_arr, 9); + RS_SetControllerLeading(rs_arr, false); + ClearTimerRS_Live(rs_arr); + rs_arr->RS_PrevCmd = 0; // не было никаких команд + + rs_arr->RS_DataSended = 0; + rs_arr->RS_DataWillSend = 0; + + rs_arr->RS_DataReadyAnswer = 0; + rs_arr->RS_DataReadyAnswerAnalyze = 0; + + rs_arr->RS_DataReadyRequest = 0; + rs_arr->do_resetup_rs = 0; + + +// SCIb_RX_IntClear(); +// SCIb_TX_IntClear(); // clear TX FIFO interrupts + + EnableUART_Int_RX(rs_arr->commnumber); // разрешение прерываний UART + +// return -1; + +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +/* проверка на живучесть RS */ +int test_rs_live(RS_DATA_STRUCT *rs_arr) +{ + if (rs_arr->time_wait_rs_out>(2*RS_TIME_OUT)) + return 2; /* пора переружать */ + if (rs_arr->time_wait_rs_out>RS_TIME_OUT) + return 0; /* умер */ + if (rs_arr->time_wait_rs_out_mpu>RS_TIME_OUT_MPU) + return 4; /* пора переружать */ + + if (rs_arr->time_wait_rs_out>RS_TIME_OUT_HMI) + return 5; /* пора повторить запрос */ + + else + return 1; /* жив */ +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void inc_RS_timeout_cicle(void) +{ + + unsigned int i, t_refresh; + static unsigned int old_time_rs = 0; + + t_refresh = get_delta_milisec(&old_time_rs, 1); + if (t_refresh>1000) + t_refresh = 1000; + if (t_refresh<1) + t_refresh = 1; + + if (rs_a.time_wait_rs_out=RS_TIME_OUT_LOST) + resetup_mpu_rs(&rs_a); + } + else + { + if (rs_b.time_wait_rs_lost>=RS_TIME_OUT_LOST) + resetup_mpu_rs(&rs_b); + } + +} +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void clear_buffers_rs(RS_DATA_STRUCT *rs_arr) +{ + unsigned int i; + + + for (i=0;iRS_Header[i] = 0; + + for (i=0;ibuffer[i] = 0; + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +#ifdef _USE_RS_FIFO +void SetupUART(char commnumber, unsigned long speed_baud) +{ + // x1 Free run. Continues SCI operation regardless of suspend + // 10 Complete current receive/transmit sequence before stopping + // 00 Immediate stop on suspend + + + if(commnumber==COM_1) + { + SciaRegs.SCIPRI.bit.FREE = 1; + SciaRegs.SCIPRI.bit.SOFT = 0; + +// Initialize SCI-A: +// Note: Clocks were turned on to the SCIA peripheral +// in the InitSysCtrl() function + + EALLOW; + GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5=1; + GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4=1; + EDIS; + + RS_SetLineMode(commnumber,8,'N',1); + +/////// + SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback + // No parity,8 char bits, + // async mode, idle-line protocol + + SciaRegs.SCICTL1.all = 0; +// SciaRegs.SCICTL1.bit.RXENA = 1; // enable RX, +// SciaRegs.SCICTL1.bit.TXENA = 1; // enable TX + SciaRegs.SCICTL1.bit.RXENA = 0; // disable RX, + SciaRegs.SCICTL1.bit.TXENA = 0; // disable TX + SciaRegs.SCICTL1.bit.RXERRINTENA = 1; //Receive error interrupt enabled + SciaRegs.SCICTL1.bit.TXWAKE = 0; + SciaRegs.SCICTL1.bit.SLEEP = 0; + + SciaRegs.SCICTL2.bit.TXINTENA = 0;//1; + SciaRegs.SCICTL2.bit.RXBKINTENA = 0;//1; + + RS_SetLineSpeed(commnumber,speed_baud); /* скорость линии */ + + SciaRegs.SCICCR.bit.LOOPBKENA = 0; // Enable loop back + +// SciaRegs.SCIFFTX.all=0xC028; +//SCIFFTX + SciaRegs.SCIFFTX.bit.SCIFFENA=1; // SCI FIFO enable + + SciaRegs.SCIFFTX.bit.TXFFILIL = 0;//1; // TXFFIL4–0 Transmit FIFO interrupt level bits. Transmit FIFO will generate interrupt when the FIFO + // status bits (TXFFST4–0) and FIFO level bits (TXFFIL4–0 ) match (less than or equal to). + + SciaRegs.SCIFFTX.bit.TXFIFOXRESET=0; + SciaRegs.SCIFFTX.bit.TXFFST = 0; + SciaRegs.SCIFFTX.bit.TXFFINT = 0; + SciaRegs.SCIFFTX.bit.TXINTCLR = 0; + SciaRegs.SCIFFTX.bit.TXFFIENA = 0; // Transmit FIFO interrrupt enable + + SciaRegs.SCIFFTX.bit.SCIRST = 1; + +//SCIFFRX +// SciaRegs.SCIFFRX.all=0x0028; +// SciaRegs.SCIFFRX.all=0x0022; + SciaRegs.SCIFFRX.bit.RXFFIL = 1; // 4:0 Interrupt level + SciaRegs.SCIFFRX.bit.RXFFIENA = 1; // Interrupt enable + + SciaRegs.SCIFFCT.all=0x00; // FIFO control register + SciaRegs.SCIFFCT.bit.ABDCLR=1; + SciaRegs.SCIFFCT.bit.CDC=0; + SciaRegs.SCIFFCT.bit.FFTXDLY = 0;//100; + + +// SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset + SciaRegs.SCICTL1.bit.SWRESET = 1; // Relinquish SCI from Reset + + SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; + SciaRegs.SCIFFRX.bit.RXFIFORESET=1; + + EALLOW; + PieVectTable.RXAINT = &RSA_RX_Handler; + PieVectTable.TXAINT = &RSA_TX_Handler; + PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1 + PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2 + IER |= M_INT9; // Enable CPU INT + EDIS; + + SetupArrCmdLength(); + clear_buffers_rs(&rs_a); + + RS_SetControllerLeading(&rs_a,false); + + RS_LineToReceive(commnumber); // режим приема RS485 + EnableUART_Int_RX(commnumber); // разрешение прерываний UART + + RS_SetBitMode(&rs_a,9); + rs_a.RS_PrevCmd = 0; // не было никаких команд + SCIa_RX_IntClear(); + SCIa_TX_IntClear(); // clear TX FIFO interrupts + + resetup_mpu_rs(&rs_a); + + + + } + + if(commnumber==COM_2) + { +// Initialize SCI-B: +// Note: Clocks were turned on to the SCIA peripheral +// in the InitSysCtrl() function + + ScibRegs.SCIPRI.bit.FREE = 1; + ScibRegs.SCIPRI.bit.SOFT = 0; + + EALLOW; + GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5=1; + GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4=1; + GpioMuxRegs.GPBMUX.bit.C5TRIP_GPIOB14=0; + + GpioMuxRegs.GPBDIR.bit.GPIOB14=1; + + EDIS; + RS_SetLineMode(commnumber,8,'N',1); + +/////// + ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback + // No parity,8 char bits, + // async mode, idle-line protocol + + ScibRegs.SCICTL1.all = 0; +// SciaRegs.SCICTL1.bit.RXENA = 1; // enable RX, +// SciaRegs.SCICTL1.bit.TXENA = 1; // enable TX + ScibRegs.SCICTL1.bit.RXENA = 0; // disable RX, + ScibRegs.SCICTL1.bit.TXENA = 0; // disable TX + ScibRegs.SCICTL1.bit.RXERRINTENA = 1; //Receive error interrupt enabled + ScibRegs.SCICTL1.bit.TXWAKE = 0; + ScibRegs.SCICTL1.bit.SLEEP = 0; + + ScibRegs.SCICTL2.bit.TXINTENA = 0;//1; + ScibRegs.SCICTL2.bit.RXBKINTENA =0;// 1; + + + RS_SetLineSpeed(commnumber,speed_baud); /* скорость линии */ + + ScibRegs.SCICCR.bit.LOOPBKENA = 0; // Enable loop back + +// SciaRegs.SCIFFTX.all=0xC028; +//SCIFFTX + ScibRegs.SCIFFTX.bit.SCIFFENA=1; // SCI FIFO enable + + ScibRegs.SCIFFTX.bit.TXFFILIL = 0;//1; // TXFFIL4–0 Transmit FIFO interrupt level bits. Transmit FIFO will generate interrupt when the FIFO + // status bits (TXFFST4–0) and FIFO level bits (TXFFIL4–0 ) match (less than or equal to). + + ScibRegs.SCIFFTX.bit.TXFIFOXRESET=0; + ScibRegs.SCIFFTX.bit.TXFFST = 0; + ScibRegs.SCIFFTX.bit.TXFFINT = 0; + ScibRegs.SCIFFTX.bit.TXINTCLR = 0; + ScibRegs.SCIFFTX.bit.TXFFIENA = 0; // Transmit FIFO interrrupt enable + + ScibRegs.SCIFFTX.bit.SCIRST = 1; + +//SCIFFRX +// SciaRegs.SCIFFRX.all=0x0028; +// SciaRegs.SCIFFRX.all=0x0022; + ScibRegs.SCIFFRX.bit.RXFFIL = 1; // 4:0 Interrupt level + ScibRegs.SCIFFRX.bit.RXFFIENA = 1; // Interrupt enable + + ScibRegs.SCIFFCT.all=0x00; // FIFO control register + ScibRegs.SCIFFCT.bit.ABDCLR=1; + ScibRegs.SCIFFCT.bit.CDC=0; + ScibRegs.SCIFFCT.bit.FFTXDLY = 0;//100; + + ScibRegs.SCICTL1.bit.SWRESET = 1; // Relinquish SCI from Reset + ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1; + ScibRegs.SCIFFRX.bit.RXFIFORESET=1; + + EALLOW; + PieVectTable.RXBINT = &RSB_RX_Handler; + PieVectTable.TXBINT = &RSB_TX_Handler; + + PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3 + PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4 + + IER |= M_INT9; // Enable CPU INT + EDIS; + + SetupArrCmdLength(); + clear_buffers_rs(&rs_b); + + + RS_SetControllerLeading(&rs_b,false); + + RS_LineToReceive(commnumber); // режим приема RS485 + EnableUART_Int_RX(commnumber); // разрешение прерываний UART + + RS_SetBitMode(&rs_b,9); + rs_b.RS_PrevCmd = 0; // не было никаких команд + SCIb_RX_IntClear(); + SCIb_TX_IntClear(); // clear TX FIFO interrupts + + resetup_mpu_rs(&rs_b); + + } + + + + +} +#else +// +void SetupUART(char commnumber, unsigned long speed_baud) +{ + + if(commnumber==COM_1) + { +// Initialize SCI-A: +// Note: Clocks were turned on to the SCIA peripheral +// in the InitSysCtrl() function + + EALLOW; + GpioMuxRegs.GPFMUX.bit.SCIRXDA_GPIOF5=1; + GpioMuxRegs.GPFMUX.bit.SCITXDA_GPIOF4=1; + EDIS; + + RS_SetLineMode(commnumber,8,'N',1); + +// enable TX, RX, internal SCICLK, +// Disable RX ERR, SLEEP, TXWAKE + SciaRegs.SCIFFCT.bit.ABDCLR=1; + SciaRegs.SCIFFCT.bit.CDC=0; + + SciaRegs.SCICTL1.bit.RXERRINTENA=0; + SciaRegs.SCICTL1.bit.SWRESET=0; + SciaRegs.SCICTL1.bit.TXWAKE=0; + SciaRegs.SCICTL1.bit.SLEEP=0; + SciaRegs.SCICTL1.bit.TXENA=1; + SciaRegs.SCICTL1.bit.RXENA=1; + + SciaRegs.SCIFFTX.bit.SCIFFENA=0; // fifo off + SciaRegs.SCIFFRX.bit.RXFFIL=1; //Длина наименьшей команды + + EALLOW; + PieVectTable.RXAINT = &RSA_RX_Handler; + PieVectTable.TXAINT = &RSA_TX_Handler; + PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1 + PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2 + IER |= M_INT9; // Enable CPU INT + EDIS; + + SetupArrCmdLength(); + RS_SetLineSpeed(commnumber,speed_baud); /* скорость линии */ + RS_SetControllerLeading(&rs_a,false); + + RS_LineToReceive(commnumber); // режим приема RS485 + EnableUART_Int(commnumber); // разрешение прерываний UART + + RS_SetBitMode(&rs_a,9); + rs_a.RS_PrevCmd = 0; // не было никаких команд + SCI_RX_IntClear(commnumber); + + SciaRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset +// SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; +// SciaRegs.SCIFFRX.bit.RXFIFORESET=1; + } + + if(commnumber==COM_2) + { +// Initialize SCI-B: +// Note: Clocks were turned on to the SCIA peripheral +// in the InitSysCtrl() function + + EALLOW; + GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5=1; + GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4=1; + GpioMuxRegs.GPBMUX.bit.C5TRIP_GPIOB14=0; + + GpioMuxRegs.GPBDIR.bit.GPIOB14=1; + + EDIS; + RS_SetLineMode(commnumber,8,'N',1); + +// enable TX, RX, internal SCICLK, +// Disable RX ERR, SLEEP, TXWAKE + ScibRegs.SCIFFCT.bit.CDC=0; + ScibRegs.SCIFFCT.bit.ABDCLR=1; + ScibRegs.SCICTL1.bit.RXERRINTENA=0; + ScibRegs.SCICTL1.bit.SWRESET=0; + ScibRegs.SCICTL1.bit.TXWAKE=0; + ScibRegs.SCICTL1.bit.SLEEP=0; + ScibRegs.SCICTL1.bit.TXENA=1; + ScibRegs.SCICTL1.bit.RXENA=1; + + ScibRegs.SCIFFTX.bit.SCIFFENA=0; // fifo off + ScibRegs.SCIFFRX.bit.RXFFIL=1; //Длина наименьшей команды + + EALLOW; + PieVectTable.RXBINT = &RSB_RX_Handler; + PieVectTable.TXBINT = &RSB_TX_Handler; + + PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT3 + PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT4 + IER |= M_INT9; // Enable CPU INT + EDIS; + + SetupArrCmdLength(); + RS_SetLineSpeed(commnumber,speed_baud); /* скорость линии */ + RS_SetControllerLeading(&rs_b,false); + + RS_LineToReceive(commnumber); // режим приема RS485 + EnableUART_Int(commnumber); // разрешение прерываний UART + + RS_SetBitMode(&rs_b,9); + rs_b.RS_PrevCmd = 0; // не было никаких команд + SCI_RX_IntClear(commnumber); + + ScibRegs.SCICTL1.bit.SWRESET=1; // Relinquish SCI from Reset + +// SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1; +// SciaRegs.SCIFFRX.bit.RXFIFORESET=1; + + } + + +} +#endif + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +void SCI_Send(char commnumber, char bs) +{ + switch (commnumber) + { + case COM_1: SCIa_Send(bs); + break; + case COM_2: SCIb_Send(bs); + break; + } + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + + +#ifdef _USE_RS_FIFO + +void RS_Wait4OK(char commnumber) +{ + switch (commnumber) + { + case COM_1: while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}//SCIa_Wait4OK(); + break; + case COM_2: while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}//SCIb_Wait4OK(); + break; + } +} + +void RS_Wait4OK_TXRDY(char commnumber) +{ + switch (commnumber) + { + case COM_1: while (SciaRegs.SCICTL2.bit.TXEMPTY != 0) {} + break; + case COM_2: while (ScibRegs.SCICTL2.bit.TXEMPTY != 0) {} + break; + } +} + + +#else +void RS_Wait4OK(char commnumber) +{ + switch (commnumber) + { + case COM_1: SCIa_Wait4OK(); + break; + case COM_2: SCIb_Wait4OK(); + break; + } +} +#endif + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + + +void SetCntrlAddr (int cntrl_addr,int cntrl_addr_for_all) +{ + CNTRL_ADDR = cntrl_addr; + ADDR_FOR_ALL = cntrl_addr_for_all; +} + +void Poke(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned long Address; + unsigned int Data; + + Address = RS232_Arr->RS_Header[5] & 0xFF; + Address = (Address<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + Data = 0; + Data = (Data<<8) | (RS232_Arr->RS_Header[7] & 0xFF); + Data = (Data<<8) | (RS232_Arr->RS_Header[6] & 0xFF); + + WriteMemory(Address,Data); + + Answer(RS232_Arr, CMD_RS232_POKE); +} + +void Peek(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned long Address; + unsigned int Data, crc; + + Address = RS232_Arr->RS_Header[5] & 0xFF; + Address = (Address<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + Data = 0; + Data = i_ReadMemory(Address); + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = CMD_RS232_PEEK; + + RS232_Arr->buffer[2] = LOBYTE(Data); + RS232_Arr->buffer[3] = HIBYTE(Data); + RS232_Arr->buffer[4] = 0; + RS232_Arr->buffer[5] = 0; + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, 6); + + RS232_Arr->buffer[6] = LOBYTE(crc); + RS232_Arr->buffer[7] = HIBYTE(crc); + RS232_Arr->buffer[8] = 0; + RS232_Arr->buffer[9] = 0; + + RS_Send(RS232_Arr,RS232_Arr->buffer, 10); +} + +static char _GetByte(unsigned int *addr, int32 offs) +{ + unsigned int *address; + unsigned int byte; + + address = addr + offs/2; + byte = *address; + if(offs%2) return LOBYTE(byte); + else return HIBYTE(byte); +} + +void Answer(RS_DATA_STRUCT *RS232_Arr,int n) +{ + int crc; + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = n; + + crc = 0xffff; + crc = GetCRC16_IBM( crc, RS232_Arr->buffer, 2); + + RS232_Arr->buffer[2] = LOBYTE(crc); + RS232_Arr->buffer[3] = HIBYTE(crc); + + RS232_Arr->buffer[4] = 0; + RS232_Arr->buffer[5] = 0; + RS_Send(RS232_Arr,RS232_Arr->buffer, 6); +} + + + +void Load(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int rcrc, crc; + + crc = (_GetByte(RS232_Arr->pRecvPtr, RS232_Arr->RS_Length-1) << 8) + + _GetByte(RS232_Arr->pRecvPtr, RS232_Arr->RS_Length-2); + + RS232_Arr->RS_Header[0] = RS232_Arr->addr_recive; + +// CNTRL_ADDR; + RS232_Arr->RS_Header[1]=CMD_RS232_LOAD; + + rcrc = 0xffff; + rcrc = GetCRC16_IBM( rcrc, RS232_Arr->RS_Header, 2); + rcrc = GetCRC16_B( rcrc, RS232_Arr->pRecvPtr, RS232_Arr->RS_Length-2); + + if(rcrc == crc) + { + Answer(RS232_Arr,CMD_RS232_LOAD); + RS232_Arr->BS_LoadOK = true; + } + else + { + RS232_Arr->BS_LoadOK = false; + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + } +} + +void InitLoad(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned long Address; + + Address = RS232_Arr->RS_Header[5] & 0xFF; + Address = (Address<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address = (Address<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + RS232_Arr->RS_Length = RS232_Arr->RS_Header[9] & 0xFF; + RS232_Arr->RS_Length = (RS232_Arr->RS_Length<<8) | (RS232_Arr->RS_Header[8] & 0xFF); + RS232_Arr->RS_Length = (RS232_Arr->RS_Length<<8) | (RS232_Arr->RS_Header[7] & 0xFF); + RS232_Arr->RS_Length = (RS232_Arr->RS_Length<<8) | (RS232_Arr->RS_Header[6] & 0xFF); + + RS232_Arr->RS_Length += 2; + RS232_Arr->pRS_RecvPtr = (unsigned int *)Address; //(unsigned int *)Address; + RS232_Arr->pRecvPtr = (unsigned int *)Address; //(unsigned int *)Address; + + Answer(RS232_Arr,CMD_RS232_INITLOAD); +} + +int GetCommand(RS_DATA_STRUCT *RS232_Arr) +{ + int cmd; + unsigned int crc, rcrc; + + if(RS232_Arr->RS_DataReady) // Данные по RS пришли + { + RS232_Arr->RS_DataReady = false; + cmd = RS232_Arr->RS_Header[1]; // Прочитали номер команды + + // ПроверЯем длину команды длЯ считываниЯ CRC + if((RS_Len[cmd]<3) || (RS_Len[cmd]>MAX_RECEIVE_LENGTH)) + { + (RS232_Arr->count_recive_bad)++; + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + + if (RS232_Arr->RS_DataSended) + RS232_Arr->RS_DataSended = 0; + return -1; + } + if(cmd == 4) { + asm(" NOP "); + } + + if(cmd == CMD_RS232_LOAD) // Если команда загрузки + { + RS232_Arr->RS_PrevCmd = cmd; + return cmd; // Нет проверки crc + } + else // Все остальные команды + { + // Считываем crc из посылки + crc = (RS232_Arr->RS_Header[RS_Len[cmd]-1] << 8) | + (RS232_Arr->RS_Header[RS_Len[cmd]-2]) ; + } + // Рассчитываем crc из посылки + rcrc = 0xffff; + rcrc = GetCRC16_IBM( rcrc, RS232_Arr->RS_Header, (RS_Len[cmd]-2) ); + + if(crc == rcrc) // ПроверЯем crc + { + (RS232_Arr->count_recive_ok)++; + + RS232_Arr->RS_PrevCmd = cmd; + if (RS232_Arr->RS_DataSended) + { + RS232_Arr->RS_DataSended = 0; + RS232_Arr->RS_DataReadyAnswer = 1; + } + return cmd; + } + else + { + (RS232_Arr->count_recive_error_crc)++; + + RS_SetAdrAnswerController(RS232_Arr,0); + RS_SetControllerLeading(RS232_Arr, false); + + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + + if (RS232_Arr->RS_DataSended) + RS232_Arr->RS_DataSended = 0; + + } } + + return -1; +} + +void ExtendBios(RS_DATA_STRUCT *RS232_Arr) +{ + volatile unsigned long Address1,Address2; + volatile unsigned long Length, LengthW,i; + unsigned int code1,code2, crc; + + unsigned long AdrOut1,AdrOut2,LengthOut; + unsigned int cerr, repl, count_ok, return_code, old_started; + volatile unsigned int go_to_reset = 0, go_to_set_baud = 0; + unsigned long set_baud; + + //int code_eeprom; + old_started = x_parallel_bus_project.flags.bit.started; + + + + Address1 = RS232_Arr->RS_Header[5] & 0xFF; + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[4] & 0xFF); + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[3] & 0xFF); + Address1 = (Address1<<8) | (RS232_Arr->RS_Header[2] & 0xFF); + + Address2 = RS232_Arr->RS_Header[9] & 0xFF; + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[8] & 0xFF); + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[7] & 0xFF); + Address2 = (Address2<<8) | (RS232_Arr->RS_Header[6] & 0xFF); + + Length = RS232_Arr->RS_Header[13] & 0xFF; + Length = (Length<<8) | (RS232_Arr->RS_Header[12] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[11] & 0xFF); + Length = (Length<<8) | (RS232_Arr->RS_Header[10] & 0xFF); + + LengthW = Length/2; + if (LengthW*2RS_Header[14] & 0xFF; + code2=RS232_Arr->RS_Header[15] & 0xFF; + + AdrOut1 = 0; + AdrOut2 = 0; + LengthOut = 0; + + for (i=0;i<1000;i++) + { + DINT; + } + + DRTM; + DINT; + switch ( code1 ) + { + // грузим Xilinx Из flash + case 1: + x_parallel_bus_project.stop(&x_parallel_bus_project); + load_xilinx_new(0x130000,SIZE_XILINX200); + project.reload_all_plates_with_reset_no_stop_error(); + project.clear_errors_all_plates(); + if (old_started) project_start_parallel_bus(); + + + break; + + /* грузим 6713 из Flash + загрузка происходит с ресетом 2812 !!!! + */ + //case 2: select_reset28_for_load67(); break; // настройка загрузки + + // грузим Xilinx Из RAM + case 3: load_xilinx_new(0x80000,SIZE_XILINX200); break; + + //4 и 5 команда занЯты под EEPROM длЯ Slave + + case 6: + // for Spartan2 + x_parallel_bus_project.stop(&x_parallel_bus_project); + xflash_remote_eeprom(code2, Address1, Address2, LengthW,&AdrOut1,&AdrOut2,&LengthOut ); + project.reload_all_plates_with_reset_no_stop_error(); + project.clear_errors_all_plates(); + if (old_started) project_start_parallel_bus(); + break; + + case 7: + x_parallel_bus_project.stop(&x_parallel_bus_project); + xread_remote_eeprom(code2, Address1, Address2, LengthW, &AdrOut1,&AdrOut2,&LengthOut ); + project.reload_all_plates_with_reset_no_stop_error(); + project.clear_errors_all_plates(); + if (old_started) project_start_parallel_bus(); + +// xread_remote_eeprom_byte(code2, Address1, Address2, Length, &AdrOut1,&AdrOut2,&LengthOut ); + break; + case 17: + x_parallel_bus_project.stop(&x_parallel_bus_project); + xverify_remote_eeprom(code2, Address1, Address2, LengthW, &AdrOut1,&AdrOut2,&LengthOut ); + project.reload_all_plates_with_reset_no_stop_error(); + project.clear_errors_all_plates(); + if (old_started) project_start_parallel_bus(); +// xread_remote_eeprom_byte(code2, Address1, Address2, Length, &AdrOut1,&AdrOut2,&LengthOut ); + break; + + + case 8: + // reload al plates + x_parallel_bus_project.stop(&x_parallel_bus_project); + project.reload_all_plates_with_reset_no_stop_error(); + project.clear_errors_all_plates(); + if (old_started) project_start_parallel_bus(); + + break; + + + case 9: + go_to_reset = 1; +// SetLoad28_FromResetInternalFlash(); +// SelectReset28(); + + break; + + case 10: + // for Spartan6 + memWrite(code2, Address1, Address2, LengthW,&AdrOut1,&AdrOut2,&LengthOut); + break; + + case 11: + // flash со статистикой + if(!RS232_Arr->BS_LoadOK) + { + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + return; + } + + return_code = RunFlashData(Address1, Address2, LengthW, &cerr, &repl, &count_ok ); + AdrOut1 = cerr; + AdrOut2 = repl; + LengthOut = return_code+1; + + break; + + case 12: + // Verify flash со статистикой + if(!RS232_Arr->BS_LoadOK) + { + RS_LineToReceive(RS232_Arr->commnumber); // режим приема RS485 + RS_SetBitMode(RS232_Arr,9); + return; + } + + return_code = VerifyFlashData(Address1, Address2, LengthW, &cerr, &repl, &count_ok ); + AdrOut1 = cerr; + AdrOut2 = repl; + LengthOut = return_code+1; + + break; + + case 100: + go_to_set_baud = 1; + set_baud = Address1; +// SetLoad28_FromResetInternalFlash(); +// SelectReset28(); + //speed_baud = Address1; + + + break; + + + + default: break; + } + + EnableInterrupts(); + ERTM; // Enable Global realtime interrupt DBGM + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = CMD_RS232_EXTEND; + + RS232_Arr->buffer[2] = BYTE0(AdrOut1); + RS232_Arr->buffer[3] = BYTE1(AdrOut1); + RS232_Arr->buffer[4] = BYTE2(AdrOut1); + RS232_Arr->buffer[5] = BYTE3(AdrOut1); + + RS232_Arr->buffer[6] = BYTE0(AdrOut2); + RS232_Arr->buffer[7] = BYTE1(AdrOut2); + RS232_Arr->buffer[8] = BYTE2(AdrOut2); + RS232_Arr->buffer[9] = BYTE3(AdrOut2); + + RS232_Arr->buffer[10] = BYTE0(LengthOut); + RS232_Arr->buffer[11] = BYTE1(LengthOut); + RS232_Arr->buffer[12] = BYTE2(LengthOut); + RS232_Arr->buffer[13] = BYTE3(LengthOut); + + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, 14); + + RS232_Arr->buffer[14] = LOBYTE(crc); + RS232_Arr->buffer[15] = HIBYTE(crc); + RS232_Arr->buffer[16] = 0; + RS232_Arr->buffer[17] = 0; + + RS_Send(RS232_Arr,RS232_Arr->buffer, 18); + + + if (go_to_reset) + { + for (i=0;i<2;i++) + DELAY_US(1000000); + + DRTM; + DINT; + + for (i=0;i<2;i++) + DELAY_US(1000000); + + SetLoad28_FromResetInternalFlash(); + SelectReset28(); + + go_to_reset = 0; + + } + + + if (go_to_set_baud) + { + // for (i=0;i<2;i++) + DELAY_US(1000000); + +// DRTM; +// DINT; + +// for (i=0;i<2;i++) +// DELAY_US(1000000); + + RS_SetLineSpeed(RS232_Arr->commnumber, set_baud); /* скорость линии */ + + go_to_set_baud = 0; + + } + return; + +} + +void create_uart_vars(char size_cmd15_set, char size_cmd16_set) +{ + + size_cmd15=size_cmd15_set; + size_cmd16=size_cmd16_set; + + rs_a.commnumber=COM_1; + rs_b.commnumber=COM_2; + +} + + + + +////////////////////////////////////////////////////// +/// +////////////////////////////////////////////////////// +int RS_Send(RS_DATA_STRUCT *RS232_Arr,unsigned int *pBuf,unsigned long len) +{ + unsigned int i; + + + if (RS232_Arr->RS_DataWillSend) + { +// RS232_Arr->RS_DataReadyAnswer = 0; + RS232_Arr->RS_DataReadyAnswer = 0; + RS232_Arr->RS_DataSended = 0; + } + + //for (i=0; i <= 30000; i++){} /* Пауза длЯ PC 30000*/ + + RS_LineToSend(RS232_Arr->commnumber); /* режим передачи RS485 */ + + //for (i=0; i <= 10000; i++){} /* Пауза длЯ PC10000 */ + + RS232_Arr->RS_SLength = len; /* Настраиваем переменные */ +// RS232_Arr->pRS_SendPtr = pBuf + 1; + RS232_Arr->pRS_SendPtr = pBuf; + + RS232_Arr->RS_SendBlockMode = BM_CHAR32; + +// RS_Wait4OK(RS232_Arr->commnumber); /* ДожидаемсЯ ухода */ + RS_SetBitMode(RS232_Arr,8); /* Остальные в 8-бит режиме */ + + RS232_Arr->RS_SendLen = 0; /* Два байта уже передали */ + +// if(len > 1) +// { + EnableUART_Int_TX(RS232_Arr->commnumber); /* Разрешаем прерываниЯ по передаче */ + // SCI_Send(RS232_Arr->commnumber, *pBuf); // Передаем второй байт по прерыванию +// } +// else +// { +// SCI_Send(RS232_Arr->commnumber, *pBuf); // Передаем второй байт по прерыванию +// RS_Wait4OK(RS232_Arr->commnumber); /* ДожидаемсЯ ухода без прерываниЯ */ +// for (i=0; i <= TIME_WAIT_RS232_BYTE_OUT; i++){} /* Пауза длЯ PC */ +// RS_SetBitMode(RS232_Arr,9); /* Обратно в 9-бит режим */ +// RS_LineToReceive(RS232_Arr->commnumber); /* режим приема RS485 */ +// } + return 0; +} + +void RS232_TuneUp(unsigned long speed_baud_a, unsigned long speed_baud_b) +{ +#if (USE_TEST_TERMINAL) + create_uart_vars(sizeof(CMD_TO_TMS_STRUCT), sizeof(CMD_TO_TMS_TEST_ALL_STRUCT)); +#else + create_uart_vars(100, 100); +#endif + + SetupUART(COM_1, speed_baud_a); + SetupUART(COM_2, speed_baud_b); +} + + +void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsigned int enable_int_timeout) +{ + + if (enable_int_timeout) + inc_RS_timeout_cicle(); + + if (enable_rs_a) + { + resetup_rs_on_timeout_lost(COM_1); + switch (GetCommand(&rs_a)) + { + case CMD_RS232_INIT: break; + + case CMD_RS232_INITLOAD: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + InitLoad(&rs_a); + break; + + case CMD_RS232_LOAD: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + Load(&rs_a); + break; + + case CMD_RS232_RUN: break; + + case CMD_RS232_PEEK: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + Peek(&rs_a); + //Led1_Toggle(); + break; + +//#if USE_MODBUS_TABLE_SVU +// case CMD_RS232_MODBUS_3: +// if (rs_a.flag_LEADING) +// ReceiveAnswerCommandModbus3(&rs_a); +// else +// ReceiveCommandModbus3(&rs_a); +// break; +// case CMD_RS232_MODBUS_16: +// if (rs_a.flag_LEADING) +// ReceiveAnswerCommandModbus16(&rs_a); +// else +// ReceiveCommandModbus16(&rs_a); +// break; +//#endif + +#if (USE_TEST_TERMINAL) + case CMD_RS232_STD: + rs_a.RS_DataReadyRequest = 1; + flag_special_mode_rs = 0; + ReceiveCommand(&rs_a); + break; + + case CMD_RS232_TEST_ALL: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + ReceiveCommandTestAll(&rs_a); + break; +#endif + case CMD_RS232_POKE: + if (disable_flag_special_mode_rs) + break; + + + flag_special_mode_rs = 1; + Poke(&rs_a); + Led2_Toggle(); + break; + case CMD_RS232_UPLOAD: +// flag_special_mode_rs = 1; + Upload(&rs_a); + break; + case CMD_RS232_TFLASH: + if (disable_flag_special_mode_rs) + break; + + + flag_special_mode_rs = 1; + T_Flash(&rs_a); + break; + case CMD_RS232_EXTEND: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + ExtendBios(&rs_a); + break; + + default: break; + } // end switch + } // end if (enable_rs_a) + + + if (enable_rs_b) + { + resetup_rs_on_timeout_lost(COM_2); + switch (GetCommand(&rs_b)) + { + case CMD_RS232_INIT: break; + + case CMD_RS232_INITLOAD: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + InitLoad(&rs_b); + break; + + case CMD_RS232_LOAD: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + Load(&rs_b); + break; + + case CMD_RS232_RUN: break; + case CMD_RS232_PEEK: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + Peek(&rs_b); + break; + +#if USE_MODBUS_TABLE_SVU + + case CMD_RS232_MODBUS_1: + if (rs_b.flag_LEADING) + { + ModbusRTUreceiveAnswer1(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + break; + case CMD_RS232_MODBUS_3: + if (rs_b.flag_LEADING) + { + ModbusRTUreceiveAnswer3(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + else + ModbusRTUreceive3(&rs_b); + + break; + case CMD_RS232_MODBUS_4: + if (rs_b.flag_LEADING) + { + + ModbusRTUreceiveAnswer4(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + else + ModbusRTUreceive4(&rs_b); + break; + case CMD_RS232_MODBUS_5: + + if (rs_b.flag_LEADING) + { + ModbusRTUreceiveAnswer5(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + break; + case CMD_RS232_MODBUS_6: + + + + if (rs_b.flag_LEADING) + { + ModbusRTUreceiveAnswer6(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + break; + + + case CMD_RS232_MODBUS_15: + if (rs_b.flag_LEADING) + { +//#if (USE_CONTROL_STATION==1) +// control_station.count_error_modbus_15[CONTROL_STATION_INGETEAM_PULT_RS485]--; +//#endif + ModbusRTUreceiveAnswer15(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + else + ModbusRTUreceive15(&rs_b); + + break; + case CMD_RS232_MODBUS_16: + if (rs_b.flag_LEADING) + { +//#if (USE_CONTROL_STATION==1) +// control_station.count_error_modbus_16[CONTROL_STATION_INGETEAM_PULT_RS485]--; +//#endif + ModbusRTUreceiveAnswer16(&rs_b); + rs_b.RS_DataReadyAnswerAnalyze = 1; + rs_b.RS_DataReadyRequest = 1; + } + else + ModbusRTUreceive16(&rs_b); + break; + +#endif + +#if (USE_TEST_TERMINAL) + case CMD_RS232_STD: flag_special_mode_rs = 0; + ReceiveCommand(&rs_b); + break; + case CMD_RS232_TEST_ALL: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + ReceiveCommandTestAll(&rs_b); + break; +#endif + case CMD_RS232_POKE: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + Poke(&rs_b); + break; + case CMD_RS232_UPLOAD: +// flag_special_mode_rs = 1; + + Upload(&rs_b); + break; + case CMD_RS232_TFLASH: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + T_Flash(&rs_b); + break; + case CMD_RS232_EXTEND: + if (disable_flag_special_mode_rs) + break; + + flag_special_mode_rs = 1; + ExtendBios(&rs_b); + break; + + default: break; + } // end switch + } // end if (enable_rs_b) + +} + diff --git a/Inu/Src2/N12_Xilinx/RS_Functions.h b/Inu/Src2/N12_Xilinx/RS_Functions.h new file mode 100644 index 0000000..e98725e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_Functions.h @@ -0,0 +1,142 @@ +#ifndef _RS_FUNCTIONS_H +#define _RS_FUNCTIONS_H + + +#define MAX_RECEIVE_LENGTH 254 +#define MAX_SEND_LENGTH 400 //266 //254 + +#define CMD_RS232_MODBUS_1 1 +#define CMD_RS232_MODBUS_3 3 +#define CMD_RS232_MODBUS_4 4 +#define CMD_RS232_MODBUS_5 5 +#define CMD_RS232_MODBUS_6 6 +#define CMD_RS232_MODBUS_15 15 +#define CMD_RS232_MODBUS_16 16 + +#define RS_TIME_OUT 6000 +#define RS_TIME_OUT_MPU 6000//6000 // ожидание ответа от МПУ +#define RS_TIME_OUT_HMI 1000 +#define RS_TIME_OUT_MAX 10000 +#define RS_TIME_OUT_LOST 1000 + + + +typedef unsigned char CHAR; + +// Message RS declaration +typedef struct { + unsigned int commnumber; // Номер порта + unsigned long RS_Length; // Длина пакета + + unsigned int *pRS_RecvPtr; // Буфер приема + unsigned int *pRS_SendPtr; // Буфер посылки + unsigned int *pRS_SendPtr_stage1; // Буфер посылки + unsigned int *pRS_SendPtr_stage2; // Буфер посылки + unsigned int *pRecvPtr; + + unsigned int RS_PrevCmd; // ПредыдущаЯ комманда + unsigned int RS_Cmd; // ТекущаЯ комманда + unsigned int RS_Header[MAX_RECEIVE_LENGTH]; // Заголовок + + unsigned int flag_TIMEOUT_to_Send; // Флаг ожиданиЯ таймаута на отсылку + unsigned int flag_TIMEOUT_to_Receive; // Флаг ожиданиЯ таймаута на прием + unsigned int RS_DataReady; // Флаг готовности RS данных + unsigned int buffer[MAX_SEND_LENGTH]; // Буфер длЯ отсылки по RS + unsigned int buffer_stage1[8]; // Буфер длЯ отсылки по RS +// unsigned int buffer_stage2[8]; // Буфер длЯ отсылки по RS + + unsigned int addr_answer; // адрес куда отвечать в режиме ведущего + unsigned int addr_recive;// адрес по которому нас запросили + unsigned int flag_LEADING; // Флаг режима контроллера (по умолчанию ведомый) + unsigned long RS_RecvLen; + unsigned long RS_SLength; // Длина пакета длЯ посылки + unsigned long RS_SendLen; // Количество байт уже передали + + unsigned long RS_SLength_stage1; // Длина пакета длЯ посылки + unsigned long RS_SLength_stage2; // Длина пакета длЯ посылки + + unsigned int time_wait_rs_out; + unsigned int time_wait_rs_out_mpu; + unsigned int time_wait_rs_lost; // слишком большая пауза между байтами - есть потеря!!! + + + char RS_SendBlockMode; /* Режим передачи */ + char RS_SendBlockMode_stage1; /* Режим передачи */ + char RS_SendBlockMode_stage2; /* Режим передачи */ + char RS_Flag9bit; /* длЯ RS485???????? */ + + int BS_LoadOK;/** Флаг успешности приема блока */ + int RS_FlagBegin; + int RS_HeaderCnt; + int RS_FlagSkiping; + + int RS_DataReadyAnswer; // флаг, что мы получили ответ на свой запрос, если мы мастер + int RS_DataReadyAnswerAnalyze; // флаг, что мы получили ответ на свой запрос, если мы мастер и обработали его + + int RS_DataSended; // флаг, что мы отправили свой запрос, ждем ответ и мы мастер + int RS_DataWillSend; // флаг, что мы подготовили свой запрос и сейчас начнем его передавать и мы мастер + + int RS_DataReadyRequest; // флаг, что мы получили запрос, если мы слейв + int RS_DataReadyFullUpdate; // флаг, что мы получили ответы и массив полностью обновился + + int RS_OnTransmitedData ; // флаг что мы еще передаем запрошенные данные + int current_tx_stage; + int cmd_tx_stage; + + unsigned int count_recive_ok; // принято посылок с валидным crc, + unsigned int count_recive_error_crc; // ошибок crc + unsigned int count_recive_dirty; // принято посылок до расчета crc, совпала только длина и код команды + unsigned int count_recive_bad; // принято посылок c неправильным форматом + unsigned int count_recive_bytes_all; // принято всего байт + unsigned int count_recive_bytes_skipped; // пропущено всего байт + unsigned int count_recive_cmd_skipped; // пропущено всего посылок + unsigned int count_recive_rxerror; // ошибки по прерыванию + + unsigned int do_resetup_rs; // выполнить пересброс порта при ошибках. + + int RS_DataWillSend2; // флаг2, что мы подготовили свой запрос и сейчас начнем его передавать и мы мастер + + + + + } RS_DATA_STRUCT; + +#define RS_DATA_STRUCT_DEFAULT {0,0,0,0,0,0,0,0,0,{0}, 0,0,0,{0},{0}, 0,0,0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0, 0,0,0, 0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0} +////////////////////////////////////////////////////////// + +#define TMS_TO_TERMINAL_TEST_ALL_STRUCT_DEFAULT {{0}, {0}, {0}, 0, 0, 0} + +enum { + CMD_RS232_LOAD = 51, CMD_RS232_UPLOAD, CMD_RS232_RUN, CMD_RS232_XFLASH, CMD_RS232_TFLASH, + CMD_RS232_PEEK, CMD_RS232_POKE, CMD_RS232_INITLOAD, CMD_RS232_INIT,CMD_RS232_EXTEND, + CMD_RS232_VECTOR = 61, CMD_RS232_IMPULSE, CMD_RS232_STD = 65, CMD_RS232_TEST_ALL, CMD_RS232_STD_ANS, + CMD_RS232_LAST + }; + +//enum { +// false = 0, true +// }; + +#define RS_LEN_CMD CMD_RS232_LAST + +//extern RS_DATA_STRUCT RS232_A, RS232_B; +extern RS_DATA_STRUCT rs_a,rs_b; + +int RS_Send(RS_DATA_STRUCT *rs_arr,unsigned int *pBuf,unsigned long len); +void RS232_WorkingWith(unsigned int enable_rs_a, unsigned int enable_rs_b, unsigned int enable_int_timeout); +void RS232_TuneUp(unsigned long speed_baud_a, unsigned long speed_baud_b); +void inc_RS_timeout_cicle(void); +void resetup_rs_on_timeout_lost(int rsp); + +void resetup_rs(RS_DATA_STRUCT *rs_arr); +void resetup_mpu_rs(RS_DATA_STRUCT *rs_arr); +int test_rs_live(RS_DATA_STRUCT *rs_arr); +void RS_SetControllerLeading(RS_DATA_STRUCT *RS232_Arr,int boool); +void RS_SetAdrAnswerController(RS_DATA_STRUCT *RS232_Arr,int set_addr_answer); +void SetCntrlAddr (int cntrl_addr,int cntrl_addr_for_all); + +extern float KmodTerm, freqTerm; +extern unsigned int RS_Len[RS_LEN_CMD]; +extern int flag_special_mode_rs, disable_flag_special_mode_rs; + +#endif diff --git a/Inu/Src2/N12_Xilinx/RS_modbus_svu.c b/Inu/Src2/N12_Xilinx/RS_modbus_svu.c new file mode 100644 index 0000000..c254171 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_modbus_svu.c @@ -0,0 +1,328 @@ +#include "RS_modbus_svu.h" + +#include +#include + +#include "modbus_table_v2.h" +#include "options_table.h" +#include "DSP281x_Device.h" +#include "CRC_Functions.h" +#include "MemoryFunctions.h" +#include "RS_Functions.h" + + +int err_modbus3 = 1; +int err_modbus16 = 1; +int cmd_3_or_16 = 0; +int err_send_log_16 = 0; //Switch between command 3 and 16 +unsigned int flag_send_answer_rs = 0; //This flag enables fast answer to SVU when values changed + + +unsigned int adr_read_from_modbus3 = 0; +unsigned int flag_received_first_mess_from_MPU = 0; + + + + +void ReceiveCommandModbus3(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, Address_MB, Length_MB, i/*, Data*/; +// int buf_out[200]; + +/* получили начальный адрес чтениy. */ + Address_MB =(RS232_Arr->RS_Header[2] << 8) | RS232_Arr->RS_Header[3]; + +/* получили количество слов данных */ + Length_MB = (RS232_Arr->RS_Header[4] << 8 ) | RS232_Arr->RS_Header[5]; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + +// f.RScount = SECOND*3; + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; //CNTRL_ADDR; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_3; + RS232_Arr->buffer[2] = Length_MB*2; + + for (i=0;i=ADR_MODBUS_TABLE && Address_MB<0xe00) + { + RS232_Arr->buffer[3+i*2 ]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.HB; + RS232_Arr->buffer[3+i*2+1]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.LB; + } + + if (Address_MB>=0xe00 && Address_MB<0xf00) + { + RS232_Arr->buffer[3+i*2 ]=options_controller[Address_MB-0xe00+i].byte.HB; + RS232_Arr->buffer[3+i*2+1]=options_controller[Address_MB-0xe00+i].byte.LB; + } + + } + + crc = 0xffff; + crc = GetCRC16_IBM(crc, RS232_Arr->buffer, Length_MB*2+3); + + RS232_Arr->buffer[Length_MB*2+3] = LOBYTE(crc); + RS232_Arr->buffer[Length_MB*2+4] = HIBYTE(crc); + + RS232_Arr->buffer[Length_MB*2+5] = 0; + RS232_Arr->buffer[Length_MB*2+6] = 0; + RS_Send(RS232_Arr,RS232_Arr->buffer, Length_MB*2+7); + + return; +} + +/***************************************************************/ +/***************************************************************/ +/* Запрос данных по протоколу ModBus - команда 3 + Чтение Ячеек данных */ +/***************************************************************/ +/***************************************************************/ +void SendCommandModbus3(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start,unsigned int count_word) +{ + // КонтрольнаЯ сумма + unsigned int crc; //, Address_MB, Length_MB, i, Data; +// int buf_out[200]; +// int buf_in[200]; + +// rs_arr->buffer[0]= + rs_arr->buffer[0] = LOBYTE(adr_contr); + rs_arr->buffer[1] = CMD_RS232_MODBUS_3; + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + rs_arr->buffer[4] = 0; + rs_arr->buffer[5] = LOBYTE(count_word); + + crc = 0xffff; + crc = GetCRC16_IBM( crc, rs_arr->buffer, 6); +// crc = get_crc_ccitt( crc, rs_arr->buffer, 6); + + + rs_arr->buffer[6] = LOBYTE(crc); + rs_arr->buffer[7] = HIBYTE(crc); + + rs_arr->buffer[8] = 0; + rs_arr->buffer[9] = 0; + + RS_Send(rs_arr,rs_arr->buffer, 11); + + /* ждем ответа */ + if (adr_contr>0 && adr_contr<0xff) + { + + RS_Len[CMD_RS232_MODBUS_3]=5+count_word*2; + + adr_read_from_modbus3=adr_start; + RS_SetControllerLeading(rs_arr,true); + RS_SetAdrAnswerController(rs_arr,adr_contr); + + } + + + return; +} + + +void ReceiveCommandModbus16(RS_DATA_STRUCT *RS232_Arr) +{ + // Контрольнаy сумма + unsigned int crc, Address_MB, Length_MB, Bytecnt_MB, i/*, Data1,Data2,Quantity*/; + int /*Data,*/i1,i2; + +/* получили начальный адрес чтениy. */ + Address_MB = RS232_Arr->RS_Header[3] | ( RS232_Arr->RS_Header[2] << 8); + +/* получили quantity. */ + //Quantity = RS232_Arr->RS_Header[5] | ( RS232_Arr->RS_Header[4] << 8); + +/* получили количество байт данных */ +// Length_MB = (RS232_Arr->RS_Header[4] << 8 ) | RS232_Arr->RS_Header[5]; + + Bytecnt_MB = RS232_Arr->RS_Header[6]; + + Length_MB = Bytecnt_MB>>1; + + + for (i=0;i=ADR_MODBUS_TABLE && Address_MB<0xe00) + { + RS232_Arr->buffer[3+i*2 ]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.HB; + RS232_Arr->buffer[3+i*2+1]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.LB; + } + + if (Address_MB>=0xe00 && Address_MB<0xf00) + { + options_controller[Address_MB-0xe00+i].byte.HB=RS232_Arr->RS_Header[7+i*2 ]; + options_controller[Address_MB-0xe00+i].byte.LB=RS232_Arr->RS_Header[7+i*2+1]; + } + + } + + + if (Address_MB>=0xe00 && Address_MB<0xf00) + { + i1 = options_controller[0].all; + i2 = options_controller[1].all; + store_data_flash(options_controller,sizeof(options_controller)); + SetCntrlAddr(i1, i2); /* Установка адреса контроллера */ + } + + + ///////////////////////////////////////////////// + // Отсылка + // Посчитали контрольную сумму перед самой посылкой + + RS232_Arr->buffer[0] = RS232_Arr->addr_recive; + RS232_Arr->buffer[1] = CMD_RS232_MODBUS_16; + RS232_Arr->buffer[2] = HIBYTE(Address_MB); + RS232_Arr->buffer[3] = LOBYTE(Address_MB); + RS232_Arr->buffer[4] = 0; + RS232_Arr->buffer[5] = 2; + + crc = 0xffff; + crc = GetCRC16_IBM( crc, RS232_Arr->buffer, 6); + + RS232_Arr->buffer[6] = LOBYTE(crc); + RS232_Arr->buffer[7] = HIBYTE(crc); + + RS232_Arr->buffer[8] = 0; + RS232_Arr->buffer[9] = 0; + RS_Send(RS232_Arr,RS232_Arr->buffer, 10); + + return; + + +} +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ +/* Передача данных по протоколу ModBus - команда 16 + Передача данных */ +/***************************************************************/ +/***************************************************************/ +/***************************************************************/ + +void SendCommandModbus16(RS_DATA_STRUCT *rs_arr,int adr_contr, unsigned int adr_start,unsigned int count_word) +{ + + // КонтрольнаЯ сумма + unsigned int crc, Address_MB, i; //, Length_MB; //, Bytecnt_MB, Data1,Data2; +// int Data, digital, ust_I, ust_Time; + + //Length_MB = count_word; + Address_MB = adr_start; + + + // Отсылка + // Посчитали контрольную сумму перед самой посылкой + + rs_arr->buffer[0] = adr_contr; + rs_arr->buffer[1] = CMD_RS232_MODBUS_16; + + rs_arr->buffer[2] = HIBYTE(adr_start); + rs_arr->buffer[3] = LOBYTE(adr_start); + + rs_arr->buffer[4] = HIBYTE(count_word); + rs_arr->buffer[5] = LOBYTE(count_word); + + rs_arr->buffer[6] = LOBYTE(count_word*2); + + + + for (i=0;ibuffer[7+i*2 ]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.HB; + rs_arr->buffer[7+i*2+1]=modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].byte.LB;//LOBYTE(buffer_out_data[Address_MB+i]); + } + + crc = 0xffff; +// crc = get_crc_ccitt(crc, rs_arr->buffer, Length_MB*2+7); + crc = GetCRC16_IBM(crc, rs_arr->buffer, (unsigned long)(count_word*2+7)); + + rs_arr->buffer[count_word*2+7] = LOBYTE(crc); + rs_arr->buffer[count_word*2+8] = HIBYTE(crc); + + rs_arr->buffer[count_word*2+9] = 0; + rs_arr->buffer[count_word*2+10] = 0; + + RS_Send(rs_arr,rs_arr->buffer,( count_word*2+10+2)); + + + // ждем ответа + if (adr_contr>0 && adr_contr<0xff) + { + RS_Len[CMD_RS232_MODBUS_16]=8; + RS_SetControllerLeading(rs_arr,true); + RS_SetAdrAnswerController(rs_arr,adr_contr); + } + +} + + +void ReceiveAnswerCommandModbus3(RS_DATA_STRUCT *RS232_Arr) +{ + unsigned int Address_MB, Length_MB, i; + MODBUS_REG_STRUCT elementData; + +/* получили начальный адрес чтениЯ. */ + Address_MB = adr_read_from_modbus3; + +/* получили количество слов данных */ + Length_MB = RS232_Arr->RS_Header[2] >> 1; + + ///////////////////////////////////////////////// + // Отсылка + /* Посчитали контрольную сумму перед самой посылкой */ + + for (i=0;iRS_Header[3+i*2]; + elementData.byte.LB = RS232_Arr->RS_Header[3+i*2+1]; + if (elementData.all != modbus_table_rs_in[Address_MB-ADR_MODBUS_TABLE+i].all) { + flag_send_answer_rs = 1; + } + modbus_table_rs_in[Address_MB-ADR_MODBUS_TABLE+i].all = elementData.all; + // modbus_table_rs_in[Address_MB-ADR_MODBUS_TABLE+i].byte.HB=RS232_Arr->RS_Header[3+i*2]; + // modbus_table_rs_in[Address_MB-ADR_MODBUS_TABLE+i].byte.LB=RS232_Arr->RS_Header[3+i*2+1]; + //Commented, because of out table can be rewrited before new value had been sent to SVO + modbus_table_rs_out[Address_MB-ADR_MODBUS_TABLE+i].all = modbus_table_rs_in[Address_MB-ADR_MODBUS_TABLE+i].all; + } + + + RS_SetControllerLeading(RS232_Arr,false); + RS_SetAdrAnswerController(RS232_Arr, 0); + err_modbus3=0; + cmd_3_or_16=1; + flag_received_first_mess_from_MPU=1; + return; +} + +void ReceiveAnswerCommandModbus16(RS_DATA_STRUCT *RS232_Arr) +{ + // КонтрольнаЯ сумма + //unsigned int crc, Address_MB, Length_MB, Bytecnt_MB/*, i, Data1,Data2*/; + //int Data, digital, ust_I, ust_Time; + +/* получили начальный адрес чтениЯ. */ + //Address_MB = RS232_Arr->RS_Header[3] | ( RS232_Arr->RS_Header[2] << 8); + +/* получили количество слов данных */ + //Length_MB = (RS232_Arr->RS_Header[4] << 8 ) | RS232_Arr->RS_Header[5]; + + //Bytecnt_MB = RS232_Arr->RS_Header[6]; + + RS_SetAdrAnswerController(RS232_Arr,0); + RS_SetControllerLeading(RS232_Arr,false); + err_modbus16 = 0; + cmd_3_or_16 = 0; + flag_received_first_mess_from_MPU=1; + return; +} + + + + diff --git a/Inu/Src2/N12_Xilinx/RS_modbus_svu.h b/Inu/Src2/N12_Xilinx/RS_modbus_svu.h new file mode 100644 index 0000000..a6a3d88 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/RS_modbus_svu.h @@ -0,0 +1,27 @@ +#ifndef _RS_MODBUS_SVU_H +#define _RS_MODBUS_SVU_H + +#include "RS_Functions.h" + +void ReceiveCommandModbus3(RS_DATA_STRUCT *RS232_Arr); +void ReceiveCommandModbus16(RS_DATA_STRUCT *RS232_Arr); +void SendCommandModbus3(RS_DATA_STRUCT *rs_arr, int adr_contr, unsigned int adr_start,unsigned int count_word); +void SendCommandModbus16(RS_DATA_STRUCT *rs_arr,int adr_contr, unsigned int adr_start,unsigned int count_word); +void ReceiveAnswerCommandModbus3(RS_DATA_STRUCT *RS232_Arr); +void ReceiveAnswerCommandModbus16(RS_DATA_STRUCT *RS232_Arr); + + +extern int err_modbus3; +extern int err_modbus16; +extern int cmd_3_or_16; +extern int err_send_log_16; +extern unsigned int flag_received_first_mess_from_MPU; + +extern unsigned int flag_send_answer_rs; + +extern unsigned int adr_read_from_modbus3; + + + +#endif + diff --git a/Inu/Src2/N12_Xilinx/Spartan2E_Adr.h b/Inu/Src2/N12_Xilinx/Spartan2E_Adr.h new file mode 100644 index 0000000..e8c5b2b --- /dev/null +++ b/Inu/Src2/N12_Xilinx/Spartan2E_Adr.h @@ -0,0 +1,90 @@ +#ifndef _SPARTAN2E_ADR_H +#define _SPARTAN2E_ADR_H + +// EEPROM +#define ADR_CONTR_REG_FOR_WRITE 0x2020 +#define ADR_CONTR_REG_FOR_READ 0x2028 + +//serial bus +#define ADR_SERIAL_BUS_DATA_WRITE 0x200A +#define ADR_SERIAL_BUS_CMD 0x200B + +#define ADR_SERIAL_BUS_DATA_READ 0x200F + +//Er workith +#define ADR_BUS_ERROR_READ 0x2012 +#define ADR_ERRORS_TOTAL_INFO 0x2026 + + +//parallel bus +#define ADR_PARALLEL_BUS_CMD 0x200C +#define ADR_PARALLEL_BUS_ADR_TABLE 0x200D +#define ADR_PARALLEL_BUS_SET_TABLE 0x200E + +//async bus +#define ADR_ASYNC_BUS_TABLE 0x2029 + + +//build, test +#define ADR_CONTROLLER_BUILD 0x2014 +#define ADR_XTEST_REG 0x2013 + + +// adr free block in memory TMS +#define ADR_FIRST_FREE 0x2040 +#define ADR_LAST_FREE 0x207F + + +//hwp +#define ADR_HWP_SERVICE_0 0x2009 +#define ADR_HWP_SERVICE_1 0x2008 +#define ADR_HWP_DATA_RECEVED_0 0x2010 +#define ADR_HWP_DATA_RECEVED_1 0x2011 +#define ADR_HWP_TEST_TIMER 0x2027 + +//sensor rotor +#define ADR_SENSOR_S1_T_PERIOD 0x2015 +#define ADR_SENSOR_S1_COUNT_IMPULS 0x2016 + +#define ADR_SENSOR_S2_T_PERIOD 0x2017 +#define ADR_SENSOR_S2_COUNT_IMPULS 0x2018 + +#define ADR_SENSOR_CMD 0x2019 + +#define ADR_SENSOR_S1_T_PERIOD_LOW_ONE_IMPULS 0x2021 +#define ADR_SENSOR_S1_T_PERIOD_HIGH_ONE_IMPULS 0x2022 +#define ADR_SENSOR_S2_T_PERIOD_LOW_ONE_IMPULS 0x2023 +#define ADR_SENSOR_S2_T_PERIOD_HIGH_ONE_IMPULS 0x2024 + +//pwm + +#define ADR_PWM_WDOG 0x2025 + +#define ADR_PWM_DIRECT 0x2000 +#define ADR_PWM_DIRECT2 0x2030 +#define ADR_PWM_DRIVE_MODE 0x2001 +#define ADR_PWM_DEAD_TIME 0x2002 +#define ADR_PWM_KEY_NUMBER 0x2003 +#define ADR_PWM_PERIOD 0x2004 +#define ADR_PWM_SAW_DIRECT 0x2005 +#define ADR_PWM_START_STOP 0x2006 +#define ADR_PWM_TIMING 0x2007 + +#define ADR_SAW_REQUEST 0x2031 +#define ADR_SAW_VALUE 0x2032 +#define ADR_TK_MASK_0 0x2033 +#define ADR_TK_MASK_1 0x2034 +#define ADR_PWM_IT_TYPE 0x2035 + + + +//optical bus +#define SI_OPTICS_WORD_TO_SEND_1 0x2036 +#define SI_OPTICS_WORD_TO_SEND_2 0x2037 +#define SI_OPTICS_WORD_TO_SEND_3 0x2038 +#define SI_OPTICS_WORD_TO_SEND_4 0x2039 + + + +#endif + diff --git a/Inu/Src2/N12_Xilinx/Spartan2E_Functions.c b/Inu/Src2/N12_Xilinx/Spartan2E_Functions.c new file mode 100644 index 0000000..9da7fa4 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/Spartan2E_Functions.c @@ -0,0 +1,896 @@ +#include + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +//#include "xerror.h" + +//#include "SpaceVectorPWM.h" +//#include "v_pwm24_v2.h" +//#include "PWMTools.h" + + + +#define SelectLoadXilinx() WriteOper(0,0,0,1) + +//#define TypeAccess_Is_SerialBus 21 + +#define dat_xilinx_line_do(bitb) \ + GpioDataRegs.GPEDAT.bit.GPIOE0=bitb + +#define setup_xilinx_line_do_on() \ + GpioMuxRegs.GPEDIR.bit.GPIOE0=1;\ + GpioDataRegs.GPEDAT.bit.GPIOE0=1 + +#define reset_xilinx() WriteOper(1,1,0,1) + +#define XSEEPROM_WRITE_REPEAT 3 +#define XSEEPROM_READ_REPEAT 3 +#define XSEEPROM_MAX_ERROR_CONSECUTIVE_FRAME 20 // threshold +#define XSEEPROM_MIN_LENTH 7 // max 7 => 1 word = 2 byte + +#define XSEEPROM_MAX_ERROR_CONSECUTIVE_BREAK (XSEEPROM_MAX_ERROR_CONSECUTIVE_FRAME + 10) + +#define xseeprom_pause { } + +#pragma DATA_SECTION(xeeprom_controll_fast,".fast_vars"); +unsigned int xeeprom_controll_fast; + +//XSerial_bus XSerial_bus0; +//Xmemory_uni Xmemory_uni0; + +//XSerial_bus_stats XSerial_bus_stats0; + +#pragma DATA_SECTION(Controll, ".fast_vars"); +XControll_reg Controll; + +unsigned int xeeprom_controll_store; + +void write_bit_xilinx(unsigned char bitb); +int xseeprom_read_all(unsigned int Mode_is_Verify, XSeeprom_t * Ptr); +int xseeprom_write_all(XSeeprom_t * Ptr); +void xseeprom_adr(unsigned int adr); +//unsigned int xseeprom_case_xilinx (void); +void xseeprom_delay(void); +void xseeprom_init(void); +void xControll_wr(); +unsigned int xseeprom_read_byte(unsigned int use_ack); +void xseeprom_set_mode_ON (unsigned int set_mode); +void xseeprom_start(void); +void xseeprom_stop(void); +void xseeprom_undo (void); +unsigned int xseeprom_write_byte(unsigned int byte); +void xseeprom_clk (unsigned int clk); +unsigned int xseeprom_din (void); +void xseeprom_dout (unsigned int data); +void xseeprom_mode_wr (unsigned int mode); +void ResetPeriphPlane(); + + +unsigned int time = 0; + +void write_byte_xilinx(unsigned char bx) +{ + int i; + + for (i=0;i<=7;i++) + write_bit_xilinx( (bx >> i) & 1); + +} + +void write_bit_xilinx(unsigned char bitb) +{ + pause_1000(1); + EALLOW; + + GpioDataRegs.GPBDAT.bit.GPIOB8=1; + dat_xilinx_line_do(bitb); + + pause_1000(1); + GpioDataRegs.GPBDAT.bit.GPIOB8=0; + + pause_1000(1); + GpioDataRegs.GPBDAT.bit.GPIOB8=1; + EDIS; +} + +void setup_xilinx_line() +{ + EALLOW; + GpioMuxRegs.GPBMUX.bit.CAP4Q1_GPIOB8=0; + GpioMuxRegs.GPAMUX.bit.CAP2Q2_GPIOA9=0; + + + GpioMuxRegs.GPBDIR.bit.GPIOB8=1; + GpioMuxRegs.GPADIR.bit.GPIOA9=0; + GpioDataRegs.GPBDAT.bit.GPIOB8=1; + + // init line + GpioMuxRegs.GPEMUX.bit.XNMI_XINT13_GPIOE2=0; // as io + GpioMuxRegs.GPEDIR.bit.GPIOE2 = 0; // as input + + setup_xilinx_line_do_on(); + + EDIS; +} + +unsigned int read_init_xilinx() +{ + unsigned int i; + EALLOW; + i=GpioDataRegs.GPEDAT.bit.GPIOE2; + EDIS; + return (i); +} + +unsigned int read_done_xilinx() +{ +unsigned int i; + EALLOW; + i=GpioDataRegs.GPADAT.bit.GPIOA9; + EDIS; + return (i); +} + +long xverify_remote_eeprom(unsigned int adr_device, unsigned long adr, + unsigned long adr_eeprom, unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ) +{ + int i; + static XSeeprom_t rom; + unsigned long repeat_er=0; + unsigned int er_wr=0; + unsigned int er_rd=0; + + rom.Adr_device=adr_device; + rom.Adr=adr; + rom.Adr_seeprom=adr_eeprom; + rom.size=size; + + if (er_wr) + return 0; + + for (i=0; i>8) & 0xff); + write_byte_xilinx( wx & 0xff); + } + + +// slow part of loading + adr_x=adr_int; + wx=i_ReadMemory(adr_x+adr); + write_byte_xilinx( (wx>>8) & 0xff); + pause_1000(10000); + write_byte_xilinx( wx & 0xff); + pause_1000(10000); + adr_int++; + +// final part of loading + for (adr_x=adr_int;adr_x<(size+1);adr_x++) + { + unsigned int bx; + int i; + + done_line=read_done_xilinx(); + if(done_line==1) + break; + + wx=i_ReadMemory(adr_x+adr); + bx=(wx>>8) & 0xff; + for (i=0;i<=7;i++) + { + write_bit_xilinx( (bx >> i) & 1); + done_line=read_done_xilinx(); + if(done_line==1) + break; + } + if(done_line==1) + break; + + wx=i_ReadMemory(adr_x+adr); + bx= wx & 0xff; + for (i=0;i<=7;i++) + { + write_bit_xilinx( (bx >> i) & 1); + done_line=read_done_xilinx(); + if(done_line==1) + break; + } + if(done_line==1) + break; + } +// configure line DO as input +// EALLOW; +// setup_xilinx_line_do_off(); +// EDIS; + + +// activation part of loading +// restore peripheral frequency +// xfrequency_peripheral_is_slow(Clk_mode_store); + + + // DONE activate on clock 2 + + write_bit_xilinx(1); // clock 3, activate GWE + + write_bit_xilinx(1); // clock 4, activate GSR + + write_bit_xilinx(1); // clock 5, activate GTS. Led is work. + + write_bit_xilinx(1); // clock 6, activate DLL + + write_bit_xilinx(0); // clock 7 + + write_bit_xilinx(1); + pause_1000(100); + + write_bit_xilinx(0); + pause_1000(100); + +// controll line DONE + Value=read_done_xilinx(); // there must be level '1' + if(Value != 1) + return xerror(xtools_er_ID(2),(void *)0); + +// pause for DLL in Xilinx + pause_1000(10000); + + return 0; +} + + + +int xseeprom_write_all(XSeeprom_t * Ptr) +{ + + union XSeeprom_command_reg command; + unsigned int data; + unsigned int i; + unsigned int er=0; + unsigned long er_ack=0; + unsigned int er_for_one_pack=0; + unsigned int er_consecutive=0; + unsigned long adr_x=Ptr->Adr; + unsigned long adr_eeprom=Ptr->Adr_seeprom; + unsigned int count_word=128; + unsigned int wx; + + command.bit.bit7=1; + command.bit.bit6=0; + command.bit.bit5=1; + command.bit.bit4=0; + command.bit.bit3=0; + command.bit.A1=1; + command.bit.WR0=0; + + Ptr->ok_write=0; + Ptr->repeat_error=0; + Ptr->write_error=0; + + xseeprom_init(); + pause_1000(100); + xseeprom_adr(Ptr->Adr_device); + // xseeprom_set_mode_ON(1); + + xeeprom_controll_fast=Controll.all; + + pause_1000(100); + + while ((adr_x-Ptr->Adr)<(Ptr->size)) { // while size + er=0; + for(;;){ + Led2_Toggle(); + xseeprom_start(); + command.bit.P0=(adr_eeprom>>15 & 0x0001); + er=xseeprom_write_byte(command.all); + if(er) + break; + + data=adr_eeprom>>7 & 0x00ff; + er=xseeprom_write_byte(data); + if(er) + break; + + data=adr_eeprom<<1 & 0x00ff; + er=xseeprom_write_byte(data); + break; + } + + i=0; + while ( (iAdr)<(Ptr->size)) && ((adr_eeprom<<1 & 0x00ff)+2*i < 0x00ff) ) { + wx=i_ReadMemory(adr_x+i); + er=xseeprom_write_byte(wx>>8); + if(er) + break; + er=xseeprom_write_byte(wx); + if(er) + break; + i+=1; + } + + xseeprom_stop(); + xseeprom_delay(); + + if (er == 0) { + adr_x+=i; + adr_eeprom+=i; + Ptr->ok_write+=i; + er_consecutive=0; + } else { + er_consecutive++; + er_ack++; + if (er_consecutive > XSEEPROM_MAX_ERROR_CONSECUTIVE_FRAME) { + if (er_for_one_pack < XSEEPROM_MIN_LENTH) { + er_for_one_pack +=1; + er_consecutive=0; + } + } + Led1_Toggle(); + } + + switch (er_for_one_pack) { + case 0 : count_word = 128; break; + case 1 : count_word = 64; break; + case 2 : count_word = 32; break; + case 3 : count_word = 16; break; + case 4 : count_word = 8; break; + case 5 : count_word = 4; break; + case 6 : count_word = 2; break; + case 7 : count_word = 1; break; + default : break; + } + + Ptr->repeat_error=er_ack; + if(er_consecutive > XSEEPROM_MAX_ERROR_CONSECUTIVE_BREAK) { + xseeprom_undo(); + return(4); + } + } // while size + xseeprom_undo(); + return 0; +} + +int xseeprom_read_all(unsigned int Mode_is_Verify, XSeeprom_t * Ptr) +{ + union XSeeprom_command_reg command; + unsigned int data; +// unsigned int i; + + unsigned long i; + + unsigned int er; + unsigned long er_ack=0; + unsigned int er_consecutive=0; + unsigned long adr_x=Ptr->Adr; + unsigned long adr_eeprom=Ptr->Adr_seeprom; + unsigned int count_word=128; + unsigned int data_rd; + unsigned int wx; + + command.bit.bit7=1; + command.bit.bit6=0; + command.bit.bit5=1; + command.bit.bit4=0; + command.bit.bit3=0; + command.bit.A1=1; + + Ptr->ok_write=0; + Ptr->repeat_error=0; + Ptr->write_error=0; + + xseeprom_init(); + xseeprom_adr(Ptr->Adr_device); + // xseeprom_set_mode_ON(1); + + xeeprom_controll_fast=Controll.all; + + + pause_1000(100); + + while ((adr_x-Ptr->Adr)<(Ptr->size)) { // while size + er=0; + for(;;){ + Led2_Toggle(); + xseeprom_start(); + command.bit.P0=(adr_eeprom>>15 & 0x0001); + command.bit.WR0=0; + er=xseeprom_write_byte(command.all); + if(er) + break; + + data=adr_eeprom>>7 & 0x00ff; + er=xseeprom_write_byte(data); + if(er) + break; + + data=adr_eeprom<<1 & 0x00ff; + er=xseeprom_write_byte(data); + if(er) + break; + + xseeprom_start(); + command.bit.WR0=1; + er=xseeprom_write_byte(command.all); + break; + } + + i=0; + while ( (iAdr)<(Ptr->size)) && (( adr_eeprom<<1 & 0x00ff)+2*i < 0x00ff) ) { + data_rd=xseeprom_read_byte(1); + data_rd<<=8; + if( ((i+1)!=count_word) && ((adr_x-Ptr->Adr)<(Ptr->size-1)) && ((adr_eeprom<<1 & 0x00ff)+2*i+1 < 0x00ff) ) + data_rd|=xseeprom_read_byte(1); // use ack + else + data_rd|=xseeprom_read_byte(0); // don't use ack + if(Mode_is_Verify==0) + { + i_WriteMemory((adr_x),data_rd); + } + else { + wx=i_ReadMemory(adr_x); + if(wx!=data_rd) + Ptr->write_error++; + } + i++; + adr_x++; + } + + xseeprom_stop(); +// xseeprom_delay(); + + if (er == 0) { + adr_eeprom+=i; + Ptr->ok_write+=i; + er_consecutive=0; + } else { + er_consecutive++; + er_ack++; + Led1_Toggle(); + } + + Ptr->repeat_error=er_ack; + if(er_consecutive > XSEEPROM_MAX_ERROR_CONSECUTIVE_BREAK) { + xseeprom_undo(); + return(4); + } + } // while size + ResetPeriphPlane(); + xseeprom_undo(); + return 0; +} + +void xseeprom_adr(unsigned int adr) +{ + Controll.bit.line_P7_4_Sorce_Is_Tms=1; + Controll.bit.line_P7_4_Is=adr; + xControll_wr(); +} + +void xseeprom_delay(void) +{ + pause_1000(10000); +} + +void ResetNPeriphPlane(unsigned int np) +{ + + Controll.bit.line_P7_4_Is = np; + + Controll.bit.OE_BUF_Is_ON = 1; + Controll.bit.line_Z_ER0_OUT_Is = 0; + Controll.bit.line_SET_MODE_Is = 1; + xControll_wr(); + pause_1000(10000); + + + + Controll.bit.line_P7_4_Is = 0x0; + Controll.bit.line_Z_ER0_OUT_Is = 1; + xControll_wr(); + + + +// Controll.bit.RemotePlane_Is_Reset = 1; + xControll_wr(); + pause_1000(10000); +// Controll.bit.RemotePlane_Is_Reset = 0; + Controll.bit.line_P7_4_Is = 0x0; +} + +void ResetPeriphPlane() +{ + Controll.bit.line_P7_4_Is = 0xf; +// Controll.bit.RemotePlane_Is_Reset = 1; + xControll_wr(); + pause_1000(10000); +// Controll.bit.RemotePlane_Is_Reset = 0; + Controll.bit.line_P7_4_Is = 0x0; + xControll_wr(); +} + +void xseeprom_init(void) +{ + xeeprom_controll_store=Controll.all; + Controll.bit.line_CLKS_Sorce_Is_Tms=1; + Controll.bit.line_CLKS_Is=1; + Controll.bit.line_ER0_OUT_Sorce_Is_Tms=1; + Controll.bit.line_ER0_OUT_Is=1; + Controll.bit.line_P7_4_Sorce_Is_Tms=1; + Controll.bit.line_P7_4_Is=0xf; + Controll.bit.line_Z_ER0_OUT_Is=0; // read + Controll.bit.line_SET_MODE_Is=0; // off + // буфер открыли на выход + Controll.bit.OE_BUF_Is_ON=0;//1; + // снЯт сброс с периферийных плат + Controll.bit.RemotePlane_Is_Reset=0; + xControll_wr(); +} + +void xControll_wr() +{ + i_WriteMemory(ADR_CONTR_REG_FOR_WRITE, Controll.all); +} +/* +unsigned int xseeprom_case_xilinx (void) { + xinput_new_uni_rd_status(&Xinput_new_uni_tms0); + return Xinput_new_uni_tms0.ChanalsPtr.ChanalPtr[XINPUT_NEW_TMS0_NUMBER_LINE_CASE_XILINX].rd_status; +} +*/ +unsigned int xseeprom_read_byte(unsigned int use_ack){ + int i; + unsigned int data=0; + + xseeprom_dout(1); + xseeprom_mode_wr(0); + for (i=7;i>=0;i--) + { + xseeprom_pause + xseeprom_clk(1); + xseeprom_pause + data=data<<1|(xseeprom_din() & 0x0001); + xseeprom_clk(0); + xseeprom_pause + } + + pause_1000(10); + + xseeprom_mode_wr(1); + xseeprom_dout(!use_ack); // ack + xseeprom_pause + xseeprom_clk(1); + xseeprom_pause + xseeprom_clk(0); + xseeprom_pause + xseeprom_dout(1); + xseeprom_mode_wr(0); + + + pause_1000(10); + return data; +} + +void xseeprom_set_mode_ON (unsigned int set_mode) { + Controll.bit.line_SET_MODE_Is=~set_mode; + xControll_wr(); +} + +void xseeprom_start(void) { + xseeprom_clk(1); + xseeprom_dout(1); + xseeprom_mode_wr(1); + xseeprom_pause + xseeprom_dout(0); // start + xseeprom_pause + xseeprom_clk(0); + xseeprom_pause +} + +void xseeprom_stop(void) { + xseeprom_mode_wr(1); + xseeprom_dout(0); + pause_1000(10); + xseeprom_clk(1); + pause_1000(10); + xseeprom_dout(1); + pause_1000(10); +} + +void xseeprom_undo (void){ + Controll.all=xeeprom_controll_store; + Controll.bit.OE_BUF_Is_ON=1; + xControll_wr(); +} + +unsigned int xseeprom_write_byte(unsigned int byte){ + int i; + unsigned int ack; + + xseeprom_mode_wr(1); + for (i=7;i>=0;i--) + { + xseeprom_dout((byte >> i) & 1); + xseeprom_pause + xseeprom_clk(1); + xseeprom_pause + xseeprom_clk(0); + xseeprom_pause + } + + xseeprom_dout(1); + xseeprom_mode_wr(0); + pause_1000(10); + + xseeprom_pause + xseeprom_clk(1); + pause_1000(10); + xseeprom_pause + ack=xseeprom_din(); + xseeprom_clk(0); + xseeprom_pause + + pause_1000(10); + + /* +// xseeprom_dout(1); + xseeprom_mode_wr(0); + pause_1000(10); + +// xseeprom_mode_wr(0); + xseeprom_dout(1); + xseeprom_pause + xseeprom_clk(1); + xseeprom_pause + ack=xseeprom_din(); + xseeprom_clk(0); + xseeprom_pause + + pause_1000(10); + */ + return ack; // '0' - ok! +} + +void xseeprom_clk (unsigned int clk) { + xeeprom_controll_fast&=0xfdff; + xeeprom_controll_fast|=(clk<<9 & 0x0200); + i_WriteMemory(ADR_CONTR_REG_FOR_WRITE,xeeprom_controll_fast); +} + +unsigned int xseeprom_din (void) { + return (i_ReadMemory(ADR_CONTR_REG_FOR_READ)>>15 & 0x0001); +} + +void xseeprom_dout (unsigned int data) { + xeeprom_controll_fast&=0xff7f; + xeeprom_controll_fast|=(data<<7 & 0x0080); + i_WriteMemory(ADR_CONTR_REG_FOR_WRITE,xeeprom_controll_fast); +} + +void xseeprom_mode_wr (unsigned int mode) { // '1' - write, '0' - read + xeeprom_controll_fast&=0xffef; + xeeprom_controll_fast|=(mode<<4 & 0x0010); + i_WriteMemory(ADR_CONTR_REG_FOR_WRITE,xeeprom_controll_fast); +} + + + + + +/*********************** example ****************************************** +* i=xilinx_live_smart(0x5aaa); +* i=i|xilinx_live_smart(0x0000) +***************************************************************************/ +unsigned int xilinx_live_smart(unsigned int d) // dout(15:0) = din(11:8) & din(15:12) & not din(7:0); +{ + unsigned int dout; + unsigned int d_rd; + + i_WriteMemory(ADR_XTEST_REG,d); + dout = ~d; + d_rd = i_ReadMemory(ADR_XTEST_REG); + if (d_rd!=dout) + return 1; + return 0; +} + + + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// + +int enable_er0_control(void) +{ + return xilinx_live_smart(0x5AA5); +} + + + +int test_xilinx_live(void) +{ + unsigned int i; + //test xilinx controller on read/write operation + for(i=0;i<10000;i++) + if(xilinx_live_smart(i)) + return xerror(main_er_ID(1),(void *)0); + return 0; +} + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// + + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// + + + + + diff --git a/Inu/Src2/N12_Xilinx/Spartan2E_Functions.h b/Inu/Src2/N12_Xilinx/Spartan2E_Functions.h new file mode 100644 index 0000000..be1577a --- /dev/null +++ b/Inu/Src2/N12_Xilinx/Spartan2E_Functions.h @@ -0,0 +1,264 @@ +#ifndef _SPARTAN2E_FUNCTIONS_H +#define _SPARTAN2E_FUNCTIONS_H + +#include "DSP281x_Device.h" + +#define SIZE_XILINX200 90126 // count words + +struct XControll_reg_bit { + unsigned int OE_BUF_Is_ON:1; + unsigned int RemotePlane_Is_Reset:1; + unsigned int Int_for_XNMI_XINT13_ON:1; + unsigned int Int_for_XINT1_XBIO_ON:1; + unsigned int line_Z_ER0_OUT_Is:1; + unsigned int line_SET_MODE_Is:1; + unsigned int line_ER0_OUT_Sorce_Is_Tms:1; + unsigned int line_ER0_OUT_Is:1; + unsigned int line_CLKS_Sorce_Is_Tms:1; + unsigned int line_CLKS_Is:1; + unsigned int line_P7_4_Sorce_Is_Tms:1; + unsigned int line_P7_4_Is:4; // 4 bits + unsigned int line_ER0_IN_Is:1; // WR has no effect + }; + typedef union { + unsigned int all; + struct XControll_reg_bit bit; + } XControll_reg; + +union XSeeprom_command_reg { + unsigned int all; + struct { + unsigned int WR0:1; + unsigned int P0:1; + unsigned int A1:1; + unsigned int bit3:1; + unsigned int bit4:1; + unsigned int bit5:1; + unsigned int bit6:1; + unsigned int bit7:1; + } bit; + }; + +struct XSerial_bus_config_bit { + unsigned int Use_Config:1; + unsigned int Number_of_Frequency_is:3; + unsigned int Use_Timer:1; + unsigned int Range_CountTimer:4; + unsigned int Use_Filtr_on_din:1; + unsigned int Use_only_fast_Filtr_on_din:1; + unsigned int Use_Tweaking:1; + unsigned int Use_compensation_delay_on_Tweaking:1; + unsigned int Use_SyncRdWr:1; + unsigned int reserve_bits:2; // unused 2 bits + }; + +union XSerial_bus_config_reg { + unsigned int all; + struct XSerial_bus_config_bit bit; + }; + +struct XSerial_bus_intc_din_bit { + unsigned int State_Is_Idle:1; + unsigned int Error_CRC:1; + unsigned int Error_Comand:1; + unsigned int Timeout_Is_Complete:1; + unsigned int Mode_Is_Config:1; + unsigned int rezerv:3; + }; + +typedef volatile union { + unsigned int all; + struct XSerial_bus_intc_din_bit bit; + } XSerial_bus_intc_din_reg; + +struct XSerial_bus_adr_bit { + unsigned int AdrPlane:4; + unsigned int reserve_bits:3; // unused 3 bits + unsigned int RdWR:1; // '0' - WR, '1' - RD + unsigned int AdrReg:8; + }; + +union XSerial_bus_adr_reg { + unsigned int all; + struct XSerial_bus_adr_bit bit; + }; + +typedef struct { + unsigned int TypeAccess; + unsigned int AdrPlane; + unsigned int AdrReg; + unsigned int DataWr; + unsigned int DataRd; + } Xmemory_uni; + +typedef volatile struct { + unsigned int BaseAddress; // Base address of registers // + unsigned int DataWr; // Data for write to selected register // + unsigned int DataRd; // Reading data from selected register // + union XSerial_bus_adr_reg Adr; + XSerial_bus_intc_din_reg ISR; + union XSerial_bus_config_reg Config; + unsigned int IsReady:1; // Device is initialized and ready // + } XSerial_bus; + +struct XSeeprom_s { + unsigned int Adr_device; + unsigned long Adr; + unsigned long Adr_seeprom; + unsigned long size; + unsigned long ok_write; + unsigned long write_error; + unsigned long repeat_error; + }; + +typedef volatile struct XSeeprom_s XSeeprom_t; + +struct XSerial_bus_intc_mer_bit { + unsigned int Master_Enable:1; + unsigned int Hardware_Int_Enable:1; + }; + +union XSerial_bus_intc_mer_reg { + unsigned int all; + struct XSerial_bus_intc_mer_bit bit; + }; + +struct XSerial_bus_INTC { + XSerial_bus_intc_din_reg ISR; + XSerial_bus_intc_din_reg IER; + XSerial_bus_intc_din_reg IPR; + union XSerial_bus_intc_mer_reg MER; + }; + +struct XSerial_Tweaking_Data { + unsigned int Tweaking_tr_line:4; + unsigned int Tweaking_rec_line:4; + }; +/* +struct XSerial_bus_Config_Data { + unsigned int Constant_for_Timer; + unsigned int Number_Wait_State_for_TrRec:4; + unsigned int Number_Wait_State_for_Pause:4; + struct XSerial_Tweaking_Data Tweaking_chanal[8]; + unsigned int Delay_clk_for_Tr:7; + unsigned int Delay_clk_for_Rec:7; + unsigned int Use_fast_Filtr:1; + unsigned int Use_fast_Transmit:1; + unsigned int Tweaking_tbuf_en:4; + }; + */ +/* +typedef volatile struct { + unsigned int PlaneIsLive; // For selected DelayLine chanal is visible: QualityTrRec = 100%, bit per chanal + unsigned int CountErrors; // count errors transmit-recieve + XSerial_bus *Bus; + struct XSerial_bus_INTC INTC; + struct XSerial_bus_Config_Data Config_Data; + unsigned int Number_Chanal; + } XSerial_bus_stats; +*/ + +/* +struct PARALLEL_BITS { // bits description + Uint16 res0:1; // 0 + Uint16 res1:1; // 1 + Uint16 res2:1; // 2 + Uint16 res3:1; // 3 + Uint16 res4:1; // 4 + Uint16 res5:1; // 5 + Uint16 res6:1; // 6 + Uint16 res7:1; // 7 + Uint16 res8:1; // 8 + Uint16 res9:1; // 9 + Uint16 res10:1; // 10 + Uint16 res11:1; // 11 + Uint16 res12:1; // 12 + Uint16 res13:1; // 13 + Uint16 res14:1; // 14 + Uint16 res15:1; // 15 +}; + +struct PARALLEL_STATUS_BITS { // bits description + Uint16 err_crc:1; // 0 + Uint16 not_ready:1; // 1 + Uint16 res2:1; // 2 + Uint16 res3:1; // 3 + Uint16 res4:1; // 4 + Uint16 res5:1; // 5 + Uint16 res6:1; // 6 + Uint16 res7:1; // 7 + Uint16 res8:1; // 8 + Uint16 res9:1; // 9 + Uint16 res10:1; // 10 + Uint16 res11:1; // 11 + Uint16 res12:1; // 12 + Uint16 res13:1; // 13 + Uint16 res14:1; // 14 + Uint16 res15:1; // 15 +}; + + +union PARALLEL1_REG { + Uint16 all; + struct PARALLEL_BITS bit; +}; + +union PARALLEL2_REG { + Uint16 all; + struct PARALLEL_BITS bit; +}; + +union PARALLEL3_REG { + Uint16 all; + struct PARALLEL_BITS bit; +}; + +union PARALLEL4_REG { + Uint16 all; + struct PARALLEL_BITS bit; +}; + +union PARALLEL5_REG { + Uint16 all; + struct PARALLEL_BITS bit; +}; + +union PARALLEL_STATUS_REG { + Uint16 all; + struct PARALLEL_STATUS_BITS bit; +}; + +typedef volatile struct { // bits description + union PARALLEL1_REG reg1; + union PARALLEL2_REG reg2; + union PARALLEL3_REG reg3; + union PARALLEL4_REG reg4; + union PARALLEL5_REG reg5; + union PARALLEL_STATUS_REG status; +} PARALLEL_REGS; +*/ + +int load_xilinx_new(unsigned long adr,unsigned long size); + +int xflash_remote_eeprom(unsigned int adr_device, unsigned long adr, + unsigned long adr_eeprom, unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ); + +long xread_remote_eeprom(unsigned int adr_device, unsigned long adr_eeprom, + unsigned long adr, unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ); + +long xverify_remote_eeprom(unsigned int adr_device, unsigned long adr, + unsigned long adr_eeprom, unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ); + + +int test_xilinx_live(void); + +int enable_er0_control(void); + +void ResetNPeriphPlane(unsigned int np); + + + +#endif diff --git a/Inu/Src2/N12_Xilinx/TuneUpPlane.c b/Inu/Src2/N12_Xilinx/TuneUpPlane.c new file mode 100644 index 0000000..9dd05b3 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/TuneUpPlane.c @@ -0,0 +1,340 @@ +#include "TuneUpPlane.h" + +#include "DSP281x_Examples.h" +#include "DSP281x_Device.h" +#include "DSP281x_Xintf.h" + +#define SelectWorkWithFlash() WriteOper(0,0,0,0) +#define SelectStrob67_ForFlash() WriteOper(1,0,1,0) + +unsigned int cl_led1 = 0; +unsigned int cl_led2 = 0; + +void SetupOperLine(); + +#pragma CODE_SECTION(Led1_Toggle,".fast_run"); +#pragma CODE_SECTION(Led2_Toggle,".fast_run"); + +#pragma CODE_SECTION(i_led2_on_off,".fast_run"); +void i_led2_on_off(int i) +{ + EALLOW; + + if (i) GpioDataRegs.GPDSET.bit.GPIOD6=1; + else GpioDataRegs.GPDCLEAR.bit.GPIOD6=1; + + + EDIS; +} + +#pragma CODE_SECTION(i_led1_on_off,".fast_run"); +void i_led1_on_off(int i) +{ + EALLOW; + if (i) GpioDataRegs.GPASET.bit.GPIOA10=1; + else GpioDataRegs.GPACLEAR.bit.GPIOA10=1; + + EDIS; +} + + +//#pragma CODE_SECTION(i_led2_on_off_special,".fast_run"); +//void i_led2_on_off_special(int i) +//{ +// EALLOW; +// +// if (i) GpioDataRegs.GPDSET.bit.GPIOD6=1; +// else GpioDataRegs.GPDCLEAR.bit.GPIOD6=1; +// +// +// EDIS; +//} + +#pragma CODE_SECTION(i_led1_on_off_special,".fast_run"); +void i_led1_on_off_special(int i) +{ + EALLOW; + if (i) + { + GpioDataRegs.GPASET.bit.GPIOA10=1; + cl_led1++; + } + else + { + if (cl_led1) + cl_led1--; + + if (cl_led1 == 0) + GpioDataRegs.GPACLEAR.bit.GPIOA10=1; + } + + EDIS; +} + +#pragma CODE_SECTION(i_led2_on_off_special,".fast_run"); +void i_led2_on_off_special(int i) +{ + EALLOW; + if (i) + { + GpioDataRegs.GPDSET.bit.GPIOD6=1; + cl_led2++; + } + else + { + if (cl_led2) + cl_led2--; + + if (cl_led2 == 0) + GpioDataRegs.GPDCLEAR.bit.GPIOD6=1; + } + + EDIS; +} + + +void Led1_Toggle() +{ + EALLOW; + GpioDataRegs.GPATOGGLE.bit.GPIOA10=1; + EDIS; +} + + +void Led2_Toggle() +{ + EALLOW; + GpioDataRegs.GPDTOGGLE.bit.GPIOD6=1; + EDIS; +} + +void SetupLedsLine() +{ + EALLOW; + GpioMuxRegs.GPDMUX.bit.T4CTRIP_SOCB_GPIOD6 = 0; + GpioDataRegs.GPDDAT.bit.GPIOD6 = 0; + GpioMuxRegs.GPDDIR.bit.GPIOD6 = 1; + + GpioMuxRegs.GPAMUX.bit.CAP3QI1_GPIOA10 = 0; + GpioDataRegs.GPADAT.bit.GPIOA10 = 0; + GpioMuxRegs.GPADIR.bit.GPIOA10 = 1; + EDIS; + +} + +#pragma CODE_SECTION(pause_1000,".fast_run"); +void pause_1000(unsigned long t) +{ + unsigned long i; + + t = t >> 1; + + for (i = 0; i < t; i++) + { + DSP28x_usDelay(40L); + } +} +//Xilinx Zone +void XintfZone0_Timing(void) +{ + // Zone 0------------------------------------ + // When using ready, ACTIVE must be 1 or greater + // Lead must always be 1 or greater + // Zone write timing + XintfRegs.XTIMING0.bit.XWRLEAD = 3;//2; + XintfRegs.XTIMING0.bit.XWRACTIVE = 5;//2;//1; // 1 + XintfRegs.XTIMING0.bit.XWRTRAIL = 1;//0; + // Zone read timing + XintfRegs.XTIMING0.bit.XRDLEAD = 3; + XintfRegs.XTIMING0.bit.XRDACTIVE = 5;//1 + XintfRegs.XTIMING0.bit.XRDTRAIL = 1;//1 + + // do not double all Zone read/write lead/active/trail timing + XintfRegs.XTIMING0.bit.X2TIMING = 0; + + // Zone will not sample READY + XintfRegs.XTIMING0.bit.USEREADY = 0;//1; + XintfRegs.XTIMING0.bit.READYMODE = 0;//1; + + // Size must be 1,1 - other values are reserved + XintfRegs.XTIMING0.bit.XSIZE = 3; + + + + //Force a pipeline flush to ensure that the write to + //the last register configured occurs before returning. + asm(" RPT #7 || NOP"); +} + +void XintfZone6_And7_Timing(void) +{ + + // All Zones--------------------------------- + // Timing for all zones based on XTIMCLK = SYSCLKOUT/2 + XintfRegs.XINTCNF2.bit.XTIMCLK = 1; + // Buffer up to 0 writes + XintfRegs.XINTCNF2.bit.WRBUFF = 0; + // XCLKOUT is enabled + XintfRegs.XINTCNF2.bit.CLKOFF = 0; + // XCLKOUT = XTIMCLK +#ifdef XLOW_FREQUENCY_MODE + XintfRegs.XINTCNF2.bit.CLKMODE = 1; +#else + XintfRegs.XINTCNF2.bit.CLKMODE = 0; +#endif + XintfRegs.XINTCNF2.bit.MPNMC = 0; + + + // Zone 6------------------------------------ + // When using ready, ACTIVE must be 1 or greater + // Lead must always be 1 or greater + // Zone write timing + XintfRegs.XTIMING6.bit.XWRLEAD = 3; + XintfRegs.XTIMING6.bit.XWRACTIVE = 7; + XintfRegs.XTIMING6.bit.XWRTRAIL = 3; + // Zone read timing + XintfRegs.XTIMING6.bit.XRDLEAD = 3; + XintfRegs.XTIMING6.bit.XRDACTIVE = 7;//3; + XintfRegs.XTIMING6.bit.XRDTRAIL = 3; + + // do not double all Zone read/write lead/active/trail timing + XintfRegs.XTIMING6.bit.X2TIMING = 0; + + // Zone will not sample READY + XintfRegs.XTIMING6.bit.USEREADY = 0;//1; + XintfRegs.XTIMING6.bit.READYMODE = 0;//1; + + // Size must be 1,1 - other values are reserved + XintfRegs.XTIMING6.bit.XSIZE = 3; + + + // Zone 7------------------------------------ + // When using ready, ACTIVE must be 1 or greater + // Lead must always be 1 or greater + // Zone write timing + XintfRegs.XTIMING7.bit.XWRLEAD = 3; + XintfRegs.XTIMING7.bit.XWRACTIVE = 7; + XintfRegs.XTIMING7.bit.XWRTRAIL = 3; + // Zone read timing + XintfRegs.XTIMING7.bit.XRDLEAD = 3; + XintfRegs.XTIMING7.bit.XRDACTIVE = 3; + XintfRegs.XTIMING7.bit.XRDTRAIL = 3; + + // don't double all Zone read/write lead/active/trail timing + XintfRegs.XTIMING7.bit.X2TIMING = 0; + + // Zone will not sample XREADY signal + XintfRegs.XTIMING7.bit.USEREADY = 0; + XintfRegs.XTIMING7.bit.READYMODE = 0; + + // Size must be 1,1 - other values are reserved + XintfRegs.XTIMING7.bit.XSIZE = 3; + + //Force a pipeline flush to ensure that the write to + //the last register configured occurs before returning. + asm(" RPT #7 || NOP"); +} + +void XintfZone2_Timing(void) +{ + + // All Zones--------------------------------- + // Timing for all zones based on XTIMCLK = SYSCLKOUT/2 + XintfRegs.XINTCNF2.bit.XTIMCLK = 1; + // Buffer up to 0 writes + XintfRegs.XINTCNF2.bit.WRBUFF = 0; + // XCLKOUT is enabled + XintfRegs.XINTCNF2.bit.CLKOFF = 0; + // XCLKOUT = XTIMCLK + XintfRegs.XINTCNF2.bit.CLKMODE = 0; + + XintfRegs.XINTCNF2.bit.MPNMC = 0; + + + // Zone 6------------------------------------ + // When using ready, ACTIVE must be 1 or greater + // Lead must always be 1 or greater + // Zone write timing + XintfRegs.XTIMING2.bit.XWRLEAD = 3;//2; + XintfRegs.XTIMING2.bit.XWRACTIVE = 4;//2; + XintfRegs.XTIMING2.bit.XWRTRAIL = 2;//2; + // Zone read timing + XintfRegs.XTIMING2.bit.XRDLEAD = 2; + XintfRegs.XTIMING2.bit.XRDACTIVE = 3; //1; + XintfRegs.XTIMING2.bit.XRDTRAIL = 1;//2;//0; + + // do not double all Zone read/write lead/active/trail timing + XintfRegs.XTIMING2.bit.X2TIMING = 0; + + // Zone will not sample READY + XintfRegs.XTIMING2.bit.USEREADY = 0;//1; + XintfRegs.XTIMING2.bit.READYMODE = 0;//1; + + // Size must be 1,1 - other values are reserved + XintfRegs.XTIMING2.bit.XSIZE = 3; + + + + //Force a pipeline flush to ensure that the write to + //the last register configured occurs before returning. + asm(" RPT #7 || NOP"); +} + +void FlashInit() +{ + SetupOperLine(); + + SelectStrob67_ForFlash(); + + XintfZone6_And7_Timing(); + SelectWorkWithFlash(); +} + +void SetupOperLine() +{ + EALLOW; + + GpioMuxRegs.GPAMUX.bit.C1TRIP_GPIOA13=0; + GpioMuxRegs.GPAMUX.bit.C2TRIP_GPIOA14=0; + GpioMuxRegs.GPAMUX.bit.C3TRIP_GPIOA15=0; + GpioMuxRegs.GPBMUX.bit.C4TRIP_GPIOB13=0; + GpioMuxRegs.GPBMUX.bit.C6TRIP_GPIOB15=0; + + GpioMuxRegs.GPADIR.bit.GPIOA13=1; + GpioMuxRegs.GPADIR.bit.GPIOA14=1; + GpioMuxRegs.GPADIR.bit.GPIOA15=1; + GpioMuxRegs.GPBDIR.bit.GPIOB13=1; + GpioMuxRegs.GPBDIR.bit.GPIOB15=1; + + GpioMuxRegs.GPAQUAL.all=0; + GpioMuxRegs.GPBQUAL.all=0; + EDIS; + + WriteOper(1,1,1,1); + +} + +void WriteOper(unsigned char oper_mode1,unsigned char oper_mode2, unsigned char oper_mode3, unsigned char oper_mode4) +{ + EALLOW; + GpioDataRegs.GPADAT.bit.GPIOA13=oper_mode1; + GpioDataRegs.GPADAT.bit.GPIOA14=oper_mode2; + GpioDataRegs.GPADAT.bit.GPIOA15=oper_mode3; + GpioDataRegs.GPBDAT.bit.GPIOB13=oper_mode4; + + asm(" NOP"); + GpioDataRegs.GPBDAT.bit.GPIOB15=0; + asm(" NOP"); + asm(" NOP"); + asm(" NOP"); + GpioDataRegs.GPBDAT.bit.GPIOB15=1; + asm(" NOP"); + asm(" NOP"); + asm(" NOP"); + GpioDataRegs.GPBDAT.bit.GPIOB15=0; + asm(" NOP"); + asm(" NOP"); + asm(" NOP"); + + EDIS; +} diff --git a/Inu/Src2/N12_Xilinx/TuneUpPlane.h b/Inu/Src2/N12_Xilinx/TuneUpPlane.h new file mode 100644 index 0000000..1388b59 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/TuneUpPlane.h @@ -0,0 +1,38 @@ +#ifndef _TUNE_UP_PLANE_H +#define _TUNE_UP_PLANE_H + +#include "DSP281x_Device.h" + +void WriteOper(unsigned char oper_mode1,unsigned char oper_mode2, unsigned char oper_mode3, unsigned char oper_mode4); +void pause_1000(unsigned long t); +void XintfZone0_Timing(void); +void XintfZone6_And7_Timing(void); +void XintfZone2_Timing(void); +void FlashInit(); + +//extern void DSP28x_usDelay(long LoopCount); + +void Led1_Toggle(); +void Led2_Toggle(); + +void i_led2_on_off(int i); +void i_led1_on_off(int i); + +void i_led2_on_off_special(int i); +void i_led1_on_off_special(int i); + + +#define i_led1_on() {EALLOW;GpioDataRegs.GPASET.bit.GPIOA10 = 1;EDIS;} +#define i_led1_off() {EALLOW;GpioDataRegs.GPACLEAR.bit.GPIOA10 = 1;;EDIS;} + +#define i_led2_on() {EALLOW;GpioDataRegs.GPDSET.bit.GPIOD6 = 1;EDIS;} +#define i_led2_off() {EALLOW;GpioDataRegs.GPDCLEAR.bit.GPIOD6 = 1;;EDIS;} + +#define i_led1_toggle() {EALLOW; GpioDataRegs.GPATOGGLE.bit.GPIOA10 = 1; EDIS;} +#define i_led2_toggle() {EALLOW; GpioDataRegs.GPDTOGGLE.bit.GPIOD6 = 1; EDIS;} + + + +void SetupLedsLine(); + +#endif diff --git a/Inu/Src2/N12_Xilinx/modbus_struct.h b/Inu/Src2/N12_Xilinx/modbus_struct.h new file mode 100644 index 0000000..d3dec6e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/modbus_struct.h @@ -0,0 +1,39 @@ +#ifndef _MODBUS_STRUCT_H +#define _MODBUS_STRUCT_H + +//#include "RS_Functions.h" + +struct MODBUS_WORD_STRUCT { // bit description + unsigned int LB:8; // 16:23 High word low byte + unsigned int HB:8; // 24:31 High word high byte +}; + + +struct MODBUS_BITS_STRUCT { // bit description + unsigned int bit0: 1; + unsigned int bit1: 1; + unsigned int bit2: 1; + unsigned int bit3: 1; + unsigned int bit4: 1; + unsigned int bit5: 1; + unsigned int bit6: 1; + unsigned int bit7: 1; + unsigned int bit8: 1; + unsigned int bit9: 1; + unsigned int bit10: 1; + unsigned int bit11: 1; + unsigned int bit12: 1; + unsigned int bit13: 1; + unsigned int bit14: 1; + unsigned int bit15: 1; +}; + +typedef union { + //unsigned int all; + int all; + struct MODBUS_BITS_STRUCT bit; + struct MODBUS_WORD_STRUCT byte; +} MODBUS_REG_STRUCT; + +#endif + diff --git a/Inu/Src/N12_Xilinx/not_use/xp_rotation_sensor.c b/Inu/Src2/N12_Xilinx/not_use/xp_rotation_sensor.c similarity index 100% rename from Inu/Src/N12_Xilinx/not_use/xp_rotation_sensor.c rename to Inu/Src2/N12_Xilinx/not_use/xp_rotation_sensor.c diff --git a/Inu/Src/N12_Xilinx/not_use/xp_rotation_sensor.h b/Inu/Src2/N12_Xilinx/not_use/xp_rotation_sensor.h similarity index 100% rename from Inu/Src/N12_Xilinx/not_use/xp_rotation_sensor.h rename to Inu/Src2/N12_Xilinx/not_use/xp_rotation_sensor.h diff --git a/Inu/Src/N12_Xilinx/profile_interrupt.c b/Inu/Src2/N12_Xilinx/profile_interrupt.c similarity index 100% rename from Inu/Src/N12_Xilinx/profile_interrupt.c rename to Inu/Src2/N12_Xilinx/profile_interrupt.c diff --git a/Inu/Src/N12_Xilinx/profile_interrupt.h b/Inu/Src2/N12_Xilinx/profile_interrupt.h similarity index 100% rename from Inu/Src/N12_Xilinx/profile_interrupt.h rename to Inu/Src2/N12_Xilinx/profile_interrupt.h diff --git a/Inu/Src2/N12_Xilinx/xHWP.c b/Inu/Src2/N12_Xilinx/xHWP.c new file mode 100644 index 0000000..8599431 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xHWP.c @@ -0,0 +1,11 @@ +#include "xHWP.h" + +#include "DSP281x_Examples.h" +#include "DSP281x_Device.h" +#include "x_parallel_bus.h" +#include "xerror.h" + + + + + diff --git a/Inu/Src2/N12_Xilinx/xHWP.h b/Inu/Src2/N12_Xilinx/xHWP.h new file mode 100644 index 0000000..efb1a9e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xHWP.h @@ -0,0 +1,6 @@ +#ifndef _XHWP_H +#define _XHWP_H + + +#endif + diff --git a/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.c b/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.c new file mode 100644 index 0000000..ccd10f7 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.c @@ -0,0 +1,561 @@ +#include "xPeriphSP6_loader.h" + +#include "DSP281x_Examples.h" +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Functions.h" +#include "TuneUpPlane.h" +#include "x_parallel_bus.h" +#include "xp_project.h" + + + +Byte byte; //used 8 most significant bits +Word word; +ControlReg controlReg; + +volatile AddrToSent addrToSent; +WordToReverse wordToReverse; +WordReversed wordReversed; + + +volatile int fail = 0; +volatile unsigned long length = 0; +volatile int tryNumb = 0; +int manufactorerAndProductID = 0; +static int countInMemWrite = 0; + +void initState(int adr_device){ + controlReg.all = 0x0000; + controlReg.bit.cs = 1; + controlReg.bit.rw = 1; + controlReg.bit.plane_addr = adr_device; + controlReg.bit.clock = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + + + +void sendByte(void){ + int bitCnt = 8; + + controlReg.bit.clock = 0; + controlReg.bit.data = byte.bit.data; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + + while (bitCnt > 0) { + if (controlReg.bit.clock == 1) { + controlReg.bit.clock = 0; + controlReg.bit.data = byte.bit.data; + // bitCnt--; + } else { + controlReg.bit.clock = 1; + byte.all = byte.all << 1; + bitCnt--; + } + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + } +} + + +void sendWord(void){ + int bitCnt = 16; + + controlReg.bit.clock = 0; + controlReg.bit.data = word.bit.data; +// controlReg.bit.data = word.bit.dataReceived; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + + while (bitCnt > 0) { + if (controlReg.bit.clock == 1) { + controlReg.bit.clock = 0; +// controlReg.bit.data = word.bit.dataReceived; + controlReg.bit.data = word.bit.data; + } else { + controlReg.bit.clock = 1; +// word.all = word.all >> 1; + word.all = word.all << 1; + bitCnt--; + } + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + } +} + + + +void readByte(void){ + int bitCnt = 8; + controlReg.bit.clock = 0; + controlReg.bit.rw = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +// byte.all = 0x0000; + while (bitCnt > 0) { + if (controlReg.bit.clock == 1) { + byte.all = byte.all << 1; + controlReg.all = i_ReadMemory(ADR_CONTR_REG_FOR_READ); + byte.bit.dataReceived = controlReg.bit.eeprom_read; + controlReg.bit.clock = 0; + bitCnt--; + } else { + controlReg.all = i_ReadMemory(ADR_CONTR_REG_FOR_READ); + controlReg.bit.clock = 1; + } + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + } +} + +void readWord(void){ + int bitCnt = 16; + word.all = 0x0000; + while (bitCnt > 0) { + if (controlReg.bit.clock == 1) { + word.all = word.all << 1; + // word.all = word.all >> 1; + controlReg.all = i_ReadMemory(ADR_CONTR_REG_FOR_READ); + word.bit.dataReceived = controlReg.bit.eeprom_read; + // word.bit.data = controlReg.bit.eeprom_read; + controlReg.bit.clock = 0; + bitCnt--; + } else { + controlReg.all = i_ReadMemory(ADR_CONTR_REG_FOR_READ); + controlReg.bit.clock = 1; + } + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + } +} + + + + +void WREN(void) { + controlReg.bit.cs = 0; + byte.all= 0x0600; + sendByte(); + + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + controlReg.bit.cs = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + +void WRDI(void) { + controlReg.bit.cs = 0; + byte.all= 0x0400; + sendByte(); + + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + controlReg.bit.cs = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + +void WRSR(void) { + controlReg.bit.cs = 0; + byte.all= 0x0100; + sendByte(); + + byte.all= 0x0200; + sendByte(); + + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + controlReg.bit.cs = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + +void RDSR(void) { + controlReg.bit.cs = 0; + controlReg.bit.rw = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + byte.all= 0x0500; + sendByte(); + + + readByte(); + + controlReg.bit.cs = 1; + controlReg.bit.rw = 1; + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + +} + +void RDID(void) { + controlReg.bit.cs = 0; + controlReg.bit.rw = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + if (manufactorerAndProductID == 0) + byte.all = 0x1500; + else + byte.all = 0x9F00; + sendByte(); + + + readByte(); + + controlReg.bit.cs = 1; + controlReg.bit.rw = 1; + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + +} + +void ERASE(void) { + controlReg.bit.cs = 0; + if (manufactorerAndProductID == 0) + byte.all = 0x6200; + else + byte.all = 0xC700; + sendByte(); + + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + controlReg.bit.cs = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + + + +void READ(void) { + controlReg.bit.cs = 0; + byte.all= 0x0300; + sendByte(); +} + +void PROGRAM(void) { + controlReg.bit.cs = 0; + byte.all= 0x0200; + sendByte(); +} + +void ADDR3bytes(FlashAddr flashAddr) { + int bitCnt = 24; + addrToSent.all= flashAddr.all; + addrToSent.all= addrToSent.all << 8; + + + controlReg.bit.clock = 0; + controlReg.bit.data = addrToSent.bit.data; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + + while (bitCnt > 0) { + if (controlReg.bit.clock == 1) { + controlReg.bit.clock = 0; + controlReg.bit.data = addrToSent.bit.data; + // bitCnt--; + } else { + controlReg.bit.clock = 1; + addrToSent.all = addrToSent.all << 1; + bitCnt--; + } + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + } + +} + + + +void DataW256Bytes(volatile unsigned long addrToRead) { + unsigned long WordNum = 0; + + while (WordNum < 128) { + wordToReverse.all= i_ReadMemory(addrToRead + WordNum); + + wordReversed.bit.bit0 = wordToReverse.bit.bit7; + wordReversed.bit.bit1 = wordToReverse.bit.bit6; + wordReversed.bit.bit2 = wordToReverse.bit.bit5; + wordReversed.bit.bit3 = wordToReverse.bit.bit4; + wordReversed.bit.bit4 = wordToReverse.bit.bit3; + wordReversed.bit.bit5 = wordToReverse.bit.bit2; + wordReversed.bit.bit6 = wordToReverse.bit.bit1; + wordReversed.bit.bit7 = wordToReverse.bit.bit0; + + wordReversed.bit.bit8 = wordToReverse.bit.bit15; + wordReversed.bit.bit9 = wordToReverse.bit.bit14; + wordReversed.bit.bit10 = wordToReverse.bit.bit13; + wordReversed.bit.bit11 = wordToReverse.bit.bit12; + wordReversed.bit.bit12 = wordToReverse.bit.bit11; + wordReversed.bit.bit13 = wordToReverse.bit.bit10; + wordReversed.bit.bit14 = wordToReverse.bit.bit9; + wordReversed.bit.bit15 = wordToReverse.bit.bit8; + + word.all= wordReversed.all; + sendWord(); + WordNum++; + } + + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + controlReg.bit.cs = 1; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + +} + +void DataR256Bytes(volatile unsigned long addrToRead) { + + unsigned long WordNum = 0; + + controlReg.bit.clock = 0; + controlReg.bit.rw = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); + + while (WordNum < 128) { + if ((addrToRead + WordNum) <= length) { + readWord(); + + wordToReverse.all= i_ReadMemory(addrToRead + WordNum); + + wordReversed.bit.bit0 = wordToReverse.bit.bit7; + wordReversed.bit.bit1 = wordToReverse.bit.bit6; + wordReversed.bit.bit2 = wordToReverse.bit.bit5; + wordReversed.bit.bit3 = wordToReverse.bit.bit4; + wordReversed.bit.bit4 = wordToReverse.bit.bit3; + wordReversed.bit.bit5 = wordToReverse.bit.bit2; + wordReversed.bit.bit6 = wordToReverse.bit.bit1; + wordReversed.bit.bit7 = wordToReverse.bit.bit0; + + wordReversed.bit.bit8 = wordToReverse.bit.bit15; + wordReversed.bit.bit9 = wordToReverse.bit.bit14; + wordReversed.bit.bit10 = wordToReverse.bit.bit13; + wordReversed.bit.bit11 = wordToReverse.bit.bit12; + wordReversed.bit.bit12 = wordToReverse.bit.bit11; + wordReversed.bit.bit13 = wordToReverse.bit.bit10; + wordReversed.bit.bit14 = wordToReverse.bit.bit9; + wordReversed.bit.bit15 = wordToReverse.bit.bit8; + + if (word.all != wordReversed.all) { + fail++; + WordNum =128; + } else { + fail = 0; + } + WordNum++; + } else { + // flashAddr.bit.addr2 = 0xFF; + WordNum =128; //finish flash writing + } + } + + controlReg.bit.cs = 1; + controlReg.bit.rw = 1; + controlReg.bit.clock = 0; + controlReg.bit.data = 0; + WriteMemory(ADR_CONTR_REG_FOR_WRITE, controlReg.all); +} + + + + + +void memWrite (unsigned int adr_device, volatile unsigned long adr, + volatile unsigned long adr_eeprom, volatile unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ) +{ + +/////////********************** +/////////before start procedure +/////////********************** + volatile int failNumb = 0; + volatile int checkNumb = 0; + volatile unsigned long addrToRead = 0; + volatile FlashAddr flashAddr; + + + Led1_Toggle(); + Led2_Toggle(); + + *ok_write= size; + + + countInMemWrite++; + + failNumb = 0; + checkNumb = 0; + addrToRead = adr; + length = size + addrToRead; + addrToRead = adr +8; + + *write_error = 0; + *repeat_error = 0; + + project.stop_parallel_bus(); + + initState(adr_device); + + + WREN(); + manufactorerAndProductID = 0; + RDID(); + if (byte.all != 0x1F00) { + manufactorerAndProductID = 1; + RDID(); + if ((byte.all != 0x2000) && (byte.all != 0xEF00)) *write_error = 5; //TODO: make defines with flash ID NAMES + } + WREN(); + WRSR(); + RDSR(); + + while (byte.all > 0) { + if (checkNumb < 3) { + DELAY_US(150); + RDSR(); //check that flash is not busy + +// byte.all = 1; // for test! + + if (failNumb > 1000) { +// if (failNumb > 30000) { //1000 // for test! + WREN(); + WRSR(); + RDSR(); + failNumb = 0; + checkNumb++; + } + failNumb++; + } else { + *write_error = 1; + *ok_write= 0; + failNumb = 1000; + byte.all = 0x0000; + tryNumb++; + } + } + + +// failNumb = 1000; // for test! + + if (failNumb < 1000) { + + failNumb = 0; + checkNumb = 0; + + + WREN(); + ERASE(); + RDSR(); + while (byte.all > 0) { + DELAY_US(70000); + RDSR(); //check that flash is not busy + if (failNumb > 1000) { + *ok_write= 0; + *write_error = 2; + byte.all = 0x0000; + tryNumb++; + } + failNumb++; + } + } + + if (failNumb < 1000) { + failNumb = 0; + + flashAddr.all = 0; + + + /////////********************** + /////////before start procedure finished + /////////********************** + + while (flashAddr.bit.addr2 < 0x08){ + WREN(); + PROGRAM(); + ADDR3bytes(flashAddr); + DataW256Bytes(addrToRead); + RDSR(); + Led1_Toggle(); + failNumb = 0; + checkNumb = 0; + while (byte.all != 0x0000){ + if (byte.all != 0x0200) { + if (checkNumb < 30) { + DELAY_US(3500); + RDSR(); //check that flash is not busy + checkNumb++; + } else { + byte.all = 0x0200; + } + + } else { //programming the page not completed, it's still "data ready" + if (failNumb < 20) { + WREN(); + PROGRAM(); //complete procedure again + ADDR3bytes(flashAddr); + DataW256Bytes(addrToRead); + RDSR(); + checkNumb = 0; + failNumb++; + } else { + *ok_write= addrToRead - adr-8; + *write_error = 3; + byte.all = 0x0000; + flashAddr.bit.addr2 = 0x08; + tryNumb++; + // asm (" ESTOP0"); //for save flash life + } + } + } + + if (failNumb < 20){ + READ(); + ADDR3bytes(flashAddr); + DataR256Bytes(addrToRead); + Led2_Toggle(); + if (fail ==0) { //if page written correctly, go to the next + if (flashAddr.bit.addr1 < 0xff) { + flashAddr.bit.addr1++; + } else { + flashAddr.bit.addr1 = 0; + flashAddr.bit.addr2++; + } + addrToRead += 0x00000080; + } else if (fail > 7) { + *ok_write= addrToRead - adr - 8; + *write_error = 4; + *repeat_error = fail; + flashAddr.bit.addr2 = 0x08; + tryNumb++; + // asm (" ESTOP0"); //for save flash life + } + } + + } + if ((*write_error != 0) && (tryNumb < 3) && (countInMemWrite < 3)) { + memWrite (adr_device, adr, adr_eeprom, size, ok_write, write_error, repeat_error ); + } + countInMemWrite = 0; + } + + + tryNumb =0; + + WriteMemory(ADR_CONTR_REG_FOR_WRITE, 0xffff); + WriteMemory(ADR_CONTR_REG_FOR_READ, 0xffff); + + project.reload_all_plates_without_reset_no_stop_error();// wait_start_cds + load_cfg + + + + WriteMemory(ADR_BUS_ERROR_READ, 0); + + if(i_ReadMemory(ADR_ERRORS_TOTAL_INFO)) //Если на линиЯх остались ошибки. + { + xerror(main_er_ID(3),(void *)0); + } + + + project.start_parallel_bus(); +} diff --git a/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.h b/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.h new file mode 100644 index 0000000..a9fa2bf --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xPeriphSP6_loader.h @@ -0,0 +1,133 @@ +#ifndef _XPERIPHSP6_LOADER_H +#define _XPERIPHSP6_LOADER_H + +typedef union{ + unsigned int all; + struct{ + unsigned int loader_on:1; + unsigned int cs:1; + unsigned int reserved0:2; + unsigned int rw:1; + unsigned int mode:1; + unsigned int reserved1:1; + unsigned int data:1; + unsigned int reserved2:1; + unsigned int clock:1; + unsigned int reserved3:1; + unsigned int plane_addr:4; + unsigned int eeprom_read:1; + }bit; +}ControlReg; + + +typedef union{ + unsigned long all; + struct{ + unsigned int addr0:8; + unsigned int addr1:8; + unsigned int addr2:8; + unsigned int reserved:8; + }bit; +}FlashAddr; + +typedef union{ + unsigned long all; + struct{ + unsigned int reserved:16; + unsigned int reserved1:15; + unsigned int data:1; + }bit; +}AddrToSent; + + +typedef union{ + unsigned int all; + struct{ + unsigned int reserved0:8; + unsigned int dataReceived:1; + unsigned int reserved1:6; + unsigned int data:1; + }bit; +}Byte; + +typedef union{ + unsigned int all; + struct{ + unsigned int dataReceived:1; + unsigned int reserved1:14; + unsigned int data:1; + }bit; +}Word; + +typedef union{ + unsigned int all; + struct{ + unsigned int bit0:1; + unsigned int bit1:1; + unsigned int bit2:1; + unsigned int bit3:1; + + unsigned int bit4:1; + unsigned int bit5:1; + unsigned int bit6:1; + unsigned int bit7:1; + + unsigned int bit8:1; + unsigned int bit9:1; + unsigned int bit10:1; + unsigned int bit11:1; + + unsigned int bit12:1; + unsigned int bit13:1; + unsigned int bit14:1; + unsigned int bit15:1; + + }bit; +}WordToReverse; + +typedef union{ + unsigned int all; + struct{ + unsigned int bit0:1; + unsigned int bit1:1; + unsigned int bit2:1; + unsigned int bit3:1; + + unsigned int bit4:1; + unsigned int bit5:1; + unsigned int bit6:1; + unsigned int bit7:1; + + unsigned int bit8:1; + unsigned int bit9:1; + unsigned int bit10:1; + unsigned int bit11:1; + + unsigned int bit12:1; + unsigned int bit13:1; + unsigned int bit14:1; + unsigned int bit15:1; + }bit; +}WordReversed; + + + +void memWrite (unsigned int adr_device, volatile unsigned long adr, + volatile unsigned long adr_eeprom, volatile unsigned long size, unsigned long *ok_write, + unsigned long *write_error, unsigned long *repeat_error ); + + +void RDID(void); +void RDSR(void); +void WREN(void); +void WRDI(void); +void WRSR(void); +void RDSR(void); +void ERASE(void); +void READ(void); +void PROGRAM(void); + + + +#endif + diff --git a/Inu/Src2/N12_Xilinx/x_basic_types.h b/Inu/Src2/N12_Xilinx/x_basic_types.h new file mode 100644 index 0000000..2991441 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_basic_types.h @@ -0,0 +1,111 @@ +#ifndef X_BASIC_TYPES_H /* prevent circular inclusions */ +#define X_BASIC_TYPES_H /* by using protection macros */ + + + +#ifndef TRUE + #define TRUE 1 +#endif + +#ifndef FALSE + #define FALSE 0 +#endif + +#ifndef NULL + #define NULL 0 +#endif + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +typedef signed char Int8; +typedef signed int Int16; +typedef signed long Int32; +typedef signed long long Int64; + +typedef unsigned char UInt8; +typedef unsigned int UInt16; +typedef unsigned long UInt32; +typedef unsigned long long UInt64; + +#ifndef real +typedef float real; +#endif + + +typedef enum { + component_NotReady = 0x1, // не готов, не было инита и не было обмена + component_Ready = 0x2, // готов, прошел проверку на обмен по шине + component_Started = 0x4, // переходной режим, инит был, но обмена еще нет, после нескольких неудачных попыток обмена получим переход в component_Error + component_Error = 0x8, // ошибка или не прошел внутренний тест. + component_Detected = 0x10, // плата обнаружена, но обмен с ней отключен в настройках проекта. Только при запуске поиска ВСЕХ плат. + component_NotFinded = 0x20, // плата включена в настройках проекта, но не была обнаружена при старте программы. + component_NotDetected = 0x40, // плата не обнаружена, и обмен с ней отключен в настройках проекта. Только при запуске поиска ВСЕХ плат. + component_ErrorSBus = 0x80, // нет обмена по SBUS + component_ErrorPBus = 0x100 // авария по PBUS +} T_component_status; + +typedef enum { + local_status_NotReady = 0x1, // не готов, не было инита и не было обмена + local_status_Ok = 0x2, // Нет ошибок + local_status_Error = 0x4 // есть ошибки. +} T_local_status; + + +typedef enum { + status_Success = 0, + status_Failed = 1 +} T_status_ReturnType; + + + +//typedef UInt16 T_Status; + + +#define HiWord(l)((UInt16)(((UInt32)(l)>>16)&0xFFFF)) +#define LoWord(l)((UInt16)( (UInt32)(l) &0xFFFF)) + +#define HiByte(w)((UInt8)(((UInt16)(w)>>8)&0xFF)) +#define LoByte(w)((UInt8)( (UInt16)(w) &0xFF)) + +#define Byte3(l)((UInt8)(((UInt32)(l)>>24)&0xFF)) +#define Byte2(l)((UInt8)(((UInt32)(l)>>16)&0xFF)) +#define Byte1(l)((UInt8)(((UInt32)(l)>> 8)&0xFF)) +#define Byte0(l)((UInt8)( (UInt32)(l) &0xFF)) + +#define Bit_UInt32(bit_index, value) ((UInt32)((((UInt32)(value)) >> (bit_index)) & 0x01)) + + +#define UInt16_Byte0(c) ((((UInt16)(c)) << 0) & 0x00ff) +#define UInt16_Byte1(c) ((((UInt16)(c)) << 8) & 0xff00) + +#define UInt32_Byte0(c) ((((UInt32)(c)) << 0) & 0x000000ff) +#define UInt32_Byte1(c) ((((UInt32)(c)) << 8) & 0x0000ff00) +#define UInt32_Byte2(c) ((((UInt32)(c)) << 16) & 0x00ff0000) +#define UInt32_Byte3(c) ((((UInt32)(c)) << 24) & 0xff000000) + +#define UInt32_LoWord(w) ((((UInt32)(w)) << 0) & 0x0000ffff) +#define UInt32_HiWord(w) ((((UInt32)(w)) << 16) & 0xffff0000) + +#define UInt16_Bit(index, value) ((((UInt16)(value)) & 0x0001) << (index)) +#define UInt32_Bit(index, value) ((((UInt32)(value)) & 0x00000001) << (index)) + + + +#define X_ASSERT_ESTOP0(useit) \ +{ \ + if(useit == TRUE) \ + { \ + X_Stop(); \ + asm (" ESTOP0"); \ + } \ +} + + +/*------------------------------------------------------------------------------ + Prototypes for the functions in x_basic_types.c +------------------------------------------------------------------------------*/ + +void X_Stop(); + +#endif diff --git a/Inu/Src2/N12_Xilinx/x_int13.c b/Inu/Src2/N12_Xilinx/x_int13.c new file mode 100644 index 0000000..fe5f9d1 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_int13.c @@ -0,0 +1,218 @@ +#include "x_int13.h" + +#include <281xEvTimersInit.h> +#include + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "xp_write_xpwm_time.h" +#include "params.h" +#include "pwm_test_lines.h" +#include "sync_tools.h" +#include "profile_interrupt.h" + +//Pointers to handler functions +void (*int13_handler)() = NULL; + + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// + +//unsigned int enable_profile_led1_pwm = 1; +//unsigned int enable_profile_led2_pwm = 1; + + + +int InitXilinxSpartan2E(void (*int_handler)()) +{ + int err; + + project.controller.status = component_NotReady; + + err = load_xilinx_new(0x130000, SIZE_XILINX200); + if (err) + return err; + + err = test_xilinx_live(); + + +#ifdef ENABLE_XINTC_INT13 + if (int_handler) + XIntcInterruptSetup(int_handler); + else + err = 1; +#endif + + if (err == 0) + project.controller.status = component_Ready; + + return err; +} + +#pragma CODE_SECTION(XIntc_INT13_Handler,".fast_run2"); +interrupt void XIntc_INT13_Handler(void) +{ + static int l2; + + IER &= MINT13; // Set "global" priority + + if (xpwm_time.disable_sync_out==0) + { + if (xpwm_time.do_sync_out) + { + i_sync_pin_on(); + + #if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_17_ON; + #endif + + + } + else + { + i_sync_pin_off(); + + #if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_17_OFF; + #endif + + } + } + + if (xpwm_time.what_next_interrupt==PWM_LOW_LEVEL_INTERRUPT) + { + l2 = 1; + } + else + l2 = 0; + + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.pwm && l2) + i_led1_on_off_special(1); +#endif + +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.pwm && l2) + i_led2_on_off_special(1); + +#endif + + + + + EINT; + + // Insert ISR Code here....... + + +// i_led2_on_off(1); +// IER &= 0xEFFF; + + if (project.controller.write.setup.bit.use_int13 == 1) + { + +// EnableInterrupts(); + //Останавливаем прерывание, в котором производим расчёты, из-за которых плавало прерывание ШИМ +// stop_eva_timer1(); + + if(int13_handler) + { + int13_handler(); + } + //Запускаем обратно +//// start_eva_timer1(); +// DINT; +// +// IFR &= 0xefff; // очистим если вдруг прерывание уже пришло! +// IER |= M_INT13; + } + else + { +// IFR &= 0xefff; // очистим если вдруг прерывание уже пришло! +// IER |= M_INT13; + + } + + +// EnableInterrupts(); +// c = IFR; // & 0x0100 +// if (c) +// { +// count_lost_interrupt++; +// IFR &= 0xfeff; // очистим если вдруг прерывание уже пришло! +// } +// EnableInterrupts(); +// i_led2_on_off(0); + +// IFR &= 0xfeff; // очистим если вдруг прерывание уже пришло! +// EINT; + + +#if (_ENABLE_INTERRUPT_PROFILE_LED1) + if (profile_interrupt.for_led1.bits.pwm) + i_led1_on_off_special(0); +#endif +#if (_ENABLE_INTERRUPT_PROFILE_LED2) + if (profile_interrupt.for_led2.bits.pwm) + if (l2) + i_led2_on_off_special(0); +#endif + + +} + +int XIntcInterruptSetup(void (*int_handler)()) +{ + int result = 0; + + EALLOW; + + GpioMuxRegs.GPEMUX.bit.XNMI_XINT13_GPIOE2=1; +// GpioMuxRegs.GPEDIR.bit.GPIOE2 = 0; +// GpioDataRegs.GPESET.bit.GPIOE2 = 1; + + PieVectTable.XINT13=&XIntc_INT13_Handler; + int13_handler = int_handler; +// PieCtrlRegs.PIECRTL.bit. + XIntruptRegs.XNMICR.bit.POLARITY=0; + XIntruptRegs.XNMICR.bit.SELECT=1; + XIntruptRegs.XNMICR.bit.ENABLE=0; + +// Enable interrupt 13 + // IER |= M_INT13; + + project.controller.read.status.bit.int13_inited = 1; + +// EDIS; +// EnableInterrupts(); + + /* + * Start the interrupt controller in simulation mode. + */ + // result = XIntc_Start(Ptr, intc_mode_is_Sim); // sim mode +// if (!(result == status_Success)) + return result; + +// return status_Success; +} + +void start_int13_interrupt(void) +{ + // Enable interrupt 13 + IER |= M_INT13; +} + +void stop_int13_interrupt(void) +{ + // Disable interrupt 13 +// IER &= ~(M_INT13); + IER &= MINT13; // Set "global" priority +} diff --git a/Inu/Src2/N12_Xilinx/x_int13.h b/Inu/Src2/N12_Xilinx/x_int13.h new file mode 100644 index 0000000..ebe2b50 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_int13.h @@ -0,0 +1,36 @@ +#ifndef _X_INT13_H +#define _X_INT13_H + +#include + + + + + +#if(C_PROJECT_TYPE==PROJECT_22220) +#define ENABLE_XINTC_INT13 1 +#endif + +#if(C_PROJECT_TYPE==PROJECT_BALZAM) +#define ENABLE_XINTC_INT13 1 +#endif + + +#if(C_PROJECT_TYPE==PROJECT_23550) +#define ENABLE_XINTC_INT13 1 +#endif + + + +////////////////////////////////////////// + + +int InitXilinxSpartan2E(void (*int_handler)()); + +int XIntcInterruptSetup(void (*int_handler)()); + +void start_int13_interrupt(void); +void stop_int13_interrupt(void); + + +#endif diff --git a/Inu/Src2/N12_Xilinx/x_parallel_bus.c b/Inu/Src2/N12_Xilinx/x_parallel_bus.c new file mode 100644 index 0000000..ea4001d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_parallel_bus.c @@ -0,0 +1,238 @@ + +#include "x_parallel_bus.h" + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Functions.h" +#include "xp_controller.h" +#include "xerror.h" + + +X_PARALLEL_BUS x_parallel_bus_project = X_PARALLEL_BUS_DEFAULTS; + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_run_cmd(X_PARALLEL_BUS *v) +{ + volatile unsigned int d_wr; + + d_wr = ( (v->flags.bit.cmd_start & 0x1) << 15 ) | ( (v->setup.setup_error_count_read & 0xf) << 8 ) | ((v->setup.size_table - 1) & 0xff); + WriteMemory(ADR_PARALLEL_BUS_CMD, d_wr); + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_clear_table(X_PARALLEL_BUS *v) +{ + v->setup.size_table = -1; + v->setup.free_table = -1; + + v->flags.bit.cmd_start = 1; + x_parallel_bus_run_cmd(v); + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +int x_parallel_bus_check_free_table(X_PARALLEL_BUS *v) +{ + + if ( (v->setup.size_table + v->setup.tms_adr_data_start) <= v->setup.tms_adr_data_finish) + { + return 1; + } + return 0; + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_add_table(X_PARALLEL_BUS *v) +{ + volatile unsigned int d_wr; + + if (v->flags.bit.started) + { + v->stop(v); + } + +// if (v->setup.size_table != 0) +// v->setup.size_table++; + if ( (v->setup.size_table + v->setup.tms_adr_data_start) > v->setup.tms_adr_data_finish) + { + // места в таблице нету!!! + xerror(xparall_bus_er_ID(1),(void *)0); + return; + } + + d_wr = v->setup.size_table & 0xff; + WriteMemory(ADR_PARALLEL_BUS_ADR_TABLE, d_wr); + d_wr = ( (v->slave_addr & 0xf) << 12 ) | ( (v->reg_addr & 0xf) << 8 ) | (( (v->setup.tms_adr_data_start & 0xff) + v->setup.size_table) & 0xff); + WriteMemory(ADR_PARALLEL_BUS_SET_TABLE, d_wr); + + v->setup.free_table = (v->setup.tms_adr_data_finish - v->setup.tms_adr_data_start) - v->setup.size_table; + +// x_parallel_bus_run_cmd(v); + + + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_start(X_PARALLEL_BUS *v) +{ + if (v->setup.size_table != 0) + { + v->flags.bit.error = 0; + v->flags.bit.cmd_start = 1; + v->flags.bit.was_started = 0; + + x_parallel_bus_run_cmd(v); + v->flags.bit.started = 1; + } +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_stop(X_PARALLEL_BUS *v) +{ + v->flags.bit.cmd_start = 0; + x_parallel_bus_run_cmd(v); + v->flags.bit.started = 0; + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_restart(X_PARALLEL_BUS *v) +{ + v->flags.bit.cmd_start = 0; + x_parallel_bus_run_cmd(v); + v->flags.bit.started = 0; + + v->flags.bit.error = 0; + v->flags.bit.cmd_start = 1; + x_parallel_bus_run_cmd(v); + v->flags.bit.started = 1; + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_init(X_PARALLEL_BUS *v) +{ + if (v->flags.bit.init) + return; + + v->setup.size_table = 0;//-1; + v->setup.tms_adr_data_start = ADR_FIRST_FREE; + v->setup.tms_adr_data_finish = ADR_LAST_FREE; + v->setup.setup_error_count_read = MAX_WAIT_ERROR_PARALLEL_BUS; + v->setup.free_table = v->setup.tms_adr_data_finish - v->setup.tms_adr_data_start; + + + v->flags.all = 0; + + v->slave_addr = 0; + v->reg_addr = 0; + v->error_count_start = 0; + v->count_read = 0; + + v->stop(v); + + v->flags.bit.init = 1; + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_parallel_bus_read_status(X_PARALLEL_BUS *v) +{ +// volatile unsigned int d_rd; + static unsigned int prev_error = 0; + T_controller_read r_c; + +// check prev status? + if (v->flags.bit.error) + return; + +// read status bus + r_c.errors_buses.all = i_ReadMemory(ADR_BUS_ERROR_READ); + + v->flags.bit.count_error = r_c.errors_buses.bit.count_error_pbus;// ((d_rd >> 8) & 0xf); + v->flags.bit.slave_addr_error = r_c.errors_buses.bit.slave_addr_error; // ((d_rd >> 4) & 0xf); + + if ( v->flags.bit.count_error >= v->setup.setup_error_count_read ) + { + v->flags.bit.error = 1; + } + else + v->flags.bit.error = 0; + + if ((prev_error != v->flags.bit.error ) && (v->flags.bit.error)) + { + v->error_count_start++; + if (v->flags.bit.started) + { + v->flags.bit.was_started = 1; + x_parallel_bus_stop(v); + } + } + + prev_error = v->flags.bit.error; + + if ( v->flags.bit.started && (v->flags.bit.error == 0)) + v->count_read++; + + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(x_parallel_bus_read_one_data,".fast_run"); +void x_parallel_bus_read_one_data(X_PARALLEL_BUS *v) +{ +// read data from parallel bus + v->data_table_read = i_ReadMemory(ADR_FIRST_FREE + v->adr_table_read); +} +//////////////////////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/x_parallel_bus.h b/Inu/Src2/N12_Xilinx/x_parallel_bus.h new file mode 100644 index 0000000..493b96b --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_parallel_bus.h @@ -0,0 +1,127 @@ +#ifndef _X_PARALLEL_BUS_H +#define _X_PARALLEL_BUS_H + +#define MAX_WAIT_ERROR_PARALLEL_BUS 3 // макс. кол-во ожиданиЯ чтениЯ с шины + + + +typedef union { + unsigned int all; + struct { + unsigned int started:1; + unsigned int error:1; + unsigned int cmd_start:1; + unsigned int count_error:4; + unsigned int slave_addr_error:4; + unsigned int init:1; + unsigned int was_started:1; + unsigned int rezerv:3; + + } bit; +} X_PARALLEL_BUS_flags; + + +typedef struct { + unsigned int setup_error_count_read; // настройка макс кол-ва попыток чтений с шины до возникновениЯ ошибки + int size_table; // кол-во данных в обмене (считаетсЯ автоматически при вызове функции add_table + unsigned int tms_adr_data_finish; //конечный адрес в памЯти TMS длЯ получениЯ данных с шины , должен быть свободен от спец регистров + unsigned int tms_adr_data_start; // начальный адрес в памЯти TMS длЯ получениЯ данных с шины, должен быть свободен от спец регистров + int free_table; // кол-во свободныз данных в таблице +} X_PARALLEL_BUS_Setup; + +#define X_PARALLEL_BUS_Setup_DEFAULTS {MAX_WAIT_ERROR_PARALLEL_BUS, -1, 0, 0, -1} + +typedef struct { X_PARALLEL_BUS_flags flags; // флаги + X_PARALLEL_BUS_Setup setup; // настройка + unsigned int slave_addr; // номер периф.платы + unsigned int reg_addr; // адрес внутреннего регистра длЯ парал. шины в периф.плате + unsigned int error_count_start; // общее колич-во ошибок запуска шины + unsigned int count_read; // общее колич-во чтениЯ шины + unsigned int adr_table_read; // номер из таблицы длЯ чтениЯ = 0 _ (size_table-1) , + // adr_table_read + tms_adr_data_start + unsigned int data_table_read; // прочитанный байт из parallel bus, + + +// unsigned int error_count_write; // общее колич-во ошибок записи +// unsigned int error_count_hold; // общее колич-во ошибок захвата шины + void (*clear_table)(); // Pointer to read function + void (*add_table)(); // Pointer to read function + void (*start)(); // Pointer to read function + void (*stop)(); // Pointer to read function + void (*restart)(); // Pointer to read function + void (*init)(); // Pointer to init function + void (*read_status)(); // Pointer to init function + void (*read_one_data)(); // Pointer to init function + int (*check_free_table)(); // Pointer to init function + + }X_PARALLEL_BUS; + + + +/* +// таймаут ожиданиЯ выполениЯ команды +#define TIME_OUT_SERIAL_BUS 10000 // max 65535 + + +#define CMD_SERIAL_BUS_READ 0x0000 +#define CMD_SERIAL_BUS_WRITE 0x8000 + +*/ + + +typedef X_PARALLEL_BUS *X_PARALLEL_BUS_handle; + +#define X_PARALLEL_BUS_DEFAULTS { 0, \ + X_PARALLEL_BUS_Setup_DEFAULTS, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + (void (*)(Uint32))x_parallel_bus_clear_table,\ + (void (*)(Uint32))x_parallel_bus_add_table,\ + (void (*)(Uint32))x_parallel_bus_start,\ + (void (*)(Uint32))x_parallel_bus_stop,\ + (void (*)(Uint32))x_parallel_bus_restart,\ + (void (*)(Uint32))x_parallel_bus_init,\ + (void (*)(Uint32))x_parallel_bus_read_status,\ + (void (*)(Uint32))x_parallel_bus_read_one_data,\ + (int (*)(Uint32))x_parallel_bus_check_free_table\ + } + + +void x_parallel_bus_clear_table(X_PARALLEL_BUS_handle); +void x_parallel_bus_add_table(X_PARALLEL_BUS_handle); +void x_parallel_bus_start(X_PARALLEL_BUS_handle); +void x_parallel_bus_stop(X_PARALLEL_BUS_handle); + +void x_parallel_bus_restart(X_PARALLEL_BUS_handle); +void x_parallel_bus_init(X_PARALLEL_BUS_handle); + +void x_parallel_bus_read_status(X_PARALLEL_BUS_handle); + +void x_parallel_bus_read_one_data(X_PARALLEL_BUS_handle); +int x_parallel_bus_check_free_table(X_PARALLEL_BUS_handle); + +extern X_PARALLEL_BUS x_parallel_bus_project; + + +#define read_pbus_value(bit,adr,res) {if (bit) res = i_ReadMemory(adr++); else res = 0; } +#define read_pbus_value_full(bit,adr,res) {res = i_ReadMemory(adr++); } + +#define read_pbus_adc_value(bit,adr,res) {if (bit) res = i_ReadMemory(adr++) & 0xfff; else res = 0; } +#define read_pbus_adc_value_full(bit,adr,res) {res = i_ReadMemory(adr++) & 0xfff; } + +// ver 2 +#define read_pbus_value_v2(bit,adr,res) {if (bit) { res = i_ReadMemory(adr); i_WriteMemory(adr++,0x0); } else res = 0; } +#define read_pbus_value_full_v2(bit,adr,res) {res = i_ReadMemory(adr); i_WriteMemory(adr++,0x0); } +#define read_pbus_value_full_v3(bit,adr,res) {res = i_ReadMemory(adr++); } + +#define read_pbus_adc_value_v2(bit,adr,res) {if (bit) { res = i_ReadMemory(adr) & 0xfff; i_WriteMemory(adr++,0x0);} else res = 0; } +#define read_pbus_adc_value_full_v2(bit,adr,res) {res = i_ReadMemory(adr) & 0xfff; i_WriteMemory(adr++,0x0); } + + + +#endif // end _X_PARALLEL_BUS_H + diff --git a/Inu/Src2/N12_Xilinx/x_project_useit.h b/Inu/Src2/N12_Xilinx/x_project_useit.h new file mode 100644 index 0000000..0ce3a1b --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_project_useit.h @@ -0,0 +1,7 @@ +#ifndef PROJECT_USEIT_H +#define PROJECT_USEIT_H + + + +#endif // end PROJECT_USEIT_H + diff --git a/Inu/Src2/N12_Xilinx/x_serial_bus.c b/Inu/Src2/N12_Xilinx/x_serial_bus.c new file mode 100644 index 0000000..fbc0dbc --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_serial_bus.c @@ -0,0 +1,319 @@ +#include "x_serial_bus.h" + +#include "DSP281x_Examples.h" +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Functions.h" +#include "TuneUpPlane.h" +#include "x_parallel_bus.h" +#include "xp_controller.h" + + + +X_SERIAL_BUS x_serial_bus_project = X_SERIAL_BUS_DEFAULTS; +T_controller_read r_c_sbus; + +static unsigned int counterSBWriteErrors = 0; + +/////////////////////////////////////////////////////// +// +// +// Example use: +// +// x_serial_bus_project.init(&x_serial_bus_project); +// +// x_serial_bus_project.reg_addr = 1; // adr memory in plate +// x_serial_bus_project.slave_addr = 6; // number plate +// +// x_serial_bus_project.read(&x_serial_bus_project); // read +// +// if (x_serial_bus_project.flags.bit.read_error==0) // check error +// { +// x_serial_bus_project.write_data = 1000; // write data +// x_serial_bus_project.write(&x_serial_bus_project); // make write +// } +// +// check return data: +// +// x_serial_bus_project.flags.bit.read_error - error +// x_serial_bus_project.flags.bit.write_error - error +// x_serial_bus_project.error_count_read - sum count read +// x_serial_bus_project.error_count_write - sum count write +/////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// Read from serial bus +//////////////////////////////////////////////////////////////// +int x_serial_bus_read(X_SERIAL_BUS *v) +{ + volatile unsigned int d_rd, d_wr; + unsigned int time_out = 0; + int err = 0; + + if (v->slave_addr>0xf) +// overfull adr - error? + return 1; +// check bus hold? + if (v->flags.bit.count_hold_bus) + // bus hold - error? + return 1; + +// test hold bus + v->flags.bit.count_hold_bus++; + if (v->flags.bit.count_hold_bus>1) + { + // parallel hold - error? + v->error_count_hold++; + return 1; + } + +// clear bus flags + d_rd = i_ReadMemory(ADR_SERIAL_BUS_DATA_READ); + +// read status bus +// d_rd = i_ReadMemory(ADR_BUS_ERROR_READ); + r_c_sbus.errors_buses.all = i_ReadMemory(ADR_BUS_ERROR_READ); + v->flags.bit.error = r_c_sbus.errors_buses.bit.err_sbus;// ((d_rd >> 14) & 0x1); + v->flags.bit.trans_compl = r_c_sbus.errors_buses.bit.sbus_updated;//((d_rd >> 15) & 0x1); + +// check status bits - all clear? +// if (v->flags.bit.error || v->flags.bit.trans_compl) + if (v->flags.bit.trans_compl) + { + v->flags.bit.read_error = 2; + v->error_count_read++; + return 1; + } + +// write cmd + d_wr = CMD_SERIAL_BUS_READ | ( (v->slave_addr & 0xf) << 4 ) | (v->reg_addr & 0xf); + WriteMemory(ADR_SERIAL_BUS_CMD, d_wr); + +// wait transmited data + v->flags.bit.trans_compl = 0; + v->flags.bit.error_timeout = 0; + time_out = 0; + + DELAY_US(200); + while (!v->flags.bit.trans_compl) + { +// read status bus +// d_rd = i_ReadMemory(ADR_BUS_ERROR_READ); + r_c_sbus.errors_buses.all = i_ReadMemory(ADR_BUS_ERROR_READ); + v->flags.bit.error = r_c_sbus.errors_buses.bit.err_sbus;//((d_rd >> 14) & 0x1); + v->flags.bit.trans_compl = r_c_sbus.errors_buses.bit.sbus_updated; //((d_rd >> 15) & 0x1); + +//check timeout + time_out++; + if (time_out>TIME_OUT_SERIAL_BUS) + { +// time out - error! + v->flags.bit.error_timeout = 1; + break; + } + + if (v->flags.bit.trans_compl) + { +// check error + if (v->flags.bit.error==0) + { +// data ready - read it! + d_rd = i_ReadMemory(ADR_SERIAL_BUS_DATA_READ); + v->read_data = d_rd; + } + } + } +// clear bus flags + d_rd = i_ReadMemory(ADR_SERIAL_BUS_DATA_READ); + if (v->flags.bit.error_timeout || v->flags.bit.error) + { + v->flags.bit.read_error = 1; + v->error_count_read++; + err = 1; + } + else + { + v->flags.bit.read_error = 0; + v->ok_count_read++; + } + +// unhold bus + v->flags.bit.count_hold_bus = 0; + v->count_timer = time_out; + + + return err; +} + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// Write to serial bus +//////////////////////////////////////////////////////////////// +int x_serial_bus_write(X_SERIAL_BUS *v) +{ + volatile unsigned int d_rd, d_wr; + unsigned int time_out = 0; + int err = 0; + + if (v->slave_addr>0xf) +// overfull adr - error? + return 1; + +// check bus hold? + if (v->flags.bit.count_hold_bus) + return 1; + +// test hold bus + if (v->flags.bit.count_hold_bus<8) + v->flags.bit.count_hold_bus++; + + if (v->flags.bit.count_hold_bus>1) + { + // parallel hold - error? + v->error_count_hold++; + v->flags.bit.count_hold_bus = 0; + return 1; + } + + + //cycle to write several times if there was some errors + counterSBWriteErrors = 0; + do{ + +// clear bus flags + d_rd = i_ReadMemory(ADR_SERIAL_BUS_DATA_READ); + +// read status bus +// d_rd = i_ReadMemory(ADR_BUS_ERROR_READ); + r_c_sbus.errors_buses.all = i_ReadMemory(ADR_BUS_ERROR_READ); + v->flags.bit.error = r_c_sbus.errors_buses.bit.err_sbus;//((d_rd >> 14) & 0x1); + v->flags.bit.trans_compl = r_c_sbus.errors_buses.bit.sbus_updated; //((d_rd >> 15) & 0x1); + +// check status bits - all clear? +// if (v->flags.bit.error || v->flags.bit.trans_compl) + if (v->flags.bit.trans_compl) + { + v->flags.bit.read_error = 2; + v->error_count_write++; + v->flags.bit.count_hold_bus = 0; + return 1; + } + +// write data + WriteMemory(ADR_SERIAL_BUS_DATA_WRITE, v->write_data); + +// write cmd + d_wr = CMD_SERIAL_BUS_WRITE | ( (v->slave_addr & 0xf) << 4 ) | (v->reg_addr & 0xf); + WriteMemory(ADR_SERIAL_BUS_CMD, d_wr); + +// wait transmited data + v->flags.bit.trans_compl = 0; + v->flags.bit.error_timeout = 0; + time_out = 0; + + while (!v->flags.bit.trans_compl) + { +// read status bus + d_rd = i_ReadMemory(ADR_BUS_ERROR_READ); + v->flags.bit.error = ((d_rd >> 14) & 0x1); + v->flags.bit.trans_compl = ((d_rd >> 15) & 0x1); + +//check timeout + time_out++; + if (time_out>TIME_OUT_SERIAL_BUS) + { +// time out - error! + v->flags.bit.error_timeout = 1; + break; + } + + if (v->flags.bit.trans_compl) + { +// d_rd = i_ReadMemory(ADR_BUS_ERROR_READ); +// if (v->flags.bit.error==0) +// { +// } + break; + } + + } + + if (v->flags.bit.error) + { + counterSBWriteErrors++; // если ошибка есть в этом месте, то повторЯем передачу + } + else + { + break; // если тут ошибок нет, то прерываем цикл и едем дальше + } + + + }while(counterSBWriteErrors <= SB_ERROR_REPEATS); + + +// clear bus flags + d_rd = i_ReadMemory(ADR_SERIAL_BUS_DATA_READ); + + if (v->flags.bit.error_timeout || v->flags.bit.error) + { + v->flags.bit.write_error = 1; + v->error_count_write++; + err = 1; + } + else + v->ok_count_write++; + + v->count_timer = time_out; + +// unhold bus + v->flags.bit.count_hold_bus = 0; + return err; + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +void x_serial_bus_check(X_SERIAL_BUS *v) +{ + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + +void x_serial_bus_init(X_SERIAL_BUS *v) +{ + v->flags.all = 0; + + v->count_timer = 0; + v->read_data = 0x0; + v->write_data = 0x0; + v->reg_addr = 0; + v->slave_addr = 0; + + v->error_count_read = 0; + v->error_count_write = 0; + v->error_count_hold = 0; + v->ok_count_read = 0; + v->ok_count_write = 0; +} + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + +void x_serial_bus_clear_stat_error(X_SERIAL_BUS *v) +{ + v->error_count_read = 0; + v->error_count_write = 0; + v->error_count_hold = 0; + v->count_timer = 0; + + v->ok_count_read = 0; + v->ok_count_write = 0; + +} diff --git a/Inu/Src2/N12_Xilinx/x_serial_bus.h b/Inu/Src2/N12_Xilinx/x_serial_bus.h new file mode 100644 index 0000000..5d591fa --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_serial_bus.h @@ -0,0 +1,87 @@ +#ifndef _X_SERIAL_BUS_H +#define _X_SERIAL_BUS_H + +// таймаут ожиданиЯ выполениЯ команды +#define TIME_OUT_SERIAL_BUS 1000 //10000 // max 65535 + + +#define CMD_SERIAL_BUS_READ 0x0000 +#define CMD_SERIAL_BUS_WRITE 0x8000 + +#define SB_ERROR_REPEATS 7 + + + +typedef union { + unsigned int all; + struct { + unsigned int data_ready:1; + unsigned int trans_compl:1; + unsigned int error:1; + unsigned int write_error:1; + unsigned int read_error:2; + unsigned int error_timeout:1; + unsigned int count_hold_bus:3; + unsigned int rezerv:6; + } bit; +} X_SERIAL_BUS_flags; + + + +typedef struct { X_SERIAL_BUS_flags flags; // флаги + unsigned int slave_addr; // номер периф.платы + unsigned int reg_addr; // адрес внутреннего регистра в периф.плате + unsigned int write_data; // данные длЯ записи + unsigned int read_data; // прочитанные данные + unsigned int count_timer; // внутренний счтчик ожиданиЯ выполнениЯ команды + unsigned int error_count_read; // общее колич-во ошибок чтениЯ + unsigned int error_count_write; // общее колич-во ошибок записи + unsigned int error_count_hold; // общее колич-во ошибок захвата шины + unsigned int ok_count_read; // общее колич-во успещных чтений + unsigned int ok_count_write; // общее колич-во успешных записей + + int (*read)(); // Pointer to read function + int (*write)(); // Pointer to write function + void (*check)(); // Pointer to check function + void (*init)(); // Pointer to init function + void (*clear_stat)(); // Pointer to init function + }X_SERIAL_BUS; + + + + + +typedef X_SERIAL_BUS *X_SERIAL_BUS_handle; + +#define X_SERIAL_BUS_DEFAULTS { 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + (int (*)(Uint32))x_serial_bus_read,\ + (int (*)(Uint32))x_serial_bus_write,\ + (void (*)(Uint32))x_serial_bus_check,\ + (void (*)(Uint32))x_serial_bus_init,\ + (void (*)(Uint32))x_serial_bus_clear_stat_error\ + } + + +int x_serial_bus_read(X_SERIAL_BUS_handle); +int x_serial_bus_write(X_SERIAL_BUS_handle); +void x_serial_bus_check(X_SERIAL_BUS_handle); +void x_serial_bus_init(X_SERIAL_BUS_handle); +void x_serial_bus_clear_stat_error(X_SERIAL_BUS_handle); + +void xPeriphReadyCheck(void); + +extern X_SERIAL_BUS x_serial_bus_project; + + +#endif // end _X_SERIAL_BUS_H + diff --git a/Inu/Src2/N12_Xilinx/x_wdog.c b/Inu/Src2/N12_Xilinx/x_wdog.c new file mode 100644 index 0000000..c6a6501 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_wdog.c @@ -0,0 +1,23 @@ +/* + * x_wdog.c + * + * Created on: 10 февр. 2020 г. + * Author: yura + */ + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" + + +void stop_wdog(void) +{ + i_WriteMemory(ADR_PWM_WDOG, 0x000e); +} + +void start_wdog(void) +{ + i_WriteMemory(ADR_PWM_WDOG, 0x800f); +} + + + diff --git a/Inu/Src2/N12_Xilinx/x_wdog.h b/Inu/Src2/N12_Xilinx/x_wdog.h new file mode 100644 index 0000000..b5e61f6 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/x_wdog.h @@ -0,0 +1,18 @@ +/* + * x_wdog.h + * + * Created on: 10 февр. 2020 г. + * Author: yura + */ + +#ifndef _X_WDOG_H_ +#define _X_WDOG_H_ + + + +void stop_wdog(void); +void start_wdog(void); + + + +#endif /* _X_WDOG_H_ */ diff --git a/Inu/Src2/N12_Xilinx/xerror.c b/Inu/Src2/N12_Xilinx/xerror.c new file mode 100644 index 0000000..b3fdc10 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xerror.c @@ -0,0 +1,428 @@ +#include "xerror.h" + + + +/* +#pragma CODE_SECTION(xassert,".fast_run"); +int xassert(unsigned int er, unsigned int er_ID, void *CallBackRef){ + if(er) + return xerror(er_ID, CallBackRef); + return 0; +} +*/ + +int xerror(unsigned int er_ID, void *CallBackRef) +{ + + switch(er_ID){ + + +//main + + // error test Xilinx. Xilinx dead. + case main_er_ID(1): XERROR_DEBUG_MODE; break; + +// ошибка в настройках проекта, размерность массива например + case main_er_ID(2): XERROR_DEBUG_MODE; break; + +// ошибка на линии err0 + case main_er_ID(3): XERROR_DEBUG_MODE; break; + +//xtools + + // error load Xilinx. faulse level on line INIT + case xtools_er_ID(1): XERROR_DEBUG_MODE; break; + + // error load Xilinx. faulse level on line DONE + case xtools_er_ID(2): XERROR_DEBUG_MODE; break; + + + +//xseeprom + + //error write to serial eeprom. xseeprom_write_all + case xseeprom_er_ID(1): XERROR_DEBUG_MODE; break; + + // error read from serial eeprom. xseeprom_read_all + case xseeprom_er_ID(2): XERROR_DEBUG_MODE; break; + + // error compare serial eeprom. + case xseeprom_er_ID(3): XERROR_DEBUG_MODE; break; + + +//serialBus + + //error write to serial bus + case xserial_bus_er_ID(1): XERROR_DEBUG_MODE; break; + //error find plates on serial bus + case xserial_bus_er_ID(2): XERROR_DEBUG_MODE; break; + +//PBus + + //error setup to parall bus, overfull size pbus array! + case xparall_bus_er_ID(1): XERROR_DEBUG_MODE; break; + //error run parall bus! + case xparall_bus_er_ID(2): XERROR_DEBUG_MODE; break; + + default: XERROR_DEBUG_MODE; break; + + } + + + + return 1; + +} + + + + + +/* +int xerror(unsigned int er_ID, void *CallBackRef){ + + unsigned int er=1; + unsigned int Value; + static int count_error=0; + + // XIn_Plane XIn_Plane0; + +// if(x_mask_er) +// return 0; + +// asm (" ESTOP0"); + + switch(er_ID){ + + // error write/read + case main_er_ID(1): XERROR_DEBUG_MODE; xReady_reg_reset(); break; + + // error in write/read + //case xinput_new_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY +// case xinput_new_er_ID(2): XERROR_DEBUG_MODE; break; + case xinput_new_er_ID(2): XERROR_DEBUG_MODE_INPUT_NEW_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty + case xinput_new_er_ID(3): XERROR_DEBUG_MODE; break; + + // bad input parameter + case xinput_new_er_ID(4): XERROR_DEBUG_MODE; break; + + // too large parameter max,high or low + case xinput_new_er_ID(5): XERROR_DEBUG_MODE; break; + + // High_value must be more 0 + case xinput_new_er_ID(6): XERROR_DEBUG_MODE; break; + + // too large parameter Max_value + case xinput_new_er_ID(7): XERROR_DEBUG_MODE; break; + + // triggeing data is NOT READY + case xinput_new_er_ID(8): XERROR_DEBUG_MODE; break; + + // test write/read is failure + case xinput_new_er_ID(9): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xintc_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xintc_er_ID(2): XERROR_DEBUG_MODE; break; + + // unknown mode + case xintc_er_ID(3): XERROR_DEBUG_MODE; break; + + // Id is not exist + case xintc_er_ID(4): XERROR_DEBUG_MODE; break; + + // Handle is Null + case xintc_er_ID(5): XERROR_DEBUG_MODE; break; + + //self-test is failure because mode is Real or + //simulate of interrupt is failure because mode is Real + case xintc_er_ID(6): XERROR_DEBUG_MODE; break; + + //self-test is failure + case xintc_er_ID(7): XERROR_DEBUG_MODE; break; + + + + // error in write/read + case xserial_bus_er_ID(1): //XERROR_DEBUG_MODE; + count_error++; + Value=((XSerial_bus *)CallBackRef)->Adr.bit.AdrPlane; + break; + + // structure is NOT READY + case xserial_bus_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is empty + case xserial_bus_er_ID(3): XERROR_DEBUG_MODE; break; + + // PicoBlaze is not found in hardware + case xserial_bus_er_ID(4): XERROR_DEBUG_MODE; break; + + // serial bus is hang up + case xserial_bus_er_ID(5): XERROR_DEBUG_MODE; write_memory(((XSerial_bus *)CallBackRef)->BaseAddress+adr_Xserial_iar_ipr,0xffff); break; + + + + // error in write/read + case xserial_bus_simple_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xserial_bus_simple_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is empty + case xserial_bus_simple_er_ID(3): XERROR_DEBUG_MODE; break; + + // self-test is failure + case xserial_bus_simple_er_ID(4): XERROR_DEBUG_MODE; break; + + // tune is failure + case xserial_bus_simple_er_ID(5): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xsoft_fifo_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xsoft_fifo_er_ID(2): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xtimer_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xtimer_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is empty + case xtimer_er_ID(3): XERROR_DEBUG_MODE; break; + + // self-test is failure + case xtimer_er_ID(4): XERROR_DEBUG_MODE; break; + + // start is failure + case xtimer_er_ID(5): XERROR_DEBUG_MODE; break; + + // value_us must be more 0 + case xtimer_er_ID(6): XERROR_DEBUG_MODE; break; + + // hw is't compatible with software: RangeCount_Is too small or time_us too large + case xtimer_er_ID(7): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xplane_hwp_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xplane_hwp_er_ID(2): XERROR_DEBUG_MODE_HWP_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty or bad + case xplane_hwp_er_ID(3): XERROR_DEBUG_MODE; break; + + // test er_line is failure + case xplane_hwp_er_ID(4): XERROR_DEBUG_MODE; break; + + // error in write/read in dac + case xplane_hwp_er_ID(5): XERROR_DEBUG_MODE; break; + + // no error test is failure + case xplane_hwp_er_ID(6): XERROR_DEBUG_MODE; break; + + // watch timer test is failure + case xplane_hwp_er_ID(7): XERROR_DEBUG_MODE; break; + + // reference test is failure + case xplane_hwp_er_ID(8): XERROR_DEBUG_MODE; break; + + // define voltage test is failure + case xplane_hwp_er_ID(9): XERROR_DEBUG_MODE; break; + + // voltage test is failure + case xplane_hwp_er_ID(10): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xtools_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + //case xtools_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is empty + //case xtools_er_ID(3): XERROR_DEBUG_MODE; break; + + // bad input parameter Time_Unit_Is + case xtools_er_ID(4): XERROR_DEBUG_MODE; break; + + // bad input parameter Time_Unit_Is + case xtools_er_ID(5): XERROR_DEBUG_MODE; break; + + // too large parameter Value + case xtools_er_ID(6): XERROR_DEBUG_MODE; break; + + // faulse level on line INIT + case xtools_er_ID(7): XERROR_DEBUG_MODE; break; + + // faulse level on line DONE + case xtools_er_ID(8): XERROR_DEBUG_MODE; break; + + + + + // error in write/read + //case xtk_plane_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xtk_plane_er_ID(2): XERROR_DEBUG_MODE_TK_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty + case xtk_plane_er_ID(3): XERROR_DEBUG_MODE; ((XTk_Plane *)CallBackRef)->IsReady=0; break; + + // self-test is failure + case xtk_plane_er_ID(4): XERROR_DEBUG_MODE; ((XTk_Plane *)CallBackRef)->IsReady=0; break; + + // no connection on serial bus + case xtk_plane_er_ID(5): XERROR_DEBUG_MODE; ((XTk_Plane *)CallBackRef)->IsReady=0; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // test Tk_Bus is failure + case xtk_plane_er_ID(6): XERROR_DEBUG_MODE; ((XTk_Plane *)CallBackRef)->IsReady=0; break; + + + + // error in write/read + //case xtk_plane_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xin_plane_er_ID(2): XERROR_DEBUG_MODE_IN_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty + case xin_plane_er_ID(3): XERROR_DEBUG_MODE; ((XIn_Plane *)CallBackRef)->IsReady=0; break; + + // self-test is failure + case xin_plane_er_ID(4): XERROR_DEBUG_MODE; ((XIn_Plane *)CallBackRef)->IsReady=0; break; + + // no connection on serial bus + case xin_plane_er_ID(5): XERROR_DEBUG_MODE; ((XIn_Plane *)CallBackRef)->IsReady=0; if (XERROR_DEBUG_LEVEL==1) {er=0;}; break; + + // bad configuration of InputNew + case xin_plane_er_ID(6): XERROR_DEBUG_MODE; ((XIn_Plane *)CallBackRef)->IsReady=0; break; + + // error in set Real mode + case xin_plane_er_ID(7): XERROR_DEBUG_MODE; ((XIn_Plane *)CallBackRef)->IsReady=0; break; + + + + // error in write/read + //case xtk_plane_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xout_plane_er_ID(2): XERROR_DEBUG_MODE_OUT_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty + case xout_plane_er_ID(3): XERROR_DEBUG_MODE; ((XOut_Plane *)CallBackRef)->IsReady=0; break; + + // self-test is failure + case xout_plane_er_ID(4): XERROR_DEBUG_MODE; ((XOut_Plane *)CallBackRef)->IsReady=0; break; + + // no connection on serial bus + case xout_plane_er_ID(5): XERROR_DEBUG_MODE; ((XOut_Plane *)CallBackRef)->IsReady=0; if (XERROR_DEBUG_LEVEL==1) {er=0;}; break; + + // bad configuration of InputNew + //case xout_plane_er_ID(6): XERROR_DEBUG_MODE; break; + + // error in set Real mode + //case xout_plane_er_ID(7): XERROR_DEBUG_MODE; break; + + + + // error in write/read + //case xspeed_sensor_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + //case xspeed_sensor_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is empty + //case xspeed_sensor_er_ID(3): XERROR_DEBUG_MODE; break; + + // self-test is failure + //case xspeed_sensor_er_ID(4): XERROR_DEBUG_MODE; break; + + // bad configuration of InputNew + case xspeed_sensor_er_ID(5): XERROR_DEBUG_MODE; break; + + // too large parameter Filtr_Max + case xspeed_sensor_er_ID(6): XERROR_DEBUG_MODE; break; + + // too large parameter Lenth_Min + //case xspeed_sensor_er_ID(7): XERROR_DEBUG_MODE; break; + + // compare predefine macros is failure + case xspeed_sensor_er_ID(8): XERROR_DEBUG_MODE; break; + + // maximum of reriod is small + case xspeed_sensor_er_ID(9): XERROR_DEBUG_MODE; break; + + // maximum of reriod is small => overrun count_max_by_hw + case xspeed_sensor_er_ID(10): XERROR_DEBUG_MODE; break; + + // count_max_by_sw must be less count_max_by_hw + case xspeed_sensor_er_ID(11): XERROR_DEBUG_MODE; break; + + + + + // error in write/read + //case xcontroller_plane_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + //case xcontroller_plane_er_ID(2): XERROR_DEBUG_MODE; break; + + // config information is failure + case xcontroller_plane_er_ID(3): XERROR_DEBUG_MODE; break; + + // self-test is failure + //case xcontroller_plane_er_ID(4): XERROR_DEBUG_MODE; break; + + + + + + // error in write/read + //case xplane_analog_er_ID(1): XERROR_DEBUG_MODE; break; + + // structure is NOT READY + case xplane_analog_er_ID(2): XERROR_DEBUG_MODE_ANALOG_NOT_READY; if (XERROR_DEBUG_LEVEL==1) {er=0;} break; + + // config information is empty or bad + case xplane_analog_er_ID(3): XERROR_DEBUG_MODE; break; + + // test er_line is failure + // case xplane_analog_er_ID(4): XERROR_DEBUG_MODE; break; + + // error in write/read in dac + case xplane_analog_er_ID(5): XERROR_DEBUG_MODE_ANALOG; break; // xplane_analog_chanals_init(&XPlane_Analog_Chanals0); break; + + + + + default: break; + } + + x_er|=er; + xReady_reg_update(); + + return 1; +} + +*/ + + diff --git a/Inu/Src2/N12_Xilinx/xerror.h b/Inu/Src2/N12_Xilinx/xerror.h new file mode 100644 index 0000000..5694774 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xerror.h @@ -0,0 +1,66 @@ +#ifndef X_ERROR_H +#define X_ERROR_H + +#define XERROR_DEBUG_LEVEL 2 + +#define XERROR_DEBUG_MODE_ANALOG asm (" NOP") + + +#if (XERROR_DEBUG_LEVEL == 0) + #define XERROR_DEBUG_MODE asm (" NOP") +#else + #define XERROR_DEBUG_MODE asm (" ESTOP0") +#endif + + +#if (XERROR_DEBUG_LEVEL <= 1) + #define XERROR_DEBUG_MODE_TK_NOT_READY asm (" NOP") + #define XERROR_DEBUG_MODE_IN_NOT_READY asm (" NOP") + #define XERROR_DEBUG_MODE_OUT_NOT_READY asm (" NOP") + #define XERROR_DEBUG_MODE_HWP_NOT_READY asm (" NOP") + #define XERROR_DEBUG_MODE_ANALOG_NOT_READY asm (" NOP") + #define XERROR_DEBUG_MODE_INPUT_NEW_NOT_READY asm (" NOP") +#else + #define XERROR_DEBUG_MODE_TK_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_IN_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_OUT_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_HWP_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_ANALOG_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_INPUT_NEW_NOT_READY asm (" ESTOP0") + #define XERROR_DEBUG_MODE_HWP_ERROR_SET_LEVEL_PROTECT asm (" ESTOP0") +#endif + + + + #define main_er_ID(er_ID) ( 0 + er_ID) + #define xseeprom_er_ID(er_ID) (100 + er_ID) + #define xtools_er_ID(er_ID) (200 + er_ID) + #define xserial_bus_er_ID(er_ID) (300 + er_ID) + #define xparall_bus_er_ID(er_ID) (400 + er_ID) + #define xplane_hwp_er_ID(er_ID) (700 + er_ID) + #define xtk_plane_er_ID(er_ID) (900 + er_ID) + #define xin_plane_er_ID(er_ID) (1000 + er_ID) + +/* + #define xinput_new_er_ID(er_ID) (100 + er_ID) + #define xintc_er_ID(er_ID) (200 + er_ID) + #define xserial_bus_er_ID(er_ID) (300 + er_ID) + #define xserial_bus_simple_er_ID(er_ID) (400 + er_ID) + #define xsoft_fifo_er_ID(er_ID) (500 + er_ID) + #define xtimer_er_ID(er_ID) (600 + er_ID) + #define xplane_hwp_er_ID(er_ID) (700 + er_ID) + #define xtk_plane_er_ID(er_ID) (900 + er_ID) + #define xin_plane_er_ID(er_ID) (1000 + er_ID) + #define xout_plane_er_ID(er_ID) (1100 + er_ID) + #define xspeed_sensor_er_ID(er_ID) (1200 + er_ID) + #define xcontroller_plane_er_ID(er_ID) (1300 + er_ID) + #define xplane_analog_er_ID(er_ID) (1400 + er_ID) +*/ + int xerror(unsigned int er_ID, void *CallBackRef); +// int xassert(unsigned int er, unsigned int er_ID, void *CallBackRef); + +// #define XERROR_DEBUG_MODE_HWP_NOT_READY asm (" ESTOP0") + +void xPeriphErrReset(void); + +#endif //X_ERROR_H diff --git a/Inu/Src2/N12_Xilinx/xp_adc.c b/Inu/Src2/N12_Xilinx/xp_adc.c new file mode 100644 index 0000000..4df1e8e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_adc.c @@ -0,0 +1,643 @@ + +#include "xp_adc.h" + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_tools.h" +#include "xerror.h" + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void adc_init(T_adc *v) +{ + int old_started = 0; + unsigned int i, k; + + if (v->useit == 0) + { + clear_adr_sync_table(v->plane_address); + return ; + } + set_adr_sync_table(v->plane_address); + + if (x_parallel_bus_project.flags.bit.init==0) + x_parallel_bus_project.init(&x_parallel_bus_project); + + + old_started = x_parallel_bus_project.flags.bit.started; + + if (x_parallel_bus_project.flags.bit.started) + x_parallel_bus_project.stop(&x_parallel_bus_project); + + + x_parallel_bus_project.slave_addr = v->plane_address; + + // for (i=0;isetup_pbus.count_elements_pbus;i++) + for (i=0;i<16;i++) + { + if (v->setup_pbus.use_reg_in_pbus.all & (1<adr_pbus.adr_table[i] = x_parallel_bus_project.setup.size_table; + x_parallel_bus_project.add_table(&x_parallel_bus_project); + x_parallel_bus_project.reg_addr++; + x_parallel_bus_project.setup.size_table++; + } + else + { + // места в таблице нет!!! + xerror(xparall_bus_er_ID(1),(void *)0); + v->setup_pbus.use_reg_in_pbus.all &= (~(1<useit == 0) + return 0; + + adc_read_sbus(v); + adc_read_pbus(v); + return 0; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int adc_write_all(T_adc *v) +{ + if (v->useit == 0) + return 0; + + adc_write_sbus(v); + adc_write_pbus(v); + return 0; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int adc_write_sbus(T_adc *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 test reg + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.test; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + + +//6 protect_error + if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) + v->write.sbus.protect_error.bit.err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + + } + +//// + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int adc_write_pbus(T_adc *v) +{ + if (v->useit == 0) + return 0; + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int adc_read_sbus(T_adc *v) +{ + + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 test + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.test = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 id_plate + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.id_plate.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->type_cds_xilinx = v->read.type_cds_xilinx; + if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) // SP6 + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + + if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP2) + { + //6 protect_error + v->read.sbus.protect_error.all = 0; + //7 lock_status_error + v->read.sbus.lock_status_error.all = 0; + } + else // TYPE_CDS_XILINX_SP6 + { + //6 protect_error + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + //7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + } +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +#pragma CODE_SECTION(adc_read_pbus,".fast_run"); +int adc_read_pbus(T_adc *v) +{ + unsigned int i,k; + + if (v->useit == 0) + return 0; + + if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) + { + + + for (i=0,k=0;isetup_pbus.count_elements_pbus;i++) + { + if (v->setup_pbus.use_reg_in_pbus.all & (1<adr_pbus.adr_table[k]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.adc_value[i] = (x_parallel_bus_project.data_table_read & 0xfff); // наложили маску, т.к. в данных присутствует адрес канала. + k++; + } + else + { + v->read.pbus.adc_value[i] = 0xffff; + } + } + + } + else + { + + v->read.pbus.adc_value[0] = 0; + v->read.pbus.adc_value[1] = 0; + v->read.pbus.adc_value[2] = 0; + v->read.pbus.adc_value[3] = 0; + v->read.pbus.adc_value[4] = 0; + v->read.pbus.adc_value[5] = 0; + v->read.pbus.adc_value[6] = 0; + v->read.pbus.adc_value[7] = 0; + v->read.pbus.adc_value[8] = 0; + v->read.pbus.adc_value[9] = 0; + v->read.pbus.adc_value[10] = 0; + v->read.pbus.adc_value[11] = 0; + v->read.pbus.adc_value[12] = 0; + v->read.pbus.adc_value[13] = 0; + v->read.pbus.adc_value[14] = 0; + v->read.pbus.adc_value[15] = 0; + + } + return 0; +} + + + +//#define read_adc_value(bit,adr,res) {if (bit) res = i_ReadMemory(adr++) & 0xfff; else res = 0xffff; } +//#define read_adc_value(bit,adr,res) {if (bit) res = i_ReadMemory(adr++) & 0xfff; } +//#define read_adc_value_full(bit,adr,res) {res = i_ReadMemory(adr++) & 0xfff; } + + + +#pragma CODE_SECTION(adc_read_pbus_without_cycle,".fast_run"); +int adc_read_pbus_without_cycle(T_adc *v) +{ + unsigned long adr_adc; + unsigned int a_adc,i; + + if (v->useit == 0) + return 0; + + if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) + { +//i_led2_on(); + adr_adc = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; +// a_adc = 0; +/* + v->read.pbus.adc_value[0] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[1] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[2] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[3] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[4] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[5] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[6] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[7] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[8] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[9] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[10] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[11] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[12] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[13] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[14] = i_ReadMemory(ADR_FIRST_FREE); + v->read.pbus.adc_value[15] = i_ReadMemory(ADR_FIRST_FREE); +*/ + +// if (v->setup_pbus.use_reg_in_pbus.all == 0xffff) +// { + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_adc,v->read.pbus.adc_value[0]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_adc,v->read.pbus.adc_value[1]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_adc,v->read.pbus.adc_value[2]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_adc,v->read.pbus.adc_value[3]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_adc,v->read.pbus.adc_value[4]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_adc,v->read.pbus.adc_value[5]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg6,adr_adc,v->read.pbus.adc_value[6]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg7,adr_adc,v->read.pbus.adc_value[7]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg8,adr_adc,v->read.pbus.adc_value[8]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg9,adr_adc,v->read.pbus.adc_value[9]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg10,adr_adc,v->read.pbus.adc_value[10]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg11,adr_adc,v->read.pbus.adc_value[11]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg12,adr_adc,v->read.pbus.adc_value[12]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg13,adr_adc,v->read.pbus.adc_value[13]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg14,adr_adc,v->read.pbus.adc_value[14]); + read_pbus_adc_value_full(v->setup_pbus.use_reg_in_pbus.bit.reg15,adr_adc,v->read.pbus.adc_value[15]); +// } +// else +// { +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_adc,v->read.pbus.adc_value[0]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_adc,v->read.pbus.adc_value[1]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_adc,v->read.pbus.adc_value[2]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_adc,v->read.pbus.adc_value[3]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_adc,v->read.pbus.adc_value[4]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_adc,v->read.pbus.adc_value[5]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg6,adr_adc,v->read.pbus.adc_value[6]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg7,adr_adc,v->read.pbus.adc_value[7]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg8,adr_adc,v->read.pbus.adc_value[8]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg9,adr_adc,v->read.pbus.adc_value[9]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg10,adr_adc,v->read.pbus.adc_value[10]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg11,adr_adc,v->read.pbus.adc_value[11]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg12,adr_adc,v->read.pbus.adc_value[12]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg13,adr_adc,v->read.pbus.adc_value[13]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg14,adr_adc,v->read.pbus.adc_value[14]); +// read_pbus_adc_value(v->setup_pbus.use_reg_in_pbus.bit.reg15,adr_adc,v->read.pbus.adc_value[15]); +// } + +/* + if (v->setup_pbus.use_reg_in_pbus.bit.reg0) + { +// v->read.pbus.adc_value[0] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; +// a_adc++; + } + else + v->read.pbus.adc_value[0] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg1) + { +// v->read.pbus.adc_value[1] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[1] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[1] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg2) + { + v->read.pbus.adc_value[2] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[2] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg3) + { + v->read.pbus.adc_value[3] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[3] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg4) + { + v->read.pbus.adc_value[4] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[4] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg5) + { + v->read.pbus.adc_value[5] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[5] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg6) + { + v->read.pbus.adc_value[6] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[6] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg7) + { + v->read.pbus.adc_value[7] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[7] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg8) + { + v->read.pbus.adc_value[8] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[8] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg9) + { + v->read.pbus.adc_value[9] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[9] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg10) + { + v->read.pbus.adc_value[10] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[10] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg11) + { + v->read.pbus.adc_value[11] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[11] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg12) + { + v->read.pbus.adc_value[12] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[12] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg13) + { + v->read.pbus.adc_value[13] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + v->read.pbus.adc_value[0] = i_ReadMemory(adr_adc++) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[13] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg14) + { + v->read.pbus.adc_value[14] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[14] = 0xffff; + + if (v->setup_pbus.use_reg_in_pbus.bit.reg15) + { + v->read.pbus.adc_value[15] = i_ReadMemory(ADR_FIRST_FREE + adr_adc + a_adc) & 0xfff; + a_adc++; + } + else + v->read.pbus.adc_value[15] = 0xffff; +*/ +//i_led2_off(); + } + else + { + v->read.pbus.adc_value[0] = 0; + v->read.pbus.adc_value[1] = 0; + v->read.pbus.adc_value[2] = 0; + v->read.pbus.adc_value[3] = 0; + v->read.pbus.adc_value[4] = 0; + v->read.pbus.adc_value[5] = 0; + v->read.pbus.adc_value[6] = 0; + v->read.pbus.adc_value[7] = 0; + v->read.pbus.adc_value[8] = 0; + v->read.pbus.adc_value[9] = 0; + v->read.pbus.adc_value[10] = 0; + v->read.pbus.adc_value[11] = 0; + v->read.pbus.adc_value[12] = 0; + v->read.pbus.adc_value[13] = 0; + v->read.pbus.adc_value[14] = 0; + v->read.pbus.adc_value[15] = 0; + } + return 0; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void adc_reset_error(T_adc *v) +{ + if (v->useit == 0) + return ; + + if (v->status == component_Error || v->status == component_ErrorSBus) + v->status = component_Started; + + clear_cur_stat_sbus(&v->status_serial_bus); + + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + + clear_cur_stat_pbus(&v->status_parallel_bus); + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//7 cmd_reset_error + + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + } + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void adc_store_disable_error(T_adc *v) +{ + if (v->useit == 0) + return ; + + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + + v->store_protect_error = v->write.sbus.protect_error.all; + v->write.sbus.protect_error.all = 0; // disable all error. + + adc_write_sbus(v); + + } + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void adc_restore_enable_error(T_adc *v) +{ + if (v->useit == 0) + return ; + + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + + v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. + adc_write_sbus(v); + + } + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_adc.h b/Inu/Src2/N12_Xilinx/xp_adc.h new file mode 100644 index 0000000..eae3c84 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_adc.h @@ -0,0 +1,267 @@ +#ifndef XP_ADC_H +#define XP_ADC_H + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + +#define T_ADC_COUNT_ADR_PBUS 16 // count max elements in parallel bus + +#define T_ADC_SETUP_USE_ADR_PBUS 0xffff // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + UInt16 test; +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :14; + UInt16 err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :14; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; + +//14 + union + { + UInt16 all; + struct + { + UInt16 revision :5; + UInt16 version :6; + T_plate_type plate_type :5; + } bit; + } id_plate; + +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :14; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + +} T_adc_read_sbus; + +#define T_ADC_READ_SBUS_DEFAULTS {0,0,0,0,0} +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + UInt16 test; + +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :14; + UInt16 err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; + +//7 + UInt16 cmd_reset_error; + +} T_adc_write_sbus; + +#define T_ADC_WRITE_SBUS_DEFAULTS {0,0,0} +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//read reg parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 adc_value[T_ADC_COUNT_ADR_PBUS]; +} T_adc_read_pbus; + +#define T_ADC_READ_PBUS_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + +///////////////////////////////////////////////////////////// +// Table for adr parallel bus +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 adr_table[T_ADC_COUNT_ADR_PBUS]; +} T_adc_adr_pbus; + +#define T_ADC_ADR_PBUS_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 reg0 : 1; + UInt16 reg1 : 1; + UInt16 reg2 : 1; + UInt16 reg3 : 1; + + UInt16 reg4 : 1; + UInt16 reg5 : 1; + UInt16 reg6 : 1; + UInt16 reg7 : 1; + + UInt16 reg8 : 1; + UInt16 reg9 : 1; + UInt16 reg10 : 1; + UInt16 reg11 : 1; + + UInt16 reg12 : 1; + UInt16 reg13 : 1; + UInt16 reg14 : 1; + UInt16 reg15 : 1; + }bit; + } use_reg_in_pbus; + +} T_adc_setup_pbus; + +#define T_ADC_SETUP_PBUS_DEFAULTS {T_ADC_COUNT_ADR_PBUS,T_ADC_SETUP_USE_ADR_PBUS} +////////////////////////////////////////////////////////////// + + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +typedef struct{ + T_adc_read_pbus pbus; + T_adc_read_sbus sbus; + Int16 type_cds_xilinx; +} T_adc_read; + +typedef struct{ + T_adc_write_sbus sbus; +} T_adc_write; + +////////////////////////////////////////////////////////////// + +typedef struct TS_adc{ + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_adc_setup_pbus setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_adc_write write; + T_adc_read read; + T_adc_adr_pbus adr_pbus; + + UInt16 store_protect_error; + + UInt16 timer_wait_load; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_adc; + +typedef T_adc *T_adc_handle; + +/*----------------------------------------------------------------------------- +Default initalizer for object. +-----------------------------------------------------------------------------*/ +#define T_adc_DEFAULTS { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_ADC_SETUP_PBUS_DEFAULTS, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + T_ADC_WRITE_SBUS_DEFAULTS,\ + {T_ADC_READ_PBUS_DEFAULTS,T_ADC_READ_SBUS_DEFAULTS,TYPE_CDS_XILINX_DEFAULTS},\ + T_ADC_ADR_PBUS_DEFAULTS,\ + 0,\ + 0, \ + (void (*)(Uint32))adc_init, \ + (int (*)(Uint32))adc_read_all, \ + (int (*)(Uint32))adc_write_all, \ + (int (*)(Uint32))adc_read_sbus, \ + (int (*)(Uint32))adc_write_sbus, \ + (int (*)(Uint32))adc_read_pbus_without_cycle, \ + (int (*)(Uint32))adc_write_pbus, \ + (void (*)(Uint32))adc_reset_error, \ + (void (*)(Uint32))adc_store_disable_error, \ + (void (*)(Uint32))adc_restore_enable_error \ + } + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +void adc_init(T_adc_handle); + +int adc_read_all(T_adc_handle); +int adc_write_all(T_adc_handle); + +int adc_read_sbus(T_adc_handle); +int adc_write_sbus(T_adc_handle); + +int adc_read_pbus(T_adc_handle); +int adc_write_pbus(T_adc_handle); +int adc_read_pbus_without_cycle(T_adc_handle); + +void adc_reset_error(T_adc_handle); +void adc_store_disable_error(T_adc_handle); +void adc_restore_enable_error(T_adc_handle); + +//------------------------------------------------------------------------------ +// Return Type +//------------------------------------------------------------------------------ + +#endif diff --git a/Inu/Src2/N12_Xilinx/xp_cds_in.c b/Inu/Src2/N12_Xilinx/xp_cds_in.c new file mode 100644 index 0000000..96a2c35 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_in.c @@ -0,0 +1,440 @@ +#include "MemoryFunctions.h" +#include "xp_cds_in.h" + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_tools.h" +#include "xerror.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_in_init(T_cds_in *v) +{ + int old_started = 0; + unsigned int i; + + if (v->useit == 0) + { + clear_adr_sync_table(v->plane_address); + return ; + } + set_adr_sync_table(v->plane_address); + + if (x_parallel_bus_project.flags.bit.init==0) + x_parallel_bus_project.init(&x_parallel_bus_project); + + + old_started = x_parallel_bus_project.flags.bit.started; + + if (x_parallel_bus_project.flags.bit.started) + x_parallel_bus_project.stop(&x_parallel_bus_project); + + + x_parallel_bus_project.slave_addr = v->plane_address; + +// for (i=0;isetup_pbus.count_elements_pbus;i++) + for (i=0;i<16;i++) + { + if (v->setup_pbus.use_reg_in_pbus.all & (1<adr_pbus.adr_table[i] = x_parallel_bus_project.setup.size_table; + x_parallel_bus_project.add_table(&x_parallel_bus_project); + x_parallel_bus_project.reg_addr++; + x_parallel_bus_project.setup.size_table++; + } + else + { + // места в таблице нет!!! + xerror(xparall_bus_er_ID(1),(void *)0); + v->setup_pbus.use_reg_in_pbus.all &= (~(1<useit == 0) + return 0; + + err = cds_in_read_sbus(v); + err |= cds_in_read_pbus(v); + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int cds_in_write_all(T_cds_in *v) +{ + int err = 0; + + if (v->useit == 0) + return 0; + + err = cds_in_write_sbus(v); + err |= cds_in_write_pbus(v); + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_in_write_sbus(T_cds_in *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 enabled channels + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.enabled_channels.all;//use_invers_sensor_speed.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 first sensor connection + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.first_sensor.all;//sensor_combo; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 second sensor connection + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.second_sensor.all;//sensor_combo; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { +//3 zero sensor connection + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.zero_sensors.all;//sensor_combo; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + } + + +//6 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_in_write_pbus(T_cds_in *v) +{ + if (v->useit == 0) + return 0; + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_in_read_sbus(T_cds_in *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 enabled_channels + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.enabled_channels.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 first_sensor + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.first_sensor.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//2 second_sensor + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.second_sensor.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->type_cds_xilinx = v->read.type_cds_xilinx; + + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + + +//3 zero sensors + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.zero_sensors.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + } +//6 protect_error + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 id_plate + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.id_plate.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//////////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_in_read_pbus(T_cds_in *v) +{ + unsigned long adr_pbus; + unsigned int t; + + if (v->useit == 0) + return 0; + + if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + adr_pbus = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; + + if ((v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) && (v->type_plate == cds_in_type_in_1)) + { + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus, t); + v->read.pbus.data_in.all = (t & 0xff00) | ((~t) & 0x00ff); + } + else + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.data_in.all); + + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.ready_in.all); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.direction_in.all); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.SpeedS1_cnt); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.SpeedS1_cnt90); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.SpeedS2_cnt); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg6,adr_pbus,v->read.pbus.SpeedS2_cnt90); + if ((v->type_cds_xilinx == TYPE_CDS_XILINX_SP6)) + { + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg7,adr_pbus,v->read.pbus.Time_since_zero_point_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg8,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg9,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S1); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg10,adr_pbus,v->read.pbus.Time_since_zero_point_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg11,adr_pbus,v->read.pbus.Impulses_since_zero_point_Rising_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg12,adr_pbus,v->read.pbus.Impulses_since_zero_point_Falling_S2); + read_pbus_value(v->setup_pbus.use_reg_in_pbus.bit.reg13,adr_pbus,v->read.pbus.channel_alive.all); + } + + } + else + { + v->read.pbus.data_in.all = 0; + v->read.pbus.ready_in.all = 0; + v->read.pbus.direction_in.all = 0; + v->read.pbus.SpeedS1_cnt = 0; + v->read.pbus.SpeedS1_cnt90 = 0; + v->read.pbus.SpeedS2_cnt = 0; + v->read.pbus.SpeedS2_cnt90 = 0; + v->read.pbus.Time_since_zero_point_S1 = 0; + v->read.pbus.Impulses_since_zero_point_Rising_S1 = 0; + v->read.pbus.Impulses_since_zero_point_Falling_S1 = 0; + v->read.pbus.Time_since_zero_point_S2 = 0; + v->read.pbus.Impulses_since_zero_point_Rising_S2 = 0; + v->read.pbus.Impulses_since_zero_point_Falling_S2 = 0; + v->read.pbus.channel_alive.all = 0; + } + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_in_reset_error(T_cds_in *v) +{ + if (v->useit == 0) + return ; + + if (v->status == component_Error || v->status == component_ErrorSBus) + v->status = component_Started; + clear_cur_stat_sbus(&v->status_serial_bus); + clear_cur_stat_pbus(&v->status_parallel_bus); + + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//7 cmd_reset_error + + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_in_store_disable_error(T_cds_in *v) +{ + if (v->useit == 0) + return ; + + v->store_protect_error = v->write.sbus.protect_error.all; + v->write.sbus.protect_error.all = 0; // disable all error. + + cds_in_write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void cds_in_restore_enable_error(T_cds_in *v) +{ + if (v->useit == 0) + return ; + + v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. + cds_in_write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_in.h b/Inu/Src2/N12_Xilinx/xp_cds_in.h new file mode 100644 index 0000000..dc73d10 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_in.h @@ -0,0 +1,517 @@ +#ifndef XP_CDS_IN_H +#define XP_CDS_IN_H + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + +// Тип платы IN1 или IN2 +typedef enum { + cds_in_type_in_1 = 0x0, // тип платы IN1 с внешним питание + cds_in_type_in_2 = 0x1, // тип платы IN2 с внутренним питанием + cds_in_type_not_inited = -1 // не определен +} T_cds_in_type_plate; + +#define C_cds_in_dout_range 4 +// xSENS - number sensors +// FIRST_x_x_SECOND_x_x - number sens pairs +// 0 pair = in0+in1 +// 1 pair = in2+in3 +// 2 pair = in4+in5 +// 3 pair = in6+in7 + +#define T_CDS_IN_COUNT_ADR_PBUS 14 // count max elements in parallel bus + +#define T_CDS_IN_COUNT_ADR_PBUS_SP2 8 // тут 8 штук, т.к. длЯ SP2 нет измерителЯ длЯ метки НУЛЯ. +#define T_CDS_IN_COUNT_ADR_PBUS_SP6 T_CDS_IN_COUNT_ADR_PBUS + + +#define T_CDS_IN_SETUP_USE_ADR_PBUS 0xffff // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные, 0x0000 - никакие + +#define SENSOR_COMBO_2SENS_FIRST_0_1_SECOND_2_3 1 +#define SENSOR_COMBO_2SENS_FIRST_0_3_SECOND_1_2 2 +#define SENSOR_COMBO_2SENS_FIRST_0_2_SECOND_1_3 3 +#define SENSOR_COMBO_1SENS_FIRST_0_1 4 +#define SENSOR_COMBO_1SENS_FIRST_1_2 5 +#define SENSOR_COMBO_1SENS_FIRST_2_3 6 +#define SENSOR_COMBO_1SENS_FIRST_0_2 7 +#define SENSOR_COMBO_1SENS_FIRST_0_3 8 +#define SENSOR_COMBO_1SENS_FIRST_1_3 9 + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + +//0 + union + { + UInt16 all; + struct{ + UInt16 discret : 1; + UInt16 reserv : 7; + UInt16 sens_2_inv_ch_90deg : 1; + UInt16 sens_2_direct_ch_90deg : 1; + UInt16 sens_2_inv_ch : 1; + UInt16 sens_2_direct_ch : 1; + UInt16 sens_1_inv_ch_90deg : 1; + UInt16 sens_1_direct_ch_90deg : 1; + UInt16 sens_1_inv_ch : 1; + UInt16 sens_1_direct_ch : 1; + }bit; + }enabled_channels; + +//1 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }first_sensor; + +//2 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }second_sensor; + +//3 // for SP6 only + union + { + UInt16 all; + struct{ + UInt16 enable_sensor2 : 1; // 0 - disable, 1 - enable + UInt16 enable_sensor1 : 1; // 0 - disable, 1 - enable + UInt16 reserv : 6; + UInt16 for_sensor2 : 4; + UInt16 for_sensor1 : 4; + }bit; + }zero_sensors; + + //UInt16 sensor_combo; +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; + +//7 + UInt16 cmd_reset_error; + +} T_cds_in_write_sbus; + +#define T_CDS_IN_WRITE_SBUS_DEFAULTS {0,0,0,0,0xc000,0} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//read reg parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 PB + union + { + UInt16 all; + struct{ + UInt16 in0 : 1; + UInt16 in1 : 1; + UInt16 in2 : 1; + UInt16 in3 : 1; + UInt16 in4 : 1; + UInt16 in5 : 1; + UInt16 in6 : 1; + UInt16 in7 : 1; + UInt16 in8 : 1; + UInt16 in9 : 1; + UInt16 in10 : 1; + UInt16 in11 : 1; + UInt16 in12 : 1; + UInt16 in13 : 1; + UInt16 in14 : 1; + UInt16 in15 : 1; + }bit; + } data_in; +//1 PB + union + { + UInt16 all; + struct{ + UInt16 in0 : 1; + UInt16 in1 : 1; + UInt16 in2 : 1; + UInt16 in3 : 1; + UInt16 in4 : 1; + UInt16 in5 : 1; + UInt16 in6 : 1; + UInt16 in7 : 1; + UInt16 in8 : 1; + UInt16 in9 : 1; + UInt16 in10 : 1; + UInt16 in11 : 1; + UInt16 in12 : 1; + UInt16 in13 : 1; + UInt16 in14 : 1; + UInt16 in15 : 1; + }bit; + } ready_in; +//2 PB + union + { + UInt16 all; + struct{ + UInt16 dir_sens_1 : 2; // 00 - stop, 10-"+" 01-"-" 11-error + UInt16 dir_sens_2 : 2; // 00 - stop, 10-"+" 01-"-" 11-error + UInt16 reserv : 4; + UInt16 mode_sensor2_90 : 1; //режим дискретизации, при котором была расчитана длительность испульса 1 - 20ns 0 - 2us. + UInt16 mode_sensor2_direct : 1; //режим дискретизации, при котором была расчитана длительность испульса 1 - 20ns 0 - 2us. + UInt16 mode_sensor1_90 : 1; //режим дискретизации, при котором была расчитана длительность испульса 1 - 20ns 0 - 2us. + UInt16 mode_sensor1_direct : 1; //режим дискретизации, при котором была расчитана длительность испульса 1 - 20ns 0 - 2us. + UInt16 value_vaild_sensor2_90 : 1;//1- не было смены дискретизации в процессе расчета 0 - смена была, значение использовать нельзЯ + UInt16 value_vaild_sensor2_direct: 1; + UInt16 value_vaild_sensor1_90 : 1; + UInt16 value_vaild_sensor1_direct: 1; + }bit; + } direction_in; + + +//3 PB + UInt16 SpeedS1_cnt; +//4 PB + UInt16 SpeedS1_cnt90; +//5 PB + UInt16 SpeedS2_cnt; +//6 PB + UInt16 SpeedS2_cnt90; +//7 PB + UInt16 Time_since_zero_point_S1; +//8 PB + UInt16 Impulses_since_zero_point_Rising_S1; +//9 PB + UInt16 Impulses_since_zero_point_Falling_S1; +//10 PB + UInt16 Time_since_zero_point_S2; +//11 PB + UInt16 Impulses_since_zero_point_Rising_S2; +//12 PB + UInt16 Impulses_since_zero_point_Falling_S2; +//13 PB + union + { + UInt16 all; + struct{ + UInt16 reserv : 8; + UInt16 sens_2_inv_ch_90deg : 1; + UInt16 sens_2_direct_ch_90deg : 1; + UInt16 sens_2_inv_ch : 1; + UInt16 sens_2_direct_ch : 1; + UInt16 sens_1_inv_ch_90deg : 1; + UInt16 sens_1_direct_ch_90deg : 1; + UInt16 sens_1_inv_ch : 1; + UInt16 sens_1_direct_ch : 1; + }bit; + } channel_alive; + +} T_cds_in_read_pbus; + +#define T_CDS_IN_READ_PBUS_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0} +///////////////////////////////////////////////////////////// +// Table for adr parallel bus +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 adr_table[T_CDS_IN_COUNT_ADR_PBUS]; +} T_cds_in_adr_pbus; + +#define T_CDS_IN_ADR_PBUS_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct{ + UInt16 discret : 1; + UInt16 reserv : 7; + UInt16 sens_2_inv_ch_90deg : 1; + UInt16 sens_2_direct_ch_90deg : 1; + UInt16 sens_2_inv_ch : 1; + UInt16 sens_2_direct_ch : 1; + UInt16 sens_1_inv_ch_90deg : 1; + UInt16 sens_1_direct_ch_90deg : 1; + UInt16 sens_1_inv_ch : 1; + UInt16 sens_1_direct_ch : 1; + }bit; + }enabled_channels; + +//1 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }first_sensor; + +//2 + union + { + UInt16 all; + struct{ + UInt16 inv_ch_90deg : 4; + UInt16 direct_ch_90deg : 4; + UInt16 inv_ch : 4; + UInt16 direct_ch : 4; + }bit; + }second_sensor; + +//3 // for SP6 only + union + { + UInt16 all; + struct{ + UInt16 enable_sensor2 : 1; // 0 - disable, 1 - enable + UInt16 enable_sensor1 : 1; // 0 - disable, 1 - enable + UInt16 reserv : 6; + UInt16 for_sensor1 : 4; + UInt16 for_sensor2 : 4; + }bit; + }zero_sensors; + +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; + +//14 + union + { + UInt16 all; + struct + { + UInt16 revision :5; + UInt16 version :6; + T_plate_type plate_type :5; + } bit; + } id_plate; + + +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_in_read_sbus; + +#define T_CDS_IN_READ_SBUS_DEFAULTS {0,0,0,0,0} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_in_write_sbus sbus; +} T_cds_in_write; + +typedef struct{ + T_cds_in_read_sbus sbus; + T_cds_in_read_pbus pbus; + Int16 type_cds_xilinx; +} T_cds_in_read; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 reg0 : 1; + UInt16 reg1 : 1; + UInt16 reg2 : 1; + UInt16 reg3 : 1; + UInt16 reg4 : 1; + UInt16 reg5 : 1; + UInt16 reg6 : 1; + UInt16 reg7 : 1; + UInt16 reg8 : 1; + UInt16 reg9 : 1; + UInt16 reg10 : 1; + UInt16 reg11 : 1; + UInt16 reg12 : 1; + UInt16 reg13 : 1; + UInt16 reg14 : 1; + UInt16 reg15 : 1; + }bit; + } use_reg_in_pbus; + +} T_cds_in_setup_pbus; + +#define T_CDS_IN_SETUP_PBUS_DEFAULTS {T_CDS_IN_COUNT_ADR_PBUS,T_CDS_IN_SETUP_USE_ADR_PBUS} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + +typedef struct TS_cds_in{ + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_in_type_plate type_plate; + + T_cds_in_setup_pbus setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_in_write write; + T_cds_in_read read; + T_cds_in_adr_pbus adr_pbus; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_in; + + +typedef T_cds_in *T_cds_in_handle; + +/*----------------------------------------------------------------------------- +Default initalizer for object. +-----------------------------------------------------------------------------*/ +#define T_cds_in_DEFAULTS { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + cds_in_type_not_inited,\ + T_CDS_IN_SETUP_PBUS_DEFAULTS,\ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_IN_WRITE_SBUS_DEFAULTS},\ + {T_CDS_IN_READ_SBUS_DEFAULTS,T_CDS_IN_READ_PBUS_DEFAULTS,TYPE_CDS_XILINX_DEFAULTS},\ + T_CDS_IN_ADR_PBUS_DEFAULTS, \ + 0, \ + (void (*)(Uint32))cds_in_init, \ + (int (*)(Uint32))cds_in_read_all, \ + (int (*)(Uint32))cds_in_write_all, \ + (int (*)(Uint32))cds_in_read_sbus, \ + (int (*)(Uint32))cds_in_write_sbus, \ + (int (*)(Uint32))cds_in_read_pbus, \ + (int (*)(Uint32))cds_in_write_pbus, \ + (void (*)(Uint32))cds_in_reset_error, \ + (void (*)(Uint32))cds_in_store_disable_error, \ + (void (*)(Uint32))cds_in_restore_enable_error \ + } + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +void cds_in_init(T_cds_in_handle); + +int cds_in_read_all(T_cds_in_handle); +int cds_in_write_all(T_cds_in_handle); + +int cds_in_read_sbus(T_cds_in_handle); +int cds_in_write_sbus(T_cds_in_handle); + +int cds_in_read_pbus(T_cds_in_handle); +int cds_in_write_pbus(T_cds_in_handle); + +void cds_in_reset_error(T_cds_in_handle); +void cds_in_store_disable_error(T_cds_in_handle); +void cds_in_restore_enable_error(T_cds_in_handle); + + + +#endif diff --git a/Inu/Src2/N12_Xilinx/xp_cds_out.c b/Inu/Src2/N12_Xilinx/xp_cds_out.c new file mode 100644 index 0000000..56200f4 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_out.c @@ -0,0 +1,310 @@ +#include "x_serial_bus.h" +#include "xp_cds_out.h" + +#include "x_serial_bus.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_out_init(T_cds_out *v) +{ + if (v->useit == 0) + { + clear_adr_sync_table(v->plane_address); + return ; + } + set_adr_sync_table(v->plane_address); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int cds_out_read_all(T_cds_out *v) +{ + int err = 0; + + if (v->useit == 0) + return 0; + + err = cds_out_read_sbus(v); + err |= cds_out_read_pbus(v); + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int cds_out_write_all(T_cds_out *v) +{ + int err = 0; + + if (v->useit == 0) + return 0; + + err = cds_out_write_sbus(v); + err |= cds_out_write_pbus(v); + + return err; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_out_write_sbus(T_cds_out *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + static unsigned int e; + static unsigned int c_ok=0; + + if (v->useit == 0) + return 0; + + e = 0; + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 data_out + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.data_out.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + { + v->status_serial_bus.count_write_error++; + e |= 1; + } + +//1 enable_protect_out + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.enable_protect_out.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + { + v->status_serial_bus.count_write_error++; + e |= 2; + } + +//6 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + { + v->status_serial_bus.count_write_error++; + e |= 4; + } + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + c_ok++; + err = 0; // no errors + } + else + { + err = 1; // !errors! + c_ok = 0; + } + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_out_write_pbus(T_cds_out *v) +{ + + if (v->useit == 0) + return 0; + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_out_read_sbus(T_cds_out *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 data_out + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.data_out.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 enable_protect_out + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.enable_protect_out.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//6 protect_error + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->type_cds_xilinx = v->read.type_cds_xilinx; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_out_read_pbus(T_cds_out *v) +{ + if (v->useit == 0) + return 0; + + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_out_reset_error(T_cds_out *v) +{ + + if (v->useit == 0) + return ; + + if (v->status == component_Error || v->status == component_ErrorSBus) + v->status = component_Started; + clear_cur_stat_sbus(&v->status_serial_bus); + clear_cur_stat_pbus(&v->status_parallel_bus); + + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//7 cmd_reset_error + + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_out_store_disable_error(T_cds_out *v) +{ + if (v->useit == 0) + return ; + + v->store_protect_error = v->write.sbus.protect_error.all; + v->write.sbus.protect_error.all = 0; // disable all error. + + cds_out_write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void cds_out_restore_enable_error(T_cds_out *v) +{ + + if (v->useit == 0) + return ; + + v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. + cds_out_write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_out.h b/Inu/Src2/N12_Xilinx/xp_cds_out.h new file mode 100644 index 0000000..0494910 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_out.h @@ -0,0 +1,286 @@ +#ifndef XP_CDS_OUT_H +#define XP_CDS_OUT_H + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct{ + UInt16 dout0 : 1; + UInt16 dout1 : 1; + UInt16 dout2 : 1; + UInt16 dout3 : 1; + UInt16 dout4 : 1; + UInt16 dout5 : 1; + UInt16 dout6 : 1; + UInt16 dout7 : 1; + UInt16 dout8 : 1; + UInt16 dout9 : 1; + UInt16 dout10 : 1; + UInt16 dout11 : 1; + UInt16 dout12 : 1; + UInt16 dout13 : 1; + UInt16 dout14 : 1; + UInt16 dout15 : 1; + }bit; + } data_out; +//1 + union + { + UInt16 all; + struct{ + UInt16 dout0 : 1; + UInt16 dout1 : 1; + UInt16 dout2 : 1; + UInt16 dout3 : 1; + UInt16 dout4 : 1; + UInt16 dout5 : 1; + UInt16 dout6 : 1; + UInt16 dout7 : 1; + UInt16 dout8 : 1; + UInt16 dout9 : 1; + UInt16 dout10 : 1; + UInt16 dout11 : 1; + UInt16 dout12 : 1; + UInt16 dout13 : 1; + UInt16 dout14 : 1; + UInt16 dout15 : 1; + }bit; + } enable_protect_out; +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; + +} T_cds_out_write_sbus; + +#define T_CDS_OUT_WRITE_SBUS_DEFAULTS {0xffff,0xffff,0xf000,0} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct{ + UInt16 dout0 : 1; + UInt16 dout1 : 1; + UInt16 dout2 : 1; + UInt16 dout3 : 1; + UInt16 dout4 : 1; + UInt16 dout5 : 1; + UInt16 dout6 : 1; + UInt16 dout7 : 1; + UInt16 dout8 : 1; + UInt16 dout9 : 1; + UInt16 dout10 : 1; + UInt16 dout11 : 1; + UInt16 dout12 : 1; + UInt16 dout13 : 1; + UInt16 dout14 : 1; + UInt16 dout15 : 1; + }bit; + } data_out; +//1 + union + { + UInt16 all; + struct{ + UInt16 dout0 : 1; + UInt16 dout1 : 1; + UInt16 dout2 : 1; + UInt16 dout3 : 1; + UInt16 dout4 : 1; + UInt16 dout5 : 1; + UInt16 dout6 : 1; + UInt16 dout7 : 1; + UInt16 dout8 : 1; + UInt16 dout9 : 1; + UInt16 dout10 : 1; + UInt16 dout11 : 1; + UInt16 dout12 : 1; + UInt16 dout13 : 1; + UInt16 dout14 : 1; + UInt16 dout15 : 1; + }bit; + } enable_protect_out; + +//6 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; + +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_out_read_sbus; + +#define T_CDS_OUT_READ_SBUS_DEFAULTS {0,0,0,0,0} +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_out_write_sbus sbus; +} T_cds_out_write; + +typedef struct{ + T_cds_out_read_sbus sbus; + Int16 type_cds_xilinx; +} T_cds_out_read; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// main struct +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct TS_cds_out{ + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_out_write write; + T_cds_out_read read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_out; + +typedef T_cds_out *T_cds_out_handle; + +/*----------------------------------------------------------------------------- +Default initalizer for object. +-----------------------------------------------------------------------------*/ +#define T_cds_out_DEFAULTS { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_OUT_WRITE_SBUS_DEFAULTS},\ + {T_CDS_OUT_READ_SBUS_DEFAULTS,TYPE_CDS_XILINX_DEFAULTS},\ + 0,\ + (void (*)(Uint32))cds_out_init, \ + (int (*)(Uint32))cds_out_read_all, \ + (int (*)(Uint32))cds_out_write_all, \ + (int (*)(Uint32))cds_out_read_sbus, \ + (int (*)(Uint32))cds_out_write_sbus, \ + (int (*)(Uint32))cds_out_read_pbus, \ + (int (*)(Uint32))cds_out_write_pbus, \ + (void (*)(Uint32))cds_out_reset_error, \ + (void (*)(Uint32))cds_out_store_disable_error, \ + (void (*)(Uint32))cds_out_restore_enable_error \ + } + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +void cds_out_init(T_cds_out_handle); + +int cds_out_read_all(T_cds_out_handle); +int cds_out_write_all(T_cds_out_handle); + +int cds_out_read_sbus(T_cds_out_handle); +int cds_out_write_sbus(T_cds_out_handle); + +int cds_out_read_pbus(T_cds_out_handle); +int cds_out_write_pbus(T_cds_out_handle); + +void cds_out_reset_error(T_cds_out_handle); +void cds_out_store_disable_error(T_cds_out_handle); +void cds_out_restore_enable_error(T_cds_out_handle); + +#endif diff --git a/Inu/Src2/N12_Xilinx/xp_cds_rs.c b/Inu/Src2/N12_Xilinx/xp_cds_rs.c new file mode 100644 index 0000000..b19acde --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_rs.c @@ -0,0 +1,399 @@ +#include "x_parallel_bus.h" +#include "xp_cds_rs.h" + +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_tools.h" +#include "xp_tools.h" +#include "xerror.h" + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_rs_init(T_cds_rs *v) +{ + int old_started = 0; + unsigned int i; + + if (v->useit == 0) + { + clear_adr_sync_table(v->plane_address); + return ; + } + set_adr_sync_table(v->plane_address); + + if (x_parallel_bus_project.flags.bit.init==0) + x_parallel_bus_project.init(&x_parallel_bus_project); + + + old_started = x_parallel_bus_project.flags.bit.started; + + if (x_parallel_bus_project.flags.bit.started) + x_parallel_bus_project.stop(&x_parallel_bus_project); + + + x_parallel_bus_project.slave_addr = v->plane_address; + + // for (i=0;isetup_pbus.count_elements_pbus;i++) + for (i=0;i<16;i++) + { + if (v->setup_pbus.use_reg_in_pbus.all & (1<adr_pbus.adr_table[i] = x_parallel_bus_project.setup.size_table; + x_parallel_bus_project.add_table(&x_parallel_bus_project); + x_parallel_bus_project.reg_addr++; + x_parallel_bus_project.setup.size_table++; + } + else + { + // места в таблице нет!!! + xerror(xparall_bus_er_ID(1),(void *)0); + v->setup_pbus.use_reg_in_pbus.all &= (~(1<useit == 0) + return 0; + + cds_rs_read_sbus(v); + cds_rs_read_pbus(v); + return 0; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int cds_rs_write_all(T_cds_rs *v) +{ + if (v->useit == 0) + return 0; + + cds_rs_write_sbus(v); + cds_rs_write_pbus(v); + return 0; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_rs_write_sbus(T_cds_rs *v) +{ + unsigned int old_err; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//8 config rs speed, master/slave and period of survey + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.config.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + return 0; // no errors + } + + return 1; // !error! + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_rs_write_pbus(T_cds_rs *v) +{ + if (v->useit == 0) + return 0; + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_rs_read_sbus(T_cds_rs *v) +{ + unsigned int old_err; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 + if(v->write.sbus.config.bit.channel1_enable) + { + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[0].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.sbus.sensor[0].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } + else + v->status_serial_bus.count_read_error++; + } + +//1 + if(v->write.sbus.config.bit.channel2_enable) + { + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[1].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.sbus.sensor[1].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } + else + v->status_serial_bus.count_read_error++; + } +//2 + if(v->write.sbus.config.bit.channel3_enable) + { + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[2].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.sbus.sensor[2].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } + else + v->status_serial_bus.count_read_error++; + } +//3 + if(v->write.sbus.config.bit.channel4_enable) + { + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[3].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.sbus.sensor[3].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } + else + v->status_serial_bus.count_read_error++; + } +//4 + if(v->write.sbus.config.bit.channel1_enable) + { + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[0].angle = x_parallel_bus_project.data_table_read << 2; + } + else + v->status_serial_bus.count_read_error++; + } +//5 + if(v->write.sbus.config.bit.channel2_enable) + { + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[1].angle = x_parallel_bus_project.data_table_read << 2; + } + else + v->status_serial_bus.count_read_error++; + } +//6 + if(v->write.sbus.config.bit.channel3_enable) + { + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[2].angle = x_parallel_bus_project.data_table_read << 2; + } + else + v->status_serial_bus.count_read_error++; + } +//7 + if(v->write.sbus.config.bit.channel4_enable) + { + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.sensor[3].angle = x_parallel_bus_project.data_table_read << 2; + } + else + v->status_serial_bus.count_read_error++; + } + +//8 + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.sbus.config.all = x_parallel_bus_project.data_table_read; + } + else + v->status_serial_bus.count_read_error++; + + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; +// v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +//////////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + return 0; // no errors + } + + return 1; // !errors! +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_rs_read_pbus(T_cds_rs *v) +{ + if (v->useit == 0) + return 0; + + if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) + { +//0 + if(v->write.sbus.config.bit.channel1_enable && v->setup_pbus.use_reg_in_pbus.bit.reg0) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[0]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[0].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.pbus.sensor[0].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } +//1 + if(v->write.sbus.config.bit.channel2_enable && v->setup_pbus.use_reg_in_pbus.bit.reg1) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[1]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[1].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.pbus.sensor[1].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } +//2 + if(v->write.sbus.config.bit.channel3_enable && v->setup_pbus.use_reg_in_pbus.bit.reg2) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[2]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[2].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.pbus.sensor[2].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } +//3 + if(v->write.sbus.config.bit.channel4_enable && v->setup_pbus.use_reg_in_pbus.bit.reg3) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[3]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[3].direction = (x_parallel_bus_project.data_table_read >> 15) & 1; + v->read.pbus.sensor[3].turned_angle = (x_parallel_bus_project.data_table_read & 0x7FFF) << 3; + } +//4 + if(v->write.sbus.config.bit.channel1_enable && v->setup_pbus.use_reg_in_pbus.bit.reg4) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[4]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[0].angle = x_parallel_bus_project.data_table_read << 2; + } +//5 + if(v->write.sbus.config.bit.channel2_enable && v->setup_pbus.use_reg_in_pbus.bit.reg5) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[5]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[1].angle = x_parallel_bus_project.data_table_read << 2; + } +//6 + if(v->write.sbus.config.bit.channel3_enable && v->setup_pbus.use_reg_in_pbus.bit.reg6) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[6]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[2].angle = x_parallel_bus_project.data_table_read << 2; + } +//7 + if(v->write.sbus.config.bit.channel4_enable && v->setup_pbus.use_reg_in_pbus.bit.reg7) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[7]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.sensor[3].angle = x_parallel_bus_project.data_table_read << 2; + } + } + else + { + v->read.pbus.sensor[0].direction = 0; + v->read.pbus.sensor[0].turned_angle = 0; + v->read.pbus.sensor[0].angle = 0; + + v->read.pbus.sensor[1].direction = 0; + v->read.pbus.sensor[1].turned_angle = 0; + v->read.pbus.sensor[1].angle = 0; + + v->read.pbus.sensor[2].direction = 0; + v->read.pbus.sensor[2].turned_angle = 0; + v->read.pbus.sensor[2].angle = 0; + + v->read.pbus.sensor[3].direction = 0; + v->read.pbus.sensor[3].turned_angle = 0; + v->read.pbus.sensor[3].angle = 0; + } + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_rs.h b/Inu/Src2/N12_Xilinx/xp_cds_rs.h new file mode 100644 index 0000000..c9b04c2 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_rs.h @@ -0,0 +1,182 @@ +#ifndef XP_CDS_RS_H +#define XP_CDS_RS_H + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + +#define T_CDS_RS_COUNT_ADR_PBUS 8 // count max elements in parallel bus +#define T_CDS_RS_SETUP_USE_ADR_PBUS 0xffff // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +#define USED_RS_SENSORS 4 // Number of measuring channels + +typedef union { + unsigned int all; + struct { + unsigned int survey_time:8; //Период опроса по 10мкс (0==10, 1==20,...) + unsigned int channel4_enable:1; + unsigned int channel3_enable:1; + unsigned int channel2_enable:1; + unsigned int channel1_enable:1; + unsigned int transmition_speed:3; + unsigned int plane_is_master:1; + }bit; +} T_cds_rs_config; + +#define T_CDS_RS_CONFIG_DEFAULT {0xA131} + +typedef struct { + T_cds_rs_config config; +} T_cds_rs_write_sbus; + +#define T_CDS_RS_WRITE_SBUS_DEFAULT \ + {T_CDS_RS_CONFIG_DEFAULT} + +typedef struct { + int direction; + unsigned long turned_angle; + unsigned long angle; +} Sensor; + +#define SENSOR_DEFAULT {0, 0, 0} + +typedef struct { + Sensor sensor[USED_RS_SENSORS]; +} T_cds_rs_read_pbus; + +#define T_CDS_RS_READ_PBUS_DEFAULT { \ + {SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT}} + +typedef struct { + Sensor sensor[USED_RS_SENSORS]; + T_cds_rs_config config; +} T_cds_rs_read_sbus; + +#define T_CDS_RS_READ_SBUS_DEFAULT { \ + {SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT, SENSOR_DEFAULT}, \ + T_CDS_RS_CONFIG_DEFAULT} + +typedef struct { + T_cds_rs_write_sbus sbus; +} T_cds_rs_write; + +#define T_CDS_RS_WRITE_DEFAULT \ + {T_CDS_RS_WRITE_SBUS_DEFAULT} + +typedef struct { + T_cds_rs_read_pbus pbus; + T_cds_rs_read_sbus sbus; + Int16 type_cds_xilinx; +} T_cds_rs_read; + +#define T_CDS_RS_READ_DEFAULT \ + {T_CDS_RS_READ_PBUS_DEFAULT, T_CDS_RS_READ_SBUS_DEFAULT,TYPE_CDS_XILINX_DEFAULTS} + +///////////////////////////////////////////////////////////// +// Table for adr parallel bus +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 adr_table[T_CDS_RS_COUNT_ADR_PBUS]; +} T_cds_rs_adr_pbus; + +#define T_CDS_RS_ADR_PBUS_DEFAULTS {0,0,0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 reg0 : 1; + UInt16 reg1 : 1; + UInt16 reg2 : 1; + UInt16 reg3 : 1; + + UInt16 reg4 : 1; + UInt16 reg5 : 1; + UInt16 reg6 : 1; + UInt16 reg7 : 1; + + UInt16 res : 8; + }bit; + } use_reg_in_pbus; + +} T_cds_rs_setup_pbus; + +#define T_CDS_RS_SETUP_PBUS_DEFAULTS {T_CDS_RS_COUNT_ADR_PBUS,T_CDS_RS_SETUP_USE_ADR_PBUS} +////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// + + + +typedef struct { + UInt16 plane_address; + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_rs_setup_pbus setup_pbus; + + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_rs_write write; + T_cds_rs_read read; + T_cds_rs_adr_pbus adr_pbus; + + void(*init)(); + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + +} T_cds_rs; + +typedef T_cds_rs *T_cds_rs_handle; + +/*----------------------------------------------------------------------------- +Default initalizer for object. +-----------------------------------------------------------------------------*/ +#define T_cds_rs_DEFAULTS { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_RS_SETUP_PBUS_DEFAULTS,\ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + T_CDS_RS_WRITE_DEFAULT,\ + T_CDS_RS_READ_DEFAULT, \ + T_CDS_RS_ADR_PBUS_DEFAULTS, \ + (void (*)(Uint32))cds_rs_init, \ + (int (*)(Uint32))cds_rs_read_all, \ + (int (*)(Uint32))cds_rs_write_all, \ + (int (*)(Uint32))cds_rs_read_sbus, \ + (int (*)(Uint32))cds_rs_write_sbus, \ + (int (*)(Uint32))cds_rs_read_pbus, \ + (int (*)(Uint32))cds_rs_write_pbus, \ + } + +void cds_rs_init(T_cds_rs *v); +int cds_rs_read_all(T_cds_rs *v); +int cds_rs_write_all(T_cds_rs *v); +int cds_rs_write_sbus(T_cds_rs *v); +int cds_rs_write_pbus(T_cds_rs *v); +int cds_rs_read_sbus(T_cds_rs *v); +int cds_rs_read_pbus(T_cds_rs *v); + + +#endif //XP_CDS_RS_H diff --git a/Inu/Src2/N12_Xilinx/xp_cds_status_bus.c b/Inu/Src2/N12_Xilinx/xp_cds_status_bus.c new file mode 100644 index 0000000..3718d57 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_status_bus.c @@ -0,0 +1,217 @@ +#include "xp_cds_status_bus.h" +//#include "xp_tools.h" + + +void clear_cur_stat_sbus(T_cds_status_serial_bus *v) +{ + v->cur_read_error = 0; + v->cur_write_error = 0; +} + +void clear_cur_stat_pbus(T_cds_status_parallel_bus *v) +{ + v->cur_read_error = 0; + v->cur_write_error = 0; +} + +void clear_cur_stat_hwpbus(T_cds_status_hwp_bus *v) +{ + v->cur_read_error = 0; + v->cur_write_error = 0; +} + + +//////////////////////////////////////////// +//////////////////////////////////////////// + + +void clear_stat_sbus(T_cds_status_serial_bus *v) +{ + v->count_read_error = 0; + v->count_write_error = 0; + v->count_read_ok = 0; + v->count_write_ok = 0; + v->cur_read_error = 0; + v->cur_write_error = 0; + + v->status = 0; +} + +void clear_stat_pbus(T_cds_status_parallel_bus *v) +{ + v->count_read_error = 0; + v->count_write_error = 0; + v->count_read_ok = 0; + v->count_write_ok = 0; + v->cur_read_error = 0; + v->cur_write_error = 0; + + v->status = 0; +} + +void clear_stat_hwpbus(T_cds_status_hwp_bus *v) +{ + v->count_read_error = 0; + v->count_write_error = 0; + v->count_read_ok = 0; + v->count_write_ok = 0; + + v->cur_read_error = 0; + v->cur_write_error = 0; + + v->status = 0; +} + + +int check_cds_ready_sbus(int err, int wr_rd, T_cds_status_serial_bus *v) +{ + + if (wr_rd == ITS_WRITE_BUS) // write + { + if (err) + { + if (v->cur_write_error < v->max_write_error) + v->cur_write_error++; + } + else + { + if (v->cur_write_error > 0) + v->cur_write_error--; + } + } + + + if (wr_rd == ITS_READ_BUS) // read + { + + if (err) + { + if (v->cur_read_error < v->max_read_error) + v->cur_read_error++; + } + else + { + if (v->cur_read_error > 0) + v->cur_read_error--; + } + } + + + if ( (v->cur_write_error >= v->max_write_error) || ( v->cur_read_error >= v->max_read_error) ) + return 1; + + + return 0; +} + + + +int check_cds_ready_pbus(int err, int wr_rd, T_cds_status_parallel_bus *v) +{ + + if (wr_rd == ITS_WRITE_BUS) // write + { + if (err) + { + if (v->cur_write_error < v->max_write_error) + v->cur_write_error++; + } + else + { + if (v->cur_write_error > 0) + v->cur_write_error--; + } + } + + + if (wr_rd == ITS_READ_BUS) // read + { + + if (err) + { + if (v->cur_read_error < v->max_read_error) + v->cur_read_error++; + } + else + { + if (v->cur_read_error > 0) + v->cur_read_error--; + } + } + + + if ( (v->cur_write_error >= v->max_write_error) || ( v->cur_read_error >= v->max_read_error) ) + return 1; + + + return 0; +} + + + +int check_cds_ready_hwpbus(int err, int wr_rd, T_cds_status_hwp_bus *v) +{ + + if (wr_rd == ITS_WRITE_BUS) // write + { + if (err) + { + v->count_write_error++; + if (v->cur_write_error < v->max_write_error) + v->cur_write_error++; + } + else + { + if (v->cur_write_error > 0) + v->cur_write_error--; + v->count_write_ok++; + + } + } + + + if (wr_rd == ITS_READ_BUS) // read + { + + if (err) + { + v->count_read_error++; + if (v->cur_read_error < v->max_read_error) + v->cur_read_error++; + } + else + { + if (v->cur_read_error > 0) + v->cur_read_error--; + v->count_read_ok++; + } + } + + + if ( (v->cur_write_error >= v->max_write_error) || ( v->cur_read_error >= v->max_read_error) ) + return 1; + + + return 0; +} + + + + +void set_status_cds(int err_ready, T_component_status *ss) +{ + + if (err_ready == 0) // all ok + { + if ((*ss == component_NotReady) || (*ss == component_Started)) + *ss = component_Ready; + } + + if (err_ready == 1) // all !bad! + { + *ss = component_ErrorSBus;//component_Error; + } + +} + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_status_bus.h b/Inu/Src2/N12_Xilinx/xp_cds_status_bus.h new file mode 100644 index 0000000..092be0e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_status_bus.h @@ -0,0 +1,95 @@ +#ifndef XP_CDS_STATUS_BUS_H +#define XP_CDS_STATUS_BUS_H + +#include "x_basic_types.h" + +#define ITS_WRITE_BUS 0 +#define ITS_READ_BUS 1 + +#define TYPE_CDS_XILINX_NOT_INITED -1 +#define TYPE_CDS_XILINX_SP2 0 +#define TYPE_CDS_XILINX_SP6 1 + + +#define MAX_WRITE_ERROR_SBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready +#define MAX_READ_ERROR_SBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready + +#define MAX_WRITE_ERROR_PBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready +#define MAX_READ_ERROR_PBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready + +#define MAX_WRITE_ERROR_HWPBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready +#define MAX_READ_ERROR_HWPBUS_DEFAULT 1 // количество повторных операций до возникновениЯ ошибки - снЯтие Ready + +#define T_cds_status_serial_bus_DEFAULT {0,0,0,0,0,0,0,MAX_WRITE_ERROR_SBUS_DEFAULT,MAX_READ_ERROR_SBUS_DEFAULT} +#define T_cds_status_parallel_bus_DEFAULT {0,0,0,0,0,0,0,MAX_WRITE_ERROR_PBUS_DEFAULT,MAX_READ_ERROR_PBUS_DEFAULT} +#define T_cds_status_hwp_bus_DEFAULT {0,0,0,0,0,0,0,MAX_WRITE_ERROR_HWPBUS_DEFAULT,MAX_READ_ERROR_HWPBUS_DEFAULT} + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ + +typedef struct { + UInt16 status; + UInt16 count_read_ok; + UInt16 count_write_ok; + UInt16 count_read_error; + UInt16 count_write_error; + UInt16 cur_read_error; + UInt16 cur_write_error; + UInt16 max_write_error; + UInt16 max_read_error; +} T_cds_status_serial_bus; + + +typedef struct { + UInt16 status; + UInt16 count_read_ok; + UInt16 count_write_ok; + UInt16 count_read_error; + UInt16 count_write_error; + UInt16 cur_read_error; + UInt16 cur_write_error; + UInt16 max_write_error; + UInt16 max_read_error; +} T_cds_status_parallel_bus; + +typedef struct { + UInt16 status; + UInt16 count_read_ok; + UInt16 count_write_ok; + UInt16 count_read_error; + UInt16 count_write_error; + UInt16 cur_read_error; + UInt16 cur_write_error; + UInt16 max_write_error; + UInt16 max_read_error; +} T_cds_status_hwp_bus; + +typedef struct { + UInt16 type_xilinx; +} T_cds_type_xilinx; + + +#define TYPE_CDS_XILINX_DEFAULTS TYPE_CDS_XILINX_NOT_INITED +#define TYPE_IN_1_2_DEFAULTS TYPE_IN_1_2_NOT_INITED + +void clear_stat_sbus(T_cds_status_serial_bus *v); +void clear_stat_pbus(T_cds_status_parallel_bus *v); +void clear_stat_hwpbus(T_cds_status_hwp_bus *v); + +void clear_cur_stat_sbus(T_cds_status_serial_bus *v); +void clear_cur_stat_pbus(T_cds_status_parallel_bus *v); +void clear_cur_stat_hwpbus(T_cds_status_hwp_bus *v); + + +int check_cds_ready_sbus(int err, int wr_rd, T_cds_status_serial_bus *v); +int check_cds_ready_pbus(int err, int wr_rd, T_cds_status_parallel_bus *v); +int check_cds_ready_hwpbus(int err, int wr_rd, T_cds_status_hwp_bus *v); + +void set_status_cds(int err_ready, T_component_status *ss); + + + + +#endif + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk.c b/Inu/Src2/N12_Xilinx/xp_cds_tk.c new file mode 100644 index 0000000..6248104 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk.c @@ -0,0 +1,196 @@ +#include "x_parallel_bus.h" +#include "xp_cds_tk.h" + +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_tools.h" +#include "xerror.h" + +/* тут лежат универсальные функции длЯ работы плат tk не зависЯщие от типа проекта */ + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_tk_init(T_cds_tk *v) +{ +//#if (Cds_Tk_Xilinx_SP6 == 1) && (C_PROJECT_TYPE == PROJECT_22220) + int old_started = 0; + unsigned int i; +//#endif + if (v->useit == 0) + { + clear_adr_sync_table(v->plane_address); + return ; + } + set_adr_sync_table(v->plane_address); + +//#if (Cds_Tk_Xilinx_SP6 == 1) && (C_PROJECT_TYPE == PROJECT_22220) +#if (C_PROJECT_TYPE == PROJECT_22220) || (C_PROJECT_TYPE == PROJECT_23550) + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + if (x_parallel_bus_project.flags.bit.init==0) + x_parallel_bus_project.init(&x_parallel_bus_project); + + + old_started = x_parallel_bus_project.flags.bit.started; + + if (x_parallel_bus_project.flags.bit.started) + x_parallel_bus_project.stop(&x_parallel_bus_project); + + + x_parallel_bus_project.slave_addr = v->plane_address; + + // for (i=0;isetup_pbus.count_elements_pbus;i++) + for (i=0;i<16;i++) + { + if (v->setup_pbus.use_reg_in_pbus.all & (1<adr_pbus.adr_table[i] = x_parallel_bus_project.setup.size_table; + x_parallel_bus_project.add_table(&x_parallel_bus_project); + x_parallel_bus_project.reg_addr++; + x_parallel_bus_project.setup.size_table++; + } + else + { + // места в таблице нет!!! + xerror(xparall_bus_er_ID(1),(void *)0); + v->setup_pbus.use_reg_in_pbus.all &= (~(1<useit == 0) + return 0; + + err = v->read_sbus(v); + err |= v->read_pbus(v); + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int cds_tk_write_all(T_cds_tk *v) +{ + int err = 0; + + if (v->useit == 0) + return 0; + + err = v->write_sbus(v); + err |= v->write_pbus(v); + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_pbus(T_cds_tk *v) +{ + if (v->useit == 0) + return 0; + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_pbus(T_cds_tk *v) +{ + if (v->useit == 0) + return 0; + + return 0; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +void cds_tk_reset_error(T_cds_tk *v) +{ + if (v->useit == 0) + return ; + + if (v->status == component_Error || v->status == component_ErrorSBus) + v->status = component_Started; + + clear_cur_stat_sbus(&v->status_serial_bus); + clear_cur_stat_pbus(&v->status_parallel_bus); + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//7 cmd_reset_error + + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void cds_tk_store_disable_error(T_cds_tk *v) +{ + if (v->useit == 0) + return ; + + v->store_protect_error = v->write.sbus.protect_error.all; + v->write.sbus.protect_error.all = 0; // disable all error. + + v->write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void cds_tk_restore_enable_error(T_cds_tk *v) +{ + if (v->useit == 0) + return ; + + v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. + v->write_sbus(v); + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk.h b/Inu/Src2/N12_Xilinx/xp_cds_tk.h new file mode 100644 index 0000000..6979039 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk.h @@ -0,0 +1,114 @@ +#ifndef XP_CDS_TK_H +#define XP_CDS_TK_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_cds_tk_10510.h" +#include "xp_cds_tk_21180.h" +#include "xp_cds_tk_21300.h" +#include "xp_cds_tk_22220.h" +#include "xp_cds_tk_23470.h" +#include "xp_cds_tk_23550.h" +#include "xp_cds_tk_balzam.h" +#include "xp_id_plate_info.h" +#include "xp_plane_adr.h" + + + + + +///////////////////////////////////////////////////////////////// +/*----------------------------------------------------------------------------- +Default initalizer for object. +-----------------------------------------------------------------------------*/ + +#if (C_PROJECT_TYPE == PROJECT_21180) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_21180 +#define T_cds_tk T_cds_tk_21180 +typedef T_cds_tk_21180 *T_cds_tk_handle; +#endif + +#if (C_PROJECT_TYPE == PROJECT_23470) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_23470 +#define T_cds_tk T_cds_tk_23470 +typedef T_cds_tk_23470 *T_cds_tk_handle; +#endif + +#if (C_PROJECT_TYPE == PROJECT_21300) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_21300 +#define T_cds_tk T_cds_tk_21300 +typedef T_cds_tk_21300 *T_cds_tk_handle; +#endif + +#if (C_PROJECT_TYPE == PROJECT_22220) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_22220 +#define T_cds_tk T_cds_tk_22220 +typedef T_cds_tk_22220 *T_cds_tk_handle; +#endif + +#if (C_PROJECT_TYPE == PROJECT_BALZAM) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_BALZAM +#define T_cds_tk T_cds_tk_balzam +typedef T_cds_tk_balzam *T_cds_tk_handle; +#endif + + +#if (C_PROJECT_TYPE == PROJECT_23550) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_23550 +#define T_cds_tk T_cds_tk_23550 +typedef T_cds_tk_23550 *T_cds_tk_handle; +#endif + +#if (C_PROJECT_TYPE == PROJECT_10510) +#define T_cds_tk_DEFAULTS T_cds_tk_DEFAULTS_10510 +#define T_cds_tk T_cds_tk_10510 +typedef T_cds_tk_10510 *T_cds_tk_handle; +#endif + + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +void cds_tk_init(T_cds_tk_handle); + +int cds_tk_read_all(T_cds_tk_handle); +int cds_tk_write_all(T_cds_tk_handle); +/// +int cds_tk_read_sbus_21300(T_cds_tk_handle_21300); +int cds_tk_write_sbus_21300(T_cds_tk_handle_21300); + +int cds_tk_read_sbus_22220(T_cds_tk_handle_22220); +int cds_tk_write_sbus_22220(T_cds_tk_handle_22220); +int cds_tk_read_pbus_22220(T_cds_tk_handle_22220); + +int cds_tk_read_sbus_balzam(T_cds_tk_handle_balzam); +int cds_tk_write_sbus_balzam(T_cds_tk_handle_balzam); + +int cds_tk_read_sbus_21180(T_cds_tk_handle_21180); +int cds_tk_write_sbus_21180(T_cds_tk_handle_21180); + +int cds_tk_read_sbus_23470(T_cds_tk_handle_23470); +int cds_tk_write_sbus_23470(T_cds_tk_handle_23470); + +int cds_tk_read_sbus_23550(T_cds_tk_handle_23550); +int cds_tk_write_sbus_23550(T_cds_tk_handle_23550); +int cds_tk_read_pbus_23550(T_cds_tk_handle_23550); + +int cds_tk_read_sbus_10510(T_cds_tk_handle_10510); +int cds_tk_write_sbus_10510(T_cds_tk_handle_10510); + + +//// +int cds_tk_read_pbus(T_cds_tk_handle); +int cds_tk_write_pbus(T_cds_tk_handle); + +void cds_tk_reset_error(T_cds_tk_handle); +void cds_tk_store_disable_error(T_cds_tk_handle); +void cds_tk_restore_enable_error(T_cds_tk_handle); + +#endif + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.c new file mode 100644 index 0000000..1d4ee36 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.c @@ -0,0 +1,280 @@ +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 10510 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_10510(T_cds_tk_10510 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.deadtime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mintime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_10510(T_cds_tk_10510 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.deadtime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//10 status_protect_deadtime_mintime + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_deadtime_mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//11 time_err_tk0_tk1 + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk0_tk1 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//12 time_err_tk2_tk3 + x_serial_bus_project.reg_addr = 12; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk2_tk3 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//13 time_err_tk4_tk5 + x_serial_bus_project.reg_addr = 13; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk4_tk5 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 time_err_tk6_tk7 + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk6_tk7 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.h new file mode 100644 index 0000000..2de6424 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_10510.h @@ -0,0 +1,460 @@ +#ifndef XP_CDS_TK_10510_H +#define XP_CDS_TK_10510_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 10510 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +#define T_CDS_TK_COUNT_ADR_PBUS_10510 0 // count max elements in parallel bus + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_10510 0x0 // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 enable :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) - 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +// + +} T_cds_tk_write_sbus_10510; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_10510 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000, 0x0105}//{0,0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 reserv :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) + 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +//10 + union + { + UInt16 all; + struct + { + UInt16 tk0_deadtime :1; + UInt16 tk1_deadtime :1; + UInt16 tk2_deadtime :1; + UInt16 tk3_deadtime :1; + UInt16 tk4_deadtime :1; + UInt16 tk5_deadtime :1; + UInt16 tk6_deadtime :1; + UInt16 tk7_deadtime :1; + UInt16 tk0_mintime :1; + UInt16 tk1_mintime :1; + UInt16 tk2_mintime :1; + UInt16 tk3_mintime :1; + UInt16 tk4_mintime :1; + UInt16 tk5_mintime :1; + UInt16 tk6_mintime :1; + UInt16 tk7_mintime :1; + } bit; + } status_protect_deadtime_mintime; +//11 + UInt16 time_err_tk0_tk1; +//12 + UInt16 time_err_tk2_tk3; +//13 + UInt16 time_err_tk4_tk5; +//14 + UInt16 time_err_tk6_tk7; +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_tk_read_sbus_10510; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_10510 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 res : 16; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_10510; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_10510 {T_CDS_TK_COUNT_ADR_PBUS_10510,T_CDS_TK_SETUP_USE_ADR_PBUS_10510} +////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_tk_write_sbus_10510 sbus; +} T_cds_tk_write_10510; + +typedef struct{ + T_cds_tk_read_sbus_10510 sbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_10510; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_10510 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_10510 write; + T_cds_tk_read_10510 read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_10510; + + + + +#define T_cds_tk_DEFAULTS_10510 { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_10510, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_10510},\ + {T_CDS_TK_READ_SBUS_DEFAULTS_10510,TYPE_CDS_XILINX_DEFAULTS},\ + 0, \ + (void (*)(Uint32))cds_tk_init, \ + (int (*)(Uint32))cds_tk_read_all, \ + (int (*)(Uint32))cds_tk_write_all, \ + (int (*)(Uint32))cds_tk_read_sbus_10510, \ + (int (*)(Uint32))cds_tk_write_sbus_10510, \ + (int (*)(Uint32))cds_tk_read_pbus, \ + (int (*)(Uint32))cds_tk_write_pbus, \ + (void (*)(Uint32))cds_tk_reset_error, \ + (void (*)(Uint32))cds_tk_store_disable_error, \ + (void (*)(Uint32))cds_tk_restore_enable_error \ + } + + +typedef T_cds_tk_10510 *T_cds_tk_handle_10510; + + + +#endif // XP_CDS_TK_10510_H + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.c new file mode 100644 index 0000000..fa39ccf --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.c @@ -0,0 +1,280 @@ +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 21180 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_21180(T_cds_tk_21180 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.deadtime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mintime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_21180(T_cds_tk_21180 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.deadtime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//10 status_protect_deadtime_mintime + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_deadtime_mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//11 time_err_tk0_tk2 + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk0_tk2 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//12 time_err_tk2_tk3 + x_serial_bus_project.reg_addr = 12; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk1_tk3 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//13 time_err_tk4_tk5 + x_serial_bus_project.reg_addr = 13; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk4_tk6 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 time_err_tk6_tk7 + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk5_tk7 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.h new file mode 100644 index 0000000..a9b6063 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_21180.h @@ -0,0 +1,459 @@ +#ifndef XP_CDS_TK_21180_H +#define XP_CDS_TK_21180_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 21180 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + + +#define T_CDS_TK_COUNT_ADR_PBUS_21180 0 // count max elements in parallel bus + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_21180 0x0 // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 enable :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) - 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +// + +} T_cds_tk_write_sbus_21180; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_21180 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000, 0x0105}//{0,0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 reserv :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) + 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +//10 + union + { + UInt16 all; + struct + { + UInt16 tk0_deadtime :1; + UInt16 tk1_deadtime :1; + UInt16 tk2_deadtime :1; + UInt16 tk3_deadtime :1; + UInt16 tk4_deadtime :1; + UInt16 tk5_deadtime :1; + UInt16 tk6_deadtime :1; + UInt16 tk7_deadtime :1; + UInt16 tk0_mintime :1; + UInt16 tk1_mintime :1; + UInt16 tk2_mintime :1; + UInt16 tk3_mintime :1; + UInt16 tk4_mintime :1; + UInt16 tk5_mintime :1; + UInt16 tk6_mintime :1; + UInt16 tk7_mintime :1; + } bit; + } status_protect_deadtime_mintime; +//11 + UInt16 time_err_tk0_tk2; +//12 + UInt16 time_err_tk1_tk3; +//13 + UInt16 time_err_tk4_tk6; +//14 + UInt16 time_err_tk5_tk7; +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_tk_read_sbus_21180; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_21180 {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 res : 16; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_21180; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_21180 {T_CDS_TK_COUNT_ADR_PBUS_21180,T_CDS_TK_SETUP_USE_ADR_PBUS_21180} +////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_tk_write_sbus_21180 sbus; +} T_cds_tk_write_21180; + +typedef struct{ + T_cds_tk_read_sbus_21180 sbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_21180; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_21180 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_21180 write; + T_cds_tk_read_21180 read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_21180; + + + + + +#define T_cds_tk_DEFAULTS_21180 { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_21180, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_21180},\ + {T_CDS_TK_READ_SBUS_DEFAULTS_21180,TYPE_CDS_XILINX_DEFAULTS},\ + 0, \ + (void (*)(Uint32))cds_tk_init, \ + (int (*)(Uint32))cds_tk_read_all, \ + (int (*)(Uint32))cds_tk_write_all, \ + (int (*)(Uint32))cds_tk_read_sbus_21180, \ + (int (*)(Uint32))cds_tk_write_sbus_21180, \ + (int (*)(Uint32))cds_tk_read_pbus, \ + (int (*)(Uint32))cds_tk_write_pbus, \ + (void (*)(Uint32))cds_tk_reset_error, \ + (void (*)(Uint32))cds_tk_store_disable_error, \ + (void (*)(Uint32))cds_tk_restore_enable_error \ + } + + + +typedef T_cds_tk_21180 *T_cds_tk_handle_21180; + + +#endif // XP_CDS_TK_21180_H + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.c new file mode 100644 index 0000000..662fa78 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.c @@ -0,0 +1,280 @@ +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 21300 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_21300(T_cds_tk_21300 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.deadtime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mintime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_21300(T_cds_tk_21300 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.deadtime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//10 status_protect_deadtime_mintime + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_deadtime_mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//11 time_err_tk0_tk1 + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk0_tk1 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//12 time_err_tk2_tk3 + x_serial_bus_project.reg_addr = 12; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk2_tk3 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//13 time_err_tk4_tk5 + x_serial_bus_project.reg_addr = 13; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk4_tk5 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 time_err_tk6_tk7 + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk6_tk7 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.h new file mode 100644 index 0000000..5b91533 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_21300.h @@ -0,0 +1,460 @@ +#ifndef XP_CDS_TK_21300_H +#define XP_CDS_TK_21300_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 21300 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +#define T_CDS_TK_COUNT_ADR_PBUS_21300 0 // count max elements in parallel bus + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_21300 0x0 // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 enable :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) - 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +// + +} T_cds_tk_write_sbus_21300; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_21300 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000, 0x0105}//{0,0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 reserv :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) + 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +//10 + union + { + UInt16 all; + struct + { + UInt16 tk0_deadtime :1; + UInt16 tk1_deadtime :1; + UInt16 tk2_deadtime :1; + UInt16 tk3_deadtime :1; + UInt16 tk4_deadtime :1; + UInt16 tk5_deadtime :1; + UInt16 tk6_deadtime :1; + UInt16 tk7_deadtime :1; + UInt16 tk0_mintime :1; + UInt16 tk1_mintime :1; + UInt16 tk2_mintime :1; + UInt16 tk3_mintime :1; + UInt16 tk4_mintime :1; + UInt16 tk5_mintime :1; + UInt16 tk6_mintime :1; + UInt16 tk7_mintime :1; + } bit; + } status_protect_deadtime_mintime; +//11 + UInt16 time_err_tk0_tk1; +//12 + UInt16 time_err_tk2_tk3; +//13 + UInt16 time_err_tk4_tk5; +//14 + UInt16 time_err_tk6_tk7; +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_tk_read_sbus_21300; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_21300 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 res : 16; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_21300; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_21300 {T_CDS_TK_COUNT_ADR_PBUS_21300,T_CDS_TK_SETUP_USE_ADR_PBUS_21300} +////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_tk_write_sbus_21300 sbus; +} T_cds_tk_write_21300; + +typedef struct{ + T_cds_tk_read_sbus_21300 sbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_21300; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_21300 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_21300 write; + T_cds_tk_read_21300 read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_21300; + + + + +#define T_cds_tk_DEFAULTS_21300 { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_21300, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_21300},\ + {T_CDS_TK_READ_SBUS_DEFAULTS_21300,TYPE_CDS_XILINX_DEFAULTS},\ + 0, \ + (void (*)(Uint32))cds_tk_init, \ + (int (*)(Uint32))cds_tk_read_all, \ + (int (*)(Uint32))cds_tk_write_all, \ + (int (*)(Uint32))cds_tk_read_sbus_21300, \ + (int (*)(Uint32))cds_tk_write_sbus_21300, \ + (int (*)(Uint32))cds_tk_read_pbus, \ + (int (*)(Uint32))cds_tk_write_pbus, \ + (void (*)(Uint32))cds_tk_reset_error, \ + (void (*)(Uint32))cds_tk_store_disable_error, \ + (void (*)(Uint32))cds_tk_restore_enable_error \ + } + + +typedef T_cds_tk_21300 *T_cds_tk_handle_21300; + + + +#endif // XP_CDS_TK_21300_H + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.c new file mode 100644 index 0000000..8c87148 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.c @@ -0,0 +1,302 @@ +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 22220 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_22220(T_cds_tk_22220 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.dead_min_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + +//9 delay_ack_ignore + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.filter_time_current_protect.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_22220(T_cds_tk_22220 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.dead_min_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//9 delay_ack_ignore + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.filter_time_current_protect.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//11 time_err_tk_all + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk_all.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_pbus_22220(T_cds_tk_22220 *v) +{ + if (v->useit == 0) + return 0; + +//#if (Cds_Tk_Xilinx_SP6 == 1) && (C_PROJECT_TYPE == PROJECT_22220) + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { +//0 + if (v->setup_pbus.use_reg_in_pbus.bit.reg0) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[0]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.DataReg0.all = x_parallel_bus_project.data_table_read; + } +//1 + if (v->setup_pbus.use_reg_in_pbus.bit.reg1) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[1]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.DataReg1.all = x_parallel_bus_project.data_table_read; + } + +//2 + if (v->setup_pbus.use_reg_in_pbus.bit.reg2) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[2]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.DataReg2.all = x_parallel_bus_project.data_table_read; + } + +//3 + if (v->setup_pbus.use_reg_in_pbus.bit.reg3) + { + x_parallel_bus_project.adr_table_read = v->adr_pbus.adr_table[3]; + x_parallel_bus_project.read_one_data(&x_parallel_bus_project); + v->read.pbus.DataReg3.all = x_parallel_bus_project.data_table_read; + } + } +//#endif + + return 0; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.h new file mode 100644 index 0000000..6e322ca --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_22220.h @@ -0,0 +1,539 @@ +#ifndef XP_CDS_TK_22220_H +#define XP_CDS_TK_22220_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 22220 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//#define Cds_Tk_Xilinx_SP6 0 + +//#if Cds_Tk_Xilinx_SP6 == 1 +#define T_CDS_TK_COUNT_ADR_PBUS_22220 4 // count max elements in parallel bus +//#else +// #define T_CDS_TK_COUNT_ADR_PBUS_22220 0 // count max elements in parallel bus +//#endif //Cds_Tk_Xilinx_SP6 + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_22220 0xffff // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=5000kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=5000kHz + } bit; + } dead_min_time; +//2 + union + { + UInt16 all; + struct + { + UInt16 delay_off :8; + UInt16 delay_on :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :5; + UInt16 enable_mask_err_serial_2 :1; // for SP6 + UInt16 enable_uksi_serial_2 :1; // for SP6 + UInt16 enable_mask_err_serial_1 :1; // for SP6 + UInt16 enable_uksi_serial_1 :1; // for SP6 + UInt16 reserv9 :1; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +//9 + union + { + UInt16 all; + struct + { + UInt16 filter_time :8; // fclk=5000kHz + UInt16 reserv :8; // + } bit; + } filter_time_current_protect; + +// + +} T_cds_tk_write_sbus_22220; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_22220 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000,0x0105} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; + +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=5000kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=5000kHz + } bit; + } dead_min_time; + +//2 + union + { + UInt16 all; + struct + { + UInt16 delay_off :8; + UInt16 delay_on :8; + } bit; + } ack_time; + +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; + +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :5; + UInt16 enable_mask_err_serial_2 :1; // for SP6 + UInt16 enable_uksi_serial_2 :1; // for SP6 + UInt16 enable_mask_err_serial_1 :1; // for SP6 + UInt16 enable_uksi_serial_1 :1; // for SP6 + UInt16 reserv9 :1; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; + +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; + +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; + +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :5; + UInt16 sp6_err_recive_serial_2 :1; // for SP6 + UInt16 sp6_err_recive_serial_1 :1; // for SP6 + UInt16 line_err_keys_3210 :1; + UInt16 line_err_keys_7654 :1; + UInt16 mintime_err_keys_3210 :1; + UInt16 mintime_err_keys_7654 :1; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; + +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; + +//9 + union + { + UInt16 all; + struct + { + UInt16 filter_time :8; // fclk=5000kHz + UInt16 reserv :8; // fclk=5000kHz + } bit; + } filter_time_current_protect; + +//11 + union + { + UInt16 all; + struct + { + UInt16 tk_3210 :8; + UInt16 tk_7654 :8; + } bit; + } time_err_tk_all; + +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :9; + UInt16 sp6_err_recive_UKSI_2 :1; + UInt16 sp6_err_recive_UKSI_1 :1; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + +} T_cds_tk_read_sbus_22220; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_22220 {0,0,0,0,0,0,0,0,0,0,0,0} + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + + +typedef struct { + //0 + union { + UInt16 all; + struct { + UInt16 UKSI_upper_bits:15; + UInt16 parity_bit:1; + } bit; + } DataReg0; + //1 + union { + UInt16 all; + struct { + UInt16 reserved:6; + UInt16 UKSI_upper_bits:9; + UInt16 parity_bit:1; + } bit; + } DataReg1; + //2 + union { + UInt16 all; + struct { + UInt16 UKSI_upper_bits:15; + UInt16 parity_bit:1; + } bit; + } DataReg2; + //3 + union { + UInt16 all; + struct { + UInt16 reserved:6; + UInt16 UKSI_upper_bits:9; + UInt16 parity_bit:1; + } bit; + } DataReg3; +} T_cds_tk_read_pbus_22220; + +#define T_CDS_TK_READ_PBUS_DEFAULTS_22220 {0,0,0,0} + + +///////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 reg0 : 1; + UInt16 reg1 : 1; + UInt16 reg2 : 1; + UInt16 reg3 : 1; + + UInt16 res : 12; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_22220; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_22220 {T_CDS_TK_COUNT_ADR_PBUS_22220,T_CDS_TK_SETUP_USE_ADR_PBUS_22220} +////////////////////////////////////////////////////////////// + + + + +typedef struct{ + T_cds_tk_write_sbus_22220 sbus; +} T_cds_tk_write_22220; + +typedef struct{ + T_cds_tk_read_sbus_22220 sbus; + T_cds_tk_read_pbus_22220 pbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_22220; + +#define T_CDS_TK_READ_DEFAULTS_22220 {T_CDS_TK_READ_SBUS_DEFAULTS_22220,T_CDS_TK_READ_PBUS_DEFAULTS_22220,TYPE_CDS_XILINX_DEFAULTS} + +typedef struct { + UInt16 adr_table[T_CDS_TK_COUNT_ADR_PBUS_22220]; +} T_cds_tk_adr_pbus_22220; + +#define T_CDS_TK_ADR_PBUS_DEFAULTS_22220 {0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_22220 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_22220 write; + T_cds_tk_read_22220 read; +//#if Cds_Tk_Xilinx_SP6 == 1 + T_cds_tk_adr_pbus_22220 adr_pbus; +//#endif + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_22220; + + + +#define T_cds_tk_DEFAULTS_22220 {0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_22220,\ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_22220},\ + T_CDS_TK_READ_DEFAULTS_22220,\ + T_CDS_TK_ADR_PBUS_DEFAULTS_22220,\ + 0,\ + (void (*)(Uint32))cds_tk_init,\ + (int (*)(Uint32))cds_tk_read_all,\ + (int (*)(Uint32))cds_tk_write_all,\ + (int (*)(Uint32))cds_tk_read_sbus_22220,\ + (int (*)(Uint32))cds_tk_write_sbus_22220,\ + (int (*)(Uint32))cds_tk_read_pbus_22220,\ + (int (*)(Uint32))cds_tk_write_pbus,\ + (void (*)(Uint32))cds_tk_reset_error,\ + (void (*)(Uint32))cds_tk_store_disable_error,\ + (void (*)(Uint32))cds_tk_restore_enable_error\ + } + + + + + + +typedef T_cds_tk_22220 *T_cds_tk_handle_22220; + + +#endif // XP_CDS_TK_22220_H diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.c new file mode 100644 index 0000000..a9a4aa2 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.c @@ -0,0 +1,280 @@ +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 21180 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_23470(T_cds_tk_23470 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.deadtime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mintime.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_23470(T_cds_tk_23470 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 deadtime + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.deadtime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//9 mintime + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//10 status_protect_deadtime_mintime + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_deadtime_mintime.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//11 time_err_tk0_tk1 + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk0_tk1 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; +//12 time_err_tk2_tk3 + x_serial_bus_project.reg_addr = 12; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk2_tk3 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//13 time_err_tk4_tk5 + x_serial_bus_project.reg_addr = 13; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk4_tk5 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//14 time_err_tk6_tk7 + x_serial_bus_project.reg_addr = 14; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk6_tk7 = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.h new file mode 100644 index 0000000..9c19268 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_23470.h @@ -0,0 +1,459 @@ +#ifndef XP_CDS_TK_23470_H +#define XP_CDS_TK_23470_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 23470 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +#define T_CDS_TK_COUNT_ADR_PBUS_23470 0 // count max elements in parallel bus + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_23470 0x0 // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 enable :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) - 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +// + +} T_cds_tk_write_sbus_23470; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_23470 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000, 0x0105}//{0,0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) fclk=50000kHz + UInt16 reserv :1; + } bit; + } deadtime; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 delay :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :12; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; +//9 + union + { + UInt16 all; + struct + { + UInt16 value :15; // N=(mintime * fclk) + 2 fclk=50000kHz + UInt16 enable :1; + } bit; + } mintime; +//10 + union + { + UInt16 all; + struct + { + UInt16 tk0_deadtime :1; + UInt16 tk1_deadtime :1; + UInt16 tk2_deadtime :1; + UInt16 tk3_deadtime :1; + UInt16 tk4_deadtime :1; + UInt16 tk5_deadtime :1; + UInt16 tk6_deadtime :1; + UInt16 tk7_deadtime :1; + UInt16 tk0_mintime :1; + UInt16 tk1_mintime :1; + UInt16 tk2_mintime :1; + UInt16 tk3_mintime :1; + UInt16 tk4_mintime :1; + UInt16 tk5_mintime :1; + UInt16 tk6_mintime :1; + UInt16 tk7_mintime :1; + } bit; + } status_protect_deadtime_mintime; +//11 + UInt16 time_err_tk0_tk1; +//12 + UInt16 time_err_tk2_tk3; +//13 + UInt16 time_err_tk4_tk5; +//14 + UInt16 time_err_tk6_tk7; +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_tk_read_sbus_23470; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_23470 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 res : 16; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_23470; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_23470 {T_CDS_TK_COUNT_ADR_PBUS_23470,T_CDS_TK_SETUP_USE_ADR_PBUS_23470} +////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_tk_write_sbus_23470 sbus; +} T_cds_tk_write_23470; + +typedef struct{ + T_cds_tk_read_sbus_23470 sbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_23470; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_23470 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_23470 write; + T_cds_tk_read_23470 read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_23470; + + + +#define T_cds_tk_DEFAULTS_23470 { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_23470, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_23470},\ + {T_CDS_TK_READ_SBUS_DEFAULTS_23470,TYPE_CDS_XILINX_DEFAULTS},\ + 0, \ + (void (*)(Uint32))cds_tk_init, \ + (int (*)(Uint32))cds_tk_read_all, \ + (int (*)(Uint32))cds_tk_write_all, \ + (int (*)(Uint32))cds_tk_read_sbus_23470, \ + (int (*)(Uint32))cds_tk_write_sbus_23470, \ + (int (*)(Uint32))cds_tk_read_pbus, \ + (int (*)(Uint32))cds_tk_write_pbus, \ + (void (*)(Uint32))cds_tk_reset_error, \ + (void (*)(Uint32))cds_tk_store_disable_error, \ + (void (*)(Uint32))cds_tk_restore_enable_error \ + } + + +typedef T_cds_tk_23470 *T_cds_tk_handle_23470; + + + + + +#endif // XP_CDS_TK_23470_H + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.c new file mode 100644 index 0000000..ea8424b --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.c @@ -0,0 +1,560 @@ +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// 23550 +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_23550(T_cds_tk_23550 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.dead_min_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//10 time_after_err + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.time_after_err; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_23550(T_cds_tk_23550 *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.dead_min_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//9 id_plate + x_serial_bus_project.reg_addr = 9; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.id_plate.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//10 time_after_err + x_serial_bus_project.reg_addr = 10; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_after_err = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//11 time_err_tk_all + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk_all.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->type_cds_xilinx = v->read.type_cds_xilinx; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +#pragma CODE_SECTION(cds_tk_read_pbus_23550,".fast_run2"); +int cds_tk_read_pbus_23550(T_cds_tk_23550 *v) +{ + unsigned long adr_pbus; + + if (v->useit == 0 || v->setup_pbus.use_reg_in_pbus.all==0) + return 0; + + if (v->status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) + { +//#if (Cds_Tk_Xilinx_SP6 == 1) && (C_PROJECT_TYPE == PROJECT_23550) + if (v->type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + adr_pbus = v->adr_pbus.adr_table[0] + ADR_FIRST_FREE; + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg0,adr_pbus,v->read.pbus.status1.all); + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg1,adr_pbus,v->read.pbus.DataReg0.all); + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg2,adr_pbus,v->read.pbus.DataReg1.all); + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg3,adr_pbus,v->read.pbus.DataReg2.all); + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg4,adr_pbus,v->read.pbus.DataReg3.all); + read_pbus_value_full_v3(v->setup_pbus.use_reg_in_pbus.bit.reg5,adr_pbus,v->read.pbus.status2.all); + } + } + else + { + v->read.pbus.status1.all = 0; + v->read.pbus.DataReg0.all = 0; + v->read.pbus.DataReg1.all = 0; + v->read.pbus.DataReg2.all = 0; + v->read.pbus.DataReg3.all = 0; + v->read.pbus.status2.all = 0; + } + +//#endif + + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +#pragma CODE_SECTION(cds_tk_optical_bus_write_data,".fast_run"); +void cds_tk_optical_bus_write_data(T_cds_tk_23550 *v) +{ + if (v->useit == 0) + return ; + + i_WriteMemory(SI_OPTICS_WORD_TO_SEND_1,v->optical_data_out.buf[0]); + i_WriteMemory(SI_OPTICS_WORD_TO_SEND_2,v->optical_data_out.buf[1]); + i_WriteMemory(SI_OPTICS_WORD_TO_SEND_3,v->optical_data_out.buf[2]); + i_WriteMemory(SI_OPTICS_WORD_TO_SEND_4,v->optical_data_out.buf[3]); + v->optical_data_out.count_send++; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +#pragma CODE_SECTION(cds_tk_optical_bus_check_error_read,".fast_run"); +void cds_tk_optical_bus_check_error_read(T_cds_tk_23550 *v) +{ + unsigned int delta_id_sbus = 0; +// static unsigned int prev_id_sbus = 0; + + if (v->useit == 0) + return ; + + // i_led2_on_off(1); + + v->optical_data_in.status_1.all = v->read.pbus.status1.all; + v->optical_data_in.status_2.all = v->read.pbus.status2.all; + +// if ( (v->read.pbus.status1.all == v->read.pbus.status2.all) +// && (v->read.pbus.status1.bit.receiver_busy==0) +// && (v->read.pbus.status1.bit.receiver_error==0) +// ) + + if ( v->optical_data_in.status_1.bit.id_sbus == v->optical_data_in.status_2.bit.id_sbus + && v->optical_data_in.status_1.bit.id == v->optical_data_in.status_2.bit.id +// && (v->read.pbus.status1.bit.receiver_error==0) +// && (v->read.pbus.status2.bit.receiver_error==0) + ) + { + // если выставился этот бит, то знвчит приемник в приеме данных, но т.к. эти данные мы получаем по PBUS с некоторым лагом + // смысл этого бита теряет свой смысл, просто как информация, данные мы получим всегда последние удачные. + v->optical_data_in.status_read.bit.receiver_busy = v->optical_data_in.status_1.bit.receiver_busy || v->optical_data_in.status_2.bit.receiver_busy; + + // may be data new and ok? + // счетчик новых принимаемых посылок не изменился + if (v->optical_data_in.status_1.bit.id_sbus == v->optical_data_in.prev_id_sbus) { + // data old + v->optical_data_in.status_read.bit.old_data = 1; + v->optical_data_in.same_id_count += 1; + + if (v->optical_data_in.same_id_count_between < v->optical_data_in.setup_count_error_between) + v->optical_data_in.same_id_count_between += 1; + else + // читали все время старые данные, передатчик умер на той стороне? + v->optical_data_in.ready = 0; + } + else + { + // очистка ошибок + v->optical_data_in.same_id_count_between = 0; + v->optical_data_in.local_count_error = 0; + v->optical_data_in.raw_local_error = 0; + v->optical_data_in.ready = 1; + + // есть ли потери в чтении? + if (v->optical_data_in.status_1.bit.id_sbus >= v->optical_data_in.prev_id_sbus) + delta_id_sbus = v->optical_data_in.status_1.bit.id_sbus - v->optical_data_in.prev_id_sbus; + else + delta_id_sbus = 0x10 + v->optical_data_in.status_1.bit.id_sbus - v->optical_data_in.prev_id_sbus; + + if (delta_id_sbus == 1 ) + { + // тут все ок. + v->optical_data_in.count_ok++; + } + else + { + // есть потери + v->optical_data_in.count_lost += (delta_id_sbus - 1); + v->optical_data_in.count_ok++; + v->optical_data_in.status_read.bit.lost_data = 1; + } + + // вдруг данные мы не забрали? + if (v->optical_data_in.status_read.bit.new_data_ready) + v->optical_data_in.status_read.bit.overfull_new_data = 1; // переполнение данных, потеря предыдущих + + // забрали данные + v->optical_data_in.buf[0] = v->read.pbus.DataReg0.all; + v->optical_data_in.buf[1] = v->read.pbus.DataReg1.all; + v->optical_data_in.buf[2] = v->read.pbus.DataReg2.all; + v->optical_data_in.buf[3] = v->read.pbus.DataReg3.all; + + + v->optical_data_in.status_read.bit.new_data_ready = 1; + + } + + v->optical_data_in.prev_id_sbus = v->read.pbus.status1.bit.id_sbus; + } + else + { + if ((v->optical_data_in.status_1.bit.id_sbus != v->optical_data_in.status_2.bit.id_sbus) + || (v->optical_data_in.status_1.bit.id != v->optical_data_in.status_2.bit.id) ) + v->optical_data_in.status_read.bit.bad_status12 = 1; + + if (v->read.pbus.status1.bit.receiver_error==1 || v->read.pbus.status2.bit.receiver_error==1) + v->optical_data_in.status_read.bit.receiver_error = 1; + + v->optical_data_in.raw_local_error = 1; + v->optical_data_in.full_count_error++; + + if (v->optical_data_in.local_count_error >= v->optical_data_in.setup_count_error) + { + v->optical_data_in.ready = 0; + +// v->optical_data_in.buf[0] = 0; +// v->optical_data_in.buf[1] = 0; +// v->optical_data_in.buf[2] = 0; +// v->optical_data_in.buf[3] = 0; + } + else + { + v->optical_data_in.local_count_error++; + } + + } + + +// +// +// if ( (v->read.pbus.status1.all == v->read.pbus.status2.all) +// && (v->read.pbus.status1.bit.id_sbus != v->optical_data_in.prev_id_sbus ) +// && (v->read.pbus.status1.bit.receiver_busy==0) +// && (v->read.pbus.status1.bit.receiver_error==0) +// ) +// { +// +// +// if (v->read.pbus.status1.bit.id_sbus >= v->optical_data_in.prev_id_sbus) +// delta_id_sbus = v->read.pbus.status1.bit.id_sbus - v->optical_data_in.prev_id_sbus; +// else +// delta_id_sbus = 0x10 + v->read.pbus.status1.bit.id_sbus - v->optical_data_in.prev_id_sbus; +// +// v->optical_data_in.local_count_error = 0; +// v->optical_data_in.raw_local_error = 0; +// v->optical_data_in.ready = 1; +// +// +// +// if (delta_id_sbus == 1 ) +// v->optical_data_in.count_ok++; +// else +// { +// v->optical_data_in.count_lost += (delta_id_sbus - 1); +// v->optical_data_in.count_ok++; +// } +// +// v->optical_data_in.buf[0] = v->read.pbus.DataReg0.all; +// v->optical_data_in.buf[1] = v->read.pbus.DataReg1.all; +// v->optical_data_in.buf[2] = v->read.pbus.DataReg2.all; +// v->optical_data_in.buf[3] = v->read.pbus.DataReg3.all; +// +// // вдруг данные мы не забрали? +// if (v->optical_data_in.new_data_ready) +// v->optical_data_in.overfull_new_data = 1; // переполнение данных, потеря предыдущих +// +// v->optical_data_in.new_data_ready = 1; +// +// } +// else +// { +//// Led1_Toggle(); +// +//// i_led1_on_off(1); +// +// v->optical_data_in.raw_local_error = 1; +// +// if (v->read.pbus.status1.bit.id_sbus != v->optical_data_in.prev_id_sbus) { +// v->optical_data_in.same_id_count += 1; +// } +// v->optical_data_in.full_count_error++; +// if (v->optical_data_in.local_count_error >= v->optical_data_in.setup_count_error) +// { +// v->optical_data_in.ready = 0; +// +// v->optical_data_in.buf[0] = 0; +// v->optical_data_in.buf[1] = 0; +// v->optical_data_in.buf[2] = 0; +// v->optical_data_in.buf[3] = 0; +// +// } +// else +// { +// v->optical_data_in.local_count_error++; +//// i_led2_toggle(); +// } +// +//// i_led1_on_off(0); +// } +// v->optical_data_in.prev_id_sbus = v->read.pbus.status1.bit.id_sbus; +// // i_led2_on_off(0); +// +// +//// v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. +//// v->write_sbus(v); +// + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +#pragma CODE_SECTION(cds_tk_optical_bus_check_error_write,".fast_run"); +void cds_tk_optical_bus_check_error_write(T_cds_tk_23550 *v) +{ + if (v->useit == 0) + return ; + + if ( (v->read.pbus.status1.all == v->read.pbus.status2.all) + && (v->read.pbus.status1.bit.trans_busy==0) + && (v->read.pbus.status1.bit.trans_error==0) + ) + { + v->optical_data_out.local_count_error = 0; + v->optical_data_out.ready = 1; + v->optical_data_out.raw_local_error = 0; + } + else + { + v->optical_data_out.raw_local_error = 1; + v->optical_data_out.full_count_error++; + if (v->optical_data_out.local_count_error >= v->optical_data_out.setup_count_error) + v->optical_data_out.ready = 0; + else + { + v->optical_data_out.local_count_error++; + } + + } + +// v->write.sbus.protect_error.all = v->store_protect_error; // restore all setup error. +// v->write_sbus(v); + + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.h new file mode 100644 index 0000000..f12da6d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_23550.h @@ -0,0 +1,616 @@ +#ifndef XP_CDS_TK_23550_H +#define XP_CDS_TK_23550_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// 23550 +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//#define Cds_Tk_Xilinx_SP6 0 + +//#if Cds_Tk_Xilinx_SP6 == 1 +#define T_CDS_TK_COUNT_ADR_PBUS_23550 6 // count max elements in parallel bus +//#else +// #define T_CDS_TK_COUNT_ADR_PBUS_23550 0 // count max elements in parallel bus +//#endif //Cds_Tk_Xilinx_SP6 + +#define T_CDS_TK_SETUP_USE_ADR_PBUS_23550 0xffff // по умолчанию - настройка какие регистры использовать длЯ PBUS, 0xffff - все возможные + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=5000kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=5000kHz + } bit; + } dead_min_time; +//2 + union + { + UInt16 all; + struct + { + UInt16 time :8; + UInt16 reserv :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :8; + UInt16 detect_soft_disconnect :1; + UInt16 enable_soft_disconnect :1; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; + +//10 + UInt16 time_after_err; //time_after_err = 4000<-DEC * 0.02 = 80mc + +} T_cds_tk_write_sbus_23550; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_23550 {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0105} + + +//////////////////////////////////// ///////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; + +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=5000kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=5000kHz + } bit; + } dead_min_time; + +//2 + union + { + UInt16 all; + struct + { + UInt16 time :8; + UInt16 reserv :8; + } bit; + } ack_time; + +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; + +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :8; + UInt16 detect_soft_disconnect :1; + UInt16 enable_soft_disconnect :1; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; + +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; + +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; + +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :5; + UInt16 ErrorSoftShutdownForbidComb :1; + UInt16 ErrorSoftShutdownFromErr0 :1; + UInt16 line_err_keys_3210 :1; + UInt16 line_err_keys_7654 :1; + UInt16 mintime_err_keys_3210 :1; + UInt16 mintime_err_keys_7654 :1; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; + +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; + +//9 + union + { + UInt16 all; + struct + { + UInt16 revision :5; + UInt16 version :6; + T_plate_type plate_type :5; + } bit; + } id_plate; + +//10 + + UInt16 time_after_err; + + +//11 + union + { + UInt16 all; + struct + { + UInt16 tk_3210 :8; + UInt16 tk_7654 :8; + } bit; + } time_err_tk_all; + +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + +} T_cds_tk_read_sbus_23550; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_23550 {0,0,0,0,0,0,0,0,0,0,0} + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +typedef union { + UInt16 all; + struct { + UInt16 id:4; // -Идентификатор отправки(целостности по параллельной шине). До прочтения + // (должен совпасть с идентификатором после) + UInt16 id_sbus:4; // Счетчик принимаемых посылок, увелич.на +1 при каждой новой посылке + + UInt16 count_receiver_error:4; // число ошибок при получении данных (приемник на текущей плате ТК) + UInt16 trans_busy:1; // busy 1-приемник в процессе получения данных, 0- в ожидании (приемник на плате ТК в другой корзине) + UInt16 trans_error:1; // ошибка при получении данных (приемник на плате ТК в другой корзине) + UInt16 receiver_busy :1; // busy 1-приемник в процессе получения данных, 0- в ожидании (приемник на текущей плате ТК) + UInt16 receiver_error:1; // ошибка при получении данных (приемник на текущей плате ТК) + } bit; +} STATUS_OPT_BUS; + +///////////////////////////////////////////////////////////// + +typedef struct { + //0 + STATUS_OPT_BUS status1; + //1 + union { + UInt16 all; + } DataReg0; + //2 + union { + UInt16 all; + } DataReg1; + //3 + union { + UInt16 all; + } DataReg2; + //4 + union { + UInt16 all; + } DataReg3; + //5 + STATUS_OPT_BUS status2; + +} T_cds_tk_read_pbus_23550; +//в общем 15, 14, 11-8 это статусы приема, 13, 12 - статусы отправки, являющиеся статусами приема у платы во второй корзине +//ну в общем ключевой бит - 15, значит мы от платы в другой корзине получили данные, у которых не совпал ЦРЦ, и 13, значит что в другую корзину данные не ушли. +//busy чисто на всякий случай, проверить перед отправкой. +//Ну и после, если бизи ноль(12), еррор(13) ноль, значит данные ушли и все супер. +//если бизи 1, значит в процессе, либо что-то залипло, но вроде не должно +//Ну а при чтении данных полученных из другой корзины мы смотрим 15 и 14, если 15 и 14 = 0, значит все хорошо, если 15 = 1, бизи 0, значит передача была, но не удачно +//идентификатор отправки обновляется каждый раз, как данные были изменены. +//соответственно если пока мы что-то слали по параллельной шине, по оптике пришли новые данные, и идентификатор обновился, данные могли смешаться, это плохо, значит надо прочитать параллельную шину еще раз +//Регистр #0 должен быть равен #5 если передача не была нарушена или перезаписана на этапе ее трансляции в PBUS +//id инкрементируется по кругу при каждой передачи + + +#define T_CDS_TK_READ_PBUS_DEFAULTS_23550 {0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//setup parallel bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + UInt16 count_elements_pbus; +// use_or_not? + union + { + UInt16 all; + struct{ + UInt16 reg0 : 1; + UInt16 reg1 : 1; + UInt16 reg2 : 1; + UInt16 reg3 : 1; + UInt16 reg4 : 1; + UInt16 reg5 : 1; + UInt16 res : 10; + }bit; + } use_reg_in_pbus; + +} T_cds_tk_setup_pbus_23550; + +#define T_CDS_TK_SETUP_PBUS_DEFAULTS_23550 {T_CDS_TK_COUNT_ADR_PBUS_23550,T_CDS_TK_SETUP_USE_ADR_PBUS_23550} +////////////////////////////////////////////////////////////// + + + + +typedef struct{ + T_cds_tk_write_sbus_23550 sbus; +} T_cds_tk_write_23550; + +typedef struct{ + T_cds_tk_read_sbus_23550 sbus; + T_cds_tk_read_pbus_23550 pbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_23550; + +#define T_CDS_TK_READ_DEFAULTS_23550 {T_CDS_TK_READ_SBUS_DEFAULTS_23550,T_CDS_TK_READ_PBUS_DEFAULTS_23550,TYPE_CDS_XILINX_DEFAULTS} + +typedef struct { + UInt16 adr_table[T_CDS_TK_COUNT_ADR_PBUS_23550]; +} T_cds_tk_adr_pbus_23550; + +#define T_CDS_TK_ADR_PBUS_DEFAULTS_23550 {0,0,0,0,0,0} + + +////////////////////////////////////////////////////////////// +typedef struct { + UInt16 setup_count_error; + UInt16 full_count_error; + UInt16 local_count_error; + UInt16 count_send; + UInt16 ready; + UInt16 error_not_ready_count; + UInt16 raw_local_error; + UInt16 buf[4]; +} T_cds_optical_bus_data_out; + +#define T_CDS_OPTICAL_BUS_DATA_OUT_DEFAULTS {15,0,0,0,0,0,0,{0,0,0,0}} + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +typedef union { + UInt16 all; + struct { + UInt16 new_data_ready:1; // есть новые данные + UInt16 overfull_new_data:1; // данные новые затерли старые + UInt16 old_data:1; // старые данные + UInt16 lost_data:1; // были потери при чтении, слишком медленно читаем парал.шину + UInt16 bad_status12:1; // при чтении была напушена целостность данных, надо повторить чтение + UInt16 receiver_busy:1; //busy 1-приемник в процессе получения данных, 0- в ожидании (приемник на текущей плате ТК) + UInt16 receiver_error:1; // ошибка при получении данных (приемник на текущей плате ТК) + + } bit; +} STATUS_DATA_READ_OPT_BUS; + +///////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +typedef struct { + UInt16 setup_count_error; // сколько ждем до падения шины + UInt16 setup_count_error_between; // сколько ждем до падения шины при чтении старых значений + UInt16 full_count_error; // всего ошибок + UInt16 local_count_error; // текущий счетчик ошибок, идет до setup_count_error и снимается ready, при удачном чтении обнуляется + UInt16 count_ok; // сколько удачных чтений + UInt16 count_lost; // сколько потерь данных (по id_sbus) + UInt16 ready; // шина работает, ошибки не превысили setup_count_error + UInt16 same_id_count; // сколько всего повторных чтений техже данных, т.е. передатчик в др.ПЧ не прислал ничего нового + UInt16 same_id_count_between; // между удачными чтениями, сколько повторных чтений техже данных, т.е. передатчик в др.ПЧ не прислал ничего нового + UInt16 error_not_ready_count; // сколько ошибок не готовности шины ready + UInt16 raw_local_error; // есть ошибка при чтении, но шина не упала еще + UInt16 buf[4]; // данные + STATUS_OPT_BUS status_1; // копия status 1 + STATUS_OPT_BUS status_2; // копия status 2 + UInt16 prev_id_sbus; // пред. значение id_sbus + STATUS_DATA_READ_OPT_BUS status_read;// статус после чтения и анализа данных + STATUS_DATA_READ_OPT_BUS prev_status_read;// статус после чтения и анализа данных +} T_cds_optical_bus_data_in; + +#define T_CDS_OPTICAL_BUS_DATA_IN_DEFAULTS {15,50,0,0,0,0,0,0,0,0,0,{0,0,0,0},0,0,0,0,0} + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + T_cds_tk_setup_pbus_23550 setup_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_23550 write; + T_cds_tk_read_23550 read; +//#if Cds_Tk_Xilinx_SP6 == 1 + T_cds_tk_adr_pbus_23550 adr_pbus; +//#endif + UInt16 store_protect_error; + + T_cds_optical_bus_data_out optical_data_out; + T_cds_optical_bus_data_in optical_data_in; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*optical_bus_write_data)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + + void (*optical_bus_check_error_read)(); // Pointer to calculation function + void (*optical_bus_check_error_write)(); // Pointer to calculation function + +} T_cds_tk_23550; + + + +#define T_cds_tk_DEFAULTS_23550 {0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_SETUP_PBUS_DEFAULTS_23550,\ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_23550},\ + T_CDS_TK_READ_DEFAULTS_23550,\ + T_CDS_TK_ADR_PBUS_DEFAULTS_23550,\ + 0,\ + T_CDS_OPTICAL_BUS_DATA_OUT_DEFAULTS,\ + T_CDS_OPTICAL_BUS_DATA_IN_DEFAULTS,\ + (void (*)(Uint32))cds_tk_init,\ + (int (*)(Uint32))cds_tk_read_all,\ + (int (*)(Uint32))cds_tk_write_all,\ + (int (*)(Uint32))cds_tk_read_sbus_23550,\ + (int (*)(Uint32))cds_tk_write_sbus_23550,\ + (int (*)(Uint32))cds_tk_read_pbus_23550,\ + (int (*)(Uint32))cds_tk_write_pbus,\ + (void (*)(Uint32))cds_tk_optical_bus_write_data,\ + (void (*)(Uint32))cds_tk_reset_error,\ + (void (*)(Uint32))cds_tk_store_disable_error,\ + (void (*)(Uint32))cds_tk_restore_enable_error,\ + (void (*)(Uint32))cds_tk_optical_bus_check_error_read,\ + (void (*)(Uint32))cds_tk_optical_bus_check_error_write\ + } + + + + + + +typedef T_cds_tk_23550 *T_cds_tk_handle_23550; + +void cds_tk_optical_bus_write_data(T_cds_tk_23550 *v); +void cds_tk_optical_bus_check_error_read(T_cds_tk_23550 *v); +void cds_tk_optical_bus_check_error_write(T_cds_tk_23550 *v); + +#endif // XP_CDS_TK_23550_H diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.c b/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.c new file mode 100644 index 0000000..5564462 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.c @@ -0,0 +1,236 @@ +#include "x_serial_bus.h" +#include "xp_cds_tk.h" +#include "xp_tools.h" + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +// BALZAM +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_write_sbus_balzam(T_cds_tk_balzam *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_write_error; + x_serial_bus_project.slave_addr = v->plane_address; // number plate + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_protect_tk.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + +//4 protect_error +// if (v->read.type_cds_xilinx == TYPE_CDS_XILINX_SP6) +// v->write.sbus.protect_error.bit.enable_err_switch = 0; // для SP6 отключаем ошибку по разъему, т.к. ее нет пока + + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.protect_error.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.mask_tk_out_40pin.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.dead_min_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.ack_time.all; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_write_error++; + + + + +//7 cmd_reset_error +/* + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.write_data = v->write.sbus.cmd_reset_error; // write data + + if (x_serial_bus_project.write(&x_serial_bus_project)) // make write + v->status_serial_bus.count_error++; +*/ + + if (old_err == v->status_serial_bus.count_write_error)// no errors + { + v->status_serial_bus.count_write_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_WRITE_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; + + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int cds_tk_read_sbus_balzam(T_cds_tk_balzam *v) +{ + unsigned int old_err, err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + old_err = v->status_serial_bus.count_read_error; + + x_serial_bus_project.slave_addr = v->plane_address; // number plate + +//0 mask_tk_out_40pin + x_serial_bus_project.reg_addr = 0; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_tk_out_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//1 dead_min_time + x_serial_bus_project.reg_addr = 1; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.dead_min_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//2 ack_time + x_serial_bus_project.reg_addr = 2; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.ack_time.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + + +//3 mask_protect_tk + x_serial_bus_project.reg_addr = 3; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.mask_protect_tk.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//4 protect_error + x_serial_bus_project.reg_addr = 4; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.protect_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//5 status_tk_40pin + x_serial_bus_project.reg_addr = 5; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_40pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//6 status_tk_96pin + x_serial_bus_project.reg_addr = 6; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_tk_96pin.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//7 lock_status_error + x_serial_bus_project.reg_addr = 7; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.lock_status_error.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//8 status_protect_current_ack + x_serial_bus_project.reg_addr = 8; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.status_protect_current_ack.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//11 time_err_tk_all + x_serial_bus_project.reg_addr = 11; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + v->read.sbus.time_err_tk_all.all = x_serial_bus_project.read_data; + else + v->status_serial_bus.count_read_error++; + +//15 current_status_error + x_serial_bus_project.reg_addr = 15; // adr memory in plate + x_serial_bus_project.read(&x_serial_bus_project); // read + + if (x_serial_bus_project.flags.bit.read_error == 0) // check error + { + v->read.type_cds_xilinx = x_serial_bus_project.read_data & 0x1; + v->read.sbus.current_status_error.all = x_serial_bus_project.read_data & 0xfffe; + } + else + v->status_serial_bus.count_read_error++; + + +/////////// + + if (old_err == v->status_serial_bus.count_read_error)// no errors + { + v->status_serial_bus.count_read_ok++; + err = 0; // no errors + } + else + err = 1; // !errors! + + err_ready = check_cds_ready_sbus( err, ITS_READ_BUS, &v->status_serial_bus); + set_status_cds(err_ready, &v->status); + + return err_ready; +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.h b/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.h new file mode 100644 index 0000000..35eedda --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_cds_tk_balzam.h @@ -0,0 +1,403 @@ +#ifndef XP_CDS_TK_BALZAM_H +#define XP_CDS_TK_BALZAM_H + + +#include + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//// BALZAM +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +#define T_CDS_TK_COUNT_ADR_PBUS_BALZAM 0 // count max elements in parallel bus + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +// write serial bus reg +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=6250kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=6250kHz + } bit; + } dead_min_time; +//2 + union + { + UInt16 all; + struct + { + UInt16 time0 :8; + UInt16 reserv :8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :10; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//7 + UInt16 cmd_reset_error; +// + +} T_cds_tk_write_sbus_balzam; + +#define T_CDS_TK_WRITE_SBUS_DEFAULTS_BALZAM {0x0000,0x5f5f,0x0909,0x0000,0x0000,0x0000}//{0,0,0,0,0,0,0} + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg serial bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 + union + { + UInt16 all; + struct + { + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + UInt16 reserv :8; + } bit; + } mask_tk_out_40pin; +//1 + union + { + UInt16 all; + struct + { + UInt16 mintime :8; // N=mintime * fclk fclk=6250kHz + UInt16 deadtime :8; // N=deadtime * fclk fclk=6250kHz + } bit; + } dead_min_time; +//2 + union + { + UInt16 all; + struct + { + UInt16 time :8; + UInt16 reserv : 8; + } bit; + } ack_time; +//3 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } mask_protect_tk; +//4 + union + { + UInt16 all; + struct + { + UInt16 reserv :10; + UInt16 enable_line_err :1; + UInt16 disable_err_mintime :1; + UInt16 disable_err_hwp :1; + UInt16 disable_err0_in :1; + UInt16 enable_err_switch :1; + UInt16 enable_err_power :1; + } bit; + } protect_error; +//5 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0 :1; + UInt16 tk1 :1; + UInt16 tk2 :1; + UInt16 tk3 :1; + UInt16 tk4 :1; + UInt16 tk5 :1; + UInt16 tk6 :1; + UInt16 tk7 :1; + } bit; + } status_tk_40pin; +//6 + union + { + UInt16 all; + struct + { + UInt16 tk0_a4 :1; + UInt16 tk1_b4 :1; + UInt16 tk2_c4 :1; + UInt16 tk3_a5 :1; + UInt16 tk4_b5 :1; + UInt16 tk5_c5 :1; + UInt16 tk6_a6 :1; + UInt16 tk7_b6 :1; + UInt16 tk8_c6 :1; + UInt16 tk9_a7 :1; + UInt16 tk10_b7 :1; + UInt16 tk11_c7 :1; + UInt16 tk12_a8 :1; + UInt16 tk13_b8 :1; + UInt16 tk14_a9 :1; + UInt16 tk15_b9 :1; + } bit; + } status_tk_96pin; +//7 + union + { + UInt16 all; + struct + { + UInt16 reserv :7; + UInt16 line_err_keys_3210 :1; + UInt16 line_err_keys_7654 :1; + UInt16 mintime_err_keys_3210 :1; + UInt16 mintime_err_keys_7654 :1; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } lock_status_error; +//8 + union + { + UInt16 all; + struct + { + UInt16 tk0_ack :1; + UInt16 tk1_ack :1; + UInt16 tk2_ack :1; + UInt16 tk3_ack :1; + UInt16 tk4_ack :1; + UInt16 tk5_ack :1; + UInt16 tk6_ack :1; + UInt16 tk7_ack :1; + UInt16 tk0_current :1; + UInt16 tk1_current :1; + UInt16 tk2_current :1; + UInt16 tk3_current :1; + UInt16 tk4_current :1; + UInt16 tk5_current :1; + UInt16 tk6_current :1; + UInt16 tk7_current :1; + } bit; + } status_protect_current_ack; +//11 + union + { + UInt16 all; + struct + { + UInt16 tk_3210 :8; + UInt16 tk_7654 :8; + } bit; + } time_err_tk_all; +//15 + union + { + UInt16 all; + struct + { + UInt16 reserv :11; + UInt16 err0_local :1; + UInt16 err_hwp :1; + UInt16 err0_in :1; + UInt16 err_switch :1; + UInt16 err_power :1; + } bit; + } current_status_error; + + +} T_cds_tk_read_sbus_balzam; + + +#define T_CDS_TK_READ_SBUS_DEFAULTS_BALZAM {0,0,0,0, 0,0,0,0, 0,0,0} + + + + + +///////////////////////////////////////////////////////////////// + + +typedef struct{ + T_cds_tk_write_sbus_balzam sbus; +} T_cds_tk_write_balzam; + +typedef struct{ + T_cds_tk_read_sbus_balzam sbus; + Int16 type_cds_xilinx; +} T_cds_tk_read_balzam; + +////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + +typedef struct { + UInt16 plane_address; // 0 to 15 + UInt16 useit; + Int16 type_cds_xilinx; + UInt16 count_elements_pbus; + T_cds_status_serial_bus status_serial_bus; + T_cds_status_parallel_bus status_parallel_bus; + T_component_status status; + T_local_status local_status; + + T_cds_tk_write_balzam write; + T_cds_tk_read_balzam read; + + UInt16 store_protect_error; + + void (*init)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*read_sbus)(); // Pointer to calculation function + int (*write_sbus)(); // Pointer to calculation function + + int (*read_pbus)(); // Pointer to calculation function + int (*write_pbus)(); // Pointer to calculation function + + void (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + +} T_cds_tk_balzam; + + + +#define T_cds_tk_DEFAULTS_BALZAM { 0,\ + 0,\ + TYPE_CDS_XILINX_DEFAULTS,\ + T_CDS_TK_COUNT_ADR_PBUS_BALZAM, \ + T_cds_status_serial_bus_DEFAULT,\ + T_cds_status_parallel_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + {T_CDS_TK_WRITE_SBUS_DEFAULTS_BALZAM},\ + {T_CDS_TK_READ_SBUS_DEFAULTS_BALZAM,TYPE_CDS_XILINX_DEFAULTS},\ + 0, \ + (void (*)(Uint32))cds_tk_init, \ + (int (*)(Uint32))cds_tk_read_all, \ + (int (*)(Uint32))cds_tk_write_all, \ + (int (*)(Uint32))cds_tk_read_sbus_balzam, \ + (int (*)(Uint32))cds_tk_write_sbus_balzam, \ + (int (*)(Uint32))cds_tk_read_pbus, \ + (int (*)(Uint32))cds_tk_write_pbus, \ + (void (*)(Uint32))cds_tk_reset_error, \ + (void (*)(Uint32))cds_tk_store_disable_error, \ + (void (*)(Uint32))cds_tk_restore_enable_error \ + } + + +typedef T_cds_tk_balzam *T_cds_tk_handle_balzam; + + + + + + +#endif // XP_CDS_TK_BALZAM_H + + diff --git a/Inu/Src2/N12_Xilinx/xp_controller.c b/Inu/Src2/N12_Xilinx/xp_controller.c new file mode 100644 index 0000000..87118a6 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_controller.c @@ -0,0 +1,58 @@ +#include "xp_controller.h" + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "xerror.h" + + + + +void controller_init(T_controller *v) +{ + +} + +void controller_int13_enable(T_controller *v) +{ + if (v->read.status.bit.int13_inited) + v->write.setup.bit.use_int13 = 1; + else + { + + + } +} + +void controller_int13_disable(T_controller *v) +{ + v->write.setup.bit.use_int13 = 0; +} + +/* +T_controller_read controller_read_errors(T_controller *v) +{ + T_controller_read r; + + r.errors.all = i_ReadMemory (ADR_ERRORS_TOTAL_INFO); + r.errors_buses.all = i_ReadMemory (ADR_BUS_ERROR_READ); + + return r; +} +*/ + +int controller_read_all(T_controller *v) +{ + + v->read.errors.all = ReadMemory (ADR_ERRORS_TOTAL_INFO); + v->read.errors_buses.all = ReadMemory (ADR_BUS_ERROR_READ); + return 0; +} + + + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_controller.h b/Inu/Src2/N12_Xilinx/xp_controller.h new file mode 100644 index 0000000..2d26af4 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_controller.h @@ -0,0 +1,144 @@ +#ifndef X_CONTROLLER_H +#define X_CONTROLLER_H + +#include "x_basic_types.h" +#include "xp_id_plate_info.h" +#include "xp_plane_adr.h" + +//#include "xp_controller_fpga.h" +//#include "xp_controller_cpld.h" +//#include "x_command.h" + +/*----------------------------------------------------------------------------- +Define the types +-----------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// write reg +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { +//0 +// + union + { + UInt16 all; + struct + { + UInt16 use_int13 :1; + UInt16 reserv :15; + } bit; + + } setup; + +} T_controller_write; + +#define T_CONTROLLER_WRITE_DEFAULTS {0} +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// read reg +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + union + { + UInt16 all; + struct + { + UInt16 reserv :9; + + UInt16 errHWP_trig :1; //TODO: есть ли этот сигнал непонятно, нужна проверка прошивки!!! + UInt16 pwm_wdog :1; + UInt16 errHWP :1; + + UInt16 status_er0 :1; + UInt16 error_pbus :1; + UInt16 er0_trig :1; //er0+erHWP + UInt16 er0_out :1; + } bit; + } errors; + + union + { + UInt16 all; + struct + { + UInt16 reserv0_3 :4; + UInt16 slave_addr_error :4; // адрес слейва, по которому произошел сбой у параллельной шины. + + UInt16 count_error_pbus :4; // ParallelBus - number of errors. if errrors > failCnt then ER0 = active. (задается по адресу 200С) + UInt16 reserv12 :1; // + UInt16 err_transmit_hwp_bus :1; // HWP data transmit fail + UInt16 err_sbus :1; // serialBus_Error + UInt16 sbus_updated :1; // serialBus_DataUpdated + } bit; + } errors_buses; + + union + { + UInt16 all; + struct + { + UInt16 int13_inited :1; + UInt16 reserv0 :15; + } bit; + } status; + + +} T_controller_read; + +#define T_CONTROLLER_READ_DEFAULTS {0,0,0} +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// main struct +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct TS_controller +{ + T_component_status status; + unsigned int build; + T_controller_write write; + T_controller_read read; + + void (*init)(); // Pointer to calculation function + int (*read_all)(); // Pointer to calculation function + void (*enable_int13)(); // Pointer to calculation function + void (*disable_int13)(); // Pointer to calculation function + + +} T_controller; + +typedef T_controller *T_controller_handle; + +// command type +/*typedef enum { + controller_Command_ReadParameters = 1 + +} T_controller_Command; +*/ + +#define T_controller_DEFAULTS { component_NotReady,\ +0,\ +T_CONTROLLER_WRITE_DEFAULTS,\ +T_CONTROLLER_READ_DEFAULTS,\ +(void (*)(Uint32))controller_init,\ +(int (*)(Uint32))controller_read_all,\ +(void (*)(Uint32))controller_int13_enable,\ +(void (*)(Uint32))controller_int13_disable\ +} + + +/*------------------------------------------------------------------------------ + Prototypes for the functions +------------------------------------------------------------------------------*/ + +void controller_init(T_controller_handle); +int controller_read_all(T_controller_handle); + +//T_controller_read controller_read_errors(T_controller_handle); + +void controller_int13_enable(T_controller_handle); +void controller_int13_disable(T_controller_handle); + + +#endif diff --git a/Inu/Src2/N12_Xilinx/xp_hwp.c b/Inu/Src2/N12_Xilinx/xp_hwp.c new file mode 100644 index 0000000..37a7d0d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_hwp.c @@ -0,0 +1,1419 @@ +#include "xp_hwp.h" + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "TuneUpPlane.h" +#include "xerror.h" +#include "xp_controller.h" + + +T_controller_read r_controller; + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +/////////////////////////////////////// ////////////////////// +unsigned int calcVoltsToDACUop(unsigned int miliVolts) +{ + static unsigned int voltsOut = 0; + static float rez = 0; + static float volts = 0.0; + static float percent = 0.0; + + volts = miliVolts / 3.0; // 3 беретсЯ из коэф. усилениЯ первого ОУ по каналу Uop + percent = (float)(volts / UrefDAC); + rez = 4095.0 * percent; + voltsOut = (int)rez; // = 4095.0 * miliVolts / (UrefDAC*3.0); + + return voltsOut; +} +///////////////////////////////////////////////////////////// +unsigned int voltsForChanals(int miliVolts, unsigned int miliVoltsUop) +{ + static float volts = 0.0; + static float percent = 0.0; + static float rez = 0; + static unsigned int voltsOut = 0; + + volts = miliVoltsUop - miliVolts; // вычитаем, т.к. первый ОУ вводит инверсию входного сигнала : ACP_XX = (-1) * ACPXX + percent = (float)(volts / UrefDAC); + rez = 4095.0 * percent; + voltsOut = (int)rez; // = 4095.0 * miliVolts / UrefDAC; + + return voltsOut; +} + +///////////////////////////////////////////////////////////// +unsigned int calcVoltsToDACUtest(unsigned int miliVolts) +{ + static unsigned int voltsOut = 0; + static float rez = 0; + static float volts = 0.0; + static float percent = 0.0; + + volts = miliVolts; // выход на ОУ = 3*Uop - (Utest + ACPx) + percent = (float)(volts / UrefDAC); + rez = 4095.0 * percent; + voltsOut = (int)rez; // = 4095.0 * miliVolts / (UrefDAC*3.0); + + return voltsOut; +} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +int convert_values(T_hwp *v) +{ + int i; + v->low_setup.DACValues[0] = calcVoltsToDACUtest(v->write.U_test); + v->low_setup.DACValues[1] = calcVoltsToDACUop(v->write.U_opora); + + + + for (i=0;i<16;i++) + { + if (i == 0 || i == 1) + { + if (i==0) + v->low_setup.DACValues[2] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/ ); + if (i==1) + v->low_setup.DACValues[3] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/); + } + else + { + v->low_setup.DACValues[i*2] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/); + v->low_setup.DACValues[i*2+1] = voltsForChanals(-v->write.values[i].minus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/); + } + } + + return 0; +} + + +/////////////////////////////////////////////// +int convert_masks(T_hwp *v) +{ + + v->low_setup.mask_13to0.all = 0; + v->low_setup.mask_29to14.all = 0; + +// накладываем маски на отключенные каналы + v->write.mask.plus.all |= (v->write.use_channel.plus.all); + v->write.mask.minus.all |= (v->write.use_channel.minus.all); + +//set masks on UREF0_29 + v->low_setup.mask_13to0.bit.DACCh0 = v->write.mask.plus.bit.ch0; + v->low_setup.mask_13to0.bit.DACCh1 = v->write.mask.plus.bit.ch1; + + v->low_setup.mask_13to0.bit.DACCh2 = v->write.mask.plus.bit.ch2; + v->low_setup.mask_13to0.bit.DACCh3 = v->write.mask.minus.bit.ch2; + + v->low_setup.mask_13to0.bit.DACCh4 = v->write.mask.plus.bit.ch3; + v->low_setup.mask_13to0.bit.DACCh5 = v->write.mask.minus.bit.ch3; + + v->low_setup.mask_13to0.bit.DACCh6 = v->write.mask.plus.bit.ch4; + v->low_setup.mask_13to0.bit.DACCh7 = v->write.mask.minus.bit.ch4; + + v->low_setup.mask_13to0.bit.DACCh8 = v->write.mask.plus.bit.ch5; + v->low_setup.mask_13to0.bit.DACCh9 = v->write.mask.minus.bit.ch5; + + v->low_setup.mask_13to0.bit.DACCh10 = v->write.mask.plus.bit.ch6; + v->low_setup.mask_13to0.bit.DACCh11 = v->write.mask.minus.bit.ch6; + + v->low_setup.mask_13to0.bit.DACCh12 = v->write.mask.plus.bit.ch7; + v->low_setup.mask_13to0.bit.DACCh13 = v->write.mask.minus.bit.ch7; + + v->low_setup.mask_29to14.bit.DACCh14 = v->write.mask.plus.bit.ch8; + v->low_setup.mask_29to14.bit.DACCh15 = v->write.mask.minus.bit.ch8; + + v->low_setup.mask_29to14.bit.DACCh16 = v->write.mask.plus.bit.ch9; + v->low_setup.mask_29to14.bit.DACCh17 = v->write.mask.minus.bit.ch9; + + v->low_setup.mask_29to14.bit.DACCh18 = v->write.mask.plus.bit.ch10; + v->low_setup.mask_29to14.bit.DACCh19 = v->write.mask.minus.bit.ch10; + + v->low_setup.mask_29to14.bit.DACCh20 = v->write.mask.plus.bit.ch11; + v->low_setup.mask_29to14.bit.DACCh21 = v->write.mask.minus.bit.ch11; + + v->low_setup.mask_29to14.bit.DACCh22 = v->write.mask.plus.bit.ch12; + v->low_setup.mask_29to14.bit.DACCh23 = v->write.mask.minus.bit.ch12; + + v->low_setup.mask_29to14.bit.DACCh24 = v->write.mask.plus.bit.ch13; + v->low_setup.mask_29to14.bit.DACCh25 = v->write.mask.minus.bit.ch13; + + v->low_setup.mask_29to14.bit.DACCh26 = v->write.mask.plus.bit.ch14; + v->low_setup.mask_29to14.bit.DACCh27 = v->write.mask.minus.bit.ch14; + + v->low_setup.mask_29to14.bit.DACCh28 = v->write.mask.plus.bit.ch15; + v->low_setup.mask_29to14.bit.DACCh29 = v->write.mask.minus.bit.ch15; + + return 0; +} + + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void hwp_init(T_hwp *v) +{ + + if (v->useit == 0) + return ; + + convert_values(v); + convert_masks(v); + +#if (USE_HWP_0) + if (v->plane_address == C_hwp0_address) + v->low_setup.dac_config.bit.HWPAddress = 0; +#endif + +#if (USE_HWP_1) + if (v->plane_address == C_hwp1_address) + v->low_setup.dac_config.bit.HWPAddress = 1; +#endif + +#if (USE_HWP_2) +// if (v->plane_address == C_hwp2_address) +// v->low_setup.dac_config.bit.HWPAddress = /0/1/2; +#endif + + +#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_NORMAL) +// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp + v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL; +#endif + +#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_SLOW) +// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp + v->write.HWP_Speed = MODE_HWP_SPEED_SLOW; +#endif + +#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_AUTO) +// v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_AUTO;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp + v->write.HWP_Speed = MODE_HWP_SPEED_AUTO; +#endif + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// +int run_internal_test(T_hwp *v) +{ + int i,k,err, may_be_err_ch; + + if (v->useit == 0) + return 0; + + + + for (i=0;i<16;i++) + { + v->write.values[i].plus = HWP_DEF_LEVEL_ERROR; + v->write.values[i].minus = HWP_DEF_LEVEL_ERROR; + } +// prepare for test plus + + v->write.U_test = HWP_U_TEST_DEFINE; + v->write.U_opora = HWP_U_OPORA_DEFINE; +// + v->write.mask.minus.all = HWP_ENABLE_ALL_MASK; + v->write.mask.plus.all = HWP_ENABLE_ALL_MASK; + + convert_values(v); + convert_masks(v); + + err = 0; + err += hwp_write_all_dacs(v); + err += hwp_write_all_mask(v); + +// DELAY_US(200); + + if (err) + { + v->status = component_Error; + return 1; + } + + err += hwp_reset_error(v); + hwp_read_error(v); + + // читаем состоЯниЯ компараторов, не должно быть срабатываний! + err += hwp_read_comparators(v); + + if (v->read.errors.er0_HWP || err) + { + v->status = component_Error; + // нет сброса линии er0_hwp + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + +// start plus + for (i=0;i<16;i++) + { +// DELAY_US(200000); // + + v->write.mask.plus.all = HWP_ENABLE_ALL_MASK; + convert_masks(v); +// DELAY_US(20000);//+ + err = hwp_write_all_mask(v); + + err = 0; + v->read.test_passed.plus.all &= ~(1 << i); + + if (!(v->write.use_channel.plus.all & (1 << i))) + { + // канал исключен из опроса + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*10; // грузим очень большое число - как признак исключения + may_be_err_ch = 1; + if (v->write.test_all_channel==0) + continue; + } + else + may_be_err_ch = 0; + + + v->write.U_test = HWP_U_TEST_LEVEL_FOR_PREPARE_PLUS_TEST; + v->write.U_opora = HWP_U_OPORA_LEVEL_FOR_PREPARE_PLUS_TEST; + + for (k=0;k<16;k++) + { + if (k==i) + v->write.values[k].plus = HWP_U_LEVEL_COMP_FOR_TEST_DEFINE; // выставили уровень для теста + else + v->write.values[k].plus = HWP_DEF_LEVEL_ERROR; + } + + convert_values(v); + + err += hwp_write_all_dacs(v); +// DELAY_US(20000);//+ + err += hwp_write_all_dacs(v); +// DELAY_US(20000); // + + err += hwp_reset_error(v); +// DELAY_US(20000); + DELAY_US(2000); + + hwp_read_error(v); +// DELAY_US(20000);//+ + +/* + if (v->read.errors.er0_HWP) + { + DELAY_US(20000); + DELAY_US(20000); + DELAY_US(20000); + DELAY_US(20000); + + i_led2_on_off(1); +// err += hwp_write_all_dacs(v); +// DELAY_US(2000); // + + err += hwp_reset_error(v); + DELAY_US(20000); + DELAY_US(20000); + + i_led2_on_off(0); + + hwp_read_error(v); + DELAY_US(20000);//+ + + if (v->read.errors.er0_HWP) + { + i_led2_on_off(1); + // err += hwp_write_all_dacs(v); + // DELAY_US(2000); // + + err += hwp_reset_error(v); + DELAY_US(20000); + DELAY_US(20000); + DELAY_US(20000); + DELAY_US(20000); + + i_led2_on_off(0); + + hwp_read_error(v); + DELAY_US(20000);//+ + DELAY_US(20000); + + if (v->read.errors.er0_HWP==0) + { + DELAY_US(20000); + err += hwp_reset_error(v); + err += hwp_reset_error(v); + err += hwp_reset_error(v); + } + + } + else + { + DELAY_US(20000); + err += hwp_reset_error(v); + err += hwp_reset_error(v); + err += hwp_reset_error(v); + } + } + +*/ + + + + err += hwp_read_comparators(v); +// DELAY_US(20000);//+ + + + if (v->read.errors.er0_HWP || err) + { + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*2; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + v->status = component_Error; + // нет сброса линии er0_hwp или ошибка записи уставок в DAC + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + +// теперь пишем маски на ошибки кроме проверЯемого канала и опЯть +// читаем состоЯние компаратора, не должно быть срабатываниЯ! + + v->write.mask.plus.all = (1 << i); // clear mask + convert_masks(v); + err += hwp_write_all_mask(v); + + // читаем состоЯниЯ компараторов, не должно быть срабатываний! + err += hwp_read_comparators(v); + if (v->read.comp_s.plus.all || err) + { + // есть сработавший компаратор - это ошибка! + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*3; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + +// снимаем все маски с ошибок и читаем состоЯние компараторов, +// сработавших не должно быть! + v->write.mask.plus.all = HWP_DISABLE_ALL_MASK; // clear all mask +// v->write.mask.plus.all = (1 << i); // clear mask + if (may_be_err_ch==0) + v->write.mask.plus.all = v->write.use_channel.plus.all; + + convert_masks(v); + err += hwp_write_all_mask(v); + + // читаем состоЯниЯ компараторов, не должно быть срабатываний! + err += hwp_read_comparators(v); + if (v->read.comp_s.plus.all || err) + { + // есть сработавший компаратор - это ошибка! + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*4; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + +// проверЯем прохождение линии ERR0_HWP + v->write.mask.plus.all = (1 << i); // will wait it status + + err += hwp_read_comparators(v); + + hwp_read_error(v); + if ((v->read.errors.er0_HWP && v->read.comp_s.plus.all==0)|| err) + { + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*5; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + v->status = component_Error; + + // есть сигнал на линии er0_hwp, а не должно быть или ошибка записи масок в DAC + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + err += hwp_read_comparators(v); + + if ( (v->read.comp_s.plus.all && v->read.errors.er0_HWP==0) || err) + { +// v->status = component_Error; + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*6; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + +// ЗамерЯем времЯ срабатываниЯ компаратора + hwp_clear_delay(); + v->write.U_test = HWP_U_TEST_LEVEL_FOR_DO_PLUS_TEST; + convert_values(v); + err += hwp_write_u_test_dacs(v); + + + if (err) + { + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + v->status = component_Error; + // ошибка записи уствки в DAC U_test + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + DELAY_US(2000); + + hwp_read_error(v); + err = hwp_read_delay(v); + err += hwp_read_comparators(v); + + if (!v->read.errors.er0_HWP) + { +// v->status = component_Error; + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*7; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + // нет сигнал на линии er0_hwp, а должен быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + + if (v->read.comp_s.plus.all != v->write.mask.plus.all) + err++; + + if (v->low_setup.delay.bit.ready == 0 || err) + { + v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE; // грузим очень большое число - как признак ошибки + } + else + { + v->real_delays.plus[i] = v->low_setup.delay.bit.counter/6; + if (v->real_delays.plus[i]>=MINIMAL_TEST_TIME_ERROR_HWP && v->real_delays.plus[i]<=MAXIMAL_TEST_TIME_ERROR_HWP) + v->read.test_passed.plus.all |= (1 << i); + } + + v->write.values[i].plus = HWP_DEF_LEVEL_ERROR; + } + + +// prepare for test minus + // поднимаем сигналы на верхний уровень = 3500 mV + v->write.U_opora = 3500;//HWP_U_OPORA_DEFINE; + // и затем тест на 1500 mV + v->write.U_test = 1500;//HWP_U_TEST_DEFINE; + // в итоге получаем сигналы обратно на уровне 2000 mV. + // подаваЯ дальше тест =0V получим изменение сигнала длЯ проверки срабатываниЯ компараторов. + + v->write.mask.minus.all = HWP_ENABLE_ALL_MASK; + v->write.mask.plus.all = HWP_ENABLE_ALL_MASK; + + convert_values(v); + convert_masks(v); + + err = 0; + err += hwp_write_all_dacs(v); + err += hwp_write_all_mask(v); + + if (err) + { + v->status = component_Error; + // ошибка записи уставок в DAC или масок + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + err += hwp_reset_error(v); + DELAY_US(2000); + hwp_read_error(v); + + if (v->read.errors.er0_HWP || err) + { + v->status = component_Error; + // есть сигнал на линии er0_hwp, а не должно быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + +// minus + + for (i=2;i<16;i++) + { + v->write.mask.minus.all = HWP_ENABLE_ALL_MASK; + convert_masks(v); + err = hwp_write_all_mask(v); + + + err = 0; + v->read.test_passed.minus.all &= ~(1 << i); + + if (!(v->write.use_channel.minus.all & (1 << i))) + { + // канал исключен из опроса + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*10; // грузим очень большое число - как признак исключения + may_be_err_ch = 1; + if (v->write.test_all_channel==0) + continue; + } + else + may_be_err_ch = 0; + + + v->write.U_test = HWP_U_TEST_LEVEL_FOR_PREPARE_MINUS_TEST;//HWP_U_TEST_DEFINE; + v->write.U_opora = HWP_U_OPORA_LEVEL_FOR_PREPARE_MINUS_TEST;//HWP_U_OPORA_DEFINE; + + for (k=2;k<16;k++) + { + if (k==i) + v->write.values[k].minus = HWP_U_LEVEL_COMP_FOR_TEST_DEFINE; // выставили уровень для теста + else + v->write.values[k].minus = HWP_DEF_LEVEL_ERROR; + } + + convert_values(v); + err += hwp_write_all_dacs(v); + + err += hwp_reset_error(v); + DELAY_US(2000); + + hwp_read_error(v); + err += hwp_read_comparators(v); + if (v->read.errors.er0_HWP || err) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*2; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + v->status = component_Error; + // есть сигнал на линии er0_hwp, а не должно быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + err += hwp_read_comparators(v); + + if (v->read.comp_s.minus.all || err) + { +// v->status = component_Error; + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*3; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + +// снимаем все маски с ошибок и читаем состоЯние компараторов, +// сработавших не должно быть! + v->write.mask.minus.all = HWP_DISABLE_ALL_MASK; // clear all mask + // v->write.mask.minus.all = (1 << i); // clear mask + if (may_be_err_ch==0) + v->write.mask.minus.all = v->write.use_channel.minus.all; + + + convert_masks(v); + err += hwp_write_all_mask(v); + + // читаем состоЯниЯ компараторов, не должно быть срабатываний! + err += hwp_read_comparators(v); + if (v->read.comp_s.minus.all || err) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*4; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + // есть сработавший компаратор - это ошибка! + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + +// теперь пишем маски на ошибки кроме проверЯемого канала и опЯть +// читаем состоЯние компаратора, не должно быть срабатываниЯ! + + v->write.mask.minus.all = (1 << i); // clear mask + convert_masks(v); + err += hwp_write_all_mask(v); + + // читаем состоЯниЯ компараторов, не должно быть срабатываний! + err += hwp_read_comparators(v); + if (v->read.comp_s.minus.all || err) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*5; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + // есть сработавший компаратор - это ошибка! + // считываетсЯ состоЯние сработавшего компаратора, но нет сигнала на линии er0_hwp, + //а не должно быть или ошибка чтениЯ состоЯниЯ компараторов + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + +// проверЯем прохождение линии ERR0_HWP + + v->write.mask.minus.all = (1 << i); // will wait it status + + hwp_read_error(v); + if ((v->read.errors.er0_HWP && v->read.comp_s.minus.all==0) || err) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*6; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно + v->status = component_Error; + // есть сигнал на линии er0_hwp, а не должно быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + hwp_clear_delay(); + v->write.U_test = HWP_U_TEST_LEVEL_FOR_DO_MINUS_TEST; + convert_values(v); + err += hwp_write_u_test_dacs(v); + + if (err) + { + v->status = component_Error; + // ошибка записи уствки в DAC U_test + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + DELAY_US(2000); + + hwp_read_error(v); + err = hwp_read_delay(v); + err += hwp_read_comparators(v); + + if (!v->read.errors.er0_HWP) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*7; // грузим очень большое число - как признак ошибки + if (may_be_err_ch) + continue; // если канал и так исключен, то это правильная ошибка возможно +// v->status = component_Error; + // нет сигнал на линии er0_hwp, а должен быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + continue; +// return 1; + } + + hwp_read_delay(v); + + err += hwp_read_comparators(v); + + if (v->read.comp_s.minus.all != v->write.mask.minus.all) + err++; + + if (v->low_setup.delay.bit.ready == 0 || err) + { + v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE; // грузим очень большое число - как признак ошибки + } + else + { + v->real_delays.minus[i] = v->low_setup.delay.bit.counter/6; + if (v->real_delays.minus[i]>=MINIMAL_TEST_TIME_ERROR_HWP && v->real_delays.minus[i]<=MAXIMAL_TEST_TIME_ERROR_HWP) + v->read.test_passed.minus.all |= (1 << i); + } + v->write.values[i].minus = HWP_DEF_LEVEL_ERROR; + + } + + +// m = (v->read.test_passed.minus.all & v->write.use_channel.minus.all); +// p = (v->read.test_passed.plus.all & v->write.use_channel.plus.all); + +// if ((v->write.use_channel.minus.all != v->read.test_passed.minus.all ) || (v->write.use_channel.plus.all != v->read.test_passed.plus.all ) ) + if ((v->write.use_channel.minus.all != (v->read.test_passed.minus.all & v->write.use_channel.minus.all) ) + || (v->write.use_channel.plus.all != (v->read.test_passed.plus.all & v->write.use_channel.plus.all ) ) ) + { + v->status = component_Error; + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + +// finish + + v->write.U_test = HWP_U_TEST_DEFINE; + v->write.U_opora = HWP_U_OPORA_DEFINE; + + v->write.mask.minus.all = HWP_ENABLE_ALL_MASK; + v->write.mask.plus.all = HWP_ENABLE_ALL_MASK; + + convert_values(v); + convert_masks(v); + + err = 0; + err += hwp_write_all_dacs(v); + err += hwp_write_all_mask(v); + + if (err) + { + v->status = component_Error; + // ошибка записи уставок в DAC или масок + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + err += hwp_reset_error(v); + + hwp_read_error(v); + + if (v->read.errors.er0_HWP || err) + { + v->status = component_Error; + // есть сигнал на линии er0_hwp, а не должно быть + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + return 0; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +int hwp_internal_test(T_hwp *v) +{ + int i,err; + T_hwp_channels old_mask; + unsigned int old_U_test, old_U_opora; + T_hwp_cannel_values old_channel_values[16]; + + if (v->useit == 0) + return 0; + + if (v->status != component_Ready) + return 1; + + // проверим что уставки все правильные + for (i=0;i<16;i++) + { + if (v->write.values[i].plus>=HWP_U_OPORA_DEFINE) + { + XERROR_DEBUG_MODE_HWP_ERROR_SET_LEVEL_PROTECT; // ошибка расчета уставок защит, переполнение больше HWP_U_OPORA_DEFINE + v->status = component_Error; + return 1; + } + + if (v->write.values[i].minus>=HWP_U_OPORA_DEFINE) + { + XERROR_DEBUG_MODE_HWP_ERROR_SET_LEVEL_PROTECT; // ошибка расчета уставок защит, переполнение больше HWP_U_OPORA_DEFINE + v->status = component_Error; + return 1; + } + + } + + + + old_mask = v->write.mask; + old_U_test = v->write.U_test; + old_U_opora = v->write.U_opora; + for (i=0;i<16;i++) + old_channel_values[i] = v->write.values[i]; + + err = run_internal_test(v); + + v->write.mask = old_mask; + v->write.U_test = old_U_test; + v->write.U_opora = old_U_opora; + for (i=0;i<16;i++) + v->write.values[i] = old_channel_values[i]; + + convert_values(v); + convert_masks(v); + + err += hwp_write_all_dacs(v); + err += hwp_write_all_mask(v); + + if (err) + { +// XERROR_DEBUG_MODE_HWP_NOT_READY; + v->status = component_Error; + return 1; + } + + err += hwp_reset_error(v); + hwp_read_error(v); + + if (v->read.errors.er0_HWP || err) + { + v->status = component_Error; + // нет сброса линии er0_hwp + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + return 0; +} + +/////////////////////////////////////////////// +int hwp_read_delay(T_hwp *v) +{ + unsigned int cnt_wait_tr; + + if (v->useit == 0) + return 0; + + + v->low_setup.delay.bit.ready = 0; + cnt_wait_tr = MAX_WAIT_TEST_ERROR_HWP; + + // wait finish transmit data + while((v->low_setup.delay.bit.ready==0) && (cnt_wait_tr!=0)) + { + v->low_setup.delay.all = i_ReadMemory(ADR_HWP_TEST_TIMER); + cnt_wait_tr--; + } + + if (cnt_wait_tr==0) + return 1; // error + else + return 0; // all ok + + +} + + +/////////////////////////////////////////////// +void hwp_clear_delay(void) +{ + WriteMemory(ADR_HWP_TEST_TIMER, 0x0); +} + + +/////////////////////////////////////////////// +void hwp_autospeed_detect(T_hwp *v) +{ + int err1 = 0, err2 = 0; + + + // auto set speed? + if (v->write.HWP_Speed == MODE_HWP_SPEED_AUTO) + { + if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_NOTDETECTED) + { + v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW; +// v->write.HWP_Speed = MODE_HWP_SPEED_SLOW; + + err1 = hwp_read_comparators(v); + + v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL; +// v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL; + + err2 = hwp_read_comparators(v); + + + if (err1==0 /*&& err2==1*/) // почему-то втооая плата hwp Отвечает и на быстрой скорости!? очень странно!!! + { + v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_DETECTED; + v->write.HWP_Speed = MODE_HWP_SPEED_SLOW; + hwp_read_comparators(v); + return; + } + else + if (err1==1 && err2==0) + { + v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_DETECTED; + v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL; + hwp_read_comparators(v); + return; + } + else + { + v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_FIALED; + v->write.HWP_Speed = MODE_HWP_SPEED_SLOW; + XERROR_DEBUG_MODE_HWP_NOT_READY; + return; + + } + + } // HWP_AUTOSPEED_NOTDETECTED + } // MODE_HWP_SPEED_AUTO + else + if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_NOTDETECTED) + v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_OFF; + +} + +/////////////////////////////////////////////// + +int hwp_read_all(T_hwp *v) +{ + int err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + if (v->status == component_Error || v->status == component_NotFinded) + return 2; + +// hwp_autospeed_detect(v); + + if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_FIALED) + { + if (v->status==component_NotReady) + v->status = component_NotFinded; + else + v->status = component_Error; + + return 2; + } + + v->low_setup.dac_config.bit.HWP_Speed = v->write.HWP_Speed; + err = hwp_read_comparators(v); + err_ready = check_cds_ready_hwpbus( err, ITS_READ_BUS, &v->status_hwp_bus); + + set_status_cds(err_ready, &v->status); + + return err_ready; +} + + +/////////////////////////////////////////////// +int hwp_read_comparators(T_hwp *v) +{ + + if (v->useit == 0) + return 0; + +// send cmd to read comparators + v->low_setup.dac_config.bit.DACOrMask = 1; + v->low_setup.dac_config.bit.R_W_Direction = 1; + + v->low_setup.transmitErr = wait_hwp_transfer(v); + + v->low_setup.dac_config.bit.DACOrMask = 0; + v->low_setup.dac_config.bit.R_W_Direction = 0; + + if (v->low_setup.transmitErr) + { + // ошибка передачи по сериальной шине HWP +// if (v->write.HWP_Speed != MODE_HWP_SPEED_AUTO) +// XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + v->low_setup.comp_29to14.all = i_ReadMemory(ADR_HWP_DATA_RECEVED_0); + v->low_setup.comp_13to0.all = i_ReadMemory(ADR_HWP_DATA_RECEVED_1); + + + v->read.comp_s.plus.bit.ch0 = v->low_setup.comp_13to0.bit.DACCh0; + v->read.comp_s.plus.bit.ch1 = v->low_setup.comp_13to0.bit.DACCh1; + + v->read.comp_s.plus.bit.ch2 = v->low_setup.comp_13to0.bit.DACCh2; + v->read.comp_s.minus.bit.ch2 = v->low_setup.comp_13to0.bit.DACCh3; + + v->read.comp_s.plus.bit.ch3 = v->low_setup.comp_13to0.bit.DACCh4; + v->read.comp_s.minus.bit.ch3 = v->low_setup.comp_13to0.bit.DACCh5; + + v->read.comp_s.plus.bit.ch4 = v->low_setup.comp_13to0.bit.DACCh6; + v->read.comp_s.minus.bit.ch4 = v->low_setup.comp_13to0.bit.DACCh7; + + v->read.comp_s.plus.bit.ch5 = v->low_setup.comp_13to0.bit.DACCh8; + v->read.comp_s.minus.bit.ch5 = v->low_setup.comp_13to0.bit.DACCh9; + + v->read.comp_s.plus.bit.ch6 = v->low_setup.comp_13to0.bit.DACCh10; + v->read.comp_s.minus.bit.ch6 = v->low_setup.comp_13to0.bit.DACCh11; + + v->read.comp_s.plus.bit.ch7 = v->low_setup.comp_13to0.bit.DACCh12; + v->read.comp_s.minus.bit.ch7 = v->low_setup.comp_13to0.bit.DACCh13; + +// + v->read.comp_s.plus.bit.ch8 = v->low_setup.comp_29to14.bit.DACCh14; + v->read.comp_s.minus.bit.ch8 = v->low_setup.comp_29to14.bit.DACCh15; + + v->read.comp_s.plus.bit.ch9 = v->low_setup.comp_29to14.bit.DACCh16; + v->read.comp_s.minus.bit.ch9 = v->low_setup.comp_29to14.bit.DACCh17; + + v->read.comp_s.plus.bit.ch10 = v->low_setup.comp_29to14.bit.DACCh18; + v->read.comp_s.minus.bit.ch10 = v->low_setup.comp_29to14.bit.DACCh19; + + v->read.comp_s.plus.bit.ch11 = v->low_setup.comp_29to14.bit.DACCh20; + v->read.comp_s.minus.bit.ch11 = v->low_setup.comp_29to14.bit.DACCh21; + + v->read.comp_s.plus.bit.ch12 = v->low_setup.comp_29to14.bit.DACCh22; + v->read.comp_s.minus.bit.ch12 = v->low_setup.comp_29to14.bit.DACCh23; + + v->read.comp_s.plus.bit.ch13 = v->low_setup.comp_29to14.bit.DACCh24; + v->read.comp_s.minus.bit.ch13 = v->low_setup.comp_29to14.bit.DACCh25; + + v->read.comp_s.plus.bit.ch14 = v->low_setup.comp_29to14.bit.DACCh26; + v->read.comp_s.minus.bit.ch14 = v->low_setup.comp_29to14.bit.DACCh27; + + v->read.comp_s.plus.bit.ch15 = v->low_setup.comp_29to14.bit.DACCh28; + v->read.comp_s.minus.bit.ch15 = v->low_setup.comp_29to14.bit.DACCh29; + + return 0; + +} +/////////////////////////////////////////////// + + +int hwp_write_all_mask(T_hwp *v) +{ + if (v->useit == 0) + return 0; + + WriteMemory(ADR_HWP_DATA_RECEVED_0, v->low_setup.mask_29to14.all); + WriteMemory(ADR_HWP_DATA_RECEVED_1, v->low_setup.mask_13to0.all); + +// send cmd to write masks + v->low_setup.dac_ch.bit.DACChannelNumb = 0; + v->low_setup.dac_config.bit.DACOrMask = 1; + v->low_setup.dac_config.bit.ErrReset = 0; + v->low_setup.dac_config.bit.R_W_Direction = 0; + v->low_setup.dac_config.bit.DACNumber = 0; + + v->low_setup.transmitErr = wait_hwp_transfer(v); + + v->low_setup.dac_config.bit.DACOrMask = 0; + + if (v->low_setup.transmitErr) + { + // ошибка передачи по сериальной шине HWP + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 1; + } + + return 0; +} +/////////////////////////////////////////////// +/////////////////////////////////////////////// +int hwp_write_u_test_dacs(T_hwp *v) +{ + + if (v->useit == 0) + return 0; + + v->low_setup.dac_ch.bit.DACChannelNumb = 0; + v->low_setup.dac_config.bit.DACOrMask = 0; + v->low_setup.dac_config.bit.ErrReset = 0; + v->low_setup.dac_config.bit.R_W_Direction = 0; + v->low_setup.dac_config.bit.DACNumber = 0; + + //HWP LOAD___________________ + + v->low_setup.dac_ch.bit.DACValue = v->low_setup.DACValues[0]; + v->low_setup.dac_ch.bit.DACChannelNumb = 0; + WriteMemory(ADR_HWP_SERVICE_1, v->low_setup.dac_ch.all); + + v->low_setup.transmitErr = wait_hwp_transfer(v); + + if(v->low_setup.transmitErr) + { + v->read.errors.transmit_data = 1; + return 1; + } + + return 0; +} +/////////////////////////////////////////////// +// return - 0 - all ok +// 1 - timeout send +// 2 - error transfer +/////////////////////////////////////////////// +int wait_hwp_transfer(T_hwp *v) +{ + unsigned int cnt_wait_tr; + volatile unsigned int r_hwp; + int err; + + err = 1; + cnt_wait_tr = MAX_WAIT_TRANSMIT_TO_HWP; + + v->low_setup.dac_config.bit.transfer_finished = 0; + WriteMemory(ADR_HWP_SERVICE_0, v->low_setup.dac_config.all); + + DELAY_US(500); + + // wait finish transmit data + while(err && (cnt_wait_tr!=0)) + { + r_hwp = ReadMemory (ADR_HWP_SERVICE_0); + if (r_hwp & 0x1) + err = 0; + cnt_wait_tr--; + DELAY_US(10); + } + + if (err) + return err; + + // error transmit? + r_hwp = ReadMemory (ADR_HWP_SERVICE_0); + + if (r_hwp & 0x2) + return 2; + else + return 0; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +int hwp_write_all_dacs(T_hwp *v) +{ + int i = 0, j = 0; + + if (v->useit == 0) + return 0; + + v->low_setup.dac_ch.bit.DACChannelNumb = 0; + v->low_setup.dac_config.bit.DACOrMask = 0; + v->low_setup.dac_config.bit.ErrReset = 0; + v->low_setup.dac_config.bit.R_W_Direction = 0; + v->low_setup.dac_config.bit.DACNumber = 0; + + //HWP LOAD___________________ + + while(i < 32) + { + DELAY_US(200); + DELAY_US(200); + + v->low_setup.dac_ch.bit.DACValue = v->low_setup.DACValues[i]; + if ((i%8 == 0) && i!=0) + { + j = 0; + v->low_setup.dac_config.bit.DACNumber++; + } + v->low_setup.dac_ch.bit.DACChannelNumb = j; + WriteMemory(ADR_HWP_SERVICE_1, v->low_setup.dac_ch.all); + DELAY_US(200); + DELAY_US(200); + + v->low_setup.transmitErr = wait_hwp_transfer(v); + + if(v->low_setup.transmitErr) + { + v->read.errors.transmit_data = 0; + + if (i<16) + v->low_setup.error_transfer_to_dac_0_1.all |= (1 << i); + + if (i>=16) + v->low_setup.error_transfer_to_dac_2_3.all |= (1 << (i-16)); + + i++; + j++; + } + else + { + i++; + j++; + } + + } + + if ( (v->low_setup.error_transfer_to_dac_0_1.all == 0xffff) + && (v->low_setup.error_transfer_to_dac_2_3.all == 0xffff)) + { + v->read.errors.transmit_data = 1; + // ошибка загрузки всех DACов + // скорее всего платы просто нет! + XERROR_DEBUG_MODE_HWP_NOT_READY; + return 2; + } + + + if (v->low_setup.error_transfer_to_dac_0_1.all || v->low_setup.error_transfer_to_dac_2_3.all) + { + v->read.errors.transmit_data = 1; + // ошибка загрузки одного из DACов + XERROR_DEBUG_MODE_HWP_NOT_READY; + } + + if (v->read.errors.transmit_data) + return 1; + else + return 0; + +} + + + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + +int hwp_write_all(T_hwp *v) +{ + + int err = 0, err_ready = 0; + + if (v->useit == 0) + return 0; + + if (v->status == component_Error || v->status == component_NotFinded) + return 1; + + hwp_autospeed_detect(v); + + if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_FIALED) + { + if (v->status==component_NotReady) + v->status = component_NotFinded; + else + v->status = component_Error; + return 1; + } + + if (v->write.HWP_Speed>1) // тут или 0 или 1, если 16 то это ошибка последовательности инита + { + // ошибка последовательности инита, скорее всего плата уже была приотестирована с автоскростью, а мы ее опять сбросили в автоскорость. + XERROR_DEBUG_MODE_HWP_NOT_READY; + } + v->low_setup.dac_config.bit.HWP_Speed = v->write.HWP_Speed; + + convert_values(v); + convert_masks(v); + + err = hwp_write_all_dacs(v); + + if (err == 0) + err = hwp_write_all_mask(v); + + + if (err) + { + if (v->status==component_NotReady) + v->status = component_NotFinded; + else + v->status = component_Error; + } + else + v->status = component_Ready; + + err_ready = check_cds_ready_hwpbus( err, ITS_WRITE_BUS, &v->status_hwp_bus); + + + return 0; + +} + + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void hwp_read_error(T_hwp *v) +{ + if (v->useit == 0) + return ; + + r_controller.errors.all = i_ReadMemory (ADR_ERRORS_TOTAL_INFO); + v->read.errors.er0_HWP = r_controller.errors.bit.errHWP; + + +} +/////////////////////////////////////////////// + +int hwp_reset_error(T_hwp *v) +{ + int err; + + if (v->useit == 0) + return 0; + + if (v->status == component_NotReady || v->status == component_NotFinded) + return 1; + + + if (v->status == component_Error) + v->status = component_Started; + clear_cur_stat_hwpbus(&v->status_hwp_bus); + + + + err = 0; + v->low_setup.dac_config.bit.ErrReset = 1; + + v->low_setup.transmitErr = wait_hwp_transfer(v); + + if (v->low_setup.transmitErr) + { + // ошибка передачи по сериальной шине HWP + XERROR_DEBUG_MODE_HWP_NOT_READY; + err = 1; + } + + + DELAY_US(200); + + v->low_setup.dac_config.bit.ErrReset = 0; + + return err; +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + +void hwp_store_disable_error(T_hwp *v) +{ + if (v->useit == 0) + return ; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// +void hwp_restore_enable_error(T_hwp *v) +{ + if (v->useit == 0) + return ; + +} + +/////////////////////////////////////////////// +/////////////////////////////////////////////// + + + + + + + + + + + + + + + + + + + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_hwp.h b/Inu/Src2/N12_Xilinx/xp_hwp.h new file mode 100644 index 0000000..2fbec28 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_hwp.h @@ -0,0 +1,445 @@ +#ifndef XP_HWP_H +#define XP_HWP_H + +#include "x_basic_types.h" +#include "xp_cds_status_bus.h" +#include "xp_id_plate_info.h" + + +#define MODE_HWP_SPEED_NORMAL 0 // 0 - обычнаЯ версиЯ шины HWP (длЯ старых плат) +#define MODE_HWP_SPEED_SLOW 1 // 1 - медленнаЯ версиЯ шины HWP (длЯ новых плат) +#define MODE_HWP_SPEED_AUTO 16 // 16 - пробуем перебрать в автомате оба варианта: 0 and 1 + + +enum {HWP_AUTOSPEED_NOTDETECTED=0, + HWP_AUTOSPEED_DETECTED, + HWP_AUTOSPEED_FIALED, + HWP_AUTOSPEED_OFF +}; + +#define HWP_SPEED_VERSION_DEFINE MODE_HWP_SPEED_AUTO // MODE_HWP_SPEED_NORMAL + +#define UrefDAC 4000.0 // 4V Uref DAC - питание ЦАПа +#define HWP_U_OPORA_DEFINE 2000 // mV значение опоры = 2В - все каналы поднимаютсЯ на этот уровень +#define HWP_U_TEST_DEFINE 0 // mV канал длЯ подачи тестового сигнала = 0 + +#define HWP_ENABLE_ALL_MASK 0x0 // 0 = маска наложена = канал отключен +#define HWP_DISABLE_ALL_MASK 0xffff // 1 = маска снЯта = канал включен в работу + +#define MAX_WAIT_TRANSMIT_TO_HWP 1000 // времЯ ожиданиЯ завершениЯ конца передачи в HWP +#define MAX_WAIT_TEST_ERROR_HWP 50000 // времЯ ожиданиЯ завершениЯ срабатываниЯ тестового сигнала, измерение DELAY +#define HWP_U_LEVEL_COMP_FOR_TEST_DEFINE 1000 // mV - уставка компаратора при ловле тестового сигнала +#define HWP_MAX_ERROR_DELAY_DEFINE 1000 // это макс. число загрузитсЯ в массив определениЯ задержек каналов при ошибке в канале + +#define HWP_U_TEST_LEVEL_FOR_DO_PLUS_TEST 1100 //mV - уровень подачи U_TEST при тесте плюсовых каналов +#define HWP_U_TEST_LEVEL_FOR_DO_MINUS_TEST 0 //mV- уровень подачи U_TEST при тесте минусовых каналов + +#define HWP_U_TEST_LEVEL_FOR_PREPARE_MINUS_TEST 1500 //mV - начальный уровень U_TEST до подачи теста длЯ минусовых каналов +#define HWP_U_OPORA_LEVEL_FOR_PREPARE_MINUS_TEST 3500 //mV- начальный уровень U_OPORA до подачи теста длЯ минусовых каналов +#define HWP_U_TEST_LEVEL_FOR_PREPARE_PLUS_TEST 0 //mV - начальный уровень U_TEST до подачи теста длЯ плюсовых каналов +#define HWP_U_OPORA_LEVEL_FOR_PREPARE_PLUS_TEST 2000 //mV - начальный уровень U_OPORA до подачи теста длЯ плюсовых каналов + + +#define HWP_DEF_LEVEL_ERROR 1900 // mV - уставка компараторов по умолчанию + +/////////////////////////////// +#define MINIMAL_TEST_TIME_ERROR_HWP 15 // mks*10 минимальное ожидаемое времЯ срабатываниЯ компараторов, если получим меньше - ошибка канала +#define MAXIMAL_TEST_TIME_ERROR_HWP 200 //mks*10 максимальное ожидаемое времЯ срабатываниЯ компараторов, если получим больше - ошибка канала + +#define HWP_DEFAULT_USE_CHANNEL_PLUS 0xffff // по умолчанию использовать все каналы в плюсах +#define HWP_DEFAULT_USE_CHANNEL_MINUS 0xfffc // по умолчанию использовать все каналы в минусах, но кроме двух первых 0 и 1. эти отсутствуют. + + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// + +typedef union{ + unsigned int all; + struct{ + unsigned int DACValue:12; + unsigned int DACChannelNumb:4; + }bit; +}DAC_Channals; + +typedef union{ + unsigned int all; + struct{ + unsigned int transfer_finished:1; + unsigned int transmitErr:1; + unsigned int Reserv:7; + unsigned int HWP_Speed:1; + unsigned int DACNumber:2; + unsigned int ErrReset:1; + unsigned int DACOrMask:1; + unsigned int R_W_Direction:1; + unsigned int HWPAddress:1; + }bit; +}HWPDACConfig; + +typedef union{ + unsigned int all; + struct{ + unsigned int DACCh14:1; + unsigned int DACCh15:1; + unsigned int DACCh16:1; + unsigned int DACCh17:1; + unsigned int DACCh18:1; + unsigned int DACCh19:1; + unsigned int DACCh20:1; + unsigned int DACCh21:1; + unsigned int DACCh22:1; + unsigned int DACCh23:1; + unsigned int DACCh24:1; + unsigned int DACCh25:1; + unsigned int DACCh26:1; + unsigned int DACCh27:1; + unsigned int DACCh28:1; + unsigned int DACCh29:1; + }bit; +}MaskDACs_29to14; + +typedef union{ + unsigned int all; + struct{ + unsigned int Reserve:2; + unsigned int DACCh0:1; + unsigned int DACCh1:1; + unsigned int DACCh2:1; + unsigned int DACCh3:1; + unsigned int DACCh4:1; + unsigned int DACCh5:1; + unsigned int DACCh6:1; + unsigned int DACCh7:1; + unsigned int DACCh8:1; + unsigned int DACCh9:1; + unsigned int DACCh10:1; + unsigned int DACCh11:1; + unsigned int DACCh12:1; + unsigned int DACCh13:1; + }bit; +}MaskDACs_13to0; + +typedef struct{ + DAC_Channals dac_ch; + HWPDACConfig dac_config; + MaskDACs_29to14 mask_29to14; + MaskDACs_13to0 mask_13to0; + MaskDACs_29to14 comp_29to14; + MaskDACs_13to0 comp_13to0; + unsigned int transmitErr; + unsigned int DACValues[32]; + + union + { + UInt16 all; + struct + { + UInt16 counter :15; + UInt16 ready :1; + } bit; + } delay; + + union + { + UInt16 all; + struct + { + unsigned int DAC0Ch0:1; + unsigned int DAC0Ch1:1; + unsigned int DAC0Ch2:1; + unsigned int DAC0Ch3:1; + unsigned int DAC0Ch4:1; + unsigned int DAC0Ch5:1; + unsigned int DAC0Ch6:1; + unsigned int DAC0Ch7:1; + + unsigned int DAC1Ch0:1; + unsigned int DAC1Ch1:1; + unsigned int DAC1Ch2:1; + unsigned int DAC1Ch3:1; + unsigned int DAC1Ch4:1; + unsigned int DAC1Ch5:1; + unsigned int DAC1Ch6:1; + unsigned int DAC1Ch7:1; + } bit; + } error_transfer_to_dac_0_1; + + union + { + UInt16 all; + struct + { + unsigned int DAC2Ch0:1; + unsigned int DAC2Ch1:1; + unsigned int DAC2Ch2:1; + unsigned int DAC2Ch3:1; + unsigned int DAC2Ch4:1; + unsigned int DAC2Ch5:1; + unsigned int DAC2Ch6:1; + unsigned int DAC2Ch7:1; + + unsigned int DAC3Ch0:1; + unsigned int DAC3Ch1:1; + unsigned int DAC3Ch2:1; + unsigned int DAC3Ch3:1; + unsigned int DAC3Ch4:1; + unsigned int DAC3Ch5:1; + unsigned int DAC3Ch6:1; + unsigned int DAC3Ch7:1; + } bit; + } error_transfer_to_dac_2_3; + +}HWPstr; + + +#define HWPstr_DEFAULTS {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},0,0,0} + + + + + + +unsigned int calcVoltsToDACUop(unsigned int miliVolts); +unsigned int voltsForChanals(int miliVolts, unsigned int miliVoltsUop); +unsigned int calcVoltsToDACUtest(unsigned int miliVolts); + + +typedef struct{ + union + { + UInt16 all; + struct + { + UInt16 ch0 :1; + UInt16 ch1 :1; + UInt16 ch2 :1; + UInt16 ch3 :1; + + UInt16 ch4 :1; + UInt16 ch5 :1; + UInt16 ch6 :1; + UInt16 ch7 :1; + + UInt16 ch8 :1; + UInt16 ch9 :1; + UInt16 ch10 :1; + UInt16 ch11 :1; + + UInt16 ch12 :1; + UInt16 ch13 :1; + UInt16 ch14 :1; + UInt16 ch15 :1; + + } bit; + } minus; + + union + { + UInt16 all; + struct + { + UInt16 ch0 :1; + UInt16 ch1 :1; + UInt16 ch2 :1; + UInt16 ch3 :1; + + UInt16 ch4 :1; + UInt16 ch5 :1; + UInt16 ch6 :1; + UInt16 ch7 :1; + + UInt16 ch8 :1; + UInt16 ch9 :1; + UInt16 ch10 :1; + UInt16 ch11 :1; + + UInt16 ch12 :1; + UInt16 ch13 :1; + UInt16 ch14 :1; + UInt16 ch15 :1; + + } bit; + } plus; +} T_hwp_channels; + + + +typedef struct{ + unsigned int minus; + unsigned int plus; +} T_hwp_cannel_values; + +#define T_HWP_CANNEL_VALUES_DEFAULTS {HWP_DEF_LEVEL_ERROR, HWP_DEF_LEVEL_ERROR} + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +//write reg hwp bus +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +typedef struct{ + + T_hwp_channels mask; + T_hwp_channels use_channel; + + unsigned int U_test; + unsigned int U_opora; + + unsigned int HWP_Speed; + + unsigned int flag_detect_HWP_Speed; + unsigned int test_all_channel; // тестировать все каналы, даже с масками + + T_hwp_cannel_values values[16]; +} T_hwp_write; + + +#define T_HWP_WRITE_DEFAULTS {\ + {0xffff,0xffff},\ + { HWP_DEFAULT_USE_CHANNEL_MINUS, HWP_DEFAULT_USE_CHANNEL_PLUS },\ + HWP_U_TEST_DEFINE,HWP_U_OPORA_DEFINE,HWP_SPEED_VERSION_DEFINE, HWP_AUTOSPEED_NOTDETECTED, 0, \ + { T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, \ + T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, \ + T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, \ + T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS, T_HWP_CANNEL_VALUES_DEFAULTS\ + }\ + } + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct{ + union + { + UInt16 all; + struct + { + UInt16 counter :14; + UInt16 ready :1; + } bit; + } timer; +} T_hwp_delay; + +////////////////////////////////////////////////////////////// +typedef struct{ + unsigned int er0_HWP; + unsigned int transmit_data; + +} T_hwp_errors; + +#define T_HWP_ERRORS_DEFAULTS {0,0} +////////////////////////////////////////////////////////////// +typedef struct{ + T_hwp_errors errors; + T_hwp_channels comp_s; + T_hwp_channels test_passed; +} T_hwp_read; + + +#define T_HWP_READ_DEFAULTS {T_HWP_ERRORS_DEFAULTS,{0,0},{0,0}} +////////////////////////////////////////////////////////////// + +typedef struct{ + unsigned int plus[16]; + unsigned int minus[16]; +} T_hwp_delays; +#define T_HWP_DELAYS_DEFAULTS {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} +////////////////////////////////////////////////////////////// + + +typedef struct TS_hwp{ + UInt16 plane_address; // 0 to 15 + UInt16 useit; + T_cds_status_hwp_bus status_hwp_bus; + T_component_status status; + T_local_status local_status; + + T_hwp_delays real_delays; + + T_hwp_read read; + T_hwp_write write; + + HWPstr low_setup; + + + void (*init)(); // Pointer to calculation function + int (*internal_test)(); // Pointer to calculation function + + int (*read_all)(); // Pointer to calculation function + int (*write_all)(); // Pointer to calculation function + + int (*convert_values)(); // Pointer to calculation function + + int (*reset_error)(); // Pointer to calculation function + void (*store_disable_error)(); // Pointer to calculation function + void (*restore_enable_error)(); // Pointer to calculation function + void (*autospeed_detect)(); // Pointer to calculation function +} T_hwp; + + +typedef T_hwp *T_hwp_handle; + +//----------------------------------------------------------------------------- +// Default initalizer for object. +//----------------------------------------------------------------------------- +#define T_hwp_DEFAULTS { 0,\ + 0,\ + T_cds_status_hwp_bus_DEFAULT,\ + component_NotReady,\ + local_status_NotReady,\ + T_HWP_DELAYS_DEFAULTS,\ + T_HWP_READ_DEFAULTS,\ + T_HWP_WRITE_DEFAULTS,\ + HWPstr_DEFAULTS,\ + (void (*)(Uint32))hwp_init,\ + (int (*)(Uint32))hwp_internal_test,\ + (int (*)(Uint32))hwp_read_all,\ + (int (*)(Uint32))hwp_write_all,\ + (int (*)(Uint32))convert_values,\ + (int (*)(Uint32))hwp_reset_error,\ + (void (*)(Uint32))hwp_store_disable_error,\ + (void (*)(Uint32))hwp_restore_enable_error,\ + (void (*)(Uint32))hwp_autospeed_detect\ +} + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +void hwp_init(T_hwp_handle); + +int run_internal_test(T_hwp_handle); + +int hwp_internal_test(T_hwp_handle); +int hwp_read_all(T_hwp_handle); +int hwp_write_all(T_hwp_handle); +void hwp_autospeed_detect(T_hwp_handle); + + +int convert_values(T_hwp_handle); +int convert_masks(T_hwp_handle); + + +int hwp_reset_error(T_hwp_handle); +void hwp_store_disable_error(T_hwp_handle); +void hwp_restore_enable_error(T_hwp_handle); + +int hwp_write_all_mask(T_hwp_handle); +int hwp_write_all_dacs(T_hwp_handle); + +int hwp_read_comparators(T_hwp_handle); +int hwp_read_delay(T_hwp_handle); +void hwp_clear_delay(void); + +void hwp_read_error(T_hwp_handle); +int hwp_write_u_test_dacs(T_hwp_handle); + +int wait_hwp_transfer(T_hwp_handle); +//------------------------------------------------------------------------------ +// Return Type +//------------------------------------------------------------------------------ + +#endif diff --git a/Inu/Src2/N12_Xilinx/xp_id_plate_info.h b/Inu/Src2/N12_Xilinx/xp_id_plate_info.h new file mode 100644 index 0000000..3a9ac66 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_id_plate_info.h @@ -0,0 +1,71 @@ +#ifndef XP_ID_PLATE_INFO_H +#define XP_ID_PLATE_INFO_H + + +#define PLATE_TYPE_RESERVED 1 +#define PLATE_TYPE_IN 1 +#define PLATE_TYPE_TK_ICEBREAKER 1 +#define PLATE_TYPE_TK_BALZAM 1 +#define PLATE_TYPE_ADC 1 +#define PLATE_TYPE_TK_21300 1 +#define PLATE_TYPE_TK_23550 1 +#define PLATE_TYPE_OUT 1 +#define PLATE_TYPE_TK_EDRK 1 +#define PLATE_TYPE_ROT_SENSOR_PLATE 1 + + +typedef enum { + plate_type_undefined= 0, + plate_type_reserved, + plate_type_IN, + plate_type_TK_ICEBREAKER = 5, + plate_type_TK_BALZAM, + plate_type_ADC, + plate_type_TK_21300 = 9, + plate_type_TK_23550 = 10, + plate_type_OUT = 11, + plate_type_TK_EDRK = 13, + plate_type_ROT_SENSOR_PLATE = 14 +} T_plate_type; + +/* + +"BITS (15:11) - plate type +0 -undefined, +1-RESERVED +2-IN +3-RESERVED +4-RESERVED +5-TK-ICEBREAKER +6-TK-BALZAM +7-ADC +8-RESERVED +9-TK-21300(2 LEVEL INV STANDART_TYPE) +10-TK-23550(BALSAM Modification with optics serial interface) +11-OUT +12-RESERVED +13-TK_EDRK +14-ROT_SENSOR_PLATE +15-to 31 RESERVED + +BITS (10:5) -Version +0-UNDEFINED Переполнение допускаетсЯ, если больше 51, номер платы = остаток от делениЯ на 50 + +BITS (4:0) - Revision +0-UNDEFINED, 1- A, 2-B.. 26-Z +" +*/ + + + + + +/*------------------------------------------------------------------------------ + Plane counter +------------------------------------------------------------------------------*/ + + +#endif // end XP_ID_PLATE_INFO_H + + + diff --git a/Inu/Src2/N12_Xilinx/xp_inc_sensor.c b/Inu/Src2/N12_Xilinx/xp_inc_sensor.c new file mode 100644 index 0000000..493c106 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_inc_sensor.c @@ -0,0 +1,396 @@ +#include "xp_project.h" +#include "xp_inc_sensor.h" + +#include "xp_project.h" + + +T_inc_sensor inc_sensor = T_INC_SENSOR_DEFAULT; + +//Дискретизацию, при которой расчитываетсю длительность импульсов +#define SAMPLING_TIME_NS 1 // 16,666667ns +#define SAMPLING_TIME_MS 0 // 1,666667us +// Количество импульсов, при которых переключаетсу период дискретизации. +// Величины выбраны с "нахлёстом" что бы не было постоюнных переключений +// в районе граничных величин +#define LEVEL_SWITCH_NANOSEC 300 +#define LEVEL_SWITCH_MICROSEC 40000 + + +static void read_in_sensor_line1(T_inc_sensor *inc_s); +static void read_in_sensor_line2(T_inc_sensor *inc_s); +static void read_command_reg(T_inc_sensor *inc_s); +static void write_command_reg(T_inc_sensor *inc_s); +static void tune_sampling_time(T_inc_sensor *inc_s); +static void wait_for_registers_updated(T_inc_sensor *inc_s); +static void read_direction_in_plane(T_inc_sensor *inc_s); +static void detect_break_sensor_1_2(T_inc_sensor *inc_s); + +void sensor_set(T_inc_sensor *inc_s) +{ +/* + if(inc_s->use_sensor1 || inc_s->use_sensor2) + { + inc_s->in_plane.set(&inc_s->in_plane); + } + if(inc_s->use_angle_plane) + { + inc_s->rotation_plane.set(&inc_s->rotation_plane); + } +*/ +} + +void inc_sensor_set(T_inc_sensor *inc_s) +{ +/* + if(!inc_s->cds_in->useit) + { + return; + } + + inc_s->cds_in->write.sbus.enabled_channels.all = inc_s->write.sbus.enabled_channels.all; + inc_s->cds_in->write.sbus.first_sensor.all = inc_s->write.sbus.first_sensor_inputs.all; + inc_s->cds_in->write.sbus.second_sensor.all = inc_s->write.sbus.second_sensor_inputs.all; + // inc_s->cds_in->write_sbus(inc_s->cds_in); + write_command_reg(inc_s); +*/ + + write_command_reg(inc_s); + +} + + +void inc_sensor_read(T_inc_sensor *inc_s) +{ + if (inc_s->use_sensor1 || inc_s->use_sensor2) + { + wait_for_registers_updated(inc_s); + read_direction_in_plane(inc_s); + } + else + { + return; + } + + if (inc_s->use_sensor1) + { + inc_s->read_sensor1(inc_s); + } + + if (inc_s->use_sensor2) + { + inc_s->read_sensor2(inc_s); + } + + detect_break_sensor_1_2(inc_s); + +#ifdef AUTO_CHANGE_SAMPLING_TIME + tune_sampling_time(inc_s); +#endif +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +#define MAX_COUNT_OVERFULL_DISCRET_3 150 +#pragma CODE_SECTION(inc_sensor_read1,".fast_run"); +void inc_sensor_read1(T_inc_sensor *inc_s) +{ + read_in_sensor_line1(inc_s); + +//#if C_PROJECT_TYPE != PROJECT_BALZAM + inc_s->data.Impulses1 = inc_s->pm67regs.n_impulses_line1; + inc_s->data.Time1 = inc_s->pm67regs.time_line1/60; + //Counter`s freq is 60МГц => N/60 = time in mksec + + if (inc_s->pm67regs.n_impulses_line1>=2) + { + inc_s->data.TimeCalcFromImpulses1 = (unsigned long)inc_s->pm67regs.time_line1*1000/inc_s->pm67regs.n_impulses_line1; + inc_s->data.TimeCalcFromImpulses1 /= 60; + } + else + inc_s->data.TimeCalcFromImpulses1 = 0; + + +//#endif + //inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; + + if (inc_s->pm67regs.zero_time_line1==0) + { + if (inc_s->data.countCountZero1==MAX_COUNT_OVERFULL_DISCRET_3) + { + inc_s->data.prev_CountZero1 = inc_s->data.CountZero1 = 0; + } + else + { + inc_s->data.CountZero1 = inc_s->data.prev_CountZero1; + inc_s->data.countCountZero1++; + } + } + else + { + inc_s->data.countCountZero1 = 0; + inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; + inc_s->data.prev_CountZero1 = inc_s->pm67regs.zero_time_line1; + } + +// inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; + if (inc_s->pm67regs.one_time_line1==0) + { + if (inc_s->data.countCountOne1==MAX_COUNT_OVERFULL_DISCRET_3) + { + inc_s->data.prev_CountOne1 = inc_s->data.CountOne1 = 0; + } + else + { + inc_s->data.CountOne1 = inc_s->data.prev_CountOne1; + inc_s->data.countCountOne1++; + } + } + else + { + inc_s->data.countCountOne1 = 0; + inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; + inc_s->data.prev_CountOne1 = inc_s->pm67regs.one_time_line1; + } + + + inc_s->data.counter_freq1 = inc_s->pm67regs.read_comand_reg.bit.sampling_time1; + +// inc_s->data.direction1 = inc_s->read.pbus.direction.bit.sensor1; +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +#pragma CODE_SECTION(inc_sensor_read2,".fast_run"); +void inc_sensor_read2(T_inc_sensor *inc_s) +{ + read_in_sensor_line2(inc_s); + +//#if C_PROJECT_TYPE != PROJECT_BALZAM + inc_s->data.Impulses2 = inc_s->pm67regs.n_impulses_line2; + inc_s->data.Time2 = inc_s->pm67regs.time_line2 / 60; + //Counter`s freq is 60МГц => N/60 = time in mksec + + if (inc_s->pm67regs.n_impulses_line2>=2) + { + inc_s->data.TimeCalcFromImpulses2 = (unsigned long)inc_s->pm67regs.time_line2*1000/inc_s->pm67regs.n_impulses_line2; + inc_s->data.TimeCalcFromImpulses2 /= 60; + } + else + inc_s->data.TimeCalcFromImpulses2 = 0; + +//#endif + //inc_s->data.CountZero1 = inc_s->pm67regs.zero_time_line1; + + if (inc_s->pm67regs.zero_time_line2==0) + { + if (inc_s->data.countCountZero2==MAX_COUNT_OVERFULL_DISCRET_3) + { + inc_s->data.prev_CountZero2 = inc_s->data.CountZero2 = 0; + } + else + { + inc_s->data.CountZero2 = inc_s->data.prev_CountZero2; + inc_s->data.countCountZero2++; + } + } + else + { + inc_s->data.countCountZero2 = 0; + inc_s->data.CountZero2 = inc_s->pm67regs.zero_time_line2; + inc_s->data.prev_CountZero2 = inc_s->pm67regs.zero_time_line2; + } + +// inc_s->data.CountOne1 = inc_s->pm67regs.one_time_line1; + if (inc_s->pm67regs.one_time_line2==0) + { + if (inc_s->data.countCountOne2==MAX_COUNT_OVERFULL_DISCRET_3) + { + inc_s->data.prev_CountOne2 = inc_s->data.CountOne2 = 0; + } + else + { + inc_s->data.CountOne2 = inc_s->data.prev_CountOne2; + inc_s->data.countCountOne2++; + } + } + else + { + inc_s->data.countCountOne2 = 0; + inc_s->data.CountOne2 = inc_s->pm67regs.one_time_line2; + inc_s->data.prev_CountOne2 = inc_s->pm67regs.one_time_line2; + } + + inc_s->data.counter_freq2 = inc_s->pm67regs.read_comand_reg.bit.sampling_time2; + +// inc_s->data.direction2 = inc_s->read.pbus.direction.bit.sensor2; + +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void read_in_sensor_line1(T_inc_sensor *inc_s) +{ + + if(!inc_s->pm67regs.read_comand_reg.bit.update_registers) + { + + inc_s->pm67regs.time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD);//TODO check time when turn off + inc_s->pm67regs.n_impulses_line1 = i_ReadMemory(ADR_SENSOR_S1_COUNT_IMPULS); + + inc_s->pm67regs.zero_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_LOW_ONE_IMPULS); + inc_s->pm67regs.one_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_HIGH_ONE_IMPULS); + } + +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void read_in_sensor_line2(T_inc_sensor *inc_s) +{ + if(!inc_s->pm67regs.read_comand_reg.bit.update_registers) + { + + inc_s->pm67regs.time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD);//TODO check time when turn off + inc_s->pm67regs.n_impulses_line2 = i_ReadMemory(ADR_SENSOR_S2_COUNT_IMPULS); + + inc_s->pm67regs.zero_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_LOW_ONE_IMPULS); + inc_s->pm67regs.one_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_HIGH_ONE_IMPULS); + } +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void write_command_reg(T_inc_sensor *inc_s) +{ + WriteMemory(ADR_SENSOR_CMD, inc_s->pm67regs.write_comand_reg.all); +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void read_command_reg(T_inc_sensor *inc_s) +{ + inc_s->pm67regs.read_comand_reg.all = i_ReadMemory(ADR_SENSOR_CMD); +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void update_sensors_data_s(T_inc_sensor *inc_s) +{ + inc_s->pm67regs.write_comand_reg.bit.update_registers = 1; + write_command_reg(inc_s); +// inc_s->in_plane.write.regs.comand_reg.bit.update_registers = 0; +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void read_direction_in_plane(T_inc_sensor *inc_s) +{ +/* + inc_s->read.pbus.direction.bit.sensor1 = inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 2 ? 1 : + inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 1 ? -1 : + 0; + inc_s->read.pbus.direction.bit.sensor2 = inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 2 ? 1 : + inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 1 ? -1 : + 0; + inc_s->read.pbus.direction.bit.sens_err1 = inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 3; + inc_s->read.pbus.direction.bit.sens_err2 = inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 3; + //Direction changes not often. May be, it`s enough to read it in main cycle. +*/ +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void wait_for_registers_updated(T_inc_sensor *inc_s) +{ + int counter_in_while = 0; + read_command_reg(inc_s); + while(inc_s->pm67regs.read_comand_reg.bit.update_registers) + { + read_command_reg(inc_s); + inc_s->count_wait_for_update_registers++; + counter_in_while++; + if(counter_in_while > 1000) + { + inc_s->error_update++; + break; + } + } +} + +//////////////////////////////////////////////////////// +void detect_break_sensor_1_2(T_inc_sensor *inc_s) +{ + unsigned int f1 = (inc_s->data.CountOne1 || inc_s->data.CountZero1); + unsigned int f2 = (inc_s->data.CountOne2 || inc_s->data.CountZero2); + + + if (f1 && f2==0) + { + inc_s->break_sensor1 = 0; + inc_s->break_sensor2 = 1; + } + + if (f1==0 && f2) + { + inc_s->break_sensor1 = 1; + inc_s->break_sensor2 = 0; + } + + if ((f1==0 && f2==0) || (f1 && f2)) + { + inc_s->break_sensor1 = 0; + inc_s->break_sensor2 = 0; + } + + +} +//////////////////////////////////////////////////////// + + +void tune_sampling_time(T_inc_sensor *inc_s) +{ + +// сначала проверЯем на максимум, т.к. если датчик отвалилсЯ, то он покажет = 0. + + if( + (inc_s->use_sensor1 && inc_s->break_sensor1==0 && (inc_s->data.CountOne1 > LEVEL_SWITCH_MICROSEC) && (inc_s->data.CountZero1 > LEVEL_SWITCH_MICROSEC) ) + || (inc_s->use_sensor2 && inc_s->break_sensor2==0 && (inc_s->data.CountOne2 > LEVEL_SWITCH_MICROSEC) && (inc_s->data.CountZero2 > LEVEL_SWITCH_MICROSEC) ) + ) + { + inc_s->pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS; + return; + } + +// проверка на минимум + if( + (inc_s->use_sensor1 && inc_s->break_sensor1==0 && (inc_s->data.CountOne1 < LEVEL_SWITCH_NANOSEC) && (inc_s->data.CountZero1 < LEVEL_SWITCH_NANOSEC) ) + || (inc_s->use_sensor2 && inc_s->break_sensor2==0 && (inc_s->data.CountOne2 < LEVEL_SWITCH_NANOSEC) && (inc_s->data.CountZero2 < LEVEL_SWITCH_NANOSEC) ) + ) + { + inc_s->pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_NS; + } + +} + + + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// diff --git a/Inu/Src2/N12_Xilinx/xp_inc_sensor.h b/Inu/Src2/N12_Xilinx/xp_inc_sensor.h new file mode 100644 index 0000000..6c4684d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_inc_sensor.h @@ -0,0 +1,137 @@ +#ifndef XP_INC_SENS_H +#define XP_INC_SENS_H + +#include "x_basic_types.h" +#include "xp_cds_in.h" +#include "xp_id_plate_info.h" + + + +//Дискретизацию, при которой расчитываетсю длительность импульсов +#define SAMPLING_TIME_NS 1 // 16,666667ns +#define SAMPLING_TIME_MS 0 // 1,666667us + +//Автоматически переключает счётчик, когда количество отсчётов +// на 1 импульс становитсЯ слишком большим или маленьким. +#define AUTO_CHANGE_SAMPLING_TIME 1 +/* + Что бы прочитать данные из датчика, нужно вызвать + rotation_sensor.read_sensors(&rotation_sensor); + Результат платы IN будет в + rotation_sensor.in_plane.out.... +*/ + +///////////////////////////////////////////////////////////// +// IN plane +///////////////////////////////////////////////////////////// +// Registers with data for incremental sensor +///////////////////////////////////////////////////////////// +typedef union { + unsigned int all; + struct { + unsigned int filter_sensitivity:12; + unsigned int set_sampling_time:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time2:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time1:1; + unsigned int update_registers:1; //0 - updated + }bit; +}T_inc_sensor_comand; + +#define T_INC_COMAND_DEFAULT 0 +//////////////////////////////////////////////////////////// +typedef struct { + unsigned int time_line1; + unsigned int n_impulses_line1; + unsigned int time_line2; + unsigned int n_impulses_line2; + + unsigned int zero_time_line1; + unsigned int one_time_line1; + unsigned int zero_time_line2; + unsigned int one_time_line2; + + T_inc_sensor_comand write_comand_reg; + T_inc_sensor_comand read_comand_reg; + +} T_inc_sensor_regs; + +#define T_INC_SENSOR_REGS_DEFAULTS {0,0,0,0, 0,0,0,0, T_INC_COMAND_DEFAULT, T_INC_COMAND_DEFAULT} + + +//////////////////////////////////////////////// +////// incremental sensors with IN plane +/////////////////////////////////////////////// +typedef struct { + //UInt16 plane_address; + unsigned int count_wait_for_update_registers; + unsigned int error_update; + unsigned int use_sensor1; + unsigned int use_sensor2; + unsigned int break_sensor1; + unsigned int break_sensor2; + unsigned int break_direction; + + + struct { + + unsigned int Time1; // Sensor's survey time in mksec + unsigned int Impulses1; // Quantity of full impulses during survey time + unsigned int CountZero1; // Value of the zero-half-period counter + unsigned int CountOne1; // Value of the one-half-period counter + unsigned int prev_CountZero1; // Value of the prev zero-half-period counter + unsigned int prev_CountOne1; // Value of the prev one-half-period counter + unsigned int countCountZero1; // Value of the zero-half-period counter + unsigned int countCountOne1; // Value of the one-half-period counter + unsigned int counter_freq1; // 1 - 60MHz; 0 - 600KHz + unsigned long TimeCalcFromImpulses1; // Пересчет времени импульса из количества Impulses1 и времени Time1 + int direction1; // 1 - direct; 0 - reverse + + unsigned int Time2; // Sensor's survey time in mksec + unsigned int Impulses2; // Quantity of full impulses during survey time + unsigned int CountZero2; // Value of the zero-half-period counter + unsigned int CountOne2; // Value of the one-half-period counter + unsigned int prev_CountZero2; // Value of the prev zero-half-period counter + unsigned int prev_CountOne2; // Value of the prev one-half-period counter + unsigned int countCountZero2; // Value of the zero-half-period counter + unsigned int countCountOne2; // Value of the one-half-period counter + unsigned int counter_freq2; // 1 - 60MHz; 0 - 600KHz + unsigned long TimeCalcFromImpulses2; // Пересчет времени импульса из количества Impulses1 и времени Time1 + int direction2; // 1 - direct; 0 - reverse + } data; + + T_inc_sensor_regs pm67regs; + + void (*set)(); // Pointer to calculation function + + void (*update_sensors)(); + void (*read_sensors)(); + void (*read_sensor1)(); + void (*read_sensor2)(); + +} T_inc_sensor; + +#define T_INC_SENSOR_DEFAULT {0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0, 0,0,0,0}, \ + T_INC_SENSOR_REGS_DEFAULTS, \ + inc_sensor_set,\ + update_sensors_data_s, \ + inc_sensor_read, \ + inc_sensor_read1, \ + inc_sensor_read2 \ + } + +////////////////////////////////////////////////////////////////////////////////// +//// +////////////////////////////////////////////////////////////////////////////////// + +//Public functions + +void inc_sensor_set(T_inc_sensor *inc_s); +void inc_sensor_read1(T_inc_sensor *inc_s); +void inc_sensor_read2(T_inc_sensor *inc_s); +void inc_sensor_read(T_inc_sensor *inc_s); +void update_sensors_data_s(T_inc_sensor *inc_s); + + +extern T_inc_sensor inc_sensor; + +#endif //XP_INC_SENS_H diff --git a/Inu/Src2/N12_Xilinx/xp_incremental_sensors.c b/Inu/Src2/N12_Xilinx/xp_incremental_sensors.c new file mode 100644 index 0000000..45756f0 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_incremental_sensors.c @@ -0,0 +1,235 @@ +#include "xp_project.h" +#include "xp_incremental_sensors.h" + +#include "xp_project.h" + +#pragma DATA_SECTION(incr_sensors,".slow_vars"); +T_Incremental_sensors incr_sensors;// = T_Incremental_sensors_DEFAULT; + + + +//static void read_in_sensor_line1(T_inc_sensor *inc_s); +//static void read_in_sensor_line2(T_inc_sensor *inc_s); + +static void incremental_sensors_read_cmd_pm67(T_Incremental_sensors *inc_s); +static void incremental_sensors_write_cmd_pm67(T_Incremental_sensors *inc_s); + +static void incremental_sensors_tune_sampling_time_pm67(T_Incremental_sensors *inc_s); +static void incremental_sensors_wait_for_registers_updated_pm67(T_Incremental_sensors *inc_s); + +void incremental_sensors_read_data_pm67(T_Incremental_sensors *inc_s); +void incremental_sensors_read_pm67(T_Incremental_sensors *inc_s); + + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void incremental_sensors_write_cmd_pm67(T_Incremental_sensors *inc_s) +{ + WriteMemory(ADR_SENSOR_CMD, inc_s->write_comand_reg_pm67.all); +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void incremental_sensors_wait_for_registers_updated_pm67(T_Incremental_sensors *inc_s) +{ +// int counter_in_while = 0; + + incremental_sensors_read_cmd_pm67(inc_s); + + if (inc_s->read_comand_reg_pm67.bit.update_registers) + { + inc_s->error_alarms_counters.for_pm67.error_update_registers = 0; + } + else + while(inc_s->read_comand_reg_pm67.bit.update_registers) + { + incremental_sensors_read_cmd_pm67(inc_s); + + inc_s->error_alarms_counters.for_pm67.error_update_registers++; + inc_s->error_alarms_stat.for_pm67.error_update_registers++; + + if(inc_s->error_alarms_counters.for_pm67.error_update_registers > inc_s->config.error_alarms_timeouts.for_pm67.error_update_registers) + { + inc_s->error_alarms_status.for_pm67.error_update_registers |= 1; + break; + } + } + +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + +void incremental_sensors_read_cmd_pm67(T_Incremental_sensors *inc_s) +{ + inc_s->read_comand_reg_pm67.all = i_ReadMemory(ADR_SENSOR_CMD); +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void incremental_sensors_tune_sampling_time_pm67(T_Incremental_sensors *inc_s) +{ +// Проверка идет только на времЯ длительности импульса - времЯ единички (one_time_line) +// если меандр с датчика идельный то one_time_line будет примерно равен zero_time_line = скважность 50% + +// сначала проверЯем на максимум, т.к. если датчик отвалилсЯ, то он покажет = 0. + if((inc_s->config.for_pm67.use_s1 && (inc_s->data_from_pm67.data_from_xilinx.one_time_line1 > LEVEL_SWITCH_TUNE_TIME_PM67_MICROSEC)) + || (inc_s->config.for_pm67.use_s2 && (inc_s->data_from_pm67.data_from_xilinx.one_time_line2 > LEVEL_SWITCH_TUNE_TIME_PM67_MICROSEC))) + { + inc_s->write_comand_reg_pm67.bit.set_sampling_time = SAMPLING_TIME_PM67_MS; + return; + } + +// проверка на минимум + if((inc_s->config.for_pm67.use_s1 && (inc_s->data_from_pm67.data_from_xilinx.one_time_line1 < LEVEL_SWITCH_TUNE_TIME_PM67_NANOSEC)) + || (inc_s->config.for_pm67.use_s2 && (inc_s->data_from_pm67.data_from_xilinx.one_time_line2 < LEVEL_SWITCH_TUNE_TIME_PM67_NANOSEC))) + { + inc_s->write_comand_reg_pm67.bit.set_sampling_time = SAMPLING_TIME_PM67_NS; + } + +} + + + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void incremental_sensors_init(T_Incremental_sensors *inc_s) +{ + +/* + if(!inc_s->cds_in->useit) + { + return; + } + + inc_s->cds_in->write.sbus.enabled_channels.all = inc_s->write.sbus.enabled_channels.all; + inc_s->cds_in->write.sbus.first_sensor.all = inc_s->write.sbus.first_sensor_inputs.all; + inc_s->cds_in->write.sbus.second_sensor.all = inc_s->write.sbus.second_sensor_inputs.all; + // inc_s->cds_in->write_sbus(inc_s->cds_in); + write_command_reg(inc_s); +*/ + + incremental_sensors_write_cmd_pm67(inc_s); + +} + + +void incremental_sensors_read_pm67(T_Incremental_sensors *inc_s) +{ + if(inc_s->config.for_pm67.use_s1 || inc_s->config.for_pm67.use_s2) + { + incremental_sensors_wait_for_registers_updated_pm67(inc_s); + } + else + { + return; + } + + incremental_sensors_read_data_pm67(inc_s); + + if (inc_s->config.for_pm67.ModeAutoDiscret != MODE_OFF_SPEED_TUNE_PM67) + incremental_sensors_tune_sampling_time_pm67(inc_s); + +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + +void incremental_sensors_read_data_pm67(T_Incremental_sensors *inc_s) +{ + if (inc_s->read_comand_reg_pm67.bit.update_registers) + { + inc_s->data_from_pm67.data_from_xilinx.time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD); + inc_s->data_from_pm67.data_from_xilinx.n_impulses_line1 = i_ReadMemory(ADR_SENSOR_S1_COUNT_IMPULS); + + inc_s->data_from_pm67.data_from_xilinx.zero_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_LOW_ONE_IMPULS); + inc_s->data_from_pm67.data_from_xilinx.one_time_line1 = i_ReadMemory(ADR_SENSOR_S1_T_PERIOD_HIGH_ONE_IMPULS); + + inc_s->data_from_pm67.data_from_xilinx.time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD); + inc_s->data_from_pm67.data_from_xilinx.n_impulses_line2 = i_ReadMemory(ADR_SENSOR_S2_COUNT_IMPULS); + + inc_s->data_from_pm67.data_from_xilinx.zero_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_LOW_ONE_IMPULS); + inc_s->data_from_pm67.data_from_xilinx.one_time_line2 = i_ReadMemory(ADR_SENSOR_S2_T_PERIOD_HIGH_ONE_IMPULS); + } + + + if (inc_s->config.for_pm67.use_s1) + { + inc_s->data_from_pm67.raw_solo.time_s1 = inc_s->data_from_pm67.data_from_xilinx.one_time_line1 + inc_s->data_from_pm67.data_from_xilinx.zero_time_line1; + + //Counter`s freq is 60МГц => N/60 = time in mksec + if (inc_s->data_from_pm67.data_from_xilinx.n_impulses_line1>2) + inc_s->data_from_pm67.raw_pulses.TimeCalcS1 = inc_s->data_from_pm67.data_from_xilinx.time_line1*1000/inc_s->data_from_pm67.data_from_xilinx.n_impulses_line1/60; + else + inc_s->data_from_pm67.raw_pulses.TimeCalcS1 = 0; + } + else + { + inc_s->data_from_pm67.raw_solo.time_s1 = 0; + inc_s->data_from_pm67.raw_pulses.TimeCalcS1 = 0; + } + + if (inc_s->config.for_pm67.use_s2) + { + inc_s->data_from_pm67.raw_solo.time_s2 = inc_s->data_from_pm67.data_from_xilinx.one_time_line2 + inc_s->data_from_pm67.data_from_xilinx.zero_time_line2; + + //Counter`s freq is 60МГц => N/60 = time in mksec + if (inc_s->data_from_pm67.data_from_xilinx.n_impulses_line2>2) + inc_s->data_from_pm67.raw_pulses.TimeCalcS2 = inc_s->data_from_pm67.data_from_xilinx.time_line2*1000/inc_s->data_from_pm67.data_from_xilinx.n_impulses_line2/60; + else + inc_s->data_from_pm67.raw_pulses.TimeCalcS2 = 0; + } + else + { + inc_s->data_from_pm67.raw_solo.time_s2 = 0; + inc_s->data_from_pm67.raw_pulses.TimeCalcS2 = 0; + } + +// inc_s->data.counter_freq1 = inc_s->pm67regs.read_comand_reg.bit.sampling_time1; +// inc_s->data.direction1 = inc_s->read.pbus.direction.bit.sensor1; +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + +void incremental_sensors_update_sensors_data_pm67(T_Incremental_sensors *inc_s) +{ + inc_s->write_comand_reg_pm67.bit.update_registers = 1; + incremental_sensors_write_cmd_pm67(inc_s); +// inc_s->in_plane.write.regs.comand_reg.bit.update_registers = 0; +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// + + +void read_direction_in_plane(T_Incremental_sensors *inc_s) +{ +/* + inc_s->read.pbus.direction.bit.sensor1 = inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 2 ? 1 : + inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 1 ? -1 : + 0; + inc_s->read.pbus.direction.bit.sensor2 = inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 2 ? 1 : + inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 1 ? -1 : + 0; + inc_s->read.pbus.direction.bit.sens_err1 = inc_s->cds_in->read.pbus.direction_in.bit.dir0 == 3; + inc_s->read.pbus.direction.bit.sens_err2 = inc_s->cds_in->read.pbus.direction_in.bit.dir1 == 3; + //Direction changes not often. May be, it`s enough to read it in main cycle. +*/ +} + +//////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// diff --git a/Inu/Src2/N12_Xilinx/xp_incremental_sensors.h b/Inu/Src2/N12_Xilinx/xp_incremental_sensors.h new file mode 100644 index 0000000..67ce10d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_incremental_sensors.h @@ -0,0 +1,531 @@ +#ifndef XP_INCREMENTAL_SENSORS_H +#define XP_INCREMENTAL_SENSORS_H + +#include "IQmathLib.h" +#include "x_basic_types.h" +#include "xp_cds_in.h" +#include "xp_id_plate_info.h" + +#define INCREMENTAL_SENSOR_SAMPLING_TIME_PM67_MS 0 +#define INCREMENTAL_SENSOR_SAMPLING_TIME_PM67_NS 1 + +#define LEVEL_SWITCH_TUNE_TIME_PM67_MICROSEC 40000 +#define LEVEL_SWITCH_TUNE_TIME_PM67_NANOSEC 300 + +//Дискретизацию, при которой расчитываетсЯ длительность импульсов +#define SAMPLING_TIME_PM67_NS 1 // 16,666667ns +#define SAMPLING_TIME_PM67_MS 0 // 1,666667us + +#define MODE_OFF_SPEED_TUNE_PM67 0 +#define MODE_AUTO_SPEED_TUNE_PM67 1 +#define MODE_LOW_SPEED_TUNE_PM67 2 +#define MODE_FAST_SPEED_TUNE_PM67 3 + + +///////////////////////////////////////////////////////////// +// IN plane +///////////////////////////////////////////////////////////// +// Registers with data for incremental sensor +///////////////////////////////////////////////////////////// +typedef union { + unsigned int all; + struct { + unsigned int filter_sensitivity:12; + unsigned int set_sampling_time:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time2:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time1:1; + unsigned int update_registers:1; //0 - updated + }bit; +}T_inc_sensor_comand_pm67; + +#define T_INC_COMAND_DEFAULT 0 +//////////////////////////////////////////////////////////// +typedef struct { + unsigned int time_line1; + unsigned int n_impulses_line1; + unsigned int time_line2; + unsigned int n_impulses_line2; + + unsigned int zero_time_line1; + unsigned int one_time_line1; + unsigned int zero_time_line2; + unsigned int one_time_line2; + +} T_inc_sensor_data_pm67; + +#define T_INC_SENSOR_DATA_PM67 {0,0,0,0,0,0,0,0} +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// + + + + +typedef struct +{ +//////////////////////// +//////////////////////// +// data_from_pm67 // +//////////////////////// + struct { + + struct { + _iq time_s1; + _iq time_s2; + } raw_solo; + + struct { + _iq before_time_s1; + _iq before_time_s2; + + _iq time_s1; + _iq time_s2; + } filter_solo; + + struct { + _iq TimeCalcS1; + _iq TimeCalcS2; + + } raw_pulses; + + struct { + _iq before_ch0_s1; + _iq before_ch1_s1; + + _iq before_ch0_s2; + _iq before_ch1_s2; + + _iq ch0_s1; + _iq ch1_s1; + + _iq ch0_s2; + _iq ch1_s2; + + } filter_pulses; + + +// _iq solo_time_s1; +// _iq solo_time_s2; + +// _iq pulses_time_s1; +// _iq pulses_time_s2; + + T_inc_sensor_data_pm67 data_from_xilinx; + + } data_from_pm67; + +//////////////////////// +//////////////////////// +//////////////////////// +// data_from_in // +//////////////////////// + + struct { + + struct { + _iq speed_s1; + _iq speed_90_s1; + + _iq speed_s2; + _iq speed_90_s2; + + _iq zero_point_s1; + _iq zero_point_rising_s1; + _iq zero_point_falling_s1; + + _iq zero_point_s2; + _iq zero_point_rising_s2; + _iq zero_point_falling_s2; + + unsigned int dir_s1; + unsigned int dir_s2; + + _iq angle_f_s1; + _iq angle_r_s1; + + _iq angle_f_s2; + _iq angle_r_s2; + + int status_s1; + int status_s2; + + } raw; + + struct { + + _iq speed_s1; + _iq speed_90_s1; + + _iq speed_s2; + _iq speed_90_s2; + + _iq zero_point_s1; + _iq zero_point_rising_s1; + _iq zero_point_falling_s1; + + _iq zero_point_s2; + _iq zero_point_rising_s2; + _iq zero_point_falling_s2; + + + unsigned int dir_s1; + unsigned int dir_s2; + + } filter; + + +//////////////////////// + + } data_from_in; + +//////////////////////// +//////////////////////// +/// config // +//////////////////////// + struct { + + struct { + _iq KoefNormMS; + _iq KoefNormNS; + _iq koefW; + long long KoefNormImpulses; + unsigned int use; + unsigned int use_s1; + unsigned int use_s2; + unsigned int ModeAutoDiscret;// 1 -auto, 2-low speed, 3- fast speed + unsigned int time_level_discret_1to0; + unsigned int time_level_discret_0to1; + + } for_pm67; +//////////////////////// + + struct { + + unsigned int use_it; + unsigned int use_sp6; + struct { + unsigned int ModeAutoDiscret;// 1 -auto, 2-low speed, 3- fast speed + unsigned int use_s1; + unsigned int use_s2; + unsigned int decoder_zero_level; + unsigned int decoder_max_level; + unsigned int max_count_overfull_discret; + unsigned int max_count_zero_discret; + unsigned int time_level_discret_1to0; + unsigned int time_level_discret_0to1; + long long KoefNorm_discret0; + long long KoefNorm_discret1; + } incremental_sensors; + + struct { + long long KoefNorm_angle; + unsigned int use_z1; + unsigned int use_z2; + } zero_sensors; + } for_in; + +//////////////////////// + + struct { + unsigned int count_impulses; // one oborots + } inc_sensor; + +//////////////////////// + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int error_s1_s2; + unsigned int error_update_registers; + } for_pm67; + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int alarm_dir1; + unsigned int alarm_dir2; + unsigned int error_s1_s2; + unsigned int error_dir1_dir2; + } incremental_sensors; + + struct { + unsigned int alarm_z1; + unsigned int alarm_z2; + unsigned int error_z1_z2; + } zero_sensors; + } for_in; + + } error_alarms_timeouts; + +//////////////////////// + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int error_s1_s2; + } for_pm67; + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int alarm_dir1; + unsigned int alarm_dir2; + unsigned int error_s1_s2; + unsigned int error_dir1_dir2; + } incremental_sensors; + + struct { + unsigned int alarm_z1; + unsigned int alarm_z2; + unsigned int error_z1_z2; + } zero_sensors; + } for_in; + + } error_alarms_on_off; + + } config; +//////////////////////// +// error_alarms_stat +//////////////////////// + + struct { + + struct { + unsigned int error_update_registers; + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int error_s1_s2; + } for_pm67; + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int alarm_dir1; + unsigned int alarm_dir2; + unsigned int error_s1_s2; + unsigned int error_dir1_dir2; + } incremental_sensors; + + struct { + unsigned int alarm_z1; + unsigned int alarm_z2; + unsigned int error_z1_z2; + } zero_sensors; + } for_in; + + } error_alarms_stat; +//////////////////////// +// error_alarms_status +//////////////////////// + struct { + + struct { + unsigned int error_update_registers; + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int error_s1_s2; + } for_pm67; + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int alarm_dir1; + unsigned int alarm_dir2; + unsigned int error_s1_s2; + unsigned int error_dir1_dir2; + } incremental_sensors; + + struct { + unsigned int alarm_z1; + unsigned int alarm_z2; + unsigned int error_z1_z2; + } zero_sensors; + } for_in; + + } error_alarms_status; +//////////////////////// +//////////////////////// +// error_alarms_counters +//////////////////////// + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int error_s1_s2; + unsigned int error_update_registers; + } for_pm67; + + struct { + + struct { + unsigned int alarm_s1; + unsigned int alarm_s2; + unsigned int alarm_dir1; + unsigned int alarm_dir2; + unsigned int error_s1_s2; + unsigned int error_dir1_dir2; + } incremental_sensors; + + struct { + unsigned int alarm_z1; + unsigned int alarm_z2; + unsigned int error_z1_z2; + } zero_sensors; + } for_in; + + } error_alarms_counters; + +//////////////////////// + T_inc_sensor_comand_pm67 write_comand_reg_pm67; + T_inc_sensor_comand_pm67 read_comand_reg_pm67; + +//////////////////////// + +//////////////////////// +//////////////////////// + +// int RotorDirection1; +// int RotorDirection2; + + void (*init)(); // Pointer to calculation function + +// void (*request_data_from_sensors_pm67)(); + void (*read_sensors_pm67)(); + void (*read_sensors_in)(); + void (*update_regs_sensors_pm67)(); +// void (*update_regs_sensors_in)(); + +} T_Incremental_sensors; + +#define T_Incremental_sensors_DEFAULT {} + +void incremental_sensors_init(T_Incremental_sensors *inc_s); +void incremental_sensors_read_pm67(T_Incremental_sensors *inc_s); +void incremental_sensors_update_sensors_data_pm67(T_Incremental_sensors *inc_s); + +/* + + + + + + +//Автоматически переключает счётчик, когда количество отсчётов +// на 1 импульс становитсЯ слишком большим или маленьким. +#define AUTO_CHANGE_SAMPLING_TIME 1 +// +// Что бы прочитать данные из датчика, нужно вызвать +// rotation_sensor.read_sensors(&rotation_sensor); +// Результат платы IN будет в +// rotation_sensor.in_plane.out.... +// + +///////////////////////////////////////////////////////////// +// IN plane +///////////////////////////////////////////////////////////// +// Registers with data for incremental sensor +///////////////////////////////////////////////////////////// +typedef union { + unsigned int all; + struct { + unsigned int filter_sensitivity:12; + unsigned int set_sampling_time:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time2:1; //(1)-16,666667ns (0)-1,666667us + unsigned int sampling_time1:1; + unsigned int update_registers:1; //0 - updated + }bit; +}T_inc_sensor_comand; + +#define T_INC_COMAND_DEFAULT 0 +//////////////////////////////////////////////////////////// +typedef struct { + unsigned int time_line1; + unsigned int n_impulses_line1; + unsigned int time_line2; + unsigned int n_impulses_line2; + + unsigned int zero_time_line1; + unsigned int one_time_line1; + unsigned int zero_time_line2; + unsigned int one_time_line2; + + T_inc_sensor_comand write_comand_reg; + T_inc_sensor_comand read_comand_reg; + +} T_inc_sensor_regs; + +#define T_INC_SENSOR_REGS_DEFAULTS {0,0,0,0, 0,0,0,0, T_INC_COMAND_DEFAULT, T_INC_COMAND_DEFAULT} + + +//////////////////////////////////////////////// +////// incremental sensors with IN plane +/////////////////////////////////////////////// +typedef struct { + //UInt16 plane_address; + unsigned int count_wait_for_update_registers; + unsigned int error_update; + unsigned int use_sensor1; + unsigned int use_sensor2; + + struct { + + unsigned int Time1; // Sensor's survey time in mksec + unsigned int Impulses1; // Quantity of full impulses during survey time + unsigned int CountZero1; // Value of the zero-half-period counter + unsigned int CountOne1; // Value of the one-half-period counter + unsigned int counter_freq1; // 1 - 60MHz; 0 - 600KHz + unsigned long TimeCalcFromImpulses1; // Пересчет времени импульса из количества Impulses1 и времени Time1 + int direction1; // 1 - direct; 0 - reverse + + unsigned int Time2; // Sensor's survey time in mksec + unsigned int Impulses2; // Quantity of full impulses during survey time + unsigned int CountZero2; // Value of the zero-half-period counter + unsigned int CountOne2; // Value of the one-half-period counter + unsigned int counter_freq2; // 1 - 60MHz; 0 - 600KHz + unsigned long TimeCalcFromImpulses2; // Пересчет времени импульса из количества Impulses1 и времени Time1 + int direction2; // 1 - direct; 0 - reverse + } data; + + T_inc_sensor_regs pm67regs; + + void (*set)(); // Pointer to calculation function + + void (*update_sensors)(); + void (*read_sensors)(); + void (*read_sensor1)(); + void (*read_sensor2)(); + +} T_inc_sensor; + +#define T_INC_SENSOR_DEFAULT {0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, T_INC_SENSOR_REGS_DEFAULTS, inc_sensor_set, update_sensors_data, inc_sensor_read, inc_sensor_read1, inc_sensor_read2} + +////////////////////////////////////////////////////////////////////////////////// +//// +////////////////////////////////////////////////////////////////////////////////// + +//Public functions + +void inc_sensor_set(T_inc_sensor *inc_s); +void inc_sensor_read1(T_inc_sensor *inc_s); +void inc_sensor_read2(T_inc_sensor *inc_s); +void inc_sensor_read(T_inc_sensor *inc_s); +void update_sensors_data(T_inc_sensor *inc_s); + + +extern T_inc_sensor inc_sensor; +*/ + + +#endif //XP_INCREMENTAL_SENSORS_H diff --git a/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.c b/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.c new file mode 100644 index 0000000..c1b7769 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.c @@ -0,0 +1,98 @@ + +#include "xp_optlink_tms2tms.h" + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Functions.h" +#include "xp_controller.h" + + + +X_OPTLINK_TMS2TMS x_optlink_tms2tms_project = X_OPTLINK_TMS2TMS_DEFAULTS; + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// + + +void x_optlink_tms2tms_read_data(X_OPTLINK_TMS2TMS *v) +{ + volatile unsigned int d_wr; + +// v->data_receiver[0] = ReadMemory(ADR_FIRST_FREE + v->adr_table_read); +// d_wr = v->; +// WriteMemory(ADR_PARALLEL_BUS_CMD, d_wr); + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + + +void x_optlink_tms2tms_write_data(X_OPTLINK_TMS2TMS *v) +{ + volatile unsigned int d_wr; + + +// d_wr = v->; +// WriteMemory(ADR_PARALLEL_BUS_CMD, d_wr); + +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +void x_optlink_tms2tms_init(X_OPTLINK_TMS2TMS *v) +{ + if (v->flags.bit.init) + return; +/* + v->setup.size_table = 0;//-1; + v->setup.tms_adr_data_start = ADR_FIRST_FREE; + v->setup.tms_adr_data_finish = ADR_LAST_FREE; + v->setup.setup_error_count_read = MAX_WAIT_ERROR_PARALLEL_BUS; + + v->flags.all = 0; + + v->slave_addr = 0; + v->reg_addr = 0; + v->error_count_start = 0; + v->count_read = 0; + + v->stop(v); + + v->flags.bit.init = 1; +*/ +} +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////// +/* +#pragma CODE_SECTION(x_parallel_bus_read_one_data,".fast_run"); +void x_parallel_bus_read_one_data(X_OPTLINK_TMS2TMS *v) +{ +// read data from parallel bus +// v->data_table_read = ReadMemory(ADR_FIRST_FREE + v->adr_table_read); +} +*/ +//////////////////////////////////////////////////////////////// + + + + diff --git a/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.h b/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.h new file mode 100644 index 0000000..227d3b6 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_optlink_tms2tms.h @@ -0,0 +1,110 @@ +#ifndef _X_OPTLINK_TMS2TMS_H +#define _X_OPTLINK_TMS2TMS_H + +#define MAX_WAIT_ERROR_X_OPTLINK_TMS2TMS 1 // макс. кол-во ожиданиЯ чтениЯ с шины + + +typedef union { + unsigned int all; + struct { + unsigned int id:8; + unsigned int count_receiver_error:4; + unsigned int trans_busy:1; // приемник на внешней плате ТК + unsigned int trans_error:1; // приемник на внешней плате ТК + unsigned int receiver_busy :1; // приемник на текущей плате ТК + unsigned int receiver_error:1; // приемник на текущей плате ТК + } bit; +} X_OPTLINK_TMS2TMS_status; + + + + +typedef union { + unsigned int all; + struct { + unsigned int started:1; + unsigned int error:1; + unsigned int cmd_start:1; + unsigned int count_error:4; + unsigned int slave_addr_error:4; + unsigned int init:1; + unsigned int was_started:1; + unsigned int rezerv:3; + + } bit; +} X_OPTLINK_TMS2TMS_flags; + + + + +typedef struct { + unsigned int setup_error_count_read; // настройка макс кол-ва попыток чтений с шины до возникновениЯ ошибки +} X_OPTLINK_TMS2TMS_Setup; + + + +typedef struct { X_OPTLINK_TMS2TMS_flags flags; // флаги + X_OPTLINK_TMS2TMS_Setup setup; // настройка + + X_OPTLINK_TMS2TMS_status status1; // статус1 + X_OPTLINK_TMS2TMS_status status2; // статус2 + + unsigned int data_receiver[4]; // данные принЯтые - 0..3 + unsigned int data_send[4]; // данные длЯ передачи - 0..3 + + unsigned int error_count_send; // общее колич-во ошибок передачи + unsigned int error_count_receiver; // общее колич-во ошибок передачи + unsigned int count_receiver; // общее колич-во чтениЯ + unsigned int count_send; // общее колич-во передачи + +// unsigned int error_count_write; // общее колич-во ошибок записи +// unsigned int error_count_hold; // общее колич-во ошибок захвата шины + + void (*init)(); // Pointer to init function + void (*read_data)(); // Pointer to init function + void (*write_data)(); // Pointer to init function + }X_OPTLINK_TMS2TMS; + + + +/* +// таймаут ожиданиЯ выполениЯ команды +#define TIME_OUT_SERIAL_BUS 10000 // max 65535 + + +#define CMD_SERIAL_BUS_READ 0x0000 +#define CMD_SERIAL_BUS_WRITE 0x8000 + +*/ + + +typedef X_OPTLINK_TMS2TMS *X_OPTLINK_TMS2TMS_handle; + +#define X_OPTLINK_TMS2TMS_DEFAULTS { 0, \ + 0,0,\ + MAX_WAIT_ERROR_X_OPTLINK_TMS2TMS, \ + {0,0,0,0},\ + {0,0,0,0},\ + 0, \ + 0, \ + 0, \ + 0, \ + (void (*)(Uint32))x_optlink_tms2tms_init,\ + (void (*)(Uint32))x_optlink_tms2tms_read_data,\ + (void (*)(Uint32))x_optlink_tms2tms_write_data\ + } + + +void x_optlink_tms2tms_init(X_OPTLINK_TMS2TMS_handle); + +void x_optlink_tms2tms_read_data(X_OPTLINK_TMS2TMS_handle); + +void x_optlink_tms2tms_write_data(X_OPTLINK_TMS2TMS_handle); + + +extern X_OPTLINK_TMS2TMS x_optlink_tms2tms_project; + + + +#endif // end _X_OPTLINK_TMS2TMS_H + diff --git a/Inu/Src2/N12_Xilinx/xp_plane_adr.h b/Inu/Src2/N12_Xilinx/xp_plane_adr.h new file mode 100644 index 0000000..04b6e96 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_plane_adr.h @@ -0,0 +1,175 @@ +#ifndef XP_PLANE_ADR_H +#define XP_PLANE_ADR_H +#include +/*------------------------------------------------------------------------------ + Plane counter +------------------------------------------------------------------------------*/ +///////////////////////////////////////////////////////////////////// +// Настройка номеров плат, для каждого проекта разной может быть +///////////////////////////////////////////////////////////////////// + +#if (C_PROJECT_TYPE==PROJECT_10510) + +// Подсчет количества плат + +// +// для выставления авторазмер массивов в project. +// но т.к. границу массива сложно проверить, возвращаем в максим. возможный размер +// память кушает, но лучше так возможно +// +#define MAX_C_CDS_TK_NUMBER 6 // max 8 +#define MAX_C_CDS_IN_NUMBER 3 // max 3 +#define MAX_C_CDS_OUT_NUMBER 3 // max 3 +#define MAX_C_ADC_NUMBER 3 // max 3 +#define MAX_C_HWP_NUMBER 3 // max 3 +#define MAX_C_CDS_RS_NUMBER 1 // max 1 + +/*------------------------------------------------------------------------------ + Plane address +------------------------------------------------------------------------------*/ +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_controller_address 1 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_cds_in0_address 2 +#define C_cds_in1_address 3 +#define C_cds_in2_address 4 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_cds_tk0_address 6 +#define C_cds_tk1_address 7 +#define C_cds_tk2_address 8 +#define C_cds_tk3_address 9 +#define C_cds_tk4_address 10 +#define C_cds_tk5_address 11 +//#define C_cds_tk6_address 19 +//#define C_cds_tk7_address 20 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_cds_out0_address 5 +#define C_cds_out1_address 21 +#define C_cds_out2_address 22 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_adc0_address 13 +#define C_adc1_address 15 +#define C_adc2_address 12 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_cds_rs0_address 14 +//////////////////////////////////////////////////////////////////////////////////////////////////// +#define C_hwp0_address 16 +#define C_hwp1_address 17 +#define C_hwp2_address 18 +#else +///////////////////////////////////////// +// это для остальных проектов +//////////////////////////////////////// + +// Подсчет количества плат + +// +// для выставления авторазмер массивов в project. +// но т.к. границу массива сложно проверить, возвращаем в максим. возможный размер +// память кушает, но лучше так возможно +// +#define MAX_C_CDS_TK_NUMBER 4 // max 8 +#define MAX_C_CDS_IN_NUMBER 3 // max 3 +#define MAX_C_CDS_OUT_NUMBER 3 // max 3 +#define MAX_C_ADC_NUMBER 2 // max 3 +#define MAX_C_HWP_NUMBER 2 // max 3 +#define MAX_C_CDS_RS_NUMBER 1 // max 1 + +/*------------------------------------------------------------------------------ + Plane number address +------------------------------------------------------------------------------*/ +#define C_controller_address 1 + +#define C_cds_in0_address 2 +#define C_cds_in1_address 3 +#define C_cds_in2_address 4 + +#define C_cds_tk0_address 5 +#define C_cds_tk1_address 6 +#define C_cds_tk2_address 9 +#define C_cds_tk3_address 10 + +//#define C_cds_tk4_address 255 +//#define C_cds_tk5_address 255 +//#define C_cds_tk6_address 255 +//#define C_cds_tk7_address 255 + +#define C_cds_out0_address 11 +#define C_cds_out1_address 12 +#define C_cds_out2_address 13 + +#define C_adc0_address 7 +#define C_adc1_address 8 +//#define C_adc2_address 255 + +#define C_cds_rs0_address 14 + +#define C_hwp0_address 16 +#define C_hwp1_address 17 +//#define C_hwp2_address 255 + +#endif + + + +/////////////////////////////////////////////////////// +// тут авто расчет +// количество плат может вдруг превысить MAX_C_CDS_TK_NUMBER (см.выше) +// тогда производим авто пересчет +/////////////////////////////////////////////////////// + + + + + +#if (MAX_COUNT_PLATES_CDS_TK>MAX_C_CDS_TK_NUMBER) +#define C_cds_tk_number MAX_COUNT_PLATES_CDS_TK // max 8 +#else +#define C_cds_tk_number MAX_COUNT_PLATES_CDS_TK // max 8 +#endif + + +#if (MAX_COUNT_PLATES_ADC>MAX_C_ADC_NUMBER) +#define C_adc_number MAX_C_ADC_NUMBER // max 3 +#else +#define C_adc_number MAX_COUNT_PLATES_ADC // max 3 +#endif + +#if (MAX_COUNT_PLATES_HWP>=MAX_C_HWP_NUMBER) +#define C_hwp_number MAX_C_HWP_NUMBER // max 3 +#else +#define C_hwp_number MAX_COUNT_PLATES_HWP // max 3 +#endif + + +#if (MAX_COUNT_PLATES_OUT>MAX_C_CDS_OUT_NUMBER) +#define C_cds_out_number MAX_C_CDS_OUT_NUMBER // max 3 +#else +#define C_cds_out_number MAX_COUNT_PLATES_OUT // max 3 +#endif + + +#if (MAX_COUNT_PLATES_IN>MAX_C_CDS_IN_NUMBER) +#define C_cds_in_number MAX_C_CDS_IN_NUMBER // max 3 +#else +#define C_cds_in_number MAX_COUNT_PLATES_IN // max 3 +#endif + + +#if (MAX_COUNT_PLATES_CDS_RS>MAX_C_CDS_RS_NUMBER) +#define C_cds_rs_number MAX_COUNT_PLATES_CDS_RS // max 1 +#else +#define C_cds_rs_number MAX_COUNT_PLATES_CDS_RS // max 1 +#endif + + + +//#define C_cds_in_number MAX_C_CDS_IN_NUMBER // max 3 +//#define C_cds_out_number MAX_C_CDS_OUT_NUMBER // max 3 +//#define C_cds_rs_number MAX_C_CDS_RS_NUMBER // max 1 + + +#endif // end XP_PLANE_ADR_H + + + diff --git a/Inu/Src2/N12_Xilinx/xp_project.c b/Inu/Src2/N12_Xilinx/xp_project.c new file mode 100644 index 0000000..b9be18e --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_project.c @@ -0,0 +1,1986 @@ + +#include "xp_project.h" + +#include "x_serial_bus.h" +#include "xp_controller.h" + + +#pragma DATA_SECTION(project,".fast_vars"); +//#pragma DATA_SECTION(project,".slow_vars"); +T_project project = PROJECT_DEFAULTS; + + +void project_enable_all_interrupts(void) +{ + + + KickDog(); + EDIS; + EnableInterrupts(); + ERTM;// Enable Global realtime interrupt DBGM + KickDog(); +} + +void project_disable_all_interrupts(void) +{ +// KickDog(); + DINT; +// DRTM; +// DisableInterrupts(); + +} + + + +////////////////////////////////////////////////////////////////////// +// Обновление суммарного статуса готовности и ошибок по всем платам +////////////////////////////////////////////////////////////////////// +#define get_status_err_plates(p) ((p.local_status & ( local_status_Error)) != 0) +void project_update_all_err_status_plates(void) +{ + +#if(C_cds_tk_number>=1) + project.all_status_plates.tk0 = project.cds_tk[0].status; + project.all_err_plates.errors_tk.bit.tk0 = get_status_err_plates(project.cds_tk[0]);// ((project.cds_tk[0].status & ( component_Error | component_ErrorSBus)) != 0) ;// (project.cds_tk[0].status == component_Error); +#endif + +#if(C_cds_tk_number>=2) + project.all_status_plates.tk1 = project.cds_tk[1].status; + project.all_err_plates.errors_tk.bit.tk1 = get_status_err_plates(project.cds_tk[1]);// == component_Error); +#endif + +#if(C_cds_tk_number>=3) + project.all_status_plates.tk2 = project.cds_tk[2].status; + project.all_err_plates.errors_tk.bit.tk2 = get_status_err_plates(project.cds_tk[2]);// == component_Error); +#endif + +#if(C_cds_tk_number>=4) + project.all_status_plates.tk3 = project.cds_tk[3].status; + project.all_err_plates.errors_tk.bit.tk3 = get_status_err_plates(project.cds_tk[3]);// == component_Error); +#endif + +#if(C_cds_tk_number>=5) + project.all_status_plates.tk4 = project.cds_tk[3].status; + project.all_err_plates.errors_tk.bit.tk4 = get_status_err_plates(project.cds_tk[4]);// == component_Error); +#endif +#if(C_cds_tk_number>=6) + project.all_status_plates.tk5 = project.cds_tk[3].status; + project.all_err_plates.errors_tk.bit.tk5 = get_status_err_plates(project.cds_tk[5]);// == component_Error); +#endif +#if(C_cds_tk_number>=7) + project.all_status_plates.tk6 = project.cds_tk[3].status; + project.all_err_plates.errors_tk.bit.tk6 = get_status_err_plates(project.cds_tk[6]);// == component_Error); +#endif +#if(C_cds_tk_number>=8) + project.all_status_plates.tk7 = project.cds_tk[3].status; + project.all_err_plates.errors_tk.bit.tk7 = get_status_err_plates(project.cds_tk[7]);// == component_Error); +#endif + + +#if(C_cds_out_number>=1) + project.all_status_plates.out0 = project.cds_out[0].status; + project.all_err_plates.errors.bit.out0 = get_status_err_plates(project.cds_out[0]);// == component_Error); +#endif + +#if(C_cds_out_number>=2) + project.all_status_plates.out1 = project.cds_out[1].status; + project.all_err_plates.errors.bit.out1 = get_status_err_plates(project.cds_out[1]);// == component_Error); +#endif + +#if(C_cds_out_number>=3) + project.all_status_plates.out2 = project.cds_out[2].status; + project.all_err_plates.errors.bit.out2 = get_status_err_plates(project.cds_out[2]);// == component_Error); +#endif + + + +#if(C_cds_in_number>=1) + project.all_status_plates.in0 = project.cds_in[0].status; + project.all_err_plates.errors.bit.in0 = get_status_err_plates(project.cds_in[0]);// == component_Error); +#endif + +#if(C_cds_in_number>=2) + project.all_status_plates.in1 = project.cds_in[1].status; + project.all_err_plates.errors.bit.in1 = get_status_err_plates(project.cds_in[1]);// == component_Error); +#endif + +#if(C_cds_in_number>=3) + project.all_status_plates.in2 = project.cds_in[2].status; + project.all_err_plates.errors.bit.in2 = get_status_err_plates(project.cds_in[2]);// == component_Error); +#endif + + +#if(C_adc_number>=1) + project.all_status_plates.adc0 = project.adc[0].status; + project.all_err_plates.errors.bit.adc0 = get_status_err_plates(project.adc[0]);// == component_Error); +#endif +#if(C_adc_number>=2) + project.all_status_plates.adc1 = project.adc[1].status; + project.all_err_plates.errors.bit.adc1 = get_status_err_plates(project.adc[1]);// == component_Error); +#endif +#if(C_adc_number>=3) + project.all_status_plates.adc2 = project.adc[2].status; + project.all_err_plates.errors.bit.adc2 = get_status_err_plates(project.adc[2]);// == component_Error); +#endif + + +#if(C_hwp_number>=1) + project.all_status_plates.hwp0 = project.hwp[0].status; + project.all_err_plates.errors.bit.hwp0 = get_status_err_plates(project.hwp[0]);// == component_Error); +#endif +#if(C_hwp_number>=2) + project.all_status_plates.hwp1 = project.hwp[1].status; + project.all_err_plates.errors.bit.hwp1 = get_status_err_plates(project.hwp[1]);// == component_Error); +#endif +#if(C_hwp_number>=3) + project.all_status_plates.hwp2 = project.hwp[2].status; + project.all_err_plates.errors.bit.hwp2 = get_status_err_plates(project.hwp[2]);// == component_Error); +#endif + +#if(C_cds_rs_number>=1) + project.all_status_plates.rs0 = project.cds_rs[0].status; + project.all_err_plates.errors.bit.rs0 = get_status_err_plates(project.cds_rs[0]);// == component_Error); +#endif + +} + + +void project_all_test_hwp(void) +{ + + if (project.controller.status != component_Ready) + return; + + project.write_all_hwp(); + +#if(C_hwp_number>=1) + project.hwp[0].internal_test(&project.hwp[0]); +#endif +#if(C_hwp_number>=2) + project.hwp[1].internal_test(&project.hwp[1]); +#endif +#if(C_hwp_number>=3) + project.hwp[2].internal_test(&project.hwp[2]); +#endif + + +} + + +//////////////////////////////////////////////////////////////// +// грузим настройки в перифер. платы и HWP +//////////////////////////////////////////////////////////////// +void project_load_cfg_to_plates(void) +{ + + if (project.controller.status != component_Ready) + return; + + project.write_all_hwp(); + project.write_all_sbus(); + +} + + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// + + + + +void project_clear(void) +{ +// UInt16 i; +// for(i=0;i=1) + project.adc[0].plane_address = C_adc0_address; +#endif +#if(C_adc_number>=2) + project.adc[1].plane_address = C_adc1_address; +#endif +#if(C_adc_number>=3) + project.adc[2].plane_address = C_adc2_address; +#endif + +#if(C_cds_in_number>=1) + project.cds_in[0].plane_address = C_cds_in0_address; +#endif +#if(C_cds_in_number>=2) + project.cds_in[1].plane_address = C_cds_in1_address; +#endif +#if(C_cds_in_number>=3) + project.cds_in[2].plane_address = C_cds_in2_address; +#endif + +#if(C_cds_out_number>=1) + project.cds_out[0].plane_address = C_cds_out0_address; +#endif +#if(C_cds_out_number>=2) + project.cds_out[1].plane_address = C_cds_out1_address; +#endif +#if(C_cds_out_number>=3) + project.cds_out[2].plane_address = C_cds_out2_address; +#endif + + + +#if(C_cds_tk_number>=1) +#if(C_cds_tk0_address<1) +#error "неправильно определено C_cds_tk0_address в xp_plane_adr.h" +#endif + project.cds_tk[0].plane_address = C_cds_tk0_address; +#endif +#if(C_cds_tk_number>=2) +#if(C_cds_tk1_address<1) +#error "неправильно определено C_cds_tk1_address в xp_plane_adr.h" +#endif + project.cds_tk[1].plane_address = C_cds_tk1_address; +#endif +#if(C_cds_tk_number>=3) +#if(C_cds_tk2_address<1) +#error "неправильно определено C_cds_tk2_address в xp_plane_adr.h" +#endif + project.cds_tk[2].plane_address = C_cds_tk2_address; +#endif +#if(C_cds_tk_number>=4) +#if(C_cds_tk3_address<1) +#error "неправильно определено C_cds_tk3_address в xp_plane_adr.h" +#endif + project.cds_tk[3].plane_address = C_cds_tk3_address; +#endif +#if(C_cds_tk_number>=5) +#if(C_cds_tk4_address<1) +#error "неправильно определено C_cds_tk4_address в xp_plane_adr.h" +#endif + project.cds_tk[4].plane_address = C_cds_tk4_address; +#endif +#if(C_cds_tk_number>=6) +#if(C_cds_tk5_address<1) +#error "неправильно определено C_cds_tk5_address в xp_plane_adr.h" +#endif + project.cds_tk[5].plane_address = C_cds_tk5_address; +#endif +#if(C_cds_tk_number>=7) +#if(C_cds_tk6_address<1) +#error "неправильно определено C_cds_tk6_address в xp_plane_adr.h" +#endif + project.cds_tk[6].plane_address = C_cds_tk6_address; +#endif +#if(C_cds_tk_number>=8) +#if(C_cds_tk7_address<1) +#error "неправильно определено C_cds_tk7_address в xp_plane_adr.h" +#endif + project.cds_tk[7].plane_address = C_cds_tk7_address; +#endif + + + + + +#if(C_cds_rs_number>=1) + project.cds_rs[0].plane_address = C_cds_rs0_address; +#endif + +#if(C_hwp_number>=1) + project.hwp[0].plane_address = C_hwp0_address; + project.hwp[0].init(&project.hwp[0]); +#endif +#if(C_hwp_number>=2) + project.hwp[1].plane_address = C_hwp1_address; + project.hwp[1].init(&project.hwp[1]); +#endif +#if(C_hwp_number>=3) + project.hwp[2].plane_address = C_hwp2_address; + project.hwp[2].init(&project.hwp[2]); +#endif + + + if (project.controller.status == component_Ready) + project.controller.build = i_ReadMemory(ADR_CONTROLLER_BUILD); + else + project.controller.build = 0xffff; + + + + project.inited = 1; // есть инициализациЯ данных! + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +// инициализациЯ структур длЯ перифер. плат +/////////////////////////////////////////////////////////// +void project_run_init_all_plates(void) +{ + if (project.controller.status == component_Ready) + { + + #if(C_adc_number>=1) + if (project.adc[0].status & (component_Started | component_Ready | component_Error )) + project.adc[0].init(&project.adc[0]); + #endif + #if(C_adc_number>=2) + if (project.adc[1].status & (component_Started | component_Ready | component_Error )) + project.adc[1].init(&project.adc[1]); + #endif + #if(C_adc_number>=3) + if (project.adc[2].status & (component_Started | component_Ready | component_Error )) + project.adc[2].init(&project.adc[2]); + #endif + + #if(C_cds_tk_number>=1) + if (project.cds_tk[0].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[0].init(&project.cds_tk[0]); + #endif + #if(C_cds_tk_number>=2) + if (project.cds_tk[1].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[1].init(&project.cds_tk[1]); + #endif + #if(C_cds_tk_number>=3) + if (project.cds_tk[2].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[2].init(&project.cds_tk[2]); + #endif + #if(C_cds_tk_number>=4) + if (project.cds_tk[3].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[3].init(&project.cds_tk[3]); + #endif + #if(C_cds_tk_number>=5) + if (project.cds_tk[4].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[4].init(&project.cds_tk[4]); + #endif + #if(C_cds_tk_number>=6) + if (project.cds_tk[5].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[5].init(&project.cds_tk[5]); + #endif + #if(C_cds_tk_number>=7) + if (project.cds_tk[6].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[6].init(&project.cds_tk[6]); + #endif + #if(C_cds_tk_number>=8) + if (project.cds_tk[7].status & (component_Started | component_Ready | component_Error )) + project.cds_tk[7].init(&project.cds_tk[7]); + #endif + +#if(C_cds_in_number>=1) + if (project.cds_in[0].status & (component_Started | component_Ready | component_Error )) + project.cds_in[0].init(&project.cds_in[0]); +#endif +#if(C_cds_in_number>=2) + if (project.cds_in[1].status & (component_Started | component_Ready | component_Error )) + project.cds_in[1].init(&project.cds_in[1]); +#endif +#if(C_cds_in_number>=3) + if (project.cds_in[2].status & (component_Started | component_Ready | component_Error )) + project.cds_in[2].init(&project.cds_in[2]); +#endif + +#if(C_cds_out_number>=1) + if (project.cds_out[0].status & (component_Started | component_Ready | component_Error )) + project.cds_out[0].init(&project.cds_out[0]); +#endif +#if(C_cds_out_number>=2) + if (project.cds_out[1].status & (component_Started | component_Ready | component_Error )) + project.cds_out[1].init(&project.cds_out[1]); +#endif +#if(C_cds_out_number>=3) + if (project.cds_out[2].status & (component_Started | component_Ready | component_Error )) + project.cds_out[2].init(&project.cds_out[2]); +#endif + +#if(C_cds_rs_number>=1) + if (project.cds_rs[0].status & (component_Started | component_Ready | component_Error )) + project.cds_rs[0].init(&project.cds_rs[0]); +#endif + + project_all_test_hwp(); +// +//#if(C_hwp_number>=1) +// if (project.hwp[0].status & (component_Started | component_Ready | component_Error )) +// project.hwp[0].init(&project.hwp[0]); +//#endif +//#if(C_hwp_number>=2) +// if (project.hwp[1].status & (component_Started | component_Ready | component_Error )) +// project.hwp[1].init(&project.hwp[1]); +//#endif +//#if(C_hwp_number>=3) +// if (project.hwp[2].status & (component_Started | component_Ready | component_Error )) +// project.hwp[2].init(&project.hwp[2]); +//#endif + } + + + + +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +#define set_local_status(p) p.local_status = p.read.sbus.lock_status_error.all ? local_status_Error : local_status_Ok +#define set_local_status_hwp(p) p.local_status = (p.read.comp_s.minus.all || p.read.comp_s.plus.all) ? local_status_Error : local_status_Ok +/////////////////////////////////////////////////////////// + +void project_read_all_sbus(void) +{ + + if (project.controller.status == component_Ready) + { +#if(C_adc_number>=1) + if (project.adc[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus)) + { + project.adc[0].read_sbus(&project.adc[0]); + set_local_status(project.adc[0]); + } +#endif +#if(C_adc_number>=2) + if (project.adc[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.adc[1].read_sbus(&project.adc[1]); + set_local_status(project.adc[1]); + } + +#endif +#if(C_adc_number>=3) + if (project.adc[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.adc[2].read_sbus(&project.adc[2]); + set_local_status(project.adc[2]); + } +#endif + +#if(C_cds_tk_number>=1) + if (project.cds_tk[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[0].read_sbus(&project.cds_tk[0]); + set_local_status(project.cds_tk[0]); + } +#endif +#if(C_cds_tk_number>=2) + if (project.cds_tk[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[1].read_sbus(&project.cds_tk[1]); + set_local_status(project.cds_tk[1]); + } +#endif +#if(C_cds_tk_number>=3) + if (project.cds_tk[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[2].read_sbus(&project.cds_tk[2]); + set_local_status(project.cds_tk[2]); + } +#endif +#if(C_cds_tk_number>=4) + if (project.cds_tk[3].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[3].read_sbus(&project.cds_tk[3]); + set_local_status(project.cds_tk[3]); + } +#endif +#if(C_cds_tk_number>=5) + if (project.cds_tk[4].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[4].read_sbus(&project.cds_tk[4]); + set_local_status(project.cds_tk[4]); + } +#endif +#if(C_cds_tk_number>=6) + if (project.cds_tk[5].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[5].read_sbus(&project.cds_tk[5]); + set_local_status(project.cds_tk[5]); + } +#endif +#if(C_cds_tk_number>=7) + if (project.cds_tk[6].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[6].read_sbus(&project.cds_tk[6]); + set_local_status(project.cds_tk[6]); + } +#endif +#if(C_cds_tk_number>=8) + if (project.cds_tk[7].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_tk[7].read_sbus(&project.cds_tk[7]); + set_local_status(project.cds_tk[7]); + } +#endif + +#if(C_cds_in_number>=1) + if (project.cds_in[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_in[0].read_sbus(&project.cds_in[0]); + set_local_status(project.cds_in[0]); + } +#endif +#if(C_cds_in_number>=2) + if (project.cds_in[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_in[1].read_sbus(&project.cds_in[1]); + set_local_status(project.cds_in[1]); + } +#endif +#if(C_cds_in_number>=3) + if (project.cds_in[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_in[2].read_sbus(&project.cds_in[2]); + set_local_status(project.cds_in[2]); + } +#endif + +#if(C_cds_rs_number>=1) + if (project.cds_rs[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_rs[0].read_sbus(&project.cds_rs[0]); + // set_local_status(project.cds_rs[0]); + } +#endif + +#if(C_cds_out_number>=1) + if (project.cds_out[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_out[0].read_sbus(&project.cds_out[0]); + set_local_status(project.cds_out[0]); + } +#endif +#if(C_cds_out_number>=2) + if (project.cds_out[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_out[1].read_sbus(&project.cds_out[1]); + set_local_status(project.cds_out[1]); + } +#endif +#if(C_cds_out_number>=3) + if (project.cds_out[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { + project.cds_out[2].read_sbus(&project.cds_out[2]); + set_local_status(project.cds_out[2]); + } +#endif + +#if(C_hwp_number>=1) + if (project.hwp[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { +// project.cds_out[0].read_sbus(&project.cds_out[0]); + set_local_status_hwp(project.hwp[0]); + } +#endif +#if(C_hwp_number>=2) + if (project.hwp[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { +// project.cds_out[0].read_sbus(&project.cds_out[0]); + set_local_status_hwp(project.hwp[1]); + } +#endif +#if(C_hwp_number>=3) + if (project.hwp[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + { +// project.cds_out[0].read_sbus(&project.cds_out[0]); + set_local_status_hwp(project.hwp[2]); + } +#endif + + + + project_update_all_err_status_plates(); + + } + +} + + +void project_read_all_pbus(void) +{ + + if (project.controller.status == component_Ready) + { + + x_parallel_bus_project.read_status(&x_parallel_bus_project); + +#if(C_adc_number>=1) + project.adc[0].read_pbus(&project.adc[0]); +#endif +#if(C_adc_number>=2) + project.adc[1].read_pbus(&project.adc[1]); +#endif +#if(C_adc_number>=3) + project.adc[2].read_pbus(&project.adc[2]); +#endif + +#if(C_cds_tk_number>=1) + project.cds_tk[0].read_pbus(&project.cds_tk[0]); +#endif +#if(C_cds_tk_number>=2) + project.cds_tk[1].read_pbus(&project.cds_tk[1]); +#endif +#if(C_cds_tk_number>=3) + project.cds_tk[2].read_pbus(&project.cds_tk[2]); +#endif +#if(C_cds_tk_number>=4) + project.cds_tk[3].read_pbus(&project.cds_tk[3]); +#endif +#if(C_cds_tk_number>=5) + project.cds_tk[4].read_pbus(&project.cds_tk[4]); +#endif +#if(C_cds_tk_number>=6) + project.cds_tk[5].read_pbus(&project.cds_tk[5]); +#endif +#if(C_cds_tk_number>=7) + project.cds_tk[6].read_pbus(&project.cds_tk[6]); +#endif +#if(C_cds_tk_number>=8) + project.cds_tk[7].read_pbus(&project.cds_tk[7]); +#endif + + +#if(C_cds_in_number>=1) + project.cds_in[0].read_pbus(&project.cds_in[0]); +#endif +#if(C_cds_in_number>=2) + project.cds_in[1].read_pbus(&project.cds_in[1]); +#endif +#if(C_cds_in_number>=3) + project.cds_in[2].read_pbus(&project.cds_in[2]); +#endif + +#if(C_cds_rs_number>=1) + project.cds_rs[0].read_pbus(&project.cds_rs[0]); +#endif + +#if(C_cds_out_number>=1) + project.cds_out[0].read_pbus(&project.cds_out[0]); +#endif +#if(C_cds_out_number>=2) + project.cds_out[1].read_pbus(&project.cds_out[1]); +#endif +#if(C_cds_out_number>=3) + project.cds_out[2].read_pbus(&project.cds_out[2]); +#endif + + } + +} + +///////////////////////////////////////////////////// +// записываем настройки в платы по сериаль. каналу +///////////////////////////////////////////////////// +void project_write_all_sbus(void) +{ + + if (project.controller.status == component_Ready) + { + +#if(C_adc_number>=1) + if (project.adc[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.adc[0].write_sbus(&project.adc[0]); +#endif +#if(C_adc_number>=2) + if (project.adc[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.adc[1].write_sbus(&project.adc[1]); +#endif +#if(C_adc_number>=3) + if (project.adc[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.adc[2].write_sbus(&project.adc[2]); +#endif + +#if(C_cds_tk_number>=1) + if (project.cds_tk[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[0].write_sbus(&project.cds_tk[0]); +#endif +#if(C_cds_tk_number>=2) + if (project.cds_tk[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[1].write_sbus(&project.cds_tk[1]); +#endif +#if(C_cds_tk_number>=3) + if (project.cds_tk[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[2].write_sbus(&project.cds_tk[2]); +#endif +#if(C_cds_tk_number>=4) + if (project.cds_tk[3].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[3].write_sbus(&project.cds_tk[3]); +#endif +#if(C_cds_tk_number>=5) + if (project.cds_tk[4].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[4].write_sbus(&project.cds_tk[4]); +#endif +#if(C_cds_tk_number>=6) + if (project.cds_tk[5].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[5].write_sbus(&project.cds_tk[5]); +#endif +#if(C_cds_tk_number>=7) + if (project.cds_tk[6].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[6].write_sbus(&project.cds_tk[6]); +#endif +#if(C_cds_tk_number>=8) + if (project.cds_tk[7].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_tk[7].write_sbus(&project.cds_tk[7]); +#endif + +#if(C_cds_in_number>=1) + if (project.cds_in[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_in[0].write_sbus(&project.cds_in[0]); +#endif +#if(C_cds_in_number>=2) + if (project.cds_in[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_in[1].write_sbus(&project.cds_in[1]); +#endif +#if(C_cds_in_number>=3) + if (project.cds_in[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_in[2].write_sbus(&project.cds_in[2]); +#endif + +#if(C_cds_rs_number>=1) + if (project.cds_rs[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_rs[0].write_sbus(&project.cds_rs[0]); +#endif + +#if(C_cds_out_number>=1) + if (project.cds_out[0].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_out[0].write_sbus(&project.cds_out[0]); +#endif +#if(C_cds_out_number>=2) + if (project.cds_out[1].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_out[1].write_sbus(&project.cds_out[1]); +#endif +#if(C_cds_out_number>=3) + if (project.cds_out[2].status & (component_Started | component_Ready | component_Error | component_ErrorSBus )) + project.cds_out[2].write_sbus(&project.cds_out[2]); +#endif + + project_update_all_err_status_plates(); + + } + + + +} + +///////////////////////////////////////////////////// +// записываем настройки в HWP платы по hwp каналу +///////////////////////////////////////////////////// +void project_write_all_hwp(void) +{ + + if (project.controller.status == component_Ready) + { +#if(C_hwp_number>=1) + project.hwp[0].write_all(&project.hwp[0]); +#endif +#if(C_hwp_number>=2) + project.hwp[1].write_all(&project.hwp[1]); +#endif +#if(C_hwp_number>=3) + project.hwp[2].write_all(&project.hwp[2]); +#endif + + } + +} + + + + +///////////////////////////////////////////////////// +// чтение из HWP платы по hwp каналу +///////////////////////////////////////////////////// +void project_read_all_hwp(void) +{ + + if (project.controller.status == component_Ready) + { +#if(C_hwp_number>=1) + project.hwp[0].read_all(&project.hwp[0]); +#endif +#if(C_hwp_number>=2) + project.hwp[1].read_all(&project.hwp[1]); +#endif +#if(C_hwp_number>=3) + project.hwp[2].read_all(&project.hwp[2]); +#endif + } + +} + + +///////////////////////////////////////////////////// +// чтение из HWP платы по hwp каналу +///////////////////////////////////////////////////// +void project_autospeed_all_hwp(void) +{ + + if (project.controller.status == component_Ready) + { +#if(C_hwp_number>=1) + project.hwp[0].autospeed_detect(&project.hwp[0]); +#endif +#if(C_hwp_number>=2) + project.hwp[1].autospeed_detect(&project.hwp[1]); +#endif +#if(C_hwp_number>=3) + project.hwp[2].autospeed_detect(&project.hwp[2]); +#endif + } + +} + + + + + +#define PAUSE_WAIT_SBUS 10000 +#define MAX_COUNT_ERR_READ_SBUS 1100 //2000 запас по времени 2х относительно нормального периода загрузки всей корзины +#define MAX_COUNT_ERR_READ_SBUS_2 600 //2000 запас по времени 2х относительно нормального периода загрузки всей корзины + +#define MAX_COUNT_OR_READ_SBUS 20//200 + + +////////////////////////////////////////////////////////////// +// ожидание загрузки и старта перефир. плат. +// если flag_reset == 1 то не даем ошибку при ожидании плат +// enable_find_all_plates = 1 разрешаем поиск отключенных плат по USE_???? +////////////////////////////////////////////////////////////// +unsigned int project_wait_load_all_cds(int flag_reset) +{ + unsigned long counterErr = 0; + unsigned int counterOk = 0, err; + unsigned int i,count_find_plat; + unsigned int old_status_max_read_error = 0; + unsigned int prev_count_one_find_plat = 0, count_one_find_plat = 0; + unsigned int max_count_err_read_sbus = MAX_COUNT_ERR_READ_SBUS; +// unsigned int erReg, rd; +/* + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i= max_count_err_read_sbus) + { + if (flag_reset == 0) + xerror(xserial_bus_er_ID(2), (void *)0); + err = 1; + break; + } + // test ok read - stable? + if (counterOk >= MAX_COUNT_OR_READ_SBUS) + { + err = 0; + // all ok! + break; + } + if (count_find_plat == 0) // nothing find! + { + err = 0; + // all ok! + break; + } + + + } + + +// clear statistics on serial bus + + x_serial_bus_project.clear_stat(&x_serial_bus_project); + +/////////////////////////////////////// +//ADC +#if(C_adc_number>=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i=1) + for (i=0;i + +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_GlobalPrototypes.h" +#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" +#include "DSP281x_Ev.h" // DSP281x Examples Include File +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "Spartan2E_Functions.h" +#include "TuneUpPlane.h" +#include "x_int13.h" +#include "x_parallel_bus.h" +#include "x_serial_bus.h" +#include "xerror.h" +#include "xp_adc.h" +#include "xp_cds_in.h" +#include "xp_cds_out.h" +#include "xp_cds_rs.h" +#include "xp_cds_tk.h" +#include "xp_controller.h" +#include "xp_hwp.h" +#include "xp_inc_sensor.h" +#include "xPeriphSP6_loader.h" + + +#define WITH_RESET_ALL_PLATES 1 +#define WITHOUT_RESET_ALL_PLATES 0 +#define WITHOUT_RESET_ALL_PLATES_NO_STOP_ERROR 2 +#define WITH_RESET_ALL_PLATES_NO_STOP_ERROR 3 + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +// Суммарные статусы по всем платам +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +typedef struct { + +#if(C_cds_tk_number>=1) + T_component_status tk0; +#endif +#if(C_cds_tk_number>=2) + T_component_status tk1; +#endif +#if(C_cds_tk_number>=3) + T_component_status tk2; +#endif +#if(C_cds_tk_number>=4) + T_component_status tk3; +#endif +#if(C_cds_tk_number>=5) + T_component_status tk4; +#endif +#if(C_cds_tk_number>=6) + T_component_status tk5; +#endif +#if(C_cds_tk_number>=7) + T_component_status tk6; +#endif +#if(C_cds_tk_number>=8) + T_component_status tk7; +#endif + +#if(C_adc_number>=1) + T_component_status adc0; +#endif +#if(C_adc_number>=2) + T_component_status adc1; +#endif +#if(C_adc_number>=3) + T_component_status adc2; +#endif + +#if(C_cds_in_number>=1) + T_component_status in0; +#endif +#if(C_cds_in_number>=2) + T_component_status in1; +#endif + +#if(C_cds_in_number>=3) + T_component_status in2; +#endif +#if(C_cds_out_number>=1) + T_component_status out0; +#endif +#if(C_cds_out_number>=2) + T_component_status out1; +#endif +#if(C_cds_out_number>=3) + T_component_status out2; +#endif + +#if (C_cds_rs_number>=1) + T_component_status rs0; +#endif + +#if(C_hwp_number>=1) + T_component_status hwp0; +#endif +#if(C_hwp_number>=2) + T_component_status hwp1; +#endif +#if(C_hwp_number>=3) + T_component_status hwp2; +#endif + +} T_project_all_status_plates; + + + + + + + +typedef struct { + union + { + UInt16 all; + struct + { +#if(C_cds_tk_number>=1) + UInt16 tk0 :1; +#endif +#if(C_cds_tk_number>=2) + UInt16 tk1 :1; +#endif +#if(C_cds_tk_number>=3) + UInt16 tk2 :1; +#endif +#if(C_cds_tk_number>=4) + UInt16 tk3 :1; +#endif +#if(C_cds_tk_number>=5) + UInt16 tk4 :1; +#endif +#if(C_cds_tk_number>=6) + UInt16 tk5 :1; +#endif +#if(C_cds_tk_number>=7) + UInt16 tk6 :1; +#endif +#if(C_cds_tk_number>=8) + UInt16 tk7 :1; +#endif + + UInt16 res :(16-C_cds_tk_number); + + } bit; + } errors_tk; + union + { + UInt16 all; + struct + { + +#if(C_adc_number>=1) + UInt16 adc0 :1; +#endif +#if(C_adc_number>=2) + UInt16 adc1 :1; +#endif +#if(C_adc_number>=3) + UInt16 adc2 :1; +#endif + +#if(C_cds_in_number>=1) + UInt16 in0 :1; +#endif +#if(C_cds_in_number>=2) + UInt16 in1 :1; +#endif +#if(C_cds_in_number>=3) + UInt16 in2 :1; +#endif + +#if(C_cds_out_number>=1) + UInt16 out0 :1; +#endif +#if(C_cds_out_number>=2) + UInt16 out1 :1; +#endif +#if(C_cds_out_number>=3) + UInt16 out2 :1; +#endif + +#if (C_cds_rs_number>=1) + UInt16 rs0 :1; +#endif + +#if(C_hwp_number>=1) + UInt16 hwp0 :1; +#endif +#if(C_hwp_number>=2) + UInt16 hwp1 :1; +#endif +#if(C_hwp_number>=3) + UInt16 hwp2 :1; +#endif + + UInt16 res :1; + + } bit; + } errors; + +} T_project_all_errors_plates; + +#define T_PROJECT_ALL_ERRORS_PLATES_DEFAULTS {0,0} +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + + + + +typedef struct TS_project{ + T_controller controller; +// int controller; + T_project_all_errors_plates all_err_plates; + T_project_all_status_plates all_status_plates; + T_cds_tk cds_tk[C_cds_tk_number]; + T_adc adc[C_adc_number]; + T_cds_in cds_in[C_cds_in_number]; + T_cds_out cds_out[C_cds_out_number]; +#if (C_cds_rs_number>=1) + T_cds_rs cds_rs[C_cds_rs_number]; +#endif + T_hwp hwp[C_hwp_number]; +// T_omega omega[C_omega_number]; +// T_dispatcher dispatcher; +// T_project_soft_info soft_info; + X_SERIAL_BUS *x_serial_bus; + X_PARALLEL_BUS *x_parallel_bus; + + int inited; + + + void (*init)(); // Pointer to calculation function + void (*read_all_sbus)(); // Pointer to calculation function + void (*read_all_pbus)(); + void (*write_all_sbus)(); + void (*reload_all_plates_with_reset)(); // со сбросом плат + void (*reload_all_plates_without_reset)(); // без сброса + void (*reload_all_plates_with_reset_no_stop_error)(); // со сбросом плат и без стопа на ошибках + void (*reload_all_plates_without_reset_no_stop_error)(); // без сброса и без стопа на ошибках + void (*write_all_hwp)(); + void (*read_all_hwp)(); + void (*send_reset_all_plates)(); + void (*stop_parallel_bus)(); + void (*start_parallel_bus)(); + void (*clear)(); + void (*read_errors_controller)(); + void (*reset_errors_controller)(); + void (*load_cfg_to_plates)(); + void (*clear_errors_all_plates)(); + void (*disable_all_interrupt)(); + void (*enable_all_interrupt)(); + void (*enable_int13)(); + void (*disable_int13)(); + void (*find_all_cds)(); + + + +} T_project; + +extern T_project project; + + +#if(C_cds_tk_number==8) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==7) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==6) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS, T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==5) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==4) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==3) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==2) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS,T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady +#endif +#if(C_cds_tk_number==1) +#define PROJECT_DEFAULTS_CDS_TK {T_cds_tk_DEFAULTS} +#define CDS_TK_STATUS_PLATES_DEFAULTS component_NotReady +#endif + +#if(C_adc_number==1) +#define PROJECT_DEFAULTS_ADC {T_adc_DEFAULTS} +#define ADC_STATUS_PLATES_DEFAULTS component_NotReady +#endif +#if(C_adc_number==2) +#define PROJECT_DEFAULTS_ADC {T_adc_DEFAULTS,T_adc_DEFAULTS} +#define ADC_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady +#endif +#if(C_adc_number==3) +#define PROJECT_DEFAULTS_ADC {T_adc_DEFAULTS,T_adc_DEFAULTS,T_adc_DEFAULTS} +#define ADC_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady +#endif + + +#if(C_hwp_number==1) +#define PROJECT_DEFAULTS_HWP T_hwp_DEFAULTS +#define HWP_STATUS_PLATES_DEFAULTS component_NotReady +#endif +#if(C_hwp_number==2) +#define PROJECT_DEFAULTS_HWP {T_hwp_DEFAULTS, T_hwp_DEFAULTS} +#define HWP_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady +#endif +#if(C_hwp_number==3) +#define PROJECT_DEFAULTS_HWP {T_hwp_DEFAULTS, T_hwp_DEFAULTS, T_hwp_DEFAULTS} +#define HWP_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady +#endif + + +#if(C_cds_out_number==1) +#define PROJECT_DEFAULTS_OUT {T_cds_out_DEFAULTS} +#define OUT_STATUS_PLATES_DEFAULTS component_NotReady +#endif +#if(C_cds_out_number==2) +#define PROJECT_DEFAULTS_OUT {T_cds_out_DEFAULTS,T_cds_out_DEFAULTS} +#define OUT_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady +#endif +#if(C_cds_out_number==3) +#define PROJECT_DEFAULTS_OUT {T_cds_out_DEFAULTS,T_cds_out_DEFAULTS,T_cds_out_DEFAULTS} +#define OUT_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady +#endif + +#if(C_cds_in_number==1) +#define PROJECT_DEFAULTS_IN {T_cds_in_DEFAULTS} +#define IN_STATUS_PLATES_DEFAULTS component_NotReady +#endif +#if(C_cds_in_number==2) +#define PROJECT_DEFAULTS_IN {T_cds_in_DEFAULTS,T_cds_in_DEFAULTS} +#define IN_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady +#endif +#if(C_cds_in_number==3) +#define PROJECT_DEFAULTS_IN {T_cds_in_DEFAULTS,T_cds_in_DEFAULTS,T_cds_in_DEFAULTS} +#define IN_STATUS_PLATES_DEFAULTS component_NotReady,component_NotReady,component_NotReady +#endif + + + +#if(C_cds_rs_number>=1) +#define PROJECT_DEFAULTS_CDS_RS {T_cds_rs_DEFAULTS}, +#define CDS_RS_STATUS_PLATES_DEFAULTS ,component_NotReady +#else +#define PROJECT_DEFAULTS_CDS_RS +#define CDS_RS_STATUS_PLATES_DEFAULTS +#endif + + +#define T_PROJECT_ALL_STATUS_PLATES_DEFAULTS {HWP_STATUS_PLATES_DEFAULTS, ADC_STATUS_PLATES_DEFAULTS, CDS_TK_STATUS_PLATES_DEFAULTS, OUT_STATUS_PLATES_DEFAULTS, IN_STATUS_PLATES_DEFAULTS CDS_RS_STATUS_PLATES_DEFAULTS} + + + + +#define PROJECT_DEFAULTS { T_controller_DEFAULTS, \ + T_PROJECT_ALL_ERRORS_PLATES_DEFAULTS, T_PROJECT_ALL_STATUS_PLATES_DEFAULTS, \ + PROJECT_DEFAULTS_CDS_TK, \ + PROJECT_DEFAULTS_ADC, \ + PROJECT_DEFAULTS_IN, \ + PROJECT_DEFAULTS_OUT, \ + PROJECT_DEFAULTS_CDS_RS \ + PROJECT_DEFAULTS_HWP, \ + NULL, NULL, \ + 0,\ + (void (*)(Uint32))project_init, \ + (void (*)(Uint32))project_read_all_sbus, \ + (void (*)(Uint32))project_read_all_pbus,\ + (void (*)(Uint32))project_write_all_sbus,\ + (void (*)(Uint32))project_reload_all_plates_with_reset, \ + (void (*)(Uint32))project_reload_all_plates_without_reset, \ + (void (*)(Uint32))project_reload_all_plates_with_reset_no_stop_error, \ + (void (*)(Uint32))project_reload_all_plates_without_reset_no_stop_error, \ + (void (*)(Uint32))project_write_all_hwp, \ + (void (*)(Uint32))project_read_all_hwp, \ + (void (*)(Uint32))send_reset_all_plates, \ + (void (*)(Uint32))project_stop_parallel_bus, \ + (void (*)(Uint32))project_start_parallel_bus, \ + (void (*)(Uint32))project_clear, \ + (void (*)(Uint32))project_read_errors_controller,\ + (void (*)(Uint32))project_reset_errors_controller, \ + (void (*)(Uint32))project_load_cfg_to_plates, \ + (void (*)(Uint32))project_clear_errors_all_plates, \ + (void (*)(Uint32))project_disable_all_interrupts, \ + (void (*)(Uint32))project_enable_all_interrupts,\ + (void (*)(Uint32))project_enable_int13,\ + (void (*)(Uint32))project_disable_int13,\ + (void (*)(Uint32))project_find_all_cds\ + } + + +void project_init(void); +void project_read_all_sbus(void); +void project_read_all_pbus(void); +void project_write_all_sbus(void); +void project_reload_all_plates_with_reset(void); +void project_reload_all_plates_without_reset(void); +void project_reload_all_plates_with_reset_no_stop_error(void); +void project_reload_all_plates_without_reset_no_stop_error(void); +void project_write_all_hwp(void); +void project_read_all_hwp(void); +void project_autospeed_all_hwp(void); + +void send_reset_all_plates(void); + + +unsigned int project_wait_load_all_cds(int flag_reset); +void project_find_all_cds(void); + +void project_stop_parallel_bus(void); +void project_start_parallel_bus(void); +void project_load_cfg_to_plates(void); + +void project_clear(void); +void project_read_errors_controller(void); + +void project_reset_errors_controller(void); + + + +void project_reload_all_plates(int reset); + +void project_clear_errors_all_plates(void); + +void project_all_test_hwp(void); + +////////////////////////////////////////////////////////////////////// +// Обновление суммарного статуса готовности и ошибок по всем платам +////////////////////////////////////////////////////////////////////// +void project_update_all_err_status_plates(void); + + +void project_enable_all_interrupts(void); +void project_disable_all_interrupts(void); + + +void project_enable_int13(void); +void project_disable_int13(void); + +void project_run_init_all_plates(void); + +#endif // end XP_PROJECT_H diff --git a/Inu/Src2/N12_Xilinx/xp_tools.c b/Inu/Src2/N12_Xilinx/xp_tools.c new file mode 100644 index 0000000..15c8f82 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_tools.c @@ -0,0 +1,41 @@ +#include "MemoryFunctions.h" +#include "xp_tools.h" +#include "xp_tools.h" + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" + + + +////////////////////////////////////// +////////////////////////////////////// +// установить бит в ADR_ASYNC_BUS_TABLE +////////////////////////////////////// +////////////////////////////////////// +void set_adr_sync_table(int np) +{ + unsigned int active_address; + + active_address = i_ReadMemory(ADR_ASYNC_BUS_TABLE); + active_address |= (1 << np); + + WriteMemory(ADR_ASYNC_BUS_TABLE, active_address); +} + + +////////////////////////////////////// +////////////////////////////////////// +// сбросить бит в ADR_ASYNC_BUS_TABLE +////////////////////////////////////// +////////////////////////////////////// +void clear_adr_sync_table(int np) +{ + unsigned int active_address; + + active_address = i_ReadMemory(ADR_ASYNC_BUS_TABLE); + active_address &= (~(1 << np)); + + WriteMemory(ADR_ASYNC_BUS_TABLE, active_address); +} + + diff --git a/Inu/Src2/N12_Xilinx/xp_tools.h b/Inu/Src2/N12_Xilinx/xp_tools.h new file mode 100644 index 0000000..7382290 --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_tools.h @@ -0,0 +1,16 @@ +#ifndef _XP_TOOLS_H +#define _XP_TOOLS_H + + + + +void set_adr_sync_table(int np); +void clear_adr_sync_table(int np); + + + + + + +#endif // END _XP_TOOLS_H + diff --git a/Inu/Src2/N12_Xilinx/xp_write_xpwm_time.c b/Inu/Src2/N12_Xilinx/xp_write_xpwm_time.c new file mode 100644 index 0000000..580483d --- /dev/null +++ b/Inu/Src2/N12_Xilinx/xp_write_xpwm_time.c @@ -0,0 +1,671 @@ +/* + * xp_write_xpwm_time.c + * + * Created on: 03 апр. 2018 г. + * Author: stud + */ + +#include "xp_write_xpwm_time.h" + +#include + +#include "MemoryFunctions.h" +#include "Spartan2E_Adr.h" +#include "xerror.h" + + + + +#pragma DATA_SECTION(xpwm_time,".fast_vars1"); +XPWM_TIME xpwm_time = DEFAULT_XPWM_TIME; + + +#define set_default_tclosed(k,b) {if (b) k = p->Tclosed_saw_direct_1; else k = p->Tclosed_saw_direct_0;} +/////////////////////////////////////////////////////// +/////////////////////////////////////////////////////// +/////////////////////////////////////////////////////// +void set_mode_soft_x24(void) +{ + i_WriteMemory(ADR_PWM_START_STOP, (i_ReadMemory(ADR_PWM_START_STOP) | 0x8000) ); +} + +void set_mode_hard_x24(void) +{ + i_WriteMemory(ADR_PWM_START_STOP, (i_ReadMemory(ADR_PWM_START_STOP) & 0x7fff) ); +} + +void set_start_pwm_x24(void) +{ + i_WriteMemory(ADR_PWM_START_STOP, (i_ReadMemory(ADR_PWM_START_STOP) | 0x0001) ); +} + +void set_stop_pwm_x24(void) +{ + i_WriteMemory(ADR_PWM_START_STOP, (i_ReadMemory(ADR_PWM_START_STOP) & 0xfffe) ); +} + +////////////////////////////////////////////////////////// + + + +void initXpwmTimeStructure(XPWM_TIME *p) +{ + + set_default_tclosed(p->Ta0_0, p->saw_direct.bits.bit0); + set_default_tclosed(p->Ta0_1, p->saw_direct.bits.bit1); + set_default_tclosed(p->Tb0_0, p->saw_direct.bits.bit2); + set_default_tclosed(p->Tb0_1, p->saw_direct.bits.bit3); + set_default_tclosed(p->Tc0_0, p->saw_direct.bits.bit4); + set_default_tclosed(p->Tc0_1, p->saw_direct.bits.bit5); + + set_default_tclosed(p->Ta1_0, p->saw_direct.bits.bit6); + set_default_tclosed(p->Ta1_1, p->saw_direct.bits.bit7); + set_default_tclosed(p->Tb1_0, p->saw_direct.bits.bit8); + set_default_tclosed(p->Tb1_1, p->saw_direct.bits.bit9); + set_default_tclosed(p->Tc1_0, p->saw_direct.bits.bit10); + set_default_tclosed(p->Tc1_1, p->saw_direct.bits.bit11); + + p->Tbr0_0 = 0; + p->Tbr0_1 = 0; + p->Tbr1_0 = 0; + p->Tbr1_1 = 0; + + if (p->freq_pwm == 0) + { + xerror(main_er_ID(2),(void *)1); // 0 не может быть!!! + } + + + p->inited = 1; +} + +#pragma CODE_SECTION(xpwm_write_zero_1,".fast_run1"); +void xpwm_write_zero_1(XPWM_TIME *p) +{ + unsigned int tclose; + + //a + set_default_tclosed(tclose, p->saw_direct.bits.bit0); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Ta0_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit1); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Ta0_1 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit2); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tb0_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit3); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tb0_1 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit4); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tc0_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit5); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tc0_1 = tclose; + +} + +#pragma CODE_SECTION(xpwm_write_zero_2,".fast_run1"); +void xpwm_write_zero_2(XPWM_TIME *p) +{ + unsigned int tclose; + +//b + set_default_tclosed(tclose, p->saw_direct.bits.bit6); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Ta1_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit7); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Ta1_1 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit8); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tb1_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit9); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tb1_1 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit10); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tc1_0 = tclose; + + set_default_tclosed(tclose, p->saw_direct.bits.bit11); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, tclose); + p->Tc1_1 = tclose; + +} + +#pragma CODE_SECTION(xpwm_write_zero_break_1,".fast_run1"); +void xpwm_write_zero_break_1(XPWM_TIME *p) +{ + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, 0); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, 0); + + p->Tbr0_0 = 0; + p->Tbr0_1 = 0; + +} + +#pragma CODE_SECTION(xpwm_write_zero_break_2,".fast_run1"); +void xpwm_write_zero_break_2(XPWM_TIME *p) +{ + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, 0); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, 0); + + p->Tbr1_0 = 0; + p->Tbr1_1 = 0; +} + +#pragma CODE_SECTION(xpwm_write_zero_winding_break_times_16_lines,".fast_run1"); +void xpwm_write_zero_winding_break_times_16_lines(XPWM_TIME *p) +{ + xpwm_write_zero_1(p); + xpwm_write_zero_2(p); + xpwm_write_zero_break_1(p); + xpwm_write_zero_break_2(p); +} + +#pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines,".fast_run1"); +void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) +{ + if (!(i_ReadMemory(ADR_ERRORS_TOTAL_INFO))) + { +//a + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit0==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Ta0_0); + } + + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit1 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit1==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Ta0_1); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit2 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit2==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tb0_0); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit3 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit3==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tb0_1); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit4 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit4==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tc0_0); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit5 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit5==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tc0_1); + } +//b + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit6 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit6==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Ta1_0); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit7 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit7==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Ta1_1); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit8 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit8==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tb1_0); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit9 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit9==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tb1_1); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit10 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit10==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tc1_0); + } + if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) + || (p->saw_direct.bits.bit11 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) + || (p->saw_direct.bits.bit11==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) + { + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tc1_1); + } + +//br1 br2 + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_0); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_1); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_0); + i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); + i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_1); + } + else + { + hard_stop_x24_pwm_all(); + xpwm_write_zero_winding_break_times_16_lines(p); + } +} + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +// Разрешение выходов ШИМа +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_start_x24_break_1,".fast_run2") +void soft_start_x24_break_1(void) +{ + unsigned int mask_tk_lines; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_BREAK_1; + + set_mode_soft_x24(); + + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_start_x24_break_2,".fast_run2") +void soft_start_x24_break_2(void) +{ + unsigned int mask_tk_lines; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_BREAK_2; + + set_mode_soft_x24(); + + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_start_x24_break_all,".fast_run2") +void soft_start_x24_break_all(void) +{ + unsigned int mask_tk_lines; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_BREAK_ALL; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start +} + +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(soft_start_x24_pwm_1,".fast_run"); +void soft_start_x24_pwm_1(void) +{ + unsigned int mask_tk_lines; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_1; + +#if (TK_DISABLE_OUTPUT_A1) + mask_tk_lines |= DISABLE_PWM_A1; +#endif +#if (TK_DISABLE_OUTPUT_B1) + mask_tk_lines |= DISABLE_PWM_B1; +#endif +#if (TK_DISABLE_OUTPUT_C1) + mask_tk_lines |= DISABLE_PWM_C1; +#endif + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_start_x24_pwm_2,".fast_run"); +void soft_start_x24_pwm_2(void) +{ + unsigned int mask_tk_lines; +// mPWM_b = 1; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_2; + +#if (TK_DISABLE_OUTPUT_A2) + mask_tk_lines |= DISABLE_PWM_A2; +#endif +#if (TK_DISABLE_OUTPUT_B2) + mask_tk_lines |= DISABLE_PWM_B2; +#endif +#if (TK_DISABLE_OUTPUT_C2) + mask_tk_lines |= DISABLE_PWM_C2; +#endif + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_start_x24_pwm_1_2,".fast_run"); +void soft_start_x24_pwm_1_2(void) +{ + unsigned int mask_tk_lines; +// mPWM_a = 1; +// mPWM_b = 1; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_1_2; + +#if (TK_DISABLE_OUTPUT_A1) + mask_tk_lines |= DISABLE_PWM_A1; +#endif +#if (TK_DISABLE_OUTPUT_B1) + mask_tk_lines |= DISABLE_PWM_B1; +#endif +#if (TK_DISABLE_OUTPUT_C1) + mask_tk_lines |= DISABLE_PWM_C1; +#endif +#if (TK_DISABLE_OUTPUT_A2) + mask_tk_lines |= DISABLE_PWM_A2; +#endif +#if (TK_DISABLE_OUTPUT_B2) + mask_tk_lines |= DISABLE_PWM_B2; +#endif +#if (TK_DISABLE_OUTPUT_C2) + mask_tk_lines |= DISABLE_PWM_C2; +#endif + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start + +} + +//////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(soft_start_x24_pwm_all,".fast_run"); +void soft_start_x24_pwm_all(void) +{ + unsigned int mask_tk_lines; +// mPWM_a = 1; +// mPWM_b = 1; + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines &= ENABLE_PWM_ALL; + +#if (TK_DISABLE_OUTPUT_A1) + mask_tk_lines |= DISABLE_PWM_A1; +#endif +#if (TK_DISABLE_OUTPUT_B1) + mask_tk_lines |= DISABLE_PWM_B1; +#endif +#if (TK_DISABLE_OUTPUT_C1) + mask_tk_lines |= DISABLE_PWM_C1; +#endif +#if (TK_DISABLE_OUTPUT_A2) + mask_tk_lines |= DISABLE_PWM_A2; +#endif +#if (TK_DISABLE_OUTPUT_B2) + mask_tk_lines |= DISABLE_PWM_B2; +#endif +#if (TK_DISABLE_OUTPUT_C2) + mask_tk_lines |= DISABLE_PWM_C2; +#endif + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + set_start_pwm_x24(); + +// if (!(i_ReadMemory(ADR_PWM_START_STOP) & 0x1)) +// i_WriteMemory(ADR_PWM_START_STOP, PWM_START_SOFT); // soft start + +} + +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +// Запрещение выходов ШИМа +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(hard_stop_x24_pwm_all,".fast_run"); +void hard_stop_x24_pwm_all(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_1(&xpwm_time); + xpwm_write_zero_2(&xpwm_time); + + xpwm_write_zero_break_1(&xpwm_time); + xpwm_write_zero_break_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_ALL; + + set_mode_hard_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + set_stop_pwm_x24(); + +// i_WriteMemory(ADR_PWM_START_STOP, PWM_STOP_HARD); + +} + +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(soft_stop_x24_pwm_all,".fast_run"); +void soft_stop_x24_pwm_all(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_1(&xpwm_time); + xpwm_write_zero_2(&xpwm_time); + + xpwm_write_zero_break_1(&xpwm_time); + xpwm_write_zero_break_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_ALL; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + set_stop_pwm_x24(); + +// i_WriteMemory(ADR_PWM_START_STOP, PWM_STOP_SOFT); + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_pwm_1_2,".fast_run"); +void soft_stop_x24_pwm_1_2(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_1(&xpwm_time); + xpwm_write_zero_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_1_2; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); +// WriteMemory(ADR_PWM_START_STOP, PWM_STOP_SOFT); + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_pwm_1,".fast_run"); +void soft_stop_x24_pwm_1(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_1(&xpwm_time); +// xpwm_write_zero_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_1; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_pwm_2,".fast_run"); +void soft_stop_x24_pwm_2(void) +{ + unsigned int mask_tk_lines; + +// xpwm_write_zero_1(&xpwm_time); + xpwm_write_zero_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_2; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); +} +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_break_1,".fast_run2") +void soft_stop_x24_break_1(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_break_1(&xpwm_time); +// xpwm_write_zero_break_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_BREAK_1; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); + +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_break_2,".fast_run2") +void soft_stop_x24_break_2(void) +{ + unsigned int mask_tk_lines; + +// xpwm_write_zero_break_1(&xpwm_time); + xpwm_write_zero_break_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_BREAK_2; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); +} +////////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(soft_stop_x24_break_all,".fast_run2") +void soft_stop_x24_break_all(void) +{ + unsigned int mask_tk_lines; + + xpwm_write_zero_break_1(&xpwm_time); + xpwm_write_zero_break_2(&xpwm_time); + + mask_tk_lines = i_ReadMemory(ADR_TK_MASK_0); + mask_tk_lines |= DISABLE_PWM_BREAK_ALL; + + set_mode_soft_x24(); + i_WriteMemory(ADR_TK_MASK_0, mask_tk_lines); + if (mask_tk_lines == DISABLE_PWM_ALL) + set_stop_pwm_x24(); +} +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////// + diff --git a/Inu/Src2/main/xp_write_xpwm_time.h b/Inu/Src2/N12_Xilinx/xp_write_xpwm_time.h similarity index 55% rename from Inu/Src2/main/xp_write_xpwm_time.h rename to Inu/Src2/N12_Xilinx/xp_write_xpwm_time.h index 5e1159d..22293a9 100644 --- a/Inu/Src2/main/xp_write_xpwm_time.h +++ b/Inu/Src2/N12_Xilinx/xp_write_xpwm_time.h @@ -100,30 +100,30 @@ ///////////////////////////////////// typedef struct { - // Winding 1 times - unsigned int Ta0_0; - unsigned int Ta0_1; - unsigned int Tb0_0; - unsigned int Tb0_1; - unsigned int Tc0_0; - unsigned int Tc0_1; - // Winding 2 times - unsigned int Ta1_0; - unsigned int Ta1_1; - unsigned int Tb1_0; - unsigned int Tb1_1; - unsigned int Tc1_0; - unsigned int Tc1_1; - // Break transistors - unsigned int Tbr0_0; - unsigned int Tbr0_1; - unsigned int Tbr1_0; - unsigned int Tbr1_1; - //Level transistors closed - unsigned int Tclosed_0; - unsigned int Tclosed_1; + // Winding 1 times + unsigned int Ta0_0; + unsigned int Ta0_1; + unsigned int Tb0_0; + unsigned int Tb0_1; + unsigned int Tc0_0; + unsigned int Tc0_1; + // Winding 2 times + unsigned int Ta1_0; + unsigned int Ta1_1; + unsigned int Tb1_0; + unsigned int Tb1_1; + unsigned int Tc1_0; + unsigned int Tc1_1; + // Break transistors + unsigned int Tbr0_0; + unsigned int Tbr0_1; + unsigned int Tbr1_0; + unsigned int Tbr1_1; + //Level transistors closed unsigned int Tclosed_high; +// unsigned int Tclosed_1; unsigned int pwm_tics; + unsigned int half_pwm_tics; unsigned int inited; unsigned int freq_pwm; unsigned int Tclosed_saw_direct_0; @@ -132,52 +132,97 @@ typedef struct unsigned int where_interrupt; unsigned int mode_reload; unsigned int one_or_two_interrupts_run; + unsigned int what_next_interrupt; + unsigned int do_sync_out; + unsigned int disable_sync_out; WORD_UINT2BITS_STRUCT saw_direct; - void (*write_1_2_winding_break_times)(); - void (*write_1_2_winding_break_times_split)(); + void (*write_1_2_winding_break_times)(); + void (*write_zero_winding_break_times)(); + void (*init)(); } XPWM_TIME; -#define DEFAULT_XPWM_TIME {0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,0,0,0,0, {0}, \ +#define DEFAULT_XPWM_TIME {0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0, 0,0,0, 0, 0, 0, 0, 0,0,0, 0,0, {0}, \ xpwm_write_1_2_winding_break_times_16_lines, \ - xpwm_write_1_2_winding_break_times_16_lines_split_eages } + xpwm_write_zero_winding_break_times_16_lines, \ + initXpwmTimeStructure \ + } + +void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p); +void xpwm_write_zero_winding_break_times_16_lines(XPWM_TIME *p); -void xpwm_write_1_2_winding_break_times_16_lines(); -void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p); -void xpwm_write_zero_winding_break_times_16_lines_split_eages(); void initXpwmTimeStructure(XPWM_TIME *p); extern XPWM_TIME xpwm_time; #define write_winding1_fase_a(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 0); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 1); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 0); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 1); i_WriteMemory(ADR_PWM_TIMING, T1);} #define write_winding1_fase_b(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 2); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 3); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 2); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 3); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_winding1_fase_c(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 4); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 5); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 4); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 5); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_winding2_fase_a(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 6); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 7); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 6); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 7); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_winding2_fase_b(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 8); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 9); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 8); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 9); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_winding2_fase_c(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 10); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 11); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 10); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 11); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_break_winding1(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 12); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 13); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 12); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 13); i_WriteMemory(ADR_PWM_TIMING, T1); } #define write_break_winding2(T0, T1) \ - WriteMemory(ADR_PWM_KEY_NUMBER, 14); WriteMemory(ADR_PWM_TIMING, T0); \ - WriteMemory(ADR_PWM_KEY_NUMBER, 15); WriteMemory(ADR_PWM_TIMING, T1); + { i_WriteMemory(ADR_PWM_KEY_NUMBER, 14); i_WriteMemory(ADR_PWM_TIMING, T0); \ + i_WriteMemory(ADR_PWM_KEY_NUMBER, 15); i_WriteMemory(ADR_PWM_TIMING, T1); } + + +//// +// stop +void hard_stop_x24_pwm_all(void); +void soft_stop_x24_pwm_all(void); + +void soft_stop_x24_pwm_1_2(void); + +void soft_stop_x24_pwm_1(void); +void soft_stop_x24_pwm_2(void); + +void soft_stop_x24_break_1(void); +void soft_stop_x24_break_2(void); + +void soft_stop_x24_break_all(void); + +//// +// start +void soft_start_x24_pwm_all(void); + +void soft_start_x24_pwm_1(void); +void soft_start_x24_pwm_2(void); +void soft_start_x24_pwm_1_2(void); + +void soft_start_x24_break_1(void); +void soft_start_x24_break_2(void); +void soft_start_x24_break_all(void); + + + +/////////////// +void set_mode_soft_x24(void); +void set_mode_hard_x24(void); + +void set_start_pwm_x24(void); +void set_stop_pwm_x24(void); +//////////////// + #endif /* XP_WRITE_TIME_H_ */ diff --git a/Inu/Src2/VectorControl/abc_to_alphabeta.c b/Inu/Src2/VectorControl/abc_to_alphabeta.c deleted file mode 100644 index 7f37475..0000000 --- a/Inu/Src2/VectorControl/abc_to_alphabeta.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "IQmathLib.h" // Include header for IQmath library -#include "abc_to_alphabeta.h" - - - - -///////////////////////////////////////////////// - - -#pragma CODE_SECTION(abc_to_alphabeta_calc,".fast_run"); -void abc_to_alphabeta_calc(ABC_TO_ALPHABETA *v) -{ - static _iq iq_1_sqrt3 = _IQ(0.57735026918962576450914878050196); // = 1/sqrt(3) - static _iq iq_2_sqrt3 = _IQ(1.1547005383792515290182975610039); // =2/sqrt(3) - - v->Ualpha = v->Ua; - v->Ubeta = _IQmpy(iq_1_sqrt3,v->Ua) + _IQmpy(iq_2_sqrt3,v->Ub); - -} - - - -///////////////////////////////////////////////// diff --git a/Inu/Src2/VectorControl/abc_to_alphabeta.h b/Inu/Src2/VectorControl/abc_to_alphabeta.h deleted file mode 100644 index eb16b58..0000000 --- a/Inu/Src2/VectorControl/abc_to_alphabeta.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __ABC_ALPHABETA_H__ -#define __ABC_ALPHABETA_H__ - -#include "IQmathLib.h" - -typedef struct { _iq Ua; //phase A voltage, input - _iq Ub; //phase B voltage, input - _iq Uc; //phase C voltage, input -// _iq Tetta; //phase angle, input - _iq Ualpha; // axis d voltage, output - _iq Ubeta; // axis q voltage, output - void (*calc)(); // Pointer to calculation function - }ABC_TO_ALPHABETA; - - - - - -typedef ABC_TO_ALPHABETA *ABC_TO_ALPHABETA_handle; - -#define ABC_TO_ALPHABETA_DEFAULTS { 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(Uint32))abc_to_alphabeta_calc\ - } - - -void abc_to_alphabeta_calc(ABC_TO_ALPHABETA_handle); - - - - - - - - -#endif // end __ABC_ALPHABETA_H diff --git a/Inu/Src2/VectorControl/abc_to_dq.c b/Inu/Src2/VectorControl/abc_to_dq.c deleted file mode 100644 index 39c414d..0000000 --- a/Inu/Src2/VectorControl/abc_to_dq.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "IQmathLib.h" // Include header for IQmath library -#include "abc_to_dq.h" - - - - - - - - -///////////////////////////////////////////////// - - -#pragma CODE_SECTION(abc_to_dq_calc,".fast_run"); -void abc_to_dq_calc(ABC_TO_DQ *v) -{ - static _iq iq_two_third_pi = _IQ(6.283185307179586476925286766559/3.0); - static _iq iq_two_third = _IQ(2.0/3.0); - - v->Id = _IQmpy(iq_two_third,_IQmpy(v->Ia, _IQsin(v->Tetta)) + _IQmpy(v->Ib, _IQsin(v->Tetta - iq_two_third_pi)) + _IQmpy(v->Ic, _IQsin(v->Tetta + iq_two_third_pi))); - v->Iq = _IQmpy(iq_two_third,_IQmpy(v->Ia, _IQcos(v->Tetta)) + _IQmpy(v->Ib, _IQcos(v->Tetta - iq_two_third_pi)) + _IQmpy(v->Ic, _IQcos(v->Tetta + iq_two_third_pi))); -} - - -#pragma CODE_SECTION(abc_to_dq_calc_v2,".fast_run"); -void abc_to_dq_calc_v2(ABC_TO_DQ *v) -{ - static _iq iq_two_third_pi = _IQ(6.283185307179586476925286766559/3.0); - static _iq iq_two_third = _IQ(2.0/3.0); - - v->Id = _IQmpy(iq_two_third,_IQmpy(v->Ia, _IQcos(v->Tetta)) + _IQmpy(v->Ib, _IQcos(v->Tetta - iq_two_third_pi)) + _IQmpy(v->Ic, _IQcos(v->Tetta + iq_two_third_pi))); - v->Iq = _IQmpy(iq_two_third,_IQmpy(-v->Ia, _IQsin(v->Tetta)) - _IQmpy(v->Ib, _IQcos(v->Tetta - iq_two_third_pi)) - _IQmpy(v->Ic, _IQcos(v->Tetta + iq_two_third_pi))); -} - - -///////////////////////////////////////////////// - - diff --git a/Inu/Src2/VectorControl/abc_to_dq.h b/Inu/Src2/VectorControl/abc_to_dq.h deleted file mode 100644 index 1afd618..0000000 --- a/Inu/Src2/VectorControl/abc_to_dq.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __ABC_DQ_H__ -#define __ABC_DQ_H__ - - - -typedef struct { _iq Ia; //phase A voltage, input - _iq Ib; //phase B voltage, input - _iq Ic; //phase C voltage, input - _iq Tetta; //phase angle, input - _iq Id; // axis d voltage, output - _iq Iq; // axis q voltage, output - void (*calc)(); // Pointer to calculation function - void (*calc_v2)(); // Pointer to calculation function - }ABC_TO_DQ; - - - - - -typedef ABC_TO_DQ *ABC_TO_DQ_handle; - -#define ABC_TO_DQ_DEFAULTS { 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(_iq))abc_to_dq_calc, \ - (void (*)(_iq))abc_to_dq_calc_v2 } - - -void abc_to_dq_calc(ABC_TO_DQ_handle); -void abc_to_dq_calc_v2(ABC_TO_DQ_handle); - - - - - - - - -#endif // end __ABC_DQ_H diff --git a/Inu/Src2/VectorControl/alphabeta_to_abc.c b/Inu/Src2/VectorControl/alphabeta_to_abc.c deleted file mode 100644 index a161888..0000000 --- a/Inu/Src2/VectorControl/alphabeta_to_abc.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "IQmathLib.h" // Include header for IQmath library -#include "alphabeta_to_abc.h" - - - - -///////////////////////////////////////////////// - - -#pragma CODE_SECTION(alphabeta_to_abc_calc,".fast_run"); -void alphabeta_to_abc_calc(ALPHABETA_TO_ABC *v) -{ - static _iq iq_0_5 = _IQ(0.5); // = 1/2 - static _iq iq_sqrt3_2 = _IQ(0.86602540378443864676372317075294); // =sqrt(3)/2 - - v->Ua = v->Ualpha; - v->Ub = -_IQmpy(iq_0_5,v->Ualpha) + _IQmpy(iq_sqrt3_2,v->Ubeta); - v->Uc = -_IQmpy(iq_0_5,v->Ualpha) - _IQmpy(iq_sqrt3_2,v->Ubeta); - -} - - - -///////////////////////////////////////////////// diff --git a/Inu/Src2/VectorControl/alphabeta_to_abc.h b/Inu/Src2/VectorControl/alphabeta_to_abc.h deleted file mode 100644 index c5dca95..0000000 --- a/Inu/Src2/VectorControl/alphabeta_to_abc.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __ALPHABETA_ABC_H__ -#define __ALPHABETA_ABC_H__ - -#include "IQmathLib.h" - -typedef struct { _iq Ualpha; // axis d voltage, output - _iq Ubeta; // axis q voltage, output - _iq Ua; //phase A voltage, input - _iq Ub; //phase B voltage, input - _iq Uc; //phase C voltage, input - void (*calc)(); // Pointer to calculation function - }ALPHABETA_TO_ABC; - - - - - -typedef ALPHABETA_TO_ABC *ALPHABETA_TO_ABC_handle; - -#define ALPHABETA_TO_ABC_DEFAULTS{ 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(Uint32))alphabeta_to_abc_calc\ - } - - -void alphabeta_to_abc_calc(ALPHABETA_TO_ABC_handle); - - - - - - - - -#endif // end __ALPHABETA_ABC_H__ diff --git a/Inu/Src2/VectorControl/alphabeta_to_dq.c b/Inu/Src2/VectorControl/alphabeta_to_dq.c deleted file mode 100644 index 026a212..0000000 --- a/Inu/Src2/VectorControl/alphabeta_to_dq.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "IQmathLib.h" // Include header for IQmath library -#include "alphabeta_to_dq.h" - - - - - - - - -///////////////////////////////////////////////// - - -#pragma CODE_SECTION(alphabeta_to_dq_calc,".fast_run"); -void alphabeta_to_dq_calc(ALPHABETA_TO_DQ *v) -{ - - v->Ud = _IQmpy(v->Ualpha, _IQcos(v->Tetta)) + _IQmpy(v->Ubeta, _IQsin(v->Tetta)); - v->Uq = -_IQmpy(v->Ualpha, _IQsin(v->Tetta)) + _IQmpy(v->Ubeta, _IQcos(v->Tetta)); - -} -///////////////////////////////////////////////// diff --git a/Inu/Src2/VectorControl/alphabeta_to_dq.h b/Inu/Src2/VectorControl/alphabeta_to_dq.h deleted file mode 100644 index cd7ac27..0000000 --- a/Inu/Src2/VectorControl/alphabeta_to_dq.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __ALPHABETA_DQ_H__ -#define __ALPHABETA_DQ_H__ - -#include "IQmathLib.h" - -typedef struct { _iq Ualpha; //phase A voltage, input - _iq Ubeta; //phase B voltage, input - _iq Tetta; //phase angle, input - _iq Ud; // axis d voltage, output - _iq Uq; // axis q voltage, output - void (*calc)(); // Pointer to calculation function - }ALPHABETA_TO_DQ; - - - - - -typedef ALPHABETA_TO_DQ *ALPHABETA_TO_DQ_handle; - -#define ALPHABETA_TO_DQ_DEFAULTS { 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(Uint32))alphabeta_to_dq_calc \ - } - - -void alphabeta_to_dq_calc(ALPHABETA_TO_DQ_handle); - - -#endif // end __ALPHABETA_DQ_H diff --git a/Inu/Src2/VectorControl/dq_to_alphabeta_cos.c b/Inu/Src2/VectorControl/dq_to_alphabeta_cos.c deleted file mode 100644 index e0dd2f8..0000000 --- a/Inu/Src2/VectorControl/dq_to_alphabeta_cos.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "dq_to_alphabeta_cos.h" - -#include "IQmathLib.h" // Include header for IQmath library - - - - - -///////////////////////////////////////////////// - - -#pragma CODE_SECTION(dq_to_alphabeta_calc,".fast_run2"); -void dq_to_alphabeta_calc(DQ_TO_ALPHABETA_handle v) -{ - - v->Ualpha = _IQmpy(v->Ud, _IQcos(v->Tetta)) + _IQmpy(v->Uq, _IQsin(v->Tetta)); - v->Ubeta = -_IQmpy(v->Ud, _IQsin(v->Tetta)) + _IQmpy(v->Uq, _IQcos(v->Tetta)); - -} - - -#pragma CODE_SECTION(dq_to_alphabeta_calc2,".fast_run2"); -void dq_to_alphabeta_calc2(DQ_TO_ALPHABETA_handle v) -{ - - v->Ualpha = _IQmpy(v->Ud, _IQsin(v->Tetta)) + _IQmpy(v->Uq, _IQcos(v->Tetta)); - v->Ubeta = -_IQmpy(v->Ud, _IQcos(v->Tetta)) + _IQmpy(v->Uq, _IQsin(v->Tetta)); - -} - -#pragma CODE_SECTION(dq_to_alphabeta_calc_cos,".fast_run2"); -void dq_to_alphabeta_calc_cos(DQ_TO_ALPHABETA_handle v) -{ - - v->Ualpha = _IQmpy(v->Ud, _IQcos(v->Tetta)) - _IQmpy(v->Uq, _IQsin(v->Tetta)); - v->Ubeta = _IQmpy(v->Ud, _IQsin(v->Tetta)) + _IQmpy(v->Uq, _IQcos(v->Tetta)); - -} -///////////////////////////////////////////////// diff --git a/Inu/Src2/VectorControl/dq_to_alphabeta_cos.h b/Inu/Src2/VectorControl/dq_to_alphabeta_cos.h deleted file mode 100644 index b261ced..0000000 --- a/Inu/Src2/VectorControl/dq_to_alphabeta_cos.h +++ /dev/null @@ -1,40 +0,0 @@ - - - -#ifndef __DQ_ALPHABETA_H__ -#define __DQ_ALPHABETA_H__ - -#include "IQmathLib.h" - -typedef struct { _iq Ualpha; //phase A voltage, input - _iq Ubeta; //phase B voltage, input - _iq Tetta; //phase angle, input - _iq Ud; // axis d voltage, output - _iq Uq; // axis q voltage, output - void (*calc)(); // Pointer to calculation function - void (*calc2)(); // Pointer to calculation function. Like in MATLAB - void (*calc_cos)(); // Pointer to calculation function, Ualpha = Uq*Cos(Tetta) - }DQ_TO_ALPHABETA; - - - - - -typedef DQ_TO_ALPHABETA *DQ_TO_ALPHABETA_handle; - -#define DQ_TO_ALPHABETA_DEFAULTS { 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - (void (*)(Uint32))dq_to_alphabeta_calc, \ - (void (*)(Uint32))dq_to_alphabeta_calc2, \ - (void (*)(Uint32))dq_to_alphabeta_calc_cos \ - } - - -void dq_to_alphabeta_calc(DQ_TO_ALPHABETA_handle); -void dq_to_alphabeta_calc2(DQ_TO_ALPHABETA_handle); -void dq_to_alphabeta_calc_cos(DQ_TO_ALPHABETA_handle); - -#endif // end __DQ_ALPHABETA_H__ diff --git a/Inu/Src2/VectorControl/efficiency_compensation.c b/Inu/Src2/VectorControl/efficiency_compensation.c deleted file mode 100644 index 16ab749..0000000 --- a/Inu/Src2/VectorControl/efficiency_compensation.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "IQmathLib.h" -#include "efficiency_compensation.h" - - -static int DetectCommandRegion(_iq *power); - -/***********************************************************/ -/** -* -*Increases the power demand depending on the machine efficiency -* -*@param p_zad - pointer to demanded power -*@param i_q - pointer to value of active current -* -*@return return value throw the pointer -* -*************************************************************/ -void EfficiencyCompensation(_iq *p_zad, _iq *i_q) -{ - static _iq efficiency_nominal = 16139681L; //96.2% - static _iq i_q_nom_levels[] = {3635063L, 4395630L, 4977240L, 5536481L, 6011835L, 6487190L, - 6934582L, 7381975L, 7751073L, 8220835L}; - - /** - * Coefficients of a square trinomial calculating the correction - */ - static _iq a0[10] = {17585441L, 17401328L, 17206712L, 17060750L, 17074172L, 16904722L, - 17129537L, 17698285L, 17188257L, 17740228L}; - static _iq a1[10] = {-2030043L, -1358954L, -905969L, -587202L, -553648L, -318767L, - -536870L, -1224736L, -570425L, -1224736L}; - static _iq a2[10] = {-385875L, -385875L, -385875L, -402653L, -335544L, - -348966L, -234881L, 0L, -167772L, 50331L}; - _iq efficiency, p_local; - _iq i_q_abs; - int region = 0; - region = DetectCommandRegion(p_zad); - efficiency = efficiency_nominal; - i_q_abs = _IQabs(*i_q); - p_local = *p_zad; - - if (i_q_abs <= i_q_nom_levels[region]) { - *p_zad = _IQdiv(*p_zad, efficiency_nominal); - return; - } - /** - * This is because of all electric values are normalized by 3000, - * but in a model in this place the current is normalized by 1000. - */ - i_q_abs = i_q_abs * 3; - efficiency = _IQmpy(i_q_abs, i_q_abs); - efficiency = a0[region] + _IQmpy(a1[region], i_q_abs) + _IQmpy(a2[region], efficiency); - p_local = _IQdiv(p_local, efficiency); - *p_zad = p_local; -} - - - -#define BOUND_1p5_MWT 2796202L -#define BOUND_2p5_MWT 4660337L -#define BOUND_3p5_MWT 6524472L -#define BOUND_4p5_MWT 8388608L -#define BOUND_6p5_MWT 12116878L -#define BOUND_7p5_MWT 13981013L -#define BOUND_8p5_MWT 15845148L -#define BOUND_5p5_MWT 10252743L -#define BOUND_9p5_MWT 17709283L - -/**************************************************************/ -/** - * Detects command mode: - * 0 corresponds to 1 MWt - * 1 - 2 MWt - * ... - * 9 - 10 MWt - * - * @param power - pointer to demanded power in watts - * - * @return corresponding mode - */ -int DetectCommandRegion(_iq *power) -{ - int region = 0; - if (*power < BOUND_1p5_MWT) - { - region = 0; - } else if (*power < BOUND_2p5_MWT) { - region = 1; - } else if (*power < BOUND_3p5_MWT) { - region = 2; - } else if (*power < BOUND_4p5_MWT) { - region = 3; - } else if (*power < BOUND_5p5_MWT) { - region = 4; - } else if (*power < BOUND_6p5_MWT) { - region = 5; - } else if (*power < BOUND_7p5_MWT) { - region = 6; - } else if (*power < BOUND_8p5_MWT) { - region = 7; - } else if (*power < BOUND_9p5_MWT) { - region = 8; - } else { - region = 9; - } - - return region; -} diff --git a/Inu/Src2/VectorControl/efficiency_compensation.h b/Inu/Src2/VectorControl/efficiency_compensation.h deleted file mode 100644 index f1d744b..0000000 --- a/Inu/Src2/VectorControl/efficiency_compensation.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * efficiency_compensation.h - * - * Created on: 26 сент. 2018 г. - * Author: stud - */ - -#ifndef SRC_VECTORCONTROL_EFFICIENCY_COMPENSATION_H_ -#define SRC_VECTORCONTROL_EFFICIENCY_COMPENSATION_H_ - -void EfficiencyCompensation(_iq *p_zad, _iq *i_q); - -#endif /* SRC_VECTORCONTROL_EFFICIENCY_COMPENSATION_H_ */ diff --git a/Inu/Src2/VectorControl/params_motor.h b/Inu/Src2/VectorControl/params_motor.h deleted file mode 100644 index 5f050ca..0000000 --- a/Inu/Src2/VectorControl/params_motor.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * params_motor.h - * - * Created on: 14 февр. 2020 г. - * Author: yura - */ - -#ifndef SRC_MAIN_PARAMS_MOTOR_H_ -#define SRC_MAIN_PARAMS_MOTOR_H_ - - -#define L_SIGMA_S 0.000964 -#define L_SIGMA_R 0.001134 -#define L_M 0.03889 -#define R_STATOR 0.0118 -#define R_ROTOR_SHTRIH 0.0111 -#define SLIP_NOM 0.0106 -#define R_ROTOR (R_ROTOR_SHTRIH / SLIP_NOM) -#define F_STATOR_NOM 12.0 - - - -#endif /* SRC_MAIN_PARAMS_MOTOR_H_ */ diff --git a/Inu/Src2/VectorControl/pwm_vector_regul.c b/Inu/Src2/VectorControl/pwm_vector_regul.c deleted file mode 100644 index 3a45fc4..0000000 --- a/Inu/Src2/VectorControl/pwm_vector_regul.c +++ /dev/null @@ -1,666 +0,0 @@ -#include "IQmathLib.h" -#include "math.h" -#include "my_filter.h" -#include "params.h" -#include "adc_tools.h" -#include "abc_to_dq.h" -#include "regul_power.h" -#include "regul_turns.h" -#include "teta_calc.h" -#include "pwm_vector_regul.h" -#include "pid_reg3.h" -#include "vector.h" -#include "params_motor.h" -#include "v_pwm24.h" -//#include "power_distribution.h" -#include "rotation_speed.h" -//#include "calc_3_power.h" - -// #pragma DATA_SECTION(pidD,".fast_vars1"); -// PIDREG3 pidD = PIDREG3_UNDEPENDENT_DEFAULTS; -PIDREG3 pidD = PIDREG3_DEFAULTS; -// #pragma DATA_SECTION(pidQ,".fast_vars1"); -// PIDREG3 pidQ = PIDREG3_UNDEPENDENT_DEFAULTS; -PIDREG3 pidQ = PIDREG3_DEFAULTS; - -// #pragma DATA_SECTION(pidD2,".fast_vars1"); -// PIDREG3 pidD2 = PIDREG3_UNDEPENDENT_DEFAULTS; -PIDREG3 pidD2 = PIDREG3_DEFAULTS; -// #pragma DATA_SECTION(pidQ2,".fast_vars1"); -// PIDREG3 pidQ2 = PIDREG3_UNDEPENDENT_DEFAULTS; -PIDREG3 pidQ2 = PIDREG3_DEFAULTS; - -// #pragma DATA_SECTION(cos_fi,".fast_vars1"); -COS_FI_STRUCT cos_fi = {0,0}; - -// #pragma DATA_SECTION(vect_control,".fast_vars1"); -VECTOR_CONTROL vect_control = VECTOR_CONTROL_DEFAULTS; - -// #pragma DATA_SECTION(koeff_Fs_filter,".fast_vars"); -long koeff_Fs_filter = _IQ(0.01); - -// _iq winding_displacement = FIXED_PIna6; - -WINDING a; -FLAG f; - - -ROTOR_VALUE rotor = ROTOR_VALUE_DEFAULTS; - -#define IQ_ONE 16777216 - -#define CONST_IQ_2PI 105414357 -#define CONST_IQ_2PI3 35138119 // 120 grad -#define CONST_IQ_PI2 26340229 - -#define K_MODUL_MIN 167772 //83886 //0.5% - ограничение из-за перенапружений -#define K_MODUL_MAX 15435038LL //13421772LL //80% 16106127LL ~ 96% //15435038LL ~ 0.92% - //15770583LL ~ 0.94% -#define K_MODUL_MAX_PART 15099494LL // 15099494LL ~ 0.9 - -#define I_ZERO_LEVEL_IQ 111848 //20A //279620 ~ 50A //55924 ~ 10A -#define K_MODUL_DEAD_TIME 503316 //3% - -//#define I_ZERO_LEVEL_IQ 27962 //5A //55924 ~ 10A - -#define Id_MIN 1118481 //200A //111848 ~ 20A //55924 ~ 10A - -// #pragma DATA_SECTION(zadan_Id_min,".fast_vars"); -_iq zadan_Id_min = Id_MIN; - -#define START_TETTA_IQ 4392264 //15 grad - -void analog_dq_calc(void); -void analog_Udq_calc(_iq Ud1, _iq Uq1, _iq Ud2, _iq Uq2); -void calcUdUqCompensation(_iq Frot); - -float kI_D = 0.2; -float kI_Q = 0.2; -float kP_D = 0.1;//.1; -float kP_Q = 0.3;//.3; - -// float kI_D_rev = 0.02; -// float kI_Q_rev = 0.03; -// float kP_D_rev = 0.1;//.3; -// float kP_Q_rev = 0.15;//.3; - -void init_DQ_pid() -{ - unsigned int i = 0; - int *pStr = (int*)&f; - for (i = 0; i < sizeof(f) / sizeof(int); i++) { - *(pStr + i) = 0; - } - - *pStr = (int*)&a; - for (i = 0; i < sizeof(a) / sizeof(int); i++) { - *(pStr + i) = 0; - } - - pidD.Ref = 0; - pidD.Kp = _IQ(kP_D);//_IQ(0.2); //_IQ(0.1); - pidD.Ki = _IQ(kI_D); //_IQ(0.2);// // - pidD.Kc = _IQ(0.3); - pidD.Kd = 0; - pidD.OutMax = K_MODUL_MAX_PART; - pidD.OutMin = -K_MODUL_MAX_PART; //0; - pidD.Up = 0; - pidD.Ui = 0; - pidD.Ud = 0; - pidD.Out = 0; - - pidQ.Ref = 0; - pidQ.Kp = _IQ(kP_Q);//_IQ(0.3);//_IQ(0.3); - pidQ.Ki = _IQ(kI_Q); //_IQ(0.2); // - pidQ.Kc = _IQ(0.3); - pidQ.Kd = 0; - pidQ.OutMax = K_MODUL_MAX_PART; //_IQ(0.9); - pidQ.OutMin = -K_MODUL_MAX_PART; //-_IQ(0.9); //0; - pidQ.Up = 0; - pidQ.Ui = 0; - pidQ.Ud = 0; - pidQ.Out = 0; - - pidD2.Ref = 0; - pidD2.Kp = _IQ(kP_D);//_IQ(0.1); //_IQ(0.1); - pidD2.Ki = _IQ(kI_D); //_IQ(0.2);// // - pidD2.Kc = _IQ(0.3); - pidD2.Kd = 0; - pidD2.OutMax = K_MODUL_MAX_PART; - pidD2.OutMin = -K_MODUL_MAX_PART; //0; - pidD2.Up = 0; - pidD2.Ui = 0; - pidD2.Ud = 0; - pidD2.Out = 0; - - pidQ2.Ref = 0; - pidQ2.Kp = _IQ(kP_Q);// _IQ(0.3);//_IQ(0.3); - pidQ2.Ki = _IQ(kI_Q); //_IQ(0.2); // - pidQ2.Kc = _IQ(0.3); - pidQ2.Kd = 0; - pidQ2.OutMax = K_MODUL_MAX_PART; //_IQ(0.9); - pidQ2.OutMin = -K_MODUL_MAX_PART; //-_IQ(0.9); //0; - pidQ2.Up = 0; - pidQ2.Ui = 0; - pidQ2.Ud = 0; - pidQ2.Out = 0; - - init_tetta_pid(); - init_Fvect_pid(); - init_Pvect_pid(); - init_tetta_calc_struct(); - - init_Adc_Variables(); - - cos_fi.cos_fi_nom = _IQ(0.87); - cos_fi.cos_fi_nom_squared = _IQ(0.87 * 0.87); - // cos_fi.cos_fi_nom = _IQ(COS_FI); - // cos_fi.cos_fi_nom_squared = _IQ(COS_FI * COS_FI); - - vect_control.koef_Ud_comp = _IQ((L_SIGMA_S + L_M * L_SIGMA_R / (L_M + L_SIGMA_R)) * 2 * 3.14 * NORMA_FROTOR); //Lsigm_s + Lm*Lsigm_r / (Lm + Lsigm_r) - vect_control.koef_Uq_comp = _IQ((L_M + L_SIGMA_S) * 2 * 3.14 * NORMA_FROTOR); - vect_control.k_modul_max = K_MODUL_MAX; - vect_control.k_modul_max_square = _IQmpy(K_MODUL_MAX, K_MODUL_MAX); - vect_control.iq_Id_out_max = _IQ(ID_OUT_SAT_POWER_LOW_SPEED / NORMA_ACP); - - vect_control.koeff_correct_Id = IQ_ONE; - - vect_control.equial_Iq_Proportional = _IQ(0.05); - vect_control.flag_reverse = 0; -} - -void reset_DQ_pid() -{ - pidD.Up = 0; - pidD.Up1 = 0; - pidD.Ui = 0; - pidD.Ud = 0; - pidD.Out = 0; - pidQ.Up = 0; - pidQ.Up1 = 0; - pidQ.Ui = 0; - pidQ.Ud = 0; - pidQ.Out = 0; - - pidD2.Up = 0; - pidD2.Up1 = 0; - pidD2.Ui = 0; - pidD2.Ud = 0; - pidD2.Out = 0; - pidQ2.Up = 0; - pidQ2.Up1 = 0; - pidQ2.Ui = 0; - pidQ2.Ud = 0; - pidQ2.Out = 0; -} - -// #pragma CODE_SECTION(Idq_to_Udq,".fast_run2"); -void Idq_to_Udq(_iq Id_zad, _iq Iq_zad, _iq Id_measured, _iq Iq_measured, _iq* Ud_zad, _iq* Uq_zad) -{ - pidD.Ref = Id_zad; - pidD.Fdb = Id_measured; - pidD.calc(&pidD); - *Ud_zad = pidD.Out; - - pidQ.Ref = Iq_zad; - pidQ.Fdb = Iq_measured; - pidQ.calc(&pidQ); - *Uq_zad = pidQ.Out; - -} - -// inline void set_pid_coeffs() { -// if (vect_control.flag_reverse == 0) { -// pidD.Kp = _IQ(kP_D);//_IQ(0.2); //_IQ(0.1); -// pidD.Ki = _IQ(kI_D); //_IQ(0.2);// // -// pidQ.Kp = _IQ(kP_Q);//_IQ(0.3);//_IQ(0.3); -// pidQ.Ki = _IQ(kI_Q); //_IQ(0.2); // -// pidD2.Kp = _IQ(kP_D);//_IQ(0.1); //_IQ(0.1); -// pidD2.Ki = _IQ(kI_D); //_IQ(0.2);// // -// pidQ2.Kp = _IQ(kP_Q);// _IQ(0.3);//_IQ(0.3); -// pidQ2.Ki = _IQ(kI_Q); //_IQ(0.2); // -// } else { -// pidD.Kp = _IQ(kP_D_rev);//_IQ(0.2); //_IQ(0.1); -// pidD.Ki = _IQ(kI_D_rev); //_IQ(0.2);// // -// pidQ.Kp = _IQ(kP_Q_rev);//_IQ(0.3);//_IQ(0.3); -// pidQ.Ki = _IQ(kI_Q_rev); //_IQ(0.2); // -// pidD2.Kp = _IQ(kP_D_rev);//_IQ(0.1); //_IQ(0.1); -// pidD2.Ki = _IQ(kI_D_rev); //_IQ(0.2);// // -// pidQ2.Kp = _IQ(kP_Q_rev);// _IQ(0.3);//_IQ(0.3); -// pidQ2.Ki = _IQ(kI_Q_rev); //_IQ(0.2); // -// } -// } - -void Idq_to_Udq_2_windings(_iq Id_zad, _iq Iq_zad, _iq Id_measured1, _iq Iq_measured1, _iq* Ud_zad1, _iq* Uq_zad1 - , _iq Id_measured2, _iq Iq_measured2, _iq* Ud_zad2, _iq* Uq_zad2) -{ - pidD.Ref = Id_zad; - pidD.Fdb = Id_measured1; - pidD.calc(&pidD); - *Ud_zad1 = pidD.Out; - - pidQ.Ref = Iq_zad; - pidQ.Fdb = Iq_measured1; - pidQ.calc(&pidQ); - *Uq_zad1 = pidQ.Out; - - pidD2.Ref = Id_zad; - pidD2.Fdb = Id_measured2; - pidD2.calc(&pidD2); - *Ud_zad2 = pidD2.Out; - - pidQ2.Ref = Iq_zad; - pidQ2.Fdb = Iq_measured2; - pidQ2.calc(&pidQ2); - *Uq_zad2 = pidQ2.Out; -} - -// #pragma CODE_SECTION(pwm_vector_model_titov,".fast_run"); -void pwm_vector_model_titov(_iq Pzad, _iq Fzad, int direction, _iq Frot, int mode, - int reset, int calcPWMtimes) -{ - int calc_channel = 1; - _iq U_zad1 = 0, U_zad2 = 0; - - - // if (f.flag_leading == 0 && f.read_task_from_optical_bus == 1 && f.sync_rotor_from_optical_bus == 1) { - // Frot = rotor.iqFrotFromOptica; - // } - - //Коррекция Id при привышении номинальных оборотов - if (_IQabs(Frot) > IQ_F_ROTOR_NOM) { - vect_control.koeff_correct_Id = _IQdiv(IQ_F_ROTOR_NOM, _IQabs(Frot)); - } else { - vect_control.koeff_correct_Id = IQ_ONE; - } - - - if(direction < 0) { Frot = -Frot; } -// prev_dir = direction; - if(reset == 1) //Сброс накопленых составл-ющих регул-тора - { - reset_DQ_pid(); - reset_tetta_pid(); - analog.iqIq1_filter = 0; - analog.iqIq2_filter = 0; - analog.iqUq2_filter = 0; - U_zad1 = K_MODUL_MIN; - U_zad2 = K_MODUL_MIN; - vect_control.iq_Id_out_max = Id_out_max_low_speed; - vect_control.flag_reverse = 0; - } - - set_cos_tetta_calc_params(); - analog_dq_calc(); - - - vector_turns(Fzad, Frot, analog.iqIq1, mode, &vect_control.iqIq_zad, &vect_control.iqId_zad); - vector_power(Pzad, analog.iqPvsi1 + analog.iqPvsi2, analog.iqIq1, mode, Frot, &vect_control.iqIq_zad, &vect_control.iqId_zad); - - vect_control.iqPzad = pidPvect.Ref; - vect_control.iqPizm = pidPvect.Fdb; - vect_control.iqFrot = Frot; - - // Задание минимального значения Id - if (vect_control.iqId_zad < Id_MIN) { vect_control.iqId_zad = zadan_Id_min; } - - //Коррекция Id при привышении номинальных оборотов - // if (_IQabs(Frot) > IQ_F_ROTOR_NOM) { - // vect_control.iqId_zad = _IQmpy(vect_control.iqId_zad, vect_control.koeff_correct_Id); - // } - - -// Frot =_IQ(15.0 / 6 / NORMA_FROTOR); -// vect_control.iqIq_zad = _IQ(IQ_OUT_NOM / NORMA_ACP); -// vect_control.iqId_zad = 0;// _IQ(789.0 / NORMA_ACP); - - // set_pid_coeffs(); - Idq_to_Udq_2_windings(vect_control.iqId_zad, vect_control.iqIq_zad, analog.iqId1, analog.iqIq1, &vect_control.iqUdKm1, &vect_control.iqUqKm1, - analog.iqId2, analog.iqIq2, &vect_control.iqUdKm2, &vect_control.iqUqKm2); - - - calc_tetta_Id(Frot, vect_control.iqId_zad, vect_control.iqIq_zad, &analog.tetta, &analog.Fsl, &analog.iqFstator, reset); - filter.Fsl = exp_regul_iq(koeff_Fs_filter, filter.Fsl, analog.Fsl); - - // analog.tetta = _IQ(vect_control.theta); - analog.iqIq_zadan = vect_control.iqIq_zad; - - // calcUdUqCompensation(Frot); //TODO: test on power after testing rotating - vect_control.iqUdKm1Out = vect_control.iqUdKm1; - vect_control.iqUqKm1Out = vect_control.iqUqKm1; - vect_control.iqUdKm2Out = vect_control.iqUdKm2; - vect_control.iqUqKm2Out = vect_control.iqUqKm2; - - if(vect_control.iqUdKm1Out > K_MODUL_MAX_PART) { vect_control.iqUdKm1Out = K_MODUL_MAX_PART;} - if(vect_control.iqUdKm1Out < -K_MODUL_MAX_PART) { vect_control.iqUdKm1Out = -K_MODUL_MAX_PART;} - if(vect_control.iqUqKm1Out > K_MODUL_MAX_PART) { vect_control.iqUqKm1Out = K_MODUL_MAX_PART;} - if(vect_control.iqUqKm1Out < -K_MODUL_MAX_PART) { vect_control.iqUqKm1Out = -K_MODUL_MAX_PART;} - - if(vect_control.iqUdKm2Out > K_MODUL_MAX_PART) { vect_control.iqUdKm2Out = K_MODUL_MAX_PART;} - if(vect_control.iqUdKm2Out < -K_MODUL_MAX_PART) { vect_control.iqUdKm2Out = -K_MODUL_MAX_PART;} - if(vect_control.iqUqKm2Out > K_MODUL_MAX_PART) { vect_control.iqUqKm2Out = K_MODUL_MAX_PART;} - if(vect_control.iqUqKm2Out < -K_MODUL_MAX_PART) { vect_control.iqUqKm2Out = -K_MODUL_MAX_PART;} - - U_zad1 = _IQsqrt(_IQmpy(vect_control.iqUdKm1Out, vect_control.iqUdKm1Out) + _IQmpy(vect_control.iqUqKm1Out, vect_control.iqUqKm1Out)); - U_zad2 = _IQsqrt(_IQmpy(vect_control.iqUdKm2Out, vect_control.iqUdKm2Out) + _IQmpy(vect_control.iqUqKm2Out, vect_control.iqUqKm2Out)); - vect_control.iqUzad1 = U_zad1; - vect_control.iqUzad2 = U_zad2; - - if (U_zad1 > vect_control.k_modul_max) { - if (vect_control.iqUqKm1Out > 0) { - vect_control.iqUqKm1Out = _IQsqrt(vect_control.k_modul_max_square - _IQmpy(vect_control.iqUdKm1Out, vect_control.iqUdKm1Out)); - } else { - vect_control.iqUqKm1Out = -_IQsqrt(vect_control.k_modul_max_square - _IQmpy(vect_control.iqUdKm1Out, vect_control.iqUdKm1Out)); - } - } - if (U_zad2 > vect_control.k_modul_max) { - if (vect_control.iqUqKm2Out > 0) { - vect_control.iqUqKm2Out = _IQsqrt(vect_control.k_modul_max_square - _IQmpy(vect_control.iqUdKm2Out, vect_control.iqUdKm2Out)); - } else { - vect_control.iqUqKm2Out = -_IQsqrt(vect_control.k_modul_max_square - _IQmpy(vect_control.iqUdKm2Out, vect_control.iqUdKm2Out)); - } - } - - // Компенсация колебания Iq между двумя обмотками - // vect_control.equial_Iq_Delta = analog.iqIq1 - analog.iqIq2; - // vect_control.equial_Iq_Out = _IQmpy(vect_control.equial_Iq_Delta, - // vect_control.equial_Iq_Proportional); - // vect_control.iqUqKm1Out -= vect_control.equial_Iq_Out; - // vect_control.iqUqKm2Out += vect_control.equial_Iq_Out; - - // if (U_zad1 < K_MODUL_DEAD_TIME) { - // vect_control.iqUdKm1 = 0; - // vect_control.iqUqKm1 = 0; - // } - // if (U_zad2 < K_MODUL_DEAD_TIME) { - // vect_control.iqUdKm2 = 0; - // vect_control.iqUqKm2 = 0; - // } - - vect_control.iqUzad1 = _IQsqrt(_IQmpy(vect_control.iqUdKm1Out, vect_control.iqUdKm1Out) + _IQmpy(vect_control.iqUqKm1Out, vect_control.iqUqKm1Out)); - vect_control.iqUzad2 = _IQsqrt(_IQmpy(vect_control.iqUdKm2Out, vect_control.iqUdKm2Out) + _IQmpy(vect_control.iqUqKm2Out, vect_control.iqUqKm2Out)); - - analog_Udq_calc(vect_control.iqUdKm1, vect_control.iqUqKm1, vect_control.iqUdKm2, vect_control.iqUqKm2); - - - if(mode == 0) // Обнул-ем при первом входе при включении - { - U_zad1 = K_MODUL_MIN; - U_zad2 = K_MODUL_MIN; - vect_control.iqUdKm1Out = 0; - vect_control.iqUqKm1Out = 0; - vect_control.iqUdKm2Out = 0; - vect_control.iqUqKm2Out = 0; -// teta_st = analog.tetta; - } - - a.iqk1 = vect_control.iqUzad1; -// analog.iqUdKm = Ud_zad; -// analog.iqUqKm = Uq_zad; -// analog.iqId_zad = vect_control.iqId_zad; - - - if(mode && f.Go && calcPWMtimes) - { - test_calc_dq_pwm24(vect_control.iqUdKm1Out, vect_control.iqUqKm1Out, vect_control.iqUdKm2Out, vect_control.iqUqKm2Out, analog.tetta,K_MODUL_MAX); - } - - -} - - - -// #pragma DATA_SECTION(koeff_Iq_filter_slow,".fast_vars"); -long koeff_Iq_filter_slow = _IQ(0.5); //_IQ(0.3); -// #pragma DATA_SECTION(koeff_Idq_filter,".fast_vars"); -long koeff_Idq_filter = _IQ(0.15); -// #pragma DATA_SECTION(koeff_Uq_filter,".fast_vars"); -long koeff_Uq_filter = 500; -// #pragma DATA_SECTION(koeff_Ud_filter,".fast_vars"); -long koeff_Ud_filter = _IQ(0.5); - - -// #pragma CODE_SECTION(analog_dq_calc,".fast_run"); -void analog_dq_calc() -{ - ABC_TO_DQ abc_dq_converter = ABC_TO_DQ_DEFAULTS; - - abc_dq_converter.Ia = analog.iqIa1_1; - abc_dq_converter.Ib = analog.iqIb1_1; - abc_dq_converter.Ic = analog.iqIc1_1; - abc_dq_converter.Tetta = analog.tetta; - abc_dq_converter.calc(&abc_dq_converter); - analog.iqId1 = abc_dq_converter.Id; - filter.iqId1 = exp_regul_iq(koeff_Idq_filter, filter.iqId1, analog.iqId1); - analog.iqIq1 = abc_dq_converter.Iq; - filter.iqIq1 = exp_regul_iq(koeff_Idq_filter, filter.iqIq1, analog.iqIq1); -// analog.iqIq1_filter = zad_intensiv_q(koeff_Iq_filter_slow, koeff_Iq_filter_slow, -// analog.iqIq1_filter, analog.iqIq1); - analog.iqIq1_filter = exp_regul_iq(koeff_Iq_filter_slow, analog.iqIq1_filter, analog.iqIq1); - - abc_dq_converter.Ia = analog.iqIa2_1; - abc_dq_converter.Ib = analog.iqIb2_1; - abc_dq_converter.Ic = analog.iqIc2_1; - abc_dq_converter.Tetta = analog.tetta - winding_displacement; - abc_dq_converter.calc(&abc_dq_converter); - analog.iqId2 = abc_dq_converter.Id; - filter.iqId2 = exp_regul_iq(koeff_Idq_filter, filter.iqId2, analog.iqId2); - analog.iqIq2 = abc_dq_converter.Iq; - filter.iqIq2 = exp_regul_iq(koeff_Idq_filter, filter.iqIq2, analog.iqIq2); -// analog.iqIq2_filter = zad_intensiv_q(koeff_Iq_filter_slow, koeff_Iq_filter_slow, -// analog.iqIq2_filter, analog.iqIq2); - analog.iqIq2_filter = exp_regul_iq(koeff_Iq_filter_slow, analog.iqIq2_filter, analog.iqIq2); - - if (_IQabs(analog.iqId1) < I_ZERO_LEVEL_IQ) { analog.iqId1 = 0; } - if (_IQabs(analog.iqIq1) < I_ZERO_LEVEL_IQ) { analog.iqIq1 = 0; } - if (_IQabs(analog.iqId2) < I_ZERO_LEVEL_IQ) { analog.iqId2 = 0; } - if (_IQabs(analog.iqIq2) < I_ZERO_LEVEL_IQ) { analog.iqIq2 = 0; } - -// analog.iqPvsi1 = _IQmpy(_IQmpy(analog.iqIq1_filter, analog.iqUq1), 25165824L); -// analog.iqPvsi2 = _IQmpy(_IQmpy(analog.iqIq2_filter, analog.iqUq2), 25165824L); - - analog.iqPvsi1 = _IQmpy(_IQmpy(analog.iqIq1_filter, _IQabs(analog.iqUq1)), 25165824L); - analog.iqPvsi2 = _IQmpy(_IQmpy(analog.iqIq2_filter, _IQabs(analog.iqUq2)), 25165824L); - -// analog.iqM_1 = _IQdiv(analog.iqPvsi1, _IQmpy(rotor.iqW, CONST_IQ_2PI)); -// analog.iqM_2 = _IQdiv(analog.iqPvsi2, _IQmpy(rotor.iqW, CONST_IQ_2PI)); -// logpar.log11 = (int16)_IQtoIQ15(analog.iqIq1_filter); -} - -// #pragma CODE_SECTION(analog_Udq_calc,".fast_run"); -void analog_Udq_calc(_iq Ud1, _iq Uq1, _iq Ud2, _iq Uq2) -{ - analog.iqUd1 = _IQmpy(Ud1, _IQmpy((filter.iqU_1_long + filter.iqU_2_long), 8388608L)); // 8388608 = _IQ(0.5) - analog.iqUq1 = _IQmpy(Uq1, _IQmpy((filter.iqU_1_long + filter.iqU_2_long), 8388608L)); - analog.iqUd2 = _IQmpy(Ud2, _IQmpy((filter.iqU_3_long + filter.iqU_4_long), 8388608L)); - analog.iqUq2 = _IQmpy(Uq2, _IQmpy((filter.iqU_3_long + filter.iqU_4_long), 8388608L)); - - filter.iqUd1 = exp_regul_iq(koeff_Ud_filter, filter.iqUd1, analog.iqUd1); - -} - - -//#pragma CODE_SECTION(analog_dq_calc_const,".fast_run"); -void analog_dq_calc_const() -{ - ABC_TO_DQ abc_dq_converter = ABC_TO_DQ_DEFAULTS; - - abc_dq_converter.Ia = analog.iqIa1_1; - abc_dq_converter.Ib = analog.iqIb1_1; - abc_dq_converter.Ic = analog.iqIc1_1; - abc_dq_converter.Tetta = analog.tetta; // svgen_pwm24_1.Alpha; - abc_dq_converter.calc(&abc_dq_converter); - analog.iqId1 = abc_dq_converter.Id; - analog.iqIq1 = abc_dq_converter.Iq; - analog.iqIq1_filter = zad_intensiv_q(koeff_Iq_filter_slow, koeff_Iq_filter_slow, - analog.iqIq1_filter, analog.iqIq1); - - abc_dq_converter.Ia = analog.iqIa2_1; - abc_dq_converter.Ib = analog.iqIb2_1; - abc_dq_converter.Ic = analog.iqIc2_1; - abc_dq_converter.Tetta = analog.tetta; // svgen_pwm24_2.Alpha; - abc_dq_converter.calc(&abc_dq_converter); - analog.iqId2 = abc_dq_converter.Id; - analog.iqIq2 = abc_dq_converter.Iq; - analog.iqIq2_filter = zad_intensiv_q(koeff_Iq_filter_slow, koeff_Iq_filter_slow, - analog.iqIq2_filter, analog.iqIq2); - - analog.iqPvsi1 = _IQmpy(_IQmpy(analog.iqIq1_filter, analog.iqUq1), 25165824L); - analog.iqPvsi2 = _IQmpy(_IQmpy(analog.iqIq2_filter, analog.iqUq2), 25165824L); -// analog.iqPvsi1 = _IQmpy(_IQmpy(analog.iqIq1, analog.iqUq1), 25165824L); -// analog.iqPvsi2 = _IQmpy(_IQmpy(analog.iqIq2, analog.iqUq2), 25165824L); - -// analog.iqM_1 = _IQdiv(analog.iqPvsi1, _IQmpy(rotor.iqW, CONST_IQ_2PI)); -// analog.iqM_2 = _IQdiv(analog.iqPvsi2, _IQmpy(rotor.iqW, CONST_IQ_2PI)); -} - -void calcUdUqCompensation(_iq Frot) { - _iq Uzpt = (filter.iqU_1_long + filter.iqU_2_long) >> 1; - _iq UdVolt = _IQmpy(_IQmpy(Frot, vect_control.koef_Ud_comp), analog.iqIq1); - _iq UqVolt = _IQmpy(_IQmpy(Frot, vect_control.koef_Uq_comp), analog.iqId1); - if (Uzpt != 0) { - vect_control.iqUdCompensation1 = -_IQdiv(UdVolt, Uzpt); - vect_control.iqUqCompensation1 = _IQdiv(UqVolt, Uzpt); - } else { - vect_control.iqUdCompensation1 = 0; - vect_control.iqUqCompensation1 = 0; - } - - vect_control.iqUdKm1Out = vect_control.iqUdKm1 + vect_control.iqUdCompensation1; - vect_control.iqUqKm1Out = vect_control.iqUqKm1 + vect_control.iqUqCompensation1; - - Uzpt = (filter.iqU_3_long + filter.iqU_4_long) >> 1; - UdVolt = _IQmpy(_IQmpy(Frot, vect_control.koef_Ud_comp), analog.iqIq2); - UqVolt = _IQmpy(_IQmpy(Frot, vect_control.koef_Uq_comp), analog.iqId2); - if (Uzpt != 0) { - vect_control.iqUdCompensation2 = -_IQdiv(UdVolt, Uzpt); - vect_control.iqUqCompensation2 = _IQdiv(UqVolt, Uzpt); - } else { - vect_control.iqUdCompensation2 = 0; - vect_control.iqUqCompensation2 = 0; - } - - - vect_control.iqUdKm2Out = vect_control.iqUdKm2 + vect_control.iqUdCompensation2; - vect_control.iqUqKm2Out = vect_control.iqUqKm2 + vect_control.iqUqCompensation2; -} - -#define IQ_150_RPM 2097152 //150об/мин -#define IQ_140_RPM 1957341 //140об/мин -//#define IQ_135_RPM 1887436 //135об/мин -#define IQ_125_RPM 1747626 //125об/мин -#define IQ_120_RPM 1677721 //120об/мин -#define IQ_115_RPM 1607816 //115об/мин -#define IQ_110_RPM 1537911 //110об/мин - -#define K_MODUL_SWITCH_COS_FI 13925089 //83% -#define K_MODUL_SWITCH_COS_FI_2 14260633 //85% -#define K_MODUL_SWITCH_OFF 10905190 //65% //11744051 ~ 70% //12582912 ~ 75% - -#define U200V 1118481 - - -// #pragma CODE_SECTION(set_cos_tetta_calc_params,".fast_run1"); -void set_cos_tetta_calc_params() { - - _iq currentCos = _IQ(COS_FI); - _iq currentCosSq = _IQ(COS_FI * COS_FI); - static _iq cosFi_low_speed = _IQ(0.85); - static _iq cosFi_Sq_low_speed = _IQ(0.85 * 0.85); - static _iq cosFi_mid_speed = _IQ(COS_FI); - static _iq cosFi_Sq_mid_speed = _IQ(COS_FI * COS_FI); - static _iq cosFi_high_speed = _IQ(0.89); - static _iq cosFi_Sq_high_speed = _IQ(0.89 * 0.89); - static _iq stepChangeCos = _IQ(0.001); - static _iq kt_low_speed = _IQ(0.0045); - static _iq kt_over_140rpm = _IQ(0.0048); - static _iq kt_over_150rpm = _IQ(0.0049); - static _iq kt_single_inv = _IQ(0.0039); - - _iq current_kt = _IQ(0.0045); - static _iq stepChangeKt =_IQ(0.00001); - - static _iq addCompensateUd = _IQ(0.0004); - - static unsigned int flag_high_Km = 0; - - if (a.iqk1 < K_MODUL_SWITCH_OFF) { - flag_high_Km = 0; - } - -// if (_IQabs(rotor.iqFout) > IQ_150_RPM) { -// currentCos = _IQ(0.9); -// currentCosSq = _IQ(0.9 * 0.9); -//// tetta_calc.k_t = _IQ(0.0049); -// current_kt = kt_over_150rpm; //_IQ(0.0049); -// } else - if (_IQabs(rotor.iqFout) > IQ_140_RPM || (a.iqk1 > K_MODUL_SWITCH_COS_FI_2) - || flag_high_Km == 1) { - if (a.iqk1 > K_MODUL_SWITCH_COS_FI_2) { - flag_high_Km = 1; - } - currentCos = cosFi_high_speed; - currentCosSq = cosFi_Sq_high_speed; -// tetta_calc.k_t = _IQ(0.0048); - current_kt = kt_over_140rpm; //_IQ(0.0048); - } else if ((_IQabs(rotor.iqFout) > IQ_115_RPM && cos_fi.cos_fi_nom < _IQ(0.889)) - || (_IQabs(rotor.iqFout) < IQ_135_RPM && cos_fi.cos_fi_nom > _IQ(0.889)) - || (a.iqk1 > K_MODUL_SWITCH_COS_FI)) { - currentCos = cosFi_mid_speed; - currentCosSq = cosFi_Sq_mid_speed; -// tetta_calc.k_t = _IQ(0.0045); - current_kt = kt_low_speed; //_IQ(0.0045); - } else if (_IQabs(rotor.iqFout) < IQ_110_RPM) { - currentCos = cosFi_low_speed; - currentCosSq = cosFi_Sq_low_speed; - //(f.secondPChState != 4) - if(((analog.iqIm_1 > I_OUT_NOMINAL_IQ) || (analog.iqIm_2 > I_OUT_NOMINAL_IQ)) - && (f.secondPChState != 4)) { - current_kt = kt_single_inv; //_IQ(0.0039); - } else if ((analog.iqIm_1 < 9507089) || (analog.iqIm_2 < 9507089)) { - current_kt = kt_low_speed; //_IQ(0.0045); - } - } - - if (analog.iqUd1 < -U200V || (a.iqk1 > K_MODUL_SWITCH_COS_FI_2)) { - current_kt += addCompensateUd; // _IQ(0.0004); - } - cos_fi.cos_fi_nom = zad_intensiv_q(stepChangeCos, stepChangeCos, cos_fi.cos_fi_nom, currentCos); - cos_fi.cos_fi_nom_squared = zad_intensiv_q(stepChangeCos, stepChangeCos, cos_fi.cos_fi_nom_squared, currentCosSq); - - tetta_calc.k_t = zad_intensiv_q(stepChangeKt, stepChangeKt, tetta_calc.k_t, current_kt); -} - - -void limit_mzz_zad_power(_iq Frot) -{ - Frot = labs(Frot); - - if (vect_control.flag_reverse) { -// f.iq_mzz_zad = _IQ(1300.0/NORMA_MZZ); - f.iq_mzz_zad = _IQ(1100.0/NORMA_MZZ); - } else - if (Frot < 279620) //20 ob/min - { -// f.iq_mzz_zad = _IQ(1200.0/NORMA_MZZ); - f.iq_mzz_zad = _IQ(1400.0/NORMA_MZZ); - } - else if (Frot < 419430) //30 ob/min - { - f.iq_mzz_zad = _IQ(1400.0/NORMA_MZZ); - } -// else if(rotor.iqFout < 699050) //50 ob/min - else if (Frot < 838860) //60 ob/min -// else if (rotor.iqFout < 978670) //70 ob/min - { -// f.iq_mzz_zad = _IQ(1800.0/NORMA_MZZ); - f.iq_mzz_zad = _IQ(2000.0/NORMA_MZZ); - } - else - { - f.iq_mzz_zad = _IQ(2000.0/NORMA_MZZ); -// f.iq_mzz_zad = _IQ(1500.0/NORMA_MZZ); - } -} - - diff --git a/Inu/Src2/VectorControl/pwm_vector_regul.h b/Inu/Src2/VectorControl/pwm_vector_regul.h deleted file mode 100644 index 9b7c079..0000000 --- a/Inu/Src2/VectorControl/pwm_vector_regul.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef PWM_VECTOR_REGUL -#define PWM_VECTOR_REGUL - -#include "pid_reg3.h" - -void pwm_vector_model_titov(_iq Pzad, _iq Fzad, int direction, _iq Frot, int mode, - int reset, int calcPWMtimes); -void init_DQ_pid(void); -//void detect_I_M_overload(void); -void analog_dq_calc_const(void); - -void set_cos_tetta_calc_params(); -void limit_mzz_zad_power(_iq Frot); - -extern _iq zadan_Id_min; -extern PIDREG3 pidD; -extern PIDREG3 pidQ; -extern PIDREG3 pidD2; -extern PIDREG3 pidQ2; - -extern long koeff_Ud_filter; - -typedef struct { - _iq cos_fi_nom; - _iq cos_fi_nom_squared; -} COS_FI_STRUCT; - -extern COS_FI_STRUCT cos_fi; - -#define ONE_IQ24 16777216 - -typedef struct { - _iq iqId_zad; - _iq iqIq_zad; - _iq iqUdKm1; - _iq iqUqKm1; - _iq iqUdKm2; - _iq iqUqKm2; - _iq iqUdCompensation1; - _iq iqUqCompensation1; - _iq iqUdCompensation2; - _iq iqUqCompensation2; - _iq iqUdKm1Out; - _iq iqUqKm1Out; - _iq iqUdKm2Out; - _iq iqUqKm2Out; - - _iq iqUzad1; - _iq iqUzad2; - - _iq koef_Ud_comp; - _iq koef_Uq_comp; - _iq koeff_correct_Id; - - _iq equial_Iq_Proportional; //Пропорциональный коэффициент регулятора поддержания Iq одинаковым РЅР° РѕР±РѕРёС… обмотках - _iq equial_Iq_Delta; //Разница РІ Iq РґРІСѓС… обмоток - _iq equial_Iq_Out; - - _iq k_modul_max; - _iq k_modul_max_square; - _iq iq_Id_out_max; - - _iq iqPzad; - _iq iqPizm; - _iq iqFrot; - - int flag_reverse; - - float theta; - -} VECTOR_CONTROL; - -#define VECTOR_CONTROL_DEFAULTS {0,0,0,0,0,0,0,0,0,0, 0,0, 0,0,0, 0,0,0, 0,0,0,0,0, 0,0} - -extern VECTOR_CONTROL vect_control; - -extern PIDREG3 pidFvect; - -#endif //PWM_VECTOR_REGUL - - diff --git a/Inu/Src2/VectorControl/regul_power.c b/Inu/Src2/VectorControl/regul_power.c deleted file mode 100644 index 8ffcb42..0000000 --- a/Inu/Src2/VectorControl/regul_power.c +++ /dev/null @@ -1,269 +0,0 @@ -#include "vector.h" -#include "IQmathLib.h" -#include "math.h" -#include "pid_reg3.h" -#include "adc_tools.h" -#include "params.h" -#include "regul_power.h" -#include "pwm_vector_regul.h" -#include "my_filter.h" - -// #pragma DATA_SECTION(pidPvect,".fast_vars1"); -PIDREG3 pidPvect = PIDREG3_DEFAULTS; - - -#define IQ_OUT_SAT_POWER (2880.0 * COS_FI) -#define MAX_PID_CURRENT_P 2200.0 // 2200.0 ~ 1.6 Inom - -#define IM_CURRENT_STOP_RMP 11184810 //2000 - -#define IQ_1500A 8388608 -#define IQ_1800A 10066329 - -#define K_RMP_100A_PER_TIC 559240 -#define K_RMP_400A_PER_SEC 2663 - -#define K_MODUL_MAX 15770583 - -// #define P_DELTA_ZAD_IZM 5592405 //3 MWt - -#define LIMIT_Iq_ON_POWER_REVERSE - -_iq Id_out_max_low_speed = _IQ(ID_OUT_SAT_POWER_LOW_SPEED / NORMA_ACP); -_iq Id_out_max_full = _IQ(ID_OUT_SAT_POWER / NORMA_ACP); - - -void init_Pvect_pid() -{ - pidPvect.Ref = 0; - pidPvect.Kp = _IQ(1.0);//_IQ(1.0); - pidPvect.Ki = _IQ(0.1);//_IQ(0.05);//_IQ(0.06); - pidPvect.Kc = _IQ(0.5); - // pidPvect.Kp = _IQ(1); //_IQ(2.5);//_IQ(5.0);// - // pidPvect.Ki = _IQ(0.1);//_IQ(0.05);//_IQ(0.06); - // pidPvect.Kc = _IQ(0.5); - pidPvect.OutMax = _IQ(MAX_PID_CURRENT_P / NORMA_ACP); - pidPvect.OutMin = -_IQ(MAX_PID_CURRENT_P / NORMA_ACP); -} - -void reset_Pvect_pid() -{ - pidPvect.Up = 0; - pidPvect.Up1 = 0; - pidPvect.Ui = 0; - pidPvect.Ud = 0; - pidPvect.Out = 0; -} - -_iq koeff_Iq_filter = _IQ(0.5); - -#define LEVEL_LIMIT_KM 14596177 //87% //15099494 ~ 90% //15435038 ~ 92% - -#define POWER_7_MWt 13048945 -#define POWER_4_MWt 7456540 -#define POWER_200_kWt 372827 - -// #pragma CODE_SECTION(vector_power,".fast_run2"); -void vector_power(_iq Pzad, _iq P_measured, _iq Iq_measured, int mode, _iq Frot, _iq* Iq_zad, _iq* Id_zad) -{ - static _iq Pzad_rmp = 0; - static _iq koef_slow = _IQ(0.000075); //_IQ(0.000065);15sec //_IQ(0.000085); 13sec // //_IQ(0.000065); normal rampa 13 seconds - static _iq koef_slow_low_task = _IQ(0.000040); //Ðàìïà äëÿ çàäàíèé ìîùíîñòè ìåíüøå ïîëîâèíû íîìèíàëà, ÷òîáû íåáûëî ïåðåðåãóëÿöèè - static _iq koef_slow_2 = _IQ(0.000045); //_IQ(0.000039); // _IQ(0.000015); //_IQ(0.000011) ~ 10 sec 0-10MWt //_IQ(0.00002) ~ 7 Г±ГҐГЄ 0-10ÌÂò - static _iq koef_fast = _IQ(0.00013); //_IQ(0.00008); //_IQ(0.000025); ~3.1 sev 10-0MWt -// static _iq prev_Pzad = 0; -// static _iq cos_fi_nom_alg = _IQ(COS_FI), cos_fi_nom_squared_alg = _IQ(COS_FI * COS_FI); -// static _iq cos_fi_nom = _IQ(COS_FI), cos_fi_nom_squared = _IQ(COS_FI * COS_FI); - static _iq Iq_out_nom = _IQ(IQ_OUT_NOM / NORMA_ACP); //, Id_out_nom = _IQ(ID_OUT_NOM / NORMA_ACP); -// static _iq Iq_out_max = _IQ(IQ_OUT_SAT_POWER / NORMA_ACP); - static _iq Id_out_max = _IQ(ID_OUT_SAT_POWER_LOW_SPEED / NORMA_ACP); - static _iq pid_Out_max = _IQ(MAX_PID_CURRENT_P / NORMA_ACP); - _iq koef_rmp, koef_spad; //koef_spad - äëþ çàùèòû îò ïðåâûøåíèþ âèíòîì ðàçðåø¸ííûõ îáîðîòîâ (170îá/ìèí) - _iq Iq_out_unsat, Iq_out_sat, Id_out_sat, Id_out_unsat; -// _iq Iq_out_limited = 0; - static _iq Iq_out_filter = 0; - static _iq mzz_zad_int=0; - static int counterStopRampa = 0; -#ifdef LIMIT_Iq_ON_POWER_REVERSE - static int flag_reverse = 0; -#endif //LIMIT_Iq_ON_POWER_REVERSE - - // if (f.DownTemperature) { - // mzz_zad_int = zad_intensiv_q(35480, 35480, mzz_zad_int, _IQmpy(f.iq_mzz_zad, temperature_limit_koeff)); - // } else -// if(f.DownToNominal && (f.iq_mzz_zad > Iq_out_nom)) { -// mzz_zad_int = zad_intensiv_q(29480, 29480, mzz_zad_int, Iq_out_nom); -// } else if (a.iqk1 > LEVEL_LIMIT_KM || a.iqk2 > LEVEL_LIMIT_KM) { -// Pzad = 0; -// Pzad_rmp = zad_intensiv_q((koef_fast << 3), (koef_fast << 3), Pzad_rmp, Pzad); -// // f.DownToNominalVoltage = 1; -// } -// else - { - if (f.iq_mzz_zad != 0) { - mzz_zad_int = zad_intensiv_q(28480, 28480, mzz_zad_int, f.iq_mzz_zad); - } else { - mzz_zad_int = zad_intensiv_q(25480, 25480, mzz_zad_int, pid_Out_max); - } -// f.DownToNominalVoltage = 0; - } - - if((mode != 2) || (!f.Go) -// || (f.flag_leading == 0 && f.read_task_from_optical_bus == 1 && f.sync_Iq_from_optical_bus == 1) - ) - { - Pzad_rmp = P_measured; -// prev_Pzad = P_measured; - pidPvect.Ui = Iq_measured; - Id_out_max = Id_out_max_low_speed; - if(!f.Go) - { - *Iq_zad = *Id_zad = 0; - } - #ifdef LIMIT_Iq_ON_POWER_REVERSE - flag_reverse = 0; - #endif - return; - } - -#ifdef LIMIT_Iq_ON_POWER_REVERSE - // Ïðè òîðîæåíèè îãðàíè÷èâàåì Iq íóë¸ì Г±Г® ñòîðîíû Г­ГҐ òîðìîæåíèÿ - // ГІ.ГЄ. ïðè òîðìîæåíèè ГЁГ§-çà êîëåáàíèé çàäàíèå Г­Г  òîê ìîæåò ïîìåíÿòü çíàê - if ((Frot > 0 && Pzad_rmp < 0 && pidPvect.Out < 0) || - (Frot < 0 && Pzad_rmp > 0 && pidPvect.Out > 0)) { - flag_reverse = 1; - vect_control.flag_reverse = 1; - } else - if ((Frot > 0 && Pzad_rmp > 0) || (Frot < 0 && Pzad_rmp < 0)) - { - flag_reverse = 0; - vect_control.flag_reverse = 0; - } - if (flag_reverse == 0) { - pidPvect.OutMax = mzz_zad_int; - pidPvect.OutMin = -mzz_zad_int; - } else { - if (Pzad_rmp < 0) { - pidPvect.OutMax = 0; - pidPvect.OutMin = -mzz_zad_int; - } else { - pidPvect.OutMax = mzz_zad_int; - pidPvect.OutMin = 0; - } - } -#else - pidPvect.OutMax = mzz_zad_int; - pidPvect.OutMin = -mzz_zad_int; -#endif //LIMIT_Iq_ON_POWER_REVERSE - -// if (f.setCosTerminal) { -// cos_fi.cos_fi_nom = f.cosinusTerminal; -// cos_fi.cos_fi_nom_squared = f.cosinusTerminalSquared; -// } - - - //if(Pzad != prev_Pzad) - //{ - if((_IQabs(Pzad_rmp) <= _IQabs(Pzad)) && - (((Pzad >= 0) && (Pzad_rmp >= 0)) || ((Pzad < 0) && (Pzad_rmp < 0)))) - { - // if (_IQabs(Pzad) < POWER_4_MWt) { - // koef_rmp = koef_slow_low_task; - // } else if (_IQabs(Pzad_rmp) < POWER_7_MWt) { // 7MWt - // koef_rmp = koef_slow; - // } else { - // koef_rmp = koef_slow_2; - // } - koef_rmp = koef_slow; - //Ïðè íàáðîñå ìîùíîñòè ýëåêòðè÷åñêàÿ ìîùíîñòü ìîæåò ïðåâûñèòü çàäàííóþ - //ïîýòîìó åñëè ïðèáëèçèëèñü ГЄ çàäàíèþ, ГІГ® çàìåäëÿåì ðàìïó âåêòîðîé ìîùíîñòè - // if (_IQabs(f.iq_p_zad_electric) - _IQabs(analog.iqW) < POWER_200_kWt) { - // koef_rmp = koef_rmp / 4; - // } - } - else - { - koef_rmp = koef_fast; - } - //} - -// EfficiencyCompensation(&Pzad, &Iq_measured); - - // if (analog.iqIm_1 > IM_CURRENT_STOP_RMP || analog.iqIm_2 > IM_CURRENT_STOP_RMP) { - // counterStopRampa = 400; - // } else { - // if (counterStopRampa > 0) { - // counterStopRampa -= 1; - // } - // } - // if (counterStopRampa <= 0) { - // Pzad_rmp = zad_intensiv_q(koef_rmp, koef_rmp, Pzad_rmp, Pzad); - // counterStopRampa = 0; - // } else { - // Pzad_rmp = zad_intensiv_q(koef_slow_2, koef_slow_2, Pzad_rmp, Pzad); - // } - - Pzad_rmp = zad_intensiv_q(koef_rmp, koef_rmp, Pzad_rmp, Pzad); - -#ifdef P_DELTA_ZAD_IZM - //Åñëè èçìåðåííàÿ ìîùíîñòü Г­Г  ìíîãî ìåíüøå çàäàííîé ðàìïû, - //ГІГ® ðàìïà îãðàíè÷èâàåòñÿ çíà÷åíèåì èçìåðåííîé ïëþñ íåêîòîðàÿ äåëüòà - if ((Pzad_rmp > 0 && P_measured > 0) && - ((Pzad_rmp - P_measured) > P_DELTA_ZAD_IZM)) { - Pzad_rmp = P_measured + P_DELTA_ZAD_IZM; - } - if ((Pzad_rmp < 0 && P_measured < 0) && - ((Pzad_rmp - P_measured) < -P_DELTA_ZAD_IZM)) { - Pzad_rmp = P_measured - P_DELTA_ZAD_IZM; - } -#endif - - f.iq_p_rampa = Pzad_rmp; - - - //Защита от превышению винтом разрещённых оборотов - if(_IQabs(Frot) > IQ_170_RPM) - { - koef_spad = _IQdiv((IQ_170_RPM + IQ_10_RPM - _IQabs(Frot)), IQ_10_RPM); - if(koef_spad < 0) { - koef_spad = 0; - } - pidPvect.OutMax = _IQmpy(pidPvect.OutMax, koef_spad); - pidPvect.OutMin = _IQmpy(pidPvect.OutMin, koef_spad); - Pzad_rmp = _IQmpy(Pzad_rmp, koef_spad); - } - pidPvect.Ref = Pzad_rmp; - pidPvect.Fdb = P_measured; - - - pidPvect.calc(&pidPvect); - - Iq_out_unsat = pidPvect.Out; - - Iq_out_filter = Iq_out_unsat; // exp_regul_iq(koeff_Iq_filter, Iq_out_filter, Iq_out_unsat); - - //Г‚ ìîäåëè çäåñü Г­ГҐ áûëî îãðàíè÷åíèé - Iq_out_sat = _IQsat(Iq_out_filter, mzz_zad_int, -mzz_zad_int); //Test - - if(Iq_out_filter < 0) - { - Id_out_unsat = _IQdiv(_IQmpy((-Iq_out_filter), _IQsqrt(ONE_IQ24 - cos_fi.cos_fi_nom_squared)), cos_fi.cos_fi_nom); - } else { - Id_out_unsat = _IQdiv(_IQmpy(Iq_out_filter, _IQsqrt(ONE_IQ24 - cos_fi.cos_fi_nom_squared)), cos_fi.cos_fi_nom); - } - - if (_IQabs(Frot) < IQ_50_RPM) { - Id_out_max = zad_intensiv_q(5592, 5592, Id_out_max, Id_out_max_low_speed); //???? - } else { - Id_out_max = zad_intensiv_q(5592, 5592, Id_out_max, Id_out_max_full); - } - Id_out_sat = _IQsat(Id_out_unsat, Id_out_max, 0); - -// prev_Iq_zad = Iq_out_sat; - - *Iq_zad = Iq_out_sat; - *Id_zad = Id_out_sat; - -} - - diff --git a/Inu/Src2/VectorControl/regul_power.h b/Inu/Src2/VectorControl/regul_power.h deleted file mode 100644 index 2f1b127..0000000 --- a/Inu/Src2/VectorControl/regul_power.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef REGUL_POWER -#define REGUL_POWER -#include "IQmathLib.h" -#include "pid_reg3.h" - -void init_Pvect_pid(void); -void vector_power(_iq Pzad, _iq P_measured, _iq Iq, int mode, _iq Frot, _iq* Iq_zad, _iq* Id_zad); - -extern PIDREG3 pidPvect; - -extern _iq Id_out_max_low_speed; -extern _iq Id_out_max_full; - - -#define IQ_5_RPM 69905L //5об/мин -#define IQ_10_RPM 139810L -#define IQ_20_RPM 279620L -#define IQ_50_RPM 699050L -#define IQ_135_RPM 1887436L -#define IQ_165_RPM 2306867L //165об/мин -#define IQ_170_RPM 2376772L //170об/мин -#define IQ_175_RPM 2446677L -#define IQ_190_RPM 2656392L -#define IQ_250_RPM 3495253L -#define IQ_255_RPM 3565158L - - -#define ID_OUT_SAT_POWER 800 //0.456 ~ sin(Fi) -#define ID_OUT_SAT_POWER_LOW_SPEED (500.0) //0.52 ~ sin(Fi) - - -#endif //REGUL_POWER diff --git a/Inu/Src2/VectorControl/regul_turns.c b/Inu/Src2/VectorControl/regul_turns.c deleted file mode 100644 index 444547f..0000000 --- a/Inu/Src2/VectorControl/regul_turns.c +++ /dev/null @@ -1,185 +0,0 @@ -#include "IQmathLib.h" -#include "math.h" -#include "params.h" -#include "adc_tools.h" -#include "regul_turns.h" -#include "pid_reg3.h" -#include "vector.h" -#include "teta_calc.h" -#include "pwm_vector_regul.h" -#include "my_filter.h" - -// #pragma DATA_SECTION(pidFvect,".fast_vars1"); -PIDREG3 pidFvect = PIDREG3_DEFAULTS; - -#define MAX_PID_CURRENT IQ_OUT_NOM - -#define IQ_165_RPM 2306867 //165об/мин -#define IQ_170_RPM 2376772 //170об/мин -#define IQ_5_RPM 69905 //5об/мин - -#define TIME_RMP_FAST 10.0 //sec -#define TIME_RMP_SLOW 30.0 //sec -#define F_DEST 3.0 //Hz - -void init_Fvect_pid() -{ - pidFvect.Ref = 0; - pidFvect.Kp = _IQ(10.0);//_IQ(30.0);// // - pidFvect.Ki = _IQ(0.03); //_IQ(0.015); - pidFvect.Kc = _IQ(0.5); - pidFvect.OutMax = _IQ(MAX_PID_CURRENT / NORMA_ACP); - pidFvect.OutMin = -_IQ(MAX_PID_CURRENT / NORMA_ACP); -} - -void reset_F_pid() -{ - pidFvect.Up = 0; - pidFvect.Up1 = 0; - pidFvect.Ui = 0; - pidFvect.Ud = 0; - pidFvect.Out = 0; -} - -void vector_turns(_iq Fzad, _iq Frot, _iq Iq, int mode, _iq* Iq_zad, _iq* Id_zad) -{ - static _iq Fzad_rmp = 0, koef_fast = _IQ(F_DEST / (float)NORMA_FROTOR / TIME_RMP_SLOW / (float)FREQ_PWM / 2.5); - static _iq koef_slow = _IQ(F_DEST / (float)NORMA_FROTOR / TIME_RMP_SLOW / (float)FREQ_PWM / 5.0); -// static _iq cos_fi_nom = _IQ(COS_FI), cos_fi_nom_squared = _IQ(COS_FI * COS_FI); //prev_Fzad = 0, - static _iq Iq_out_max = _IQ(IQ_OUT_NOM / NORMA_ACP); - static _iq Id_out_max = _IQ(500.0 / NORMA_ACP); //_IQ(ID_OUT_NOM / NORMA_ACP); - static _iq mzz_zad_int=0; - static int Iq_rmp_to_optica = 0; -// static int flag_Iq_synced_with_optica = 0; -// static _iq step_Iq_rmp = _IQ(20.0 / NORMA_ACP); - _iq koef_rmp; //, koef_spad; - _iq Iq_out_unsat, Iq_out_sat, Id_out_sat, Id_out_unsat; - _iq deltaVar; - -// if (f.DownTemperature) { -// // mzz_zad_int = zad_intensiv_q(35480, 35480, mzz_zad_int, _IQmpy(Iq_out_max, temperature_limit_koeff)); -// mzz_zad_int = zad_intensiv_q(25480, 25480, mzz_zad_int, _IQmpy(f.iq_mzz_zad, temperature_limit_koeff)); -// } else - { - mzz_zad_int = zad_intensiv_q(35480, 35480, mzz_zad_int, f.iq_mzz_zad); -// mzz_zad_int = zad_intensiv_q(25480, 25480, mzz_zad_int, pid_Out_max); - } - - pidFvect.OutMax = Iq_out_max; - pidFvect.OutMin = -Iq_out_max; - - if (Fzad >= 0 && Frot > 0) { - pidFvect.OutMin = 0; - } - - if (Fzad <= 0 && Frot < 0) { - pidFvect.OutMax = 0; - } - - - - if((mode != 1) || (!f.Go)) //Заносим текущее состояние в регул-тор, что бы при смене режима не было скачков - { // - Fzad_rmp = Frot; -// prev_Fzad = Frot; - reset_F_pid(); //Было ниже, может быть что-то было не так - pidFvect.Ui = Iq; - pidFvect.Out = Iq; - *Iq_zad = Iq; - Iq_rmp_to_optica = Iq; -// *Id_zad = _IQdiv(_IQmpy(Iq, _IQsqrt(ONE_IQ24 - cos_fi.cos_fi_nom_squared)), cos_fi.cos_fi_nom); - if(!f.Go) - { - *Iq_zad = *Id_zad = 0; - } -// flag_Iq_synced_with_optica = 0; - return; - } - - //Синхронизация парных ПЧ - //Задание по Iq передаётся по оптической шине -// if ((f.flag_leading == 0) && (f.read_task_from_optical_bus == 1) && (f.sync_Iq_from_optical_bus == 1)) { -// // if (flag_Iq_synced_with_optica == 0) { -// // if (_IQabs(analog.iqIq_zad_from_optica - Iq_rmp_to_optica) > 1118481) { //200A -// // Iq_rmp_to_optica = zad_intensiv_q(step_Iq_rmp, step_Iq_rmp, Iq_rmp_to_optica, analog.iqIq_zad_from_optica); -// // } else { -// // Iq_rmp_to_optica = analog.iqIq_zad_from_optica; -// // flag_Iq_synced_with_optica = 1; -// // } -// // } else { -// // Iq_rmp_to_optica = analog.iqIq_zad_from_optica; -// // } -// Iq_rmp_to_optica = analog.iqIq_zad_from_optica; -// Iq_out_unsat = Iq_rmp_to_optica; -// Iq_out_sat = _IQsat(Iq_out_unsat, mzz_zad_int, -mzz_zad_int); -// Id_out_unsat = _IQdiv(_IQmpy(_IQabs(Iq_out_sat), _IQsqrt(ONE_IQ24 - cos_fi.cos_fi_nom_squared)), cos_fi.cos_fi_nom); -// Id_out_sat = _IQsat(Id_out_unsat, Id_out_max, 0); -// *Iq_zad = Iq_out_sat; -// *Id_zad = Id_out_sat; - -// reset_F_pid(); -// pidFvect.Ui = Iq_out_sat; -// pidFvect.Out = Iq_out_sat; -// Fzad_rmp = Frot; -// return; -// } - - //if(Fzad != prev_Fzad) //Рампа зависит от режима. Если просто повышение, то медленно. - //{ //Если понижение или реверс, то быстро. - if(_IQabs(Fzad_rmp) <= _IQabs(Fzad) && - (((Fzad >= 0) && (Fzad_rmp >= 0)) || ((Fzad < 0 ) && (Fzad_rmp < 0)))) - { - koef_rmp = koef_slow; - } - else - { - koef_rmp = koef_fast; - } -// prev_Fzad = Fzad; - //} - - // Fzad_rmp = zad_intensiv_q(koef_rmp, koef_rmp, Fzad_rmp, Fzad); -// logpar.log2 = (int16)(_IQtoIQ15(Fzad)); -// logpar.log19 = (int16)(_IQtoIQ15(Fzad_rmp)); - - //В какой-то момент перестала корректно работать функция zad_intensiv_q - // поэтому код из неё вставил сюда. - deltaVar = Fzad-Fzad_rmp; - - if ((deltaVar>koef_rmp) || (deltaVar<-koef_rmp)) - { - if (deltaVar>0) Fzad_rmp += koef_rmp; - else Fzad_rmp -= koef_rmp; - } - else - Fzad_rmp = Fzad; - - pidFvect.Ref = Fzad_rmp; - pidFvect.Fdb = Frot; - - pidFvect.calc(&pidFvect); - Iq_out_unsat = pidFvect.Out; - - //TODO: ATTENTION!!! worked better on stend - if (_IQabs(Iq_out_unsat) < 27962) //5A - { - pidTetta.Ui = 0; - pidTetta.SatErr = 0; - } - Iq_out_sat = _IQsat(Iq_out_unsat, Iq_out_max, -Iq_out_max); -// if(f.DownToNominal) //In this mode max I equial Inom -// { -// Iq_out_sat = _IQsat(Iq_out_unsat, I_OUT_NOMINAL_IQ, -I_OUT_NOMINAL_IQ); -// } - // Iq_out_sat = _IQsat(Iq_out_unsat, mzz_zad_int, -mzz_zad_int); //Test - //Расчёт d составл-ющей тока - Iq_out_unsat = _IQabs(Iq_out_unsat); - Id_out_unsat = _IQdiv(_IQmpy(Iq_out_unsat, _IQsqrt(ONE_IQ24 - cos_fi.cos_fi_nom_squared)), cos_fi.cos_fi_nom); - Id_out_sat = _IQsat(Id_out_unsat, Id_out_max, 0); - - - - *Iq_zad = Iq_out_sat; - *Id_zad = Id_out_sat; - -} diff --git a/Inu/Src2/VectorControl/regul_turns.h b/Inu/Src2/VectorControl/regul_turns.h deleted file mode 100644 index 57529b5..0000000 --- a/Inu/Src2/VectorControl/regul_turns.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef REGUL_TURNS -#define REGUL_TURNS -#include "IQmathLib.h" -#include "pid_reg3.h" - -void init_Fvect_pid(void); -void vector_turns(_iq Fzad, _iq Frot, _iq Iq, int mode, _iq* Iq_zad, _iq* Id_zad); - - -#endif //REGUL_TURNS - - diff --git a/Inu/Src2/VectorControl/teta_calc.c b/Inu/Src2/VectorControl/teta_calc.c deleted file mode 100644 index d76bfe5..0000000 --- a/Inu/Src2/VectorControl/teta_calc.c +++ /dev/null @@ -1,262 +0,0 @@ -#include "teta_calc.h" -#include "params.h" -#include "pid_reg3.h" -#include "IQmathLib.h" -#include "vector.h" -#include "my_filter.h" - -#define CONST_IQ_2PI 105414357 -#define PI 3.1415926535897932384626433832795 - -PIDREG3 pidTetta = PIDREG3_DEFAULTS; - -#define MAX_Ud_Pid_Out (167772 * 100) //419430 ~ 0.5 //251658 ~ 0.3 //209715 ~ 0.25 //167772 ~ 0.2Hz //100663 //0.12Hz -// 184549 ~ 2.2 - -#define MAX_Ud_Pid_Out_Id 176160 //0.2 ~ 167772 //0.21 ~ 176160 - //0.15 ~ 125829 -#define BPSI_START 0.17 //0.15 - -void init_tetta_pid() -{ - pidTetta.Ref = 0; - pidTetta.Fdb = 0; - pidTetta.Kp = _IQ(0.1); //_IQ(0.15); - pidTetta.Ki = _IQ(0.0003); //_IQ(0.00003) - pidTetta.Kc = _IQ(0.5); - pidTetta.OutMax = MAX_Ud_Pid_Out; - pidTetta.OutMin = -MAX_Ud_Pid_Out; - pidTetta.Up = 0; - pidTetta.Ui = 0; -} - -void reset_tetta_pid() -{ - pidTetta.Up = 0; - pidTetta.Up1 = 0; - pidTetta.Ui = 0; - pidTetta.Out = 0; -} - - -//#pragma CODE_SECTION(calc_tetta,".fast_run"); -void calc_tetta(_iq Frot, int direction, _iq Ud, int direct_zadan, _iq *tetta_out, _iq *Fsl_out, _iq *Fstator_out, int mode, int reset) // -{ - static _iq tetta = 0, Fsl_start = 0, bpsi_start = _IQ(BPSI_START / NORMA_FROTOR);// , bpsi_start_on_go = _IQ(0.1 / NORMA_FROTOR); - static _iq hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / FREQ_PWM / 2.0); - static int flag_start = 0; - static int koeff_zad_int = 30; //1000; - static long stop_frot = 27962; //2 rpm // 10000; -// static _iq prev_Fsl = 0; - static int flag_reverse = 0; -// static int flag_out_of_reverse = 0; - static int prev_direction = 0; - static _iq koeffKpRmp = _IQ(0.0003750); - static _iq koeffKiRmp = _IQ(0.00005); - static _iq lowSpeedKp = _IQ(0.1); - static _iq lowSpeedKi = _IQ(0.0003); - static _iq highSpeedKp = _IQ(0.01); - static _iq highSpeedKi = _IQ(0.011); //_IQ(0.02); - - _iq Fstat, Fsl; - int reverse_Ud = 1; - - if(reset == 1) - { - flag_start = 1; //Won`t work, if machine will stop without changing mode - Fsl_start = 0; - flag_reverse = 0; -// flag_out_of_reverse = 0; - } - if (_IQabs(Frot) < 768955) { //55 rpm - pidTetta.Kp = zad_intensiv_q(koeffKpRmp, koeffKpRmp, pidTetta.Kp, lowSpeedKp); - pidTetta.Ki = zad_intensiv_q(koeffKiRmp, koeffKiRmp, pidTetta.Ki, lowSpeedKi); - } - else if ((_IQabs(Frot) < 1118481)) { //80 rpm - pidTetta.Kp = zad_intensiv_q(koeffKpRmp, koeffKpRmp, pidTetta.Kp, highSpeedKp); - pidTetta.Ki = zad_intensiv_q(koeffKiRmp, koeffKiRmp, pidTetta.Ki, highSpeedKi); - } - //прюмое направление direction == 1 - //direction == 0 - двигатель стоит -// if(((Frot >= 0) && (direct_zadan == 1) && (direction >= 0)) || -// ((direct_zadan == -1) && (direction >= 0) && (Frot >= stop_frot))) - //27962 ~ 2 rpm -// if(((direct_zadan == 1) && (direction == 0)) || (direction > 0)) -// { -// Ud = -Ud; -// } - - - if(Frot >= 27962) { - reverse_Ud = -1; - flag_reverse = (Frot >= 27962 && direct_zadan == -1) ? 1 : 0; - prev_direction = 1; - } - else if (Frot <= -27962) { - reverse_Ud = 1; - flag_reverse = (Frot <= -27962 && direct_zadan == 1) ? 1 : 0; - prev_direction = -1; - } - if(_IQabs(Frot) < 27962) { - if (flag_reverse == 1) { - if (prev_direction == 1) { - reverse_Ud = -1; - } else { - reverse_Ud = 1; - } - } else -// if (flag_start) - { - if (direct_zadan == 1) { - reverse_Ud = -1; - } else { - reverse_Ud = 1; - } - } - } - Ud = Ud * reverse_Ud; - - pidTetta.Ref = Ud * 100; //Ref -заданое - pidTetta.calc(&pidTetta); - Fsl = pidTetta.Out / 100; - - if(flag_start) // - { - if(_IQabs(Frot) < stop_frot) - { - Fsl_start = bpsi_start * direct_zadan; //Если двигатель стоит, прибавл-ем скольжение. - } - else - { - if(Fsl_start == 0) - { - Fsl_start = bpsi_start * direct_zadan; //direction; - } - flag_start = 0; - } - - } - else - { - //Когда переходим через ноль, нужно добавить скольжение, т.к. регуляторы сами не поддерживают правильное состояние. - if(_IQabs(Frot) < (stop_frot)) - { -// if((direct_zadan == 1) && (Fsl + Fsl_start < bpsi_start)) -// { -// Fsl_start += (koeff_zad_int << 2); -//// Fsl_start += koeff_zad_int; -// } -// if((direct_zadan == -1) && (Fsl + Fsl_start > -bpsi_start)) -// { -// Fsl_start -= (koeff_zad_int << 2); -//// Fsl_start -= koeff_zad_int; -// } - } - else - { - if(_IQabs(Fsl_start) > koeff_zad_int) - { - if(Fsl_start > 0) - { - Fsl_start -= koeff_zad_int; - } - if(Fsl_start < 0) - { - Fsl_start += koeff_zad_int; - } - } - else - { - Fsl_start = 0; - } - } - - } - Fsl += Fsl_start; - Fstat = Frot * POLUS + Fsl; - tetta += _IQmpy(Fstat, hz_to_angle); - - - if (tetta > CONST_IQ_2PI) - { - tetta -= CONST_IQ_2PI; - } - - if (tetta < 0) - { - tetta += CONST_IQ_2PI; - } - *tetta_out = tetta; - *Fsl_out = Fsl; -// prev_Fsl = Fsl; - *Fstator_out = Fstat; - - -} - -TETTA_CALC tetta_calc = TETTA_CALC_DEF; - -void init_tetta_calc_struct() -{ - tetta_calc.Imds = 0; - tetta_calc.tetta = 0; - tetta_calc.k_r = _IQ(0.015); - tetta_calc.k_t = _IQ(0.0045); //_IQ(0.0045); - tetta_calc.hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / FREQ_PWM / 2.); -} - -void calc_tetta_Id(_iq Frot, _iq Id, _iq Iq, _iq *tetta_out, _iq *Fsl_out, _iq *Fstator_out, int reset) { - - _iq Fsl, Fst; - if (reset) { - tetta_calc.Imds = 0; - } - - tetta_calc.Imds = tetta_calc.Imds + _IQmpy(tetta_calc.k_r, (Id - tetta_calc.Imds)); - Fsl = _IQmpy(tetta_calc.k_t, Iq); - if (tetta_calc.Imds != 0) { - Fsl = _IQdiv(Fsl, tetta_calc.Imds); - } else { - Fsl = 0; - } - // Fsl = _IQ(0.2 / NORMA_FROTOR); - if (Fsl > MAX_Ud_Pid_Out_Id) { Fsl = MAX_Ud_Pid_Out_Id;} - if (Fsl < -MAX_Ud_Pid_Out_Id) { Fsl = -MAX_Ud_Pid_Out_Id;} - - Fst = Frot * POLUS + Fsl; - tetta_calc.tetta += _IQmpy(Fst, tetta_calc.hz_to_angle); - - if (tetta_calc.tetta > CONST_IQ_2PI) - { - tetta_calc.tetta -= CONST_IQ_2PI; - } - - if (tetta_calc.tetta < 0) - { - tetta_calc.tetta += CONST_IQ_2PI; - } - *Fsl_out = Fsl; - *tetta_out = tetta_calc.tetta; - *Fstator_out = Fst; - - -} - -#define LEVEL_REDUCE_UD 838860 //150V - -void correct_tetta_calc_Kt(void) { - static _iq coeff_add_Kt = _IQ(0.00005); - static _iq max_Kt = _IQ(0.0069); - static _iq min_Kt = _IQ(0.0029); - - if (tetta_calc.Imds > LEVEL_REDUCE_UD) { - tetta_calc.k_t -= coeff_add_Kt; - } - if (tetta_calc.Imds < -LEVEL_REDUCE_UD) { - tetta_calc.k_t += coeff_add_Kt; - } - if (tetta_calc.k_t > max_Kt) {tetta_calc.k_t = max_Kt; } - if (tetta_calc.k_t < min_Kt) {tetta_calc.k_t = min_Kt; } -} - - diff --git a/Inu/Src2/VectorControl/teta_calc.h b/Inu/Src2/VectorControl/teta_calc.h deleted file mode 100644 index b04dda5..0000000 --- a/Inu/Src2/VectorControl/teta_calc.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TETA_CALC -#define TETA_CALC - -#include "IQmathLib.h" -#include "pid_reg3.h" - -void init_tetta_pid(void); -void reset_tetta_pid(void); -void calc_tetta(_iq Frot, int direction, _iq Ud, int direct_zadan, _iq *tetta_out, _iq *Fsl_out, _iq *Fstator_out, int mode, int reset); -void calc_tetta_Id(_iq Frot, _iq Id, _iq Iq, _iq *tetta_out, _iq *Fsl_out, _iq *Fstator_out, int reset); -void init_tetta_calc_struct(void); - -// k_r = Ts / Tr_cm -// Tr_cm = Lr / Rr -// Lr - индуктивность ротора -// Rr - сопротивление ротора -// -// k_t = 1 / (Tr_cm * 2 * Pi * f_b) -// -// K = Ts * f_b -// f_b - базовая электрическая частота (12 Гц) -// Ts - период расчёта (840 Гц) - -typedef struct { - _iq Imds; - _iq tetta; - - _iq hz_to_angle; - _iq k_r; - _iq k_t; -} TETTA_CALC; - -#define TETTA_CALC_DEF {0,0,0,0,0} - -extern TETTA_CALC tetta_calc; - -extern PIDREG3 pidTetta; -#endif //TETA_CALC - diff --git a/Inu/Src2/551/main/281xEvTimersInit.c b/Inu/Src2/main/281xEvTimersInit.c similarity index 100% rename from Inu/Src2/551/main/281xEvTimersInit.c rename to Inu/Src2/main/281xEvTimersInit.c diff --git a/Inu/Src2/551/main/281xEvTimersInit.h b/Inu/Src2/main/281xEvTimersInit.h similarity index 100% rename from Inu/Src2/551/main/281xEvTimersInit.h rename to Inu/Src2/main/281xEvTimersInit.h diff --git a/Inu/Src2/551/main/CAN_project.h b/Inu/Src2/main/CAN_project.h similarity index 100% rename from Inu/Src2/551/main/CAN_project.h rename to Inu/Src2/main/CAN_project.h diff --git a/Inu/Src2/main/IQmathLib.c b/Inu/Src2/main/IQmathLib.c deleted file mode 100644 index 5720d7e..0000000 --- a/Inu/Src2/main/IQmathLib.c +++ /dev/null @@ -1,182 +0,0 @@ -#include "IQmathLib.h" - - -// Преобразование числа СЃ плавающей точкой РІ число СЃ фиксированной точкой -#define float_to_fixed(A) (long)((A)*(1 << (GLOBAL_Q)) + (A > 0 ? 0.5: -0.5)) -// Преобразование числа СЃ плавающей точкой РІ число СЃ фиксированной точкой СЃ выбором числа Р±РёС‚, отдаваемых РїРѕРґ РґСЂРѕР±РЅСѓСЋ часть -#define float_to_fixed_base_select(A, F_BITS) (long)((A)*(1 << (F_BITS)) + (A > 0 ? 0.5: -0.5)) -// Преобразование целого числа РІ число СЃ фиксированной точкой -#define int_to_fixed(A) (long)((A) << (GLOBAL_Q)) -// Преобразование целого числа РІ число СЃ фиксированной точкой СЃ выбором числа Р±РёС‚, отдаваемых РїРѕРґ РґСЂРѕР±РЅСѓСЋ часть -#define int_to_fixed_base_select(A, F_BITS) (long)((A) << (F_BITS)) -//Преобразование числа СЃ фиксированной точкой РІ число СЃ плавающей точкой -#define fixed_to_float(A) ((double)A / (1 << GLOBAL_Q)) -//Перобразование числа СЃ фиксированной точкой РІ целое число -#define fixed_to_int(A) ((int)(A >> GLOBAL_Q) ) - - -long multiply(long x, long y) -{ - long long z = (long long)x * (long long)y; - return (long)(z >> GLOBAL_Q); -} -//служебная функция. Умножает числа СЃ 27 битами, отданными РїРѕРґ РґСЂРѕР±РЅСѓСЋ часть -static inline long multiply_27(long x, long y) -{ - long long z = (long long)x * (long long)y; - return z & 0x4000000 ? (long)(z >> 27) + 1 : (long)(z >> 27); -} - -long long multiply_fixed_base_select(long long x, long long y, int base) -{ - long long z = (long long)x * (long long)y; - return z & (1 << base) ? (z >> base) + 1 : (z >> base); -} - -long divide(long num, long den) -{ - long long numLong = (long long)num; - long long quotient = (numLong << GLOBAL_Q) / den; - return (long)quotient; -} -// -static inline long long divide_fixed_base_select(long long num, long long den, int base) -{ - long long quotient = ((long long)num << base) / den; - return quotient; -} - -#define div_def(A,B) (long)(((long long)(A) << 24)/(B)) -#define div_mod(A,B) (A)%(B) -#define mult_def(A,B) (long)((((long long)(A))*((long long)(B))) >> 24) -#define abs_def(A) ((A) > 0 ? (A): -(A)) - -long sin_fixed(long x) -{ - //Константы сделал ститическими, что Р±С‹ РѕРЅРё вычислялись РІРѕ время запуска программы, Р° РЅРµ исполнения - static long FIXED_2PI = float_to_fixed(TWO_PI); - static long FIXED_PI = float_to_fixed(PI); - static long FIXED_PIna2 = float_to_fixed(PI_2); - //Здесть так же что Р±С‹ РЅРµ производить операции деления посчитал констаны СЂСЏРґР° Тейлора - static long one_110 = float_to_fixed_base_select(1./110, 27); - static long one_72 = float_to_fixed_base_select(1./72, 27); - static long one_42 = float_to_fixed_base_select(1./42, 27); - static long one_20= float_to_fixed_base_select(1./20, 27); - static long one_6 = float_to_fixed_base_select(1./6, 27); - - long long xx, tmp ; - while(x >= FIXED_2PI) { x -= FIXED_2PI;} //Помещаю аргумент РІ диапазон 2 РџР - while(x <= -FIXED_2PI) { x += FIXED_2PI;} - //Так как СЂСЏРґС‹ быстрее сходнятся РїСЂРё малых значениях, помещаю значение аргумента - //РІ ближайшие Рє нулю области - if(x > FIXED_PI) - { - x -= FIXED_2PI; - } - else if(x < -FIXED_PI) - { - x += FIXED_2PI; - } - if(x < -FIXED_PIna2) - { - x = -FIXED_PI - x; - } - else if(x > FIXED_PIna2) - { - x = FIXED_PI - x; - } - //проверяю СѓРіРѕР» РЅР° значения, РїСЂРё которых СЃРёРЅСѓСЃ раве 0 или 1 - if(x == 0) return 0; - if(x == FIXED_PIna2) return int_to_fixed(1); - if(x == -FIXED_PIna2) return int_to_fixed(-1); - //Перевожу РІ формат СЃ максимальной точностью для возможного дипазано значений - x <<= (27 - GLOBAL_Q); - //Считаю СЂСЏРґ фурье - xx = multiply_27(x, x); - tmp = ONE_27 - multiply_27(one_110, xx); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_72); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_42); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_20); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_6); - tmp = multiply_27(x, tmp); - return tmp >> (27 - GLOBAL_Q); //Перед возвращением РёР· функции преобразую РІ первоначальный формат -} - -long cos_fixed(long x) -{ - //Константы сделал ститическими, что Р±С‹ РѕРЅРё вычислялись РІРѕ время запуска программы, Р° РЅРµ исполнения - static long FIXED_2PI = float_to_fixed(TWO_PI); - static long FIXED_PI = float_to_fixed(PI); - static long FIXED_PIna2 = float_to_fixed(PI_2); - //Здесть так же что Р±С‹ РЅРµ производить операции деления посчитал констаны СЂСЏРґР° Тейлора - static long one_132 = float_to_fixed_base_select(1./132, 27); - static long one_90 = float_to_fixed_base_select(1./90, 27); - static long one_56 = float_to_fixed_base_select(1./56, 27); - static long one_30 = float_to_fixed_base_select(1./30, 27); - static long one_12 = float_to_fixed_base_select(1./12, 27); - - long xx, tmp, counter = 0; - while(x >= FIXED_2PI) { x -= FIXED_2PI;} //Помещаю аргумент РІ диапазон 2 РџР - while(x < 0) { x += FIXED_2PI;} - x = _IQabs(x); //Так как РєРѕСЃРёРЅСѓСЃ симметричен относительно нуля, нахожу его модуль - //проверяю СѓРіРѕР» РЅР° значения, РїСЂРё которых СЃРёРЅСѓСЃ раве 0 или 1 - if(x == 0) return 1 << GLOBAL_Q; - if(x == FIXED_PI) return -(1 << GLOBAL_Q); - if(x == (FIXED_PIna2) || (x == FIXED_3PIna2))return 0; - //Так как СЂСЏРґС‹ быстрее сходнятся РїСЂРё малых значениях, помещаю значение аргумента - //РІ ближайшие Рє нулю области - while(x > FIXED_PIna2) - { - x -= FIXED_PIna2; - counter++; - } - - if(counter == 1 || counter == 3) { x = FIXED_PIna2 - x;} - //Перевожу РІ формат СЃ максимальной точностью для возможного дипазона значений - x <<= (27 - GLOBAL_Q); - //Считаю СЂСЏРґ фурье - xx = multiply_27(x, x); - tmp = ONE_27 - multiply_27(xx, one_132); - tmp= multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(xx, one_90); - tmp= multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_56); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_30); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - multiply_27(tmp, one_12); - tmp = multiply_27(xx, tmp); - tmp = ONE_27 - (tmp >> 1); - tmp >>= (27 - GLOBAL_Q); - return (counter == 0) || (counter == 3) ? tmp : -tmp; -} - -long sqrt_fixed(long x) -{ - int variable_size_bits = sizeof(x) << 3; - long average_val, prev_avg_val; - if(x <= 0) return 0; - while(!(x & (1 << --variable_size_bits))); //Нахожу старший значащий Р±РёС‚ - //Нахожу приближение РєРѕСЂРЅСЏ СЃРґРІРіРѕРј РЅР° половину числа Р±РёС‚ между старшим значащим битом - //Рё положением точки - if(variable_size_bits > GLOBAL_Q) - { - average_val = x >> ((variable_size_bits - GLOBAL_Q) >> 1); - } - else - { - average_val = x << ((GLOBAL_Q - variable_size_bits) >> 1); - } - prev_avg_val = divide(x, average_val); //Нахожу 1/Рђ - //Р’ цикле нахожу среднее арифметическое между Рђ Рё 1/Рђ, РїРѕРєР° число РЅРµ перестанет меняться - while(_IQabs(prev_avg_val - average_val) > 1) - { - prev_avg_val = average_val; - average_val = (average_val + divide(x, average_val)) >> 1; - } - return average_val; -} diff --git a/Inu/Src2/main/IQmathLib.h b/Inu/Src2/main/IQmathLib.h deleted file mode 100644 index 0e52bad..0000000 --- a/Inu/Src2/main/IQmathLib.h +++ /dev/null @@ -1,661 +0,0 @@ -/** -* Иммитация библиотеки IQmath для тестирования в MATLAB -* -*/ -#ifndef IQ_MATH_LIB -#define IQ_MATH_LIB - - -#ifndef GLOBAL_Q -#define GLOBAL_Q 24 -#endif - -typedef long _iq; -typedef long _iq30; -typedef long _iq29; -typedef long _iq28; -typedef long _iq27; -typedef long _iq26; -typedef long _iq25; -typedef long _iq24; -typedef long _iq23; -typedef long _iq22; -typedef long _iq21; -typedef long _iq20; -typedef long _iq19; -typedef long _iq18; -typedef long _iq17; -typedef long _iq16; -typedef long _iq15; -typedef long _iq14; -typedef long _iq13; -typedef long _iq12; -typedef long _iq11; -typedef long _iq10; -typedef long _iq9; -typedef long _iq8; -typedef long _iq7; -typedef long _iq6; -typedef long _iq5; -typedef long _iq4; -typedef long _iq3; -typedef long _iq2; -typedef long _iq1; - -//--------------------------------------------------------------------------- -#define _IQmpy2(A) ((A)<<1) -#define _IQmpy4(A) ((A)<<2) -#define _IQmpy8(A) ((A)<<3) -#define _IQmpy16(A) ((A)<<4) -#define _IQmpy32(A) ((A)<<5) -#define _IQmpy64(A) ((A)<<6) - -#define _IQdiv2(A) ((A)>>1) -#define _IQdiv4(A) ((A)>>2) -#define _IQdiv8(A) ((A)>>3) -#define _IQdiv16(A) ((A)>>4) -#define _IQdiv32(A) ((A)>>5) -#define _IQdiv64(A) ((A)>>6) -//--------------------------------------------------------------------------- -#define _IQ30(A) (long) ((A) * 1073741824.0L) -#define _IQ29(A) (long) ((A) * 536870912.0L) -#define _IQ28(A) (long) ((A) * 268435456.0L) -#define _IQ27(A) (long) ((A) * 134217728.0L) -#define _IQ26(A) (long) ((A) * 67108864.0L) -#define _IQ25(A) (long) ((A) * 33554432.0L) -#define _IQ24(A) (long) ((A) * 16777216.0L) -#define _IQ23(A) (long) ((A) * 8388608.0L) -#define _IQ22(A) (long) ((A) * 4194304.0L) -#define _IQ21(A) (long) ((A) * 2097152.0L) -#define _IQ20(A) (long) ((A) * 1048576.0L) -#define _IQ19(A) (long) ((A) * 524288.0L) -#define _IQ18(A) (long) ((A) * 262144.0L) -#define _IQ17(A) (long) ((A) * 131072.0L) -#define _IQ16(A) (long) ((A) * 65536.0L) -#define _IQ15(A) (long) ((A) * 32768.0L) -#define _IQ14(A) (long) ((A) * 16384.0L) -#define _IQ13(A) (long) ((A) * 8192.0L) -#define _IQ12(A) (long) ((A) * 4096.0L) -#define _IQ11(A) (long) ((A) * 2048.0L) -#define _IQ10(A) (long) ((A) * 1024.0L) -#define _IQ9(A) (long) ((A) * 512.0L) -#define _IQ8(A) (long) ((A) * 256.0L) -#define _IQ7(A) (long) ((A) * 128.0L) -#define _IQ6(A) (long) ((A) * 64.0L) -#define _IQ5(A) (long) ((A) * 32.0L) -#define _IQ4(A) (long) ((A) * 16.0L) -#define _IQ3(A) (long) ((A) * 8.0L) -#define _IQ2(A) (long) ((A) * 4.0L) -#define _IQ1(A) (long) ((A) * 2.0L) - -#if GLOBAL_Q == 30 -#define _IQ(A) _IQ30(A) -#endif -#if GLOBAL_Q == 29 -#define _IQ(A) _IQ29(A) -#endif -#if GLOBAL_Q == 28 -#define _IQ(A) _IQ28(A) -#endif -#if GLOBAL_Q == 27 -#define _IQ(A) _IQ27(A) -#endif -#if GLOBAL_Q == 26 -#define _IQ(A) _IQ26(A) -#endif -#if GLOBAL_Q == 25 -#define _IQ(A) _IQ25(A) -#endif -#if GLOBAL_Q == 24 -#define _IQ(A) _IQ24(A) -#endif -#if GLOBAL_Q == 23 -#define _IQ(A) _IQ23(A) -#endif -#if GLOBAL_Q == 22 -#define _IQ(A) _IQ22(A) -#endif -#if GLOBAL_Q == 21 -#define _IQ(A) _IQ21(A) -#endif -#if GLOBAL_Q == 20 -#define _IQ(A) _IQ20(A) -#endif -#if GLOBAL_Q == 19 -#define _IQ(A) _IQ19(A) -#endif -#if GLOBAL_Q == 18 -#define _IQ(A) _IQ18(A) -#endif -#if GLOBAL_Q == 17 -#define _IQ(A) _IQ17(A) -#endif -#if GLOBAL_Q == 16 -#define _IQ(A) _IQ16(A) -#endif -#if GLOBAL_Q == 15 -#define _IQ(A) _IQ15(A) -#endif -#if GLOBAL_Q == 14 -#define _IQ(A) _IQ14(A) -#endif -#if GLOBAL_Q == 13 -#define _IQ(A) _IQ13(A) -#endif -#if GLOBAL_Q == 12 -#define _IQ(A) _IQ12(A) -#endif -#if GLOBAL_Q == 11 -#define _IQ(A) _IQ11(A) -#endif -#if GLOBAL_Q == 10 -#define _IQ(A) _IQ10(A) -#endif -#if GLOBAL_Q == 9 -#define _IQ(A) _IQ9(A) -#endif -#if GLOBAL_Q == 8 -#define _IQ(A) _IQ8(A) -#endif -#if GLOBAL_Q == 7 -#define _IQ(A) _IQ7(A) -#endif -#if GLOBAL_Q == 6 -#define _IQ(A) _IQ6(A) -#endif -#if GLOBAL_Q == 5 -#define _IQ(A) _IQ5(A) -#endif -#if GLOBAL_Q == 4 -#define _IQ(A) _IQ4(A) -#endif -#if GLOBAL_Q == 3 -#define _IQ(A) _IQ3(A) -#endif -#if GLOBAL_Q == 2 -#define _IQ(A) _IQ2(A) -#endif -#if GLOBAL_Q == 1 -#define _IQ(A) _IQ1(A) -#endif - -//--------------------------------------------------------------------------- - -#define _IQ30toF(A) ((float) ((A) / 1073741824.0L)) -#define _IQ29toF(A) ((float) ((A) / 536870912.0L)) -#define _IQ28toF(A) ((float) ((A) / 268435456.0L)) -#define _IQ27toF(A) ((float) ((A) / 134217728.0L)) -#define _IQ26toF(A) ((float) ((A) / 67108864.0L)) -#define _IQ25toF(A) ((float) ((A) / 33554432.0L)) -#define _IQ24toF(A) ((float) ((A) / 16777216.0L)) -#define _IQ23toF(A) ((float) ((A) / 8388608.0L)) -#define _IQ22toF(A) ((float) ((A) / 4194304.0L)) -#define _IQ21toF(A) ((float) ((A) / 2097152.0L)) -#define _IQ20toF(A) ((float) ((A) / 1048576.0L)) -#define _IQ19toF(A) ((float) ((A) / 524288.0L)) -#define _IQ18toF(A) ((float) ((A) / 262144.0L)) -#define _IQ17toF(A) ((float) ((A) / 131072.0L)) -#define _IQ16toF(A) ((float) ((A) / 65536.0L)) -#define _IQ15toF(A) ((float) ((A) / 32768.0L)) -#define _IQ14toF(A) ((float) ((A) / 16384.0L)) -#define _IQ13toF(A) ((float) ((A) / 8192.0L)) -#define _IQ12toF(A) ((float) ((A) / 4096.0L)) -#define _IQ11toF(A) ((float) ((A) / 2048.0L)) -#define _IQ10toF(A) ((float) ((A) / 1024.0L)) -#define _IQ9toF(A) ((float) ((A) / 512.0L)) -#define _IQ8toF(A) ((float) ((A) / 256.0L)) -#define _IQ7toF(A) ((float) ((A) / 128.0L)) -#define _IQ6toF(A) ((float) ((A) / 64.0L)) -#define _IQ5toF(A) ((float) ((A) / 32.0L)) -#define _IQ4toF(A) ((float) ((A) / 16.0L)) -#define _IQ3toF(A) ((float) ((A) / 8.0L)) -#define _IQ2toF(A) ((float) ((A) / 4.0L)) -#define _IQ1toF(A) ((float) ((A) / 2.0L)) - -#if GLOBAL_Q == 30 -#define _IQtoF(A) _IQ30toF(A) -#endif -#if GLOBAL_Q == 29 -#define _IQtoF(A) _IQ29toF(A) -#endif -#if GLOBAL_Q == 28 -#define _IQtoF(A) _IQ28toF(A) -#endif -#if GLOBAL_Q == 27 -#define _IQtoF(A) _IQ27toF(A) -#endif -#if GLOBAL_Q == 26 -#define _IQtoF(A) _IQ26toF(A) -#endif -#if GLOBAL_Q == 25 -#define _IQtoF(A) _IQ25toF(A) -#endif -#if GLOBAL_Q == 24 -#define _IQtoF(A) _IQ24toF(A) -#endif -#if GLOBAL_Q == 23 -#define _IQtoF(A) _IQ23toF(A) -#endif -#if GLOBAL_Q == 22 -#define _IQtoF(A) _IQ22toF(A) -#endif -#if GLOBAL_Q == 21 -#define _IQtoF(A) _IQ21toF(A) -#endif -#if GLOBAL_Q == 20 -#define _IQtoF(A) _IQ20toF(A) -#endif -#if GLOBAL_Q == 19 -#define _IQtoF(A) _IQ19toF(A) -#endif -#if GLOBAL_Q == 18 -#define _IQtoF(A) _IQ18toF(A) -#endif -#if GLOBAL_Q == 17 -#define _IQtoF(A) _IQ17toF(A) -#endif -#if GLOBAL_Q == 16 -#define _IQtoF(A) _IQ16toF(A) -#endif -#if GLOBAL_Q == 15 -#define _IQtoF(A) _IQ15toF(A) -#endif -#if GLOBAL_Q == 14 -#define _IQtoF(A) _IQ14toF(A) -#endif -#if GLOBAL_Q == 13 -#define _IQtoF(A) _IQ13toF(A) -#endif -#if GLOBAL_Q == 12 -#define _IQtoF(A) _IQ12toF(A) -#endif -#if GLOBAL_Q == 11 -#define _IQtoF(A) _IQ11toF(A) -#endif -#if GLOBAL_Q == 10 -#define _IQtoF(A) _IQ10toF(A) -#endif -#if GLOBAL_Q == 9 -#define _IQtoF(A) _IQ9toF(A) -#endif -#if GLOBAL_Q == 8 -#define _IQtoF(A) _IQ8toF(A) -#endif -#if GLOBAL_Q == 7 -#define _IQtoF(A) _IQ7toF(A) -#endif -#if GLOBAL_Q == 6 -#define _IQtoF(A) _IQ6toF(A) -#endif -#if GLOBAL_Q == 5 -#define _IQtoF(A) _IQ5toF(A) -#endif -#if GLOBAL_Q == 4 -#define _IQtoF(A) _IQ4toF(A) -#endif -#if GLOBAL_Q == 3 -#define _IQtoF(A) _IQ3toF(A) -#endif -#if GLOBAL_Q == 2 -#define _IQtoF(A) _IQ2toF(A) -#endif -#if GLOBAL_Q == 1 -#define _IQtoF(A) _IQ1toF(A) -#endif - -#define _IQsat(A, Pos, Neg) ((A > Pos) ? Pos : (A < Neg) ? Neg : A) -//--------------------------------------------------------------------------- -#define _IQtoIQ30(A) ((long) (A) << (30 - GLOBAL_Q)) -#define _IQ30toIQ(A) ((long) (A) >> (30 - GLOBAL_Q)) - -#if (GLOBAL_Q >= 29) -#define _IQtoIQ29(A) ((long) (A) >> (GLOBAL_Q - 29)) -#define _IQ29toIQ(A) ((long) (A) << (GLOBAL_Q - 29)) -#else -#define _IQtoIQ29(A) ((long) (A) << (29 - GLOBAL_Q)) -#define _IQ29toIQ(A) ((long) (A) >> (29 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 28) -#define _IQtoIQ28(A) ((long) (A) >> (GLOBAL_Q - 28)) -#define _IQ28toIQ(A) ((long) (A) << (GLOBAL_Q - 28)) -#else -#define _IQtoIQ28(A) ((long) (A) << (28 - GLOBAL_Q)) -#define _IQ28toIQ(A) ((long) (A) >> (28 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 27) -#define _IQtoIQ27(A) ((long) (A) >> (GLOBAL_Q - 27)) -#define _IQ27toIQ(A) ((long) (A) << (GLOBAL_Q - 27)) -#else -#define _IQtoIQ27(A) ((long) (A) << (27 - GLOBAL_Q)) -#define _IQ27toIQ(A) ((long) (A) >> (27 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 26) -#define _IQtoIQ26(A) ((long) (A) >> (GLOBAL_Q - 26)) -#define _IQ26toIQ(A) ((long) (A) << (GLOBAL_Q - 26)) -#else -#define _IQtoIQ26(A) ((long) (A) << (26 - GLOBAL_Q)) -#define _IQ26toIQ(A) ((long) (A) >> (26 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 25) -#define _IQtoIQ25(A) ((long) (A) >> (GLOBAL_Q - 25)) -#define _IQ25toIQ(A) ((long) (A) << (GLOBAL_Q - 25)) -#else -#define _IQtoIQ25(A) ((long) (A) << (25 - GLOBAL_Q)) -#define _IQ25toIQ(A) ((long) (A) >> (25 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 24) -#define _IQtoIQ24(A) ((long) (A) >> (GLOBAL_Q - 24)) -#define _IQ24toIQ(A) ((long) (A) << (GLOBAL_Q - 24)) -#else -#define _IQtoIQ24(A) ((long) (A) << (24 - GLOBAL_Q)) -#define _IQ24toIQ(A) ((long) (A) >> (24 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 23) -#define _IQtoIQ23(A) ((long) (A) >> (GLOBAL_Q - 23)) -#define _IQ23toIQ(A) ((long) (A) << (GLOBAL_Q - 23)) -#else -#define _IQtoIQ23(A) ((long) (A) << (23 - GLOBAL_Q)) -#define _IQ23toIQ(A) ((long) (A) >> (23 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 22) -#define _IQtoIQ22(A) ((long) (A) >> (GLOBAL_Q - 22)) -#define _IQ22toIQ(A) ((long) (A) << (GLOBAL_Q - 22)) -#else -#define _IQtoIQ22(A) ((long) (A) << (22 - GLOBAL_Q)) -#define _IQ22toIQ(A) ((long) (A) >> (22 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 21) -#define _IQtoIQ21(A) ((long) (A) >> (GLOBAL_Q - 21)) -#define _IQ21toIQ(A) ((long) (A) << (GLOBAL_Q - 21)) -#else -#define _IQtoIQ21(A) ((long) (A) << (21 - GLOBAL_Q)) -#define _IQ21toIQ(A) ((long) (A) >> (21 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 20) -#define _IQtoIQ20(A) ((long) (A) >> (GLOBAL_Q - 20)) -#define _IQ20toIQ(A) ((long) (A) << (GLOBAL_Q - 20)) -#else -#define _IQtoIQ20(A) ((long) (A) << (20 - GLOBAL_Q)) -#define _IQ20toIQ(A) ((long) (A) >> (20 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 19) -#define _IQtoIQ19(A) ((long) (A) >> (GLOBAL_Q - 19)) -#define _IQ19toIQ(A) ((long) (A) << (GLOBAL_Q - 19)) -#else -#define _IQtoIQ19(A) ((long) (A) << (19 - GLOBAL_Q)) -#define _IQ19toIQ(A) ((long) (A) >> (19 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 18) -#define _IQtoIQ18(A) ((long) (A) >> (GLOBAL_Q - 18)) -#define _IQ18toIQ(A) ((long) (A) << (GLOBAL_Q - 18)) -#else -#define _IQtoIQ18(A) ((long) (A) << (18 - GLOBAL_Q)) -#define _IQ18toIQ(A) ((long) (A) >> (18 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 17) -#define _IQtoIQ17(A) ((long) (A) >> (GLOBAL_Q - 17)) -#define _IQ17toIQ(A) ((long) (A) << (GLOBAL_Q - 17)) -#else -#define _IQtoIQ17(A) ((long) (A) << (17 - GLOBAL_Q)) -#define _IQ17toIQ(A) ((long) (A) >> (17 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 16) -#define _IQtoIQ16(A) ((long) (A) >> (GLOBAL_Q - 16)) -#define _IQ16toIQ(A) ((long) (A) << (GLOBAL_Q - 16)) -#else -#define _IQtoIQ16(A) ((long) (A) << (16 - GLOBAL_Q)) -#define _IQ16toIQ(A) ((long) (A) >> (16 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 15) -#define _IQtoIQ15(A) ((long) (A) >> (GLOBAL_Q - 15)) -#define _IQ15toIQ(A) ((long) (A) << (GLOBAL_Q - 15)) -#define _IQtoQ15(A) ((long) (A) >> (GLOBAL_Q - 15)) -#define _Q15toIQ(A) ((long) (A) << (GLOBAL_Q - 15)) -#else -#define _IQtoIQ15(A) ((long) (A) << (15 - GLOBAL_Q)) -#define _IQ15toIQ(A) ((long) (A) >> (15 - GLOBAL_Q)) -#define _IQtoQ15(A) ((long) (A) << (15 - GLOBAL_Q)) -#define _Q15toIQ(A) ((long) (A) >> (15 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 14) -#define _IQtoIQ14(A) ((long) (A) >> (GLOBAL_Q - 14)) -#define _IQ14toIQ(A) ((long) (A) << (GLOBAL_Q - 14)) -#define _IQtoQ14(A) ((long) (A) >> (GLOBAL_Q - 14)) -#define _Q14toIQ(A) ((long) (A) << (GLOBAL_Q - 14)) -#else -#define _IQtoIQ14(A) ((long) (A) << (14 - GLOBAL_Q)) -#define _IQ14toIQ(A) ((long) (A) >> (14 - GLOBAL_Q)) -#define _IQtoQ14(A) ((long) (A) << (14 - GLOBAL_Q)) -#define _Q14toIQ(A) ((long) (A) >> (14 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 13) -#define _IQtoIQ13(A) ((long) (A) >> (GLOBAL_Q - 13)) -#define _IQ13toIQ(A) ((long) (A) << (GLOBAL_Q - 13)) -#define _IQtoQ13(A) ((long) (A) >> (GLOBAL_Q - 13)) -#define _Q13toIQ(A) ((long) (A) << (GLOBAL_Q - 13)) -#else -#define _IQtoIQ13(A) ((long) (A) << (13 - GLOBAL_Q)) -#define _IQ13toIQ(A) ((long) (A) >> (13 - GLOBAL_Q)) -#define _IQtoQ13(A) ((long) (A) << (13 - GLOBAL_Q)) -#define _Q13toIQ(A) ((long) (A) >> (13 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 12) -#define _IQtoIQ12(A) ((long) (A) >> (GLOBAL_Q - 12)) -#define _IQ12toIQ(A) ((long) (A) << (GLOBAL_Q - 12)) -#define _IQtoQ12(A) ((long) (A) >> (GLOBAL_Q - 12)) -#define _Q12toIQ(A) ((long) (A) << (GLOBAL_Q - 12)) -#else -#define _IQtoIQ12(A) ((long) (A) << (12 - GLOBAL_Q)) -#define _IQ12toIQ(A) ((long) (A) >> (12 - GLOBAL_Q)) -#define _IQtoQ12(A) ((long) (A) << (12 - GLOBAL_Q)) -#define _Q12toIQ(A) ((long) (A) >> (12 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 11) -#define _IQtoIQ11(A) ((long) (A) >> (GLOBAL_Q - 11)) -#define _IQ11toIQ(A) ((long) (A) << (GLOBAL_Q - 11)) -#define _IQtoQ11(A) ((long) (A) >> (GLOBAL_Q - 11)) -#define _Q11toIQ(A) ((long) (A) << (GLOBAL_Q - 11)) -#else -#define _IQtoIQ11(A) ((long) (A) << (11 - GLOBAL_Q)) -#define _IQ11toIQ(A) ((long) (A) >> (11 - GLOBAL_Q)) -#define _IQtoQ11(A) ((long) (A) << (11 - GLOBAL_Q)) -#define _Q11toIQ(A) ((long) (A) >> (11 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 10) -#define _IQtoIQ10(A) ((long) (A) >> (GLOBAL_Q - 10)) -#define _IQ10toIQ(A) ((long) (A) << (GLOBAL_Q - 10)) -#define _IQtoQ10(A) ((long) (A) >> (GLOBAL_Q - 10)) -#define _Q10toIQ(A) ((long) (A) << (GLOBAL_Q - 10)) -#else -#define _IQtoIQ10(A) ((long) (A) << (10 - GLOBAL_Q)) -#define _IQ10toIQ(A) ((long) (A) >> (10 - GLOBAL_Q)) -#define _IQtoQ10(A) ((long) (A) << (10 - GLOBAL_Q)) -#define _Q10toIQ(A) ((long) (A) >> (10 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 9) -#define _IQtoIQ9(A) ((long) (A) >> (GLOBAL_Q - 9)) -#define _IQ9toIQ(A) ((long) (A) << (GLOBAL_Q - 9)) -#define _IQtoQ9(A) ((long) (A) >> (GLOBAL_Q - 9)) -#define _Q9toIQ(A) ((long) (A) << (GLOBAL_Q - 9)) -#else -#define _IQtoIQ9(A) ((long) (A) << (9 - GLOBAL_Q)) -#define _IQ9toIQ(A) ((long) (A) >> (9 - GLOBAL_Q)) -#define _IQtoQ9(A) ((long) (A) << (9 - GLOBAL_Q)) -#define _Q9toIQ(A) ((long) (A) >> (9 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 8) -#define _IQtoIQ8(A) ((long) (A) >> (GLOBAL_Q - 8)) -#define _IQ8toIQ(A) ((long) (A) << (GLOBAL_Q - 8)) -#define _IQtoQ8(A) ((long) (A) >> (GLOBAL_Q - 8)) -#define _Q8toIQ(A) ((long) (A) << (GLOBAL_Q - 8)) -#else -#define _IQtoIQ8(A) ((long) (A) << (8 - GLOBAL_Q)) -#define _IQ8toIQ(A) ((long) (A) >> (8 - GLOBAL_Q)) -#define _IQtoQ8(A) ((long) (A) << (8 - GLOBAL_Q)) -#define _Q8toIQ(A) ((long) (A) >> (8 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 7) -#define _IQtoIQ7(A) ((long) (A) >> (GLOBAL_Q - 7)) -#define _IQ7toIQ(A) ((long) (A) << (GLOBAL_Q - 7)) -#define _IQtoQ7(A) ((long) (A) >> (GLOBAL_Q - 7)) -#define _Q7toIQ(A) ((long) (A) << (GLOBAL_Q - 7)) -#else -#define _IQtoIQ7(A) ((long) (A) << (7 - GLOBAL_Q)) -#define _IQ7toIQ(A) ((long) (A) >> (7 - GLOBAL_Q)) -#define _IQtoQ7(A) ((long) (A) << (7 - GLOBAL_Q)) -#define _Q7toIQ(A) ((long) (A) >> (7 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 6) -#define _IQtoIQ6(A) ((long) (A) >> (GLOBAL_Q - 6)) -#define _IQ6toIQ(A) ((long) (A) << (GLOBAL_Q - 6)) -#define _IQtoQ6(A) ((long) (A) >> (GLOBAL_Q - 6)) -#define _Q6toIQ(A) ((long) (A) << (GLOBAL_Q - 6)) -#else -#define _IQtoIQ6(A) ((long) (A) << (6 - GLOBAL_Q)) -#define _IQ6toIQ(A) ((long) (A) >> (6 - GLOBAL_Q)) -#define _IQtoQ6(A) ((long) (A) << (6 - GLOBAL_Q)) -#define _Q6toIQ(A) ((long) (A) >> (6 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 5) -#define _IQtoIQ5(A) ((long) (A) >> (GLOBAL_Q - 5)) -#define _IQ5toIQ(A) ((long) (A) << (GLOBAL_Q - 5)) -#define _IQtoQ5(A) ((long) (A) >> (GLOBAL_Q - 5)) -#define _Q5toIQ(A) ((long) (A) << (GLOBAL_Q - 5)) -#else -#define _IQtoIQ5(A) ((long) (A) << (5 - GLOBAL_Q)) -#define _IQ5toIQ(A) ((long) (A) >> (5 - GLOBAL_Q)) -#define _IQtoQ5(A) ((long) (A) << (5 - GLOBAL_Q)) -#define _Q5toIQ(A) ((long) (A) >> (5 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 4) -#define _IQtoIQ4(A) ((long) (A) >> (GLOBAL_Q - 4)) -#define _IQ4toIQ(A) ((long) (A) << (GLOBAL_Q - 4)) -#define _IQtoQ4(A) ((long) (A) >> (GLOBAL_Q - 4)) -#define _Q4toIQ(A) ((long) (A) << (GLOBAL_Q - 4)) -#else -#define _IQtoIQ4(A) ((long) (A) << (4 - GLOBAL_Q)) -#define _IQ4toIQ(A) ((long) (A) >> (4 - GLOBAL_Q)) -#define _IQtoQ4(A) ((long) (A) << (4 - GLOBAL_Q)) -#define _Q4toIQ(A) ((long) (A) >> (4 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 3) -#define _IQtoIQ3(A) ((long) (A) >> (GLOBAL_Q - 3)) -#define _IQ3toIQ(A) ((long) (A) << (GLOBAL_Q - 3)) -#define _IQtoQ3(A) ((long) (A) >> (GLOBAL_Q - 3)) -#define _Q3toIQ(A) ((long) (A) << (GLOBAL_Q - 3)) -#else -#define _IQtoIQ3(A) ((long) (A) << (3 - GLOBAL_Q)) -#define _IQ3toIQ(A) ((long) (A) >> (3 - GLOBAL_Q)) -#define _IQtoQ3(A) ((long) (A) << (3 - GLOBAL_Q)) -#define _Q3toIQ(A) ((long) (A) >> (3 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 2) -#define _IQtoIQ2(A) ((long) (A) >> (GLOBAL_Q - 2)) -#define _IQ2toIQ(A) ((long) (A) << (GLOBAL_Q - 2)) -#define _IQtoQ2(A) ((long) (A) >> (GLOBAL_Q - 2)) -#define _Q2toIQ(A) ((long) (A) << (GLOBAL_Q - 2)) -#else -#define _IQtoIQ2(A) ((long) (A) << (2 - GLOBAL_Q)) -#define _IQ2toIQ(A) ((long) (A) >> (2 - GLOBAL_Q)) -#define _IQtoQ2(A) ((long) (A) << (2 - GLOBAL_Q)) -#define _Q2toIQ(A) ((long) (A) >> (2 - GLOBAL_Q)) -#endif - -#if (GLOBAL_Q >= 1) -#define _IQtoQ1(A) ((long) (A) >> (GLOBAL_Q - 1)) -#define _Q1toIQ(A) ((long) (A) << (GLOBAL_Q - 1)) -#else -#define _IQtoQ1(A) ((long) (A) << (1 - GLOBAL_Q)) -#define _Q1toIQ(A) ((long) (A) >> (1 - GLOBAL_Q)) -#endif - -#define _IQtoIQ1(A) ((long) (A) >> (GLOBAL_Q - 1)) -#define _IQ1toIQ(A) ((long) (A) << (GLOBAL_Q - 1)) - -///////////////////////////////////////////////////////////// -long multiply(long x, long y); -long long multiply_fixed_base_select(long long x, long long y, int base); -long divide(long num, long den); -long sin_fixed(long x); -long cos_fixed(long x); -long sqrt_fixed(long x); - -#define _IQabs(A) ((A) > 0 ? (A): -(A)) -#define _IQmpy(A,B) multiply(A,B) -#define _IQ19mpy(A,B) multiply_fixed_base_select(A,B,19) -#define _IQdiv(A,B) divide(A,B) -#define _IQsin(A) sin_fixed(A) -#define _IQcos(A) cos_fixed(A) -#define _IQsqrt(A) sqrt_fixed(A) - -#define PI 3.1415926535897932384626433832795 -#define PI_2 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 - -#ifndef ONE_24 -#define ONE_24 16777216 -#endif -#ifndef ONE_27 -#define ONE_27 134217728 -#endif -#ifndef ONE_28 -#define ONE_28 268435456 -#endif - -// #ifndef FIXED_PI -// #define FIXED_PI 52707179 -// #endif - -// #ifndef FIXED_2PI -// #define FIXED_2PI 105414357 -// #endif - -#ifndef FIXED_PI_30 -#define FIXED_PI_30 3373259426 -#endif - -#ifndef FIXED_2PI_30 -#define FIXED_2PI_30 6746518852 -#endif - -#ifndef FIXED_3PIna2 -#define FIXED_3PIna2 79060768 -#endif - -#ifndef FIXED_PIna3 -#define FIXED_PIna3 17569059 -#endif - -#ifndef FIXED_PIna6 -#define FIXED_PIna6 8784529 -#endif - - -#endif //IQ_MATH_LIB diff --git a/Inu/Src2/551/main/Main.c b/Inu/Src2/main/Main.c similarity index 100% rename from Inu/Src2/551/main/Main.c rename to Inu/Src2/main/Main.c diff --git a/Inu/Src2/551/main/PWMTMSHandle.c b/Inu/Src2/main/PWMTMSHandle.c similarity index 100% rename from Inu/Src2/551/main/PWMTMSHandle.c rename to Inu/Src2/main/PWMTMSHandle.c diff --git a/Inu/Src2/551/main/PWMTMSHandle.h b/Inu/Src2/main/PWMTMSHandle.h similarity index 100% rename from Inu/Src2/551/main/PWMTMSHandle.h rename to Inu/Src2/main/PWMTMSHandle.h diff --git a/Inu/Src2/main/PWMTools.c b/Inu/Src2/main/PWMTools.c index 561b909..b62f7b3 100644 --- a/Inu/Src2/main/PWMTools.c +++ b/Inu/Src2/main/PWMTools.c @@ -1,719 +1,2438 @@ +#include +#include +#include +#include +#include +#include //22.06 +#include +#include +#include +#include +//#include +#include #include -#include -//#include "project.h" +#include //22.06 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "f281xpwm.h" +//#include "SpaceVectorPWM.h" +#include "CAN_Setup.h" +#include "global_time.h" #include "IQmathLib.h" -//#include "f281xpwm.h" +#include "mathlib.h" +#include "oscil_can.h" +#include "rmp_cntl_v1.h" +#include "uf_alg_ing.h" +#include "vhzprof.h" +#include "vector_control.h" +#include "MemoryFunctions.h" +#include "RS_Functions.h" +#include "TuneUpPlane.h" +#include "xp_write_xpwm_time.h" +#include "pwm_test_lines.h" +#include "detect_errors.h" +#include "modbus_table_v2.h" +#include "params_alg.h" +#include "v_rotor_22220.h" +#include "log_to_memory.h" +#include "log_params.h" +#include "limit_power.h" +#include "pwm_logs.h" +#include "optical_bus_tools.h" +#include "ramp_zadanie_tools.h" +#include "pll_tools.h" + + +///////////////////////////////////// +#if (_SIMULATE_AC==1) +#include "sim_model.h" +#endif + +//#pragma DATA_SECTION(freq1,".fast_vars1"); +//_iq freq1; + +//#pragma DATA_SECTION(k1,".fast_vars1"); +//_iq k1 = 0; + +#define ENABLE_LOG_INTERRUPTS 0 //1 + + +#if (ENABLE_LOG_INTERRUPTS) + +#pragma DATA_SECTION(log_interrupts,".slow_vars"); +#define MAX_COUNT_LOG_INTERRUPTS 100 +unsigned int log_interrupts[MAX_COUNT_LOG_INTERRUPTS+2] = {0}; + + + + +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// + + +void add_log_interrupts(int cmd) +{ + static int count_log_interrupst = 0; + + if (count_log_interrupst>=MAX_COUNT_LOG_INTERRUPTS) + count_log_interrupst = 0; + + + log_interrupts[count_log_interrupst++] = cmd; + log_interrupts[count_log_interrupst++] = EvbRegs.T3CNT; + + +//#if (ENABLE_LOG_INTERRUPTS) +// add_log_interrupts(0); +//#endif + +} + +#endif //if (ENABLE_LOG_INTERRUPTS) + + + +#pragma DATA_SECTION(iq_U_1_save,".fast_vars1"); +_iq iq_U_1_save = 0; +#pragma DATA_SECTION(iq_U_2_save,".fast_vars1"); +_iq iq_U_2_save = 0; + + +unsigned int enable_calc_vector = 0; + + + +//WINDING winding1 = WINDING_DEFAULT; + +//#define COUNT_SAVE_LOG_OFF 50 //Сколько тактов ШИМ сохранЯетсЯ после остановки +#define COUNT_START_IMP 5 //10 + +#define CONST_005 838860 +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + + +#pragma CODE_SECTION(global_time_interrupt,".fast_run2"); +void global_time_interrupt(void) +{ + +// inc_RS_timeout_cicle(); +// inc_CAN_timeout_cicle(); + +#if(_ENABLE_PWM_LINES_FOR_TESTS) +// PWM_LINES_TK_18_ON; +#endif + + if (edrk.disable_interrupt_timer3) + return; + +//i_led1_on_off(1); + + + if (sync_data.latch_interrupt && sync_data.enabled_interrupt) + { + // перезапуск прерывания тут! + // для исключения дребезга + start_sync_interrupt(); + } + +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(1); +#endif + + global_time.calc(&global_time); + +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(101); +#endif + +/* +static unsigned int oldest_time = 0, time_pause = TIME_PAUSE_MODBUS_REMOUTE; +control_station_test_alive_all_control(); + if (detect_pause_milisec(time_pause,&oldest_time)) + modbusNetworkSharing(0); + + RS232_WorkingWith(0,1); +*/ + + +//i_led1_on_off(0); +#if(_ENABLE_PWM_LINES_FOR_TESTS) + // PWM_LINES_TK_18_OFF; +#endif +} + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +//#define get_tics_timer_pwm2(k) {time_buf2[k] = (EvbRegs.T3CNT-start_tics_4timer);k++;} +//unsigned int time_buf2[10] = {0}; + + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +#define PAUSE_INC_TIMEOUT_CICLE 10 // FREQPWM/10 +void pwm_inc_interrupt(void) +{ + static unsigned int t_inc = 0; + + if (t_inc>=PAUSE_INC_TIMEOUT_CICLE) + { + inc_RS_timeout_cicle(); + inc_CAN_timeout_cicle(); + t_inc = 0; + } + else + t_inc++; +} +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(pwm_analog_ext_interrupt,".fast_run2"); +void pwm_analog_ext_interrupt(void) +{ +// static int count_timer_buf2=0, start_tics_4timer = 0, c_rms = 0; +// static _iq prev_Iu=0, prev_Ua=0; + //static _iq iq_50hz_norma = _IQ(50.0/NORMA_FROTOR); + +// i_led2_on(); + + // подготовка подсчета времени работы в прерывании +// start_tics_4timer = EvaRegs.T1CNT; + +// count_timer_buf2 = 0; +// get_tics_timer_pwm2(count_timer_buf2); + + if (edrk.SumSbor == 1) { +// detect_protect_adc(uf_alg.tetta_bs, uf_alg.tetta_bs); + } + + + + calc_pll_50hz(); + // -////#include "SpaceVectorPWM.h" -//#include "MemoryFunctions.h" -//#include "PWMTools.h" -//#include "pwm_vector_regul.h" -//#include "PWMTMSHandle.h" -//#include "TuneUpPlane.h" -//#include "RS_Functions.h" -//#include "CAN_setup.h" -//#include "global_time.h" -#include "params.h" -#include "vector.h" -//#include "rmp_cntl_my1.h" -//#include "vhzprof.h" -//#include "adc_tools.h" -//#include "v_pwm24.h" -//#include "break_regul.h" -//#include "break_tools.h" -//#include "detect_phase.h" -//#include "mathlib.h" -//#include "project.h" -//#include "log_to_memory.h" -//#include "rotation_speed.h" -//#include "detect_overload.h" -//#include "xp_write_xpwm_time.h" -//#include "errors.h" -//#include "sync_tools.h" -//#include "optical_bus.h" -//#include "IQmathLib.h" +// if (c_rms>=9) +// { +// edrk.test_rms_Iu = calc_rms(analog.iqIu,prev_Iu,edrk. f_stator); +// edrk.test_rms_Ua = calc_rms(analog.iqUin_A1B1,prev_Ua, iq_50hz_norma); +// +// prev_Iu = analog.iqIu; +// prev_Ua = analog.iqUin_A1B1; +// c_rms = 0; +// } +// else +// c_rms++; -#define DEF_FREQ_PWM_XTICS (3750000 / FREQ_PWM / 2) -#define DEF_PERIOD_MIN_XTICS 400 //375 ~ 100mks //315 ~ 84 mks //460//(3750000 * mks / 1000000) -#define DEF_PERIOD_MIN_BR_XTICS 165 +// fill_RMS_buff_interrupt(uf_alg.tetta_bs, uf_alg.tetta_bs); -#define DEF_FREQ_PWM_XTICS_MIN = 4261 -#define DEF_FREQ_PWM_XTICS_MAX = 4687 - -#define STOP_ROTOR_LIMIT 27962 //2 rpm -#define STOP_ROTOR_MIN_CURRENT 4194304 //750A //3355443 //600A - -#define K_MODUL_MAX 15770583 //13421772 //80% //10066329 //60% //5033164 //30% 15099494 ~ 90% //15435038 ~ 0.92% - //15770583 ~ 0.94% -#define MIN_Fsl_WHEN_STOPED 41943 //0.05 //67108 //0.08Hz - -#define PWM_ONE_INTERRUPT_RUN 1 -#define PWM_TWICE_INTERRUPT_RUN 0 + // get_tics_timer_pwm2(count_timer_buf2); +// i_led2_off(); -//4464 -// Частота ШИМ в xilinx тиках (60000000 / 16 / FREQ_PWM = 3750000 / FREQ_PWM) -#pragma DATA_SECTION(VAR_FREQ_PWM_XTICS,".fast_vars1"); -int VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS; +// global_time.calc(&global_time); -// Минимальное значение ШИМа в xilinx тиках -#pragma DATA_SECTION(VAR_PERIOD_MAX_XTICS,".fast_vars1"); -int VAR_PERIOD_MAX_XTICS = DEF_FREQ_PWM_XTICS - DEF_PERIOD_MIN_XTICS; - -// Минимальное значение ШИМа в xilinx тиках (mintime+deadtime) (Fпилы * Tмин.ключа.сек = (60 / 16 / 2) * Tмкс = (60 * Tмкс / 16 / 2)) -#pragma DATA_SECTION(VAR_PERIOD_MIN_XTICS,".fast_vars1"); -int VAR_PERIOD_MIN_XTICS = DEF_PERIOD_MIN_XTICS;// - -// Минимальное значение ШИМа в xilinx тиках для тормозных ключей (mintime) (Fпилы * Tмин.ключа.сек = (60 / 16 / 2) * Tмкс = (60 * Tмкс / 16 / 2)) -#pragma DATA_SECTION(VAR_PERIOD_MIN_BR_XTICS,".fast_vars1"); -int VAR_PERIOD_MIN_BR_XTICS = DEF_PERIOD_MIN_BR_XTICS;// - -#pragma DATA_SECTION(freq1,".fast_vars1"); -_iq freq1; - -#pragma DATA_SECTION(k1,".fast_vars1"); -_iq k1 = 0; - -RMP_MY1 rmp_freq = RMP_MY1_DEFAULTS; -//VHZPROF vhz1 = VHZPROF_DEFAULTS; - -// WINDING a; -// FLAG f; - -#define COUNT_SAVE_LOG_OFF 100 //Сколько тактов ШИМ сохраняется после остановки -#define COUNT_START_IMP 2 - -int i = 0; -/*void InitPWM() -{ - WriteMemory(ADR_PWM_MODE_0, 0x0000); //Выбираем в качестве источника ШИМ TMS -}*/ - -static void write_swgen_pwm_times(); -void write_swgen_pwm_times_split_eages(unsigned int mode_reload); -void fix_pwm_freq_synchro_ain(); -void detect_level_interrupt(void); -void detect_current_saw_val(void); - -void InitXPWM(void) -{ - - #ifdef XPWMGEN - /* Start of PWM Generator initialization*/ - for(i = 0; i < 16; i++) // Обнуляем - { - WriteMemory(ADR_PWM_KEY_NUMBER, i); - WriteMemory(ADR_PWM_TIMING, 0); - - } - WriteMemory(ADR_PWM_DIRECT, 0xffff); - WriteMemory(ADR_PWM_DRIVE_MODE, 0); //Choose PWM sourse PWMGenerator on Spartan 200e - WriteMemory(ADR_PWM_DEAD_TIME, 360); //Dead time in tics. 1 tic = 16.67 nsec -#ifndef _test_without_power - // OFF WDOG - WriteMemory(ADR_PWM_WDOG, 0x8005); //TODO turn on -#else - // ON WDOG - WriteMemory(ADR_PWM_WDOG, 0x0005); //TODO turn on -#endif - WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec - WriteMemory(ADR_PWM_SAW_DIRECT, 0x0555); - WriteMemory(ADR_TK_MASK_0, 0); - WriteMemory(ADR_TK_MASK_1, 0xffff); //Turn off additional 16 tk lines -#if C_PROJECT_TYPE == PROJECT_BALZAM - WriteMemory(ADR_PWM_IT_TYPE, 1); //1 interrupt per PWM period -#else - WriteMemory(ADR_PWM_IT_TYPE, 0); //interrupt on each counter twist -#endif -// WriteMemory(ADR_PWM_WDOG, 0x8008);//разрешение ошибки по PWM - #endif - - #ifdef TMSPWMGEN - - WriteMemory(ADR_PWM_MODE_0, 0x0000); //Выбираем в качестве источника ШИМ TMS - - #endif - -/* End оf PWM Gen init */ -} - -void initPWM_Variables(void) -{ - //Для первой пилы закрыто, когда выше заданного уровня, для второй ниже -// xpwm_time.Tclosed_0 = 0; -// xpwm_time.Tclosed_1 = VAR_FREQ_PWM_XTICS + 1; -// xpwm_time.pwm_tics = VAR_FREQ_PWM_XTICS; -// xpwm_time.saw_direct.all = 0;//0x0555; -// xpwm_time.one_or_two_interrupts_run = PWM_TWICE_INTERRUPT_RUN; - - - init_alpha_pwm24(VAR_FREQ_PWM_XTICS); - InitVariablesSvgen(VAR_FREQ_PWM_XTICS); - init_DQ_pid(); - break_resistor_managment_init(); - - rmp_freq.RampLowLimit = _IQ(-4); //0 - rmp_freq.RampHighLimit = _IQ(4); - - rmp_freq.RampPlus = _IQ(0.00005); //_IQ(0.0002);_IQ(0.000005); - - rmp_freq.RampMinus = _IQ(-0.00005); //_IQ(-0.000005); - rmp_freq.DesiredInput = 0; - rmp_freq.Out = 0; - - a.k = 0; - a.k1 = 0; - a.k2 = 0; - - k1 = 0; - freq1 = 0; -} - -#pragma CODE_SECTION(start_PWM24,".fast_run2") -void start_PWM24(int O1, int O2) -{ - if ((O1 == 1) && (O2 == 1)) - { - start_pwm(); - } - else - { - if ((O1 == 0) && (O2 == 1)) - { - start_pwm_b(); - } - if ((O1 == 1) && (O2 == 0)) - { - start_pwm_a(); - } - } } +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// inline void init_regulators() { - if(f.Mode != 0) - { - pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor, - rotor.iqFout, f.Mode, 1, 1); - } +// if(f.Mode != 0) +// { +//// pwm_vector_model_titov(0, 0, /*rotor.iqW*/0, 0); +// } } -#define select_working_channels(go_a, go_b) go_a = !f.Obmotka1; \ - go_b = !f.Obmotka2; +#define select_working_channels(go_a, go_b) {go_a = !f.Obmotka1; \ + go_b = !f.Obmotka2;} -void PWM_interrupt() +#define MAX_COUNT_WAIT_GO_0 FREQ_PWM // 1 сек. + + +#define PAUSE_ERROR_DETECT_UPDATE_OPTBUS_DATA 900// ((unsigned int)(1*FREQ_PWM*2)) // ~1sec //50 +#define MAX_TIMER_WAIT_SET_TO_ZERO_ZADANIE 27000 //((unsigned int)(30*FREQ_PWM*2)) // 60 sec +//#define MAX_TIMER_WAIT_BOTH_READY2 108000 //(120*FREQ_PWM*2) // 120 sec +#define MAX_TIMER_WAIT_BOTH_READY2 216000 //(120*FREQ_PWM*2) // 240 sec +#define MAX_TIMER_WAIT_MASTER_SLAVE 4500 // 5 sec + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +//#define _ENABLE_PWM_LED2_PROFILE 1 + + +#if (_ENABLE_PWM_LED2_PROFILE) +unsigned int profile_pwm[30]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; +unsigned int pos_profile_pwm = 0; +#endif + +/////////////////////////////////////////////////////////////////// +#define _ENABLE_LOG_TICS_PWM 0//1 +#define _ENABLE_SLOW_PWM 0//1 +#define _ENABLE_INTERRUPT_PWM_LED2 0//1 + +#if (_ENABLE_LOG_TICS_PWM==1) + +static int c_run=0; +static int c_run_start=0; +static int i_log; + + +#pragma DATA_SECTION(time_buf,".slow_vars"); +#define MAX_COUNT_TIME_BUF 50 +int time_buf[MAX_COUNT_TIME_BUF] = {0}; + +//#define get_tics_timer_pwm(flag,k) {if (flag) {time_buf[k] = (unsigned int)(EvbRegs.T3CNT-start_tics_4timer);k++;}else{time_buf[k] = -1; k++;}} + +#define set_tics_timer_pwm(flag,k) { time_buf[k] = flag;k++; } + +//#define get_tics_timer_pwm(flag,k) if (flag) ? {time_buf[k] = (EvbRegs.T3CNT-start_tics_4timer);k++;} : {time_buf[k] = -1; k++;}; +static int count_timer_buf=0; + +#else + +#define get_tics_timer_pwm(flag) asm(" NOP;") +#define set_tics_timer_pwm(flag,k) asm(" NOP;") +//static int count_timer_buf=0; + +#endif + + +#if(_ENABLE_SLOW_PWM) +static int slow_pwm_pause = 0; +#endif + +unsigned int count_time_buf = 0; +int stop_count_time_buf=0; +unsigned int log_wait; + +unsigned int end_tics_4timer, start_tics_4timer; +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +#if (_ENABLE_LOG_TICS_PWM==1) +//#pragma CODE_SECTION(get_tics_timer_pwm,".fast_run"); +void get_tics_timer_pwm(unsigned int flag) { + unsigned int delta; + + if (flag) + { + delta = (unsigned int)(EvbRegs.T3CNT-start_tics_4timer); + if (count_timer_buf>=3) + time_buf[count_timer_buf] = delta - time_buf[count_timer_buf-2]; + else + time_buf[count_timer_buf] = delta; + time_buf[count_timer_buf] = time_buf[count_timer_buf]*33/1000; + count_timer_buf++; + } + else + { + time_buf[count_timer_buf] = -1; + count_timer_buf++; + } +} +#else + +#endif + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////// +// получаем данные с датчика оборотов +/////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(calc_rotors,".fast_run"); +void calc_rotors(int flag) +{ + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_17_ON; +#endif + + update_rot_sensors(); + + + + set_tics_timer_pwm(6,count_timer_buf); + get_tics_timer_pwm(flag); + + +#if(C_cds_in_number>=1) + project.cds_in[0].read_pbus(&project.cds_in[0]); + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_17_OFF; +#endif + +#if (_ENABLE_PWM_LED2_PROFILE) + if (profile_pwm[pos_profile_pwm++]) + i_led2_on_off(1); + else + i_led2_on_off(0); +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_19_ON; +#endif + +#if(SENSOR_ALG==SENSOR_ALG_23550) +// 23550 + RotorMeasureDetectDirection(); + RotorMeasure();// измеритель +#endif + +#if(SENSOR_ALG==SENSOR_ALG_22220) +// 22220 + Rotor_measure_22220(); + +#if (_ENABLE_PWM_LED2_PROFILE) + if (profile_pwm[pos_profile_pwm++]) + i_led2_on_off(1); + else + i_led2_on_off(0); +#endif + +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_19_OFF; +#endif + + set_tics_timer_pwm(7,count_timer_buf); + get_tics_timer_pwm(flag); + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_20_ON; +#endif + +// RotorMeasurePBus(); +#if(SENSOR_ALG==SENSOR_ALG_23550) +// 23550 + RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow, &WRotorPBus.RotorDirectionSlow2, &WRotorPBus.RotorDirectionCount); +#endif + +#if(SENSOR_ALG==SENSOR_ALG_22220) + // 22220 + // nothing +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_20_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_20_ON; +#endif + +#if(SENSOR_ALG==SENSOR_ALG_23550) +// 23550 + select_values_wrotor(); +#endif +#if(SENSOR_ALG==SENSOR_ALG_22220) +// 22220 + select_values_wrotor_22220(); + +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_20_OFF; +#endif + + set_tics_timer_pwm(8,count_timer_buf); + get_tics_timer_pwm(flag); + +#endif //(C_cds_in_number>=1) + + + edrk.rotor_direction = WRotor.RotorDirectionSlow; + +#if(SENSOR_ALG==SENSOR_ALG_23550) +// 23550 + edrk.iq_f_rotor_hz = WRotor.iqWRotorSumFilter; +#endif + +#if(SENSOR_ALG==SENSOR_ALG_22220) +// 22220 + edrk.iq_f_rotor_hz = WRotor.iqWRotorSum; +#endif + +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(calc_zadanie_rampa,".fast_run"); +void calc_zadanie_rampa(void) +{ +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_19_ON; +#endif + + + // подхват при смене режима + load_current_ramp_oborots_power(); + + if (edrk.StartGEDfromControl==0) + ramp_all_zadanie(2); // форсируем в ноль + else + if (edrk.flag_wait_set_to_zero_zadanie || edrk.flag_block_zadanie || edrk.Status_Ready.bits.ready_final==0 || /*edrk.StartGEDfromControl==0 ||*/ edrk.run_razbor_shema == 1) + ramp_all_zadanie(1); // стремим рампы в ноль, ка ктолько они доедут в ноль, то снимается edrk.StartGEDfromZadanie + else + ramp_all_zadanie(0); // тут все по штатному + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_19_OFF; +#endif + +} + +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(async_pwm_ext_interrupt,".fast_run2"); +void async_pwm_ext_interrupt(void) +{ + +#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_19_ON; +#endif + if (edrk.run_to_pwm_async) + { + PWM_interrupt(); + edrk.run_to_pwm_async = 0; + } + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_19_OFF; +#endif + +} +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +void run_detect_fast_error(void) +{ + + detect_error_u_zpt_fast(); + detect_error_u_in(); + +} +//////////////////////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(PWM_interrupt_main,".fast_run"); +void PWM_interrupt_main(void) +{ + +#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_16_ON; +#endif + + norma_adc_nc(0); + + edrk.run_to_pwm_async = 1; + +#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) + PWM_LINES_TK_16_OFF; +#endif + +} +//////////////////////////////////////////////////////////////////////////////// + + +#define MAX_COUNT_COUNTSTARTGEDFROMZADANIE FREQ_PWM //3000 // задержка в тактах появления единицы в edrk.StartGEDfromZadanie + + + +#pragma CODE_SECTION(PWM_interrupt,".fast_run"); +void PWM_interrupt(void) +{ + static unsigned int pwm_run = 0; - static _iq Uzad1, Fzad, Uzad2; - static int count_step=0; - static int count_step_ram_off = 0; - static int count_start_impuls = 0; - static int flag_record_log = 0; - static int log_saved_to_const_mem = 0; + static _iq Uzad1=0, Fzad=0, Uzad2=0, Izad_out = 0, Uzad_from_master = 0; + +// static int count_step_ram_off = 0; +// static int count_start_impuls = 0; + static int prevGo = -1; static volatile unsigned int go_a = 0; static volatile unsigned int go_b = 0; - static int stop_rotor_counter = 0; - - static int prev_go_a = 1; - static int prev_go_b = 1; + static int prev_go_a = 0; + static int prev_go_b = 0; - int pwm_enable_calc_main = 0; + static _iq iq_U_1_prev = 0; + static _iq iq_U_2_prev = 0; + static unsigned int prev_timer = 0; + unsigned int cur_timer; + static unsigned int count_lost_interrupt=0; + static int en_rotor = 1;//1; - int start_int_xtics = 0, end_int_xtics = 0; + static unsigned long timer_wait_set_to_zero_zadanie = 0; + static unsigned long timer_wait_both_ready2 = 0; -// i_led1_on_off(1); - if (pwm_run == 1) - { -// stop_pwm(); -// errors.slow_stop.bit.PWM_interrupt_to_long |= 1; - return; - } - pwm_run = 1; + static unsigned int prev_error_controller = 0,error_controller=0; + + static unsigned long time_delta = 0; + + static unsigned int run_calc_uf = 0, prev_run_calc_uf = 0, count_wait_go_0 = 0; + + int pwm_enable_calc_main = 0, pwm_up_down = 0, err_interr = 0, slow_error = 0; + + static unsigned int count_err_read_opt_bus = 0, prev_edrk_Kvitir = 0; + + static unsigned int count_wait_read_opt_bus = 0, old_count_ok = 0, data_ready_optbus = 0, count_ok_read_opt_bus = 0; + +// static T_cds_optical_bus_data_in buff[25]={0}; + static unsigned int flag_last_error_read_opt_bus = 0, sum_count_err_read_opt_bus1=0; + + static unsigned int count_read_slave = 0, flag1_change_moment_read_optbus = 0, flag2_change_moment_read_optbus = 0; + + static unsigned int count_updated_sbus = 0, prev_ManualDischarge = 0; + + static unsigned int prev_flag_detect_update_optbus_data=0, flag_detect_update_optbus_data = 0, pause_error_detect_update_optbus_data = 0; + static unsigned int timer_wait_to_master_slave = 0; + static unsigned int prev_master = 0; + + static int pwm_enable_calc_main_log = 1; + + static int what_pwm = 0; + + int localStartGEDfromZadanie; + static unsigned int countStartGEDfromZadanie = 0; -// detect_level_interrupt(); -// start_int_xtics = xpwm_time.current_period; - if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT - || xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) +// OPTICAL_BUS_CODE_STATUS optbus_status = {0}; + static STATUS_DATA_READ_OPT_BUS optbus_status; + _iq wd; + +// if (edrk.disable_interrupt_sync==0) +// start_sync_interrupt(); + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_ON; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_16_ON; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS) +// PWM_LINES_TK_16_ON; +#endif + + + +#if (_ENABLE_INTERRUPT_PWM_LED2) +i_led2_on_off(1); +#endif + + if (edrk.disable_interrupt_pwm) + { + pwm_inc_interrupt(); + return; + } + + if (flag_special_mode_rs==1) + { + calc_norm_ADC_0(1); + calc_norm_ADC_1(1); + pwm_inc_interrupt(); + + return; + } + +#if (_ENABLE_PWM_LED2_PROFILE) + pos_profile_pwm = 0; +#endif + + + +#if (_ENABLE_PWM_LED2_PROFILE) + if (profile_pwm[pos_profile_pwm++]) + i_led2_on_off(1); + else + i_led2_on_off(0); +#endif + + +// if (xpwm_time.what_next_interrupt==PWM_LOW_LEVEL_INTERRUPT) +// { +//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) +// PWM_LINES_TK_17_ON; +//#endif +// +// i_sync_pin_on(); +// +// } +// else +// { +//#if(_ENABLE_PWM_LINES_FOR_TESTS_SYNC) +// PWM_LINES_TK_17_OFF; +//#endif +// +// i_sync_pin_off(); +// } + + + +//////////////// +//PWN_COUNT_RUN_PER_INTERRUPT PWM_TWICE_INTERRUPT_RUN + err_interr = detect_level_interrupt(edrk.flag_second_PCH); + + if (err_interr) + edrk.errors.e3.bits.ERR_INT_PWM_LONG |=1; + + if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) + pwm_up_down = 2; + else + if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT) + { + pwm_up_down = 0; + } + else + pwm_up_down = 1; + + // sync line + if (pwm_up_down==2 || pwm_up_down==0) + { +// what_pwm = 0; + // i_sync_pin_on(); + calculate_sync_detected(); + } + +///////////////// +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(3); +#endif + + +#if (_ENABLE_LOG_TICS_PWM==1) + + count_timer_buf = 0; + // optical_read_data.timer=0; +#endif + + +#if (_FLOOR6==0) +// if (edrk.Stop==0) +// i_led1_on_off(1); +#else + // i_led1_on_off(1); +#endif + + + edrk.into_pwm_interrupt = 1; + + // подготовка подсчета времени работы в прерывании + start_tics_4timer = EvbRegs.T3CNT; + cur_timer = global_time.pwm_tics; + if (prev_timer>cur_timer) + { + if ((prev_timer-cur_timer)<2) + { +// stop_pwm(); + edrk.count_lost_interrupt++; + } + } + else + { + if ((cur_timer==prev_timer) || (cur_timer-prev_timer)>2) + { +// stop_pwm(); + edrk.count_lost_interrupt++; + } + } + prev_timer = cur_timer; + // закончили подготовку подсчета времени работы в прерывании + + set_tics_timer_pwm(1,count_timer_buf); + get_tics_timer_pwm(1); + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_17_ON; +#endif + +#if (_SIMULATE_AC==1) + calc_norm_ADC_0_sim(0); +#else + calc_norm_ADC_0(0); // читаем АЦП а norma была запущена в Pwm_main() +#endif + run_detect_fast_error(); //быстрые защиты + + + + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + if (edrk.Kvitir==0 && prev_edrk_Kvitir==1) + { + count_err_read_opt_bus = 0; + edrk.sum_count_err_read_opt_bus = 0; + } + + set_tics_timer_pwm(2,count_timer_buf); + get_tics_timer_pwm(1); + + ////////////////////////////// +// inc_RS_timeout_cicle(); + //////////////////////////////// + //////////////////////////////////////////// + //////////////////////////////////////////// +// inc_CAN_timeout_cicle(); + //////////////////////////////////////////// + + if (edrk.ms.another_bs_maybe_on==1 && + (edrk.auto_master_slave.local.bits.master || edrk.auto_master_slave.local.bits.slave) ) + { + + flag_detect_update_optbus_data = 1; + + if (prev_flag_detect_update_optbus_data == 0) + pause_error_detect_update_optbus_data = 0; + + + count_updated_sbus = optical_read_data.data_was_update_between_pwm_int; + + // даем задержку PAUSE_ERROR_DETECT_UPDATE_OPTBUS_DATA после входа в обмен по OPT_BUS + // после которой начинаем ловить ошибки по своевременному обновлению данных по OPT_BUS + if (pause_error_detect_update_optbus_data 2 * COUNT_START_IMP) { - count_start_impuls = 2 * COUNT_START_IMP; + if (sync_data.what_main_pch) + { + if (sync_data.what_main_pch==2) + { + if (edrk.flag_second_PCH==1) // только на втором БС + { + fix_pwm_freq_synchro_ain(); } + } + + if (sync_data.what_main_pch==1) + { + if (edrk.flag_second_PCH==0) // только на втором БС + { + fix_pwm_freq_synchro_ain(); + } + } + } + else + fix_pwm_freq_synchro_ain(); + + } + else + { + pwm_enable_calc_main = 0; + } + + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + +//#if(C_cds_in_number>=1) +// project.cds_in[0].read_pbus(&project.cds_in[0]); +//#endif + +#if(C_cds_in_number>=2) + project.cds_in[1].read_pbus(&project.cds_in[1]); +#endif - } - } - flag_record_log = 1; - log_saved_to_const_mem = 0; - } else { - if (f.Discharge - && (errors.slow_stop2.bit.Break_Resistor == 0) - && (errors.plains_and_others.bit.er0_setted == 0) - && (errors.umu_errors.bit.Voltage380_BSU_Off == 0)) -// && !f.Stop) - { - start_break_pwm(); - break_resistor_managment_calc(); - } else { - //Do not stop, when come for the first time, to write to xilinx times to close keys. - //Otherwise mintime error can occure. - //Also we do not stop pwm wile break_resistor keys working - if (!count_start_impuls) { - // это произойдет только на втором такте выключения - stop_pwm(); - } - break_resistor_set_closed(); - } - if (count_step_ram_off > 0) { - count_step_ram_off--; - flag_record_log = 1; - } else { - flag_record_log = 0; - } +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_17_OFF; +#endif - pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor, - rotor.iqFout, 0, 1, 1); - if (count_start_impuls > 0) { - count_start_impuls -= 1; - } else { - count_start_impuls = 0; - } - Uzad1 = 87772; //0.5% - Uzad2 = 87772; - k1 = Uzad1; - svgen_pwm24_1.Gain = Uzad1; - svgen_pwm24_2.Gain = Uzad1; - svgen_dq_1.Ualpha = 0; - svgen_dq_1.Ubeta = 0; - svgen_dq_2.Ualpha = 0; - svgen_dq_2.Ubeta = 0; - a.iqk = Uzad1; + set_tics_timer_pwm(10,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + if (pwm_run == 1) + { + // зашли в прерывание но почему-то мы уже были тут, повторный заход? + soft_stop_x24_pwm_all(); + edrk.errors.e9.bits.ERR_INT_PWM_VERY_LONG |=1; } -// a.iqk1 = Uzad1; -// a.iqk2 = Uzad2; -// a.iqk = (a.iqk1 + a.iqk2) >> 1; -// a.iqf = Fzad; - prevGo = f.Go; - - break_resistor_recup_calc(); - break_resistor_managment_update(); - - if (count_start_impuls >= (2 * COUNT_START_IMP) ) { - - if (f.Mode == 0) { -// test_calc_pwm24(Uzad1, Uzad2, Fzad); - if (pwm_enable_calc_main) { - test_calc_simple_dq_pwm24(Uzad1, Uzad2, Fzad, Fzad, K_MODUL_MAX); - } - analog_dq_calc_const(); - } else { - if ((_IQabs(rotor.iqFout) < STOP_ROTOR_LIMIT) - && (_IQabs(analog.iqIq1) > STOP_ROTOR_MIN_CURRENT)) { - if ((stop_rotor_counter >= 2520)) { - stop_rotor_counter = 2520; -// faults.faults5.bit.rotor_stopped |= 1; - f.rotor_stopped |= 1; - } else { - stop_rotor_counter += 1; - } - if (_IQabs(analog.Fsl) < MIN_Fsl_WHEN_STOPED) { -// faults.faults5.bit.rotor_stopped |= 1; - f.rotor_stopped |= 1; - } - } else { - if (stop_rotor_counter > 0) { - stop_rotor_counter -= 1; - } else { - stop_rotor_counter = 0; - } - } - - pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor, - rotor.iqFout, f.Mode, 0, pwm_enable_calc_main); - } - - } else { - // тут опять middle состояние перед выключением ключей - if (count_start_impuls) - { -// svgen_set_time_keys_closed(&svgen_pwm24_1); -// svgen_set_time_keys_closed(&svgen_pwm24_2); - svgen_set_time_middle_keys_open(&svgen_pwm24_1); - svgen_set_time_middle_keys_open(&svgen_pwm24_2); - } - else - // а тут мы уже выключились - { - svgen_set_time_keys_closed(&svgen_pwm24_1); - svgen_set_time_keys_closed(&svgen_pwm24_2); - //Снимаем запрет ШИМа -// if (faults.faults5.bit.rotor_stopped == 1) { - if (f.rotor_stopped == 1) { - if (stop_rotor_counter > 0) { - stop_rotor_counter -= 1; - } else { -// faults.faults5.bit.rotor_stopped = 0; - f.rotor_stopped = 0; - stop_rotor_counter = 0; - } - } else { - stop_rotor_counter = 0; - } - } - } - - if (f.Mode) { - a.iqf = analog.iqFstator; - } else { - a.iqf = Fzad; - analog.iqFstator = Fzad; - a.iqk1 = _IQsqrt(_IQmpy(svgen_dq_1.Ualpha, svgen_dq_1.Ualpha) + _IQmpy(svgen_dq_1.Ubeta, svgen_dq_1.Ubeta)); //For output Kmodul to terminal - a.iqk2 = _IQsqrt(_IQmpy(svgen_dq_2.Ualpha, svgen_dq_2.Ualpha) + _IQmpy(svgen_dq_2.Ubeta, svgen_dq_2.Ubeta)); //end counting Uout - } - a.iqk = (a.iqk1 + a.iqk2) / 2; - -// write_swgen_pwm_times(); - - if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE); else { - if (f.Go == 1) - { - if (count_start_impuls == (2 * COUNT_START_IMP)) - { - if (pwm_enable_calc_main) - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_HIGH); - else - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_LOW); - } - else -// if (pwm_enable_calc_main) - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE); - } + pwm_run = 1; + +// detect_I_M_overload(); +// if (edrk.from_rs.bits.ACTIVE) +// edrk.Go = edrk.StartGEDRS; + +// project_read_errors_controller(); // чтение ADR_ERRORS_TOTAL_INFO + + if ( (edrk.errors.e0.all) + || (edrk.errors.e1.all) + || (edrk.errors.e2.all) + || (edrk.errors.e3.all) + || (edrk.errors.e4.all) + || (edrk.errors.e5.all) + || (edrk.errors.e6.all) + || (edrk.errors.e7.all) + || (edrk.errors.e8.all) + || (edrk.errors.e9.all) + || (edrk.errors.e10.all) + || (edrk.errors.e11.all) + || (edrk.errors.e12.all) + ) + edrk.Stop |= 1; else - { - if (count_start_impuls == (2 * COUNT_START_IMP) - 1) - { - if (pwm_enable_calc_main) - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_HIGH); - else - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_LOW); + edrk.Stop = 0; + + + project.read_errors_controller(); + error_controller = (project.controller.read.errors.all | project.controller.read.errors_buses.bit.slave_addr_error | project.controller.read.errors_buses.bit.count_error_pbus); +// project.controller.read.errors.all = error_controller; + + + + if(error_controller && prev_error_controller==0) + { + edrk.errors.e11.bits.ERROR_CONTROLLER_BUS |= 1; + svgen_set_time_keys_closed(&svgen_pwm24_1); + svgen_set_time_keys_closed(&svgen_pwm24_2); + + write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); + +// xerror(main_er_ID(1),(void *)0); + } + prev_error_controller = error_controller;//project.controller.read.errors.all; + + + if (pwm_enable_calc_main==0)// заходим в расчет только раз за период шима - вторая часть + { + + if (en_rotor) + { +#if (_SIMULATE_AC==1) +// calc_rotors_sim(); +#else + calc_rotors(pwm_enable_calc_main_log); // получаем данные с датчика оборотов +#endif + + + + } + +#if (_ENABLE_PWM_LED2_PROFILE) + if (profile_pwm[pos_profile_pwm++]) + i_led2_on_off(1); + else + i_led2_on_off(0); +#endif + calc_zadanie_rampa(); + +#if (_ENABLE_PWM_LED2_PROFILE) + if (profile_pwm[pos_profile_pwm++]) + i_led2_on_off(1); + else + i_led2_on_off(0); +#endif + calc_norm_ADC_1(1); // замер температур + + calc_power_full(); + + calc_all_limit_koeffs(); + + } + + ///////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////// + + + if (pwm_enable_calc_main)// заходим в расчет только раз за период шима + { + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_18_ON; +#endif + + if (edrk.Obmotka1 == 0) + go_a = 1; + else + go_a = 0; + + if (edrk.Obmotka2 == 0) + go_b = 1; + else + go_b = 0; + + ////////////////////////// + + if (optical_read_data.data.cmd.bit.start_pwm && edrk.auto_master_slave.local.bits.slave ) + edrk.StartGEDfromSyncBus = 1; + else + edrk.StartGEDfromSyncBus = 0; + + edrk.master_Uzad = _IQ15toIQ( optical_read_data.data.pzad_or_wzad); + edrk.master_theta = _IQ12toIQ( optical_read_data.data.angle_pwm); + edrk.master_Izad = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); + edrk.master_Iq = _IQ15toIQ( optical_read_data.data.iq_zad_i_zad); + + set_tics_timer_pwm(11,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + ///////////////////////// + + if ((edrk.auto_master_slave.local.bits.slave==1 && edrk.auto_master_slave.local.bits.master==0) + || (edrk.auto_master_slave.local.bits.slave==0 && edrk.auto_master_slave.local.bits.master==1) ) + { + + if (edrk.auto_master_slave.local.bits.master != prev_master) + timer_wait_to_master_slave = 0; + + // после выбора ждем еще некоторое время. + if (timer_wait_to_master_slave>MAX_TIMER_WAIT_MASTER_SLAVE) + { + edrk.Status_Ready.bits.MasterSlaveActive = 1; + + if (edrk.auto_master_slave.local.bits.master) + edrk.MasterSlave = MODE_MASTER; + else + edrk.MasterSlave = MODE_SLAVE; + } + else + { + edrk.Status_Ready.bits.MasterSlaveActive = 0; + edrk.MasterSlave = MODE_DONTKNOW; + timer_wait_to_master_slave++; + } + prev_master = edrk.auto_master_slave.local.bits.master; + } + else + { + + edrk.Status_Ready.bits.MasterSlaveActive = 0; + edrk.MasterSlave = MODE_DONTKNOW; + + timer_wait_to_master_slave = 0; + } + + + set_tics_timer_pwm(12,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { + if (edrk.MasterSlave == MODE_MASTER) { + if (get_start_ged_from_zadanie()) { + edrk.prepare_stop_PWM = 0; + //edrk.StartGEDfromZadanie = 1; + localStartGEDfromZadanie = 1; + } else { + edrk.prepare_stop_PWM = 1; + if (edrk.k_stator1 < 41943) { //335544 ~ 2% + //edrk.StartGEDfromZadanie = 0; + localStartGEDfromZadanie = 0; + } + } + } else { + if (get_start_ged_from_zadanie()) { + //edrk.StartGEDfromZadanie = 1; + localStartGEDfromZadanie = 1; + } else { + if (edrk.k_stator1 < 41943) { //335544 ~ 2% + //edrk.StartGEDfromZadanie = 0; + localStartGEDfromZadanie = 0; + } + } + edrk.prepare_stop_PWM = optical_read_data.data.cmd.bit.prepare_stop_PWM; + } + } else { + //edrk.StartGEDfromZadanie = + localStartGEDfromZadanie = get_start_ged_from_zadanie(); + } + + // задержка прохождения localStartGEDfromZadanie=1 в edrk.StartGEDfromZadanie + if (localStartGEDfromZadanie && edrk.prevStartGEDfromZadanie==0) + { + if (countStartGEDfromZadanieMAX_TIMER_WAIT_BOTH_READY2) + edrk.errors.e1.bits.VERY_LONG_BOTH_READY2 |= 1; + else + timer_wait_both_ready2++; + + } + else + timer_wait_both_ready2 = 0; + + + if (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_ON + && optical_read_data.data.cmd.bit.ready_cmd == CODE_READY_CMD_READY2) // тот расцепитель включен или включился и тот БС собрался + { + edrk.flag_block_zadanie = 0; + edrk.flag_wait_set_to_zero_zadanie = 0; + } + + if (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_ENABLE_ON_AND_THIS_OFF + && optical_read_data.data.cmd.bit.ready_cmd == CODE_READY_CMD_READY1) // тот расцепитель выключен и схема на том БС разобрана + { + edrk.flag_block_zadanie = 0; + edrk.flag_wait_set_to_zero_zadanie = 0; + } + + + if (edrk.StartGEDfromZadanie==0 && edrk.flag_block_zadanie + && (optical_read_data.data.cmd.bit.rascepitel_cmd==CODE_RASCEPITEL_CMD_REQUEST_AND_THIS_OFF)) + // разрешаем другому БС завести расцепитель + edrk.you_can_on_rascepitel = 1; + + + if (edrk.flag_wait_set_to_zero_zadanie) + { + if (timer_wait_set_to_zero_zadanie>MAX_TIMER_WAIT_SET_TO_ZERO_ZADANIE) + { + // другой БС запросил включения своего расцепителя, мы сбросили обороты и ждали пока тот БС соберет свою схему + // но этого не произошло!!!! + edrk.errors.e1.bits.ANOTHER_BS_NOT_ON_RASCEPITEL |= 1; + + } + else + timer_wait_set_to_zero_zadanie++; + + } + else + timer_wait_set_to_zero_zadanie = 0; + + + // если ошибка подключения, то обнуляем запрос на подключение. + if (edrk.errors.e1.bits.ANOTHER_BS_NOT_ON_RASCEPITEL) + edrk.flag_wait_set_to_zero_zadanie = 0; + + + edrk.StartGED = ((edrk.StartGEDfromControl==1) && (edrk.StartGEDfromZadanie==1) && (edrk.flag_block_zadanie==0)); + + + if (edrk.MasterSlave == MODE_MASTER) + { + edrk.GoWait = ( (edrk.StartGED ) && (edrk.Stop == 0) + && (project.controller.read.errors.all==0) && + (slow_error==0) && + (edrk.Status_Ready.bits.ready_final) + && edrk.Status_Ready.bits.MasterSlaveActive + && edrk.warnings.e9.bits.BREAKER_GED_ON==0 + ); + } + else + if (edrk.MasterSlave == MODE_SLAVE) + { + edrk.GoWait = ( (edrk.StartGED && edrk.StartGEDfromSyncBus) && (edrk.Stop == 0) + && (project.controller.read.errors.all==0) && + (slow_error==0) && + (edrk.Status_Ready.bits.ready_final) + && edrk.Status_Ready.bits.MasterSlaveActive + ); + } + else + edrk.GoWait = 0; + + // if (edrk.GoWait==0 && edrk.Go == 0 && + + + // исключаем дребезг сигнала edrk.Go + if (edrk.GoWait) + { + if (count_wait_go_0>=MAX_COUNT_WAIT_GO_0) + edrk.Go = edrk.GoWait; + else + { + edrk.Go = 0; + edrk.errors.e7.bits.VERY_FAST_GO_0to1 |=1; // ошибка! слишком быстро пришел повторный edrk.Go!!! + } + } + else + { + if (edrk.Go) + count_wait_go_0 = 0; + + edrk.Go = 0; + if (count_wait_go_0=(MAX_COUNT_TIME_BUF-1)) + count_time_buf = 0; + + log_wait = 0; + if (edrk.MasterSlave == MODE_MASTER) + log_wait |= 0x1; + if (edrk.MasterSlave == MODE_SLAVE) + log_wait |= 0x2; + if (edrk.StartGED) + log_wait |= 0x4; + if (edrk.Stop) + log_wait |= 0x8; + if (edrk.Status_Ready.bits.ready_final) + log_wait |= 0x10; + if (edrk.Status_Ready.bits.MasterSlaveActive) + log_wait |= 0x20; + if (edrk.GoWait) + log_wait |= 0x40; + if (edrk.Go) + log_wait |= 0x80; + if (project.controller.read.errors.all==0) + log_wait |= 0x100; + if (slow_error) + log_wait |= 0x200; + if (edrk.StartGEDfromSyncBus) + log_wait |= 0x400; + + + time_buf[count_time_buf] = log_wait; + + if (edrk.errors.e7.bits.VERY_FAST_GO_0to1) + stop_count_time_buf = 1; + } +*/ +#endif + + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_GO) + if (edrk.StartGEDfromSyncBus) + { + PWM_LINES_TK_17_ON; + } + else + { + PWM_LINES_TK_17_OFF; + } + + if (edrk.StartGEDfromZadanie) + { + PWM_LINES_TK_18_ON; + } + else + { + PWM_LINES_TK_18_OFF; + } + if (edrk.flag_block_zadanie) + { + PWM_LINES_TK_19_ON; + } + else + { + PWM_LINES_TK_19_OFF; + } + + if (edrk.StartGEDfromControl) + { + PWM_LINES_TK_16_ON; + } + else + { + PWM_LINES_TK_16_OFF; + } + +#endif + + + + set_tics_timer_pwm(15,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + ////////////////////////////////// + ////////////////////////////////// + + if(edrk.Go == 1) + { + if (edrk.Go != prevGo) + { + edrk.count_run++; +// clear_mem(FAST_LOG); +// count_start_impuls = 0; +// count_step = 0; + f.count_step_ram_off = COUNT_SAVE_LOG_OFF; +// count_step_run = 0; + + // set_start_mem(FAST_LOG); + // set_start_mem(SLOW_LOG); + + // logpar.start_write_fast_log = 1; + + init_uf_const(); + init_simple_scalar(); + + Fzad = 0; + Uzad1 = 0; + Uzad2 = 0; + + clear_logpar(); } else - write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE); - } + { - // if (pwm_enable_calc_main) - // prev_run_calc_uf = run_calc_uf; + if (f.count_start_impuls < COUNT_START_IMP) + { + f.count_start_impuls++; + } + else + { + f.count_start_impuls = COUNT_START_IMP; + + f.flag_record_log = 1; + enable_calc_vector = 1; + + } + + } + } + else // (edrk.Go == 0) + { + + if (f.count_step_ram_off > 0) + { + f.count_step_ram_off--; + f.flag_record_log = 1; + } else { + f.flag_record_log = 0; + } + + // ручной разряд + if (edrk.ManualDischarge && prev_ManualDischarge!=edrk.ManualDischarge) + edrk.Discharge = 1; + + prev_ManualDischarge =edrk.ManualDischarge; + + if (f.count_start_impuls == 0) + { + + if (edrk.Discharge || (edrk.ManualDischarge ) ) + { + break_resistor_managment_calc(); + soft_start_x24_break_1(); + } + else + { + + if (f.count_step_ram_off > 0) + { + break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); + // soft_start_x24_break_1(); + } + else + { + // это произойдет только на последнем такте выключения + soft_stop_x24_pwm_all(); + + } + } + + } + + set_tics_timer_pwm(16,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + if (f.count_start_impuls==COUNT_START_IMP) + { + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) + { + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } + + vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, + WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + edrk.Mode_ScalarVectorUFConst, + edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, + edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, + &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, + 0, 1); + + test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, + edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, + filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.Uzad_to_slave); + analog.PowerFOC = edrk.P_to_master; + Fzad = vect_control.iqFstator; + Izad_out = edrk.Iq_to_slave; + } else { + test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, + 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, + 1, + edrk.Uzad_max, + edrk.master_theta, + edrk.master_Uzad, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.tetta_to_slave, + &edrk.Uzad_to_slave); + } + } + else + { + if (f.count_start_impuls==COUNT_START_IMP-1) + { + + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) + { + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } + + vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, + WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + edrk.Mode_ScalarVectorUFConst, + edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, + edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, + &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, + 0, 1); + + test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, + edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, + filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.Uzad_to_slave); + analog.PowerFOC = edrk.P_to_master; + Fzad = vect_control.iqFstator; + Izad_out = edrk.Iq_to_slave; + } else { + test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, + 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, + 1, + edrk.Uzad_max, + edrk.master_theta, + edrk.master_Uzad, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.tetta_to_slave, + &edrk.Uzad_to_slave); + } + + } + else + { + if (f.count_start_impuls==COUNT_START_IMP-2) + { + // тут опять middle состояние перед выключением ключей +// svgen_set_time_keys_closed(&svgen_pwm24_1); +// svgen_set_time_keys_closed(&svgen_pwm24_2); + svgen_set_time_middle_keys_open(&svgen_pwm24_1); + svgen_set_time_middle_keys_open(&svgen_pwm24_2); + } + else + // а тут мы уже выключились + { + svgen_set_time_keys_closed(&svgen_pwm24_1); + svgen_set_time_keys_closed(&svgen_pwm24_2); + } + + Fzad = 0; + + } + } + + + if (f.count_start_impuls > 0) { + f.count_start_impuls -= 1; + } else { + f.count_start_impuls = 0; + } + enable_calc_vector = 0; + + + + Uzad1 = 0; + Uzad2 = 0; + + } // end if Go==1 + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_18_OFF; +#endif + + + } // end pwm_enable_calc_main one interrupt one period only + +/* + * + // if ((m.m0.bit.EnableGoA == 1) && (f.Obmotka1 == 0)) + + + // if ((m.m0.bit.EnableGoB == 1) && (f.Obmotka2 == 0)) + if (f.Obmotka2 == 0) + { + go_b = 1; + } + else + { + go_b = 0; + } + + if (go_a == 0 && prev_go_a != go_a) + { + //отключаем 1 обмотку + soft_stop_x24_pwm_1(); + } + + if (go_a == 1 && prev_go_a != go_a) + { + //включаем 1 обмотку + soft_start_x24_pwm_1(); + } + + if (go_b == 0 && prev_go_b != go_b) + { + //отключаем 2 обмотку + soft_stop_x24_pwm_2(); + } + + if (go_b == 1 && prev_go_b != go_b) + { + //включаем 2 обмотку + soft_start_x24_pwm_2(); + } + + prev_go_a = go_a; + prev_go_b = go_b; + * + * + */ + + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + + if (pwm_enable_calc_main) // заходим в расчет только раз за период шима + { + + + if (f.count_start_impuls==1 && edrk.Go==1) + { + // а тут мы еше не включились + svgen_set_time_keys_closed(&svgen_pwm24_1); + svgen_set_time_keys_closed(&svgen_pwm24_2); + // soft_start_x24_pwm_1_2(); + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) { + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } + vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, + WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + edrk.Mode_ScalarVectorUFConst, + edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, + edrk.master_theta, edrk.master_Iq, edrk.P_from_slave, + &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, 1, edrk.prepare_stop_PWM); + } + } + + if (f.count_start_impuls==2 && edrk.Go==1) + { + // включаем ШИМ + if (go_a == 1 && go_b == 1) { + // start_pwm(); должен вызваться один раз за изменение edrk.Go + soft_start_x24_pwm_1_2(); + } else if (go_a == 1) { + soft_start_x24_pwm_1(); + } else if (go_b == 1) { + soft_start_x24_pwm_2(); + } + + // enable work break +#if (DISABLE_WORK_BREAK==1) + +#else +// if (edrk.disable_break_work==0) + { + soft_start_x24_break_1(); + } +#endif + + } // end if (count_start_impuls==5) + + + if (f.count_start_impuls==3 && edrk.Go==1) + { + // готовимся разрешить ШИМ + svgen_set_time_middle_keys_open(&svgen_pwm24_1); + svgen_set_time_middle_keys_open(&svgen_pwm24_2); + } + + + + if (f.count_start_impuls==4 && edrk.Go==1) + { + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) + { + +// void simple_scalar(int n_alg, int n_wind_pump, _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, _iq fzad_provorot, +// _iq iqIm_1, _iq iqIm_2, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, +// _iq *Fz, _iq *Uz1) + + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } + + vectorControlConstId(0, 0, + WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + edrk.Mode_ScalarVectorUFConst, + edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, + edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, + &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, + 0, edrk.prepare_stop_PWM); + + test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, + edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, + filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.Uzad_to_slave); + Fzad = vect_control.iqFstator; + Izad_out = edrk.Iq_to_slave; + } else { + test_calc_simple_dq_pwm24_Ing(Fzad, 0, 0, + 0, 0, filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.master_theta, + edrk.master_Uzad, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); + + + simple_scalar(1,0, WRotor.RotorDirectionSlow, + WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter, + 0, + 0, + 0, edrk.iq_bpsi_normal, + 0, + // analog.iqU_1_long+analog.iqU_2_long, + edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, + 0, + edrk.zadanie.iq_power_zad_rmp, 0, + edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, + 0,0, edrk.count_bs_work+1, + &Fzad, &Uzad1, &Uzad2, &Izad_out); + } + + } + + if (f.count_start_impuls == COUNT_START_IMP && edrk.Go==1) + { + if (pwm_enable_calc_main) // заходим в расчет только раз за период шима + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_21_ON; +#endif + + + //break_resistor_recup_calc(edrk.zadanie.iq_ZadanieU_Charge); + break_resistor_recup_calc(edrk.zadanie.iq_set_break_level); + + set_tics_timer_pwm(17,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + run_calc_uf = 1; + + // основная работа тут, ШИМ уже включен в middle + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_UF_CONST) + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + uf_const(&Fzad,&Uzad1,&Uzad2); +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + + test_calc_simple_dq_pwm24_Ing(Fzad, + Uzad1, + edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance, + edrk.zadanie.iq_k_u_disbalance, + filter.iqU_1_fast, + filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.master_theta, + edrk.master_Uzad, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, + &edrk.tetta_to_slave, + &edrk.Uzad_to_slave); +// rmp_freq.DesiredInput = alg_pwm24.freq1; +// rmp_freq.calc(&rmp_freq); +// Fzad = rmp_freq.Out; +// +// vhz1.Freq = Fzad; +// vhz1.calc(&vhz1); +// +// +// Uzad1 = alg_pwm24.k1; +// Uzad2 = alg_pwm24.k1; + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + + // test_calc_pwm24(Uzad1, Uzad2, Fzad); + // analog_dq_calc_const(); + + } // end ALG_MODE_UF_CONST + else + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_SCALAR_POWER) + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + simple_scalar(1, + 0, + WRotor.RotorDirectionSlow, + WRotor.iqWRotorSumFilter, //rotor_22220.iqFlong * rotor_22220.direct_rotor; + WRotor.iqWRotorSumFilter, //rotor_22220.iqFout * rotor_22220.direct_rotor; + //0, 0, + edrk.zadanie.iq_oborots_zad_hz_rmp, + edrk.all_limit_koeffs.sum_limit, + edrk.zadanie.iq_Izad_rmp, + edrk.iq_bpsi_normal, + analog.iqIm, +// analog.iqU_1_long+analog.iqU_2_long, + edrk.zadanie.iq_ZadanieU_Charge_rmp+edrk.zadanie.iq_ZadanieU_Charge_rmp, + analog.iqIin_sum, + edrk.zadanie.iq_power_zad_rmp, + edrk.iq_power_kw_full_znak,//(filter.PowerScalar+edrk.iq_power_kw_another_bs), + edrk.zadanie.iq_limit_power_zad_rmp, edrk.Mode_ScalarVectorUFConst, + edrk.master_Izad, + edrk.MasterSlave, + edrk.count_bs_work+1, + &Fzad, + &Uzad1, + &Uzad2, + &Izad_out); + + set_tics_timer_pwm(18,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + + + + if (edrk.cmd_disable_calc_km_on_slave) + Uzad_from_master = edrk.master_Uzad; + else + { +#if (DISABLE_CALC_KM_ON_SLAVE==1) + Uzad_from_master = edrk.master_Uzad; +#else + Uzad_from_master = Uzad1; +#endif + + } + + test_calc_simple_dq_pwm24_Ing(Fzad, Uzad1, edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance, edrk.zadanie.iq_k_u_disbalance, filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.master_theta, + Uzad_from_master, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.tetta_to_slave, &edrk.Uzad_to_slave); +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + + set_tics_timer_pwm(19,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } + + analog_dq_calc_external(wd, uf_alg.tetta); + + } // end ALG_MODE_SCALAR_OBOROTS + else + if (edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_OBOROTS || edrk.Mode_ScalarVectorUFConst == ALG_MODE_FOC_POWER) + { + +// void simple_scalar(int n_alg, int n_wind_pump, _iq Frot_pid, _iq Frot,_iq fzad,_iq mzz_zad, _iq bpsi_const, _iq fzad_provorot, +// _iq iqIm_1, _iq iqIm_2, _iq iqUin, _iq Iin, _iq powerzad, _iq power_pid, +// _iq *Fz, _iq *Uz1) + + if (edrk.flag_second_PCH == 0) { + wd = uf_alg.winding_displacement_bs1; + } else { + wd = uf_alg.winding_displacement_bs2; + } +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, + WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + edrk.Mode_ScalarVectorUFConst, + edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, + edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, + &edrk.tetta_to_slave, &edrk.Iq_to_slave, &edrk.P_to_master, + 0, edrk.prepare_stop_PWM); +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_ON; +#endif + + test_calc_vect_dq_pwm24_Ing(vect_control.iqTheta, vect_control.iqUdKm, vect_control.iqUqKm, + edrk.disable_alg_u_disbalance, + edrk.zadanie.iq_kplus_u_disbalance_rmp, edrk.zadanie.iq_k_u_disbalance_rmp, + filter.iqU_1_fast, filter.iqU_2_fast, + 0, + edrk.Uzad_max, + edrk.MasterSlave, + edrk.flag_second_PCH, + &edrk.Kplus, &edrk.Uzad_to_slave); + + analog.PowerFOC = edrk.P_to_master; + Fzad = vect_control.iqFstator; + Izad_out = edrk.Iq_to_slave; + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_20_OFF; +#endif + } // end ALG_MODE_FOC_OBOROTS + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_21_OFF; +#endif + + } // end pwm_enable_calc_main + + } // end (count_start_impuls == COUNT_START_IMP && edrk.Go==1) + else + { + run_calc_uf = 0; + if (pwm_enable_calc_main) // заходим в расчет только раз за период шима + { + + } + svgen_pwm24_1.Ta_imp = 0; + svgen_pwm24_1.Tb_imp = 0; + svgen_pwm24_1.Tc_imp = 0; + svgen_pwm24_2.Ta_imp = 0; + svgen_pwm24_2.Tb_imp = 0; + svgen_pwm24_2.Tc_imp = 0; + + } // end else (count_start_impuls == COUNT_START_IMP && edrk.Go==1) + + prevGo = edrk.Go; + + + + ////////////////////////////////// + optical_write_data.data.cmd.bit.start_pwm = edrk.Go; + optical_write_data.data.cmd.bit.prepare_stop_PWM = edrk.prepare_stop_PWM; + + optical_write_data.data.angle_pwm = _IQtoIQ12(edrk.tetta_to_slave + vect_control.add_tetta); + optical_write_data.data.pzad_or_wzad = _IQtoIQ15(edrk.Uzad_to_slave); + optical_write_data.data.iq_zad_i_zad = _IQtoIQ15(edrk.Izad_out); + + optical_bus_update_data_write(); + + set_tics_timer_pwm(20,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + if (edrk.ms.another_bs_maybe_on==1 && edrk.auto_master_slave.local.bits.master) + { + // i_led2_on(); + } + + ////////////////////////////////// + ////////////////////////////////// + + edrk.Izad_out = Izad_out; + + if (edrk.MasterSlave==MODE_SLAVE) + { + edrk.f_stator = Fzad; + edrk.k_stator1 = edrk.Uzad_to_slave;//Uzad1; + edrk.k_stator2 = edrk.Uzad_to_slave;//Uzad2; + + } + else + if (edrk.MasterSlave==MODE_MASTER) + { + edrk.f_stator = Fzad; + edrk.k_stator1 = edrk.Uzad_to_slave;//Uzad1; + edrk.k_stator2 = edrk.Uzad_to_slave; + } + else + { + edrk.f_stator = 0; + edrk.k_stator1 = 0; + edrk.k_stator2 = 0; + } + + } // end pwm_enable_calc_main + + + + + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + /////////////////////////////////////////// + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_22_ON; +#endif + + if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) + write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); + else + { + if (edrk.Go==1) + { + if (f.count_start_impuls==COUNT_START_IMP-1) + { + if (pwm_enable_calc_main) + write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_HIGH); + else + write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_LOW); + } + else +// if (pwm_enable_calc_main) + write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); + } + else + { + if (f.count_start_impuls==COUNT_START_IMP-3) + { + if (pwm_enable_calc_main) + write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_HIGH); + else + write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_LOW); + + } + else + write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE); + } + + + + // if (pwm_enable_calc_main) + // prev_run_calc_uf = run_calc_uf; + + + + } +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_22_OFF; +#endif + + + set_tics_timer_pwm(21,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + // test write oscil buf + + if ( pwm_enable_calc_main==0) // заходим в расчет только раз за период шима + { + + run_write_logs(); + + } + + + // i_led2_on(); + // + if (edrk.SumSbor == 1) { + detect_protect_adc(uf_alg.tetta_bs, uf_alg.tetta_bs); + //// get_tics_timer_pwm(pwm_enable_calc_main,count_timer_buf); + } + + // fill_RMS_buff_interrupt(uf_alg.tetta_bs, uf_alg.tetta_bs); + + set_tics_timer_pwm(24,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + + + // out_I_over_1_6.calc(&out_I_over_1_6); + // i_led2_off(); + + + pwm_run = 0; + + + } // end if pwm_run==1 + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_ON; +#endif + + if (pwm_enable_calc_main==0) // заходим в расчет только раз за период шима + { + + + // pwm_analog_ext_interrupt(); + +// inc_RS_timeout_cicle(); +// inc_CAN_timeout_cicle(); + +#if (_SIMULATE_AC==1) + sim_model_execute(); +#endif } + pwm_analog_ext_interrupt(); + pwm_inc_interrupt(); + + + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_ON; +#endif - // logs recording -// if ((flag_record_log && !f.stop_Log) || f.Startstoplog) -// //if (f.Log1_Log2 == 1)// && f.Go == 1 && (!f.Stop)) -// //if(f.Go == 1) -// { -// test_mem_limit(FAST_LOG, !f.Ciclelog); -// count_step++; -// -// if (count_step >= 0) { -// fillADClogs(); -//// logpar.log13 = flag_record_log; -//// logpar.log14 = count_start_impuls; -//// logpar.log10 = (int16)_IQtoIQ15(analog.iqIq1_filter); -//// logpar.log11 = (int16)_IQtoIQ15(rotor.iqFrotFromOptica); -// logpar.log15 = (int16) _IQtoIQ15(analog.iqIq2); -// logpar.log16 = (int16) _IQtoIQ15(a.iqk1); -// logpar.log17 = (int16) _IQtoIQ15(analog.iqId1); -// logpar.log18 = (int16) _IQtoIQ15(analog.iqIq1); -// -//// logpar.log24 = (int16) break_result_1; -//// logpar.log25 = (int16) break_result_2; -// logpar.log27 = (int16)(_IQtoIQ15(analog.iqIbtr1_1)); -// logpar.log28 = (int16)(_IQtoIQ15(analog.iqIbtr2_1)); -// -// getFastLogs(!f.Ciclelog); -// count_step = 0; -// } -// } else { -// if (f.Stop && log_saved_to_const_mem == 0) { -// logpar.copy_log_to_const_memory = 1; -// log_saved_to_const_mem = 1; -// } -// } + set_tics_timer_pwm(25,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); -// optical_bus_write(); -// detect_current_saw_val(); - end_int_xtics = xpwm_time.current_period; - f.PWMcounterVal = labs(start_int_xtics - end_int_xtics); +#if (_ENABLE_SLOW_PWM) +// pause_1000(slow_pwm_pause); +#endif + + set_tics_timer_pwm(26,count_timer_buf); + get_tics_timer_pwm(pwm_enable_calc_main_log); + +///////////////////////////////////////////////// + // считаем время работы в прерывании + end_tics_4timer = EvbRegs.T3CNT; + + if (end_tics_4timer>start_tics_4timer) + { + time_delta = (end_tics_4timer - start_tics_4timer); + time_delta = time_delta * 33/1000; + if (pwm_enable_calc_main) + edrk.period_calc_pwm_int1 = time_delta;//(end_tics_4timer - start_tics_4timer)*33/1000; + else + edrk.period_calc_pwm_int2 = time_delta;//(end_tics_4timer - start_tics_4timer)*33/1000; + } + // закончили считать время работы в прерывании + ///////////////////////////////////////////////// + + // get_tics_timer_pwm(pwm_enable_calc_main,count_timer_buf); + + + + + +#if (_ENABLE_LOG_TICS_PWM==1) + + for (i_log=count_timer_buf;i_log=10000) + c_run=c_run_start; + else + c_run++; +#endif + +#if (ENABLE_LOG_INTERRUPTS) + add_log_interrupts(103); +#endif + + + +// i_sync_pin_off(); + edrk.into_pwm_interrupt = 0; + +#if (_ENABLE_INTERRUPT_PWM_LED2) +i_led2_on_off(0); +#endif + + + +#if(_ENABLE_PWM_LINES_FOR_TESTS) + // PWM_LINES_TK_16_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_16_OFF; +#endif + +#if(_ENABLE_PWM_LINES_FOR_TESTS_PWM) + PWM_LINES_TK_16_OFF; +#endif + + +#if (_ENABLE_PWM_LED2_PROFILE) + i_led2_on_off(0); + if (pwm_enable_calc_main==0) + profile_pwm[pos_profile_pwm] = 2; +#endif + + +} +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// + + + +#pragma CODE_SECTION(fix_pwm_freq_synchro_ain,".fast_run"); +void fix_pwm_freq_synchro_ain(void) +{ + unsigned int new_freq; + static unsigned int delta_freq = 1; +// if (f.Sync_input_or_output == SYNC_INPUT) + { + sync_inc_error(); + + if (sync_data.disable_sync || sync_data.timeout_sync_signal == 1 || sync_data.enable_do_sync == 0) + { + + new_freq = xpwm_time.pwm_tics; + i_WriteMemory(ADR_PWM_PERIOD, new_freq); + + return; + } + + if (sync_data.pwm_freq_plus_minus_zero==1) + { + + + //Increment xtics + new_freq = xpwm_time.pwm_tics + delta_freq; + i_WriteMemory(ADR_PWM_PERIOD, new_freq); // Saw period in tics. 1 tic = 16.67 nsec + + // change_freq_pwm(VAR_FREQ_PWM_XTICS); + + + } + + if (sync_data.pwm_freq_plus_minus_zero==-1) + { + //4464 + //Decrement xtics + new_freq = xpwm_time.pwm_tics - delta_freq; + i_WriteMemory(ADR_PWM_PERIOD, new_freq); // Saw period in tics. 1 tic = 16.67 nsec + + // change_freq_pwm(VAR_FREQ_PWM_XTICS); + + } + + if (sync_data.pwm_freq_plus_minus_zero==0) + { + new_freq = xpwm_time.pwm_tics; + i_WriteMemory(ADR_PWM_PERIOD, new_freq); + // change_freq_pwm(VAR_FREQ_PWM_XTICS); + } + + } - pwm_run = 0; - i_sync_pin_off(); -// i_led1_on_off(0); } +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////// + +/* void slow_vector_update() { _iq iqKzad = 0; + freq1 = _IQ (f.fzad/F_STATOR_MAX);//f.iqFRotorSetHz; iqKzad = _IQ(f.kzad); - k1 = zad_intensiv_q(30000, 30000, k1, iqKzad); //20000 - + k1 = zad_intensiv_q(20000, 20000, k1, iqKzad); } +*/ -//#pragma CODE_SECTION(write_swgen_pwm_times,".fast_run"); -//void write_swgen_pwm_times() -//{ -// xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0.Ti; -// xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1.Ti; -// xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0.Ti; -// xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1.Ti; -// xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0.Ti; -// xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1.Ti; -// -// xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0.Ti; -// xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1.Ti; -// xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0.Ti; -// xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1.Ti; -// xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0.Ti; -// xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1.Ti; -// -// xpwm_time.Tbr0_0 = break_result_1; -// xpwm_time.Tbr0_1 = break_result_2; -// xpwm_time.Tbr1_0 = break_result_3; -// xpwm_time.Tbr1_1 = break_result_4; -// -// xpwm_time.write_1_2_winding_break_times(&xpwm_time); -// -// -//// logpar.log29 = xpwm_time.Ta0_0; -//// logpar.log30 = xpwm_time.Ta0_1; -//// logpar.log10 = xpwm_time.Tb0_0; -//// logpar.log11 = xpwm_time.Tb0_1; -//// logpar.log12 = xpwm_time.Tc0_0; -//// logpar.log13 = xpwm_time.Tc0_1; -//// logpar.log7 = _IQtoIQ12(svgen_pwm24_1.Alpha); -//// logpar.log8 = xpwm_time.Ta0_0 - xpwm_time.Tb0_0; -//// logpar.log9 = xpwm_time.Ta0_1 - xpwm_time.Tb0_1; -//// logpar.log10 = xpwm_time.Tb0_0 - xpwm_time.Tc0_0; -//// logpar.log11 = xpwm_time.Tb0_1 - xpwm_time.Tc0_1; -//// logpar.log12 = xpwm_time.Tc0_0 - xpwm_time.Ta0_0; -//// logpar.log13 = xpwm_time.Tc0_1 - xpwm_time.Ta0_1; -// -//} +void detect_work_revers(int direction, _iq fzad, _iq frot) +{ + static int prev_revers = 0; + int flag_revers; + // ограничение при рекуперации + if (direction == -1 && fzad > 0) + { + flag_revers = 1; + } + else + if (direction == 1 && fzad < 0) + { + flag_revers = 1; + } + else + { + flag_revers = 0; + } -//#pragma CODE_SECTION(write_swgen_pwm_times_split_eages,".fast_run2"); -//void write_swgen_pwm_times_split_eages(unsigned int mode_reload) -//{ -// -// xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0.Ti; -// xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1.Ti; -// xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0.Ti; -// xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1.Ti; -// xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0.Ti; -// xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1.Ti; -// -// xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0.Ti; -// xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1.Ti; -// xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0.Ti; -// xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1.Ti; -// xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0.Ti; -// xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1.Ti; -// -// xpwm_time.Tbr0_0 = break_result_1; -// xpwm_time.Tbr0_1 = break_result_2; -// xpwm_time.Tbr1_0 = break_result_3; -// xpwm_time.Tbr1_1 = break_result_4; -// -// xpwm_time.mode_reload = mode_reload; -// -// xpwm_time.write_1_2_winding_break_times_split(&xpwm_time); -//} + if (flag_revers && prev_revers==0) + edrk.count_revers++; -#define CONST_IQ_1 16777216 //1 + prev_revers = flag_revers; -//#pragma CODE_SECTION(fix_pwm_freq_synchro_ain,".fast_run"); -//void fix_pwm_freq_synchro_ain() -//{ -//// if (f.Sync_input_or_output == SYNC_INPUT) -// { -// sync_inc_error(); -// -// if (f.disable_sync || f.sync_ready == 0) -// { -// -// -// return; -// } -// -// if (f.pwm_freq_plus_minus_zero==1) -// { -// -// -// //Increment xtics -// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS + 1; -// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec -// -// change_freq_pwm(VAR_FREQ_PWM_XTICS); -// -// -// } -// -// if (f.pwm_freq_plus_minus_zero==-1) -// { -// //4464 -// //Decrement xtics -// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS - 1; -// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec -// -// change_freq_pwm(VAR_FREQ_PWM_XTICS); -// -// } -// -// if (f.pwm_freq_plus_minus_zero==0) -// { -// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS - 1; -// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); -// change_freq_pwm(VAR_FREQ_PWM_XTICS); -// } -// -// } -// -// -// -//} +} -//void detect_level_interrupt(void) -//{ -// -// WriteMemory(ADR_SAW_REQUEST, 0x8000); -// xpwm_time.current_period = ReadMemory(ADR_SAW_VALUE); -// -// if (xpwm_time.current_periodxpwm_time.pwm_tics/2) -// xpwm_time.where_interrupt = PWM_HIGH_LEVEL_INTERRUPT; -// -//} -// -//void detect_current_saw_val(void) -//{ -// WriteMemory(ADR_SAW_REQUEST, 0x8000); -// xpwm_time.current_period = ReadMemory(ADR_SAW_VALUE); -//} +void calc_power_full(void) +{ + _iq power_full_abs, power_one_abs, power_full_abs_f, power_one_abs_f; + // + power_one_abs = _IQabs(filter.PowerScalar); + power_one_abs_f = _IQabs(filter.PowerScalarFilter2); + power_full_abs = power_one_abs + _IQabs(edrk.iq_power_kw_another_bs); + power_full_abs_f = power_one_abs_f + _IQabs(edrk.iq_power_kw_another_bs); + if (edrk.oborots>=0) + { + edrk.iq_power_kw_full_znak = power_full_abs; + edrk.iq_power_kw_one_znak = power_one_abs; + edrk.iq_power_kw_full_filter_znak = power_full_abs_f; + edrk.iq_power_kw_one_filter_znak = power_one_abs_f; + } + else + { + edrk.iq_power_kw_full_znak = -power_full_abs; + edrk.iq_power_kw_one_znak = -power_one_abs; + edrk.iq_power_kw_full_filter_znak = -power_full_abs_f; + edrk.iq_power_kw_one_filter_znak = -power_one_abs_f; + } + edrk.iq_power_kw_full_abs = power_full_abs; + edrk.iq_power_kw_one_abs = power_one_abs; + edrk.iq_power_kw_full_filter_abs = power_full_abs_f; + edrk.iq_power_kw_one_filter_abs = power_one_abs_f; +} diff --git a/Inu/Src2/main/PWMTools.h b/Inu/Src2/main/PWMTools.h index 593f723..67f30b2 100644 --- a/Inu/Src2/main/PWMTools.h +++ b/Inu/Src2/main/PWMTools.h @@ -1,19 +1,54 @@ #ifndef PWMTOOLS_H #define PWMTOOLS_H -#include "f281xpwm.h" +#include +#include + + +////////////////////////////////////////////////// +////////////////////////////////////////////////// +////////////////////////////////////////////////// + -void InitXPWM(void); void InitPWM(void); void PWM_interrupt(void); -void initPWM_Variables(void); +void PWM_interrupt_main(void); -void slow_vector_update(void); + + +void stop_wdog(void); +void start_wdog(void); + + +void global_time_interrupt(void); +void optical_bus_read_write_interrupt(void); +void pwm_analog_ext_interrupt(void); +void pwm_inc_interrupt(void); + +void fix_pwm_freq_synchro_ain(void); +void async_pwm_ext_interrupt(void); + + + +void calc_rotors(int flag); + +void detect_work_revers(int direction, _iq fzad, _iq frot); + +void calc_power_full(void); + + + +////////////////////////////////////////////////// +////////////////////////////////////////////////// +////////////////////////////////////////////////// +////////////////////////////////////////////////// extern PWMGEND pwmd; -extern int VAR_FREQ_PWM_XTICS; -extern int VAR_PERIOD_MAX_XTICS; -extern int VAR_PERIOD_MIN_XTICS; -extern int VAR_PERIOD_MIN_BR_XTICS; +//extern int var_freq_pwm_xtics; +//extern int var_period_max_xtics; +//extern int var_period_min_xtics; + + + #endif //PWMTOOLS_H diff --git a/Inu/Src2/551/main/adc_internal.h b/Inu/Src2/main/adc_internal.h similarity index 100% rename from Inu/Src2/551/main/adc_internal.h rename to Inu/Src2/main/adc_internal.h diff --git a/Inu/Src2/main/adc_tools.c b/Inu/Src2/main/adc_tools.c index 4af68a7..80b3b8d 100644 --- a/Inu/Src2/main/adc_tools.c +++ b/Inu/Src2/main/adc_tools.c @@ -1,528 +1,1412 @@ -// #include "project.h" -#include "adc_tools.h" -// #include "xp_project.h" +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "IQmathLib.h" -#include "math.h" -#include "my_filter.h" -#include "params.h" -// #include "params_protect.h" -#include "vector.h" -// #include "xp_adc.h" -// #include "TuneUpPlane.h" //Ìîðãàíèå ñâåòîäèîäîì -// #include "log_to_memory.h" -// #include "errors.h" -// #define COUNT_ARR_ADC_BUF 2 -#define Shift_Filter 1 //2 +#include +#include +#include +#include +#include -#define BTR_ENABLED +#include "mathlib.h" +#include "filter_v1.h" +#include "xp_project.h" -#define R_ADC_DEFAULT { 1180 ,1180 , 256, 256, 256, 256, 256, 1180, 1180, 256, 256, 256, 256, 256, 256, 256, 256, 256 } -#define K_LEM_ADC_DEFAULT { 60000,60000,5000, 5000,5000,5000,5000,60000,60000,5000,5000,5000,5000,5000,5000,5000,5000,5000 } -//#define LOG_ACP_TO_BUF +//#include "spartan_tools.h" + + +//#define LOG_ACP_TO_BUF 1 + +#ifdef LOG_ACP_TO_BUF + +#define SIZE_BUF_LOG_ACP 500 +#pragma DATA_SECTION(BUF_ADC,".slow_vars") +int BUF_ADC[SIZE_BUF_LOG_ACP]; +#pragma DATA_SECTION(BUF_ADC_2,".slow_vars") +int BUF_ADC_2[SIZE_BUF_LOG_ACP]; + +#endif + + + +#if (USE_INTERNAL_ADC==1) + +#if(C_adc_number==1) +unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0,R_ADC_DEFAULT_INTERNAL }; +unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_INTERNAL}; +float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_INTERNAL}; +#endif +#if(C_adc_number==2) +unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1,R_ADC_DEFAULT_INTERNAL }; +unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_INTERNAL }; +float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_INTERNAL }; +#endif +#if(C_adc_number==3) +unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2,R_ADC_DEFAULT_INTERNAL }; +unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2, K_LEM_ADC_DEFAULT_INTERNAL }; +float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2, NORMA_ADC_DEFAULT_INTERNAL }; +#endif + +#else + +#if(C_adc_number==1) +#pragma DATA_SECTION(R_ADC,".slow_vars") +unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0 }; +#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") +unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0}; +#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") +float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0}; +#endif +#if(C_adc_number==2) +#pragma DATA_SECTION(R_ADC,".slow_vars") +unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1 }; +#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") +unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1 }; +#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") +float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1 }; +#endif +#if(C_adc_number==3) +#pragma DATA_SECTION(R_ADC,".slow_vars") +unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2 }; +#pragma DATA_SECTION(K_LEM_ADC,".slow_vars") +unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2 }; +#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars") +float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2 }; +#endif + +#endif + +//unsigned int const R_ADC_1[16] = R_ADC_DEFAULT_1; +//unsigned int const K_LEM_ADC_1[16] = K_LEM_ADC_DEFAULT_1; + + + + +#if (USE_INTERNAL_ADC==1) +int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; +#else + +#if(C_adc_number==1) +int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; +#endif +#if(C_adc_number==2) +int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; +#endif +#if(C_adc_number==3) +int error_ADC[COUNT_ARR_ADC_BUF][16] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; +#endif + +#endif + + +#pragma DATA_SECTION(ADC_f,".fast_vars"); int ADC_f[COUNT_ARR_ADC_BUF][16]; +#pragma DATA_SECTION(ADC_fast,".fast_vars"); +int ADC_fast[COUNT_ARR_ADC_BUF][16][COUNT_ARR_ADC_BUF_FAST_POINT]; + + +#pragma DATA_SECTION(ADC_sf,".fast_vars"); int ADC_sf[COUNT_ARR_ADC_BUF][16]; +#pragma DATA_SECTION(analog,".fast_vars"); +ANALOG_VALUE analog = ANALOG_VALUE_DEFAULT; -#define ZERO_ADC_DEFAULT {2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048} -_iq19 iq19_zero_ADC[18] = ZERO_ADC_DEFAULT; +#pragma DATA_SECTION(filter,".fast_vars"); +ANALOG_VALUE filter = ANALOG_VALUE_DEFAULT; -int zero_ADC[18] = ZERO_ADC_DEFAULT; -_iq iq_k_norm_ADC[18]; -_iq19 iq19_k_norm_ADC[18]; +#pragma DATA_SECTION(analog_zero,".fast_vars"); +ANALOG_VALUE analog_zero = ANALOG_VALUE_DEFAULT; -_iq iq_norm_ADC[18]; -unsigned int const R_ADC[18] = R_ADC_DEFAULT; -unsigned int const K_LEM_ADC[18] = K_LEM_ADC_DEFAULT; -//#pragma DATA_SECTION(analog,".fast_vars"); -ANALOG_VALUE analog; -//#pragma DATA_SECTION(filter,".fast_vars"); -ANALOG_VALUE filter; +unsigned int const level_err_ADC_PLUS[16] = level_err_ADC_PLUS_default; +unsigned int const level_err_ADC_MINUS[16] = level_err_ADC_MINUS_default; + + +#pragma DATA_SECTION(err_adc_protect,".fast_vars"); +#pragma DATA_SECTION(mask_err_adc_protect,".fast_vars"); +ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF],mask_err_adc_protect[COUNT_ARR_ADC_BUF]; + -ANALOG_RAW_DATA rawData = ANALOG_RAW_DATA_DEFAULT; -_iq koef_Ud_long_filter=0; -_iq koef_Ud_fast_filter=0; _iq koef_Im_filter=0; +_iq koef_Power_filter=0; +_iq koef_Power_filter2=0; -_iq koef_Iabc_filter=0; +#pragma DATA_SECTION(k_norm_ADC,".slow_vars") +_iq19 k_norm_ADC[COUNT_ARR_ADC_BUF][16]; -_iq koef_Wlong=0; +#pragma DATA_SECTION(iq19_zero_ADC,".fast_vars"); +_iq19 iq19_zero_ADC[COUNT_ARR_ADC_BUF][16]; -void calc_norm_ADC(void); -void analog_values_calc(void); -_iq im_calc( _iq ia, _iq ib, _iq ic); +#pragma DATA_SECTION(zero_ADC,".slow_vars") +int zero_ADC[COUNT_ARR_ADC_BUF][16]; -void read_adc(ANALOG_RAW_DATA *data) + +#pragma DATA_SECTION(iq19_k_norm_ADC,".fast_vars"); +_iq19 iq19_k_norm_ADC[COUNT_ARR_ADC_BUF][16]; + +#pragma DATA_SECTION(iq_norm_ADC,".fast_vars"); +_iq iq_norm_ADC[COUNT_ARR_ADC_BUF][16]; + +#pragma DATA_SECTION(iq_norm_ADC_sf,".fast_vars"); +_iq iq_norm_ADC_sf[COUNT_ARR_ADC_BUF][16]; + + +#pragma DATA_SECTION(koef_Uzpt_long_filter,".fast_vars"); +_iq koef_Uzpt_long_filter=0; + +#pragma DATA_SECTION(koef_Uzpt_fast_filter,".fast_vars"); +_iq koef_Uzpt_fast_filter=0; + +#pragma DATA_SECTION(koef_Uin_filter,".fast_vars"); +_iq koef_Uin_filter=0; + + +void fast_detect_protect_ACP(); +//void fast_read_all_adc_one(int cc); +//void fast_read_all_adc_more(void); + + +#if (USE_INTERNAL_ADC==1) +#pragma CODE_SECTION(adc_isr,".fast_run"); +interrupt void adc_isr(void) { - ADC_f[0][0] = data->U1_1; - ADC_f[0][1] = data->U1_2; - ADC_f[0][2] = data->Izpt1_1; - ADC_f[0][3] = data->Izpt1_2; - ADC_f[0][4] = data->Ia1; - ADC_f[0][5] = data->Ib1; - ADC_f[0][6] = data->Ic1; - ADC_f[0][7] = 0; - ADC_f[0][8] = data->U2_1; - ADC_f[0][9] = data->U2_2; - ADC_f[0][10] = data->Izpt2_1; - ADC_f[0][11] = data->Izpt2_2; - ADC_f[0][12] = data->Ia2; - ADC_f[0][13] = data->Ib2; - ADC_f[0][14] = data->Ic2; - ADC_f[0][15] = 0; +// unsigned char k; + static char l_ir=0; + static char step_acp=0; + +//i_led1_on_off(1); + +// i_led1_on_off(1); + + project.adc->read_pbus(&project.adc[0]); + + ADC_f[0][0] = project.adc[0].read.pbus.adc_value[0]; + ADC_f[0][1] = project.adc[0].read.pbus.adc_value[1]; + ADC_f[0][2] = project.adc[0].read.pbus.adc_value[2]; + ADC_f[0][3] = project.adc[0].read.pbus.adc_value[3]; + ADC_f[0][4] = project.adc[0].read.pbus.adc_value[4]; + ADC_f[0][5] = project.adc[0].read.pbus.adc_value[5]; + ADC_f[0][6] = project.adc[0].read.pbus.adc_value[6]; + ADC_f[0][7] = project.adc[0].read.pbus.adc_value[7]; + ADC_f[0][8] = project.adc[0].read.pbus.adc_value[8]; + ADC_f[0][9] = project.adc[0].read.pbus.adc_value[9]; + ADC_f[0][10] = project.adc[0].read.pbus.adc_value[10]; + ADC_f[0][11] = project.adc[0].read.pbus.adc_value[11]; + ADC_f[0][12] = project.adc[0].read.pbus.adc_value[12]; + ADC_f[0][13] = project.adc[0].read.pbus.adc_value[13]; + ADC_f[0][14] = project.adc[0].read.pbus.adc_value[14]; + ADC_f[0][15] = project.adc[0].read.pbus.adc_value[15]; ADC_sf[0][0] += (ADC_f[0][0] - ADC_sf[0][0]) >> Shift_Filter; ADC_sf[0][1] += (ADC_f[0][1] - ADC_sf[0][1]) >> Shift_Filter; ADC_sf[0][2] += (ADC_f[0][2] - ADC_sf[0][2]) >> Shift_Filter; ADC_sf[0][3] += (ADC_f[0][3] - ADC_sf[0][3]) >> Shift_Filter; - ADC_sf[0][4] += (ADC_f[0][4] - ADC_sf[0][4]) >> Shift_Filter; - ADC_sf[0][5] += (ADC_f[0][5] - ADC_sf[0][5]) >> Shift_Filter; - ADC_sf[0][6] += (ADC_f[0][6] - ADC_sf[0][6]) >> Shift_Filter; - - ADC_sf[0][7] += (ADC_f[0][7] - ADC_sf[0][7]) >> Shift_Filter; - ADC_sf[0][8] += (ADC_f[0][8] - ADC_sf[0][8]) >> Shift_Filter; - ADC_sf[0][9] += (ADC_f[0][9] - ADC_sf[0][9]) >> Shift_Filter; - ADC_sf[0][10] += (ADC_f[0][10] - ADC_sf[0][10]) >> Shift_Filter; - ADC_sf[0][11] += (ADC_f[0][11] - ADC_sf[0][11]) >> Shift_Filter; - ADC_sf[0][12] += (ADC_f[0][12] - ADC_sf[0][12]) >> Shift_Filter; - ADC_sf[0][13] += (ADC_f[0][13] - ADC_sf[0][13]) >> Shift_Filter; - ADC_sf[0][14] += (ADC_f[0][14] - ADC_sf[0][14]) >> Shift_Filter; - ADC_sf[0][15] += (ADC_f[0][15] - ADC_sf[0][15]) >> Shift_Filter; - ADC_f[1][0] = 0; - ADC_f[1][1] = 0; - ADC_f[1][2] = 0; - ADC_f[1][3] = 0; +/* + + + if (ADC_sf[2][0]>ERR_LEVEL_ADC_PLUS || ADC_sf[2][0]ERR_LEVEL_ADC_PLUS || ADC_sf[2][1]ERR_LEVEL_ADC_PLUS || ADC_f[2]ERR_LEVEL_ADC_PLUS || ADC_sf[2][3]ERR_LEVEL_ADC_PLUS || ADC_f[8]ERR_LEVEL_ADC_PLUS || ADC_f[9]ERR_LEVEL_ADC_PLUS || ADC_f[10]ERR_LEVEL_ADC_PLUS_6 || ADC_f[2][11]> Shift_Filter; - ADC_sf[1][1] += (ADC_f[1][1] - ADC_sf[1][1]) >> Shift_Filter; - ADC_sf[1][2] += (ADC_f[1][2] - ADC_sf[1][2]) >> Shift_Filter; - ADC_sf[1][3] += (ADC_f[1][3] - ADC_sf[1][3]) >> Shift_Filter; } -void acp_Handler(void) + + +// это ни при чем +#pragma CODE_SECTION(timer2_isr,".fast_run"); +interrupt void timer2_isr(void) { - // read_adc(); - calc_norm_ADC(); - analog_values_calc(); - // Read_Fast_Errors(); + +//led2_on_off(1); +//i_led2_on_off(1); +// EvaTimer2InterruptCount++; + // Enable more interrupts from this timer + + EvaRegs.EVAIMRB.bit.T2PINT = 1; + + // Note: To be safe, use a mask value to write to the entire + // EVAIFRB register. Writing to one bit will cause a read-modify-write + // operation that may have the result of writing 1's to clear + // bits other then those intended. + EvaRegs.EVAIFRB.all = BIT0; + + // Acknowledge interrupt to receive more interrupts from PIE group 3 + PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; +// AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; + +/* + ADC_filter[15] = 333; +// DOut(Error,1); +// GpioDataRegs.GPDTOGGLE.bit.GPIOD5=1; + + EvaRegs.EVAIMRA.bit.T1PINT = 1; + EvaRegs.EVAIFRA.all=0x80; + PieCtrlRegs.PIEACK.bit.ACK2=1; // Issue PIE ack + + EvbRegs.EVBIFRA.all = BIT7; + // Acknowledge interrupt to receive more interrupts from PIE group 4 + PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; +*/ +// i_led2_on_off(1); +//i_led2_on_off(0); + } -#define COUNT_DETECT_ZERO 500 -// void detect_zero_analog() -// { -// int i, k; -// double tmp_buff[2][16] = {0}; -// // _iq koef_zero_ADC_filter = 1; -// for(i = 0; i < 16; tmp_buff[0][i++] = 0); -// for(i = 0; i < 16; tmp_buff[1][i++] = 0); -// i = 0; -// for (i = 0; imaxU) maxU = buf_U1_3point[1]; +// if (buf_U1_3point[2]>maxU) maxU = buf_U1_3point[2]; +// +// if (buf_U1_3point[1]= component_Ready) + detect_zero_analog(i); + } -void calc_norm_ADC(void) -{ - iq_norm_ADC[0] = norma_adc(0, 0, 0); - iq_norm_ADC[1] = norma_adc(0, 1, 1); - iq_norm_ADC[2] = norma_adc(0, 2, 2); - iq_norm_ADC[3] = norma_adc(0, 3, 3); - iq_norm_ADC[4] = norma_adc(0, 4, 4); - iq_norm_ADC[5] = norma_adc(0, 5, 5); - iq_norm_ADC[6] = norma_adc(0, 6, 6); - iq_norm_ADC[7] = norma_adc(0, 8, 7); - iq_norm_ADC[8] = norma_adc(0, 9, 8); - iq_norm_ADC[9] = norma_adc(0, 10, 9); - iq_norm_ADC[10] = norma_adc(0, 11, 10); - iq_norm_ADC[11] = norma_adc(0, 12, 11); - iq_norm_ADC[12] = norma_adc(0, 13, 12); - iq_norm_ADC[13] = norma_adc(0, 14, 13); - iq_norm_ADC[14] = norma_adc(1, 0, 14); - iq_norm_ADC[15] = norma_adc(1, 1, 15); - iq_norm_ADC[16] = norma_adc(1, 2, 16); - iq_norm_ADC[17] = norma_adc(1, 3, 17); -} - -void analog_values_calc(void) -{ - - analog.iqU_1 = iq_norm_ADC[0]; - analog.iqU_2 = iq_norm_ADC[1]; - analog.iqU_3 = iq_norm_ADC[7]; - analog.iqU_4 = iq_norm_ADC[8]; - - analog.iqIin_1 = iq_norm_ADC[2]; - analog.iqIin_2 = -iq_norm_ADC[3]; - analog.iqIin_3 = iq_norm_ADC[9]; - analog.iqIin_4 = -iq_norm_ADC[10]; +// zero_ADC[1][2] = 2010;//1976; // uab +// zero_ADC[1][3] = 2010;//1989; // ubc +// zero_ADC[1][4] = 2010;//1994; // uca -// #if PROJECT_ARKTIKA == 1 - analog.iqIa1_1 = iq_norm_ADC[4]; - analog.iqIb1_1 = iq_norm_ADC[5]; - analog.iqIc1_1 = iq_norm_ADC[6]; + zero_ADC[0][0]=zero_ADC[0][2];//2042;//1992;//1835; //uzpt + zero_ADC[0][1]=zero_ADC[0][2];//2042;//1992;//1835; //uzpt - analog.iqIa2_1 = iq_norm_ADC[11]; - analog.iqIb2_1 = iq_norm_ADC[12]; - analog.iqIc2_1 = iq_norm_ADC[13]; -// #endif -#if PROJECT_SIBERIA == 1 - analog.iqIa1_1 = iq_norm_ADC[6]; - analog.iqIb1_1 = iq_norm_ADC[5]; - analog.iqIc1_1 = iq_norm_ADC[4]; - analog.iqIa2_1 = iq_norm_ADC[13]; - analog.iqIb2_1 = iq_norm_ADC[12]; - analog.iqIc2_1 = iq_norm_ADC[11]; + +#if (COUNT_ARR_ADC_BUF>1) + zero_ADC[1][1]=zero_ADC[1][15]; + zero_ADC[1][2]=zero_ADC[1][15]; + zero_ADC[1][3]=zero_ADC[1][15]; + zero_ADC[1][4]=zero_ADC[1][15]; + zero_ADC[1][5]=zero_ADC[1][15]; + zero_ADC[1][6]=zero_ADC[1][15]; + zero_ADC[1][7]=zero_ADC[1][15]; + zero_ADC[1][8]=zero_ADC[1][15]; + zero_ADC[1][9]=zero_ADC[1][15]; + zero_ADC[1][10]=zero_ADC[1][15]; + zero_ADC[1][11]=zero_ADC[1][15]; + zero_ADC[1][12]=zero_ADC[1][15]; + zero_ADC[1][13]=zero_ADC[1][15]; + zero_ADC[1][14]=zero_ADC[1][15]; #endif - analog.iqIbtr1_1 = labs(iq_norm_ADC[14]); - analog.iqIbtr1_2 = labs(iq_norm_ADC[16]); - analog.iqIbtr2_1 = labs(iq_norm_ADC[15]); - analog.iqIbtr2_2 = labs(iq_norm_ADC[17]); - analog.iqIa1_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIa1_rms, _IQabs(analog.iqIa1_1)); - analog.iqIb1_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIb1_rms, _IQabs(analog.iqIb1_1)); - analog.iqIc1_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIc1_rms, _IQabs(analog.iqIc1_1)); - - analog.iqIa2_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIa2_rms, _IQabs(analog.iqIa2_1)); - analog.iqIb2_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIb2_rms, _IQabs(analog.iqIb2_1)); - analog.iqIc2_rms = exp_regul_iq(koef_Iabc_filter, analog.iqIc2_rms, _IQabs(analog.iqIc2_1)); - - - filter.iqU_1_long = exp_regul_iq(koef_Ud_long_filter, filter.iqU_1_long, analog.iqU_1); - filter.iqU_2_long = exp_regul_iq(koef_Ud_long_filter, filter.iqU_2_long, analog.iqU_2); - filter.iqU_3_long = exp_regul_iq(koef_Ud_long_filter, filter.iqU_3_long, analog.iqU_3); - filter.iqU_4_long = exp_regul_iq(koef_Ud_long_filter, filter.iqU_4_long, analog.iqU_4); - - filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1); - filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2); - filter.iqIin_3 = exp_regul_iq(koef_Im_filter, filter.iqIin_3, analog.iqIin_3); - filter.iqIin_4 = exp_regul_iq(koef_Im_filter, filter.iqIin_4, analog.iqIin_4); - - - - - filter.iqU_1_fast = exp_regul_iq(koef_Ud_fast_filter, filter.iqU_1_fast, analog.iqU_1); - filter.iqU_2_fast = exp_regul_iq(koef_Ud_fast_filter, filter.iqU_2_fast, analog.iqU_2); - - filter.iqU_3_fast = exp_regul_iq(koef_Ud_fast_filter, filter.iqU_3_fast, analog.iqU_3); - filter.iqU_4_fast = exp_regul_iq(koef_Ud_fast_filter, filter.iqU_4_fast, analog.iqU_4); - - filter.iqIa1_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIa1_1, analog.iqIa1_1); - filter.iqIb1_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIb1_1, analog.iqIb1_1); - filter.iqIc1_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIc1_1, analog.iqIc1_1); - - filter.iqIa2_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIa2_1, analog.iqIa2_1); - filter.iqIb2_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIb2_1, analog.iqIb2_1); - filter.iqIc2_1 = exp_regul_iq(koef_Ud_fast_filter, filter.iqIc2_1, analog.iqIc2_1); - - - - analog.iqW1 = _IQmpy(filter.iqU_1_fast, analog.iqIin_1) + _IQmpy(filter.iqU_2_fast, analog.iqIin_2); - analog.iqW2 = _IQmpy(filter.iqU_3_fast, analog.iqIin_3) + _IQmpy(filter.iqU_4_fast, analog.iqIin_4); - analog.iqW = analog.iqW1 + analog.iqW2; + for (k=0;k<16;k++) + { + for (i=0;i2200) || (zero_ADC[i][k]<1900)) + zero_ADC[i][k] = DEFAULT_ZERO_ADC; + } + } - analog.iqIm_1 = im_calc(filter.iqIa1_1, filter.iqIb1_1, filter.iqIc1_1); - analog.iqIm_2 = im_calc(filter.iqIa2_1, filter.iqIb2_1, filter.iqIc2_1); + for (k=0;k<16;k++) + { + for (i=0;ierror_counts.adc_0) +// if (ADC_sf[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); + // if (ADC_sf[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); + } + } + + +} + +#if (USE_INTERNAL_ADC==1) +#pragma CODE_SECTION(fast_detect_protect_ACP_internal,".fast_run"); +void fast_detect_protect_ACP_internal(void) +{ + int k; + k=0; + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); + k=1; + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); + k=3; + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (2, k); + if (ADC_sf[COUNT_ARR_ADC_BUF-1][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(2, k); + + +} +#endif + + +#pragma CODE_SECTION(fast_detect_protect_ACP,".fast_run"); +void fast_detect_protect_ACP() +{ + int i,k; + +// for (i=0;i<2;i++) + { +// if (project.adc[i].status == component_Ready) +#if(C_adc_number>=1) + i = 0; + for (k=0;k<14;k++) + { + if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); + if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); + } +#endif +#if(C_adc_number>=2) + i = 1; + for (k=2;k<5;k++) + { + if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); + if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); + } +#endif +#if(C_adc_number>=3) + i = 2; + for (k=0;k<15;k++) + { + if (ADC_f[i][k] >= ERR_LEVEL_ADC_PLUS) detect_protect_ACP_plus (i, k); + if (ADC_f[i][k] <= ERR_LEVEL_ADC_MINUS) detect_protect_ACP_minus(i, k); + } +#endif + + } + +} + +#pragma CODE_SECTION(norma_adc,".fast_run"); +inline _iq norma_adc(int plane, int chan) +{ +// return _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[n_norm] - ((long)ADC_sf[plane][chan]<<19) ),iq19_k_norm_ADC[n_norm])); + return _IQ19toIQ(_IQ19mpy((((long)ADC_f[plane][chan]<<19) - iq19_zero_ADC[plane][chan]),iq19_k_norm_ADC[plane][chan])); +} + + + +#if (USE_INTERNAL_ADC==1) +#pragma CODE_SECTION(norma_adc_internal_sf,".fast_run2"); +_iq norma_adc_internal_sf(int l) +{ + return _IQ19toIQ(_IQ19mpy((((long)ADC_sf[2][l]<<19) - iq19_zero_ADC[2][l]),iq19_k_norm_ADC[2][l])); +} +#endif + + +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// +///////////////////////////////////////////////////////// +// +//#pragma CODE_SECTION(fast_read_all_adc_one,".fast_run"); +//void fast_read_all_adc_one(int cc) +//{ +// int i,k; +// int t; +// +// i_led1_on_off(1); +// +// project.adc[0].read_pbus(&project.adc[0]); +// +// for (k=0;k<16;k++) +// { +// t = project.adc[0].read.pbus.adc_value[k]; +// ADC_fast[0][k][cc] = t; +// +// // save max values +// if (t>ADC_fast[0][k][1] || cc==3) +// ADC_fast[0][k][1] = t; +// // save min values +// if (tflags.bit.error==0 ) +// { +// +// +// +// fast_read_all_adc_one(3); +// pause_1000(p); +// fast_read_all_adc_one(4); +// pause_1000(p); +// fast_read_all_adc_one(5); +// pause_1000(p); +// fast_read_all_adc_one(6); +// pause_1000(p); +// fast_read_all_adc_one(7); +// pause_1000(p); +// fast_read_all_adc_one(8); +// +// +// +// for (k=0;k<16;k++) +// { +// ADC_fast[0][k][0] = (-ADC_fast[0][k][1] - ADC_fast[0][k][2] + ADC_fast[0][k][3] + ADC_fast[0][k][4] +// +ADC_fast[0][k][5] + ADC_fast[0][k][6] + ADC_fast[0][k][7] + ADC_fast[0][k][8]) >> 2; // сумму делим на 4 +// } +// +// } +// else +// { +// for (k=0;k<16;k++) +// { +// ADC_fast[0][k][0] = 5000; // error +// } +// } +// +// +// if (project.adc[1].status == component_Ready +// && project.controller.read.errors.bit.error_pbus == 0 +// && project.controller.read.errors_buses.bit.slave_addr_error==0 +// && project.x_parallel_bus->flags.bit.error==0 ) +// { +// +// fast_read_all_adc_two(); +// } +// else +// { +// for (k=0;k<16;k++) +// { +// ADC_fast[1][k][0] = 5000; // error +// } +// } +// +//} + +///////////////////////////////////////////////////////// +// +//#pragma CODE_SECTION(norma_fast_adc,".fast_run"); +//void norma_fast_adc(void) +//{ +// int i,k; +//// int bb; +// +//#ifdef LOG_ACP_TO_BUF +// static int c_log=0; +// static int n_log_acp_p=0; +// static int n_log_acp_c=2; +// static int n_log_acp_p_2=0; +// static int n_log_acp_c_2=2; +// +//#endif +// +// for (i=0;iflags.bit.error==0 ) +// { +// for (k=0;k<16;k++) +// { +// iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_fast[i][k][0]<<19) ),iq19_k_norm_ADC[i][k])); +// } +// } +// else +// { +// for (k=0;k<16;k++) +// { +// iq_norm_ADC[i][k] = 0; +// } +// +// } +// +// } +// +//#ifdef LOG_ACP_TO_BUF +// if (c_log>=SIZE_BUF_LOG_ACP) +// c_log=0; +// BUF_ADC[c_log]=ADC_fast[n_log_acp_p][n_log_acp_c][0]; +// BUF_ADC_2[c_log]=ADC_fast[n_log_acp_p_2][n_log_acp_c_2][3]; +// c_log++; +//#endif +// +////i_led2_off(); +//} + +///////////////////////////////////////////////////////// + +/* +#pragma CODE_SECTION(norma_all_adc,".fast_run"); +void norma_all_adc(void) +{ + int i,k; +// int bb; +#ifdef LOG_ACP_TO_BUF + static int c_log=0; + static int n_log_acp_p=0; + static int n_log_acp_c=2; + static int n_log_acp_p_2=0; + static int n_log_acp_c_2=5; + +#endif + + for (i=0;iread_pbus(&project.adc[i]); + + if ( project.adc[i].status == component_Ready + && project.controller.read.errors.bit.error_pbus == 0 + && project.controller.read.errors_buses.bit.slave_addr_error==0 + && project.x_parallel_bus->flags.bit.error==0 ) + { + for (k=0;k<16;k++) + { + +// ADC_f[i][k] = (int)pr->data.adc[i].acc_short[k]; + +#ifdef ADC_READ_FROM_PARALLEL_BUS + ADC_f[i][k] = project.adc[i].read.pbus.adc_value[k]; + ADC_sf[i][k] += (((int)(ADC_f[i][k] - ADC_sf[i][k]))>>SDVIG_K_FILTER_S); +#else +// ADC_f[i][k] = project.adc[i].fpga.read.channels[k].value.acc_short;//iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[i][k] - ((long)project.adc[i].fpga.read.channels[k].value.acc_short<<19) ),iq19_k_norm_ADC[i][k])); +#endif + iq_norm_ADC[i][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[i][k] + ((long)ADC_f[i][k]<<19) ),iq19_k_norm_ADC[i][k])); +// iq_norm_ADC_sf[i][k] = _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[i][k] - ((long)ADC_sf[i][k]<<19) ),iq19_k_norm_ADC[i][k])); + } + } + else + { + for (k=0;k<16;k++) + { + ADC_f[i][k] = 5000;//DEFAULT_ZERO_ADC; + ADC_sf[i][k] = 5000;//DEFAULT_ZERO_ADC; + iq_norm_ADC[i][k] = 0; + } + + } + + } + +#ifdef LOG_ACP_TO_BUF + if (c_log>=SIZE_BUF_LOG_ACP) + c_log=0; + BUF_ADC[c_log]=ADC_f[n_log_acp_p][n_log_acp_c]; + BUF_ADC_2[c_log]=ADC_f[n_log_acp_p_2][n_log_acp_c_2]; + c_log++; +#endif + + +#if (USE_INTERNAL_ADC==1) + iq_norm_ADC[COUNT_ARR_ADC_BUF-1][0] = norma_adc_internal_sf(0); + iq_norm_ADC[COUNT_ARR_ADC_BUF-1][1] = norma_adc_internal_sf(1); + iq_norm_ADC[COUNT_ARR_ADC_BUF-1][3] = norma_adc_internal_sf(3); +#endif +//i_led2_off(); +} +*/ +//////////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(norma_adc_nc,".fast_run"); +void norma_adc_nc(int nc) +{ + int k; +// int bb; + + project.read_errors_controller(); + project.adc[nc].read_pbus(&project.adc[nc]); + + if ( project.adc[nc].status == component_Ready + && project.controller.read.errors.bit.error_pbus == 0 + && project.controller.read.errors_buses.bit.slave_addr_error==0 + && project.x_parallel_bus->flags.bit.error==0 ) + { + for (k=0;k<16;k++) + { + + ADC_f[nc][k] = project.adc[nc].read.pbus.adc_value[k]; + ADC_sf[nc][k] += (((int)(ADC_f[nc][k] - ADC_sf[nc][k]))>>SDVIG_K_FILTER_S); + iq_norm_ADC[nc][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[nc][k] + ((long)ADC_f[nc][k]<<19) ),iq19_k_norm_ADC[nc][k])); + } + } + else + { + for (k=0;k<16;k++) + { + ADC_f[nc][k] = 5000;//DEFAULT_ZERO_ADC; + ADC_sf[nc][k] = 5000;//DEFAULT_ZERO_ADC; + iq_norm_ADC[nc][k] = 0; + } + + } +} + +//////////////////////////////////////////////////////////////////// + + +#pragma CODE_SECTION(calc_norm_ADC_1,".fast_run"); +void calc_norm_ADC_1(int run_norma) +{ + _iq a1,a2,a3; + +#if (USE_ADC_1) + + if (run_norma) + norma_adc_nc(1); + + +#if (_FLOOR6==1) + + analog.T_U01 = + analog.T_U02 = + analog.T_U03 = + analog.T_U04 = + analog.T_U05 = + analog.T_U06 = + analog.T_U07 = + analog.T_Water_external = + analog.T_Water_internal = + + analog.P_Water_internal = + + analog.T_Air_01 = + analog.T_Air_02 = + analog.T_Air_03 = + analog.T_Air_04 = 0; + +#else + analog.T_U01 = iq_norm_ADC[1][1]; + analog.T_U02 = iq_norm_ADC[1][2]; + analog.T_U03 = iq_norm_ADC[1][3]; + analog.T_U04 = iq_norm_ADC[1][4]; + analog.T_U05 = iq_norm_ADC[1][5]; + analog.T_U06 = iq_norm_ADC[1][6]; + analog.T_U07 = iq_norm_ADC[1][7]; + analog.T_Water_external = iq_norm_ADC[1][9]; + analog.T_Water_internal = iq_norm_ADC[1][8]; + + analog.P_Water_internal = iq_norm_ADC[1][14]; + + analog.T_Air_01 = iq_norm_ADC[1][10]; + analog.T_Air_02 = iq_norm_ADC[1][11]; + analog.T_Air_03 = iq_norm_ADC[1][12]; + analog.T_Air_04 = iq_norm_ADC[1][13]; + + +#endif +#else + + analog.T_U01 = + analog.T_U02 = + analog.T_U03 = + analog.T_U04 = + analog.T_U05 = + analog.T_U06 = + analog.T_U07 = + analog.T_Water_external = + analog.T_Water_internal = + + analog.P_Water_internal = + + analog.T_Air_01 = + analog.T_Air_02 = + analog.T_Air_03 = + analog.T_Air_04 = 0; + +#endif +// analog.iqI_vozbud = iq_norm_ADC[1][13]; + +} + +//////////////////////////////////////////////////////////////////// +#pragma CODE_SECTION(calc_norm_ADC_0,".fast_run"); +void calc_norm_ADC_0(int run_norma) +{ + _iq a1,a2,a3; + +#if (USE_ADC_0) + + if (run_norma) + norma_adc_nc(0); + +#if (_FLOOR6) + analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit; + analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit; +#else + analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1; + analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2; +#endif + analog.iqIu_1 = iq_norm_ADC[0][2]; + analog.iqIv_1 = iq_norm_ADC[0][3]; + analog.iqIw_1 = iq_norm_ADC[0][4]; + + analog.iqIu_2 = iq_norm_ADC[0][5]; + analog.iqIv_2 = iq_norm_ADC[0][6]; + analog.iqIw_2 = iq_norm_ADC[0][7]; + + analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут + analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут + + analog.iqUin_A1B1 = iq_norm_ADC[0][10]; + +// два варианта подключения датчиков 23550.1 более правильный - по схеме +// 23550.1 + + analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1 + analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1 + +// 23550.3 bs1 bs2 + +// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3 +// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3 +// + analog.iqUin_B2C2 = iq_norm_ADC[0][13]; + + analog.iqIbreak_1 = iq_norm_ADC[0][14]; + analog.iqIbreak_2 = iq_norm_ADC[0][15]; + +#else + analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 = + analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 = + analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2 + = 0; +#endif + + analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1); + analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2); + + + + filter.iqU_1_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_1_long, analog.iqU_1); + filter.iqU_2_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_2_long, analog.iqU_2); + + +// analog.iqU_1_fast = filter_U1_3point(analog.iqU_1_fast); + filter.iqU_1_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_1_fast, analog.iqU_1); + filter.iqU_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_2_fast, analog.iqU_2); + + +// filter.iqUzpt_2_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqUzpt_2_2_fast, analog.iqUzpt_2_2); + + + +//15 + + + analog.iqIm_1 = im_calc(analog.iqIu_1, analog.iqIv_1, analog.iqIw_1); + analog.iqIm_2 = im_calc(analog.iqIu_2, analog.iqIv_2, analog.iqIw_2); + + analog.iqIu = analog.iqIu_1+analog.iqIu_2; + analog.iqIv = analog.iqIv_1+analog.iqIv_2; + analog.iqIw = analog.iqIw_1+analog.iqIw_2; + + analog.iqIm = im_calc(analog.iqIu, analog.iqIv, analog.iqIw); + + + analog.iqIin_sum = analog.iqIin_1+analog.iqIin_2; + +// analog.iqIm_3 = im_calc(analog.iqIa1_1_fir_n+analog.iqIa2_1_fir_n, analog.iqIb1_1_fir_n+analog.iqIb2_1_fir_n, analog.iqIc1_1_fir_n+analog.iqIc2_1_fir_n); + + analog.iqUin_m1 = im_calc(analog.iqUin_A1B1, analog.iqUin_B1C1, analog.iqUin_C1A1); + analog.iqUin_m2 = im_calc(analog.iqUin_A2B2, analog.iqUin_B2C2, analog.iqUin_C2A2); + +// analog.iqUin_m2 = im_calc(analog.UinA2, analog.UinB2, analog.UinC2); + + filter.iqUin_m1 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m1, analog.iqUin_m1); + filter.iqUin_m2 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m2, analog.iqUin_m2); + // i_led1_on_off(0); // i_led1_on_off(1); +//1 + filter.iqIm_1 = exp_regul_iq(koef_Im_filter, filter.iqIm_1, analog.iqIm_1); filter.iqIm_2 = exp_regul_iq(koef_Im_filter, filter.iqIm_2, analog.iqIm_2); -// filter.iqIm = exp_regul_iq(koef_Iabc_filter, filter.iqIm, filter.iqIm_2); + filter.iqIm = exp_regul_iq(koef_Im_filter, filter.iqIm, analog.iqIm); - filter.iqW1 = exp_regul_iq(koef_Iabc_filter, filter.iqW1, analog.iqW1); - filter.iqW2 = exp_regul_iq(koef_Iabc_filter, filter.iqW2, analog.iqW2); - filter.iqW = exp_regul_iq(koef_Wlong, filter.iqW, filter.iqW1 + filter.iqW2); + filter.iqIin_sum = exp_regul_iq(koef_Im_filter, filter.iqIin_sum, analog.iqIin_sum); -// filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1); -// filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2); +//3 +// filter_batter2_Iin.InpVarCurr = (analog.iqIin_1)-ZERO_I_IN; + // filter_batter2_Iin.calc(&filter_batter2_Iin); + +// filter.iqIin = _IQmpy(filter_batter2_Iin.Out,_IQ_09); + + + filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1); + filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2); + + a1 = analog.iqU_1+analog.iqU_2; + a2 = analog.iqIin_1; + a3 = _IQmpy(a1,a2); + analog.PowerScalar = a3; +// filter.Power = analog.iqU_1+analog.iqU_2; + filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar); + filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar); } -#define CONST_IQ_11PI6 96629827 //11Pi/6 -#define CONST_IQ_PI6 8784529 // Pi/6 -// _iq err_level_adc_on_go = ERR_LEVEL_ADC_PLUS_6_ON_GO_IQ; - -// _iq err_level_adc = ERR_LEVEL_ADC_PLUS_6_IQ; - - -// unsigned int detect_protect_ACP_plus() -// { -// unsigned int mask = 0, result = 0; -// static unsigned int prev_mask = 0xFCFC; - -// if(f.Go) -// { -// mask |= filter.iqU_1_long > err_level_adc_on_go ? 1 : 0; -// mask |= filter.iqU_2_long > err_level_adc_on_go ? 1 << 1: 0; -// } -// else -// { -// mask |= filter.iqU_1_long > err_level_adc ? 1 : 0; -// mask |= filter.iqU_2_long > err_level_adc ? 1 << 1: 0; -// } - - -// #ifdef NEW_I_ZPT_REZISTORS -// mask |= ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 2: 0; -// mask |= ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 3: 0; -// #else -// mask |= ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS? 1 << 2: 0; -// mask |= ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS? 1 << 3: 0; -// #endif - -// mask |= ADC_sf[0][4] < ERR_LEVEL_I_FAZA_PLUS? 1 << 4: 0; -// mask |= ADC_sf[0][5] < ERR_LEVEL_I_FAZA_PLUS? 1 << 5: 0; -// mask |= ADC_sf[0][6] < ERR_LEVEL_I_FAZA_PLUS? 1 << 6: 0; - -// if(f.Go) -// { -// mask |= filter.iqU_3_long > err_level_adc_on_go ? 1 << 8: 0; -// mask |= filter.iqU_4_long > err_level_adc_on_go ? 1 << 9: 0; -// } -// else -// { -// mask |= (filter.iqU_3_long > err_level_adc) ? 1 << 8: 0; -// mask |= (filter.iqU_4_long > err_level_adc) ? 1 << 9: 0; -// } - - -// #ifdef NEW_I_ZPT_REZISTORS -// mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 10: 0; -// mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 11: 0; -// #else -// mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS? 1 << 10: 0; -// mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS? 1 << 11: 0; -// #endif - -// mask |= ADC_sf[0][12] < ERR_LEVEL_I_FAZA_PLUS? 1 << 12: 0; -// mask |= ADC_sf[0][13] < ERR_LEVEL_I_FAZA_PLUS? 1 << 13: 0; -// mask |= ADC_sf[0][14] < ERR_LEVEL_I_FAZA_PLUS? 1 << 14: 0; - -// //Calculate values for BTR -// #ifdef BTR_ENABLED -// mask |= ADC_sf[1][0] < ERR_LEVEL_BREAK_REZ? 1 << 7: 0; //BTR1pos -// mask |= ADC_sf[1][2] < ERR_LEVEL_BREAK_REZ? 1 << 15: 0; //BTR1neg -// #endif //BTR_ENABLED -// /* */ - -// result = mask & prev_mask; -// prev_mask |= mask; // -// // -// if(mask == 0) { prev_mask = 0xFFFF;} -// return result; - -// } - - -// unsigned int detect_protect_ACP_minus() -// { -// unsigned int mask = 0, result = 0; -// static unsigned int prev_mask = 0xFCFC; // - -// /* */ -// if(f.Ready2) -// { -// // mask |= (ADC_sf[0] > ERR_LEVEL_ADC_MINUS_6) ? 1: 0; -// // mask |= (ADC_sf[1] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 1: 0; -// } -// #ifdef NEW_I_ZPT_REZISTORS -// mask |= (ADC_sf[0][2] > ERR_LEVEL_I_ZPT_MINUS_REZ_249)? 1 << 2: 0; -// mask |= (ADC_sf[0][3] > ERR_LEVEL_I_ZPT_MINUS_REZ_249)? 1 << 3: 0; -// #else -// mask |= (ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS)? 1 << 2: 0; -// mask |= (ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS)? 1 << 3: 0; -// #endif -// mask |= ADC_sf[0][4] > ERR_LEVEL_I_FAZA_MINUS? 1 << 4: 0; -// mask |= ADC_sf[0][5] > ERR_LEVEL_I_FAZA_MINUS? 1 << 5: 0; -// mask |= ADC_sf[0][6] > ERR_LEVEL_I_FAZA_MINUS? 1 << 6: 0; -// /* */ -// /* if(f.Ready2) -// { -// mask |= (ADC_sf[0][7] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 8: 0; -// mask |= (ADC_sf[0][8] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 9: 0; -// } */ -// #ifdef NEW_I_ZPT_REZISTORS -// mask |= ADC_sf[0][10] > ERR_LEVEL_I_ZPT_MINUS_REZ_249? 1 << 10: 0; -// mask |= ADC_sf[0][11] > ERR_LEVEL_I_ZPT_MINUS_REZ_249? 1 << 11: 0; -// #else -// mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS? 1 << 10: 0; -// mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS? 1 << 11: 0; -// #endif - -// mask |= ADC_sf[0][12] > ERR_LEVEL_I_FAZA_MINUS? 1 << 12: 0; -// mask |= ADC_sf[0][13] > ERR_LEVEL_I_FAZA_MINUS? 1 << 13: 0; -// mask |= ADC_sf[0][14] > ERR_LEVEL_I_FAZA_MINUS? 1 << 14: 0; - -// //Calculate values for BTR -// #ifdef BTR_ENABLED -// mask |= ADC_sf[1][1] < ERR_LEVEL_BREAK_REZ? 1 << 7: 0; //BTR2pos -// mask |= ADC_sf[1][3] < ERR_LEVEL_BREAK_REZ? 1 << 15: 0; //BTR2neg -// #endif //BTR_ENABLED -// /* */ - - -// result = mask & prev_mask; -// prev_mask |= mask; // -// // -// if(mask == 0) { prev_mask = 0xFFFF;} -// return result; - -// } - -// #pragma CODE_SECTION(fillADClogs,".fast_run"); -// void fillADClogs(void) -// { -// logpar.log1 = (int16)_IQtoIQ15(analog.iqU_1); -// logpar.log2 = (int16)_IQtoIQ15(analog.iqU_2); -// logpar.log3 = (int16)_IQtoIQ15(analog.iqIin_1); -// logpar.log4 = (int16)_IQtoIQ15(analog.iqIin_2); -// logpar.log5 = (int16)_IQtoIQ15(analog.iqIa1_1); -// logpar.log6 = (int16)_IQtoIQ15(analog.iqIb1_1); -// logpar.log7 = (int16)_IQtoIQ15(analog.iqIc1_1); -// logpar.log8 = (int16)_IQtoIQ15(analog.iqU_3); -// logpar.log9 = (int16)_IQtoIQ15(analog.iqU_4); -// logpar.log10 = (int16)_IQtoIQ15(analog.iqIin_3); -// logpar.log11 = (int16)_IQtoIQ15(analog.iqIin_4); -// logpar.log12 = (int16)_IQtoIQ15(analog.iqIa2_1); -// logpar.log13 = (int16)_IQtoIQ15(analog.iqIb2_1); -// logpar.log14 = (int16)_IQtoIQ15(analog.iqIc2_1); -// // logpar.log15 = (int16)_IQtoIQ15(filter.iqU_1_fast); -// // logpar.log16 = (int16)_IQtoIQ15(filter.iqU_1_long); -// } - +#pragma DATA_SECTION(acp_zero,".slow_vars") +_iq19 acp_zero[16]; +#pragma DATA_SECTION(acp_summ,".slow_vars") +long acp_summ[16]; /********************************************************************/ -/* Расчет РјРѕРґСѓР»y тока РёР· показаний трех фаз */ -/********************************************************************/ -_iq SQRT_32 = _IQ(0.8660254037844); -_iq CONST_23 = _IQ(2.0/3.0); -_iq CONST_15 = _IQ(1.5); +/* Определение нулy показаний АЦП */ +/********************************************************************/ +void detect_zero_analog(int nc) +{ + long i,k; + -_iq im_calc( _iq ia, _iq ib, _iq ic) -{ - _iq isa,isb, t; - + _iq koef_zero_ADC_filter = _IQ19(0.00002/0.0003185); + - isa = _IQmpy(CONST_15,ia); - isb = _IQmpy(SQRT_32,ib-ic ); - -// ( _IQ19mpy(SQRT_32, _IQ15toIQ19(ib)) - _IQ15mpy(SQRT_32, _IQ15toIQ19(ic)) ); + for (k=0;k<16;k++) + { + acp_zero[k] = 0; + acp_summ[k] = 0; + } + + + + for (i=0; i=1) +#define R_ADC_DEFAULT_0 { 271, 271, 876, 876, 876, 876, 876, 876, 249, 249, 301, 301, 301, 301, 301, 301 } +#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 } +#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } +#endif + +#if(C_adc_number>=2) +#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 } +#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 } +#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_P, NORMA_ACP } +#endif + +#if(C_adc_number>=3) +#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 } +#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 } +#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } +#endif + +// 23550.1 + +//#if(C_adc_number>=1) +//#define R_ADC_DEFAULT_0 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 312, 312, 312, 312, 309, 309 } +//#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 } +//#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } +//#endif +// +//#if(C_adc_number>=2) +//#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 } +//#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 } +//#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_P, NORMA_ACP } +//#endif +// +//#if(C_adc_number>=3) +//#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 } +//#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 } +//#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } +//#endif + + + + +#if (USE_INTERNAL_ADC==1) +#define R_ADC_DEFAULT_INTERNAL { 100,100,100,100,100,100,100,100,1248,1248,1248,100,100,100,100,100 } +#define K_LEM_ADC_DEFAULT_INTERNAL { 30,30,30,30,10,10,10,10,621,621,621,100,10,10,10,10 } +#define NORMA_ADC_DEFAULT_INTERNAL { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP } +#endif + + + + + +/* + //awa3 + //14 канал out1 + 0 - 11 кривые датчики + //15 канал out2 + 0 - 11 кривые датчики + //8 канал + 0 - 20 мА | 0 град - 200 град / линейный + 0V - 1.5V / 0 град - 200 град / линейный + //9 канал + 0 - 20 мА | 0 град - 200 град / линейный + 0V - 1.5V / 0 град - 200 град / линейный + + //10 канал + 0 - 20 мА | 0 град - 200 град / линейный + 0V - 1.5V / 0 град - 200 град / линейный + + //11 канал + 0 - 20 мА | 0 град - 200 град / линейный + 0V - 1.5V / 0 град - 200 град / линейный + //12 канал + 4 - 20 мА | 0 бар - 10 бар / линейный + 0.3V - 1.5V / 0 бар - 10 бар / линейный + + //13 канал + 4 - 20 мА | 0 бар - 10 бар / линейный + 0.3V - 1.5V / 0 бар - 10 бар / линейный +*/ + + +typedef union +{ + + struct + { + unsigned int c0_plus :1; /* 0 датчик+ */ + unsigned int c1_plus :1; /* 0 датчик+ */ + unsigned int c2_plus :1; /* 0 датчик+ */ + unsigned int c3_plus :1; /* 0 датчик+ */ + unsigned int c4_plus :1; /* 0 датчик+ */ + unsigned int c5_plus :1; /* 0 датчик+ */ + unsigned int c6_plus :1; /* 0 датчик+ */ + unsigned int c7_plus :1; /* 0 датчик+ */ + unsigned int c8_plus :1; /* 0 датчик+ */ + unsigned int c9_plus :1; /* 0 датчик+ */ + unsigned int c10_plus :1; /* 0 датчик+ */ + unsigned int c11_plus :1; /* 0 датчик+ */ + unsigned int c12_plus :1; /* 0 датчик+ */ + unsigned int c13_plus :1; /* 0 датчик+ */ + unsigned int c14_plus :1; /* 0 датчик+ */ + unsigned int c15_plus :1; /* 0 датчик+ */ + } bit; /* Ошибки побитно */ + unsigned long all; /* Ошибки вместе */ + +} ERR_ADC_PLUS_PROTECT; + + +typedef union +{ + + struct + { + unsigned int c0_minus :1; /* 0 датчик- */ + unsigned int c1_minus :1; /* 0 датчик- */ + unsigned int c2_minus :1; /* 0 датчик- */ + unsigned int c3_minus :1; /* 0 датчик- */ + unsigned int c4_minus :1; /* 0 датчик- */ + unsigned int c5_minus :1; /* 0 датчик- */ + unsigned int c6_minus :1; /* 0 датчик- */ + unsigned int c7_minus :1; /* 0 датчик- */ + unsigned int c8_minus :1; /* 0 датчик- */ + unsigned int c9_minus :1; /* 0 датчик- */ + unsigned int c10_minus :1; /* 0 датчик- */ + unsigned int c11_minus :1; /* 0 датчик- */ + unsigned int c12_minus :1; /* 0 датчик- */ + unsigned int c13_minus :1; /* 0 датчик- */ + unsigned int c14_minus :1; /* 0 датчик- */ + unsigned int c15_minus :1; /* 0 датчик- */ + + } bit; /* Ошибки побитно */ + unsigned int all; /* Ошибки вместе */ + +} ERR_ADC_MINUS_PROTECT; + typedef struct { + ERR_ADC_PLUS_PROTECT plus; + ERR_ADC_MINUS_PROTECT minus; +} ERR_ADC_PROTECT; - _iq iqIin_1; - _iq iqIin_2; - _iq iqIin_3; - _iq iqIin_4; -// _iq iqIin_1_rms; -// _iq iqIin_2_rms; -// _iq iqIin_3_rms; -// _iq iqIin_4_rms; - _iq iqIin; - - _iq iqIa1_1; - _iq iqIb1_1; - _iq iqIc1_1; - _iq iqIa2_1; - _iq iqIb2_1; - _iq iqIc2_1; - - _iq iqIa1_rms; - _iq iqIb1_rms; - _iq iqIc1_rms; - _iq iqIa2_rms; - _iq iqIb2_rms; - _iq iqIc2_rms; - - _iq iqIq_zadan; - _iq iqIq_zad_from_optica; - _iq iqId1; - _iq iqIq1; - _iq iqIq1_filter; - _iq iqId2; - _iq iqIq2; - _iq iqIq2_filter; - - _iq iqUd1; - _iq iqUq1; - _iq iqUd2; - _iq iqUq2; - _iq iqUq2_filter; - _iq tetta; - _iq Fsl; - - _iq iqFstator; +/* Глобальнаy структура значений токов и напрyжений АИН */ +typedef struct +{ _iq iqU_1; _iq iqU_2; - _iq iqU_3; - _iq iqU_4; - _iq iqW1; - _iq iqWexp; - _iq iqWfir; - _iq iqWout; - _iq iqPvsi1; - _iq iqPvsi2; - _iq iqM_1; - _iq iqM_2; + _iq iqU_1_fast; + _iq iqU_2_fast; - _iq iqW2; - - _iq iqW; - _iq iqU_1_long; _iq iqU_2_long; - _iq iqU_3_long; - _iq iqU_4_long; - _iq iqU_1_fast; - _iq iqU_2_fast; - _iq iqU_3_fast; - _iq iqU_4_fast; + _iq iqIu_1; + _iq iqIv_1; + _iq iqIw_1; - _iq iqIm_1; + _iq iqIu_2; + _iq iqIv_2; + _iq iqIw_2; + + _iq iqIu_1_rms; + _iq iqIv_1_rms; + _iq iqIw_1_rms; + + _iq iqIu_2_rms; + _iq iqIv_2_rms; + _iq iqIw_2_rms; + + _iq iqIu; + _iq iqIv; + _iq iqIw; + + _iq iqIin_1; + _iq iqIin_2; + + _iq iqUin_A1B1; + _iq iqUin_B1C1; + _iq iqUin_C1A1; + + _iq iqUin_A2B2; + _iq iqUin_B2C2; + _iq iqUin_C2A2; + + _iq iqUin_A1B1_rms; + _iq iqUin_B1C1_rms; + _iq iqUin_C1A1_rms; + + _iq iqUin_A2B2_rms; + _iq iqUin_B2C2_rms; + _iq iqUin_C2A2_rms; + + _iq iqUin_m1; + _iq iqUin_m2; + + _iq iqIbreak_1; + _iq iqIbreak_2; //39 + + _iq T_U01; + _iq T_U02; + _iq T_U03; + _iq T_U04; + _iq T_U05; + _iq T_U06; + _iq T_U07; + + _iq T_Water_external; + _iq T_Water_internal; + + _iq T_Air_01; + _iq T_Air_02; + _iq T_Air_03; + _iq T_Air_04; + + _iq P_Water_internal; //53 + + + _iq iqI_vozbud; + + _iq iqIin_sum; + + _iq iqIm_1; _iq iqIm_2; - _iq iqIm_1_long; - _iq iqIm_2_long; _iq iqIm; - _iq iqIbtr1_1; - _iq iqIbtr1_2; - _iq iqIbtr2_1; - _iq iqIbtr2_2; + + _iq iqM; + + _iq PowerScalar; + _iq PowerScalarFilter2; + _iq PowerFOC; + _iq iqU_1_imit; //63 + + + /* + _iq iqUzpt_1_2; //uzpt1 bs2 + _iq iqUzpt_2_2; //uzpt2 bs2 + _iq iqUzpt_1_2_fast; //uzpt1 bs2 + _iq iqUzpt_2_2_fast; //uzpt2 bs2 + _iq iqUzpt_1_2_long; //uzpt1 bs2 + _iq iqUzpt_2_2_long; //uzpt2 bs2 + _iq iqIin_1_1; //Iin AF1 BS1 + _iq iqIin_2_1; //Iin AF2 BS1 + _iq iqIin_3_1; //Iin AF3 BS1 + _iq iqIin_4_1; //Iin AF4 BS1 + _iq iqIin_5_1; //Iin AF5 BS1 + _iq iqIin_6_1; //Iin AF6 BS1 + _iq iqIin_1_2; //Iin AF1 BS2 + _iq iqIin_2_2; //Iin AF2 BS2 + _iq iqIin_3_2; //Iin AF3 BS2 + _iq iqIin_4_2; //Iin AF4 BS2 + _iq iqIin_5_2; //Iin AF5 BS2 + _iq iqIin_6_2; //Iin AF6 BS2 + _iq iqUin_AB; //Входное линейное напрЯжение AB + _iq iqUin_BC; //Входное линейное напрЯжение BC + _iq iqUin_CA; //Входное линейное напрЯжение CA + _iq iqUin_AB_sf; //Входное линейное напрЯжение AB + _iq iqUin_BC_sf; //Входное линейное напрЯжение BC + _iq iqUin_CA_sf; //Входное линейное напрЯжение CA + _iq iqT_WATER_in; // Температура воды на входе ПЧ + _iq iqT_WATER_out; // Температура воды на выходе ПЧ + _iq iqT_AIR_in_up; // Температура воздуха на входе ПЧ (верх) + _iq iqT_AIR_in_down;// Температура воздуха на входе ПЧ (низ) + _iq iqP_WATER_in; // Давление воды на входе ПЧ + _iq iqP_WATER_out; // Давление воды на выходе ПЧ + + _iq iqT_BK1_BK12; // Текущее показание одного из датчиков BK1_BK12 + _iq iqT_BK13_BK24; // Текущее показание одного из датчиков BK13_BK24 + + _iq iqUin_m1; //Амплитуда Входное линейное напрЯжение + + + _iq iqIu_1_1; //Iu AF1 BS1 + _iq iqIu_1_2; //Iu AF2 BS1 + _iq iqIv_1_1; //Iv AF3 BS1 + _iq iqIv_1_2; //Iv AF4 BS1 + _iq iqIw_1_1; //Iw AF5 BS1 + _iq iqIw_1_2; //Iw AF6 BS1 + + + + _iq iqIu_2_1; //Iu AF1 BS2 + _iq iqIu_2_2; //Iu AF2 BS2 + _iq iqIv_2_1; //Iv AF3 BS2 + _iq iqIv_2_2; //Iv AF4 BS2 + _iq iqIw_2_1; //Iw AF5 BS2 + _iq iqIw_2_2; //Iw AF6 BS2 + + _iq iqIm_1; + _iq iqIm_2; + + _iq iqWexp; + _iq iqWout; + + _iq iqM; +*/ } ANALOG_VALUE; -typedef struct { - float U1_1; - float U1_2; - float Izpt1_1; - float Izpt1_2; - float Ia1; - float Ib1; - float Ic1; - float U2_1; - float U2_2; - float Izpt2_1; - float Izpt2_2; - float Ia2; - float Ib2; - float Ic2; - void (*read_adc)(); -} ANALOG_RAW_DATA; +#define ANALOG_VALUE_DEFAULT {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0, 0} +/* Глобальнаy структура значений токов и напрyжений АИН */ +#define ERR_LEVEL_ADC_PLUS 3950 //+1270A //2950 // +650A //3467 // 3367 //3367 //3267 // 0xfff-0x29c +#define ERR_LEVEL_ADC_MINUS 150 //-1270A //1150 //-650A // 267 //367 + +#define ERR_LEVEL_ADC_PLUS_6 3800 //3783 //3623~1150 // 3462 ~ 1050 A // 3320 ~ 960A //3680 //3267 // 0xfff-0x29c +#define ERR_LEVEL_ADC_MINUS_6 1000 //267 //367 + +#define MIN_DETECT_UD_ZERO 2300 + + +#define level_err_ADC_PLUS_default {ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ + ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ + ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\ + ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS} + +#define level_err_ADC_MINUS_default {ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ + ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ + ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\ + ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS} + extern ANALOG_VALUE analog; extern ANALOG_VALUE filter; -extern _iq iq_norm_ADC[18]; -extern ANALOG_RAW_DATA rawData; +extern ANALOG_VALUE analog_zero; + +//void calc_norm_ADC(int fast); +void calc_norm_ADC_0(int run_norma); +void calc_norm_ADC_1(int run_norma); +void Init_Adc_Variables(void); +void norma_adc_nc(int nc); + + -#define COUNT_ARR_ADC_BUF 2 extern int ADC_f[COUNT_ARR_ADC_BUF][16]; +extern int zero_ADC[COUNT_ARR_ADC_BUF][16]; -void log_acp(void); -void acp_Handler(void); -void init_Adc_Variables(void); -void calc_Izpt_rms(void); -unsigned int detect_protect_ACP_plus(void); -unsigned int detect_protect_ACP_minus(void); -void fillADClogs(void); -void read_adc(ANALOG_RAW_DATA *data); +extern ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF],mask_err_adc_protect[COUNT_ARR_ADC_BUF]; -#define ANALOG_RAW_DATA_DEFAULT {0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ - read_adc} +extern unsigned int R_ADC[COUNT_ARR_ADC_BUF][16]; +extern unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16]; +extern float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16]; -#endif // ADC_TOOLS_H +//void norma_all_adc(void); +extern _iq koef_Uzpt_long_filter, koef_Uzpt_fast_filter, koef_Uin_filter, koef_Im_filter, koef_Power_filter, koef_Power_filter2; +void detect_zero_analog(int nc); + + +#if (USE_INTERNAL_ADC==1) + +void Init_Internal_Adc(void); + +#endif + + +#endif // end _ADC_TOOLS diff --git a/Inu/Src/main/alarm_log.c b/Inu/Src2/main/alarm_log.c similarity index 100% rename from Inu/Src/main/alarm_log.c rename to Inu/Src2/main/alarm_log.c diff --git a/Inu/Src/main/alarm_log.h b/Inu/Src2/main/alarm_log.h similarity index 100% rename from Inu/Src/main/alarm_log.h rename to Inu/Src2/main/alarm_log.h diff --git a/Inu/Src2/551/main/alg_simple_scalar.c b/Inu/Src2/main/alg_simple_scalar.c similarity index 100% rename from Inu/Src2/551/main/alg_simple_scalar.c rename to Inu/Src2/main/alg_simple_scalar.c diff --git a/Inu/Src2/551/main/alg_simple_scalar.h b/Inu/Src2/main/alg_simple_scalar.h similarity index 100% rename from Inu/Src2/551/main/alg_simple_scalar.h rename to Inu/Src2/main/alg_simple_scalar.h diff --git a/Inu/Src2/551/main/alg_uf_const.c b/Inu/Src2/main/alg_uf_const.c similarity index 100% rename from Inu/Src2/551/main/alg_uf_const.c rename to Inu/Src2/main/alg_uf_const.c diff --git a/Inu/Src2/551/main/alg_uf_const.h b/Inu/Src2/main/alg_uf_const.h similarity index 100% rename from Inu/Src2/551/main/alg_uf_const.h rename to Inu/Src2/main/alg_uf_const.h diff --git a/Inu/Src/main/another_bs.c b/Inu/Src2/main/another_bs.c similarity index 100% rename from Inu/Src/main/another_bs.c rename to Inu/Src2/main/another_bs.c diff --git a/Inu/Src/main/another_bs.h b/Inu/Src2/main/another_bs.h similarity index 100% rename from Inu/Src/main/another_bs.h rename to Inu/Src2/main/another_bs.h diff --git a/Inu/Src2/551/main/break_regul.c b/Inu/Src2/main/break_regul.c similarity index 100% rename from Inu/Src2/551/main/break_regul.c rename to Inu/Src2/main/break_regul.c diff --git a/Inu/Src2/551/main/break_regul.h b/Inu/Src2/main/break_regul.h similarity index 100% rename from Inu/Src2/551/main/break_regul.h rename to Inu/Src2/main/break_regul.h diff --git a/Inu/Src2/551/main/calc_rms_vals.c b/Inu/Src2/main/calc_rms_vals.c similarity index 100% rename from Inu/Src2/551/main/calc_rms_vals.c rename to Inu/Src2/main/calc_rms_vals.c diff --git a/Inu/Src2/551/main/calc_rms_vals.h b/Inu/Src2/main/calc_rms_vals.h similarity index 100% rename from Inu/Src2/551/main/calc_rms_vals.h rename to Inu/Src2/main/calc_rms_vals.h diff --git a/Inu/Src2/551/main/calc_tempers.c b/Inu/Src2/main/calc_tempers.c similarity index 100% rename from Inu/Src2/551/main/calc_tempers.c rename to Inu/Src2/main/calc_tempers.c diff --git a/Inu/Src2/551/main/calc_tempers.h b/Inu/Src2/main/calc_tempers.h similarity index 100% rename from Inu/Src2/551/main/calc_tempers.h rename to Inu/Src2/main/calc_tempers.h diff --git a/Inu/Src2/551/main/can_bs2bs.c b/Inu/Src2/main/can_bs2bs.c similarity index 100% rename from Inu/Src2/551/main/can_bs2bs.c rename to Inu/Src2/main/can_bs2bs.c diff --git a/Inu/Src2/551/main/can_bs2bs.h b/Inu/Src2/main/can_bs2bs.h similarity index 100% rename from Inu/Src2/551/main/can_bs2bs.h rename to Inu/Src2/main/can_bs2bs.h diff --git a/Inu/Src/main/can_protocol_ukss.h b/Inu/Src2/main/can_protocol_ukss.h similarity index 100% rename from Inu/Src/main/can_protocol_ukss.h rename to Inu/Src2/main/can_protocol_ukss.h diff --git a/Inu/Src2/551/main/control_station_project.c b/Inu/Src2/main/control_station_project.c similarity index 100% rename from Inu/Src2/551/main/control_station_project.c rename to Inu/Src2/main/control_station_project.c diff --git a/Inu/Src2/551/main/control_station_project.h b/Inu/Src2/main/control_station_project.h similarity index 100% rename from Inu/Src2/551/main/control_station_project.h rename to Inu/Src2/main/control_station_project.h diff --git a/Inu/Src2/551/main/detect_error_3_phase.c b/Inu/Src2/main/detect_error_3_phase.c similarity index 100% rename from Inu/Src2/551/main/detect_error_3_phase.c rename to Inu/Src2/main/detect_error_3_phase.c diff --git a/Inu/Src2/551/main/detect_error_3_phase.h b/Inu/Src2/main/detect_error_3_phase.h similarity index 100% rename from Inu/Src2/551/main/detect_error_3_phase.h rename to Inu/Src2/main/detect_error_3_phase.h diff --git a/Inu/Src2/551/main/detect_errors.c b/Inu/Src2/main/detect_errors.c similarity index 100% rename from Inu/Src2/551/main/detect_errors.c rename to Inu/Src2/main/detect_errors.c diff --git a/Inu/Src2/551/main/detect_errors.h b/Inu/Src2/main/detect_errors.h similarity index 100% rename from Inu/Src2/551/main/detect_errors.h rename to Inu/Src2/main/detect_errors.h diff --git a/Inu/Src2/551/main/detect_errors_adc.c b/Inu/Src2/main/detect_errors_adc.c similarity index 100% rename from Inu/Src2/551/main/detect_errors_adc.c rename to Inu/Src2/main/detect_errors_adc.c diff --git a/Inu/Src2/551/main/detect_errors_adc.h b/Inu/Src2/main/detect_errors_adc.h similarity index 100% rename from Inu/Src2/551/main/detect_errors_adc.h rename to Inu/Src2/main/detect_errors_adc.h diff --git a/Inu/Src2/551/main/detect_overload.c b/Inu/Src2/main/detect_overload.c similarity index 100% rename from Inu/Src2/551/main/detect_overload.c rename to Inu/Src2/main/detect_overload.c diff --git a/Inu/Src2/551/main/detect_overload.h b/Inu/Src2/main/detect_overload.h similarity index 100% rename from Inu/Src2/551/main/detect_overload.h rename to Inu/Src2/main/detect_overload.h diff --git a/Inu/Src2/551/main/detect_phase_break.c b/Inu/Src2/main/detect_phase_break.c similarity index 100% rename from Inu/Src2/551/main/detect_phase_break.c rename to Inu/Src2/main/detect_phase_break.c diff --git a/Inu/Src2/551/main/detect_phase_break.h b/Inu/Src2/main/detect_phase_break.h similarity index 100% rename from Inu/Src2/551/main/detect_phase_break.h rename to Inu/Src2/main/detect_phase_break.h diff --git a/Inu/Src2/551/main/detect_phase_break2.c b/Inu/Src2/main/detect_phase_break2.c similarity index 100% rename from Inu/Src2/551/main/detect_phase_break2.c rename to Inu/Src2/main/detect_phase_break2.c diff --git a/Inu/Src2/551/main/detect_phase_break2.h b/Inu/Src2/main/detect_phase_break2.h similarity index 100% rename from Inu/Src2/551/main/detect_phase_break2.h rename to Inu/Src2/main/detect_phase_break2.h diff --git a/Inu/Src/main/digital_filters.c b/Inu/Src2/main/digital_filters.c similarity index 100% rename from Inu/Src/main/digital_filters.c rename to Inu/Src2/main/digital_filters.c diff --git a/Inu/Src/main/digital_filters.h b/Inu/Src2/main/digital_filters.h similarity index 100% rename from Inu/Src/main/digital_filters.h rename to Inu/Src2/main/digital_filters.h diff --git a/Inu/Src2/main/dmctype.h b/Inu/Src2/main/dmctype.h deleted file mode 100644 index 95f314f..0000000 --- a/Inu/Src2/main/dmctype.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ================================================================================= -File name: DMCTYPE.H - -Originator: Digital Control Systems Group - Texas Instruments - -Description: DMC data type definition file. -===================================================================================== - History: -------------------------------------------------------------------------------------- - 04-15-2005 Version 3.20 -------------------------------------------------------------------------------*/ - -#ifndef DMCTYPE -#define DMCTYPE - -//--------------------------------------------------------------------------- -// For Portability, User Is Recommended To Use Following Data Type Size -// Definitions For 16-bit and 32-Bit Signed/Unsigned Integers: -// - -typedef int int16; -typedef long int32; -typedef unsigned int Uint16; -typedef unsigned long Uint32; -typedef float float32; -typedef long double float64; - - -#endif // DMCTYPE - diff --git a/Inu/Src2/551/main/edrk_main.c b/Inu/Src2/main/edrk_main.c similarity index 100% rename from Inu/Src2/551/main/edrk_main.c rename to Inu/Src2/main/edrk_main.c diff --git a/Inu/Src2/551/main/edrk_main.h b/Inu/Src2/main/edrk_main.h similarity index 100% rename from Inu/Src2/551/main/edrk_main.h rename to Inu/Src2/main/edrk_main.h diff --git a/Inu/Src2/551/main/f281xbmsk.h b/Inu/Src2/main/f281xbmsk.h similarity index 100% rename from Inu/Src2/551/main/f281xbmsk.h rename to Inu/Src2/main/f281xbmsk.h diff --git a/Inu/Src2/551/main/f281xpwm.c b/Inu/Src2/main/f281xpwm.c similarity index 100% rename from Inu/Src2/551/main/f281xpwm.c rename to Inu/Src2/main/f281xpwm.c diff --git a/Inu/Src2/551/main/f281xpwm.h b/Inu/Src2/main/f281xpwm.h similarity index 100% rename from Inu/Src2/551/main/f281xpwm.h rename to Inu/Src2/main/f281xpwm.h diff --git a/Inu/Src/main/limit_lib.c b/Inu/Src2/main/limit_lib.c similarity index 100% rename from Inu/Src/main/limit_lib.c rename to Inu/Src2/main/limit_lib.c diff --git a/Inu/Src/main/limit_lib.h b/Inu/Src2/main/limit_lib.h similarity index 100% rename from Inu/Src/main/limit_lib.h rename to Inu/Src2/main/limit_lib.h diff --git a/Inu/Src/main/limit_power.c b/Inu/Src2/main/limit_power.c similarity index 100% rename from Inu/Src/main/limit_power.c rename to Inu/Src2/main/limit_power.c diff --git a/Inu/Src/main/limit_power.h b/Inu/Src2/main/limit_power.h similarity index 100% rename from Inu/Src/main/limit_power.h rename to Inu/Src2/main/limit_power.h diff --git a/Inu/Src/main/logs_hmi.c b/Inu/Src2/main/logs_hmi.c similarity index 100% rename from Inu/Src/main/logs_hmi.c rename to Inu/Src2/main/logs_hmi.c diff --git a/Inu/Src/main/logs_hmi.h b/Inu/Src2/main/logs_hmi.h similarity index 100% rename from Inu/Src/main/logs_hmi.h rename to Inu/Src2/main/logs_hmi.h diff --git a/Inu/Src2/551/main/manch.h b/Inu/Src2/main/manch.h similarity index 100% rename from Inu/Src2/551/main/manch.h rename to Inu/Src2/main/manch.h diff --git a/Inu/Src/main/master_slave.c b/Inu/Src2/main/master_slave.c similarity index 100% rename from Inu/Src/main/master_slave.c rename to Inu/Src2/main/master_slave.c diff --git a/Inu/Src2/551/main/master_slave.h b/Inu/Src2/main/master_slave.h similarity index 100% rename from Inu/Src2/551/main/master_slave.h rename to Inu/Src2/main/master_slave.h diff --git a/Inu/Src2/551/main/message2.c b/Inu/Src2/main/message2.c similarity index 100% rename from Inu/Src2/551/main/message2.c rename to Inu/Src2/main/message2.c diff --git a/Inu/Src2/551/main/message2.h b/Inu/Src2/main/message2.h similarity index 100% rename from Inu/Src2/551/main/message2.h rename to Inu/Src2/main/message2.h diff --git a/Inu/Src2/551/main/message2can.c b/Inu/Src2/main/message2can.c similarity index 100% rename from Inu/Src2/551/main/message2can.c rename to Inu/Src2/main/message2can.c diff --git a/Inu/Src2/551/main/message2can.h b/Inu/Src2/main/message2can.h similarity index 100% rename from Inu/Src2/551/main/message2can.h rename to Inu/Src2/main/message2can.h diff --git a/Inu/Src2/551/main/message2test.c b/Inu/Src2/main/message2test.c similarity index 100% rename from Inu/Src2/551/main/message2test.c rename to Inu/Src2/main/message2test.c diff --git a/Inu/Src2/551/main/message2test.h b/Inu/Src2/main/message2test.h similarity index 100% rename from Inu/Src2/551/main/message2test.h rename to Inu/Src2/main/message2test.h diff --git a/Inu/Src2/551/main/message_modbus.c b/Inu/Src2/main/message_modbus.c similarity index 100% rename from Inu/Src2/551/main/message_modbus.c rename to Inu/Src2/main/message_modbus.c diff --git a/Inu/Src2/551/main/message_modbus.h b/Inu/Src2/main/message_modbus.h similarity index 100% rename from Inu/Src2/551/main/message_modbus.h rename to Inu/Src2/main/message_modbus.h diff --git a/Inu/Src2/551/main/message_terminals_can.c b/Inu/Src2/main/message_terminals_can.c similarity index 100% rename from Inu/Src2/551/main/message_terminals_can.c rename to Inu/Src2/main/message_terminals_can.c diff --git a/Inu/Src2/551/main/message_terminals_can.h b/Inu/Src2/main/message_terminals_can.h similarity index 100% rename from Inu/Src2/551/main/message_terminals_can.h rename to Inu/Src2/main/message_terminals_can.h diff --git a/Inu/Src2/551/main/modbus_hmi.c b/Inu/Src2/main/modbus_hmi.c similarity index 100% rename from Inu/Src2/551/main/modbus_hmi.c rename to Inu/Src2/main/modbus_hmi.c diff --git a/Inu/Src2/551/main/modbus_hmi.h b/Inu/Src2/main/modbus_hmi.h similarity index 100% rename from Inu/Src2/551/main/modbus_hmi.h rename to Inu/Src2/main/modbus_hmi.h diff --git a/Inu/Src2/551/main/modbus_hmi_read.c b/Inu/Src2/main/modbus_hmi_read.c similarity index 100% rename from Inu/Src2/551/main/modbus_hmi_read.c rename to Inu/Src2/main/modbus_hmi_read.c diff --git a/Inu/Src2/551/main/modbus_hmi_read.h b/Inu/Src2/main/modbus_hmi_read.h similarity index 100% rename from Inu/Src2/551/main/modbus_hmi_read.h rename to Inu/Src2/main/modbus_hmi_read.h diff --git a/Inu/Src2/551/main/modbus_hmi_update.c b/Inu/Src2/main/modbus_hmi_update.c similarity index 100% rename from Inu/Src2/551/main/modbus_hmi_update.c rename to Inu/Src2/main/modbus_hmi_update.c diff --git a/Inu/Src2/551/main/modbus_hmi_update.h b/Inu/Src2/main/modbus_hmi_update.h similarity index 100% rename from Inu/Src2/551/main/modbus_hmi_update.h rename to Inu/Src2/main/modbus_hmi_update.h diff --git a/Inu/Src2/551/main/modbus_svu_update.c b/Inu/Src2/main/modbus_svu_update.c similarity index 100% rename from Inu/Src2/551/main/modbus_svu_update.c rename to Inu/Src2/main/modbus_svu_update.c diff --git a/Inu/Src2/551/main/modbus_svu_update.h b/Inu/Src2/main/modbus_svu_update.h similarity index 100% rename from Inu/Src2/551/main/modbus_svu_update.h rename to Inu/Src2/main/modbus_svu_update.h diff --git a/Inu/Src2/main/my_filter.c b/Inu/Src2/main/my_filter.c deleted file mode 100644 index 3fc444f..0000000 --- a/Inu/Src2/main/my_filter.c +++ /dev/null @@ -1,122 +0,0 @@ -// #include "DSP281x_Device.h" // DSP281x Headerfile Include File -// #include "DSP281x_Examples.h" // DSP281x Examples Include File -#include "IQmathLib.h" -#include "my_filter.h" - - -// #pragma CODE_SECTION(exp_regul_iq19,".fast_run"); -_iq19 exp_regul_iq19(_iq19 k_exp_regul, _iq19 InpVarCurr, _iq19 InpVarInstant) -{ - _iq19 t1; - - t1 = (InpVarCurr + _IQ19mpy( (InpVarInstant-InpVarCurr), k_exp_regul)); - return t1; -} - - -// #pragma CODE_SECTION(exp_regul_iq,".fast_run"); -_iq exp_regul_iq(_iq k_exp_regul, _iq InpVarCurr, _iq InpVarInstant) -{ - _iq t1; - t1 = (InpVarCurr + _IQmpy( (InpVarInstant-InpVarCurr), k_exp_regul)); - return t1; -} - -// #pragma CODE_SECTION(exp_regul_iq,".fast_run"); -void exp_regul_iq_fast(_iq k_exp_regul, _iq *InpVarCurr, _iq InpVarInstant) -{ - _iq t1; - volatile _iq t2,t3,t4; - - - t2 = (InpVarInstant- *InpVarCurr); - t3 = _IQmpy( t2, k_exp_regul); - t4 = *InpVarCurr + t3; - t1 = t4; - *InpVarCurr = t1; -// t1 = (InpVarCurr + _IQmpy( (InpVarInstant-InpVarCurr), k_exp_regul)); -// return t1; -} - -_iq zad_intensiv_q(_iq StepP, _iq StepN, _iq InpVarCurr, _iq InpVarInstant) -{ - _iq deltaVar, VarOut; - - deltaVar = InpVarInstant-InpVarCurr; - - if ((deltaVar>StepP) || (deltaVar<-StepN)) - { - if (deltaVar>0) InpVarCurr += StepP; - else InpVarCurr -= StepN; - } - else - InpVarCurr=InpVarInstant; - - - VarOut = InpVarCurr; - return VarOut; - - -} - - - - - -/* - -_iq18 filter_1p(_iq18 predx,_iq18 predy, _iq18 inpx) -{ - _iq18 t1; - - t1 = _IQ18mpy(k1_filter_1p_fast,(predx+inpx))+_IQ18mpy(k2_filter_1p_fast,predy); - return t1; -} - - -*/ - -/* - -void init_filter_batter2() -{ - u_filter_batter2[0]=0; - u_filter_batter2[1]=0; - u_filter_batter2[2]=0; - - i_filter_batter2[0]=0; - i_filter_batter2[1]=0; - i_filter_batter2[2]=0; - - k_filter_batter2[0]=_IQ(K1_FILTER_BATTER2_3HZ); - k_filter_batter2[1]=_IQ(K2_FILTER_BATTER2_3HZ); - k_filter_batter2[2]=_IQ(K3_FILTER_BATTER2_3HZ ); - -} - - - - -//#pragma CODE_SECTION(filter_batter2,".fast_run"); -_iq filter_batter2(_iq InpVarCurr) -{ -_iq y; - - y = _IQmpy(k_filter_batter2[0],( InpVarCurr + _IQmpyI32(i_filter_batter2[0],2) + i_filter_batter2[1] ) ) + - _IQmpy(k_filter_batter2[1], u_filter_batter2[0]) + _IQmpy(k_filter_batter2[2], u_filter_batter2[1]); - - u_filter_batter2[1]=u_filter_batter2[0]; - u_filter_batter2[0]=y; - - i_filter_batter2[1]=i_filter_batter2[0]; - i_filter_batter2[0]=InpVarCurr; - return y; - -} - - -*/ - - - - diff --git a/Inu/Src/main/not_use/log_to_mem.c b/Inu/Src2/main/not_use/log_to_mem.c similarity index 100% rename from Inu/Src/main/not_use/log_to_mem.c rename to Inu/Src2/main/not_use/log_to_mem.c diff --git a/Inu/Src/main/not_use/log_to_mem.h b/Inu/Src2/main/not_use/log_to_mem.h similarity index 100% rename from Inu/Src/main/not_use/log_to_mem.h rename to Inu/Src2/main/not_use/log_to_mem.h diff --git a/Inu/Src2/551/main/optical_bus.c b/Inu/Src2/main/optical_bus.c similarity index 100% rename from Inu/Src2/551/main/optical_bus.c rename to Inu/Src2/main/optical_bus.c diff --git a/Inu/Src2/551/main/optical_bus.h b/Inu/Src2/main/optical_bus.h similarity index 100% rename from Inu/Src2/551/main/optical_bus.h rename to Inu/Src2/main/optical_bus.h diff --git a/Inu/Src/main/optical_bus_tools.c b/Inu/Src2/main/optical_bus_tools.c similarity index 100% rename from Inu/Src/main/optical_bus_tools.c rename to Inu/Src2/main/optical_bus_tools.c diff --git a/Inu/Src/main/optical_bus_tools.h b/Inu/Src2/main/optical_bus_tools.h similarity index 100% rename from Inu/Src/main/optical_bus_tools.h rename to Inu/Src2/main/optical_bus_tools.h diff --git a/Inu/Src2/551/main/overheat_limit.c b/Inu/Src2/main/overheat_limit.c similarity index 100% rename from Inu/Src2/551/main/overheat_limit.c rename to Inu/Src2/main/overheat_limit.c diff --git a/Inu/Src2/551/main/overheat_limit.h b/Inu/Src2/main/overheat_limit.h similarity index 100% rename from Inu/Src2/551/main/overheat_limit.h rename to Inu/Src2/main/overheat_limit.h diff --git a/Inu/Src2/main/params.h b/Inu/Src2/main/params.h index e34752d..7abc592 100644 --- a/Inu/Src2/main/params.h +++ b/Inu/Src2/main/params.h @@ -2,176 +2,177 @@ #define _PARAMS -#define PROPUSK_TEST_TKAK_ON_GO 1 // пропуск тестированиЯ перебором ключей при старте Go=1 +#if(_FLOOR6) + + +#define _ENABLE_PWM_LINES_FOR_TESTS 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 + +#else + +#define _ENABLE_PWM_LINES_FOR_TESTS 0 +#define _ENABLE_PWM_LINES_FOR_TESTS_ROTOR 0 +#define _ENABLE_PWM_LINES_FOR_TESTS_PWM 0 +#define _ENABLE_PWM_LINES_FOR_TESTS_RS 0 +#define _ENABLE_PWM_LINES_FOR_TESTS_SYNC 0//1 +#define _ENABLE_PWM_LINES_FOR_TESTS_GO 0//1 +#endif + + +#if(_FLOOR6) +#define MODE_DISABLE_ENABLE_WDOG 1 // 0 - wdog работает, 1 - запрещен +#else +#define MODE_DISABLE_ENABLE_WDOG 0 // 0 - wdog работает, 1 - запрещен +#endif + + + + + + +#define CHECK_IN_OUT_TERMINAL 1 + +#define WORK_ON_STEND_D 0//1 + + + +//////////////////////////////////////////////////////////////////// +#ifndef MODE_DISABLE_ENABLE_WDOG +#define MODE_DISABLE_ENABLE_WDOG 0 +#endif + + +#ifndef CHECK_IN_OUT_TERMINAL +#define CHECK_IN_OUT_TERMINAL 0 +#endif + +#ifndef WORK_ON_STEND_D +#define WORK_ON_STEND_D 0 +#endif + /*************************************************************************************/ -//#define _test_without_power 1 // тестоваЯ прошивка длЯ запуска без силы -//#define _test_without_skaf 1 // тестоваЯ прошивка длЯ запуска без шкафа управлениЯ -//#define _test_fast_calc 1 // тестоваЯ прошивка длЯ запуска без силы -//#define _test_fast_calc_level1 1 // отключение ненужных функций длЯ ускорениЯ расчетов - -#define _test_without_doors -//#define _test_without_BSO -//#define _test_without_CAN -//#define CHECK_IN_OUT_TERMINAL - -//#define OFF_ERROR_UKSS1 // Выпр1 -//#define OFF_ERROR_UKSS2 //Инв1 -//#define OFF_ERROR_UKSS3 //Инв2 -//#define OFF_ERROR_UKSS4 //Выпр2 -//#define OFF_ERROR_UKSS5 //ШУ -//#define OFF_ERROR_UKSS6 //BTR1 -//#define OFF_ERROR_UKSS7 //BTR2 -//#define OFF_ERROR_UKSS8 //Двиг - -//#define DISABLE_RS_MPU 1 - -#define NEW_I_ZPT_REZISTORS - -#define ENABLE_RECUPER 1 - -#define FREQ_TIMER0 200 /* частота таймера_0 */ -#define FREQ_TIMER1 3300 /* частота таймера_1 */ - -//#define FREQ_PWM 1180 /* частота ШИМа */ //3138 // 2360//2477 // -//#define DOUBLE_UPDATE_PWM 1 - -#define DMIN 750 // 15mks Dminimum -#define SECOND (FREQ_PWM*3) -#define MINUTE (SECOND*60) - - - -//#define REVERS_ON_CLOCK 1 // 0 // 1- по часовой .. 0 - против часовой - //#define BAN_ROTOR_REVERS_DIRECT 1 -//#define TIME_PAUSE_ZADATCHIK 750//500 -// +//#define TIME_PAUSE_ZADATCHIK 750//500 + //#define TIME_SET_LINE_RELAY_FAN 3000 // времЯ подачи импульса на реле включение выключение вентилЯтора //#define LEVEL_FAN_ON_TEMPER_ACDRIVE 1400 //уровень включениЯ вентилЯтора охлаждениЯ двигателЯ //#define LEVEL_FAN_OFF_TEMPER_ACDRIVE 1200 //уровень выключениЯ вентилЯтора охлаждениЯ двигателЯ -////(должен быть меньше LEVEL_FAN_ON_TEMPER_ACDRIVE с запасом на гестирезис ~20 градусов ) -//#define TIME_SET_LINE_RELAY_FAN 3000 //времЯ подачи импульса на реле включение выключение вентилЯтора -// -// -//#define MAX_TIME_DIRECT_ROTOR 5000 // макс. значение счетчика на определение направлениЯ вращениЯ -//#define MIN_TIME_DIRECT_ROTOR -5000 // минимальное значение счетчика на определение направлениЯ вращениЯ -// -//#define LEVEL_FORWARD_TIME_DIRECT_ROTOR 4000 // значение счетчика которое считаетсЯ что направление вперед -//#define LEVEL_BACK_TIME_DIRECT_ROTOR -4000 // значение счетчика которое считаетсЯ что направление назад -// -//#define MAX_TIME_ERROR_ROTOR 5000 // макс. значение счетчика на определение неисправности опреджелениЯ вращениЯ -//#define MIN_TIME_ERROR_ROTOR 0 // мин. значение счетчика на определение неисправности опреджелениЯ вращениЯ -// -// -//#define LEVEL_ON_ERROR_ROTOR 4000 // значение счетчика которое считаетсЯ что направление определЯетсЯ с ошибкой -//#define LEVEL_OFF_ERROR_ROTOR 1000 // значение счетчика которое считаетсЯ что направление определЯетсЯ без ошибкой -// -// -// -//#define WORK_TWICE 0 /* Работаем с двумy обмотками */ -// -// -//#define PID_KP_IM 0.018 //0.036 //0.018 //0.18 //0.095 // PID Kp -//#define PID_KI_IM 0.08 // 0.008 // PID Ki -//#define PID_KD_IM 0.0000 //*100 // PID Kd -//#define PID_KC_IM 0.09 // PID Kc -// -// -//#define PID_KP_F 12//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp -//#define PID_KI_F 0.00010 // 0.008 // PID Ki -//#define PID_KD_F 0.000 //*100 PID Kd -//#define PID_KC_F 0.005 // PID Kc -////#define PID_KC_F 0.000 // PID Kc -// -//#define ADD_KP_DF (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) -//#define ADD_KI_DF (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) -//#define MAX_DELTA_pidF 2.0 -//#define MIN_MZZ_FOR_DF 1761607 //(210/NORMA_MZZ) -// -// -//#define Im_PREDEL 600 /* предельный фазный ток при работе от сети */ -//#define I_OUT_PREDEL -20 /* предельный мин. ток потреблениy при работе от сети */ -//#define U_IN_PREDEL 500 /* предельное максимальное входное напрyжение при работе от сети */ -// -//#define IQ_NORMAL_CHARGE_UD_MAX 12163481 // 1450 V //13002342 // 1550 //_IQtoF(filter.iqU_1_long)*NORMA_ACP -//#define IQ_NORMAL_CHARGE_UD_MIN 10066329 // 1200 V -// -// -//#define U_D_MAX_ERROR_GLOBAL 17616076 // 2100 V //17196646 //2050V // 16777216 //2000V/2000*2^24 -//#define U_D_MAX_ERROR 16777216 // 2000V //16357785 //1950V //15938355 //1900V/2000*2^24 -// -////#define U_D_NORMA_MIN 3774873 // 450 V // 13421772 // 450 V 22.05.08 //1600V/2000*2^24 -////#define U_D_NORMA_MAX 15518924 // //15099494 //1850V/2000*2^24 -// -//#define U_D_MIN_ERROR 10905190 // 1300V/2000*2^24 -// -//#define I_IN_MAX_ERROR_GLOBAL 18454937 // 2200 A //16777216 //2000 A // 13421772 //1600 A //10905190 //1300 // 900A -// -//#define KOEFF_WROTOR_FILTER_SPARTAN 7//8 -//#define MAX_DELTA_WROTOR_S_1_2 1 -// -//#define ENABLE_I_HDW_PROTECT_ON_GLOBAL 1 // разрешить отключать силовые автоматы по аппаратной токовой защите -// -//#define TIME_WAIT_CHARGE 2000 //5000 // 10000 -//#define TIME_WAIT_CHARGE_OUT 15000 //15000 -//#define TIME_SET_LINE_RELAY 10000 -//#define TIME_SET_LINE_RELAY5 3000 -//#define TIME_WAIT_LEVEL_QPU2 3000 -// +//(должен быть меньше LEVEL_FAN_ON_TEMPER_ACDRIVE с запасом на гестирезис ~20 градусов ) +//#define TIME_SET_LINE_RELAY_FAN 3000 //времЯ подачи импульса на реле включение выключение вентилЯтора +/* +#define MAX_TIME_DIRECT_ROTOR 5000 // макс. значение счетчика на определение направлениЯ вращениЯ +#define MIN_TIME_DIRECT_ROTOR -5000 // минимальное значение счетчика на определение направлениЯ вращениЯ + +#define LEVEL_FORWARD_TIME_DIRECT_ROTOR 4000 // значение счетчика которое считаетсЯ что направление вперед +#define LEVEL_BACK_TIME_DIRECT_ROTOR -4000 // значение счетчика которое считаетсЯ что направление назад + +#define MAX_TIME_ERROR_ROTOR 5000 // макс. значение счетчика на определение неисправности опреджелениЯ вращениЯ +#define MIN_TIME_ERROR_ROTOR 0 // мин. значение счетчика на определение неисправности опреджелениЯ вращениЯ + + +#define LEVEL_ON_ERROR_ROTOR 4000 // значение счетчика которое считаетсЯ что направление определЯетсЯ с ошибкой +#define LEVEL_OFF_ERROR_ROTOR 1000 // значение счетчика которое считаетсЯ что направление определЯетсЯ без ошибкой +*/ + + +/* +#define PID_KP_IM 0.018 //0.036 //0.018 //0.18 //0.095 // PID Kp +#define PID_KI_IM 0.08 // 0.008 // PID Ki +#define PID_KD_IM 0.0000 //100 // PID Kd +#define PID_KC_IM 0.09 // PID Kc + + +#define PID_KP_F 12//26//12 //40 //20 //12 //20 //60.0 //20.0 //0.095 // PID Kp +#define PID_KI_F 0.00010 // 0.008 // PID Ki +#define PID_KD_F 0.000 //100 PID Kd +#define PID_KC_F 0.005 // PID Kc +//#define PID_KC_F 0.000 // PID Kc + +#define ADD_KP_DF (1000.0/NORMA_MZZ)//(500.0/NORMA_MZZ)//(50.0/NORMA_MZZ) +#define ADD_KI_DF (2000.0/NORMA_MZZ)//(1000.0/NORMA_MZZ)//(100.0/NORMA_MZZ) +#define MAX_DELTA_pidF 2.0 +#define MIN_MZZ_FOR_DF 1761607 //(210/NORMA_MZZ) +*/ + +/* +#define Im_PREDEL 600 // предельный фазный ток при работе от сети +#define I_OUT_PREDEL -20 // предельный мин. ток потреблениy при работе от сети +#define U_IN_PREDEL 500 // предельное максимальное входное напрyжение при работе от сети + +#define IQ_NORMAL_CHARGE_UD_MAX 12163481 // 1450 V //13002342 // 1550 //_IQtoF(filter.iqU_1_long)*NORMA_ACP +#define IQ_NORMAL_CHARGE_UD_MIN 10066329 // 1200 V + + +#define U_D_MAX_ERROR_GLOBAL 17616076 // 2100 V //17196646 //2050V // 16777216 //2000V/2000*2^24 +#define U_D_MAX_ERROR 16777216 // 2000V //16357785 //1950V //15938355 //1900V/2000*2^24 + +//#define U_D_NORMA_MIN 3774873 // 450 V // 13421772 // 450 V 22.05.08 //1600V/2000*2^24 +//#define U_D_NORMA_MAX 15518924 // //15099494 //1850V/2000*2^24 + +#define U_D_MIN_ERROR 10905190 // 1300V/2000*2^24 + +#define I_IN_MAX_ERROR_GLOBAL 18454937 // 2200 A //16777216 //2000 A // 13421772 //1600 A //10905190 //1300 // 900A + +#define KOEFF_WROTOR_FILTER_SPARTAN 7//8 +#define MAX_DELTA_WROTOR_S_1_2 1 + +#define ENABLE_I_HDW_PROTECT_ON_GLOBAL 1 // разрешить отключать силовые автоматы по аппаратной токовой защите + +#define TIME_WAIT_CHARGE 2000 //5000 // 10000 +#define TIME_WAIT_CHARGE_OUT 15000 //15000 +#define TIME_SET_LINE_RELAY 10000 +#define TIME_SET_LINE_RELAY5 3000 +#define TIME_WAIT_LEVEL_QPU2 3000 +*/ + + +/* ///--------------------------- 22220 paremetrs -------------------///////// //////////////////////////////////////////////////////////////// // Loaded capasitors level #define V_CAPASITORS_LOADED_IQ 11184810 //13421772 ~ 2400V // 11184810 ~ 2000V -#define V_NOMINAL 14260633 //15099494 ~ 2700V +#define V_NOMINAL 15099494 //15099494 ~ 2700V // Level of nominal currents -#define I_OUT_NOMINAL 1585.0 //A -#define I_OUT_NOMINAL_IQ 12482249 //9777761 ~ 1748 //8388608 ~ 1500A // 10066329 ~ 1800A // 8863067 ~ 1585 - //11184811 ~ 2000A // 12482249 ~ 2232A -#define I_OUT_1_6_NOMINAL_IQ 14180908 -#define I_OUT_1_8_NOMINAL_IQ 15953520 +#define I_OUT_NOMINAL_IQ 10066329 //8388608 ~ 1500A //5592405 ~ 1000A // 10066329 ~ 1800A + //11184811 ~ 2000A // 12482249 ~ 2232A // 6710886 ~ 1200A #define I_ZPT_NOMINAL_IQ 6123683 //1095A -#define IQ_OUT_NOM 2000.0 //1350.0 -#define ID_OUT_NOM (I_OUT_NOMINAL * 0.52) -#define NORMA_FROTOR 20.0 -#define NORMA_MZZ 3000.0 //5000 -#define NORMA_ACP 3000.0 + +#define NORMA_MZZ 3000 //5000 +//#define NORMA_ACP 3000 #define DISABLE_TEST_TKAK_ON_START 1 //#define MOTOR_STEND 1 -#define F_STATOR_MAX 20.0 /* макс. скорость ограничена электроникой */ -#define F_STATOR_NOM 12.0 //Hz -#define IQ_F_STATOR_NOM 10066329 -#define F_ROTOR_NOM 2.0 //Hz -#define IQ_F_ROTOR_NOM 1677721 -#define FREQ_PWM 450 //420 // 350 //401 //379 -#define FREQ_PWM_BASE 400 +//#define FREQ_PWM 350 //401 //379 #ifdef MOTOR_STEND -#define POLUS 4 /* число пар полюсов */ +#define POLUS 4 // число пар полюсов + #define BPSI_NORMAL 0.9//0.7 //Hz #define MAX_FZAD_FROM_SU 16.7 // Максимально возможно заданные обороты с ситемы ВУ Гц #define MAX_FZAD_FROM_SU_OBOROT 1100 -#define COS_FI 0.98 + #else -#define POLUS 6 /* число пар полюсов */ +#define POLUS 6 // число пар полюсов #define BPSI_NORMAL 0.9 //Hz #define MAX_FZAD_FROM_SU 16.7 // Максимально возможно заданные обороты с ситемы ВУ Гц #define MAX_FZAD_FROM_SU_OBOROT 1650 -#define COS_FI 0.87 -//PCH21 - 0.81 -//PCH32 - 0.82 -//PCH12 - 0.82 -#endif +#define COS_FI 0.83 +#endif +*/ #define KOEF_TEMPER_DECR_MZZ 2.0 diff --git a/Inu/Src2/551/main/params_alg.h b/Inu/Src2/main/params_alg.h similarity index 100% rename from Inu/Src2/551/main/params_alg.h rename to Inu/Src2/main/params_alg.h diff --git a/Inu/Src2/551/main/params_bsu.h b/Inu/Src2/main/params_bsu.h similarity index 100% rename from Inu/Src2/551/main/params_bsu.h rename to Inu/Src2/main/params_bsu.h diff --git a/Inu/Src2/551/main/params_hwp.h b/Inu/Src2/main/params_hwp.h similarity index 100% rename from Inu/Src2/551/main/params_hwp.h rename to Inu/Src2/main/params_hwp.h diff --git a/Inu/Src2/551/main/params_motor.h b/Inu/Src2/main/params_motor.h similarity index 100% rename from Inu/Src2/551/main/params_motor.h rename to Inu/Src2/main/params_motor.h diff --git a/Inu/Src2/551/main/params_norma.h b/Inu/Src2/main/params_norma.h similarity index 100% rename from Inu/Src2/551/main/params_norma.h rename to Inu/Src2/main/params_norma.h diff --git a/Inu/Src2/551/main/params_protect_adc.h b/Inu/Src2/main/params_protect_adc.h similarity index 100% rename from Inu/Src2/551/main/params_protect_adc.h rename to Inu/Src2/main/params_protect_adc.h diff --git a/Inu/Src2/551/main/params_pwm24.h b/Inu/Src2/main/params_pwm24.h similarity index 100% rename from Inu/Src2/551/main/params_pwm24.h rename to Inu/Src2/main/params_pwm24.h diff --git a/Inu/Src2/551/main/params_temper_p.h b/Inu/Src2/main/params_temper_p.h similarity index 100% rename from Inu/Src2/551/main/params_temper_p.h rename to Inu/Src2/main/params_temper_p.h diff --git a/Inu/Src/main/pll_tools.c b/Inu/Src2/main/pll_tools.c similarity index 100% rename from Inu/Src/main/pll_tools.c rename to Inu/Src2/main/pll_tools.c diff --git a/Inu/Src/main/pll_tools.h b/Inu/Src2/main/pll_tools.h similarity index 100% rename from Inu/Src/main/pll_tools.h rename to Inu/Src2/main/pll_tools.h diff --git a/Inu/Src2/551/main/project.c b/Inu/Src2/main/project.c similarity index 100% rename from Inu/Src2/551/main/project.c rename to Inu/Src2/main/project.c diff --git a/Inu/Src2/551/main/project.h b/Inu/Src2/main/project.h similarity index 100% rename from Inu/Src2/551/main/project.h rename to Inu/Src2/main/project.h diff --git a/Inu/Src2/551/main/project_setup.h b/Inu/Src2/main/project_setup.h similarity index 100% rename from Inu/Src2/551/main/project_setup.h rename to Inu/Src2/main/project_setup.h diff --git a/Inu/Src2/551/main/protect_levels.h b/Inu/Src2/main/protect_levels.h similarity index 100% rename from Inu/Src2/551/main/protect_levels.h rename to Inu/Src2/main/protect_levels.h diff --git a/Inu/Src2/551/main/pump_control.c b/Inu/Src2/main/pump_control.c similarity index 100% rename from Inu/Src2/551/main/pump_control.c rename to Inu/Src2/main/pump_control.c diff --git a/Inu/Src2/551/main/pump_control.h b/Inu/Src2/main/pump_control.h similarity index 100% rename from Inu/Src2/551/main/pump_control.h rename to Inu/Src2/main/pump_control.h diff --git a/Inu/Src/main/pwm_logs.c b/Inu/Src2/main/pwm_logs.c similarity index 100% rename from Inu/Src/main/pwm_logs.c rename to Inu/Src2/main/pwm_logs.c diff --git a/Inu/Src/main/pwm_logs.h b/Inu/Src2/main/pwm_logs.h similarity index 100% rename from Inu/Src/main/pwm_logs.h rename to Inu/Src2/main/pwm_logs.h diff --git a/Inu/Src2/551/main/pwm_test_lines.c b/Inu/Src2/main/pwm_test_lines.c similarity index 100% rename from Inu/Src2/551/main/pwm_test_lines.c rename to Inu/Src2/main/pwm_test_lines.c diff --git a/Inu/Src2/551/main/pwm_test_lines.h b/Inu/Src2/main/pwm_test_lines.h similarity index 100% rename from Inu/Src2/551/main/pwm_test_lines.h rename to Inu/Src2/main/pwm_test_lines.h diff --git a/Inu/Src/main/ramp_zadanie_tools.c b/Inu/Src2/main/ramp_zadanie_tools.c similarity index 100% rename from Inu/Src/main/ramp_zadanie_tools.c rename to Inu/Src2/main/ramp_zadanie_tools.c diff --git a/Inu/Src/main/ramp_zadanie_tools.h b/Inu/Src2/main/ramp_zadanie_tools.h similarity index 100% rename from Inu/Src/main/ramp_zadanie_tools.h rename to Inu/Src2/main/ramp_zadanie_tools.h diff --git a/Inu/Src2/main/rotation_speed.h b/Inu/Src2/main/rotation_speed.h deleted file mode 100644 index a28fa49..0000000 --- a/Inu/Src2/main/rotation_speed.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _ROT_SPEED -#define _ROT_SPEED - -#include "IQmathLib.h" - -#define SENSORS_NUMBER 10 -#define SENSORS_NUMBER_ONLY_IN 6 -#define IMPULSES_PER_TURN (1LL << 13) //Old sensor -//#define IMPULSES_PER_TURN (1LL << 10) //New sensor -#define ANGLE_RESOLUTION (1LL << 18) //2^18 - -typedef struct -{ - int direct_rotor; - int direct_rotor_in1; - int direct_rotor_in2; - int direct_rotor_angle; - union { - unsigned int sens_err1:1; - unsigned int sens_err2:1; - unsigned int reserved:14; - } error; - - _iq iqFsensors[SENSORS_NUMBER]; - - _iq iqF; - _iq iqFout; - _iq iqFlong; - - _iq iqFrotFromOptica; - - unsigned int error_update_count; -} ROTOR_VALUE; - -#define ROTOR_VALUE_DEFAULTS {0,0,0,0,0, {0,0,0,0,0,0,0,0},0,0,0,0,0} - -extern ROTOR_VALUE rotor; - -void Rotor_measure(void); -void rotorInit(void); -void update_rot_sensors(); - -#endif //_ROT_SPEED - diff --git a/Inu/Src2/551/main/sbor_shema.c b/Inu/Src2/main/sbor_shema.c similarity index 100% rename from Inu/Src2/551/main/sbor_shema.c rename to Inu/Src2/main/sbor_shema.c diff --git a/Inu/Src2/551/main/sbor_shema.h b/Inu/Src2/main/sbor_shema.h similarity index 100% rename from Inu/Src2/551/main/sbor_shema.h rename to Inu/Src2/main/sbor_shema.h diff --git a/Inu/Src/main/sim_model.c b/Inu/Src2/main/sim_model.c similarity index 100% rename from Inu/Src/main/sim_model.c rename to Inu/Src2/main/sim_model.c diff --git a/Inu/Src/main/sim_model.h b/Inu/Src2/main/sim_model.h similarity index 100% rename from Inu/Src/main/sim_model.h rename to Inu/Src2/main/sim_model.h diff --git a/Inu/Src2/551/main/sync_tools.c b/Inu/Src2/main/sync_tools.c similarity index 100% rename from Inu/Src2/551/main/sync_tools.c rename to Inu/Src2/main/sync_tools.c diff --git a/Inu/Src2/551/main/sync_tools.h b/Inu/Src2/main/sync_tools.h similarity index 100% rename from Inu/Src2/551/main/sync_tools.h rename to Inu/Src2/main/sync_tools.h diff --git a/Inu/Src/main/synhro_tools.c b/Inu/Src2/main/synhro_tools.c similarity index 100% rename from Inu/Src/main/synhro_tools.c rename to Inu/Src2/main/synhro_tools.c diff --git a/Inu/Src/main/synhro_tools.h b/Inu/Src2/main/synhro_tools.h similarity index 100% rename from Inu/Src/main/synhro_tools.h rename to Inu/Src2/main/synhro_tools.h diff --git a/Inu/Src/main/temper_p_tools.c b/Inu/Src2/main/temper_p_tools.c similarity index 100% rename from Inu/Src/main/temper_p_tools.c rename to Inu/Src2/main/temper_p_tools.c diff --git a/Inu/Src/main/temper_p_tools.h b/Inu/Src2/main/temper_p_tools.h similarity index 100% rename from Inu/Src/main/temper_p_tools.h rename to Inu/Src2/main/temper_p_tools.h diff --git a/Inu/Src2/551/main/tk_Test.c b/Inu/Src2/main/tk_Test.c similarity index 100% rename from Inu/Src2/551/main/tk_Test.c rename to Inu/Src2/main/tk_Test.c diff --git a/Inu/Src2/551/main/tk_Test.h b/Inu/Src2/main/tk_Test.h similarity index 100% rename from Inu/Src2/551/main/tk_Test.h rename to Inu/Src2/main/tk_Test.h diff --git a/Inu/Src/main/ukss_tools.c b/Inu/Src2/main/ukss_tools.c similarity index 100% rename from Inu/Src/main/ukss_tools.c rename to Inu/Src2/main/ukss_tools.c diff --git a/Inu/Src/main/ukss_tools.h b/Inu/Src2/main/ukss_tools.h similarity index 100% rename from Inu/Src/main/ukss_tools.h rename to Inu/Src2/main/ukss_tools.h diff --git a/Inu/Src/main/uom_tools.c b/Inu/Src2/main/uom_tools.c similarity index 100% rename from Inu/Src/main/uom_tools.c rename to Inu/Src2/main/uom_tools.c diff --git a/Inu/Src/main/uom_tools.h b/Inu/Src2/main/uom_tools.h similarity index 100% rename from Inu/Src/main/uom_tools.h rename to Inu/Src2/main/uom_tools.h diff --git a/Inu/Src2/main/v_pwm24.c b/Inu/Src2/main/v_pwm24.c deleted file mode 100644 index 357cb98..0000000 --- a/Inu/Src2/main/v_pwm24.c +++ /dev/null @@ -1,1635 +0,0 @@ - - -#include "v_pwm24.h" -//#include "DSP281x_Device.h" // DSP281x Headerfile Include File -//#include "big_dsp_module.h" -//#include "rmp2cntl.h" // Include header for the VHZPROF object -//#include "rmp_cntl_my1.h" // Include header for the VHZPROF object -#include "pid_reg3.h" // Include header for the VHZPROF object - -#include "params.h" -// #include "PWMTools.h" -#include "adc_tools.h" -#include "v_pwm24.h" - -#include "dq_to_alphabeta_cos.h" - -#include "IQmathLib.h" -// #include "log_to_memory.h" -//Xilinx -//#include "x_parameters.h" -// #include "x_basic_types.h" -// #include "xp_project.h" -// #include "xp_cds_tk.h" -#include "svgen_dq.h" -#include "xp_write_xpwm_time.h" - -#include "def.h" - -#define DEF_FREQ_PWM_XTICS T1_PRD -#define DEF_PERIOD_MIN_XTICS (DT + 10e-6)*FTBCLK - -// Частота ШИМ в xilinx тиках (60000000 / 16 / FREQ_PWM = 3750000 / FREQ_PWM) -// #pragma DATA_SECTION(VAR_FREQ_PWM_XTICS,".fast_vars1"); -int VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS; - -// Минимальное значение ШИМа в xilinx тиках -// #pragma DATA_SECTION(VAR_PERIOD_MAX_XTICS,".fast_vars1"); -int VAR_PERIOD_MAX_XTICS = DEF_FREQ_PWM_XTICS - DEF_PERIOD_MIN_XTICS; - -// Минимальное значение ШИМа в xilinx тиках (mintime+deadtime) (Fпилы * Tмин.ключа.сек = (60 / 16 / 2) * Tмкс = (60 * Tмкс / 16 / 2)) -// #pragma DATA_SECTION(VAR_PERIOD_MIN_XTICS,".fast_vars1"); -int VAR_PERIOD_MIN_XTICS = DEF_PERIOD_MIN_XTICS;// - -// Минимальное значение ШИМа в xilinx тиках для тормозных ключей (mintime) (Fпилы * Tмин.ключа.сек = (60 / 16 / 2) * Tмкс = (60 * Tмкс / 16 / 2)) -// #pragma DATA_SECTION(VAR_PERIOD_MIN_BR_XTICS,".fast_vars1"); -// int VAR_PERIOD_MIN_BR_XTICS = DEF_PERIOD_MIN_BR_XTICS;// - -#define PWM_ONE_INTERRUPT_RUN 1 -#define PWM_TWICE_INTERRUPT_RUN 0 - - - -#define SQRT3 29058990 //1.7320508075688772935274463415059 -#define CONST_IQ_1 16777216 //1 -#define CONST_IQ_05 8388608 //0.5 -#define CONST_IQ_2 33554432 //2 - -#define CONST_IQ_PI6 8784530 //30 -#define CONST_IQ_PI3 17569060 // 60 -#define CONST_IQ_PI 52707178 // 180 -#define CONST_IQ_OUR1 35664138 // -#define CONST_IQ_2PI 105414357 // 360 -#define CONST_IQ_120G 35138119 // 120 grad -#define CONST_IQ_3 50331648 // 3 - -#define IQ_ALFA_SATURATION1 15099494//16441671//15099494 -#define IQ_ALFA_SATURATION2 1677721//16441671//15099494 - - -#define PI 3.1415926535897932384626433832795 - -// #pragma DATA_SECTION(iq_alfa_coef,".fast_vars"); -_iq iq_alfa_coef = 16777216; - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -//#pragma DATA_SECTION(freq_array,".v_24pwm_vars"); -//int freq_array[COUNT_VAR_FREQ]; -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -//#pragma DATA_SECTION(pidCur_Kp,".v_24pwm_vars"); -//_iq pidCur_Kp = 0; - -// #pragma DATA_SECTION(pidCur_Ki,".fast_vars"); -_iq pidCur_Ki = 0; - -// #pragma DATA_SECTION(ar_tph,".fast_vars"); -_iq ar_tph[7]; - -// #pragma DATA_SECTION(winding_displacement,".fast_vars"); -_iq winding_displacement = CONST_IQ_PI6; - -//#pragma DATA_SECTION(iq_koef_mod_korrect_1,".fast_vars");//v_24pwm_vars -//_iq iq_koef_mod_korrect_1; - -//#pragma DATA_SECTION(iq_koef_mod_korrect_2,".v_24pwm_vars"); -//_iq iq_koef_mod_korrect_2; - -//#pragma DATA_SECTION(ar_sa_all,".v_24pwm_vars"); -// #pragma DATA_SECTION(ar_sa_all,".fast_vars"); -int ar_sa_all[3][6][4][7] = { { - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - }, - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - }, - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - }, - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - }, - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - }, - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - } - }, - { - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - }, - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - }, - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - }, - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - }, - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - }, - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - } - }, - { - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - }, - { - {-1,-1,-1,0,0,0,1},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0},{-1,-1,-1,0,0,0,0} - }, - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - }, - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - }, - { - {-1,0,0,0,1,1,1},{0,1,1,1,0,0,0},{0,0,1,1,1,0,0},{0,1,1,1,0,0,0} - }, - { - {-1,-1,0,0,0,1,1},{-1,-1,0,0,0,0,0},{-1,0,0,0,1,0,0},{0,0,1,1,0,0,0} - } - } - }; - - -// #pragma DATA_SECTION(svgen_pwm24_1,".v_24pwm_vars"); -//#pragma DATA_SECTION(svgen_pwm24_1,".fast_vars"); -SVGEN_PWM24 svgen_pwm24_1 = SVGEN_PWM24_DEFAULTS; -// #pragma DATA_SECTION(svgen_pwm24_2,".v_24pwm_vars"); -//#pragma DATA_SECTION(svgen_pwm24_2,".fast_vars"); -SVGEN_PWM24 svgen_pwm24_2 = SVGEN_PWM24_DEFAULTS; - -// #pragma DATA_SECTION(svgen_dq_1,".v_24pwm_vars"); -SVGENDQ svgen_dq_1 = SVGENDQ_DEFAULTS; -// #pragma DATA_SECTION(svgen_dq_2,".v_24pwm_vars"); -SVGENDQ svgen_dq_2 = SVGENDQ_DEFAULTS; - -//#pragma DATA_SECTION(delta_t1_struct,".v_24pwm_vars"); -//#pragma DATA_SECTION(delta_t1_struct,".fast_vars"); -//PIDREG3 delta_t1_struct = PIDREG3_DEFAULTS; -//#pragma DATA_SECTION(delta_t2_struct,".v_24pwm_vars"); -//#pragma DATA_SECTION(delta_t2_struct,".fast_vars"); -//PIDREG3 delta_t2_struct = PIDREG3_DEFAULTS; - -void calc_t_abc(_iq k, _iq teta, int region, _iq *iq_tt0, _iq *iq_tt1, _iq *iq_tt2, _iq *iq_tt3, _iq *iq_tt4, _iq *iq_tt5); -void set_predel_dshim24(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax); -void set_predel_dshim24_simple0(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax); -void set_predel_dshim24_simple1(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax); -int detect_sec(_iq teta); -int detect_region(_iq k, _iq teta); -// - - - - -//void init_alpha(void) -//{ -// -//// power_ain1.init(&power_ain1); -//// power_ain2.init(&power_ain2); -// -// svgen_mf1.NewEntry = 0;//_IQ(0.5); -// svgen_mf2.NewEntry = 0; -// -// svgen_mf1.SectorPointer = 0; -// svgen_mf2.SectorPointer = 0; -// -////сдвиг по умолчанию 0 градусов -// svgen_mf1.Alpha = _IQ(0); -// svgen_mf2.Alpha = _IQ(0); -// -// -// -// -// -//#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_30_PLUS) -//// 30 град. сдвиг -// svgen_mf1.Alpha = _IQ(0.5); -// svgen_mf2.Alpha = _IQ(0); -// -// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; -// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; -//#else -// -// -//#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_30_MINUS) -//// -30 град. сдвиг -// svgen_mf1.Alpha = _IQ(0); -// svgen_mf2.Alpha = _IQ(0.5); -// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; -// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; -//#else -// -//#if (SETUP_SDVIG_OBMOTKI == SDVIG_OBMOTKI_ZERO) -//// -30 град. сдвиг -// svgen_mf1.Alpha = _IQ(0); -// svgen_mf2.Alpha = _IQ(0); -// svgen_mf1.Full_Alpha = svgen_mf1.Alpha; -// svgen_mf2.Full_Alpha = svgen_mf2.Alpha; -//#else -// #error "!!!ОШИБКА!!! Не определен SETUP_SDVIG_OBMOTKI в params_motor.h!!!" -// -// -//#endif -// -//#endif -// -// -// -//#endif -// -// -// -//} - -void InitVariablesSvgen(unsigned int freq) -{ -////////// Inserted from 'initPWM_Variables' for modulation project ////////// - - //Для первой пилы закрыто, когда выше заданного уровня, для второй ниже - xpwm_time.Tclosed_0 = 0; - xpwm_time.Tclosed_1 = VAR_FREQ_PWM_XTICS + 1; - xpwm_time.Tclosed_high = VAR_FREQ_PWM_XTICS + 1; - xpwm_time.pwm_tics = VAR_FREQ_PWM_XTICS; - // выбрали направление пил - // "направление пил для ШИМа типа=0x0 - //Если SAW_DIRECTbit = 0 то значение пилы>уставки выставит активное включенное состояние=0 - //на выходе ШИМа - //Если SAW_DIRECTbit = 1 то значение пилы<=уставки выставит активное включенное состояние=0 - //на выходе ШИМа - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - //Для 22220 инициализирую 0, т.к. при записи в разных частях пилы появляется дизбаланс напряжения. - xpwm_time.saw_direct.all = 0;//0x0555; - xpwm_time.one_or_two_interrupts_run = PWM_TWICE_INTERRUPT_RUN; - - initXpwmTimeStructure(&xpwm_time); - init_alpha_pwm24(VAR_FREQ_PWM_XTICS); -///////////////////////////////////////////////////////////// - - svgen_pwm24_1.pwm_minimal_impuls_zero_minus = 0;//(float)DEF_PERIOD_MIN_MKS*1000.0*FREQ_INTERNAL_GENERATOR_XILINX_TMS/1000000000.0;// DEF_PERIOD_MIN_XTICS_100;//DEF_PERIOD_MIN_XTICS_80; - svgen_pwm24_1.pwm_minimal_impuls_zero_plus = 0;//(float)DEF_PERIOD_MIN_MKS*1000.0*FREQ_INTERNAL_GENERATOR_XILINX_TMS/1000000000.0;// DEF_PERIOD_MIN_XTICS_80; - - svgen_pwm24_2.pwm_minimal_impuls_zero_minus = svgen_pwm24_1.pwm_minimal_impuls_zero_minus; - svgen_pwm24_2.pwm_minimal_impuls_zero_plus = svgen_pwm24_1.pwm_minimal_impuls_zero_plus; - - - svgen_pwm24_1.Tclosed_high = xpwm_time.Tclosed_1; - svgen_pwm24_2.Tclosed_high = xpwm_time.Tclosed_1; - - - - - svgen_dq_1.Ualpha = 0; - svgen_dq_1.Ubeta = 0; - - svgen_dq_2.Ualpha = 0; - svgen_dq_2.Ubeta = 0; - - - -} - - - - - - - - - - -// #pragma CODE_SECTION(recalc_time_pwm_minimal_2_xilinx_pwm24_l,".fast_run2"); -void recalc_time_pwm_minimal_2_xilinx_pwm24_l(SVGEN_PWM24 *pwm24, - _iq *T0, _iq *T1, - _iq timpuls_corr ) -{ - -//_iq pwm_t, timpuls_corr; - - volatile unsigned long pwm_t; - volatile unsigned int minimal_plus, minimal_minus; - - - - minimal_plus = pwm24->pwm_minimal_impuls_zero_plus; - minimal_minus = pwm24->pwm_minimal_impuls_zero_minus; - - // if (pwm24->prev_level == V_PWM24_PREV_PWM_CLOSE || pwm24->prev_level == V_PWM24_PREV_PWM_MIDDLE || pwm24->prev_level == V_PWM24_PREV_PWM_WORK_KM0) - // { - // minimal_plus *= 2; -// minimal_minus *= 2; -// } - - pwm_t = timpuls_corr / pwm24->XilinxFreq; - - // *T_imp = pwm_t; - -// if (pwm_t>(pwm24->Tclosed_high-4*minimal_minus)) -// pwm_t=(pwm24->Tclosed_high-4*minimal_minus); - - - if (timpuls_corr >= 0) - { - *T0 = pwm_t + minimal_plus; - // *T1 = 0; - *T1 = pwm24->Tclosed_high - minimal_minus; - } - else - { - *T0 = 0 + minimal_plus; - // *T1 = -pwm_t - minimal_minus; - *T1 = pwm24->Tclosed_high + pwm_t - minimal_minus; - } - - - // if (*T0 < minimal_plus) - // *T0 = minimal_plus; - - // if (*T0 > (pwm24->Tclosed_high - 2 * minimal_plus)) - // *T0 = (pwm24->Tclosed_high - 2 * minimal_plus); - - // if (*T1 < (2 * minimal_minus)) - // *T1 = 2 * minimal_minus; - - // if (*T1 > (pwm24->Tclosed_high - minimal_minus)) - // *T1 = (pwm24->Tclosed_high - minimal_minus); - -} - -static DQ_TO_ALPHABETA dq_to_ab = DQ_TO_ALPHABETA_DEFAULTS; - -// #pragma CODE_SECTION(test_calc_dq_pwm24,".v_24pwm_run"); -void test_calc_dq_pwm24(_iq Ud, _iq Uq, _iq Ud2, _iq Uq2, _iq tetta,_iq Uzad_max) -{ -// DQ_TO_ALPHABETA dq_to_ab = DQ_TO_ALPHABETA_DEFAULTS; - _iq maxUq = 0; - _iq Uzad_max_square = _IQmpy(Uzad_max, Uzad_max); - - if (tetta > CONST_IQ_2PI) - { - tetta -= CONST_IQ_2PI; - } - - if (tetta < 0) - { - tetta += CONST_IQ_2PI; - } - //Ограничил коэффициент модуляции - maxUq = _IQsqrt(Uzad_max_square - _IQmpy(Ud, Ud)); - if (Uq > maxUq) { Uq = maxUq;} - if (Uq < -maxUq) { Uq = -maxUq;} - - - //Reculct dq to alpha-beta - dq_to_ab.Tetta = tetta; - dq_to_ab.Ud = Ud; - dq_to_ab.Uq = Uq; - dq_to_ab.calc2(&dq_to_ab); - //Calc swgen times for 1-st winding - svgen_dq_1.Ualpha = dq_to_ab.Ualpha; - svgen_dq_1.Ubeta = dq_to_ab.Ubeta; - svgen_dq_1.calc(&svgen_dq_1); - - //Ограничил коэффициент модуляции - maxUq = _IQsqrt(Uzad_max_square - _IQmpy(Ud, Ud)); - if (Uq2 > maxUq) { Uq2 = maxUq;} - if (Uq2 < -maxUq) { Uq2 = -maxUq;} - - //Reculc dq to alpha-beta for 2-nd winding with winding displasement - dq_to_ab.Tetta = tetta - winding_displacement; - dq_to_ab.Ud = Ud2; - dq_to_ab.Uq = Uq2; - dq_to_ab.calc2(&dq_to_ab); - //Calc swgen times for 1-st winding - svgen_dq_2.Ualpha = dq_to_ab.Ualpha; - svgen_dq_2.Ubeta = dq_to_ab.Ubeta; - svgen_dq_2.calc(&svgen_dq_2); - - //1 winding - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Ta_0.Ti, &svgen_pwm24_1.Ta_1.Ti, svgen_dq_1.Ta); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Tb_0.Ti, &svgen_pwm24_1.Tb_1.Ti, svgen_dq_1.Tb); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Tc_0.Ti, &svgen_pwm24_1.Tc_1.Ti, svgen_dq_1.Tc); - - // 2 winding - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Ta_0.Ti, &svgen_pwm24_2.Ta_1.Ti, svgen_dq_2.Ta); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Tb_0.Ti, &svgen_pwm24_2.Tb_1.Ti, svgen_dq_2.Tb); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Tc_0.Ti, &svgen_pwm24_2.Tc_1.Ti, svgen_dq_2.Tc); - -// set_predel_dshim24_simple0(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -/* - set_predel_dshim24(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS);*/ -} - - -// #pragma CODE_SECTION(test_calc_simple_dq_pwm24,".v_24pwm_run"); -void test_calc_simple_dq_pwm24(_iq uz1, _iq uz2, _iq fz1, _iq fz2,_iq Uzad_max) -{ - static _iq hz_to_angle = _IQ(2.0 * PI * NORMA_FROTOR / FREQ_PWM / 2); -// static _iq tetta = 0; - DQ_TO_ALPHABETA dq_to_ab = DQ_TO_ALPHABETA_DEFAULTS; - - _iq Ud = 0; - _iq Uq = _IQsat(uz1,Uzad_max,0); - - analog.tetta += _IQmpy(fz1, hz_to_angle); - - if (analog.tetta >= CONST_IQ_2PI) - { - analog.tetta -= CONST_IQ_2PI; - } - - if (analog.tetta < 0) - { - analog.tetta += CONST_IQ_2PI; - } - - dq_to_ab.Tetta = analog.tetta; - dq_to_ab.Ud = Ud; - dq_to_ab.Uq = Uq; - dq_to_ab.calc2(&dq_to_ab); - - svgen_dq_1.Ualpha = dq_to_ab.Ualpha; - svgen_dq_1.Ubeta = dq_to_ab.Ubeta; - -// svgen_dq_1.Ualpha = 0; -// svgen_dq_1.Ubeta = 0; - - svgen_dq_1.calc(&svgen_dq_1); - - dq_to_ab.Tetta = analog.tetta - winding_displacement; - dq_to_ab.Ud = Ud; - dq_to_ab.Uq = Uq; - dq_to_ab.calc2(&dq_to_ab); - - svgen_dq_2.Ualpha = dq_to_ab.Ualpha; - svgen_dq_2.Ubeta = dq_to_ab.Ubeta; - - svgen_dq_2.calc(&svgen_dq_2); - - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Ta_0.Ti, &svgen_pwm24_1.Ta_1.Ti, svgen_dq_1.Ta); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Tb_0.Ti, &svgen_pwm24_1.Tb_1.Ti, svgen_dq_1.Tb); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_1, &svgen_pwm24_1.Tc_0.Ti, &svgen_pwm24_1.Tc_1.Ti, svgen_dq_1.Tc); - - // 2 - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Ta_0.Ti, &svgen_pwm24_2.Ta_1.Ti, svgen_dq_2.Ta); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Tb_0.Ti, &svgen_pwm24_2.Tb_1.Ti, svgen_dq_2.Tb); - recalc_time_pwm_minimal_2_xilinx_pwm24_l (&svgen_pwm24_2, &svgen_pwm24_2.Tc_0.Ti, &svgen_pwm24_2.Tc_1.Ti, svgen_dq_2.Tc); - -// logpar.log1 = (int16)(_IQtoIQ15(uz1)); -// logpar.log2 = (int16)(_IQtoIQ15(fz1)); -// logpar.log3 = (int16)(_IQtoIQ15(Ud)); -// logpar.log4 = (int16)(_IQtoIQ15(Uq)); -// logpar.log5 = (int16)(_IQtoIQ15(svgen_dq_1.Ualpha)); -// logpar.log6 = (int16)(_IQtoIQ15(svgen_dq_1.Ubeta)); -// logpar.log7 = (int16)(_IQtoIQ15(svgen_dq_1.Ta)); -// logpar.log8 = (int16)(_IQtoIQ15(svgen_dq_1.Tb)); -// logpar.log9 = (int16)(_IQtoIQ15(svgen_dq_1.Tc)); -// logpar.log10 = (int16)(_IQtoIQ12(analog.tetta)); -// logpar.log11 = (int16)(svgen_pwm24_1.Ta_0.Ti); -// logpar.log12 = (int16)((svgen_pwm24_1.Ta_1.Ti)); -// logpar.log13 = (int16)(svgen_pwm24_1.Tb_0.Ti); -// logpar.log14 = (int16)((svgen_pwm24_1.Tb_1.Ti)); -// logpar.log15 = (int16)(svgen_pwm24_1.Tc_0.Ti); -// logpar.log16 = (int16)((svgen_pwm24_1.Tc_1.Ti)); - - -// svgen_pwm24_1.calc(&svgen_pwm24_1); -// svgen_pwm24_2.calc(&svgen_pwm24_2); - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// set_predel_dshim24_simple0(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// -// set_predel_dshim24_simple0(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); -// set_predel_dshim24_simple1(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - -} - -// #pragma CODE_SECTION(test_calc_pwm24,".v_24pwm_run"); -void test_calc_pwm24(_iq uz1, _iq uz2, _iq fz1) -{ - //static int i =0; - svgen_pwm24_1.Freq = fz1; - svgen_pwm24_2.Freq = fz1; - - svgen_pwm24_1.Gain = uz1;//_IQmpy(uz1,iq_koef_mod_korrect_1); - svgen_pwm24_2.Gain = uz2;//_IQmpy(uz2,iq_koef_mod_korrect_2); - - svgen_pwm24_1.delta_U = filter.iqU_1_fast - filter.iqU_2_fast; - svgen_pwm24_2.delta_U = filter.iqU_3_fast - filter.iqU_4_fast; - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - svgen_pwm24_1.delta_U = 0; - svgen_pwm24_2.delta_U = 0; - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - svgen_pwm24_1.Ia = analog.iqIa1_1; - svgen_pwm24_1.Ib = analog.iqIb1_1; - svgen_pwm24_1.Ic = analog.iqIc1_1; - - svgen_pwm24_2.Ia = analog.iqIa2_1; - svgen_pwm24_2.Ib = analog.iqIb2_1; - svgen_pwm24_2.Ic = analog.iqIc2_1; - - svgen_pwm24_1.calc(&svgen_pwm24_1); - svgen_pwm24_2.calc(&svgen_pwm24_2); - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - set_predel_dshim24(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - -// if(((svgen_pwm24_2.Ta_0.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Ta_0.Ti <= (VAR_FREQ_PWM_XTICS))) || -// ((svgen_pwm24_2.Ta_1.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Ta_1.Ti <= (VAR_FREQ_PWM_XTICS))) || -// ((svgen_pwm24_2.Tb_0.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Tb_0.Ti <= (VAR_FREQ_PWM_XTICS))) || -// ((svgen_pwm24_2.Tb_1.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Tb_1.Ti <= (VAR_FREQ_PWM_XTICS))) || -// ((svgen_pwm24_2.Tc_0.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Tc_0.Ti <= (VAR_FREQ_PWM_XTICS))) || -// ((svgen_pwm24_2.Tc_1.Ti > (VAR_FREQ_PWM_XTICS - VAR_PERIOD_MIN_XTICS)) && (svgen_pwm24_2.Tc_1.Ti <= (VAR_FREQ_PWM_XTICS)))) -// { -// asm(" NOP "); -// } -// -// if( ((svgen_pwm24_2.Ta_0.Ti > 0) && (svgen_pwm24_2.Ta_0.Ti < (VAR_PERIOD_MIN_XTICS))) || -// ((svgen_pwm24_2.Ta_1.Ti > 0) && (svgen_pwm24_2.Ta_1.Ti < (VAR_PERIOD_MIN_XTICS))) || -// ((svgen_pwm24_2.Tb_0.Ti > 0) && (svgen_pwm24_2.Tb_0.Ti < (VAR_PERIOD_MIN_XTICS))) || -// ((svgen_pwm24_2.Tb_1.Ti > 0) && (svgen_pwm24_2.Tb_1.Ti < (VAR_PERIOD_MIN_XTICS))) || -// ((svgen_pwm24_2.Tc_0.Ti > 0) && (svgen_pwm24_2.Tc_0.Ti < (VAR_PERIOD_MIN_XTICS))) || -// ((svgen_pwm24_2.Tc_1.Ti > 0) && (svgen_pwm24_2.Tc_1.Ti < (VAR_PERIOD_MIN_XTICS)))) -// { -// asm(" NOP "); -// } -} - - -// #pragma CODE_SECTION(svgen_pwm24_calc,".v_24pwm_run"); -void svgen_pwm24_calc(SVGEN_PWM24 *vt) -{ - _iq StepAngle; - - StepAngle = _IQmpy(vt->Freq,vt->FreqMax); - - vt->Alpha = vt->Alpha + StepAngle; - - - if (vt->Alpha > CONST_IQ_2PI) - { - vt->Alpha -= CONST_IQ_2PI; - } - - if (vt->Alpha < 0) - { - vt->Alpha += CONST_IQ_2PI; - } - - - calc_time_one_tk(vt->Gain, vt->Alpha, vt->delta_U, vt->Ia, vt->Ib, vt->Ic, - vt->number_svgen, &vt->Ta_0, &vt->Ta_1,&vt->Tb_0, &vt->Tb_1,&vt->Tc_0, &vt->Tc_1); - - - - vt->Ta_0.Ti = vt->Ta_0.Ti/vt->XilinxFreq; - vt->Ta_1.Ti = vt->Ta_1.Ti/vt->XilinxFreq; - - vt->Tb_0.Ti = vt->Tb_0.Ti/vt->XilinxFreq; - vt->Tb_1.Ti = vt->Tb_1.Ti/vt->XilinxFreq; - - vt->Tc_0.Ti = vt->Tc_0.Ti/vt->XilinxFreq; - vt->Tc_1.Ti = vt->Tc_1.Ti/vt->XilinxFreq; - -} - - -// #pragma CODE_SECTION(calc_time_one_tk,".v_24pwm_run"); -void calc_time_one_tk(_iq gain, _iq teta, _iq delta_U, - _iq Ia, _iq Ib, _iq Ic, - unsigned int number, - SVGEN_PWM24_TIME *tk0, - SVGEN_PWM24_TIME *tk1, - SVGEN_PWM24_TIME *tk2, - SVGEN_PWM24_TIME *tk3, - SVGEN_PWM24_TIME *tk4, - SVGEN_PWM24_TIME *tk5) -{ - _iq iq_t0 = 0, iq_t1 = 0, iq_t2 = 0, iq_t3 = 0, iq_t4 = 0, iq_t5 = 0; - _iq t_pos = 0, t_neg = 0; - _iq delta_ttt; - _iq teta60; - - int sector, region; - int cur_sign, i, ki; - int updown_tk0; - int updown_tk1; - - volatile _iq t_tk0, t_tk1; - - updown_tk0 = 1; - updown_tk1 = 0; - - sector = detect_sec(teta); // - teta60 = teta - _IQmpy(_IQ(sector - 1),CONST_IQ_PI3); // - - if ((sector == 2) || (sector == 4) || (sector == 6)) - { - teta60 = CONST_IQ_PI3 - teta60; - } - - region = detect_region(gain, teta60); // - - calc_t_abc(gain, teta60, region, &iq_t0, &iq_t1, &iq_t2, &iq_t3, &iq_t4, &iq_t5); - - - delta_ttt = 0; //calc_delta_t(delta_U,number,region); - //delta_ttt = 0; - - //if (number == 1) - //{ - //logpar.log1 = (int16)(_IQtoIQ15(delta_U)); - //logpar.log2 = (int16)(_IQtoIQ15(delta_ttt)); - //} - //else - //{ - //logpar.log3 = (int16)(_IQtoIQ15(delta_U)); - //logpar.log4 = (int16)(_IQtoIQ15(delta_ttt)); - //} - - calc_arr_tph(sector, region, iq_t0, iq_t1, iq_t2, iq_t3, iq_t4, iq_t5, delta_ttt,number, Ia, Ib, Ic); - - for (ki = 0; ki < 3; ki++) - { - t_pos = 0; - t_neg = 0; - - for (i = 0; i < 7; i++) - { - cur_sign = ar_sa_all[ki][sector - 1][region - 1][i]; - - if (cur_sign > 0) - { - t_pos += ar_tph[i]; - } - - if (cur_sign < 0) - { - t_neg += ar_tph[i]; - } - } - - t_pos = t_pos << 1; - - t_neg = t_neg << 1; - - if (t_neg == 0) - { - t_tk0 = 0; - } - else - { - t_tk0 = t_neg; - } - - if (t_pos == 0) - { - t_tk1 = CONST_IQ_1; - } - else - { - t_tk1 = CONST_IQ_1 - t_pos; - } - - switch (ki) - { - case 0: - tk0->up_or_down = updown_tk0; - tk0->Ti = t_tk0; - - tk1->up_or_down = updown_tk1; - tk1->Ti = t_tk1; - - break; - - case 1: - tk2->up_or_down = updown_tk0; - tk2->Ti = t_tk0; - - tk3->up_or_down = updown_tk1; - tk3->Ti = t_tk1; - - break; - - case 2: - tk4->up_or_down = updown_tk0; - tk4->Ti = t_tk0; - - tk5->up_or_down = updown_tk1; - tk5->Ti = t_tk1; - - break; - - default: break; - } - } -} - - - - -// #pragma CODE_SECTION(detect_region,".v_24pwm_run"); -int detect_region(_iq k, _iq teta) -{ - volatile _iq x,y; - volatile int reg=0; - - x = _IQmpy(k,_IQcos(teta)); - y = _IQmpy(k,_IQsin(teta)); - - if (y>=CONST_IQ_05) reg=4; - else if (y < (CONST_IQ_1 - _IQmpy(x,SQRT3))) reg = 1; - else if (y < (_IQmpy(x,SQRT3) - CONST_IQ_1)) reg = 2; - else reg = 3; - - return reg; -} - - - - -// #pragma CODE_SECTION(detect_sec,".v_24pwm_run"); -int detect_sec(_iq teta) -{ - volatile _iq sector; - volatile int sectorint; - - sector = _IQdiv(teta,CONST_IQ_PI3); - sectorint = (sector >> 24) + 1; - - if (sectorint > 6) sectorint-=6; - - return sectorint; -} - - -#define nSIN_t(k,t) _IQmpy(k,_IQsin(t)) - -#define nSIN_p3pt(k,t) _IQmpy(k,_IQsin(CONST_IQ_PI3+t)) - -#define nSIN_p3mt(k,t) _IQmpy(k,_IQsin(CONST_IQ_PI3-t)) - -#define nSIN_tmp3(k,t) _IQmpy(k,_IQsin(t-CONST_IQ_PI3)) - -//k - (Uzad) -//teta - -//region - -/* - * iq_tt0 - time of vectors op, oo, on - * iq_tt1 - time of vectors ap, an - * iq_tt2 - time of vectors bp, bn - * iq_tt3 - time of vector c - * iq_tt4 - time of vector a - * iq_tt5 - time of vector b - */ -// #pragma CODE_SECTION(calc_t_abc,".v_24pwm_run"); -void calc_t_abc(_iq k, _iq teta, int region, _iq *iq_tt0, _iq *iq_tt1, _iq *iq_tt2, _iq *iq_tt3, _iq *iq_tt4, _iq *iq_tt5) -{ - switch(region) - { - case 1 : - *iq_tt0 = CONST_IQ_05 - nSIN_p3pt(k,teta); - *iq_tt1 = nSIN_p3mt(k,teta); - *iq_tt2 = nSIN_t(k,teta); - *iq_tt3 = 0; - *iq_tt4 = 0; - *iq_tt5 = 0; - break; - - case 2 : - *iq_tt0 = 0; - *iq_tt1 = CONST_IQ_1 - nSIN_p3pt(k,teta); - *iq_tt2 = 0; - *iq_tt3 = nSIN_t(k,teta); - *iq_tt4 = nSIN_p3mt(k,teta) - CONST_IQ_05; - *iq_tt5 = 0; - break; - - case 3 : - *iq_tt0 = 0; - *iq_tt1 = CONST_IQ_05 - nSIN_t(k,teta); - *iq_tt2 = CONST_IQ_05 - nSIN_p3mt(k,teta); - *iq_tt3 = nSIN_p3pt(k,teta) - CONST_IQ_05; - *iq_tt4 = 0; - *iq_tt5 = 0; - break; - - case 4 : - *iq_tt0 = 0; - *iq_tt1 = 0; - *iq_tt2 = CONST_IQ_1 - nSIN_p3pt(k,teta); - *iq_tt3 = nSIN_p3mt(k,teta); - *iq_tt4 = 0; - *iq_tt5 = nSIN_t(k,teta) - CONST_IQ_05; - break; - - default : - *iq_tt0 = 0; - *iq_tt1 = 0; - *iq_tt2 = 0; - *iq_tt3 = 0; - *iq_tt4 = 0; - *iq_tt5 = 0; - break; - } - - return; -} - -//sector -//region -//iq_ttt0 - iq_ttt5 - times from calc_t_abs -//delta_t - -//number_sv - -//iqIa, iqIb, iqIc -// #pragma CODE_SECTION(calc_arr_tph, ".v_24pwm_run"); -void calc_arr_tph(int sector,int region, _iq iq_ttt0, _iq iq_ttt1, _iq iq_ttt2, _iq iq_ttt3, _iq iq_ttt4, - _iq iq_ttt5, _iq delta_t, unsigned int number_sv, - _iq iqIa, _iq iqIb, _iq iqIc) -{ - _iq iq_var1 = 0; - _iq iqIx, iqIy, iqIz; - _iq iq_alfa_1_p = CONST_IQ_05, iq_alfa_1_n = CONST_IQ_05, iq_alfa_2_n = CONST_IQ_05, iq_alfa_2_p = CONST_IQ_05; - _iq iq_alfa = 0; -// _iq iqIa, iqIb, iqIc; - _iq iq_mpy1 = 0; - _iq iq_mpy3 = 0; - _iq summ = 0; - - - switch (sector) - { - case 1: - iqIx = iqIc; - iqIy = iqIa; - iqIz = iqIb; - - break; - case 2: - - iqIx = iqIb; - iqIy = iqIa; - iqIz = iqIc; - - break; - case 3: - - iqIx = iqIb; - iqIy = iqIc; - iqIz = iqIa; - - break; - case 4: - - iqIx = iqIa; - iqIy = iqIc; - iqIz = iqIb; - - break; - case 5: - - iqIx = iqIa; - iqIy = iqIb; - iqIz = iqIc; - - break; - case 6: - - iqIx = iqIc; - iqIy = iqIb; - iqIz = iqIa; - - break; - default: - - iqIx = 0; - iqIy = 0; - iqIz = 0; - - break; - } - - if (region == 1) - { -// if (delta_t != 0) //разбаланс напряжений //отключено тестировать -// { -// iq_alfa = _IQsat((CONST_IQ_05 - _IQmpy(delta_t,IQ_KP_DELTA_T)),IQ_ALFA_SATURATION1,IQ_ALFA_SATURATION2); - - //if (delta_t < 0) - //{ - //iq_alfa = IQ_ALFA_SATURATION1; - //} - //else - //{ - //iq_alfa = IQ_ALFA_SATURATION2; - //} -// } -// else - { - iq_alfa = CONST_IQ_05; - } - } - else - { - iq_mpy1 = _IQmpy(_IQabs(iqIx),iq_ttt1)+_IQmpy(_IQabs(iqIy),iq_ttt2); - iq_mpy3 = _IQmpy(iqIz,iq_ttt3); - - summ = _IQdiv((iq_mpy3),(iq_mpy1)); - - //iq_alfa = _IQsat((_IQmpy(CONST_IQ_05,(CONST_IQ_1 + summ)) - _IQmpy(delta_t,IQ_KP_DELTA_T)),IQ_ALFA_SATURATION1,IQ_ALFA_SATURATION2); - iq_alfa = CONST_IQ_05; //test - } - - - if (iqIx >= 0) - { - iq_alfa_1_p = iq_alfa; - iq_alfa_1_n = CONST_IQ_1 - iq_alfa; - } - else - { - iq_alfa_1_p = CONST_IQ_1 - iq_alfa; - iq_alfa_1_n = iq_alfa; - } - - if (iqIy >= 0) - { - iq_alfa_2_p = CONST_IQ_1 - iq_alfa; - iq_alfa_2_n = iq_alfa; - } - else - { - iq_alfa_2_p = iq_alfa; - iq_alfa_2_n = CONST_IQ_1 - iq_alfa; - } - - - //if (number_sv == 2) - //{ - //logpar.log1 = (int16)(sector); - //logpar.log2 = (int16)(region); - //logpar.log3 = (int16)(_IQtoIQ15(iq_alfa)); - //logpar.log4 = (int16)(_IQtoIQ15(iq_alfa_1_p)); - //logpar.log5 = (int16)(_IQtoIQ15(iq_alfa_2_p)); - //logpar.log6 = (int16)(_IQtoIQ13(summ)); - //logpar.log3 = (int16)(_IQtoIQ14(iq_ttt0)); - //logpar.log4 = (int16)(_IQtoIQ14(iq_ttt1)); - //logpar.log5 = (int16)(_IQtoIQ14(iq_ttt2)); - //logpar.log6 = (int16)(_IQtoIQ14(iq_ttt3)); - //logpar.log7 = (int16)(_IQtoIQ14(iq_ttt4)); - //logpar.log8 = (int16)(_IQtoIQ14(iq_ttt5)); - //logpar.log10 = (int16)(_IQtoIQ15(delta_t1_struct.Up)); - //logpar.log11 = (int16)(_IQtoIQ15(delta_t1_struct.Ui)); - //logpar.log12 = (int16)(_IQtoIQ15(delta_t1_struct.Ud)); - //logpar.log13 = (int16)(_IQtoIQ15(iqIx)); - //logpar.log14 = (int16)(_IQtoIQ15(iqIy)); - //logpar.log15 = (int16)(_IQtoIQ15(iqIz)); - - //logpar.log12 = (int16)(_IQtoIQ15(_IQmpy(iq_alfa_2_p,iq_ttt2))); - //logpar.log13 = (int16)(_IQtoIQ15(_IQmpy(iq_alfa_2_n,iq_ttt2))); - //logpar.log14 = (int16)(_IQtoIQ15(delta_t)); - //} - //else - //logpar.log15 = (int16)(_IQtoIQ15(delta_t)); - -// if (region == 1) -// { -// if (f.Rele3 == 1) -// { -// iq_alfa_1_p = CONST_IQ_05; -// iq_alfa_2_p = CONST_IQ_05; -// iq_alfa_1_n = CONST_IQ_05; -// iq_alfa_2_n = CONST_IQ_05; -// } -// } -// else -// { -// if (f.Down50 == 1) -// { -// iq_alfa_1_p = CONST_IQ_05; -// iq_alfa_2_p = CONST_IQ_05; -// iq_alfa_1_n = CONST_IQ_05; -// iq_alfa_2_n = CONST_IQ_05; -// } -// } - - switch (region) - { - case 1: - iq_var1 = _IQdiv(iq_ttt0,CONST_IQ_3); - - ar_tph[0] = iq_var1; - ar_tph[1] = _IQmpy(iq_alfa_1_n,iq_ttt1); - ar_tph[2] = _IQmpy(iq_alfa_2_n,iq_ttt2); - ar_tph[3] = iq_var1; - ar_tph[4] = _IQmpy(iq_alfa_1_p,iq_ttt1); - ar_tph[5] = _IQmpy(iq_alfa_2_p,iq_ttt2); - ar_tph[6] = iq_var1; - break; - - case 2: - ar_tph[0] = _IQmpy(iq_alfa_1_n,iq_ttt1); - ar_tph[1] = iq_ttt4; - ar_tph[2] = iq_ttt3; - ar_tph[3] = _IQmpy(iq_alfa_1_p,iq_ttt1); - ar_tph[4] = 0; - ar_tph[5] = 0; - ar_tph[6] = 0; - break; - - case 3: - ar_tph[0] = _IQmpy(iq_alfa_1_n,iq_ttt1); - ar_tph[1] = _IQmpy(iq_alfa_2_n,iq_ttt2); - ar_tph[2] = iq_ttt3; - ar_tph[3] = _IQmpy(iq_alfa_1_p,iq_ttt1); - ar_tph[4] = _IQmpy(iq_alfa_2_p,iq_ttt2); - ar_tph[5] = 0; - ar_tph[6] = 0; - break; - - case 4: - ar_tph[0] = _IQmpy(iq_alfa_2_n,iq_ttt2); - ar_tph[1] = iq_ttt3; - ar_tph[2] = iq_ttt5; - ar_tph[3] = _IQmpy(iq_alfa_2_p,iq_ttt2); - ar_tph[4] = 0; - ar_tph[5] = 0; - ar_tph[6] = 0; - break; - - default : - break; - } - - -} - -/* - // Function is commented because of in project 222220 should not be large voltage diviation -// #pragma CODE_SECTION(calc_delta_t,".v_24pwm_run"); -_iq calc_delta_t(_iq delta_1, unsigned int number,int region) -{ - if(_IQabs(delta_1) > MAX_LEVEL_DELTA_T) - { - // Ошибка разбаланса ConvErrors.m2.bit.Razbalans |= 1; - return 0; - } - - if (number == 1) - { - delta_t1_struct.Fdb = delta_1; - delta_t1_struct.calc(&delta_t1_struct); - - if (_IQabs(delta_t1_struct.Out) <= INSENSITIVE_LEVEL_DELTA_T) return 0; - else return delta_t1_struct.Out; - } - else - { - delta_t2_struct.Fdb = delta_1; - delta_t2_struct.calc(&delta_t2_struct); - - if (_IQabs(delta_t2_struct.Out) <= INSENSITIVE_LEVEL_DELTA_T) return 0; - else return delta_t2_struct.Out; - } -} - -*/ -//#pragma CODE_SECTION(set_predel_dshim24,".fast_run2"); - -// #pragma CODE_SECTION(set_predel_dshim24_simple0,".v_24pwm_run"); -void set_predel_dshim24_simple0(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax) -{ - dmax++; //Надо задать значение больше, чем макс значение пилы, чтобы небыло пересечений - if (T->Ti < dmin) - { - if (T->Ti < dmin/2) - T->Ti = 0; - else - T->Ti = dmin; - - } else if (T->Ti >= (dmax - dmin)) { - T->Ti = (dmax - dmin); - } -} -// #pragma CODE_SECTION(set_predel_dshim24_simple1,".v_24pwm_run"); -void set_predel_dshim24_simple1(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax) -{ - dmax++; //Надо задать значение больше, чем макс значение пилы, чтобы небыло пересечений - if (T->Ti >= (dmax - dmin)) - { - if (T->Ti >= (dmax - dmin/2)) - T->Ti = dmax; - else - T->Ti = dmax-dmin; -// T->Ti = dmax; - } else if (T->Ti <= dmin) { - T->Ti = dmin; - } -} - - -// #pragma CODE_SECTION(set_predel_dshim24,".v_24pwm_run"); -void set_predel_dshim24(SVGEN_PWM24_TIME *T,int16 dmin,int16 dmax) -{ - //static unsigned int counter_pass = 0; - //static unsigned int summ = 0; - //int16 dshim24 = 0; - dmax++; //Надо задать значение больше, чем макс значение пилы, чтобы небыло пересечений - if (T->Ti < dmin) - { - T->impuls_lenght_max = 0; - T->counter_pass_max = 0; - - T->impuls_lenght_min = T->impuls_lenght_min + T->Ti; - T->counter_pass_min++; - - if (T->counter_pass_min <= 3) - { - if (T->impuls_lenght_min <= dmin) - { - T->Ti = 0; - } - else - { -// T->Ti = dmin; //T->impuls_lenght_min; -// T->impuls_lenght_min -= dmin;// = 0; - T->Ti = T->impuls_lenght_min; - T->impuls_lenght_min = 0; - T->counter_pass_min = 0; -// if (T->impuls_lenght_min < 0) { -// T->counter_pass_min = 0; -// T->impuls_lenght_min = 0; -// } else { -// T->counter_pass_min -= 1; -// } - } - } - else - { - T->counter_pass_min = 1; - T->impuls_lenght_min = T->Ti; - T->Ti = 0; - } - } - else - { - T->impuls_lenght_min = 0; - T->counter_pass_min = 0; - -// if (T->Ti > (dmax - dmin)) -// { -// dshim = dmax; -// } -// else -// { -// dshim = T->Ti; -// } - - if (T->Ti >= (dmax - dmin)) - { - T->impuls_lenght_max = T->impuls_lenght_max + (dmax - T->Ti - 1); - T->counter_pass_max++; - - if (T->counter_pass_max <= 3) - { - if (T->impuls_lenght_max <= dmin) - { - T->Ti = dmax; - } - else - { -// T->Ti = dmax - dmin; //T->impuls_lenght_max; -// T->impuls_lenght_max -= dmin;// = 0; - T->Ti = dmax - T->impuls_lenght_max; - T->impuls_lenght_max = 0; - T->counter_pass_max = 0; -// if (T->impuls_lenght_max < 0) { -// T->impuls_lenght_max = 0; -// T->counter_pass_max = 0; -// } else { -// T->counter_pass_max -= 1; -// } - } - } - else - { - T->counter_pass_max = 1; - T->impuls_lenght_max = dmax - T->Ti; - T->Ti = dmax; - } - } - else - { - T->counter_pass_max = 0; - T->impuls_lenght_max = 0; - } - } - - //return dshim24; -} - - - -void init_alpha_pwm24(int xFreq) -{ - xFreq = xFreq + 1; - - svgen_pwm24_1.number_svgen = 1; - svgen_pwm24_2.number_svgen = 2; - - //pidCur_Kp = _IQ(PID_KP_DELTA_KOMP_I); - //pidCur_Ki = _IQ(PID_KI_DELTA_KOMP_I); - -// svgen_pwm24_1.prev_level = V_PWM24_PREV_PWM_CLOSE; - svgen_pwm24_1.saw_direct.all = xpwm_time.saw_direct.all & 0x3f; - svgen_pwm24_1.Tclosed_saw_direct_0 = xpwm_time.Tclosed_saw_direct_0;// xpwm_time.Tclosed_high;//var_freq_pwm_xtics + 1; - svgen_pwm24_1.Tclosed_saw_direct_1 = xpwm_time.Tclosed_saw_direct_1; - svgen_pwm24_1.Tclosed_high = xpwm_time.Tclosed_high; - -// svgen_pwm24_2.prev_level = V_PWM24_PREV_PWM_CLOSE; - svgen_pwm24_2.saw_direct.all = (xpwm_time.saw_direct.all >> 6) & 0x3f; - svgen_pwm24_2.Tclosed_saw_direct_0 = xpwm_time.Tclosed_saw_direct_0;// xpwm_time.Tclosed_high;//var_freq_pwm_xtics + 1; - svgen_pwm24_2.Tclosed_saw_direct_1 = xpwm_time.Tclosed_saw_direct_1; - svgen_pwm24_2.Tclosed_high = xpwm_time.Tclosed_high; - - svgen_pwm24_1.FreqMax = _IQ(2.0*PI*F_STATOR_MAX/FREQ_PWM/2);//Допполнительное деление на 2, т.к. 2 раза заходит в прерывание за период шим - svgen_pwm24_2.FreqMax = _IQ(2.0*PI*F_STATOR_MAX/FREQ_PWM/2); - - svgen_pwm24_1.XilinxFreq = CONST_IQ_1/xFreq; - svgen_pwm24_2.XilinxFreq = CONST_IQ_1/xFreq; - - // 30 - svgen_pwm24_1.Alpha = 0; //winding_displacement; - svgen_pwm24_2.Alpha = -winding_displacement; - - svgen_pwm24_1.delta_t = 0; - svgen_pwm24_2.delta_t = 0; -} - -/* -void init_freq_array(void) -{ - unsigned int i = 0; - //unsigned int j = 0; - int var1 = 0; - - var1 = 32767 / (FREQ_PWM_MAX - FREQ_PWM_MIN); - - for (i = 0; i < COUNT_VAR_FREQ; i++) - { - //j = rand() / 1023; - //freq_array[i] = array_optim_freq[j]; - //do - freq_array[i] = FREQ_PWM_MIN + (rand() / var1); - //while ((freq_array[i] < 945) && (freq_array[i] > 930)); - } - - //freq_array[0] = 991; - //freq_array[1] = 1430; -} -*/ - - -//#pragma CODE_SECTION(calc_freq_pwm,".v_24pwm_run"); -//#pragma CODE_SECTION(calc_freq_pwm,".fast_run"); -/*void calc_freq_pwm() -{ - static int prev_freq_pwm = 0; - static float pwm_period = 0; - static float var0 = 0; - //static int line = 0; - //static int i = 0; - static unsigned int proc_ticks = 1; - int var1 = 0; - //static int i = 0; - - if ((f.flag_change_pwm_freq == 1) && (f.flag_random_freq == 1)) - { - if (proc_ticks >= 1) - { - proc_ticks = 0; - - - if (line == 0) - { - VAR_FREQ_PWM_HZ = VAR_FREQ_PWM_HZ + 1; - if (VAR_FREQ_PWM_HZ > FREQ_PWM_MAX) - { - VAR_FREQ_PWM_HZ = FREQ_PWM_MAX; - line = 1; - } - } - else - { - VAR_FREQ_PWM_HZ = VAR_FREQ_PWM_HZ - 1; - if (VAR_FREQ_PWM_HZ < FREQ_PWM) - { - VAR_FREQ_PWM_HZ = FREQ_PWM; - line = 0; - } - } - - - - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - //VAR_FREQ_PWM_HZ = freq_array[i]; - //i_led2_on_off(1); - - var1 = 32767 / (freq_pwm_max_hz - freq_pwm_min_hz); - VAR_FREQ_PWM_HZ = freq_pwm_min_hz + (rand() / var1); - - //i_led2_on_off(0); - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - if (VAR_FREQ_PWM_HZ > freq_pwm_max_hz) - { - VAR_FREQ_PWM_HZ = freq_pwm_max_hz; - } - else - { - if (VAR_FREQ_PWM_HZ < freq_pwm_min_hz) - { - VAR_FREQ_PWM_HZ = freq_pwm_min_hz; - } - } - //i++; - - //if (i >= COUNT_VAR_FREQ) - //{ - //i = 0; - //} - - } - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - //if (VAR_FREQ_PWM_HZ == FREQ_PWM_MIN) - //{ - //VAR_FREQ_PWM_HZ = FREQ_PWM_MAX; - //} - //else - //{ - //VAR_FREQ_PWM_HZ = FREQ_PWM_MIN; - //} - - //if (f.Rele1 == 1) - //{ - //if (i == 0) - //{ - //VAR_FREQ_PWM_HZ = 1192;; - //i = 1; - //} - //else - //{ - //VAR_FREQ_PWM_HZ = 792; - //} - //} - //else - //{ - //i = 0; - //VAR_FREQ_PWM_HZ = 1192; - //} - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - } - //else - //{ - //VAR_FREQ_PWM_HZ = FREQ_PWM; - //} - - - if (prev_freq_pwm != VAR_FREQ_PWM_HZ) - { - prev_freq_pwm = VAR_FREQ_PWM_HZ; - FREQ_MAX = _IQ(2.0*PI*F_STATOR_MAX/VAR_FREQ_PWM_HZ); - - var0 = (float)VAR_FREQ_PWM_HZ; - //pwm_period = ((float64)HSPCLK) / ((float64)VAR_FREQ_PWM_HZ); - - pwm_period = HSPCLK / var0; - - pwm_period = pwm_period / 2.0; - - FREQ_PWM_XTICS = ((int) pwm_period) >> 3; - - XILINX_FREQ = 16777216/(FREQ_PWM_XTICS + 1); - - FLAG_CHANGE_FREQ_PWM = 1; - } - - proc_ticks++; -} -*/ - -void change_freq_pwm(_iq xFreq) { - svgen_pwm24_1.FreqMax = _IQ(2.0*PI*F_STATOR_MAX/3750000 / xFreq / 2 /2);//Допполнительное деление на 2, т.к. 2 раза заходит в прерывание за период шим - svgen_pwm24_2.FreqMax = _IQ(2.0*PI*F_STATOR_MAX/ 3750000 / xFreq / 2 /2); - - xFreq += 1; - svgen_pwm24_1.XilinxFreq = CONST_IQ_1/xFreq; - svgen_pwm24_2.XilinxFreq = CONST_IQ_1/xFreq; -} - -// #pragma CODE_SECTION(test_calc_pwm24_dq,".v_24pwm_run"); -void test_calc_pwm24_dq(_iq U_zad1, _iq U_zad2,_iq teta) -{ - svgen_pwm24_1.Freq = 0; - svgen_pwm24_2.Freq = 0; - - svgen_pwm24_1.Gain = U_zad1; - svgen_pwm24_2.Gain = U_zad2; - - svgen_pwm24_1.Alpha = teta; - svgen_pwm24_2.Alpha = teta - winding_displacement; - - svgen_pwm24_1.delta_U = filter.iqU_1_fast - filter.iqU_2_fast; - svgen_pwm24_2.delta_U = filter.iqU_3_fast - filter.iqU_4_fast; - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - svgen_pwm24_1.delta_U = 0; - svgen_pwm24_2.delta_U = 0; - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - svgen_pwm24_1.Ia = analog.iqIa1_1; - svgen_pwm24_1.Ib = analog.iqIb1_1; - svgen_pwm24_1.Ic = analog.iqIc1_1; - - svgen_pwm24_2.Ia = analog.iqIa2_1; - svgen_pwm24_2.Ib = analog.iqIb2_1; - svgen_pwm24_2.Ic = analog.iqIc2_1; - - svgen_pwm24_1.calc_dq(&svgen_pwm24_1); - svgen_pwm24_2.calc_dq(&svgen_pwm24_2); - - - // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - set_predel_dshim24(&svgen_pwm24_1.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_1.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_1.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Ta_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Ta_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tb_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tb_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - set_predel_dshim24(&svgen_pwm24_2.Tc_0,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - set_predel_dshim24(&svgen_pwm24_2.Tc_1,VAR_PERIOD_MIN_XTICS,VAR_FREQ_PWM_XTICS); - - -} - - -// #pragma CODE_SECTION(svgen_pwm24_calc,".v_24pwm_run"); -void svgen_pwm24_calc_dq(SVGEN_PWM24 *vt) -{ - - if (vt->Alpha > CONST_IQ_2PI) - { - vt->Alpha -= CONST_IQ_2PI; - } - - if (vt->Alpha < 0) - { - vt->Alpha += CONST_IQ_2PI; - } - - - calc_time_one_tk(vt->Gain, vt->Alpha, vt->delta_U, vt->Ia, vt->Ib, vt->Ic, - vt->number_svgen, &vt->Ta_0, &vt->Ta_1,&vt->Tb_0, &vt->Tb_1,&vt->Tc_0, &vt->Tc_1); - - - vt->Ta_0.Ti = vt->Ta_0.Ti/vt->XilinxFreq; - vt->Ta_1.Ti = vt->Ta_1.Ti/vt->XilinxFreq; - - vt->Tb_0.Ti = vt->Tb_0.Ti/vt->XilinxFreq; - vt->Tb_1.Ti = vt->Tb_1.Ti/vt->XilinxFreq; - - vt->Tc_0.Ti = vt->Tc_0.Ti/vt->XilinxFreq; - vt->Tc_1.Ti = vt->Tc_1.Ti/vt->XilinxFreq; - -} - -void svgen_set_time_keys_closed(SVGEN_PWM24 *vt) -{ - vt->Ta_0.Ti = VAR_FREQ_PWM_XTICS + 1; - vt->Ta_1.Ti = 0; - - vt->Tb_0.Ti = VAR_FREQ_PWM_XTICS + 1; - vt->Tb_1.Ti = 0; - - vt->Tc_0.Ti = VAR_FREQ_PWM_XTICS + 1; - vt->Tc_1.Ti = 0; -} - -void svgen_set_time_middle_keys_open(SVGEN_PWM24 *vt) -{ - vt->Ta_0.Ti = 0; - vt->Ta_1.Ti = VAR_FREQ_PWM_XTICS + 1; - - vt->Tb_0.Ti = 0; - vt->Tb_1.Ti = VAR_FREQ_PWM_XTICS + 1; - - vt->Tc_0.Ti = 0; - vt->Tc_1.Ti = VAR_FREQ_PWM_XTICS + 1; -} diff --git a/Inu/Src2/main/v_pwm24.h b/Inu/Src2/main/v_pwm24.h deleted file mode 100644 index ff83ca4..0000000 --- a/Inu/Src2/main/v_pwm24.h +++ /dev/null @@ -1,190 +0,0 @@ -#ifndef _V_PWM24_H -#define _V_PWM24_H - -#ifdef __cplusplus - extern "C" { -#endif - -#include "IQmathLib.h" -// #include "DSP281x_Device.h" -#include "word_structurs.h" -#include "svgen_dq.h" - -//#define COUNT_VAR_FREQ 400 - -//#define IQ_KP_DELTA_T 134217728//0.004 -//#define IQ_KP_DELTA_COMP_I 134217728//0.004 - -//#define PID_KP_DELTA_T 0.5//1//20//2//0.001//11.18 //0.036 //0.018 //0.18 //0.095 // PID Kp -//#define PID_KI_DELTA_T 0.000005//0.01 //0.08 // 0.008 // PID Ki -//#define PID_KD_DELTA_T 2//5//0.01 //0.08 // 0.008 // PID Ki -//#define PID_KC_DELTA_T 0.005 //0.09 // PID Kc - -//#define PID_KP_DELTA_KOMP_I 1//0.12//0.06//5//10 -//#define PID_KI_DELTA_KOMP_I 0.005//0//0.005//0.01 -//#define PID_KC_DELTA_KOMP_I 0.005//0//0.005//0.01 -//#define PID_KD_DELTA_KOMP_I 0//0//0.005//0.01 -//#define PID_KD_DELTA_T 0.0000 //*100 // PID Kd - - - -//#define DELTA_T_MAX 1258291//15099494//0.9//8388608//0.5//13421772//0.8 //8388608// 0.5//13421772 // 0.8 -//#define DELTA_T_MIN -1258291//-15099494//0.9//-8388608//-0.5//-13421772//0.8 //-8388608// -0.5//-13421772 // -0.8 - -//#define DELTA_KOMP_I_MAX 1258291//6//1677721//0.1//3355443//0.2//1677721//200 A//4194304// 500 A -//#define DELTA_KOMP_I_MIN -1258291//-6//-1677721//-0.1//-3355443//-0.2//-1677721//-200 A//-4194304// -500 A - - -//#define INSENSITIVE_LEVEL_DELTA_T 83886 //10 V//167772// 20V //335544//40 V//83886 //10 V//335544//40 V//58720//7V//167772// 20V //83886 //10 V -//#define MAX_LEVEL_DELTA_T 1258291//150V//1677721 //200v//2516582//300 V//4194304//500 V//2516582 // 838860 //100 V - - -typedef struct { _iq Ti; // Output: reference phase-a switching function (pu) - int up_or_down; // Output: reference phase-b switching function (pu) - int impuls_lenght_max; - int impuls_lenght_min; - int counter_pass_max; - int counter_pass_min; - } SVGEN_PWM24_TIME; - - -typedef struct { - _iq Gain; // Input: reference gain voltage (pu) - //_iq Offset; // Input: reference offset voltage (pu) - _iq Freq; // Input: reference frequency (pu) - _iq FreqMax; // Parameter: Maximum step angle = 6*base_freq*T (pu) - _iq Alpha; // History: Sector angle (pu) - - _iq delta_U; - _iq delta_t; - int XilinxFreq; // Xilinx freq in TIC - - unsigned int pwm_minimal_impuls_zero_minus; - unsigned int pwm_minimal_impuls_zero_plus; - - WORD_UINT2BITS_STRUCT saw_direct; - - int prev_level; // предыдущее состояние ШИМа, для перехода из middle или close в рабочее - unsigned int Tclosed_high; - unsigned int Tclosed_saw_direct_0; - unsigned int Tclosed_saw_direct_1; - - _iq Ia; - _iq Ib; - _iq Ic; - unsigned int number_svgen; - SVGEN_PWM24_TIME Ta_0; // Output: reference phase-a switching function (pu) - SVGEN_PWM24_TIME Ta_1; // Output: reference phase-a switching function (pu) - SVGEN_PWM24_TIME Tb_0; // Output: reference phase-b switching function (pu) - SVGEN_PWM24_TIME Tb_1; // Output: reference phase-b switching function (pu) - SVGEN_PWM24_TIME Tc_0; // Output: reference phase-c switching function (pu) - SVGEN_PWM24_TIME Tc_1; // Output: reference phase-c switching function (pu) - void (*calc)(); // Pointer to calculation function - void (*calc_dq)(); // Pointer to calculation function which don`t calculate angle from freq -} SVGEN_PWM24; - -typedef SVGEN_PWM24 *SVGEN_PWM24_handle; - - -#define SVGEN_PWM24_TIME_DEFAULTS { 0,0,0,0 } - - -#define SVGEN_PWM24_DEFAULTS { 0,0,0,0,0,0,0,0,0, \ - {0}, 0,0,0,0,0,0,0,0,\ - SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS, \ - SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS, \ - (void (*)(unsigned int))svgen_pwm24_calc, (void (*)(unsigned int))svgen_pwm24_calc_dq } - -// extern int ar_sa_a[3][4][7]; - -extern SVGEN_PWM24 svgen_pwm24_1; -extern SVGEN_PWM24 svgen_pwm24_2; - -extern SVGENDQ svgen_dq_1; -extern SVGENDQ svgen_dq_2; - -// extern _iq pidCur_Kp; -// extern _iq pidCur_Ki; - -// extern _iq iq_alfa_coef; - -// extern _iq iq_koef_mod_korrect_1; -// extern _iq iq_koef_mod_korrect_2; - -//extern int freq_array[COUNT_VAR_FREQ]; - -void svgen_pwm24_calc(SVGEN_PWM24 *vt); -void svgen_pwm24_calc_dq(SVGEN_PWM24 *vt); - -void init_alpha_pwm24(int xFreq); -void test_calc_pwm24(_iq uz1, _iq uz2, _iq fz1/*, _iq fz2, int revers*/); -void calc_arr_tph(int sector,int region, _iq iq_ttt0, _iq iq_ttt1, - _iq iq_ttt2, _iq iq_ttt3, _iq iq_ttt4, _iq iq_ttt5, _iq delta_t, unsigned int number_sv, - _iq iqIa, _iq iqIb, _iq iqIc); -_iq calc_delta_t(_iq delta_1, unsigned int number,int region); - -//void change_freq_pwm(_iq FreqMax, int freq_pwm_xtics, _iq XilinxFreq); -void change_freq_pwm(_iq freq_pwm_xtics); - -//void calc_freq_pwm(); - -void calc_time_one_tk(_iq gain, _iq teta, _iq delta_U, - _iq Ia, _iq Ib, _iq Ic, - unsigned int number, - SVGEN_PWM24_TIME *tk0, - SVGEN_PWM24_TIME *tk1, - SVGEN_PWM24_TIME *tk2, - SVGEN_PWM24_TIME *tk3, - SVGEN_PWM24_TIME *tk4, - SVGEN_PWM24_TIME *tk5); - -void test_calc_pwm24_dq(_iq U_zad1, _iq U_zad2,_iq teta); - -void svgen_set_time_keys_closed(SVGEN_PWM24 *vt); -void svgen_set_time_middle_keys_open(SVGEN_PWM24 *vt); - - - -void InitVariablesSvgen(unsigned int freq); -//void init_alpha(void); -_iq correct_balance_uzpt_pwm24(_iq Tinput, _iq Kplus); -void recalc_time_pwm_minimal_2_xilinx_pwm24_l(SVGEN_PWM24 *pwm24, - _iq *T0, _iq *T1, - _iq timpuls_corr ); -void test_calc_simple_dq_pwm24(_iq uz1, _iq uz2, _iq fz1, _iq fz2, _iq Uzad_max); -void test_calc_dq_pwm24(_iq Ud, _iq Uq, _iq Ud2, _iq Uq2, _iq tetta,_iq Uzad_max); -//void test_calc_simple_uf_pwm24(_iq uz1, _iq uz2, _iq fz1, _iq fz2,_iq Uzad_max); - -//void init_freq_array(void); - -typedef union { - unsigned int all; - struct { - unsigned int k0; - unsigned int k1; - unsigned int k2; - unsigned int k3; - unsigned int k4; - unsigned int k5; - unsigned int k6; - unsigned int k7; - unsigned int k8; - unsigned int k9; - unsigned int k10; - unsigned int k11; - unsigned int k12; - unsigned int k13; - unsigned int k14; - unsigned int k15; - }bit; -} UP_OR_DOWN; - -extern UP_OR_DOWN up_down; -extern _iq winding_displacement; - - -#ifdef __cplusplus - } -#endif - -#endif /* _V_PWM24_H */ diff --git a/Inu/Src2/551/main/v_pwm24_v2.c b/Inu/Src2/main/v_pwm24_v2.c similarity index 100% rename from Inu/Src2/551/main/v_pwm24_v2.c rename to Inu/Src2/main/v_pwm24_v2.c diff --git a/Inu/Src2/551/main/v_pwm24_v2.h b/Inu/Src2/main/v_pwm24_v2.h similarity index 98% rename from Inu/Src2/551/main/v_pwm24_v2.h rename to Inu/Src2/main/v_pwm24_v2.h index e0e1baa..fab0949 100644 --- a/Inu/Src2/551/main/v_pwm24_v2.h +++ b/Inu/Src2/main/v_pwm24_v2.h @@ -54,7 +54,7 @@ typedef struct { // _iq Gain; // Input: reference gain voltage (pu) // _iq delta_t; //int16 Periodmax; //int16 PeriodMin; - unsigned int XilinxFreq; // Xilinx freq in TIC + int XilinxFreq; // Xilinx freq in TIC unsigned int pwm_minimal_impuls_zero_plus; unsigned int pwm_minimal_impuls_zero; diff --git a/Inu/Src2/551/main/v_rotor.c b/Inu/Src2/main/v_rotor.c similarity index 96% rename from Inu/Src2/551/main/v_rotor.c rename to Inu/Src2/main/v_rotor.c index 1da2a2f..0fe887c 100644 --- a/Inu/Src2/551/main/v_rotor.c +++ b/Inu/Src2/main/v_rotor.c @@ -1,1095 +1,1101 @@ -#include "DSP281x_Examples.h" // DSP281x Examples Include File -#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File -#include "DSP281x_Device.h" // DSP281x Headerfile Include File -#include "IQmathLib.h" - -#include -#include - -#include "filter_v1.h" -#include "xp_cds_in.h" -#include "xp_inc_sensor.h" -#include "xp_project.h" -#include "params.h" -#include "pwm_test_lines.h" -#include "params_norma.h" -#include "mathlib.h" #include "params_alg.h" - - -#pragma DATA_SECTION(WRotor,".fast_vars"); -WRotorValues WRotor = WRotorValues_DEFAULTS; - -#if (SENSOR_ALG==SENSOR_ALG_23550) - -#pragma DATA_SECTION(WRotorPBus,".slow_vars"); -WRotorValuesAngle WRotorPBus = WRotorValuesAngle_DEFAULTS; - -#pragma DATA_SECTION(rotor_error_update_count,".fast_vars"); -unsigned int rotor_error_update_count = 0; - - -#define SIZE_BUF_SENSOR_LOGS 32 -#pragma DATA_SECTION(sensor_1_zero,".slow_vars"); -unsigned int sensor_1_zero[6+4+8][SIZE_BUF_SENSOR_LOGS], count_sensor_1_zero=0; - -#endif - -_iq koefW = _IQ(0.05); //0.05 -_iq koefW2 = _IQ(0.01); //0.05 -_iq koefW3 = _IQ(0.002); //0.05 - - - - - - - -#if (SENSOR_ALG==SENSOR_ALG_23550) -/////////////////////////////////////////////////////////////// -void rotorInit(void) -{ - WRotorPBus.ModeAutoDiscret = 1; -} - - - -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -#define MAX_COUNT_OVERFULL_DISCRET 2250 -#define MAX_DIRECTION 4000 -#define MAX_DIRECTION_2 2000 -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -void RotorDirectionFilter(int RotorDirectionIn, int *RotorDirectionOut, int *RotorDirectionOut2, int *count_direction) -{ - -// static int count_direction = 0; -// static int count_direction_minus = 0; - - - if (RotorDirectionIn==0) - { - if (*count_direction>0) (*count_direction)--; - if (*count_direction<0) (*count_direction)++; -// if (count_direction_minus>0) count_direction_minus--; - } - else - if (RotorDirectionIn>0) - { - if (*count_direction0) count_direction_minus--; - } - else - { - if (*count_direction>-MAX_DIRECTION) (*count_direction)--; -// if (count_direction_plus>0) count_direction_plus--; - } - - - if (RotorDirectionIn==0) - *RotorDirectionOut = 0; - else - if (RotorDirectionIn>0) - *RotorDirectionOut = 1; - else - *RotorDirectionOut = -1; - - - if (*count_direction>MAX_DIRECTION_2) - *RotorDirectionOut2 = 1; - else - if (*count_direction<-MAX_DIRECTION_2) - *RotorDirectionOut2 = -1; - else - *RotorDirectionOut2 = 0; - - - -} -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -#define LEVEL_VALUE_SENSOR_OVERFULL 65535 -#define MAX_COUNT_ERROR_ANALISATOR_SENSOR_PBUS 4000 -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(AnalisatorRotorSensorPBus,".fast_run"); -int AnalisatorRotorSensorPBus(_iq d1, _iq d2, unsigned int *count_overfull_discret, unsigned int *count_zero_discret, _iq *prev_iqTimeRotor, - unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, - int modeS1, int modeS2, - int valid_sensor_direct, int valid_sensor_90, - unsigned int *error_count ) -{ - int flag_not_ready_rotor, flag_overfull_rotor; - _iq iqTimeRotor; - // discret0 = 2 mks -// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - // discret1 = 20 ns -// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - -// _iq iqWRotorSumm;//,iqWRotorCalc; - - static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. - static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. - static unsigned int discret; - - - if (valid_sensor_direct == 0) - d1 = 0; - if (valid_sensor_90 == 0) - d2 = 0; - - -// тут что-то пошло не так, была смена дискретизации по обоим каналам. - if (valid_sensor_direct == 0 && valid_sensor_90 == 0) - { - if (*error_count>1; - - - -// max OVERFULL - if (flag_overfull_rotor) - { - if (*count_overfull_discret0) - (*count_overfull_discret)--; - } - -// zero? - if (flag_not_ready_rotor) - { - if (*count_zero_discret0) - (*count_zero_discret)--; - } - -// real zero? - if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) - { - // ноль был слишком долго, значит точно ноль! - iqWRotorCalc = 0; - *prev_iqTimeRotor = 0; - iqTimeRotor = 0; - } - else - { - // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor - if (iqTimeRotor==0) - iqTimeRotor = *prev_iqTimeRotor; - } - *prev_iqTimeRotor = iqTimeRotor; - - - -// выбор нужного диапазона - if (WRotorPBus.ModeAutoDiscret==1) - { - if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) || (iqTimeRotor==0) ) - { - // тут или переполнение произошло или вдруг остановились, обороты=0 - // тогда включаем discret_out = 0 - if (discret_in == 1) // или тут надо испльзовать discret? - { - // discret был =1, переключаем на 0. - *discret_out = 0; - *count_overfull_discret = 0; // дали еще один шанс! - } - - } - else - { - // текущ. уровень discret==0 тогда... - if (discret==0 && iqTimeRotortime_level_discret_1to0 && iqTimeRotor!=65535) - *discret_out = 0; - } - } - - if (WRotorPBus.ModeAutoDiscret==2) - { - *discret_out = 0; - } - - if (WRotorPBus.ModeAutoDiscret==3) - { - *discret_out = 1; - } - - if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) ) - { - // тут уже точно в 0, т.к. слишком медленно идут импульсы! - *prev_iqTimeRotor = iqTimeRotor = 0; - } - - - - - if ((iqTimeRotor != 0)) // && (WRotorPBus.iqTimeRotor<65535) - { - if (discret==0) - *iqWRotorCalcBeforeRegul = KoefNorm_discret0 / iqTimeRotor; - if (discret==1) - *iqWRotorCalcBeforeRegul = KoefNorm_discret1 / iqTimeRotor; - - *iqWRotorCalc = exp_regul_iq(koefW, *iqWRotorCalc, *iqWRotorCalcBeforeRegul); - } - else - { - *iqWRotorCalc = 0; - *iqWRotorCalcBeforeRegul = 0; - } - - -// if (*iqWRotorCalc == 0) -// *RotorDirection = 0; - - - return 0; - -} -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// - - -#pragma CODE_SECTION(RotorMeasurePBus,".fast_run"); -void RotorMeasurePBus(void) -{ - // discret0 = 2 mks -// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - // discret1 = 20 ns -// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - - static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. - static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. - - static long long KoefNorm_angle = 16384LL; //2^24/1024 -// volatile float MyVar0 = 0; - - unsigned int MyVar3 = 0; -// int direction1 = 0, direction2 = 0; - volatile unsigned int discret; - - static unsigned int discret_out1, discret_out2; - - static int count_full_oborots = 0; - static unsigned int count_overfull_discret1 = 0; - static unsigned int count_zero_discret1 = 0; - static unsigned int count_overfull_discret2 = 0; - static unsigned int count_zero_discret2 = 0; - - static unsigned int count_discret_to_1 = 0; - static unsigned int count_discret_to_0 = 0; - - static unsigned int c_error_pbus_1 = 0; - static unsigned int c_error_pbus_2 = 0; - - - static _iq prev_iqTimeRotor1 = 0, prev_iqTimeRotor2 = 0; - - _iq iqWRotorSumm = 0; - - int flag_not_ready_rotor1, flag_overfull_rotor1; - int flag_not_ready_rotor2, flag_overfull_rotor2; - - //i_led1_on_off(1); - - - - flag_not_ready_rotor1 = 0; - flag_overfull_rotor1 = 0; - flag_not_ready_rotor2 = 0; - flag_overfull_rotor2 = 0; - - - - discret = project.cds_in[0].read.sbus.enabled_channels.bit.discret; - if (project.cds_in[0].read.sbus.enabled_channels.bit.discret != project.cds_in[0].write.sbus.enabled_channels.bit.discret) - discret = 2; - - if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) - { - sensor_1_zero[0][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S1; - sensor_1_zero[1][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1; - sensor_1_zero[2][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1; - sensor_1_zero[3][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S2; - sensor_1_zero[4][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2; - sensor_1_zero[5][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2; - } - sensor_1_zero[6][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt; - sensor_1_zero[7][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt90; - sensor_1_zero[8][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt; - sensor_1_zero[9][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt90; - - sensor_1_zero[10][count_sensor_1_zero] = inc_sensor.data.Time1; - sensor_1_zero[11][count_sensor_1_zero] = inc_sensor.data.Impulses1; - sensor_1_zero[12][count_sensor_1_zero] = inc_sensor.data.CountZero1; - sensor_1_zero[13][count_sensor_1_zero] = inc_sensor.data.CountOne1; - - sensor_1_zero[14][count_sensor_1_zero] = inc_sensor.data.Time2; - sensor_1_zero[15][count_sensor_1_zero] = inc_sensor.data.Impulses2; - sensor_1_zero[16][count_sensor_1_zero] = inc_sensor.data.CountZero2; - sensor_1_zero[17][count_sensor_1_zero] = inc_sensor.data.CountOne2; - - count_sensor_1_zero++; - if (count_sensor_1_zero>=SIZE_BUF_SENSOR_LOGS) - { - count_sensor_1_zero = 0; - count_full_oborots++; - if (count_full_oborots>3) - count_full_oborots = 0; - } -/* - if (count_sensor_1_zero==904) - { - discret = 3; - } -*/ - -#if (ENABLE_ROTOR_SENSOR_ZERO_SIGNAL==1) - if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) - { - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) - WRotorPBus.iqWRotorRawAngle1F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1-32768; - WRotorPBus.iqWRotorRawAngle1R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1-32768; - WRotorPBus.iqAngle1F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1F; - WRotorPBus.iqAngle1R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1R; -#else - WRotorPBus.iqWRotorRawAngle1F = 0; - WRotorPBus.iqWRotorRawAngle1R = 0; - WRotorPBus.iqAngle1F = 0; - WRotorPBus.iqAngle1R = 0; -#endif - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) - WRotorPBus.iqWRotorRawAngle2F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2-32768; - WRotorPBus.iqWRotorRawAngle2R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2-32768; - WRotorPBus.iqAngle2F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2F; - WRotorPBus.iqAngle2R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2R; -#else - WRotorPBus.iqWRotorRawAngle2F = 0; - WRotorPBus.iqWRotorRawAngle2R = 0; - WRotorPBus.iqAngle2F = 0; - WRotorPBus.iqAngle2R = 0; -#endif - } - else - { - WRotorPBus.iqWRotorRawAngle1F = 0; - WRotorPBus.iqWRotorRawAngle1R = 0; - WRotorPBus.iqAngle1F = 0; - WRotorPBus.iqAngle1R = 0; - - WRotorPBus.iqWRotorRawAngle2F = 0; - WRotorPBus.iqWRotorRawAngle2R = 0; - WRotorPBus.iqAngle2F = 0; - WRotorPBus.iqAngle2R = 0; - - } -#endif - - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) - //************************************************************************************************** - MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw0 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw0 = 0; - } - - MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt90; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw1 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw1 = 0; - } -#else - WRotorPBus.iqWRotorRaw0 = 0; - WRotorPBus.iqWRotorRaw1 = 0; -#endif - - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) - //*************************************************************************************************** - MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw2 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw2 = 0; - } - - MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt90; - - if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - WRotorPBus.iqWRotorRaw3 = MyVar3; - } - else - { - WRotorPBus.iqWRotorRaw3 = 0; - } -#else - WRotorPBus.iqWRotorRaw2 = 0; - WRotorPBus.iqWRotorRaw3 = 0; -#endif - - -#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) -// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90 ) - AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw0, WRotorPBus.iqWRotorRaw1, &count_overfull_discret1, &count_zero_discret1, - &prev_iqTimeRotor1, &discret_out1, project.cds_in[0].read.sbus.enabled_channels.bit.discret, - &WRotorPBus.iqWRotorCalcBeforeRegul1, &WRotorPBus.iqWRotorCalc1, - project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_90, - project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90, - &c_error_pbus_1 ); -#endif - -#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) -// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90 ) - AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw2, WRotorPBus.iqWRotorRaw3, &count_overfull_discret2, &count_zero_discret2, - &prev_iqTimeRotor2, &discret_out2, project.cds_in[0].read.sbus.enabled_channels.bit.discret, - &WRotorPBus.iqWRotorCalcBeforeRegul2, &WRotorPBus.iqWRotorCalc2, - project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_90, - project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90, - &c_error_pbus_2); -#endif - - - // RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow); - - - - if (discret_out1==1 || discret_out2==1) - { - project.cds_in[0].write.sbus.enabled_channels.bit.discret = 1; - count_discret_to_1++; - } - else - { - project.cds_in[0].write.sbus.enabled_channels.bit.discret = 0; - count_discret_to_0++; - } - - -} - - - -#define MAX_COUNT_OVERFULL_DISCRET_2 150 -#pragma CODE_SECTION(RotorMeasure,".fast_run"); -void RotorMeasure(void) -{ - - // 600 Khz clock on every edge -// static long long KoefNorm = 53635601LL;//((600 000/6256/NORMA_WROTOR/2) * ((long)2 << 24)); //15 - NormaWRotor 782*8 = 6256 -// static long long KoefNormMS = 491520000LL;//((600 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 -// static long long KoefNormNS = 49152000000LL;//((60 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormMS = 122880000LL;//((600 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormNS = 12288000000LL;//((60 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 - static long long KoefNormImpulses = 838860800000000LL;// (2^24 * 1000000000 / (Impulses(ns)) / NORMA_WROTOR - - static _iq max_value_rotor = _IQ(500.0/60.0/NORMA_FROTOR); - static _iq wrotor_add_ramp = _IQ(0.001/NORMA_FROTOR); - -// volatile float MyVar0 = 0; -// volatile unsigned int MyVar1 = 0; -// volatile unsigned int MyVar2 = 0; - unsigned int MyVar3; - - - inc_sensor.read_sensors(&inc_sensor); - - // flag_not_ready_rotor = 0; - -//************************************************************************************************** -// sensor 1 - - if (inc_sensor.use_sensor1) - { - MyVar3 = inc_sensor.data.CountOne1; -// MyVar3 = (unsigned long) rotation_sensor.in_plane.out.CountOne1; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_21_ON; -#endif - - WRotor.iqWRotorRaw0 = MyVar3; - } - else - { - -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_21_OFF; -#endif - - WRotor.iqWRotorRaw0 = 0; - } - MyVar3 = inc_sensor.data.CountZero1; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_22_ON; -#endif - WRotor.iqWRotorRaw1 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_22_OFF; -#endif - WRotor.iqWRotorRaw1 = 0; - } - } - else - { - WRotor.iqWRotorRaw0 = 0; - WRotor.iqWRotorRaw1 = 0; - } - //logpar.uns_log0 = (Uint16)(my_var1); - //logpar.uns_log1 = (Uint16)(my_var2); - - // sensor 2 - if (inc_sensor.use_sensor2) - { - MyVar3 = inc_sensor.data.CountOne2; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_18_ON; -#endif - WRotor.iqWRotorRaw2 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_18_OFF; -#endif - WRotor.iqWRotorRaw2 = 0; - } - - MyVar3 = inc_sensor.data.CountZero2; - - if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) - && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_23_ON; -#endif - WRotor.iqWRotorRaw3 = MyVar3; - } - else - { -#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) - PWM_LINES_TK_23_OFF; -#endif - WRotor.iqWRotorRaw3 = 0; - } - } - else - { - WRotor.iqWRotorRaw2 = 0; - WRotor.iqWRotorRaw3 = 0; - } - -// if (WRotor.iqWRotorRaw0==0 && WRotor.iqWRotorRaw1==0 && WRotor.iqWRotorRaw2==0 && WRotor.iqWRotorRaw3==0) -// flag_not_ready_rotor = 1; - - if (WRotor.iqWRotorRaw0==0) - { - if (WRotor.count_zero_discret0==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0 = 0; - } - else - { - WRotor.iqWRotorRaw0 = WRotor.prev_iqWRotorRaw0; - WRotor.count_zero_discret0++; - } - } - else - { - WRotor.count_zero_discret0 = 0; - WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0; - } - - if (WRotor.iqWRotorRaw1==0) - { - if (WRotor.count_zero_discret1==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1 = 0; - } - else - { - WRotor.iqWRotorRaw1 = WRotor.prev_iqWRotorRaw1; - WRotor.count_zero_discret1++; - } - } - else - { - WRotor.count_zero_discret1 = 0; - WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1; - } - - if (WRotor.iqWRotorRaw2==0) - { - if (WRotor.count_zero_discret2==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2 = 0; - } - else - { - WRotor.iqWRotorRaw2 = WRotor.prev_iqWRotorRaw2; - WRotor.count_zero_discret2++; - } - } - else - { - WRotor.count_zero_discret2 = 0; - WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2; - } - - if (WRotor.iqWRotorRaw3==0) - { - if (WRotor.count_zero_discret3==MAX_COUNT_OVERFULL_DISCRET_2) - { - WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3 = 0; - } - else - { - WRotor.iqWRotorRaw3 = WRotor.prev_iqWRotorRaw3; - WRotor.count_zero_discret3++; - } - } - else - { - WRotor.count_zero_discret3 = 0; - WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3; - } - - - WRotor.iqTimeSensor1 = WRotor.iqWRotorRaw0 + WRotor.iqWRotorRaw1; - WRotor.iqTimeSensor2 = WRotor.iqWRotorRaw2 + WRotor.iqWRotorRaw3; - - // -// // zero? -// if (flag_not_ready_rotor) -// { -// if (*count_zero_discret0) -// (*count_zero_discret)--; -// } -// -// // real zero? -// if (count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) -// { -// // ноль был слишком долго, значит точно ноль! -// WRotor.iqTimeSensor1 = 0; -// WRotor.prev_iqTimeSensor1 = 0; -// } -// else -// { -// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor -// if (WRotor.iqTimeSensor1==0) -// WRotor.iqTimeSensor1 = WRotor.prev_iqTimeSensor1; -// } -// WRotor.prev_iqTimeSensor1 = WRotor.iqTimeSensor1; -// -// -// // max OVERFULL -// if (flag_overfull_rotor) -// { -// if (*count_overfull_discret0) -// (*count_overfull_discret)--; -// } -// -// // zero? -// if (flag_not_ready_rotor) -// { -// if (*count_zero_discret0) -// (*count_zero_discret)--; -// } -// -// // real zero? -// if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) -// { -// // ноль был слишком долго, значит точно ноль! -// iqWRotorCalc = 0; -// *prev_iqTimeRotor = 0; -// iqTimeRotor = 0; -// } -// else -// { -// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor -// if (iqTimeRotor==0) -// iqTimeRotor = *prev_iqTimeRotor; -// } -// *prev_iqTimeRotor = iqTimeRotor; -// -// -// - -/// - if (WRotor.iqTimeSensor1 != 0 && inc_sensor.use_sensor1) - { - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==0) - WRotor.iqWRotorCalcBeforeRegul1 = KoefNormMS / WRotor.iqTimeSensor1; - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==1) - WRotor.iqWRotorCalcBeforeRegul1 = KoefNormNS / WRotor.iqTimeSensor1; - - if (WRotor.iqWRotorCalcBeforeRegul1 > max_value_rotor) - { - WRotor.iqWRotorCalc1 = 0; - WRotor.iqWRotorCalcBeforeRegul1 = 0; - } - else - WRotor.iqWRotorCalc1 = exp_regul_iq(koefW, WRotor.iqWRotorCalc1, WRotor.iqWRotorCalcBeforeRegul1); - - ///// - if (WRotor.iqWRotorCalc1) - { - if (WRotor.iqPrevWRotorCalc1 != WRotor.iqWRotorCalc1) - { - WRotor.iqWRotorCalc1Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc1Ramp, WRotor.iqWRotorCalc1); - WRotor.iqPrevWRotorCalc1 = WRotor.iqWRotorCalc1; - } - } - else - { - WRotor.iqPrevWRotorCalc1 = 0; - WRotor.iqWRotorCalc1Ramp = 0; - } - //// - } - else - { - WRotor.iqWRotorCalc1 = 0; - WRotor.iqWRotorCalcBeforeRegul1 = 0; - } -/// - if (WRotor.iqTimeSensor2 != 0 && inc_sensor.use_sensor2) - { - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==0) - WRotor.iqWRotorCalcBeforeRegul2 = KoefNormMS / WRotor.iqTimeSensor2; - if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==1) - WRotor.iqWRotorCalcBeforeRegul2 = KoefNormNS / WRotor.iqTimeSensor2; - - if (WRotor.iqWRotorCalcBeforeRegul2 > max_value_rotor) - { - WRotor.iqWRotorCalc2 = 0; - WRotor.iqWRotorCalcBeforeRegul2 = 0; - } - else - WRotor.iqWRotorCalc2 = exp_regul_iq(koefW, WRotor.iqWRotorCalc2, WRotor.iqWRotorCalcBeforeRegul2); - - - - ///// - if (WRotor.iqWRotorCalc2) - { - if (WRotor.iqPrevWRotorCalc2 != WRotor.iqWRotorCalc2) - { - WRotor.iqWRotorCalc2Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc2Ramp, WRotor.iqWRotorCalc2); - WRotor.iqPrevWRotorCalc2 = WRotor.iqWRotorCalc2; - } - } - else - { - WRotor.iqPrevWRotorCalc2 = 0; - WRotor.iqWRotorCalc2Ramp = 0; - } - //// - } - else - { - WRotor.iqWRotorCalc2 = 0; - WRotor.iqWRotorCalcBeforeRegul2 = 0; - } -/// - if (inc_sensor.data.TimeCalcFromImpulses1 && inc_sensor.use_sensor1) - WRotor.iqWRotorImpulsesBeforeRegul1 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses1 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); - else - WRotor.iqWRotorImpulsesBeforeRegul1 = 0; - - WRotor.iqWRotorImpulses1 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses1, WRotor.iqWRotorImpulsesBeforeRegul1); - - if (inc_sensor.data.TimeCalcFromImpulses2 && inc_sensor.use_sensor2) - WRotor.iqWRotorImpulsesBeforeRegul2 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses2 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); - else - WRotor.iqWRotorImpulsesBeforeRegul2 = 0; - - WRotor.iqWRotorImpulses2 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses2, WRotor.iqWRotorImpulsesBeforeRegul2); - - - // WRotor.iqWRotorCalcBeforeRegul = _IQdiv(WRotor.iqWRotorCalcBeforeRegul,IQ_CONST_3); -} -#define LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS 50 // Oborot -void select_values_wrotor(void) -{ - static _iq level_switch_to_get_impulses_hz = _IQ(LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS/60.0/NORMA_FROTOR); - static unsigned int prev_RotorDirectionInstant = 0; - static unsigned int status_RotorRotation = 0; // есть вращение? - static _iq wrotor_add = _IQ(0.002/NORMA_FROTOR); - - - - - if (WRotor.iqWRotorCalc1>level_switch_to_get_impulses_hz - || WRotor.iqWRotorCalc2>level_switch_to_get_impulses_hz) - { - // уже большие обороты - if (WRotor.iqWRotorImpulses1 || WRotor.iqWRotorImpulses2) - { - if(WRotor.iqWRotorImpulses1>WRotor.iqWRotorImpulses2) - WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul2; - } - else - { - if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; - } - - - } - else - { - if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; - else - WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; - - } - - - // пропало направление -// if (prev_prev_RotorDirectionInstant && WRotorPBus.RotorDirectionSlow) -// if (WRotor.iqWRotorSum) -// { -// inc_sensor.break_direction = 1; -// } -// prev_prev_RotorDirectionInstant = WRotorPBus.RotorDirectionSlow; - - - -//// ошибка направления!!! -// if (WRotorPBus.RotorDirectionSlow==0) -// { -// if (WRotor.iqWRotorSum) -// inc_sensor.break_direction = 1; -// } -// else -// inc_sensor.break_direction = 0; - - -// if (WRotorPBus.RotorDirectionSlow==0) -// { -// // гоним в 0 обороты !!! ошибка направления!!! -// WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, 0); -// } -// else - - - WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, WRotor.iqWRotorSum*WRotorPBus.RotorDirectionSlow); - - WRotor.iqWRotorSumRamp = zad_intensiv_q(wrotor_add, wrotor_add, WRotor.iqWRotorSumRamp, WRotor.iqWRotorSumFilter); - - - WRotor.iqWRotorSumFilter2 = exp_regul_iq(koefW2, WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter); - WRotor.iqWRotorSumFilter3 = exp_regul_iq(koefW3, WRotor.iqWRotorSumFilter3, WRotor.iqWRotorSumFilter); - -} - - -#pragma CODE_SECTION(RotorMeasure,".fast_run"); -void RotorMeasureDetectDirection(void) -{ - int direction1, direction2, sum_direct; - - direction1 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_CLOCKWISE ? 1 : - project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? -1 : - 0; - - direction2 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? 1 : - project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_CLOCKWISE ? -1 : - 0; - - sum_direct = (direction1 + direction2) > 0 ? 1 : - (direction1 + direction2) < 0 ? -1 : - 0; - - WRotorPBus.RotorDirectionInstant = sum_direct; - -} - - -/////////////////////////////////////////////////////////////// - -#endif - - - -/////////////////////////////////////////////////////////////// - -#pragma CODE_SECTION(update_rot_sensors,".fast_run"); -void update_rot_sensors(void) -{ - inc_sensor.update_sensors(&inc_sensor); -} -/////////////////////////////////////////////////////////////// +#include "DSP281x_Examples.h" // DSP281x Examples Include File +#include "DSP281x_SWPrioritizedIsrLevels.h" // DSP281x Examples Include File +#include "DSP281x_Device.h" // DSP281x Headerfile Include File +#include "IQmathLib.h" + +#include +#include + +#include "filter_v1.h" +#include "xp_cds_in.h" +#include "xp_inc_sensor.h" +#include "xp_project.h" +#include "params.h" +#include "pwm_test_lines.h" +#include "params_norma.h" +#include "mathlib.h" +#include "params_alg.h" + + + +#pragma DATA_SECTION(WRotor,".fast_vars"); +WRotorValues WRotor = WRotorValues_DEFAULTS; + +#if (SENSOR_ALG==SENSOR_ALG_23550) + +#pragma DATA_SECTION(WRotorPBus,".slow_vars"); +WRotorValuesAngle WRotorPBus = WRotorValuesAngle_DEFAULTS; + + +#pragma DATA_SECTION(rotor_error_update_count,".fast_vars"); +unsigned int rotor_error_update_count = 0; + + +#define SIZE_BUF_SENSOR_LOGS 32 +#pragma DATA_SECTION(sensor_1_zero,".slow_vars"); +unsigned int sensor_1_zero[6+4+8][SIZE_BUF_SENSOR_LOGS], count_sensor_1_zero=0; + +#endif + +_iq koefW = _IQ(0.05); //0.05 +_iq koefW2 = _IQ(0.01); //0.05 +_iq koefW3 = _IQ(0.002); //0.05 + + + + + + + +#if (SENSOR_ALG==SENSOR_ALG_23550) +/////////////////////////////////////////////////////////////// +void rotorInit(void) +{ + WRotorPBus.ModeAutoDiscret = 1; +} + + + +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +#define MAX_COUNT_OVERFULL_DISCRET 2250 +#define MAX_DIRECTION 4000 +#define MAX_DIRECTION_2 2000 +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +void RotorDirectionFilter(int RotorDirectionIn, int *RotorDirectionOut, int *RotorDirectionOut2, int *count_direction) +{ + +// static int count_direction = 0; +// static int count_direction_minus = 0; + + + if (RotorDirectionIn==0) + { + if (*count_direction>0) (*count_direction)--; + if (*count_direction<0) (*count_direction)++; +// if (count_direction_minus>0) count_direction_minus--; + } + else + if (RotorDirectionIn>0) + { + if (*count_direction0) count_direction_minus--; + } + else + { + if (*count_direction>-MAX_DIRECTION) (*count_direction)--; +// if (count_direction_plus>0) count_direction_plus--; + } + + + if (RotorDirectionIn==0) + *RotorDirectionOut = 0; + else + if (RotorDirectionIn>0) + *RotorDirectionOut = 1; + else + *RotorDirectionOut = -1; + + + if (*count_direction>MAX_DIRECTION_2) + *RotorDirectionOut2 = 1; + else + if (*count_direction<-MAX_DIRECTION_2) + *RotorDirectionOut2 = -1; + else + *RotorDirectionOut2 = 0; + + + +} +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +#define LEVEL_VALUE_SENSOR_OVERFULL 65535 +#define MAX_COUNT_ERROR_ANALISATOR_SENSOR_PBUS 4000 +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(AnalisatorRotorSensorPBus,".fast_run"); +int AnalisatorRotorSensorPBus(_iq d1, _iq d2, unsigned int *count_overfull_discret, unsigned int *count_zero_discret, _iq *prev_iqTimeRotor, + unsigned int *discret_out, unsigned int discret_in, _iq *iqWRotorCalcBeforeRegul, _iq *iqWRotorCalc, + int modeS1, int modeS2, + int valid_sensor_direct, int valid_sensor_90, + unsigned int *error_count ) +{ + int flag_not_ready_rotor, flag_overfull_rotor; + _iq iqTimeRotor; + // discret0 = 2 mks +// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + // discret1 = 20 ns +// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + +// _iq iqWRotorSumm;//,iqWRotorCalc; + + static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. + static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. + static unsigned int discret; + + + if (valid_sensor_direct == 0) + d1 = 0; + if (valid_sensor_90 == 0) + d2 = 0; + + +// тут что-то пошло не так, была смена дискретизации по обоим каналам. + if (valid_sensor_direct == 0 && valid_sensor_90 == 0) + { + if (*error_count>1; + + + +// max OVERFULL + if (flag_overfull_rotor) + { + if (*count_overfull_discret0) + (*count_overfull_discret)--; + } + +// zero? + if (flag_not_ready_rotor) + { + if (*count_zero_discret0) + (*count_zero_discret)--; + } + +// real zero? + if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) + { + // ноль был слишком долго, значит точно ноль! + iqWRotorCalc = 0; + *prev_iqTimeRotor = 0; + iqTimeRotor = 0; + } + else + { + // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor + if (iqTimeRotor==0) + iqTimeRotor = *prev_iqTimeRotor; + } + *prev_iqTimeRotor = iqTimeRotor; + + + +// выбор нужного диапазона + if (WRotorPBus.ModeAutoDiscret==1) + { + if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) || (iqTimeRotor==0) ) + { + // тут или переполнение произошло или вдруг остановились, обороты=0 + // тогда включаем discret_out = 0 + if (discret_in == 1) // или тут надо испльзовать discret? + { + // discret был =1, переключаем на 0. + *discret_out = 0; + *count_overfull_discret = 0; // дали еще один шанс! + } + + } + else + { + // текущ. уровень discret==0 тогда... + if (discret==0 && iqTimeRotortime_level_discret_1to0 && iqTimeRotor!=65535) + *discret_out = 0; + } + } + + if (WRotorPBus.ModeAutoDiscret==2) + { + *discret_out = 0; + } + + if (WRotorPBus.ModeAutoDiscret==3) + { + *discret_out = 1; + } + + if ( (*count_overfull_discret==MAX_COUNT_OVERFULL_DISCRET) ) + { + // тут уже точно в 0, т.к. слишком медленно идут импульсы! + *prev_iqTimeRotor = iqTimeRotor = 0; + } + + + + + if ((iqTimeRotor != 0)) // && (WRotorPBus.iqTimeRotor<65535) + { + if (discret==0) + *iqWRotorCalcBeforeRegul = KoefNorm_discret0 / iqTimeRotor; + if (discret==1) + *iqWRotorCalcBeforeRegul = KoefNorm_discret1 / iqTimeRotor; + + *iqWRotorCalc = exp_regul_iq(koefW, *iqWRotorCalc, *iqWRotorCalcBeforeRegul); + } + else + { + *iqWRotorCalc = 0; + *iqWRotorCalcBeforeRegul = 0; + } + + +// if (*iqWRotorCalc == 0) +// *RotorDirection = 0; + + + return 0; + +} +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// + + +#pragma CODE_SECTION(RotorMeasurePBus,".fast_run"); +void RotorMeasurePBus(void) +{ + // discret0 = 2 mks +// static long long KoefNorm_discret0 = 409600000LL;//((500 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret0 = 102400000LL;//((500 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + // discret1 = 20 ns +// static long long KoefNorm_discret1 = 40960000000LL;//((50 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNorm_discret1 = 10240000000LL;//((50 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + + static _iq time_level_discret_1to0 = 60000 ;//682666; // KoefNorm_discret1/60000 = 0.813801288604736328125 Гц. + static _iq time_level_discret_0to1 = 400;//204800; // KoefNorm_discret0/2000 = 0.244140625 Гц. + + static long long KoefNorm_angle = 16384LL; //2^24/1024 +// volatile float MyVar0 = 0; + + unsigned int MyVar3 = 0; +// int direction1 = 0, direction2 = 0; + volatile unsigned int discret; + + static unsigned int discret_out1, discret_out2; + + static int count_full_oborots = 0; + static unsigned int count_overfull_discret1 = 0; + static unsigned int count_zero_discret1 = 0; + static unsigned int count_overfull_discret2 = 0; + static unsigned int count_zero_discret2 = 0; + + static unsigned int count_discret_to_1 = 0; + static unsigned int count_discret_to_0 = 0; + + static unsigned int c_error_pbus_1 = 0; + static unsigned int c_error_pbus_2 = 0; + + + static _iq prev_iqTimeRotor1 = 0, prev_iqTimeRotor2 = 0; + + _iq iqWRotorSumm = 0; + + int flag_not_ready_rotor1, flag_overfull_rotor1; + int flag_not_ready_rotor2, flag_overfull_rotor2; + + //i_led1_on_off(1); + + + + flag_not_ready_rotor1 = 0; + flag_overfull_rotor1 = 0; + flag_not_ready_rotor2 = 0; + flag_overfull_rotor2 = 0; + + + + discret = project.cds_in[0].read.sbus.enabled_channels.bit.discret; + if (project.cds_in[0].read.sbus.enabled_channels.bit.discret != project.cds_in[0].write.sbus.enabled_channels.bit.discret) + discret = 2; + + if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + sensor_1_zero[0][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S1; + sensor_1_zero[1][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1; + sensor_1_zero[2][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1; + sensor_1_zero[3][count_sensor_1_zero] = project.cds_in[0].read.pbus.Time_since_zero_point_S2; + sensor_1_zero[4][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2; + sensor_1_zero[5][count_sensor_1_zero] = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2; + } + sensor_1_zero[6][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt; + sensor_1_zero[7][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS1_cnt90; + sensor_1_zero[8][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt; + sensor_1_zero[9][count_sensor_1_zero] = project.cds_in[0].read.pbus.SpeedS2_cnt90; + + sensor_1_zero[10][count_sensor_1_zero] = inc_sensor.data.Time1; + sensor_1_zero[11][count_sensor_1_zero] = inc_sensor.data.Impulses1; + sensor_1_zero[12][count_sensor_1_zero] = inc_sensor.data.CountZero1; + sensor_1_zero[13][count_sensor_1_zero] = inc_sensor.data.CountOne1; + + sensor_1_zero[14][count_sensor_1_zero] = inc_sensor.data.Time2; + sensor_1_zero[15][count_sensor_1_zero] = inc_sensor.data.Impulses2; + sensor_1_zero[16][count_sensor_1_zero] = inc_sensor.data.CountZero2; + sensor_1_zero[17][count_sensor_1_zero] = inc_sensor.data.CountOne2; + + count_sensor_1_zero++; + if (count_sensor_1_zero>=SIZE_BUF_SENSOR_LOGS) + { + count_sensor_1_zero = 0; + count_full_oborots++; + if (count_full_oborots>3) + count_full_oborots = 0; + } +/* + if (count_sensor_1_zero==904) + { + discret = 3; + } +*/ + +#if (ENABLE_ROTOR_SENSOR_ZERO_SIGNAL==1) + if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6) + { + +#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) + WRotorPBus.iqWRotorRawAngle1F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S1-32768; + WRotorPBus.iqWRotorRawAngle1R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S1-32768; + WRotorPBus.iqAngle1F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1F; + WRotorPBus.iqAngle1R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle1R; +#else + WRotorPBus.iqWRotorRawAngle1F = 0; + WRotorPBus.iqWRotorRawAngle1R = 0; + WRotorPBus.iqAngle1F = 0; + WRotorPBus.iqAngle1R = 0; +#endif + +#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) + WRotorPBus.iqWRotorRawAngle2F = project.cds_in[0].read.pbus.Impulses_since_zero_point_Falling_S2-32768; + WRotorPBus.iqWRotorRawAngle2R = project.cds_in[0].read.pbus.Impulses_since_zero_point_Rising_S2-32768; + WRotorPBus.iqAngle2F = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2F; + WRotorPBus.iqAngle2R = KoefNorm_angle * WRotorPBus.iqWRotorRawAngle2R; +#else + WRotorPBus.iqWRotorRawAngle2F = 0; + WRotorPBus.iqWRotorRawAngle2R = 0; + WRotorPBus.iqAngle2F = 0; + WRotorPBus.iqAngle2R = 0; +#endif + } + else + { + WRotorPBus.iqWRotorRawAngle1F = 0; + WRotorPBus.iqWRotorRawAngle1R = 0; + WRotorPBus.iqAngle1F = 0; + WRotorPBus.iqAngle1R = 0; + + WRotorPBus.iqWRotorRawAngle2F = 0; + WRotorPBus.iqWRotorRawAngle2R = 0; + WRotorPBus.iqAngle2F = 0; + WRotorPBus.iqAngle2R = 0; + + } +#endif + + +#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) + //************************************************************************************************** + MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw0 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw0 = 0; + } + + MyVar3 = project.cds_in[0].read.pbus.SpeedS1_cnt90; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw1 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw1 = 0; + } +#else + WRotorPBus.iqWRotorRaw0 = 0; + WRotorPBus.iqWRotorRaw1 = 0; +#endif + + +#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) + //*************************************************************************************************** + MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw2 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw2 = 0; + } + + MyVar3 = project.cds_in[0].read.pbus.SpeedS2_cnt90; + + if ((MyVar3 <= COUNT_DECODER_ZERO_WROTORPBus) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + WRotorPBus.iqWRotorRaw3 = MyVar3; + } + else + { + WRotorPBus.iqWRotorRaw3 = 0; + } +#else + WRotorPBus.iqWRotorRaw2 = 0; + WRotorPBus.iqWRotorRaw3 = 0; +#endif + + +#if (ENABLE_ROTOR_SENSOR_1_PBUS==1) +// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90 ) + AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw0, WRotorPBus.iqWRotorRaw1, &count_overfull_discret1, &count_zero_discret1, + &prev_iqTimeRotor1, &discret_out1, project.cds_in[0].read.sbus.enabled_channels.bit.discret, + &WRotorPBus.iqWRotorCalcBeforeRegul1, &WRotorPBus.iqWRotorCalc1, + project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor1_90, + project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor1_90, + &c_error_pbus_1 ); +#endif + +#if (ENABLE_ROTOR_SENSOR_2_PBUS==1) +// if (project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct && project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90 ) + AnalisatorRotorSensorPBus(WRotorPBus.iqWRotorRaw2, WRotorPBus.iqWRotorRaw3, &count_overfull_discret2, &count_zero_discret2, + &prev_iqTimeRotor2, &discret_out2, project.cds_in[0].read.sbus.enabled_channels.bit.discret, + &WRotorPBus.iqWRotorCalcBeforeRegul2, &WRotorPBus.iqWRotorCalc2, + project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.mode_sensor2_90, + project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_direct, project.cds_in[0].read.pbus.direction_in.bit.value_vaild_sensor2_90, + &c_error_pbus_2); +#endif + + + // RotorDirectionFilter(WRotorPBus.RotorDirectionInstant, &WRotorPBus.RotorDirectionSlow); + + + + if (discret_out1==1 || discret_out2==1) + { + project.cds_in[0].write.sbus.enabled_channels.bit.discret = 1; + count_discret_to_1++; + } + else + { + project.cds_in[0].write.sbus.enabled_channels.bit.discret = 0; + count_discret_to_0++; + } + + +} + + + + +#define MAX_COUNT_OVERFULL_DISCRET_2 150 +#pragma CODE_SECTION(RotorMeasure,".fast_run"); +void RotorMeasure(void) +{ + + // 600 Khz clock on every edge +// static long long KoefNorm = 53635601LL;//((600 000/6256/NORMA_WROTOR/2) * ((long)2 << 24)); //15 - NormaWRotor 782*8 = 6256 +// static long long KoefNormMS = 491520000LL;//((600 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 +// static long long KoefNormNS = 49152000000LL;//((60 000 000/1024/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormMS = 122880000LL;//((600 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormNS = 12288000000LL;//((60 000 000/4096/NORMA_WROTOR) * ((long)2 << 24)); //20 - NORMA_FROTOR 1024*8 = 8129 + static long long KoefNormImpulses = 838860800000000LL;// (2^24 * 1000000000 / (Impulses(ns)) / NORMA_WROTOR + + static _iq max_value_rotor = _IQ(500.0/60.0/NORMA_FROTOR); + static _iq wrotor_add_ramp = _IQ(0.001/NORMA_FROTOR); + +// volatile float MyVar0 = 0; +// volatile unsigned int MyVar1 = 0; +// volatile unsigned int MyVar2 = 0; + unsigned int MyVar3; + + + inc_sensor.read_sensors(&inc_sensor); + + // flag_not_ready_rotor = 0; + +//************************************************************************************************** +// sensor 1 + + if (inc_sensor.use_sensor1) + { + MyVar3 = inc_sensor.data.CountOne1; +// MyVar3 = (unsigned long) rotation_sensor.in_plane.out.CountOne1; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_21_ON; +#endif + + WRotor.iqWRotorRaw0 = MyVar3; + } + else + { + +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_21_OFF; +#endif + + WRotor.iqWRotorRaw0 = 0; + } + MyVar3 = inc_sensor.data.CountZero1; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_22_ON; +#endif + WRotor.iqWRotorRaw1 = MyVar3; + } + else + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_22_OFF; +#endif + WRotor.iqWRotorRaw1 = 0; + } + } + else + { + WRotor.iqWRotorRaw0 = 0; + WRotor.iqWRotorRaw1 = 0; + } + //logpar.uns_log0 = (Uint16)(my_var1); + //logpar.uns_log1 = (Uint16)(my_var2); + + // sensor 2 + if (inc_sensor.use_sensor2) + { + MyVar3 = inc_sensor.data.CountOne2; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_18_ON; +#endif + WRotor.iqWRotorRaw2 = MyVar3; + } + else + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_18_OFF; +#endif + WRotor.iqWRotorRaw2 = 0; + } + + MyVar3 = inc_sensor.data.CountZero2; + + if ((MyVar3 < COUNT_DECODER_ZERO_WROTOR) + && (MyVar3 > COUNT_DECODER_MAX_WROTOR)) + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_23_ON; +#endif + WRotor.iqWRotorRaw3 = MyVar3; + } + else + { +#if(_ENABLE_PWM_LINES_FOR_TESTS_ROTOR) + PWM_LINES_TK_23_OFF; +#endif + WRotor.iqWRotorRaw3 = 0; + } + } + else + { + WRotor.iqWRotorRaw2 = 0; + WRotor.iqWRotorRaw3 = 0; + } + +// if (WRotor.iqWRotorRaw0==0 && WRotor.iqWRotorRaw1==0 && WRotor.iqWRotorRaw2==0 && WRotor.iqWRotorRaw3==0) +// flag_not_ready_rotor = 1; + + if (WRotor.iqWRotorRaw0==0) + { + if (WRotor.count_zero_discret0==MAX_COUNT_OVERFULL_DISCRET_2) + { + WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0 = 0; + } + else + { + WRotor.iqWRotorRaw0 = WRotor.prev_iqWRotorRaw0; + WRotor.count_zero_discret0++; + } + } + else + { + WRotor.count_zero_discret0 = 0; + WRotor.prev_iqWRotorRaw0 = WRotor.iqWRotorRaw0; + } + + if (WRotor.iqWRotorRaw1==0) + { + if (WRotor.count_zero_discret1==MAX_COUNT_OVERFULL_DISCRET_2) + { + WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1 = 0; + } + else + { + WRotor.iqWRotorRaw1 = WRotor.prev_iqWRotorRaw1; + WRotor.count_zero_discret1++; + } + } + else + { + WRotor.count_zero_discret1 = 0; + WRotor.prev_iqWRotorRaw1 = WRotor.iqWRotorRaw1; + } + + if (WRotor.iqWRotorRaw2==0) + { + if (WRotor.count_zero_discret2==MAX_COUNT_OVERFULL_DISCRET_2) + { + WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2 = 0; + } + else + { + WRotor.iqWRotorRaw2 = WRotor.prev_iqWRotorRaw2; + WRotor.count_zero_discret2++; + } + } + else + { + WRotor.count_zero_discret2 = 0; + WRotor.prev_iqWRotorRaw2 = WRotor.iqWRotorRaw2; + } + + if (WRotor.iqWRotorRaw3==0) + { + if (WRotor.count_zero_discret3==MAX_COUNT_OVERFULL_DISCRET_2) + { + WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3 = 0; + } + else + { + WRotor.iqWRotorRaw3 = WRotor.prev_iqWRotorRaw3; + WRotor.count_zero_discret3++; + } + } + else + { + WRotor.count_zero_discret3 = 0; + WRotor.prev_iqWRotorRaw3 = WRotor.iqWRotorRaw3; + } + + + WRotor.iqTimeSensor1 = WRotor.iqWRotorRaw0 + WRotor.iqWRotorRaw1; + WRotor.iqTimeSensor2 = WRotor.iqWRotorRaw2 + WRotor.iqWRotorRaw3; + + // +// // zero? +// if (flag_not_ready_rotor) +// { +// if (*count_zero_discret0) +// (*count_zero_discret)--; +// } +// +// // real zero? +// if (count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) +// { +// // ноль был слишком долго, значит точно ноль! +// WRotor.iqTimeSensor1 = 0; +// WRotor.prev_iqTimeSensor1 = 0; +// } +// else +// { +// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor +// if (WRotor.iqTimeSensor1==0) +// WRotor.iqTimeSensor1 = WRotor.prev_iqTimeSensor1; +// } +// WRotor.prev_iqTimeSensor1 = WRotor.iqTimeSensor1; +// +// +// // max OVERFULL +// if (flag_overfull_rotor) +// { +// if (*count_overfull_discret0) +// (*count_overfull_discret)--; +// } +// +// // zero? +// if (flag_not_ready_rotor) +// { +// if (*count_zero_discret0) +// (*count_zero_discret)--; +// } +// +// // real zero? +// if (*count_zero_discret==MAX_COUNT_OVERFULL_DISCRET) +// { +// // ноль был слишком долго, значит точно ноль! +// iqWRotorCalc = 0; +// *prev_iqTimeRotor = 0; +// iqTimeRotor = 0; +// } +// else +// { +// // ноль еще не слишком долго, значит берем старое значение prev_iqTimeRotor +// if (iqTimeRotor==0) +// iqTimeRotor = *prev_iqTimeRotor; +// } +// *prev_iqTimeRotor = iqTimeRotor; +// +// +// + +/// + if (WRotor.iqTimeSensor1 != 0 && inc_sensor.use_sensor1) + { + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==0) + WRotor.iqWRotorCalcBeforeRegul1 = KoefNormMS / WRotor.iqTimeSensor1; + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time1==1) + WRotor.iqWRotorCalcBeforeRegul1 = KoefNormNS / WRotor.iqTimeSensor1; + + if (WRotor.iqWRotorCalcBeforeRegul1 > max_value_rotor) + { + WRotor.iqWRotorCalc1 = 0; + WRotor.iqWRotorCalcBeforeRegul1 = 0; + } + else + WRotor.iqWRotorCalc1 = exp_regul_iq(koefW, WRotor.iqWRotorCalc1, WRotor.iqWRotorCalcBeforeRegul1); + + ///// + if (WRotor.iqWRotorCalc1) + { + if (WRotor.iqPrevWRotorCalc1 != WRotor.iqWRotorCalc1) + { + WRotor.iqWRotorCalc1Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc1Ramp, WRotor.iqWRotorCalc1); + WRotor.iqPrevWRotorCalc1 = WRotor.iqWRotorCalc1; + } + } + else + { + WRotor.iqPrevWRotorCalc1 = 0; + WRotor.iqWRotorCalc1Ramp = 0; + } + //// + } + else + { + WRotor.iqWRotorCalc1 = 0; + WRotor.iqWRotorCalcBeforeRegul1 = 0; + } +/// + if (WRotor.iqTimeSensor2 != 0 && inc_sensor.use_sensor2) + { + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==0) + WRotor.iqWRotorCalcBeforeRegul2 = KoefNormMS / WRotor.iqTimeSensor2; + if (inc_sensor.pm67regs.read_comand_reg.bit.sampling_time2==1) + WRotor.iqWRotorCalcBeforeRegul2 = KoefNormNS / WRotor.iqTimeSensor2; + + if (WRotor.iqWRotorCalcBeforeRegul2 > max_value_rotor) + { + WRotor.iqWRotorCalc2 = 0; + WRotor.iqWRotorCalcBeforeRegul2 = 0; + } + else + WRotor.iqWRotorCalc2 = exp_regul_iq(koefW, WRotor.iqWRotorCalc2, WRotor.iqWRotorCalcBeforeRegul2); + + + + ///// + if (WRotor.iqWRotorCalc2) + { + if (WRotor.iqPrevWRotorCalc2 != WRotor.iqWRotorCalc2) + { + WRotor.iqWRotorCalc2Ramp = zad_intensiv_q(wrotor_add_ramp, wrotor_add_ramp, WRotor.iqWRotorCalc2Ramp, WRotor.iqWRotorCalc2); + WRotor.iqPrevWRotorCalc2 = WRotor.iqWRotorCalc2; + } + } + else + { + WRotor.iqPrevWRotorCalc2 = 0; + WRotor.iqWRotorCalc2Ramp = 0; + } + //// + } + else + { + WRotor.iqWRotorCalc2 = 0; + WRotor.iqWRotorCalcBeforeRegul2 = 0; + } +/// + if (inc_sensor.data.TimeCalcFromImpulses1 && inc_sensor.use_sensor1) + WRotor.iqWRotorImpulsesBeforeRegul1 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses1 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); + else + WRotor.iqWRotorImpulsesBeforeRegul1 = 0; + + WRotor.iqWRotorImpulses1 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses1, WRotor.iqWRotorImpulsesBeforeRegul1); + + if (inc_sensor.data.TimeCalcFromImpulses2 && inc_sensor.use_sensor2) + WRotor.iqWRotorImpulsesBeforeRegul2 = (long long) KoefNormImpulses / (inc_sensor.data.TimeCalcFromImpulses2 * ROTOR_SENSOR_IMPULSES_PER_ROTATE); + else + WRotor.iqWRotorImpulsesBeforeRegul2 = 0; + + WRotor.iqWRotorImpulses2 = exp_regul_iq(koefW, WRotor.iqWRotorImpulses2, WRotor.iqWRotorImpulsesBeforeRegul2); + + + // WRotor.iqWRotorCalcBeforeRegul = _IQdiv(WRotor.iqWRotorCalcBeforeRegul,IQ_CONST_3); +} + +#define LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS 50 // Oborot +void select_values_wrotor(void) +{ + static _iq level_switch_to_get_impulses_hz = _IQ(LEVEL_SWITCH_TO_GET_IMPULSES_OBOROTS/60.0/NORMA_FROTOR); + static unsigned int prev_RotorDirectionInstant = 0; + static unsigned int status_RotorRotation = 0; // есть вращение? + static _iq wrotor_add = _IQ(0.002/NORMA_FROTOR); + + + + + if (WRotor.iqWRotorCalc1>level_switch_to_get_impulses_hz + || WRotor.iqWRotorCalc2>level_switch_to_get_impulses_hz) + { + // уже большие обороты + if (WRotor.iqWRotorImpulses1 || WRotor.iqWRotorImpulses2) + { + if(WRotor.iqWRotorImpulses1>WRotor.iqWRotorImpulses2) + WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul1; + else + WRotor.iqWRotorSum = WRotor.iqWRotorImpulsesBeforeRegul2; + } + else + { + if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) + WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; + else + WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; + } + + + } + else + { + if(WRotor.iqWRotorCalc1>WRotor.iqWRotorCalc2) + WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul1; + else + WRotor.iqWRotorSum = WRotor.iqWRotorCalcBeforeRegul2; + + } + + + // пропало направление +// if (prev_prev_RotorDirectionInstant && WRotorPBus.RotorDirectionSlow) +// if (WRotor.iqWRotorSum) +// { +// inc_sensor.break_direction = 1; +// } +// prev_prev_RotorDirectionInstant = WRotorPBus.RotorDirectionSlow; + + + +//// ошибка направления!!! +// if (WRotorPBus.RotorDirectionSlow==0) +// { +// if (WRotor.iqWRotorSum) +// inc_sensor.break_direction = 1; +// } +// else +// inc_sensor.break_direction = 0; + + +// if (WRotorPBus.RotorDirectionSlow==0) +// { +// // гоним в 0 обороты !!! ошибка направления!!! +// WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, 0); +// } +// else + + + WRotor.iqWRotorSumFilter = exp_regul_iq(koefW, WRotor.iqWRotorSumFilter, WRotor.iqWRotorSum*WRotorPBus.RotorDirectionSlow); + + WRotor.iqWRotorSumRamp = zad_intensiv_q(wrotor_add, wrotor_add, WRotor.iqWRotorSumRamp, WRotor.iqWRotorSumFilter); + + + WRotor.iqWRotorSumFilter2 = exp_regul_iq(koefW2, WRotor.iqWRotorSumFilter2, WRotor.iqWRotorSumFilter); + WRotor.iqWRotorSumFilter3 = exp_regul_iq(koefW3, WRotor.iqWRotorSumFilter3, WRotor.iqWRotorSumFilter); + +} + + + +#pragma CODE_SECTION(RotorMeasure,".fast_run"); +void RotorMeasureDetectDirection(void) +{ + int direction1, direction2, sum_direct; + + direction1 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_CLOCKWISE ? 1 : + project.cds_in[0].read.pbus.direction_in.bit.dir_sens_1 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? -1 : + 0; + + direction2 = project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_COUNTERCLOCKWISE ? 1 : + project.cds_in[0].read.pbus.direction_in.bit.dir_sens_2 == ROTOR_SENSOR_CODE_CLOCKWISE ? -1 : + 0; + + sum_direct = (direction1 + direction2) > 0 ? 1 : + (direction1 + direction2) < 0 ? -1 : + 0; + + WRotorPBus.RotorDirectionInstant = sum_direct; + +} + + +/////////////////////////////////////////////////////////////// + +#endif + + + +/////////////////////////////////////////////////////////////// + +#pragma CODE_SECTION(update_rot_sensors,".fast_run"); +void update_rot_sensors(void) +{ + inc_sensor.update_sensors(&inc_sensor); +} +/////////////////////////////////////////////////////////////// diff --git a/Inu/Src2/551/main/v_rotor.h b/Inu/Src2/main/v_rotor.h similarity index 100% rename from Inu/Src2/551/main/v_rotor.h rename to Inu/Src2/main/v_rotor.h diff --git a/Inu/Src/main/v_rotor_22220.c b/Inu/Src2/main/v_rotor_22220.c similarity index 100% rename from Inu/Src/main/v_rotor_22220.c rename to Inu/Src2/main/v_rotor_22220.c diff --git a/Inu/Src/main/v_rotor_22220.h b/Inu/Src2/main/v_rotor_22220.h similarity index 100% rename from Inu/Src/main/v_rotor_22220.h rename to Inu/Src2/main/v_rotor_22220.h diff --git a/Inu/Src2/main/vector.h b/Inu/Src2/main/vector.h index 5245af8..25bc4f1 100644 --- a/Inu/Src2/main/vector.h +++ b/Inu/Src2/main/vector.h @@ -25,16 +25,16 @@ #include "IQmathLib.h" - +#include "x_basic_types.h" typedef struct { float W; /* Угловау скороть ротора */ float Angle; /* Угол положениу ротора */ float Phi; /* Поправка к углу ротора */ - float k; /* Коэфф. модуляции */ - float k1; /* Коэфф. модулуции */ - float k2; /* Коэфф. модулуции */ + float k; /* Коэфф. модулЯции */ + float k1; /* Коэфф. модулЯции */ + float k2; /* Коэфф. модулЯции */ float f; /* Частота статора */ _iq iqk; @@ -46,19 +46,18 @@ typedef struct } WINDING; - +#define WINDING_DEFAULT {0,0,0,0,0,0,0,0,0,0,0} typedef struct { unsigned int Prepare; unsigned int terminal_prepare; - unsigned int prepareSVU; unsigned int Test_Lamps; unsigned int fault; - unsigned int prevGo; - unsigned int Go; + + unsigned int Stop; unsigned int Mode; unsigned int Revers; @@ -67,14 +66,12 @@ typedef struct unsigned int Ready1; unsigned int Ready2; unsigned int Discharge; - unsigned int is_charging; + unsigned int Assemble; unsigned int ErrorChannel1; unsigned int ErrorChannel2; unsigned int FaultChannel1; unsigned int FaultChannel2; - - unsigned int secondPChState; unsigned int Set_power; @@ -84,39 +81,31 @@ typedef struct unsigned int Obmotka2; // unsigned int Down50; - unsigned int Power_over_Nominal; unsigned int I_over_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ???? - unsigned int I_over_1_6_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ???? - unsigned int I_over_1_8_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ???? unsigned int Moment_over_1_6_noninal; //????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.6 ??? unsigned int Moment_over_1_8_nominal; //????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.8 ??? unsigned int DownToNominal; - unsigned int DownToNominalCurrent; unsigned int DownToNominalMoment; - unsigned int DownTemperature; - unsigned int DownToNominalVoltage; - unsigned int DownToNominalFreq; + unsigned int Down50Temperature; unsigned int nominal_I_exceeded_counter; //??????? ??? ????????? ??????????? ??? unsigned int nominal_M_exceeded_counter; //??????? ??? ????????? ??????????? ?????? -// unsigned int I_zpt_over_nominal; unsigned int Up50; unsigned int Ciclelog; - unsigned int pidD_set; + unsigned int Provorot; unsigned int Bpsi; unsigned int Piregul1; unsigned int Piregul2; unsigned int Startstoplog; unsigned int Setspeed; - unsigned int BWC_turn_ON; - unsigned int BWC_Auto_mode; + unsigned int BWC_is_ON; unsigned int Setsdvigfaza; unsigned int Off_piregul; unsigned int Restart; - unsigned int stop_Log; + unsigned int Log1_Log2; unsigned int Work_net; unsigned int Mask_impuls; @@ -130,7 +119,7 @@ typedef struct unsigned int Uzad; unsigned int Umin; - unsigned int RScount; +// unsigned int RScount; unsigned int vector_run; unsigned int test_all_run; @@ -139,77 +128,80 @@ typedef struct unsigned int flag_Break_Resistor_Error; unsigned int flag_local_control; //1 - local - unsigned int flag_leading; //Текущий ПЧ мастер - unsigned int flag_second_leading; //Второй ПЧ мастер - unsigned int read_task_from_optical_bus; - unsigned int sync_rotor_from_optical_bus; - unsigned int sync_Iq_from_optical_bus; + unsigned int flag_leading; //??????? ?? ?????? + unsigned int flag_second_leading; //?????? ?? ?????? unsigned int flag_distance; - unsigned int flag_second_PCH; - unsigned int leftShaft; - unsigned int inverter_number; - unsigned int ice_movement_limit; - unsigned int flag_batery_charged; - unsigned int flag_Pump_Is_On; //Gidropodpor - unsigned int flag_turn_On_Pump; - unsigned int flag_UMP_blocked; + unsigned int flag_kvitirovanie; + unsigned int flag_batary_loaded; + unsigned int flag_Pump_Is_On; unsigned int power_units_doors_closed; unsigned int power_units_doors_locked; unsigned int flag_decr_mzz_power; - unsigned int rotor_stopped; - - float decr_mzz_power; + real decr_mzz_power; _iq iq_decr_mzz_power; _iq iq_decr_mzz_voltage; - float fzad; - float kzad; - float kzad_plus; - float fzad_provorot; - float Sdvigfaza; + real fzad; + real kzad; + real kzad_plus; +// real fzad_provorot; + real Sdvigfaza; +// real k_3garonica; +// _iq iq_k_3garonica; +// real bpsi_zad; - float mzz_zad; - float fr_zad; - float Power; - float p_zad; +// real Piregul1_p; +// real Piregul1_i; + +// real Piregul2_p; +// real Piregul2_i; + + + real mzz_zad; + real fr_zad; + real Power; + real p_zad; // _iq iq_bpsi_zad; - _iq iq_mzz_zad; - _iq iq_fzad_provorot; - _iq iq_fzad; - _iq iq_p_zad; - _iq iq_p_rampa; - _iq iq_p_zad_electric; - _iq iq_p_limit_zad; - int p_limit_zad; //Ограничение мощности с верхнего уровня + _iq iq_mzz_zad; +// _iq iq_fzad_provorot; + _iq iq_fzad; + + _iq iq_p_zad; unsigned int flag_Enable_Prepare; - union { - unsigned int all; - struct { - unsigned int BV1: 1; - unsigned int BV2: 1; - unsigned int BI1: 1; - unsigned int BI2: 1; - unsigned int UMU: 1; - unsigned int UKSI: 1; - unsigned int reserved: 10; - } UKSS; - } status_ready; + + unsigned int status_MODE_WORK_SVU; + unsigned int status_MODE_WORK_MPU; + unsigned int status_MODE_WORK_VPU; +// unsigned int status_MODE_WORK_EVPU; + +// unsigned int filter_READY_UKSS_BV1; +// unsigned int filter_READY_UKSS_BV2; +// unsigned int filter_READY_UKSS_BI1; +// unsigned int filter_READY_UKSS_BI2; + unsigned int filter_READY_UMU; +// unsigned int filter_READY_UKSS_UKSI; unsigned int On_Power_QTV; - unsigned int Power_QTV_is_On; unsigned int RS_MPU_ERROR; - unsigned int MPU_Ready; +// unsigned int CAN_MPU_ERROR; + +// unsigned int enable_fast_prepare; + +// unsigned int tau_break1; +// unsigned int tau_break2; unsigned int flag_tormog; +// unsigned int GoPWM; + int special_test_from_mpu; int MessageToCan1; @@ -218,34 +210,40 @@ typedef struct int flag_random_freq; long tmp; - unsigned int rele1; - _iq cosinusTerminal; - _iq cosinusTerminalSquared; -// _iq cosinusFiOut; - - int setCosTerminal; - int setTettaKt; - - //Sync vals - int pwm_freq_plus_minus_zero; - int disable_sync; - int sync_ready; - int flag_sync_vipr1_vipr2; - int level_find_sync_zero; - int delta_error_sync; - int delta_capnum; - int count_error_sync; - int capnum0; - int PWMcounterVal; - int build_version; + + + +//optical bus data + unsigned int read_task_from_optical_bus; + + + + unsigned int count_wait_after_kvitir; + unsigned int flag_record_log; + unsigned int count_step_ram_off; + unsigned int count_start_impuls; + + int flag_send_alarm_log_to_MPU; + } FLAG; - +#define FLAG_DEFAULTS {\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0,0,0,0,0,\ + 0,0,0,0,0,0\ + } extern FLAG f; -extern WINDING a; +//extern WINDING a; #ifdef __cplusplus } diff --git a/Inu/Src2/551/main/xPlatesAddress.h b/Inu/Src2/main/xPlatesAddress.h similarity index 100% rename from Inu/Src2/551/main/xPlatesAddress.h rename to Inu/Src2/main/xPlatesAddress.h diff --git a/Inu/Src2/main/xp_write_xpwm_time.c b/Inu/Src2/main/xp_write_xpwm_time.c deleted file mode 100644 index 093b88c..0000000 --- a/Inu/Src2/main/xp_write_xpwm_time.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * xp_write_xpwm_time.c - * - * Created on: 03 Г ГЇГ°. 2018 ГЈ. - * Author: stud - */ - -#include "xp_write_xpwm_time.h" -// #include "MemoryFunctions.h" -// #include "Spartan2E_Adr.h" -// #include "PWMTMSHandle.h" - -#include "def.h" - - -// #pragma DATA_SECTION(xpwm_time,".fast_vars1"); -XPWM_TIME xpwm_time = DEFAULT_XPWM_TIME; - -#define set_default_tclosed(k,b) {if (b) k = p->Tclosed_saw_direct_1; else k = p->Tclosed_saw_direct_0;} - -void initXpwmTimeStructure(XPWM_TIME *p) { - p->Ta0_0 = p->Tclosed_0; - p->Ta0_1 = p->Tclosed_1; - p->Tb0_0 = p->Tclosed_0; - p->Tb0_1 = p->Tclosed_1; - p->Tc0_0 = p->Tclosed_0; - p->Tc0_1 = p->Tclosed_1; - - p->Ta1_0 = p->Tclosed_0; - p->Ta1_1 = p->Tclosed_1; - p->Tb1_0 = p->Tclosed_0; - p->Tb1_1 = p->Tclosed_1; - p->Tc1_0 = p->Tclosed_0; - p->Tc1_1 = p->Tclosed_1; - - p->Tbr0_0 = 0; - p->Tbr0_1 = 0; - p->Tbr1_0 = 0; - p->Tbr1_1 = 0; -} - - -// Функции заглушки чтобы компилировалось в матлабе -void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) { - -} - -// void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p) { - -// } -/* -//#pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines,".fast_run1"); -void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) -{ - if(!(ReadMemory(ADR_ERRORS_TOTAL_INFO))) - { - WriteMemory(ADR_PWM_KEY_NUMBER, 0); - WriteMemory(ADR_PWM_TIMING, p->Ta0_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 1); - WriteMemory(ADR_PWM_TIMING, p->Ta0_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 2); - WriteMemory(ADR_PWM_TIMING, p->Tb0_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 3); - WriteMemory(ADR_PWM_TIMING, p->Tb0_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 4); - WriteMemory(ADR_PWM_TIMING, p->Tc0_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 5); - WriteMemory(ADR_PWM_TIMING, p->Tc0_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 6); - WriteMemory(ADR_PWM_TIMING, p->Ta1_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 7); - WriteMemory(ADR_PWM_TIMING, p->Ta1_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 8); - WriteMemory(ADR_PWM_TIMING, p->Tb1_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 9); - WriteMemory(ADR_PWM_TIMING, p->Tb1_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 10); - WriteMemory(ADR_PWM_TIMING, p->Tc1_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 11); - WriteMemory(ADR_PWM_TIMING, p->Tc1_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 12); - WriteMemory(ADR_PWM_TIMING, p->Tbr0_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 13); - WriteMemory(ADR_PWM_TIMING, p->Tbr0_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 14); - WriteMemory(ADR_PWM_TIMING, p->Tbr1_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 15); - WriteMemory(ADR_PWM_TIMING, p->Tbr1_1); - } - else - { - WriteMemory(ADR_PWM_KEY_NUMBER, 0); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 1); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 2); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 3); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 4); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 5); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 6); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 7); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 8); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 9); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 10); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); - WriteMemory(ADR_PWM_KEY_NUMBER, 11); - WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); - WriteMemory(ADR_PWM_KEY_NUMBER, 12); - WriteMemory(ADR_PWM_TIMING, 0); - WriteMemory(ADR_PWM_KEY_NUMBER, 13); - WriteMemory(ADR_PWM_TIMING, 0); - WriteMemory(ADR_PWM_KEY_NUMBER, 14); - WriteMemory(ADR_PWM_TIMING, 0); - WriteMemory(ADR_PWM_KEY_NUMBER, 15); - WriteMemory(ADR_PWM_TIMING, 0); - } -} -*/ -// #pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines_split_eages,".fast_run1"); -void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p) -{ - // if (!(i_ReadMemory(ADR_ERRORS_TOTAL_INFO))) - { -//a - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit0==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Ta0_0); - EPwm2Regs.CMPA.half.CMPA = p->Ta0_0; - } - - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit1 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit1==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Ta0_1); - EPwm1Regs.CMPA.half.CMPA = p->Ta0_1; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit2 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit2==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tb0_0); - EPwm4Regs.CMPA.half.CMPA = p->Tb0_0; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit3 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit3==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tb0_1); - EPwm3Regs.CMPA.half.CMPA = p->Tb0_1; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit4 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit4==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tc0_0); - EPwm6Regs.CMPA.half.CMPA = p->Tc0_0; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit5 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit5==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tc0_1); - EPwm5Regs.CMPA.half.CMPA = p->Tc0_1; - } -//b - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit6 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit6==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Ta1_0); - EPwm8Regs.CMPA.half.CMPA = p->Ta1_0; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit7 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit7==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Ta1_1); - EPwm7Regs.CMPA.half.CMPA = p->Ta1_1; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit8 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit8==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tb1_0); - EPwm10Regs.CMPA.half.CMPA = p->Tb1_0; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit9 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit9==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tb1_1); - EPwm9Regs.CMPA.half.CMPA = p->Tb1_1; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit10 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit10==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tc1_0); - EPwm12Regs.CMPA.half.CMPA = p->Tc1_0; - } - if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) - || (p->saw_direct.bits.bit11 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) - || (p->saw_direct.bits.bit11==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) - { - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tc1_1); - EPwm11Regs.CMPA.half.CMPA = p->Tc1_1; - } - -//br1 br2 - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_0); - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_1); - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_0); - // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); - // i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_1); - } -// else -// { -// // hard_stop_x24_pwm_all(); -// // stop_pwm(); -// xpwm_write_zero_winding_break_times_16_lines_split_eages(p); -// } -} -/* -// #pragma CODE_SECTION(xpwm_write_zero_1,".fast_run2"); -void xpwm_write_zero_1(XPWM_TIME *p) -{ - unsigned int tclose; - - //a - set_default_tclosed(tclose, p->saw_direct.bits.bit0); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Ta0_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit1); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Ta0_1 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit2); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tb0_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit3); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tb0_1 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit4); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tc0_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit5); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tc0_1 = tclose; - -} - -// #pragma CODE_SECTION(xpwm_write_zero_2,".fast_run1"); -void xpwm_write_zero_2(XPWM_TIME *p) -{ - unsigned int tclose; - -//b - set_default_tclosed(tclose, p->saw_direct.bits.bit6); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Ta1_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit7); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Ta1_1 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit8); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tb1_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit9); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tb1_1 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit10); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tc1_0 = tclose; - - set_default_tclosed(tclose, p->saw_direct.bits.bit11); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); - i_WriteMemory(ADR_PWM_TIMING, tclose); - p->Tc1_1 = tclose; - -} - -// #pragma CODE_SECTION(xpwm_write_zero_break_1,".fast_run2"); -void xpwm_write_zero_break_1(XPWM_TIME *p) -{ - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); - i_WriteMemory(ADR_PWM_TIMING, 0); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); - i_WriteMemory(ADR_PWM_TIMING, 0); - - p->Tbr0_0 = 0; - p->Tbr0_1 = 0; - -} - -// #pragma CODE_SECTION(xpwm_write_zero_break_2,".fast_run2"); -void xpwm_write_zero_break_2(XPWM_TIME *p) -{ - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); - i_WriteMemory(ADR_PWM_TIMING, 0); - i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); - i_WriteMemory(ADR_PWM_TIMING, 0); - - p->Tbr1_0 = 0; - p->Tbr1_1 = 0; -} - -// #pragma CODE_SECTION(xpwm_write_zero_winding_break_times_16_lines_split_eages,".fast_run2"); -void xpwm_write_zero_winding_break_times_16_lines_split_eages(XPWM_TIME *p) -{ - xpwm_write_zero_1(p); - xpwm_write_zero_2(p); - xpwm_write_zero_break_1(p); - xpwm_write_zero_break_2(p); -} - -*/ - diff --git a/Inu/def.h b/Inu/def.h index 49488b2..12cca02 100644 --- a/Inu/def.h +++ b/Inu/def.h @@ -11,7 +11,7 @@ // раскомментировать, если есть сдвиг между обмотками ГЭД (30 град.) #define SHIFT -#define SIMULINK_SEQUENCE V_PWM24_PHASE_SEQ_NORMAL_BCA +#define SIMULINK_SEQUENCE V_PWM24_PHASE_SEQ_REVERS_BAC /* V_PWM24_PHASE_SEQ_NORMAL_ABC, - не то V_PWM24_PHASE_SEQ_NORMAL_BCA, - похоже на правду V_PWM24_PHASE_SEQ_NORMAL_CAB, - жопа diff --git a/Inu/main_matlab/init28335.c b/Inu/main_matlab/init28335.c index 29cb321..7a096e1 100644 --- a/Inu/main_matlab/init28335.c +++ b/Inu/main_matlab/init28335.c @@ -11,19 +11,25 @@ #include "init28335.h" #define FREQ_TIMER_3 (FREQ_PWM*2) +#define MAX_U_PROC_SMALL 2.5 //1.4 +#define MAX_U_PROC 1.3 //1.11 //1.4 +#define MIN_U_PROC 0.8 //0.7 + +#define ADD_U_MAX_GLOBAL 200.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge +#define ADD_U_MAX_GLOBAL_SMALL 500.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge +#define LEVEL_DETECT_U_SMALL 1000.0 //V Насколько поднимаем уставку GLOBAL относительно ZadanieU_Charge void init28335(void) { - init_simple_scalar(); edrk.flag_second_PCH = 0; edrk_init_variables_matlab(); - init_global_time_struct(FREQ_TIMER_3); + init_global_time_struct(FREQ_TIMER_3); Init_Adc_Variables(); - svgen_pwm24_1.phase_sequence = SIMULINK_SEQUENCE; - svgen_pwm24_2.phase_sequence = SIMULINK_SEQUENCE; + //svgen_pwm24_1.phase_sequence = SIMULINK_SEQUENCE; + //svgen_pwm24_2.phase_sequence = SIMULINK_SEQUENCE; edrk.zadanie.iq_Izad = _IQ(0.5); edrk.disable_alg_u_disbalance = 1; @@ -36,7 +42,7 @@ void edrk_init_variables_matlab(void) initVectorControl(); InitXPWM(FREQ_PWM); - InitPWM_Variables(edrk.flag_second_PCH); + InitPWM_Variables(); //#if(SENSOR_ALG==SENSOR_ALG_23550) // rotorInit(); @@ -52,36 +58,9 @@ void edrk_init_variables_matlab(void) init_ramp_all_zadanie(); - init_all_limit_koeffs(); + //init_all_limit_koeffs(); - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_IZAD] = NOMINAL_SET_IZAD; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_KM] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_U_DISBALANCE] = NOMINAL_SET_K_U_DISBALANCE; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_K_PLUS_U_DISBALANCE] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SET_LIMIT_POWER] = NOMINAL_SET_LIMIT_POWER; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_UFCONST_VECTOR] = 1; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_SCALAR_FOC] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_GO] = 1; - - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_PUMP] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_ENABLE_ON_CHARGE] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_QTV] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_ON_UMP] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_MANUAL_DISCHARGE] = 0; - - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_ROTOR_POWER] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_INTERRUPT_SYNC] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_DISABLE_INTERRUPT_TIMER2] = 0; - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_STOP_LOGS] = 0; - - control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD; - control_station.array_cmd[CONTROL_STATION_MPU_SVU_CAN][CONTROL_STATION_CMD_SET_U_ZARYAD] = NOMINAL_U_ZARYAD; - - control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][CONTROL_STATION_CMD_WDOG_OFF] = 0; - for (int i = 0; i < CONTROL_STATION_CMD_LAST; i++) control_station.array_cmd[CONTROL_STATION_TERMINAL_CAN][i] = control_station.array_cmd[CONTROL_STATION_TERMINAL_RS232][i]; @@ -96,60 +75,283 @@ void edrk_init_variables_matlab(void) void edrk_init_matlab(void) { - edrk.Uzad_max = _IQ(K_STATOR_MAX); // макс амплитуда в Км для минимального импульса = DEF_PERIOD_MIN_MKS - edrk.iq_bpsi_normal = _IQ(BPSI_NORMAL / NORMA_FROTOR); - // edrk.iq_bpsi_max = _IQ(BPSI_MAXIMAL/NORMA_FROTOR); - // edrk.iq_f_provorot = _IQ(F_PROVOROT/NORMA_FROTOR); + edrk.Uzad_max = _IQ(K_STATOR_MAX); // макс амплитуда в Км для минимального импульса = DEF_PERIOD_MIN_MKS + edrk.iq_bpsi_normal = _IQ(BPSI_NORMAL / NORMA_FROTOR); + // edrk.iq_f_provorot = _IQ(F_PROVOROT/NORMA_FROTOR); - edrk.flag_enable_update_hmi = 1; + init_simple_scalar(); - - edrk.zadanie.ZadanieU_Charge = NOMINAL_U_ZARYAD; - edrk.zadanie.iq_ZadanieU_Charge = _IQ(NOMINAL_U_ZARYAD / NORMA_ACP); - - edrk.zadanie.iq_set_break_level = _IQ(NOMINAL_U_BREAK_LEVEL / NORMA_ACP); - - control_station.setup_time_detect_active[CONTROL_STATION_TERMINAL_RS232] = 50; + edrk.flag_enable_update_hmi = 1; } void set_zadanie_u_charge_matlab(void) { - // edrk.ZadanieU_Charge = edrk.ZadanieU_Charge_RS; +// edrk.ZadanieU_Charge = edrk.ZadanieU_Charge_RS; - // edrk.iq_ZadanieU_Charge = _IQ(edrk.ZadanieU_Charge/NORMA_ACP); +// edrk.iq_ZadanieU_Charge = _IQ(edrk.ZadanieU_Charge/NORMA_ACP); - if (edrk.zadanie.ZadanieU_Charge <= 100) + if (edrk.zadanie.ZadanieU_Charge<=100) { - edrk.iqMIN_U_ZPT = _IQ(-50.0 / NORMA_ACP); - edrk.iqMIN_U_IN = _IQ(-50.0 / NORMA_ACP); + edrk.iqMIN_U_ZPT = _IQ(-50.0/NORMA_ACP); + edrk.iqMIN_U_IN = _IQ(-50.0/NORMA_ACP); } else { - edrk.iqMIN_U_ZPT = _IQ(edrk.zadanie.ZadanieU_Charge * MIN_U_PROC / NORMA_ACP); - edrk.iqMIN_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge * MIN_U_PROC / NORMA_ACP); + edrk.iqMIN_U_ZPT = _IQ(edrk.zadanie.ZadanieU_Charge*MIN_U_PROC/NORMA_ACP); + edrk.iqMIN_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge*MIN_U_PROC/NORMA_ACP); } - if (edrk.zadanie.ZadanieU_Charge < LEVEL_DETECT_U_SMALL) + if (edrk.zadanie.ZadanieU_Charge U_D_MAX_ERROR_GLOBAL) - edrk.iqMAX_U_ZPT_Global = U_D_MAX_ERROR_GLOBAL; + if (edrk.iqMAX_U_ZPT_Global>U_D_MAX_ERROR_GLOBAL_2800) + edrk.iqMAX_U_ZPT_Global = U_D_MAX_ERROR_GLOBAL_2800; } - edrk.iqMAX_U_ZPT = edrk.iqMAX_U_ZPT_Global;//_IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); - edrk.iqMAX_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge * MAX_U_PROC / NORMA_ACP); + edrk.iqMAX_U_ZPT = _IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); + edrk.iqMAX_U_IN = _IQ(edrk.zadanie.ZadanieU_Charge*MAX_U_PROC/NORMA_ACP); - edrk.zadanie.iq_set_break_level = _IQ(NOMINAL_U_BREAK_LEVEL / NORMA_ACP); -} \ No newline at end of file +} + + +void init_ramp_all_zadanie(void) +{ + _iq rampafloat; + + // rmp_fzad + edrk.zadanie.rmp_fzad.RampLowLimit = _IQ(-MAX_ZADANIE_F / NORMA_FROTOR); //0 + edrk.zadanie.rmp_fzad.RampHighLimit = _IQ(MAX_ZADANIE_F / NORMA_FROTOR); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_F)); + edrk.zadanie.rmp_fzad.RampPlus = rampafloat; + edrk.zadanie.rmp_fzad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_fzad.DesiredInput = 0; + edrk.zadanie.rmp_fzad.Out = 0; + + // rmp_oborots_hz + edrk.zadanie.rmp_oborots_zad_hz.RampLowLimit = _IQ(MIN_ZADANIE_OBOROTS_ROTOR / 60.0 / NORMA_FROTOR); //0 + edrk.zadanie.rmp_oborots_zad_hz.RampHighLimit = _IQ(MAX_ZADANIE_OBOROTS_ROTOR / 60.0 / NORMA_FROTOR); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_OBOROTS_ROTOR)); + edrk.zadanie.rmp_oborots_zad_hz.RampPlus = rampafloat; + edrk.zadanie.rmp_oborots_zad_hz.RampMinus = -rampafloat; + + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + edrk.zadanie.rmp_oborots_zad_hz.Out = 0; + + + // + edrk.zadanie.rmp_Izad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_Izad.RampHighLimit = _IQ(MAX_ZADANIE_I_M / NORMA_ACP); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_I_M)); + edrk.zadanie.rmp_Izad.RampPlus = rampafloat; + edrk.zadanie.rmp_Izad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_Izad.DesiredInput = 0; + edrk.zadanie.rmp_Izad.Out = 0; + + // + edrk.zadanie.rmp_ZadanieU_Charge.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_ZadanieU_Charge.RampHighLimit = _IQ(MAX_ZADANIE_U_CHARGE / NORMA_ACP); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_U_CHARGE)); + edrk.zadanie.rmp_ZadanieU_Charge.RampPlus = rampafloat; + edrk.zadanie.rmp_ZadanieU_Charge.RampMinus = -rampafloat; + + edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = 0; + edrk.zadanie.rmp_ZadanieU_Charge.Out = 0; + + + + // + edrk.zadanie.rmp_k_u_disbalance.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_k_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_K_U_DISBALANCE); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_K_U_DISBALANCE)); + edrk.zadanie.rmp_k_u_disbalance.RampPlus = rampafloat; + edrk.zadanie.rmp_k_u_disbalance.RampMinus = -rampafloat; + + edrk.zadanie.rmp_k_u_disbalance.DesiredInput = 0; + edrk.zadanie.rmp_k_u_disbalance.Out = 0; + + + // + edrk.zadanie.rmp_kplus_u_disbalance.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_kplus_u_disbalance.RampHighLimit = _IQ(MAX_ZADANIE_KPLUS_U_DISBALANCE); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_KPLUS_U_DISBALANCE)); + edrk.zadanie.rmp_kplus_u_disbalance.RampPlus = rampafloat; + edrk.zadanie.rmp_kplus_u_disbalance.RampMinus = -rampafloat; + + edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = 0; + edrk.zadanie.rmp_kplus_u_disbalance.Out = 0; + + + + // + edrk.zadanie.rmp_kzad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_kzad.RampHighLimit = _IQ(MAX_ZADANIE_K_M); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_K_M)); + edrk.zadanie.rmp_kzad.RampPlus = rampafloat; + edrk.zadanie.rmp_kzad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.Out = 0; + + + + + + // + edrk.zadanie.rmp_powers_zad.RampLowLimit = _IQ(MIN_ZADANIE_POWER * 1000.0 / (NORMA_MZZ * NORMA_MZZ)); //0 + edrk.zadanie.rmp_powers_zad.RampHighLimit = _IQ(MAX_ZADANIE_POWER * 1000.0 / (NORMA_MZZ * NORMA_MZZ)); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_POWER)); + edrk.zadanie.rmp_powers_zad.RampPlus = rampafloat; + edrk.zadanie.rmp_powers_zad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_powers_zad.Out = 0; + + // + edrk.zadanie.rmp_limit_powers_zad.RampLowLimit = _IQ(0); //0 + edrk.zadanie.rmp_limit_powers_zad.RampHighLimit = _IQ(MAX_ZADANIE_POWER * 1000.0 / (NORMA_MZZ * NORMA_MZZ)); + + rampafloat = _IQ(1.0 / (2.0 * FREQ_PWM * T_NARAST_ZADANIE_POWER)); + edrk.zadanie.rmp_limit_powers_zad.RampPlus = rampafloat; + edrk.zadanie.rmp_limit_powers_zad.RampMinus = -rampafloat; + + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_limit_powers_zad.Out = 0; + + // + + +} + +void ramp_all_zadanie(int flag_set_zero) +{ + ////////////////////////////////////////////// + if (flag_set_zero == 0) + edrk.zadanie.rmp_Izad.DesiredInput = edrk.zadanie.iq_Izad; + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_Izad.DesiredInput = 0; + edrk.zadanie.rmp_Izad.Out = 0; + } + else + edrk.zadanie.rmp_Izad.DesiredInput = 0; + + edrk.zadanie.rmp_Izad.calc(&edrk.zadanie.rmp_Izad); + edrk.zadanie.iq_Izad_rmp = edrk.zadanie.rmp_Izad.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_ZadanieU_Charge.DesiredInput = edrk.zadanie.iq_ZadanieU_Charge; + edrk.zadanie.rmp_ZadanieU_Charge.calc(&edrk.zadanie.rmp_ZadanieU_Charge); + edrk.zadanie.iq_ZadanieU_Charge_rmp = edrk.zadanie.rmp_ZadanieU_Charge.Out; + ////////////////////////////////////////////// + if (flag_set_zero == 0) + edrk.zadanie.rmp_fzad.DesiredInput = edrk.zadanie.iq_fzad; + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_fzad.DesiredInput = 0; + edrk.zadanie.rmp_fzad.Out = 0; + } + else + edrk.zadanie.rmp_fzad.DesiredInput = 0; + + edrk.zadanie.rmp_fzad.calc(&edrk.zadanie.rmp_fzad); + edrk.zadanie.iq_fzad_rmp = edrk.zadanie.rmp_fzad.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_k_u_disbalance.DesiredInput = edrk.zadanie.iq_k_u_disbalance; + edrk.zadanie.rmp_k_u_disbalance.calc(&edrk.zadanie.rmp_k_u_disbalance); + edrk.zadanie.iq_k_u_disbalance_rmp = edrk.zadanie.rmp_k_u_disbalance.Out; + ////////////////////////////////////////////// + edrk.zadanie.rmp_kplus_u_disbalance.DesiredInput = edrk.zadanie.iq_kplus_u_disbalance; + edrk.zadanie.rmp_kplus_u_disbalance.calc(&edrk.zadanie.rmp_kplus_u_disbalance); + edrk.zadanie.iq_kplus_u_disbalance_rmp = edrk.zadanie.rmp_kplus_u_disbalance.Out; + ////////////////////////////////////////////// + if (flag_set_zero == 0) + edrk.zadanie.rmp_kzad.DesiredInput = edrk.zadanie.iq_kzad; + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.Out = 0; + } + else + edrk.zadanie.rmp_kzad.DesiredInput = 0; + edrk.zadanie.rmp_kzad.calc(&edrk.zadanie.rmp_kzad); + edrk.zadanie.iq_kzad_rmp = edrk.zadanie.rmp_kzad.Out; + ////////////////////////////////////////////// + if (flag_set_zero == 0) + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = edrk.zadanie.iq_oborots_zad_hz; + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + edrk.zadanie.rmp_oborots_zad_hz.Out = 0; + } + else + edrk.zadanie.rmp_oborots_zad_hz.DesiredInput = 0; + + edrk.zadanie.rmp_oborots_zad_hz.calc(&edrk.zadanie.rmp_oborots_zad_hz); + edrk.zadanie.iq_oborots_zad_hz_rmp = edrk.zadanie.rmp_oborots_zad_hz.Out; + + ////////////////////////////////////////////// + if (flag_set_zero == 0) + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad; + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_limit_powers_zad.Out = 0; + } + else + edrk.zadanie.rmp_limit_powers_zad.DesiredInput = 0; + + edrk.zadanie.rmp_limit_powers_zad.calc(&edrk.zadanie.rmp_limit_powers_zad); + edrk.zadanie.iq_limit_power_zad_rmp = edrk.zadanie.rmp_limit_powers_zad.Out; + + + + ////////////////////////////////////////////// + if (flag_set_zero == 0) + { + if (edrk.zadanie.iq_power_zad > edrk.zadanie.iq_limit_power_zad_rmp) + edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_limit_power_zad_rmp; + else + edrk.zadanie.rmp_powers_zad.DesiredInput = edrk.zadanie.iq_power_zad; + } + else + if (flag_set_zero == 2) + { + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + edrk.zadanie.rmp_powers_zad.Out = 0; + } + else + edrk.zadanie.rmp_powers_zad.DesiredInput = 0; + + edrk.zadanie.rmp_powers_zad.calc(&edrk.zadanie.rmp_powers_zad); + edrk.zadanie.iq_power_zad_rmp = edrk.zadanie.rmp_powers_zad.Out; + + + + +} diff --git a/Inu/main_matlab/main_matlab.c b/Inu/main_matlab/main_matlab.c index e04e43c..aeb75c3 100644 --- a/Inu/main_matlab/main_matlab.c +++ b/Inu/main_matlab/main_matlab.c @@ -21,6 +21,7 @@ EDRK edrk = EDRK_DEFAULT; FLAG f = FLAG_DEFAULTS; WRotorValues WRotor = WRotorValues_DEFAULTS; +WRotorValuesAngle WRotorPBus = WRotorValuesAngle_DEFAULTS; @@ -39,7 +40,7 @@ void mcu_simulate_step(void) wd = uf_alg.winding_displacement_bs2; } - detect_level_interrupt(edrk.flag_second_PCH); + detect_level_interrupt(); if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT || xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN) { @@ -53,10 +54,10 @@ void mcu_simulate_step(void) ramp_all_zadanie(0); // тут все по штатному - calc_norm_ADC_0(0); + calc_norm_ADC(0); vectorControlConstId(edrk.zadanie.iq_power_zad_rmp, edrk.zadanie.iq_oborots_zad_hz_rmp, - WRotor.RotorDirectionSlow, WRotor.iqWRotorSumFilter, + WRotorPBus.RotorDirection1, WRotor.iqWRotorCalcBeforeRegul1, edrk.Mode_ScalarVectorUFConst, edrk.MasterSlave, edrk.zadanie.iq_Izad, wd, edrk.master_theta, edrk.master_Iq, edrk.iq_power_kw_another_bs, @@ -319,7 +320,8 @@ void optical_bus_read(){ void optical_bus_write(void){ } - +void i_led1_on_off(int i) {} +void modbus_table_can_in(void) {} void init_flag_a(void) { diff --git a/Inu/main_matlab/param.c b/Inu/main_matlab/param.c index 2656f1e..1294f49 100644 --- a/Inu/main_matlab/param.c +++ b/Inu/main_matlab/param.c @@ -25,7 +25,7 @@ void readInputParameters(const real_T *u) { iq_norm_ADC[0][6] = _IQ(u[nn++]/NORMA_ACP); iq_norm_ADC[0][7] = _IQ(u[nn++]/NORMA_ACP); - WRotor.iqWRotorSumFilter = _IQ(u[nn++] / PI2 / NORMA_FROTOR); + WRotor.iqWRotorCalcBeforeRegul1 = _IQ(u[nn++] / PI2 / NORMA_FROTOR); u[nn++]; @@ -92,10 +92,10 @@ void writeOutputParameters(real_T* xD) { xD[nn++] = xpwm_time.Tc0_1; xD[nn++] = _IQtoF(edrk.Iq_to_slave); - xD[nn++] = _IQtoF(WRotor.iqWRotorSumFilter); + xD[nn++] = _IQtoF(0); xD[nn++] = 0; xD[nn++] = 0; - xD[nn++] = _IQtoF(WRotor.iqWRotorSumFilter); + xD[nn++] = _IQtoF(0); } \ No newline at end of file diff --git a/Inu/mcu_app_includes.h b/Inu/mcu_app_includes.h index 9885e4b..cfd1782 100644 --- a/Inu/mcu_app_includes.h +++ b/Inu/mcu_app_includes.h @@ -24,7 +24,6 @@ #include "adc_tools.h" #include "uf_alg_ing.h" #include "v_rotor.h" -#include "v_rotor_22220.h" #include "v_pwm24_v2.h" #include "control_station.h" #include "control_station_project.h" @@ -32,6 +31,8 @@ #include "RS_Functions.h" #include "master_slave.h" #include "xp_write_xpwm_time.h" +#include "global_time.h" +#include "PWMTools.h" #include #include diff --git a/allmex.m b/allmex.m index 13c6373..5e15982 100644 --- a/allmex.m +++ b/allmex.m @@ -7,19 +7,10 @@ delete("wrapper_inu.mexw64") delete("*.mexw64.pdb") status=system('run_mex.bat debug') + + if status==0 + beep else - error('Error!') -end - -% status=system('run_mex.bat wrapper_inu_2.c') -% if status==0 -% else -% error('Error!') -% end - -%mex -D"ML" -D"__IQMATHLIB_H_INCLUDED__" -D"_MATLAB_SIMULATOR" -I"..\device_support_ml\include" -I"." -I".\Inu" -I".\Inu\Src\main" -I".\Inu\Src\VectorControl" -I".\Inu\Src\main_matlab" -I".\Inu\Src\myLibs" -I".\Inu\Src\myXilinx" -outdir "." .\Inu\wrapper_inu_1.c .\Inu\controller.c .\Inu\init28335.c .\Inu\detcoeff.c .\Inu\isr.c .\Inu\main.c .\Inu\param.c .\Inu\upr.c .\Inu\Src\main_matlab\IQmathLib_matlab.c .\Inu\Src\main_matlab\main_matlab.c .\Inu\Src\main_matlab\adc_tools_matlab.c .\Inu\Src\myLibs\modbus_read_table.c .\Inu\Src\myLibs\my_filter.c .\Inu\Src\myLibs\pid_reg3.c .\Inu\Src\myLibs\svgen_dq_v2.c .\Inu\Src\myLibs\rmp_cntl_my1.c .\Inu\Src\myLibs\modbus_table.c .\Inu\Src\myLibs\mathlib.c .\Inu\Src\main_matlab\v_pwm24_matlab.c .\Inu\Src\main_matlab\xp_write_xpwm_time_matlab.c .\Inu\Src\main_matlab\errors_matlab.c .\Inu\Src\main\detect_overload.c .\Inu\Src\main\rotation_speed.c .\Inu\Src\main\global_time.c .\Inu\Src\main\PWMTools.c .\Inu\Src\VectorControl\pwm_vector_regul.c .\Inu\Src\VectorControl\abc_to_dq.c .\Inu\Src\VectorControl\regul_power.c .\Inu\Src\VectorControl\regul_turns.c .\Inu\Src\VectorControl\teta_calc.c .\Inu\Src\VectorControl\dq_to_alphabeta_cos.c ..\device_support_ml\source\C28x_FPU_FastRTS.obj ..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj -%mex -D"ML" -D"__IQMATHLIB_H_INCLUDED__" -D"_MATLAB_SIMULATOR" -I"..\device_support_ml\include" -I"." -I".\Inu" -I".\Inu\Src\main" -I".\Inu\Src\VectorControl" -I".\Inu\Src\main_matlab" -I".\Inu\Src\myLibs" -I".\Inu\Src\myXilinx" -outdir "." .\Inu\wrapper_inu_2.c .\Inu\controller.c .\Inu\init28335.c .\Inu\detcoeff.c .\Inu\isr.c .\Inu\main.c .\Inu\param.c .\Inu\upr.c .\Inu\Src\main_matlab\IQmathLib_matlab.c .\Inu\Src\main_matlab\main_matlab.c .\Inu\Src\main_matlab\adc_tools_matlab.c .\Inu\Src\myLibs\modbus_read_table.c .\Inu\Src\myLibs\my_filter.c .\Inu\Src\myLibs\pid_reg3.c .\Inu\Src\myLibs\svgen_dq_v2.c .\Inu\Src\myLibs\rmp_cntl_my1.c .\Inu\Src\myLibs\modbus_table.c .\Inu\Src\myLibs\mathlib.c .\Inu\Src\main_matlab\v_pwm24_matlab.c .\Inu\Src\main_matlab\xp_write_xpwm_time_matlab.c .\Inu\Src\main_matlab\errors_matlab.c .\Inu\Src\main\detect_overload.c .\Inu\Src\main\rotation_speed.c .\Inu\Src\main\global_time.c .\Inu\Src\main\PWMTools.c .\Inu\Src\VectorControl\pwm_vector_regul.c .\Inu\Src\VectorControl\abc_to_dq.c .\Inu\Src\VectorControl\regul_power.c .\Inu\Src\VectorControl\regul_turns.c .\Inu\Src\VectorControl\teta_calc.c .\Inu\Src\VectorControl\dq_to_alphabeta_cos.c ..\device_support_ml\source\C28x_FPU_FastRTS.obj ..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj - - -clear currFolder + error('Error!'); +end \ No newline at end of file diff --git a/run_mex.bat b/run_mex.bat index cfc449b..5518865 100644 --- a/run_mex.bat +++ b/run_mex.bat @@ -17,13 +17,9 @@ set includes_USER=-I"..\device_support_ml\include"^ :: исходный РєРѕРґ set params_main_c=.\Inu\Src\main\adc_tools.c^ .\Inu\Src\main\v_pwm24_v2.c^ - .\Inu\Src\main\limit_power.c^ - .\Inu\Src\main\limit_lib.c^ - .\Inu\Src\main\pll_tools.c^ .\Inu\Src\main\calc_rms_vals.c^ .\Inu\Src\main\alg_simple_scalar.c^ - .\Inu\Src\main\control_station_project.c^ - .\Inu\Src\main\ramp_zadanie_tools.c + .\Inu\Src\main\control_station_project.c set params_vectorcontorl_c=.\Inu\Src\N12_VectorControl\vector_control.c^ .\Inu\Src\N12_VectorControl\teta_calc.c^ @@ -38,13 +34,13 @@ set params_vectorcontorl_c=.\Inu\Src\N12_VectorControl\vector_control.c^ set params_libs_c=.\Inu\Src\N12_Libs\mathlib.c^ .\Inu\Src\N12_Libs\pid_reg3.c^ .\Inu\Src\N12_Libs\rmp_cntl_v1.c^ - .\Inu\Src\N12_Libs\rmp_cntl_v2.c^ .\Inu\Src\N12_Libs\filter_v1.c^ .\Inu\Src\N12_Libs\uf_alg_ing.c^ .\Inu\Src\N12_Libs\svgen_mf.c^ .\Inu\Src\N12_Libs\svgen_dq_v2.c^ .\Inu\Src\N12_Libs\control_station.c^ .\Inu\Src\N12_Libs\global_time.c^ + .\Inu\Src\N12_Libs\modbus_table_v2.c^ .\Inu\Src\N12_Xilinx\xp_write_xpwm_time.c