Compare commits

..

No commits in common. "864a2dfcacafd0b604b01d3078536938ddb95d20" and "c2fb7c9684a2f3cc3a4da39630eee4eda39668db" have entirely different histories.

12 changed files with 41 additions and 199 deletions

View File

@ -152,7 +152,7 @@ static void mdlInitializeSizes(SimStruct *S)
*/
static void mdlStart(SimStruct *S)
{
SIM_Initialize_Simulation(S);
SIM_Initialize_Simulation();
}
#endif // MDL_START
@ -187,7 +187,7 @@ static void mdlTerminate(SimStruct *S)
hmcu.fMCU_Stop = 1;
ResumeThread(hmcu.hMCUThread);
WaitForSingleObject(hmcu.hMCUThread, 10000);
SIM_deInitialize_Simulation(S);
SIM_deInitialize_Simulation();
mexUnlock();
}

View File

@ -5,27 +5,19 @@
Дата последнего обновления: 2021.11.08
**************************************************************************/
#ifndef _APP_CONFIG
#define _APP_CONFIG
#ifndef DEF
#define DEF
// раскомментировать, если есть сдвиг между обмотками ГЭД (30 град.)
#define SHIFT
#define ALG_MODE_SIMULINK ALG_MODE_SCALAR_OBOROTS
/*
ALG_MODE_UF_CONST,
ALG_MODE_SCALAR_OBOROTS,
ALG_MODE_SCALAR_POWER,
ALG_MODE_FOC_OBOROTS,
ALG_MODE_FOC_POWER
*/
#define SIMULINK_SEQUENCE V_PWM24_PHASE_SEQ_NORMAL_ABC
/* V_PWM24_PHASE_SEQ_NORMAL_ABC,
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
/* V_PWM24_PHASE_SEQ_NORMAL_ABC, - êðàñèâûé òîê, íåêðàñèâîå íàïðÿæåíèÿ
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 - æîïà
*/
#endif //_APP_CONFIG
#endif //DEF

View File

