алгоритм векторного управления вызывается и даже что-то считает. теперь надо завести в него уставки и измерения с ротора

This commit is contained in:
Razvalyaev 2025-01-13 13:05:34 +03:00
parent 7e0063eee0
commit adf0437341
15 changed files with 1271 additions and 2908 deletions

File diff suppressed because it is too large Load Diff

View File

@ -622,6 +622,7 @@ long exp_fixedN(long x, unsigned int n);
#define _IQdiv(A,B) divide(A,B)
#define _IQ19div(A,B) divide19(A,B)
#define _IQ18div(A,B) divideN(A,B,18)
#define _IQ22div(A,B) divideN(A,B,22)
#define _IQsin(A) sin_fixed(A)
#define _IQcos(A) cos_fixed(A)
#define _IQsinPU(A) sin_fixed(A)

View File

@ -40,6 +40,8 @@ long long multiply_fixed_base_select(long long x, long long y, int base)
long divide(long num, long den)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << GLOBAL_Q) / den;
return (long)quotient;
@ -47,6 +49,8 @@ long divide(long num, long den)
long divide19(long num, long den)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << 19) / den;
return (long)quotient;
@ -54,6 +58,8 @@ long divide19(long num, long den)
long divideN(long num, long den, unsigned int d)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << d) / den;
return (long)quotient;
@ -61,6 +67,8 @@ long divideN(long num, long den, unsigned int d)
//
static inline long long divide_fixed_base_select(long long num, long long den, int base)
{
if (den == 0)
return 0;
long long quotient = ((long long)num << base) / den;
return quotient;
}

View File

@ -0,0 +1,67 @@
/**************************************************************************
Description: Ïîñëå çàãðóçêè ïðîöåññîðà ôóíêöèÿ âûçûâàåòñÿ îäèí ðàç
è èíèöèàëèçèðóåò óïðàâëÿþùèå ðåãèñòðû ïðîöåññîðà
TMS320F28335/TMS320F28379D.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.10.04
**************************************************************************/
#include "def.h"
#include "init28335.h"
#define FREQ_TIMER_3 (FREQ_PWM*2)
void init28335(void) {
edrk.flag_second_PCH = 0;
edrk_init_variables_matlab();
init_global_time_struct(FREQ_TIMER_3);
} //void init28335(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();
}
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;
}

View File

@ -0,0 +1,10 @@
#ifndef INIT28335
#define INIT28335
#include "controller.h"
void init28335(void);
void edrk_init_matlab(void);
void edrk_init_variables_matlab(void);
#endif //INIT28335

View File

