|
|
|
/*
|
|
|
|
* SystemControl.h
|
|
|
|
*
|
|
|
|
* Author: Aleksey Gerasimenko
|
|
|
|
* gerasimenko.aleksey.n@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "framework.h"
|
|
|
|
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
|
|
|
|
#include "DSP2833x_Examples.h"
|
|
|
|
|
|
|
|
#include "FRAM/FRAMheaders.h"
|
|
|
|
#include "SYSCTRL/HeadersFLTSYSLIB.h"
|
|
|
|
#include "SYSCTRL/HeadersMODBUSRTU.h"
|
|
|
|
#include "SYSCTRL/SystemConfigurator.h"
|
|
|
|
#include "SYSCTRL/SystemEnvironment.h"
|
|
|
|
#include "SYSCTRL/VectorSpinner.h"
|
|
|
|
#include "SYSCTRL/TypeControl.h"
|
|
|
|
|
|
|
|
#include "SYSCTRL/MaxDetection.h" // for debug!!!
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef TRAPSWRST
|
|
|
|
#define TRAPSWRST __asm(" TRAP #20")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SYSCTRL_SYSTEMCONTROL_H_
|
|
|
|
#define SYSCTRL_SYSTEMCONTROL_H_
|
|
|
|
|
|
|
|
namespace SYSCTRL
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum mode_t {UNDEFINED, CONFIGURATE, OPERATIONAL};
|
|
|
|
private:
|
|
|
|
mode_t m_mode;
|
|
|
|
SYSCTRL::AlgorithmContext::algorithm_t m_algorithm_executed;
|
|
|
|
bool turnQ1On;
|
|
|
|
private:
|
|
|
|
// for debug!!!
|
|
|
|
MaxDetection IcellMax;
|
|
|
|
MaxDetection IloadMax;
|
|
|
|
MaxDetection IinputMax;
|
|
|
|
//Decompose Signals
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_input_a;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_input_b;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_input_c;
|
|
|
|
//
|
|
|
|
#if TYPEVOLTAGEDECOMPOSE == TYPEVOLTAGEDECOMPOSE_DIFFICULT
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_load_a;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_load_b;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_voltage_load_c;
|
|
|
|
#endif
|
|
|
|
#if TYPEVOLTAGEDECOMPOSE == TYPEVOLTAGEDECOMPOSE_SIMPLE
|
|
|
|
SYSCTRL::SignalDecomposeFI m_decompose_voltage_load_a;
|
|
|
|
SYSCTRL::SignalDecomposeFI m_decompose_voltage_load_b;
|
|
|
|
SYSCTRL::SignalDecomposeFI m_decompose_voltage_load_c;
|
|
|
|
#endif
|
|
|
|
//
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_load_a;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_load_b;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_load_c;
|
|
|
|
//
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_bypass_a;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_bypass_b;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_bypass_c;
|
|
|
|
//
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_cell_a;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_cell_b;
|
|
|
|
SYSCTRL::SignalDecomposeFIV m_decompose_current_cell_c;
|
|
|
|
//
|
|
|
|
private:
|
|
|
|
//
|
|
|
|
// RMS Filters
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_input_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_input_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_input_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_cell_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_cell_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_cell_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_load_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_load_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_load_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_input_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_voltage_load_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_a;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_b;
|
|
|
|
FLTSYSLIB::RMSF4O m_rms_filter_current_bypass_c;
|
|
|
|
//
|
|
|
|
private:
|
|
|
|
//
|
|
|
|
// Zero Drift Analog Signals
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_input_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_input_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_input_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_input_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_input_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_input_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_cell_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_cell_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_cell_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_load_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_load_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_voltage_load_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_load_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_load_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_load_c;
|
|
|
|
//
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_bypass_a;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_bypass_b;
|
|
|
|
FLTSYSLIB::FilterForth m_zero_filter_current_bypass_c;
|
|
|
|
//
|
|
|
|
private:
|
|
|
|
//Cell DC Voltage Filter
|
|
|
|
FLTSYSLIB::FilterForth m_cell_dc_voltage_a_filter;
|
|
|
|
FLTSYSLIB::FilterForth m_cell_dc_voltage_b_filter;
|
|
|
|
FLTSYSLIB::FilterForth m_cell_dc_voltage_c_filter;
|
|
|
|
//
|
|
|
|
private:
|
|
|
|
//PLL-ABC & Relative Input Voltage
|
|
|
|
SYSCTRL::SignalRelative m_relative_filter_voltage_input_a;
|
|
|
|
SYSCTRL::SignalRelative m_relative_filter_voltage_input_b;
|
|
|
|
SYSCTRL::SignalRelative m_relative_filter_voltage_input_c;
|
|
|
|
FLTSYSLIB::PLLABCDVR m_pll_abc_input_voltage;
|
|
|
|
private:
|
|
|
|
//Harmonica Analyzer
|
|
|
|
FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_a_harmonica_filter_5;
|
|
|
|
FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_b_harmonica_filter_5;
|
|
|
|
FLTSYSLIB::HarmonicaFilter4Order m_voltage_input_c_harmonica_filter_5;
|
|
|
|
private:
|
|
|
|
//Phase Alert monitor
|
|
|
|
SYSCTRL::PhaseAlertMonitor m_phase_alert_monitor;
|
|
|
|
private:
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_enable_work_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_system_fault_trigger;
|
|
|
|
private:
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_q1_control_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km1_control_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km2_control_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km3_control_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km11_control_on_off_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km11t_control_on_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km11t_control_off_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km1_external_command_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_km3_external_command_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_q1_external_command_trigger;
|
|
|
|
SYSCTRL::TriggerRegisterStructure m_vs_protection_control_trigger;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SYSCTRL::ContactorFault m_q1_control_fault;
|
|
|
|
SYSCTRL::ContactorFault m_km1_control_fault;
|
|
|
|
SYSCTRL::ContactorFault m_km2_control_fault;
|
|
|
|
SYSCTRL::ContactorFault m_km3_control_fault;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SYSCTRL::SystemControlSetup m_system_setup;
|
|
|
|
SYSCTRL::SystemControlConfiguration m_system_configuration;
|
|
|
|
SYSCTRL::SystemEnvironment m_environment;
|
|
|
|
SYSCTRL::AlgorithmContext m_algorithm;
|
|
|
|
FRAM::FRAMDATABASE m_fram_db;
|
|
|
|
private:
|
|
|
|
MODBUSRTU::RUBUS_REGISTER_32 m_test_read_word;
|
|
|
|
MODBUSRTU::RUBUS_REGISTER_32 m_test_write_word;
|
|
|
|
MODBUSRTU::RUBUS m_rubus;
|
|
|
|
MODBUSRTU::RUBUSDataBase m_rubus_data;
|
|
|
|
uint16_t m_modbus_break_counter;
|
|
|
|
public:
|
|
|
|
SYSCTRL::HardwareAnalogCurrentFaultRegister hardware_analog_current_fault;
|
|
|
|
public:
|
|
|
|
SystemControl();
|
|
|
|
void setup();
|
|
|
|
void configure();
|
|
|
|
void reload();
|
|
|
|
public:
|
|
|
|
void process_analog_input(AnalogInput& analog_input);
|
|
|
|
void process_digital_input(DigitalInput& digital_input);
|
|
|
|
Uint32 get_digital_output();
|
|
|
|
public:
|
|
|
|
void setup_hvcell();
|
|
|
|
void send_hvcell_syn_signal();
|
|
|
|
void send_hvcell_control_order();
|
|
|
|
void set_hvcell_level();
|
|
|
|
void get_pwm_version();
|
|
|
|
void get_hvcell_state();
|
|
|
|
void get_hvcell_dc_voltage();
|
|
|
|
void get_hvcell_version();
|
|
|
|
void send_hvcell_modulate_data();
|
|
|
|
void get_cpu_cpld_version();
|
|
|
|
void hardware_diagnostic();
|
|
|
|
public:
|
|
|
|
bool slow_loop_is_active();
|
|
|
|
void slow_loop_execute();
|
|
|
|
private:
|
|
|
|
void (SystemControl::*_slow_loop_execute)();
|
|
|
|
void _slow_loop_undef();
|
|
|
|
void _slow_loop_operational();
|
|
|
|
public:
|
|
|
|
bool additional_loop_is_active();
|
|
|
|
void execute_additional();
|
|
|
|
public:
|
|
|
|
bool symmetrical_calculator_loop_is_active();
|
|
|
|
void execute_symmetrical_calculator();
|
|
|
|
private:
|
|
|
|
void (SystemControl::*_execute_additional)();
|
|
|
|
void _additional_undef();
|
|
|
|
void _additional_operational();
|
|
|
|
public:
|
|
|
|
void execute();
|
|
|
|
private:
|
|
|
|
void (SystemControl::*_execute)();
|
|
|
|
void _execute_ubdef();
|
|
|
|
void _execute_operational();
|
|
|
|
public:
|
|
|
|
void get_hard_code_setup();
|
|
|
|
void get_hard_code_configuration();
|
|
|
|
void upload_configuration();
|
|
|
|
public:
|
|
|
|
void harmonica_multiplyer(float cos_alpha, float sin_alpha, float cos_beta, float sin_beta, float& out_cos, float& out_sin);
|
|
|
|
public:
|
|
|
|
void protection_thyristor_control();
|
|
|
|
private:
|
|
|
|
void _rms_module_calculator(float xa, float xb, float xc, float& xrms);
|
|
|
|
private:
|
|
|
|
inline void _trigger_protection_thyristor_control();
|
|
|
|
public:
|
|
|
|
void inc_break_counter();
|
|
|
|
void set_break_counter(Uint16 count);
|
|
|
|
void modbusrtu_rubus_interface(Uint16 rdReg[], Uint16 wrReg[]);
|
|
|
|
private:
|
|
|
|
void _modbusrtu_rubus_read_write_register();
|
|
|
|
inline void _modbusrtu_rubus_read_write_bool(bool& param);
|
|
|
|
inline void _modbusrtu_rubus_read_write_float(float& param);
|
|
|
|
inline void _modbusrtu_rubus_read_write_uint16(uint16_t& param);
|
|
|
|
inline void _modbusrtu_rubus_read_write_uint32(uint32_t& param);
|
|
|
|
inline void _modbusrtu_rubus_read_write_int16(int16_t& param);
|
|
|
|
inline void _modbusrtu_rubus_read_write_int32(int32_t& param);
|
|
|
|
void _modbusrtu_rubus_configurate();
|
|
|
|
private:
|
|
|
|
inline float hvcell_dc_voltage_reciprocal(float& voltage);
|
|
|
|
//
|
|
|
|
};
|
|
|
|
} /* namespace SYSCTRL */
|
|
|
|
#endif /* SYSCTRL_SYSTEMCONTROL_H_ */
|