@ -41,11 +41,11 @@ void app_init(void) {
edrk.zadanie.iq_ZadanieU_Charge = _IQ(2500 / NORMA_ACP);
edrk.temper_limit_koeffs.sum_limit = _IQ(1);
simple_scalar1.fzad_add_max = _IQ(FZAD_ADD_MAX);
edrk.Mode_ScalarVectorUFConst = ALG_MODE_SIMULINK;
//edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
//edrk.Mode_ScalarVectorUFConst = ALG_MODE_SCALAR_OBOROTS;
edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
edrk.zadanie.iq_power_zad = _IQ(1);
edrk.zadanie.iq_oborots_zad_hz = _IQ(1);
edrk.zadanie.iq_oborots_zad_hz = _IQ(0.5);
edrk.MasterSlave = MODE_MASTER;
edrk.master_theta;

View File

@ -1,5 +1,5 @@
#ifndef _APP_INIT
#define _APP_INIT
#ifndef INIT28335
#define INIT28335
#include "app_includes.h"
@ -10,4 +10,4 @@ void edrk_init_variables_matlab(void);
void set_zadanie_u_charge_matlab(void);
void init_Uin_rms(void);
void init_flag_a(void);
#endif //_APP_INIT
#endif //INIT28335

View File

@ -7,7 +7,6 @@
#include "app_io.h"
#include "pwm_sim.h"
#include "adc_sim.h"
int Unites[UNIT_QUA_UNITS][UNIT_LEN];
int CAN_timeout[UNIT_QUA];
@ -15,17 +14,17 @@ RS_DATA_STRUCT rs_a = RS_DATA_STRUCT_DEFAULT, rs_b = RS_DATA_STRUCT_DEFAULT;
// Èçìåíÿåò çíà÷åíèå ïàðàìåòðà
void readInputParameters(const real_T* u) {
int nn = 0;
iq_norm_ADC[0][0] = _IQ(AdcSim.udc1.adc_val);
iq_norm_ADC[0][1] = _IQ(AdcSim.udc2.adc_val);
iq_norm_ADC[0][2] = _IQ(AdcSim.ia1.adc_val);
iq_norm_ADC[0][3] = _IQ(AdcSim.ib1.adc_val);
iq_norm_ADC[0][4] = _IQ(AdcSim.ic1.adc_val);
iq_norm_ADC[0][5] = _IQ(AdcSim.ia2.adc_val);
iq_norm_ADC[0][6] = _IQ(AdcSim.ib2.adc_val);
iq_norm_ADC[0][7] = _IQ(AdcSim.ic2.adc_val);
iq_norm_ADC[0][0] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][1] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][2] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][3] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][4] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][5] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][6] = _IQ(u[nn++] / NORMA_ACP);
iq_norm_ADC[0][7] = _IQ(u[nn++] / NORMA_ACP);
int nn = 8;
WRotor.iqWRotorCalcBeforeRegul1 = _IQ(u[nn++] / (PI*2) / NORMA_FROTOR);
u[nn++];
@ -33,9 +32,6 @@ void readInputParameters(const real_T* u) {
edrk.Go = u[nn++];
u[nn++];
edrk.zadanie.iq_power_zad = _IQmpy(_IQ(u[nn]), (edrk.zadanie.rmp_powers_zad.RampHighLimit));
edrk.zadanie.iq_oborots_zad_hz = _IQmpy(_IQ(u[nn++]), (edrk.zadanie.rmp_oborots_zad_hz.RampHighLimit));
} //void input_param(unsigned short num, unsigned short val)
@ -119,14 +115,4 @@ void writeOutputParameters(real_T* xD) {
xD[nn++] = xpwm_time.Tc1_0;
xD[nn++] = xpwm_time.Tc1_1;
xD[nn++] = (AdcSim.udc1.adc_val);
xD[nn++] = (AdcSim.udc2.adc_val);
xD[nn++] = (AdcSim.ia1.adc_val);
xD[nn++] = (AdcSim.ib1.adc_val);
xD[nn++] = (AdcSim.ic1.adc_val);
xD[nn++] = (AdcSim.ia2.adc_val);
xD[nn++] = (AdcSim.ib2.adc_val);
xD[nn++] = (AdcSim.ic2.adc_val);
}

View File

@ -1,8 +1,8 @@
#include "simstruc.h"
#include "app_includes.h"
#ifndef _APP_IO
#define _APP_IO
#ifndef PARAM
#define PARAM
void readInputParameters(const real_T* u);
@ -13,5 +13,5 @@ extern int CAN_timeout[UNIT_QUA];
extern RS_DATA_STRUCT rs_a;
extern RS_DATA_STRUCT rs_b;
extern _iq iq_norm_ADC[COUNT_ARR_ADC_BUF][16];
#endif //_APP_IO
#endif //PARAM

View File

