Симуляция генерации синусоидального шим и управление по модбас
note: - модбас не моделируется, в s-function просто передаются константы режимов. - лишние файлы убраны в outdate. - два канала одной фазы переключаются немного криво: на один такт симуляции проскакивает высокий уровень предыдущего канала и только потом включается текущий канал
This commit is contained in:
@@ -45,9 +45,9 @@
|
||||
modbus1_suart.huart = &modbus1_huart;
|
||||
modbus1_suart.huart->Instance = USED_MODBUS_UART;
|
||||
modbus1_suart.huart->Init.BaudRate = 38400;
|
||||
modbus1_suart.GPIOx = MB_GPIOX;
|
||||
modbus1_suart.GPIO_PIN_RX = MB_GPIO_PIN_RX;
|
||||
modbus1_suart.GPIO_PIN_TX = MB_GPIO_PIN_TX;
|
||||
modbus1_suart.GPIOx = MODBUS_GPIOX;
|
||||
modbus1_suart.GPIO_PIN_RX = MODBUS_GPIO_PIN_RX;
|
||||
modbus1_suart.GPIO_PIN_TX = MODBUS_GPIO_PIN_TX;
|
||||
|
||||
// set up timeout TIM for modbus
|
||||
modbus1_stim.htim = &modbus1_htim;
|
||||
@@ -99,21 +99,21 @@ void MODBUS_FirstInit(void)
|
||||
//-----------SETUP MODBUS-------------
|
||||
// set up UART for modbus
|
||||
modbus1_suart.huart.Instance = USED_MODBUS_UART;
|
||||
modbus1_suart.huart.Init.BaudRate = MB_SPEED;
|
||||
modbus1_suart.GPIOx = MB_GPIOX;
|
||||
modbus1_suart.GPIO_PIN_RX = MB_GPIO_PIN_RX;
|
||||
modbus1_suart.GPIO_PIN_TX = MB_GPIO_PIN_TX;
|
||||
modbus1_suart.huart.Init.BaudRate = PROJSET.MB_SPEED;
|
||||
modbus1_suart.GPIOx = (GPIO_TypeDef *)PROJSET.MB_GPIOX;
|
||||
modbus1_suart.GPIO_PIN_RX = PROJSET.MB_GPIO_PIN_RX;
|
||||
modbus1_suart.GPIO_PIN_TX = PROJSET.MB_GPIO_PIN_TX;
|
||||
|
||||
// set up timeout TIM for modbus
|
||||
modbus1_stim.htim.Instance = USED_MODBUS_TIM;
|
||||
modbus1_stim.sTimAHBFreqMHz = MB_TIM_AHB_FREQ;
|
||||
modbus1_stim.sTimAHBFreqMHz = PROJSET.MB_TIM_AHB_FREQ;
|
||||
modbus1_stim.sTimMode = TIM_IT_CONF;
|
||||
|
||||
// set up modbus: MB_RX_Size_NotConst and Timeout enable
|
||||
hmodbus1.ID = MB_ID;
|
||||
hmodbus1.sRS_RX_Size_Mode = RS_RX_Size_NotConst;
|
||||
hmodbus1.sRS_Timeout = MB_MAX_TIMEOUT;
|
||||
hmodbus1.ID = PROJSET.MB_DEVICE_ID;
|
||||
hmodbus1.sRS_Timeout = PROJSET.MB_MAX_TIMEOUT;
|
||||
hmodbus1.sRS_Mode = SLAVE_ALWAYS_WAIT;
|
||||
hmodbus1.sRS_RX_Size_Mode = RS_RX_Size_NotConst;
|
||||
|
||||
// INIT
|
||||
hmodbus1.RS_STATUS = RS_Init(&hmodbus1, &modbus1_suart, &modbus1_stim, 0);
|
||||
@@ -811,17 +811,17 @@ RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hmodbus, uint32_
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//-------------------------HANDLERS FUNCTION-------------------------
|
||||
#if (MB_UART_NUMB == 1) // choose handler for UART
|
||||
#if (MODBUS_UART_NUMB == 1) // choose handler for UART
|
||||
void USART1_IRQHandler(void)
|
||||
#elif (MB_UART_NUMB == 2)
|
||||
#elif (MODBUS_UART_NUMB == 2)
|
||||
void USART2_IRQHandler(void)
|
||||
#elif (MB_UART_NUMB == 3)
|
||||
#elif (MODBUS_UART_NUMB == 3)
|
||||
void USART3_IRQHandler(void)
|
||||
#elif (MB_UART_NUMB == 4)
|
||||
#elif (MODBUS_UART_NUMB == 4)
|
||||
void USART4_IRQHandler(void)
|
||||
#elif (MB_UART_NUMB == 5)
|
||||
#elif (MODBUS_UART_NUMB == 5)
|
||||
void USART5_IRQHandler(void)
|
||||
#elif (MB_UART_NUMB == 6)
|
||||
#elif (MODBUS_UART_NUMB == 6)
|
||||
void USART6_IRQHandler(void)
|
||||
#endif
|
||||
{
|
||||
@@ -829,29 +829,29 @@ void USART6_IRQHandler(void)
|
||||
RS_UART_Handler(&hmodbus1);
|
||||
Trace_MB_UART_Exit();
|
||||
}
|
||||
#if (MB_TIM_NUMB == 1) || (MB_TIM_NUMB == 10) // choose handler for TIM
|
||||
#if (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 10) // choose handler for TIM
|
||||
void TIM1_UP_TIM10_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 2)
|
||||
#elif (MODBUS_TIM_NUMB == 2)
|
||||
void TIM2_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 3)
|
||||
#elif (MODBUS_TIM_NUMB == 3)
|
||||
void TIM3_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 4)
|
||||
#elif (MODBUS_TIM_NUMB == 4)
|
||||
void TIM4_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 5)
|
||||
#elif (MODBUS_TIM_NUMB == 5)
|
||||
void TIM5_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 6)
|
||||
#elif (MODBUS_TIM_NUMB == 6)
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 7)
|
||||
#elif (MODBUS_TIM_NUMB == 7)
|
||||
void TIM7_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 8) || (MB_TIM_NUMB == 13)
|
||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 13)
|
||||
void TIM8_UP_TIM13_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 1) || (MB_TIM_NUMB == 9)
|
||||
#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 9)
|
||||
void TIM1_BRK_TIM9_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 1) || (MB_TIM_NUMB == 11)
|
||||
#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 11)
|
||||
void TIM1_TRG_COM_TIM11_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 8) || (MB_TIM_NUMB == 12)
|
||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 12)
|
||||
void TIM8_BRK_TIM12_IRQHandler(void)
|
||||
#elif (MB_TIM_NUMB == 8) || (MB_TIM_NUMB == 14)
|
||||
#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 14)
|
||||
void TIM8_TRG_COM_TIM14_IRQHandler(void)
|
||||
#endif
|
||||
{
|
||||
|
||||
@@ -9,32 +9,29 @@ MODBUS.
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "modbus_data.h"
|
||||
#include "settings.h" // for modbus settings
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////---SETTINGS---/////////////////////////////
|
||||
//----------DEFINES FOR MODBUS SETTING--------------
|
||||
#define MB_UART_NUMB 3 // number of used uart
|
||||
#define MB_SPEED 115200
|
||||
#define MB_GPIOX GPIOB
|
||||
#define MB_GPIO_PIN_RX GPIO_PIN_11
|
||||
#define MB_GPIO_PIN_TX GPIO_PIN_10
|
||||
/* accord to this define sets define USED_MB_UART = USARTx */
|
||||
#define MB_TIM_NUMB 7 // number of used uart
|
||||
#define MB_TIM_AHB_FREQ 72
|
||||
/* accord to this define sets define USED_MB_TIM = TIMx */
|
||||
////----------DEFINES FOR MODBUS SETTING--------------
|
||||
//#define MODBUS_UART_NUMB 3 // number of used uart
|
||||
//#define MODBUS_SPEED 115200
|
||||
//#define MODBUS_GPIOX GPIOB
|
||||
//#define MODBUS_GPIO_PIN_RX GPIO_PIN_11
|
||||
//#define MODBUS_GPIO_PIN_TX GPIO_PIN_10
|
||||
///* accord to this define sets define USED_MB_UART = USARTx */
|
||||
//#define MODBUS_TIM_NUMB 7 // number of used uart
|
||||
//#define MODBUS_TIM_AHB_FREQ 72
|
||||
///* accord to this define sets define USED_MB_TIM = TIMx */
|
||||
|
||||
/* defines for modbus behaviour */
|
||||
#define MB_ID 1 // number of used uart
|
||||
#define MB_MAX_TIMEOUT 5000 // is ms
|
||||
// custom define for size of receive message
|
||||
//--------------------------------------------------
|
||||
///* defines for modbus behaviour */
|
||||
//#define MODBUS_DEVICE_ID 1 // number of used uart
|
||||
//#define MODBUS_MAX_TIMEOUT 5000 // is ms
|
||||
//// custom define for size of receive message
|
||||
////--------------------------------------------------
|
||||
|
||||
//---------------MODBUS DEVICE DATA-----------------
|
||||
|
||||
|
||||
|
||||
/* EXTERN REGISTERS/COILS */
|
||||
|
||||
|
||||
extern uint16_t sine_log[R_SINE_LOG_QNT]; // start from 0x0000
|
||||
extern uint16_t pwm_log[R_PWM_LOG_QNT]; // start from 500 (0x1F4)
|
||||
extern uint16_t cnt_log[R_CNT_LOG_QNT]; // start from 100 (0x3E8)
|
||||
@@ -136,7 +133,7 @@ typedef enum
|
||||
}MB_CoilsOpTypeDef;
|
||||
|
||||
//------------DEFINES FOR PROCESS DATA--------------
|
||||
/**S
|
||||
/**
|
||||
* @brief Calc dividing including remainder
|
||||
* @param _val_ - делимое.
|
||||
* @param _div_ - делитель.
|
||||
@@ -353,66 +350,66 @@ uint8_t MB_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg);
|
||||
/////////////////////////---CALC DEFINES---//////////////////////////
|
||||
|
||||
/* set USART_TypeDef for choosen numb of usart */
|
||||
#if (MB_UART_NUMB == 1)
|
||||
#if (MODBUS_UART_NUMB == 1)
|
||||
#define USED_MODBUS_UART USART1
|
||||
#define USE_USART1
|
||||
#elif (MB_UART_NUMB == 2)
|
||||
#elif (MODBUS_UART_NUMB == 2)
|
||||
#define USED_MODBUS_UART USART2
|
||||
#define USE_USART2
|
||||
#elif (MB_UART_NUMB == 3)
|
||||
#elif (MODBUS_UART_NUMB == 3)
|
||||
#define USED_MODBUS_UART USART3
|
||||
#define USE_USART3
|
||||
#elif (MB_UART_NUMB == 4)
|
||||
#elif (MODBUS_UART_NUMB == 4)
|
||||
#define USED_MODBUS_UART UART4
|
||||
#define USE_UART4
|
||||
#elif (MB_UART_NUMB == 5)
|
||||
#elif (MODBUS_UART_NUMB == 5)
|
||||
#define USED_MODBUS_UART UART5
|
||||
#define USE_UART6
|
||||
#elif (MB_UART_NUMB == 6)
|
||||
#elif (MODBUS_UART_NUMB == 6)
|
||||
#define USED_MODBUS_UART USART6
|
||||
#define USE_USART6
|
||||
#endif
|
||||
|
||||
#if (MB_TIM_NUMB == 1)
|
||||
#if (MODBUS_TIM_NUMB == 1)
|
||||
#define USED_MODBUS_TIM TIM1
|
||||
#define USE_TIM1
|
||||
#elif (MB_TIM_NUMB == 2)
|
||||
#elif (MODBUS_TIM_NUMB == 2)
|
||||
#define USED_MODBUS_TIM TIM2
|
||||
#define USE_TIM2
|
||||
#elif (MB_TIM_NUMB == 3)
|
||||
#elif (MODBUS_TIM_NUMB == 3)
|
||||
#define USED_MODBUS_TIM TIM3
|
||||
#define USE_TIM3
|
||||
#elif (MB_TIM_NUMB == 4)
|
||||
#elif (MODBUS_TIM_NUMB == 4)
|
||||
#define USED_MODBUS_TIM TIM4
|
||||
#define USE_TIM4
|
||||
#elif (MB_TIM_NUMB == 5)
|
||||
#elif (MODBUS_TIM_NUMB == 5)
|
||||
#define USED_MODBUS_TIM TIM5
|
||||
#define USE_TIM5
|
||||
#elif (MB_TIM_NUMB == 6)
|
||||
#elif (MODBUS_TIM_NUMB == 6)
|
||||
#define USED_MODBUS_TIM TIM6
|
||||
#define USE_TIM6
|
||||
#elif (MB_TIM_NUMB == 7)
|
||||
#elif (MODBUS_TIM_NUMB == 7)
|
||||
#define USED_MODBUS_TIM TIM7
|
||||
#define USE_TIM7
|
||||
#elif (MB_TIM_NUMB == 8)
|
||||
#elif (MODBUS_TIM_NUMB == 8)
|
||||
#define USED_MODBUS_TIM TIM8
|
||||
#define USE_TIM8
|
||||
#elif (MB_TIM_NUMB == 9)
|
||||
#elif (MODBUS_TIM_NUMB == 9)
|
||||
#define USED_MODBUS_TIM TIM9
|
||||
#define USE_TIM9
|
||||
#elif (MB_TIM_NUMB == 10)
|
||||
#elif (MODBUS_TIM_NUMB == 10)
|
||||
#define USED_MODBUS_TIM TIM10
|
||||
#define USE_TIM10
|
||||
#elif (MB_TIM_NUMB == 11)
|
||||
#elif (MODBUS_TIM_NUMB == 11)
|
||||
#define USED_MODBUS_TIM TIM11
|
||||
#define USE_TIM11
|
||||
#elif (MB_TIM_NUMB == 12)
|
||||
#elif (MODBUS_TIM_NUMB == 12)
|
||||
#define USED_MODBUS_TIM TIM12
|
||||
#define USE_TIM12
|
||||
#elif (MB_TIM_NUMB == 13)
|
||||
#elif (MODBUS_TIM_NUMB == 13)
|
||||
#define USED_MODBUS_TIM TIM13
|
||||
#define USE_TIM13
|
||||
#elif (MB_TIM_NUMB == 14)
|
||||
#elif (MODBUS_TIM_NUMB == 14)
|
||||
#define USED_MODBUS_TIM TIM14
|
||||
#define USE_TIM14
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user