matlab_23550/Inu/app_wrapper/app_init.c
Razvalyaev 20a0a62cc8 #3 Переструктурирован проект, начата работа над улучшением модуля ШИМ (open #4)
- Папка app_wrapper содержит модули для управления приложением МК: инициализция, входы/выходы, вызов функций приложения

- Папка xilinx_wrapper содержит модули для имитации xilinx (на будущее, хочу вытащить в отдельные sfunction)

- Папка Src содержит исходный код приложения МК

- В корне Inu файлы для запуска приложения (модулей app_wrapper) и run_bat для компиляции sfunction
2025-01-17 10:19:40 +03:00

200 lines
6.9 KiB
C

/**************************************************************************
Description: Ïîñëå çàãðóçêè ïðîöåññîðà ôóíêöèÿ âûçûâàåòñÿ îäèí ðàç
è èíèöèàëèçèðóåò óïðàâëÿþùèå ðåãèñòðû ïðîöåññîðà
TMS320F28335/TMS320F28379D.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.10.04
**************************************************************************/
#include "app_init.h"
#define FREQ_TIMER_3 (FREQ_PWM*2)
void app_init(void) {
init_simple_scalar();
edrk.flag_second_PCH = 0;
edrk_init_variables_matlab();
init_global_time_struct(FREQ_TIMER_3);
Init_Adc_Variables();
svgen_pwm24_1.phase_sequence = SIMULINK_SEQUENCE;
svgen_pwm24_2.phase_sequence = SIMULINK_SEQUENCE;
edrk.zadanie.iq_Izad = _IQ(1);
edrk.disable_alg_u_disbalance = 1;
edrk.zadanie.iq_limit_power_zad = _IQ(1);
edrk.flag_enable_update_hmi = 1;
edrk.temper_limit_koeffs.sum_limit = _IQ(1);
simple_scalar1.fzad_add_max = _IQ(FZAD_ADD_MAX);
//edrk.Mode_ScalarVectorUFConst = ALG_MODE_SCALAR_POWER;
edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
edrk.zadanie.iq_power_zad = _IQ(1);
edrk.zadanie.iq_oborots_zad_hz = _IQ(1);
edrk.MasterSlave = MODE_MASTER;
edrk.master_theta;
edrk.master_Iq;
edrk.iq_power_kw_another_bs = edrk.P_to_master;
edrk.tetta_to_slave;
edrk.Iq_to_slave;
edrk.P_to_master;
uf_alg.winding_displacement_bs1;
//edrk.zadanie.iq_set_break_level = _IQ(2500 / NORMA_ACP);
control_station.setup_time_detect_active[CONTROL_STATION_TERMINAL_RS232] = 50;
//analog_zero.iqU_1 = 2048;
//analog_zero.iqU_2 = 2048;
} //void app_init(void)
void edrk_init_variables_matlab(void)
{
initVectorControl();
InitXPWM(FREQ_PWM);
InitPWM_Variables(edrk.flag_second_PCH);
//#if(SENSOR_ALG==SENSOR_ALG_23550)
// rotorInit();
//#endif
//#if(SENSOR_ALG==SENSOR_ALG_22220)
// // 22220
// rotorInit_22220();
//#endif
control_station.clear(&control_station);
edrk_init_matlab();
init_ramp_all_zadanie();
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];
ramp_all_zadanie(2);
set_zadanie_u_charge_matlab();
init_Uin_rms();
}
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.flag_enable_update_hmi = 1;
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;
}
void set_zadanie_u_charge_matlab(void)
{
// edrk.ZadanieU_Charge = edrk.ZadanieU_Charge_RS;
// edrk.iq_ZadanieU_Charge = _IQ(edrk.ZadanieU_Charge/NORMA_ACP);
if (edrk.zadanie.ZadanieU_Charge <= 100)
{
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);
}
if (edrk.zadanie.ZadanieU_Charge < LEVEL_DETECT_U_SMALL)
{
edrk.iqMAX_U_ZPT_Predzaryad = _IQ(edrk.zadanie.ZadanieU_Charge * MAX_U_PROC_SMALL / NORMA_ACP);
edrk.iqMAX_U_ZPT_Global = edrk.iqMAX_U_ZPT_Predzaryad + _IQ(ADD_U_MAX_GLOBAL_SMALL / NORMA_ACP); // +500V
}
else
{
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;
}
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.zadanie.iq_set_break_level = _IQ(NOMINAL_U_BREAK_LEVEL / NORMA_ACP);
}
void init_flag_a(void)
{
//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;
//}
}