Compare commits

...

2 Commits

Author SHA1 Message Date
864a2dfcac #8 Чуть доработан модуль adc_sim и настройка режима ПЧ выведена в app_configs.h 2025-01-20 11:41:55 +03:00
3b5b9b86f7 #5 Работает и векторное и скалярное
Видимо была проблема в измерениях с двигателя, они принимались непонятно в каком формате. Сейчас сделан модуль АЦП, который все правильно преобразует
2025-01-20 10:45:47 +03:00
12 changed files with 199 additions and 41 deletions

View File

@ -152,7 +152,7 @@ static void mdlInitializeSizes(SimStruct *S)
*/
static void mdlStart(SimStruct *S)
{
SIM_Initialize_Simulation();
SIM_Initialize_Simulation(S);
}
#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();
SIM_deInitialize_Simulation(S);
mexUnlock();
}

View File

@ -5,19 +5,27 @@
Дата последнего обновления: 2021.11.08
**************************************************************************/
#ifndef DEF
#define DEF
#ifndef _APP_CONFIG
#define _APP_CONFIG
// раскомментировать, если есть сдвиг между обмотками ГЭД (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 //DEF
#endif //_APP_CONFIG

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_SCALAR_OBOROTS;
edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
edrk.Mode_ScalarVectorUFConst = ALG_MODE_SIMULINK;
//edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
edrk.zadanie.iq_power_zad = _IQ(1);
edrk.zadanie.iq_oborots_zad_hz = _IQ(0.5);
edrk.zadanie.iq_oborots_zad_hz = _IQ(1);
edrk.MasterSlave = MODE_MASTER;
edrk.master_theta;

View File

@ -1,5 +1,5 @@
#ifndef INIT28335
#define INIT28335
#ifndef _APP_INIT
#define _APP_INIT
#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 //INIT28335
#endif //_APP_INIT

View File

@ -7,6 +7,7 @@
#include "app_io.h"
#include "pwm_sim.h"
#include "adc_sim.h"
int Unites[UNIT_QUA_UNITS][UNIT_LEN];
int CAN_timeout[UNIT_QUA];
@ -14,17 +15,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(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);
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);
int nn = 8;
WRotor.iqWRotorCalcBeforeRegul1 = _IQ(u[nn++] / (PI*2) / NORMA_FROTOR);
u[nn++];
@ -32,6 +33,9 @@ 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)
@ -115,4 +119,14 @@ 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 PARAM
#define PARAM
#ifndef _APP_IO
#define _APP_IO
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 //PARAM
#endif //_APP_IO

View File

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

View File

@ -62,7 +62,8 @@ 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\pwm_sim.c^
.\Inu\xilinx_wrapper\adc_sim.c
::-------------------------------------------------------------------------

View File

@ -1,3 +1,74 @@
#include "adc_sim.h"
AdcSimHandle adcsim;
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);
}

View File

@ -1,5 +1,7 @@
#ifndef PWM_SIM
#define PWM_SIM
#include "mcu_wrapper_conf.h"
#ifndef ADC_SIM
#define ADC_SIM
// Äëÿ ìîäåëèðîâàíèÿ ADC
typedef struct
@ -7,6 +9,65 @@ 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.