diff --git a/App_Wrapper/main.c b/App_Wrapper/main.c index 4c7cca5..525b5d6 100644 --- a/App_Wrapper/main.c +++ b/App_Wrapper/main.c @@ -191,7 +191,7 @@ int main(void) // init params for pwm and log pwm_ctrl[R_PWM_CTRL_PWM_SINE_HZ] = 10000; pwm_ctrl[R_PWM_CTRL_DUTY_BRIDGE] = 10000;//HZ_TIMER_PWM; - pwm_ctrl[R_PWM_CTRL_PWM_HZ] = 200;//HZ_TIMER_PWM; + pwm_ctrl[R_PWM_CTRL_PWM_HZ] = 15000;//HZ_TIMER_PWM; pwm_ctrl[R_PWM_CTRL_MAX_PULSE_DUR] = 0; pwm_ctrl[R_PWM_CTRL_MIN_PULSE_DUR] = 0; pwm_ctrl[R_PWM_CTRL_DEAD_TIME] = 100; diff --git a/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_gpio.c b/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_gpio.c index 8935561..b16ea6a 100644 --- a/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_gpio.c +++ b/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_gpio.c @@ -31,7 +31,7 @@ void GPIO_to_SFUNC(real_T* out_buff) out_buff[PORT_WIDTH + i] = 1; } - if (GPIOE->ODR & (1 << i)) + if (GPIOA->ODR & (1 << i)) { out_buff[2*PORT_WIDTH + i] = 1; } @@ -50,12 +50,12 @@ void SFUNC_to_GPIO(real_T* in) { int i = 0; // write pwm ctrl registers - for (i = 0; i < 5; i++) + for (i = 0; i < 6; i++) { pwm_ctrl[i] = in[i]; } // write pwm ctrl coils - if (in[5] > 0.5) + if (in[i++] > 0.5) { MB_Set_Coil_Local(coils_regs, COIL_PWM_DC_MODE); } @@ -63,7 +63,7 @@ void SFUNC_to_GPIO(real_T* in) { MB_Reset_Coil_Local(coils_regs, COIL_PWM_DC_MODE); } - if (in[6] > 0.5) + if (in[i++] > 0.5) { MB_Set_Coil_Local(coils_regs, COIL_PWM_BRIDGE_MODE); } @@ -71,7 +71,7 @@ void SFUNC_to_GPIO(real_T* in) { MB_Reset_Coil_Local(coils_regs, COIL_PWM_BRIDGE_MODE); } - if (in[7] > 0.5) + if (in[i++] > 0.5) { MB_Set_Coil_Local(coils_regs, COIL_PWM_PHASE_MODE); } diff --git a/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_rcc.h b/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_rcc.h index bb7974e..6865b60 100644 --- a/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_rcc.h +++ b/MCU_STM32F4xx_Matlab/STM32F4xx_SIMULINK/stm32f4xx_matlab_rcc.h @@ -25,11 +25,11 @@ //#define AHB_Prescaler ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos) //#define AHB_Prescaler ((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos) -#define HCLK_Value (double)72000000; -#define ABP1_Value (double)72000000; -#define ABP1_TIMS_Value (double)72000000; -#define ABP2_Value (double)72000000; -#define ABP2_TIMS_Value (double)72000000; +#define HCLK_Value (double)168000000; +#define ABP1_Value (double)42000000; +#define ABP1_TIMS_Value (double)84000000; +#define ABP2_Value (double)42000000; +#define ABP2_TIMS_Value (double)84000000; /* Эти дефайны добавлены в код stm32f4xx_hal_rcc.c, чтобы не попасть в бесконечный цикл */ /* Мб перенести в MCU_Periph_Simulation(), но чет не хочется нагружать симуляцию этой херней */ diff --git a/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.c b/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.c index 79f336a..7e2a8fb 100644 --- a/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.c +++ b/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.c @@ -126,11 +126,11 @@ void Init_TIM_SIM(void) tim2s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value; tim2s.Channels.OC1_GPIOx = GPIOA; - tim2s.Channels.OC1_PIN_SHIFT = 5; - tim2s.Channels.OC2_GPIOx = GPIOA; - tim2s.Channels.OC2_PIN_SHIFT = 1; - tim2s.Channels.OC3_GPIOx = GPIOA; - tim2s.Channels.OC3_PIN_SHIFT = 2; + tim2s.Channels.OC1_PIN_SHIFT = 15; + tim2s.Channels.OC2_GPIOx = GPIOE; + tim2s.Channels.OC2_PIN_SHIFT = 11; + tim2s.Channels.OC3_GPIOx = GPIOE; + tim2s.Channels.OC3_PIN_SHIFT = 13; tim2s.Channels.OC4_GPIOx = GPIOA; tim2s.Channels.OC4_PIN_SHIFT = 3; tim2s.Channels.OC1REF = 0; diff --git a/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.h b/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.h index a20f569..72038f9 100644 --- a/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.h +++ b/MCU_STM32F4xx_Matlab/stm32f4xx_matlab_conf.h @@ -45,8 +45,8 @@ // DEFINES (UNCOMMENT WHAT YOU WILL SIMULATE) // TIMS -#define USE_TIM1 -//#define USE_TIM2 +//#define USE_TIM1 +#define USE_TIM2 #define USE_TIM3 #define USE_TIM4 //#define USE_TIM5 @@ -56,8 +56,8 @@ //#define USE_TIM9 //#define USE_TIM10 //#define USE_TIM11 -#define USE_TIM12 -//#define USE_TIM13 +//#define USE_TIM12 +#define USE_TIM13 //#define USE_TIM14 // TIM'S HANDLERS diff --git a/MCU_Wrapper/mcu_wrapper_conf.h b/MCU_Wrapper/mcu_wrapper_conf.h index 2c4a26a..2a47ed8 100644 --- a/MCU_Wrapper/mcu_wrapper_conf.h +++ b/MCU_Wrapper/mcu_wrapper_conf.h @@ -46,19 +46,19 @@ // Parametrs of MCU simulator #define CREATE_SUSPENDED 0x00000004 ///< define from WinBase.h. We dont wanna include "Windows.h" or smth like this, because of HAL there are a lot of redefine errors. -#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFFFF ///< number of for() cycles after which MCU thread would be suspended +#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFF ///< number of for() cycles after which MCU thread would be suspended #define PORT_WIDTH 16 ///< width of one port #define PORT_NUMB 3 ///< amount of ports // Parameters of S_Function #define NPARAMS 1 ///< number of input parametrs (only Ts) -#define IN_PORT_WIDTH (8) ///< width of input ports +#define IN_PORT_WIDTH (9) ///< width of input ports #define IN_PORT_NUMB 1 ///< number of input ports #define OUT_PORT_WIDTH PORT_WIDTH ///< width of output ports #define OUT_PORT_NUMB PORT_NUMB ///< number of output ports #define DISC_STATES_WIDTH PORT_WIDTH*PORT_NUMB ///< width of discrete states array -#define MCU_CORE_CLOCK SystemCoreClock +#define MCU_CORE_CLOCK 168000000 /** WRAPPER_CONF * @} */ diff --git a/mcu_test_r2021a.slx b/mcu_test_r2021a.slx index 152fe68..8513a11 100644 Binary files a/mcu_test_r2021a.slx and b/mcu_test_r2021a.slx differ