diff --git a/Inu/def.h b/Inu/def.h index 7babedb..49488b2 100644 --- a/Inu/def.h +++ b/Inu/def.h @@ -211,280 +211,4 @@ #include "math.h" #include "C28x_FPU_FastRTS.h" - -// (. control_current()) -struct Cc { - short once; - float KpOrig; - float KiOrig; - float Kp; - float Ki; - float K1; - float K2; - float K3; - float Xyff; - float yffAux2; - float yffAux3; - float del; - float kYlim; - float yd1P; - float yd1I; - float yd1FF; - float yd1; - float yq1P; - float yq1I; - float yq1FF; - float yq1; - float y1; - float yd2P; - float yd2I; - float yd2FF; - float yd2; - float yq2P; - float yq2I; - float yq2FF; - float yq2; - float y2; - short y1LimFlag; - short y2LimFlag; -}; //Cc - - -// (. control_flux()) -struct Cf { - short once; - float KpOrig; - float KiOrig; - float Kp; - float Ki; - float IdLim; - float IdLimNeg; - float del; - float idP; - float idI; - float idFF; - short idLimFlag; -}; //Cf - - -// (. control_speed_power()) -struct Csp { - short once; - float KpOrig; - float KiOrig; - float Kp; - float Ki; - float kMeNom; - float del; - float iqP; - float iqI; - float iqFF; - float IlimIncr; - float iqLimAux; - float iqLimZi; - float IqLim; - float IqLimNeg; - float iqLim; - float iqLimNeg; - float delWmAbs; - float KizIncr; - float pmZiRampDown; - float wmLimZi; - float pmLimZi; - short iqLimFlag; -}; //Csp - - -// EEPROM -struct Eprom { - short writeRequestNumber; - short readFaultNo; -}; //Eprom - - -// -struct Emerg { - float udc1; - float udc2; - float iac1; - float iac2; - float me; - float wm; - float pm; -}; //Emerg - - -// inverse park (. ipark()) -struct Ip { - float yx1Aux; - float yy1Aux; - float yx2Aux; - float yy2Aux; - float theta; - float sinTheta; - float cosTheta; - float yx1; - float yy1; - float yx2; - float yy2; -}; //Ip - - -// indirect vector control (. indirect_vector_control()) -struct Ivc { - short once; - float im; - float wr; - float wsNf; - float ws; - float sinTheta; - float cosTheta; - float id1; - float iq1; - float psi; - float id2; - float iq2; -}; //Ivc - - -// , -struct Mst { - short pzMode; - short faultReset; - short start; - float wmZz; - float pmZz; - float wmLim; - float pmLim; - float pIncrMaxTy; - float pDecrMaxTy; -}; //Mst - - -// -struct Offset { - short Udc1; - short Udc2; - short Ic1; - short Ic2; - short Ia1; - short Ia2; - short Ib1; - short Ib2; -}; //Offset - - -// -struct Out { - float K; - float udc1; - float udc2; - float iac1; - float iac2; - float me; - float wm; - float pm; -}; //Out - - -// -struct Protect { - short IacMax; - short IacMin; - unsigned short Tdi24VSource; - volatile unsigned short tDI24VSource; - unsigned short TudcMin; - volatile unsigned short tUdc1Min; - volatile unsigned short tUdc2Min; - unsigned short TwmMax; - volatile unsigned short tWmMax; - float UdcMin; - float UdcMax; - float WmMax; -}; //Protect - - -// -struct Result { - short udc1; - short udc2; - short ic1; - short ic2; - short ia1; - short ia2; - short ib1; - short ib2; -}; //Result - - -// (. reference_flux()) -struct Rf { - short once; - float PsiZ; - float PsizIncr; - float psiZi; - float psiZCorr; - float psiSub; - float psiZCorr2; - float psiZ; - float KpsiSub; - float Kpsiz; - float WmNomPsi; - float YlimPsi; - float pPsiZ; - float psiZPrev1; - float psiZPrev2; - float psiZPrev3; -}; //Rf - - -// (. reference_power()) -struct Rp { - short once; - float pmZz; - float pmZi; - float pmZ; - float Kpmz; - float PlimIncr; - float KpIncrDecr; - volatile float pmEqv; -}; //Rp - - -// (. reference_speed()) -struct Rs { - short once; - float wmZz; - float wmZi; - float wmZ; - float Kwmz; - float WlimIncr; - float wzIncrNf; - float wzIncr; - float pWmZ; - float wmZPrev1; - float wmZPrev2; - float wmZPrev3; - short tPwmZ; -}; //Rs - - -// -struct SgmPar { - float Rs; - float Lls; - float Rr; - float Llr; - float Lm; - float Ls; - float Lr; - float SigmaLs; - float LmInv; - float LrInv; - float Tr; - float TrInv; - float Kl; - float KlInv; -}; //SgmPar - #endif //DEF diff --git a/Inu/main_matlab/main_matlab.c b/Inu/main_matlab/main_matlab.c index 6c245f5..e04e43c 100644 --- a/Inu/main_matlab/main_matlab.c +++ b/Inu/main_matlab/main_matlab.c @@ -1,4 +1,5 @@ #include "mcu_wrapper_conf.h" +#include "pwm_sim.h" //#include "edrk_main.h" //#include "vector.h" //#include "vector_control.h" @@ -91,6 +92,20 @@ void mcu_simulate_step(void) +unsigned int ReadMemory(unsigned long addr) +{ + unsigned int returnval = 0; + if (addr == ADR_SAW_VALUE) + returnval = t1sim.tcnt; + //return (*(volatile int *)(addr)); + return returnval; +} + + +void WriteMemory(unsigned long addr, unsigned int data) +{ + //(*(volatile int *)( addr )) = data; +} void project_read_all_pbus2() @@ -191,17 +206,6 @@ void pause_1000(void) int xerror(unsigned int er_ID, void* CallBackRef) { }; -unsigned int ReadMemory(unsigned long addr) -{ - //return (*(volatile int *)(addr)); - return 0; -} - - -void WriteMemory(unsigned long addr, unsigned int data) -{ - //(*(volatile int *)( addr )) = data; -} void func_unpack_answer_from_Ingeteam(unsigned int a) {} void unpack_answer_from_MPU_SVU_CAN(unsigned int a) {} diff --git a/Inu/main_matlab/pwm_sim.c b/Inu/main_matlab/pwm_sim.c index d2c89fc..395fa9a 100644 --- a/Inu/main_matlab/pwm_sim.c +++ b/Inu/main_matlab/pwm_sim.c @@ -51,7 +51,7 @@ void Init_Timers(void) void initSimulateTim(TimerSimHandle* tsim, int period, double step) { tsim->dtsim.stateDt = 1; - tsim->TPr = period/2; + tsim->TPr = period; tsim->TxCntPlus = step; tsim->dtsim.DtCntPeriod = (int)(DT / hmcu.SimSampleTime); } diff --git a/Inu/mcu_wrapper.c b/Inu/mcu_wrapper.c index a38e886..d91c7eb 100644 --- a/Inu/mcu_wrapper.c +++ b/Inu/mcu_wrapper.c @@ -86,7 +86,7 @@ void MCU_Periph_Simulation(void) /** * @brief Считывание входов S-Function в порты ввода-вывода. * @param S - указатель на структуру S-Function из "simstruc.h" - * @details Пользовательский код, который записывает порты ввода-вывода из входов S-Function. + * @details Пользовательский код, который записывает входы МК из входов S-Function. */ void MCU_readInputs(SimStruct* S) { @@ -124,15 +124,16 @@ void MCU_writeOutputs(SimStruct* S) */ void SIM_Initialize_Simulation(void) { - // инициализация потока, который будет выполнять код МК #ifdef RUN_APP_THRREAD + // инициализация потока, который будет выполнять код МК hmcu.hMCUThread = (HANDLE)CreateThread(NULL, 0, MCU_App_Thread, 0, CREATE_SUSPENDED, &hmcu.idMCUThread); #endif //RUN_APP_THRREAD + /* user initialization */ Init_Timers(); init28335(); - /* wrapper initialization */ + /* clock step initialization */ hmcu.SystemClock_step = MCU_CORE_CLOCK * hmcu.SimSampleTime; // set system clock step } /* MCU WRAPPER DEINITIALIZATION */ diff --git a/Inu/mcu_wrapper_conf.h b/Inu/mcu_wrapper_conf.h index ecd8cb8..505e38f 100644 --- a/Inu/mcu_wrapper_conf.h +++ b/Inu/mcu_wrapper_conf.h @@ -86,12 +86,12 @@ typedef struct { int idMCUThread; ///< id потока МК (unused) // Flags unsigned fMCU_Stop : 1; ///< флаг для выхода из потока программы МК - double SimSampleTime; ///< sample time of simulation + double SimSampleTime; ///< sample time of simulation double SystemClockDouble; ///< Счетчик в формате double для точной симуляции системных тиков С промежуточными значений long SystemClock; ///< Счетчик тактов для симуляции системных тиков (в целочисленном формате) double SystemClock_step; ///< Шаг тиков для их симуляции, в формате double - double SimTime; + double SimTime; ///< Текущее время симуляции }SIM__MCUHandleTypeDef; extern SIM__MCUHandleTypeDef hmcu; // extern для видимости переменной во всех файлах