@ -10,7 +10,6 @@
#include "app_init.h"
#include "app_io.h"
#include "pwm_sim.h"
#include "adc_sim.h"
/**
* @addtogroup WRAPPER_CONF
@ -60,7 +59,7 @@ void MCU_Step_Simulation(SimStruct* S, time_T time)
MCU_readInputs(S); // считывание портов
MCU_Periph_Simulation(S); // simulate peripheral
MCU_Periph_Simulation(); // simulate peripheral
#ifdef RUN_APP_MAIN_FUNC_THREAD
ResumeThread(hmcu.hMCUThread);
@ -78,9 +77,8 @@ void MCU_Step_Simulation(SimStruct* S, time_T time)
* @brief Симуляция периферии МК
* @details Пользовательский код, который симулирует работу периферии МК.
*/
void MCU_Periph_Simulation(SimStruct* S)
void MCU_Periph_Simulation(void)
{
Simulate_ADC(S);
Simulate_PWM();
}
@ -124,7 +122,7 @@ void MCU_writeOutputs(SimStruct* S)
* @details Пользовательский код, который создает поток для приложения МК
и настраивает симулятор МК для симуляции.
*/
void SIM_Initialize_Simulation(SimStruct* S)
void SIM_Initialize_Simulation(void)
{
#ifdef RUN_APP_MAIN_FUNC_THREAD
// инициализация потока, который будет выполнять код МК
@ -132,9 +130,8 @@ void SIM_Initialize_Simulation(SimStruct* S)
#endif //RUN_APP_MAIN_FUNC_THREAD
/* user initialization */
app_init();
Init_ADC_Simulation();
Init_PWM_Simulation();
app_init();
/* clock step initialization */
hmcu.sSystemClock_step = MCU_CORE_CLOCK * hmcu.sSimSampleTime; // set system clock step
@ -144,7 +141,7 @@ void SIM_Initialize_Simulation(SimStruct* S)
* @brief Деинициализация симуляции МК.
* @details Пользовательский код, который будет очищать все структуры после окончания симуляции.
*/
void SIM_deInitialize_Simulation(SimStruct* S)
void SIM_deInitialize_Simulation(void)
{
//// simulate structures of peripheral deinitialization
//deInitialize_Periph_Sim();

View File

@ -142,13 +142,13 @@ extern SIM__MCUHandleTypeDef hmcu; // extern для видимос
void MCU_Step_Simulation(SimStruct *S, time_T time);
/* MCU peripheral simulation */
void MCU_Periph_Simulation(SimStruct* S);
void MCU_Periph_Simulation(void);
/* Initialize MCU simulation */
void SIM_Initialize_Simulation(SimStruct* S);
void SIM_Initialize_Simulation(void);
/* Deinitialize MCU simulation */
void SIM_deInitialize_Simulation(SimStruct* S);
void SIM_deInitialize_Simulation(void);
/* Read inputs S-function */
void MCU_readInputs(SimStruct* S);

View File

@ -62,8 +62,7 @@ set code_WRAPPER= .\Inu\MCU.c^
.\Inu\app_wrapper\app_init.c^
.\Inu\app_wrapper\app_io.c^
.\Inu\app_wrapper\app_wrapper.c^
.\Inu\xilinx_wrapper\pwm_sim.c^
.\Inu\xilinx_wrapper\adc_sim.c
.\Inu\xilinx_wrapper\pwm_sim.c
::-------------------------------------------------------------------------

View File

@ -1,74 +1,3 @@
#include "adc_sim.h"
AdcSimHandle AdcSim;
void Simulate_ADC(SimStruct* S)
{
real_T* IN = ssGetInputPortRealSignal(S, 0);
adcMeasure(&AdcSim.Measure, IN, 0);
adcConvert(&AdcSim.convertion, &AdcSim.udc1, AdcSim.Measure.udc1);
adcConvert(&AdcSim.convertion, &AdcSim.udc2, AdcSim.Measure.udc2);
adcConvert(&AdcSim.convertion, &AdcSim.ia1, AdcSim.Measure.ia1);
adcConvert(&AdcSim.convertion, &AdcSim.ib1, AdcSim.Measure.ib1);
adcConvert(&AdcSim.convertion, &AdcSim.ic1, AdcSim.Measure.ic1);
adcConvert(&AdcSim.convertion, &AdcSim.ia2, AdcSim.Measure.ia2);
adcConvert(&AdcSim.convertion, &AdcSim.ib2, AdcSim.Measure.ib2);
adcConvert(&AdcSim.convertion, &AdcSim.ic2, AdcSim.Measure.ic2);
}
void Init_ADC_Simulation()
{
adcInitConvertion(&AdcSim.convertion, NORMA_ACP, 2.5, 4096);
adcInitMeasure(&AdcSim.udc1, K_LEM_ADC[0], R_ADC[0], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.udc2, K_LEM_ADC[1], R_ADC[1], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ia1, K_LEM_ADC[2], R_ADC[2], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ib1, K_LEM_ADC[3], R_ADC[3], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ic1, K_LEM_ADC[4], R_ADC[4], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ia2, K_LEM_ADC[5], R_ADC[5], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ib2, K_LEM_ADC[6], R_ADC[6], DEFAULT_ZERO_ADC, 0);
adcInitMeasure(&AdcSim.ic2, K_LEM_ADC[7], R_ADC[7], DEFAULT_ZERO_ADC, 0);
}
void adcInitConvertion(AdcConvertionHandle* hconv, int norma_adc, double adc_amplitude, int adc_bit_depth)
{
hconv->norma_adc = norma_adc;
hconv->adc_amplitude = adc_amplitude;
hconv->adc_bit_depth = adc_bit_depth;
}
void adcInitMeasure(AdcMeasureHandle* hmeasure, int k_lem_adc, int r_adc, int offset, double real_satur)
{
hmeasure->k_lem_adc = k_lem_adc;
hmeasure->r_adc = r_adc;
hmeasure->offset = offset;
hmeasure->real_satur = real_satur;
}
void adcMeasure(AdcRealMeasureHandle *hrmeasure, const real_T* u, int startind)
{
hrmeasure->udc1 = u[startind++];
hrmeasure->udc2 = u[startind++];
hrmeasure->ia1 = u[startind++];
hrmeasure->ib1 = u[startind++];
hrmeasure->ic1 = u[startind++];
hrmeasure->ia2 = u[startind++];
hrmeasure->ib2 = u[startind++];
hrmeasure->ic2 = u[startind++];
}
void adcConvert(AdcConvertionHandle* hconv, AdcMeasureHandle* hmeasure, double realMeasure)
{
if (hmeasure->real_satur != 0)
{
if (realMeasure > hmeasure->real_satur)
realMeasure = hmeasure->real_satur;
else if (realMeasure < -hmeasure->real_satur)
realMeasure = -hmeasure->real_satur;
}
hmeasure->adc_val =
(unsigned short)(realMeasure / hmeasure->k_lem_adc * hmeasure->r_adc / hconv->norma_adc / hconv->adc_amplitude * hconv->adc_bit_depth + (float)hmeasure->offset);
}
AdcSimHandle adcsim;

View File

@ -1,7 +1,5 @@
#include "mcu_wrapper_conf.h"
#ifndef ADC_SIM
#define ADC_SIM
#ifndef PWM_SIM
#define PWM_SIM
// Äëÿ ìîäåëèðîâàíèÿ ADC
typedef struct
@ -9,65 +7,6 @@ typedef struct
int tAdc;
int Tadc;
int nAdc;
int norma_adc;
double adc_amplitude;
int adc_bit_depth;
}AdcConvertionHandle;
// Äëÿ ðåàëüíûõ èçìåðåííûõ çíà÷åíèé
typedef struct
{
double udc1;
double udc2;
double ia1;
double ib1;
double ic1;
double ia2;
double ib2;
double ic2;
double wm;
}AdcRealMeasureHandle;
// Äëÿ àöïøíûõ èçìåðåííûõ çíà÷åíèé
typedef struct
{
int adc_val;
double real_satur;
int r_adc;
int k_lem_adc;
int offset;
}AdcMeasureHandle;
typedef struct
{
AdcConvertionHandle convertion;
AdcRealMeasureHandle Measure;
AdcMeasureHandle udc1;
AdcMeasureHandle udc2;
AdcMeasureHandle ia1;
AdcMeasureHandle ib1;
AdcMeasureHandle ic1;
AdcMeasureHandle ia2;
AdcMeasureHandle ib2;
AdcMeasureHandle ic2;
AdcMeasureHandle wm;
}AdcSimHandle;
AdcSimHandle AdcSim;
void Simulate_ADC(SimStruct* S);
void Init_ADC_Simulation();
void adcInitConvertion(AdcConvertionHandle* hconv, int norma_adc, double adc_amplitude, int adc_bit_depth);
void adcInitMeasure(AdcMeasureHandle* hmeasure, int k_lem_adc, int r_adc, int offset, double real_satur);
void adcMeasure(AdcRealMeasureHandle* hrmeasure, const real_T* u, int startind);
void adcConvert(AdcConvertionHandle* hconv, AdcMeasureHandle* hmeasure, double realMeasure);
#endif //PWM_SIM

Binary file not shown.