@ -9,6 +9,7 @@
#include "edrk_main.h"
#include "vector.h"
#include "vector_control.h"
#include "v_rotor.h"
T_project project = {0};
@ -17,6 +18,7 @@ WINDING a;
EDRK edrk = EDRK_DEFAULT;
FLAG f = FLAG_DEFAULTS;
WRotorValues WRotor = WRotorValues_DEFAULTS;
void project_read_all_pbus2()
{
@ -93,6 +95,11 @@ _iq break_result_4 = 0;
// }
void update_uom(void)
{
}
void inc_RS_timeout_cicle(void)
{

View File

@ -3,16 +3,6 @@
#include "vector.h"
#include "edrk_main.h"
typedef union {
//unsigned int all;
int all;
// struct MODBUS_BITS_STRUCT bit;
// struct MODBUS_WORD_STRUCT byte;
} MODBUS_REG_STRUCT;
//extern MODBUS_REG_STRUCT modbus_table_in[1024];
//extern MODBUS_REG_STRUCT modbus_table_out[1024];
void init_flag_a(void);

View File

@ -10,12 +10,8 @@
#include "simstruc.h"
#include "wrapper_inu.h"
#include "def.h"
#include "controller.h"
#include "edrk_main.h"
#include "vector.h"
#include "vector_control.h"
#include "init28335.h"
extern UMotorMeasure motor;
@ -146,156 +142,13 @@ void processSFunctionIfChanged(SimStruct *S, int_T *iW) {
}
void initialisationOnStart(int_T *iW) {
//// êîå-÷òî âûïîëíÿåì îäèí ðàç ïðè çàïóñêå ìîäåëè
// if ( iW[1] == 1 ) {
// iW[1] = 0;
//
// timers_adc = 0;
// timers_pwm = 0;
//
// // èíèöèàëèçàöèÿ ïðîöåññîðà
// init28335();
//
// init_DQ_pid();
//
// // èìèòàöèÿ ñ÷èòûâàíèÿ ïàðàìåòðîâ èç EEPROM
// // ... ïàðàìåòðû èç ìîäåëè (ñì. áëîê "Parameters")
// for ( j = FIRST_WRITE_PAR_NUM; j < paramNo; j++ ) {
// param[j] = paramNew[j];
// }
// // ... ïàðàìåòðû èç ôàéëà
// param[180] = 930;//rf.PsiZ, %*10 îò PSI_BAZ
//
// param[200] = 2048;//offset.Ia1, åä. ÀÖÏ
// param[201] = 2048;//offset.Ib1, åä. ÀÖÏ
// param[202] = 2048;//offset.Ic1, åä. ÀÖÏ
// param[203] = 2048;//offset.Udc1, åä. ÀÖÏ
// param[206] = 2048;//offset.Ia2, åä. ÀÖÏ
// param[207] = 2048;//offset.Ib2, åä. ÀÖÏ
// param[208] = 2048;//offset.Ic2, åä. ÀÖÏ
// param[209] = 2048;//offset.Udc2, åä. ÀÖÏ
//
// param[210] = 100;//cc.Kp, %
// param[211] = 100;//cc.Ki, %
// param[212] = 100;//cf.Kp, %
// param[213] = 100;//cf.Ki, %
// param[214] = 100;//csp.Kp, %
// param[215] = 100;//csp.Ki, %
//
// param[220] = 99;//protect.IacMax, % îò IAC_SENS_MAX
// param[221] = 130;//protect.UdcMax, % îò U_NOM
// param[222] = 110;//IzLim, % îò I_BAZ (ä.á. áîëüøå cf.IdLim)
// param[223] = 105;//cf.IdLim, % îò I_BAZ (ä.á. ìåíüøå IzLim)
// param[224] = 105;//csp.IqLim, % îò I_BAZ
// param[225] = 97;//protect.UdcMin, % îò U_NOM
// param[226] = 115;//protect.WmMax, % îò N_NOM
// param[228] = 103;//rf.WmNomPsi, % îò N_NOM
// param[229] = 97;//rf.YlimPsi, % îò Y_LIM
// param[231] = 300;//protect.TudcMin, ìñ
// param[233] = 1000;//protect.TwmMax, ìñ
//
// param[244] = 26000;//rs.WlimIncr, ìñ
// param[245] = 2000;//csp.IlimIncr, ìñ
// param[248] = 6000;//rp.PlimIncr, ìñ
//
// param[269] = 9964;//9700;//KmeCorr, %*100
//
// param[285] = 10;//Kudc, ìñ*10
// param[286] = 700;//Kwm, ìñ*10
// param[288] = 250;//rs.Kwmz, ìñ
// param[289] = 50;//rf.Kpsiz, ìñ
// param[290] = 40;//Kme, ìñ
// param[292] = 80;//rp.Kpmz, ìñ
//
// param[303] = (unsigned short)(19200.);//sgmPar.Rs, ìêÎì
// param[304] = (unsigned short)(19364.);//sgmPar.Lls, ìêÃí*10
// param[305] = (unsigned short)(8500.);//sgmPar.Rr, ìêÎì
// param[306] = (unsigned short)(10212.);//sgmPar.Llr, ìêÃí*10
// param[307] = (unsigned short)(35810.);//sgmPar.Lm, ìêÃí
//
// // èíèöèàëèçàöèÿ ïðîãðàììû
// detcoeff();
//
// // äëÿ ìîäåëèðîâàíèÿ òàéìåðîâ
// T1Pr = (double)EPwm1Regs.TBPRD;
// T2Pr = (double)EPwm2Regs.TBPRD;
// T3Pr = (double)EPwm3Regs.TBPRD;
// T4Pr = (double)EPwm4Regs.TBPRD;
// T5Pr = (double)EPwm5Regs.TBPRD;
// T6Pr = (double)EPwm6Regs.TBPRD;
// T7Pr = (double)EPwm7Regs.TBPRD;
// T8Pr = (double)EPwm8Regs.TBPRD;
// T9Pr = (double)EPwm9Regs.TBPRD;
// T10Pr = (double)EPwm10Regs.TBPRD;
// T11Pr = (double)EPwm11Regs.TBPRD;
// T12Pr = (double)EPwm12Regs.TBPRD;
// t1cntAux = (double)EPwm1Regs.TBCTR;
// t2cntAux = (double)EPwm2Regs.TBCTR;
// t3cntAux = (double)EPwm3Regs.TBCTR;
// t4cntAux = (double)EPwm4Regs.TBCTR;
// t5cntAux = (double)EPwm5Regs.TBCTR;
// t6cntAux = (double)EPwm6Regs.TBCTR;
// t7cntAux = (double)EPwm7Regs.TBCTR;
// t8cntAux = (double)EPwm8Regs.TBCTR;
// t9cntAux = (double)EPwm9Regs.TBCTR;
// t10cntAux = (double)EPwm10Regs.TBCTR;
// t11cntAux = (double)EPwm11Regs.TBCTR;
// t12cntAux = (double)EPwm12Regs.TBCTR;
// // ... ïðèðàùåíèå ñ÷¸ò÷èêîâ òàéìåðîâ çà øàã äèñêðåòèçàöèè
// TxCntPlus = FTBCLK*dt;
//
// // äëÿ ìîäåëèðîâàíèÿ eQEP
// Qposmax = (double)EQep2Regs.QPOSMAX;
// qposcnt = 1.;//(double)EQep2Regs.QPOSCNT;
//
// // äëÿ ìîäåëèðîâàíèÿ ÀÖÏ
// // (íà ñ÷¸ò 1e-6 ñì. SetupAdc(), õîòÿ òàì ñêîðåå íå 1.0 ìêñ, à 0.8 ìêñ)
//// Tadc = (int)(1e-6/dt);
// Tadc = (int)(1/FREQ_ADC_TIMER/dt);
//
// // ... íà âñÿêèé ñëó÷àé
// if ( Tadc < 1 )
// Tadc = 1;
// tAdc = 1;
// // ... ÷òîáû ÀÖÏ æäàë çàïóñêà
// nAdc = 0;
//
// // äëÿ ìîäåëèðîâàíèÿ Dead-Band Unit
// CntDt = (int)(DT/dt);
// stateDt1 = stateDt2 = stateDt3 = stateDt4 = stateDt5 = stateDt6 = 1;
// stateDt7 = stateDt8 = stateDt9 = stateDt10 = stateDt11 = stateDt12 = 1;
// cntDt1 = cntDt2 = cntDt3 = cntDt4 = cntDt5 = cntDt6 = 0;
// cntDt7 = cntDt8 = cntDt9 = cntDt10 = cntDt11 = cntDt12 = 0;
//
// // äëÿ çàùèò
// DI_24V_SOURCE_FAULT = 0;
//
// // äëÿ âûâîäà
// inuWork = 0;
// ivc.psi = 0;
// rf.psiZ = 0;
// rs.wmZ = 0;
// csp.wmLimZi = 0;
// pm = 0;
// rp.pmZ = 0;
// csp.pmLimZi = 0;
// id1 = 0;
// iq1 = 0;
// id2 = 0;
// iq2 = 0;
// idZ = 0;
// iqZ = 0;
// cf.idP = 0;
// cf.idFF = 0;
// cf.idI = 0;
// csp.iqP = 0;
// csp.iqFF = 0;
// csp.iqI = 0;
// cc.yd1 = 0;
// cc.yq1 = 0;
// cc.y1 = 0;
// cc.y2 = 0;
// } //if ( iW[1] == 1 )
// êîå-÷òî âûïîëíÿåì îäèí ðàç ïðè çàïóñêå ìîäåëè
if ( iW[1] == 1 ) {
iW[1] = 0;
init28335();
} //if ( iW[1] == 1 )
}
@ -1338,6 +1191,9 @@ void writeOutputParameters(real_T *xD) {
void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW, int_T *iW) {
static _iq Uzad1 = 0, Fzad = 0, Uzad2 = 0, Izad_out = 0, Uzad_from_master = 0;
_iq wd;
readInputParameters(u);
processSFunctionIfChanged(S, iW);
initialisationOnStart(iW);
@ -1357,4 +1213,33 @@ void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW, int_T *iW
writeOutputParameters(xD);
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;
} //void controller(SimStruct ...

View File

@ -1,3 +1,25 @@
#include "wrapper_inu.h"
#include "def.h"
#include "edrk_main.h"
#include "vector.h"
#include "vector_control.h"
#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 <params.h>
#include <params_alg.h>
#include <params_norma.h>
#include <params_pwm24.h>
#include <params_temper_p.h>
#include <project.h>
#ifndef __WRAPPER_CONTROLLER_H
#define __WRAPPER_CONTROLLER_H
// Ìàêñèìàëüíàÿ äëèíà ïàðàìåòðà-âåêòîðà
#define LEN_PARAM_MATR 21
@ -220,3 +242,5 @@ extern struct Ip ip;
extern unsigned short param[];
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â controller.c (end)
#endif //__WRAPPER_CONTROLLER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
#ifndef INIT28335
#define INIT28335
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â init28335.c (begin)
//#########################################################################
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â init28335.c (end)
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â init28335.c (begin)
//#########################################################################
#ifndef ML
extern Uint16 RamfuncsLoadStart, RamfuncsLoadEnd, RamfuncsRunStart;
extern Uint16 RamfuncsLoadStart2, RamfuncsLoadEnd2, RamfuncsRunStart2;
extern Uint16 SwitchLoadStart, SwitchLoadEnd, SwitchRunStart;
extern Uint16 EconstLoadStart, EconstLoadEnd, EconstRunStart;
extern short csmSuccess;
#endif //ML
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â init28335.c (end)
#endif //INIT28335

View File

@ -6,11 +6,11 @@
Дата последнего обновления: 2021.09.22
**************************************************************************/
#include "simstruc.h"
#ifndef WRAPPER
#define WRAPPER
#define INPUT_0_WIDTH 20 //кол-во входов
#define OUTPUT_0_WIDTH 49 //кол-во выходов
#define NPARAMS 1 //кол-во параметров (скаляров и векторов)

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,7 @@ set params_i=-I"..\device_support_ml\include"^
set params_o=-outdir "."
set params_wrapper_c=.\Inu\controller.c^
.\Inu\Src\main_matlab\init28335.c^
.\Inu\Src\main_matlab\main_matlab.c^
.\Inu\Src\main_matlab\IQmathLib_matlab.c
@ -29,7 +30,10 @@ set params_vectorcontorl_c=.\Inu\Src\N12_VectorControl\vector_control.c^
.\Inu\Src\N12_VectorControl\regul_power.c^
.\Inu\Src\N12_VectorControl\regul_turns.c^
.\Inu\Src\N12_VectorControl\abc_to_dq.c^
.\Inu\Src\N12_VectorControl\dq_to_alphabeta_cos.c
.\Inu\Src\N12_VectorControl\dq_to_alphabeta_cos.c^
.\Inu\Src\N12_VectorControl\alphabeta_to_dq.c^
.\Inu\Src\N12_VectorControl\abc_to_alphabeta.c^
.\Inu\Src\N12_VectorControl\alg_pll.c
set params_libs_c=.\Inu\Src\N12_Libs\mathlib.c^
@ -40,9 +44,15 @@ set params_libs_c=.\Inu\Src\N12_Libs\mathlib.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_Xilinx\xp_write_xpwm_time.c^
.\Inu\Src\main\adc_tools.c^
.\Inu\Src\main\v_pwm24_v2.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\ramp_zadanie_tools.c
set params_obj=..\device_support_ml\source\C28x_FPU_FastRTS.obj ..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj