From 0c06d07f4eb8731a8998a7a60afcf1ded88fb678 Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Tue, 24 Dec 2024 11:20:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=B8=D0=BB=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=B9.=20=D0=9F=D1=80=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20?= =?UTF-8?q?modbus=20-=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Чуть оптимизированы функции переключения ключей: теперь ifdef для использования HAL функций не в test_func.c а в test_func.h --- .../Core/Interfaces/interface_config.h | 22 ++-- diode_tester/Core/Interfaces/modbus.c | 61 ++------- diode_tester/Core/Interfaces/modbus.h | 2 +- diode_tester/Core/Interfaces/modbus_data.h | 16 ++- diode_tester/Core/Src/main.c | 1 - diode_tester/Core/Src/stm32f1xx_it.c | 10 +- diode_tester/Core/Tester_main/tester_config.h | 2 +- diode_tester/Core/Tester_main/tester_func.c | 119 ++++++++---------- diode_tester/Core/Tester_main/tester_func.h | 37 +++++- diode_tester/Core/Tester_main/tester_main.c | 18 ++- diode_tester/MDK-ARM/diode_tester.uvoptx | 8 +- 11 files changed, 152 insertions(+), 144 deletions(-) diff --git a/diode_tester/Core/Interfaces/interface_config.h b/diode_tester/Core/Interfaces/interface_config.h index 1e86cd8..55b520a 100644 --- a/diode_tester/Core/Interfaces/interface_config.h +++ b/diode_tester/Core/Interfaces/interface_config.h @@ -18,18 +18,18 @@ @{ */ -#define MODBUS_UART_NUMB 3 ///< Номер используемого UART, по нему выставляется дефайн USED_MB_UART = USARTx +//#define MODBUS_UART_NUMB 1 ///< Номер используемого UART, по нему выставляется дефайн USED_MB_UART = USARTx #define MODBUS_SPEED 115200 ///< Скорость UART для модбас -#define MODBUS_GPIOX GPIOB ///< Порт для UART RX/TX -#define MODBUS_GPIO_PIN_RX GPIO_PIN_11 ///< Пин для UART RX -#define MODBUS_GPIO_PIN_TX GPIO_PIN_10 ///< Пин для UART TX +//#define MODBUS_GPIOX GPIOA ///< Порт для UART RX/TX +//#define MODBUS_GPIO_PIN_RX GPIO_PIN_9 ///< Пин для UART RX +//#define MODBUS_GPIO_PIN_TX GPIO_PIN_10 ///< Пин для UART TX -#define MODBUS_TIM_NUMB 7 ///< number of used tim, accord to this define sets define USED_MB_TIM = TIMx -#define MODBUS_TIM_AHB_FREQ 72 ///< TIM AHB Bus Freq +//#define MODBUS_TIM_NUMB 2 ///< number of used tim, accord to this define sets define USED_MB_TIM = TIMx +//#define MODBUS_TIM_AHB_FREQ 72 ///< TIM AHB Bus Freq // defines for modbus behaviour #define MODBUS_DEVICE_ID 1 ///< девайс текущего устройства -#define MODBUS_MAX_TIMEOUT 5000 ///< максимальнйы тайтаут MB is ms +//#define MODBUS_MAX_TIMEOUT 500 ///< максимальнйы тайтаут MB is ms #define RS_UART_Init MX_USART1_UART_Init @@ -38,8 +38,12 @@ #define RS_TIM_DeInit HAL_TIM_Base_MspDeInit #define rs_huart huart1 #define rs_htim htim2 - - +/** + * @brief Поменять комманды 0x03 и 0x04 местами (для LabView терминалки от двигателей) + * @details Терминалка от двигателей использует для чтения регистров комманду R_HOLD_REGS вместо R_IN_REGS + * Поэтому чтобы считывать Input Regs - надо поменять их местами. + */ +#define MODBUS_SWITCH_COMMAND_R_IN_REGS_AND_R_HOLD_REGS ///////////////////////////////////////////////////////////////////// /////////////////////////---CALC DEFINES---////////////////////////// diff --git a/diode_tester/Core/Interfaces/modbus.c b/diode_tester/Core/Interfaces/modbus.c index 45204d2..ce16e65 100644 --- a/diode_tester/Core/Interfaces/modbus.c +++ b/diode_tester/Core/Interfaces/modbus.c @@ -126,7 +126,6 @@ void MODBUS_FirstInit(void) #endif // set up modbus: MB_RX_Size_NotConst and Timeout enable hmodbus1.ID = MODBUS_DEVICE_ID; - hmodbus1.sRS_Timeout = MODBUS_MAX_TIMEOUT; hmodbus1.sRS_Mode = SLAVE_ALWAYS_WAIT; hmodbus1.sRS_RX_Size_Mode = RS_RX_Size_NotConst; @@ -879,54 +878,18 @@ RS_StatusTypeDef RS_Define_Size_of_RX_Message(RS_HandleTypeDef *hmodbus, uint32_ //------------------------------------------------------------------- //-------------------------HANDLERS FUNCTION------------------------- -#if (MODBUS_UART_NUMB == 1) // choose handler for UART -void USART1_IRQHandler(void) -#elif (MODBUS_UART_NUMB == 2) -void USART2_IRQHandler(void) -#elif (MODBUS_UART_NUMB == 3) -void USART3_IRQHandler(void) -#elif (MODBUS_UART_NUMB == 4) -void USART4_IRQHandler(void) -#elif (MODBUS_UART_NUMB == 5) -void USART5_IRQHandler(void) -#elif (MODBUS_UART_NUMB == 6) -void USART6_IRQHandler(void) -#endif -{ - Trace_MB_UART_Enter(); - RS_UART_Handler(&hmodbus1); - Trace_MB_UART_Exit(); -} -#if (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 10) // choose handler for TIM -void TIM1_UP_TIM10_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 2) -void TIM2_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 3) -void TIM3_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 4) -void TIM4_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 5) -void TIM5_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 6) -void TIM6_DAC_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 7) -void TIM7_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 13) -void TIM8_UP_TIM13_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 9) -void TIM1_BRK_TIM9_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 1) || (MODBUS_TIM_NUMB == 11) -void TIM1_TRG_COM_TIM11_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 12) -void TIM8_BRK_TIM12_IRQHandler(void) -#elif (MODBUS_TIM_NUMB == 8) || (MODBUS_TIM_NUMB == 14) -void TIM8_TRG_COM_TIM14_IRQHandler(void) -#endif -{ - Trace_MB_TIM_Enter(); - RS_TIM_Handler(&hmodbus1); - Trace_MB_TIM_Exit(); -} +//void USART1_IRQHandler(void) +//{ +// Trace_MB_UART_Enter(); +// RS_UART_Handler(&hmodbus1); +// Trace_MB_UART_Exit(); +//} +//void TIM1_UP_TIM10_IRQHandler(void) +//{ +// Trace_MB_TIM_Enter(); +// RS_TIM_Handler(&hmodbus1); +// Trace_MB_TIM_Exit(); +//} //-------------------------HANDLERS FUNCTION------------------------- //------------------------------------------------------------------- diff --git a/diode_tester/Core/Interfaces/modbus.h b/diode_tester/Core/Interfaces/modbus.h index ca0af1d..7359b0e 100644 --- a/diode_tester/Core/Interfaces/modbus.h +++ b/diode_tester/Core/Interfaces/modbus.h @@ -72,7 +72,7 @@ typedef enum //MB_FunctonTypeDef // reading MB_R_COILS = 0x01, ///< Чтение битовых ячеек MB_R_DISC_IN = 0x02, ///< Чтение дискретных входов -#ifndef TESTER_MODBUS_SWITCH_COMMAND_R_IN_REGS_AND_R_HOLD_REGS +#ifndef MODBUS_SWITCH_COMMAND_R_IN_REGS_AND_R_HOLD_REGS MB_R_HOLD_REGS = 0x03, ///< Чтение входных регистров MB_R_IN_REGS = 0x04, ///< Чтение регистров хранения #else diff --git a/diode_tester/Core/Interfaces/modbus_data.h b/diode_tester/Core/Interfaces/modbus_data.h index f31cbd2..e24d914 100644 --- a/diode_tester/Core/Interfaces/modbus_data.h +++ b/diode_tester/Core/Interfaces/modbus_data.h @@ -63,7 +63,7 @@ typedef struct //MB_DataInRegsTypeDef // DEFINES FOR INPUT REGISTERS ARRAYS #define R_MEASURED_ADDR 0 -#define R_MEASURED_QNT 1 +#define R_MEASURED_QNT 2 // DEFINES FOR HOLDING REGISTERS ARRAYS #define R_SETTINGS_ADDR 0 @@ -100,22 +100,28 @@ typedef struct //MB_DataInRegsTypeDef */ typedef struct //MB_DataCoilsTypeDef { - /* reg 1 */ + /* reg 1 - control */ unsigned ForwardTest:1; unsigned ReverseTest:1; unsigned StartTest:1; - unsigned reserved:13; + unsigned PhaseForwardHiTest:1; + unsigned PhaseForwardLoTest:1; + unsigned PhaseReverseHiTest:1; + unsigned PhaseReverseLoTest:1; - /* reg 2 */ + unsigned reserved:9; + + /* reg 2 - settings */ unsigned msTimeBeforeTest_enable:1; unsigned msTimeDeadtime_enable:1; unsigned msTimeBeforePeak_enable:1; unsigned msTimeBeforeDisconnect_enable:1; + unsigned reserved2:11; }MB_DataCoilsTypeDef; // DEFINES FOR COIL ARRAYS #define C_CONTROL_ADDR 0 -#define C_CONTROL_QNT 3 +#define C_CONTROL_QNT 7 #define C_SETTINGS_ADDR 16 #define C_SETTINGS_QNT 3 diff --git a/diode_tester/Core/Src/main.c b/diode_tester/Core/Src/main.c index ce7eb5e..66db229 100644 --- a/diode_tester/Core/Src/main.c +++ b/diode_tester/Core/Src/main.c @@ -113,7 +113,6 @@ int main(void) { TESTER_main_delay(&TESTER); TESTER_main_while(&TESTER); - HAL_UART_Transmit(&huart1, (uint8_t *)"axaxa", 5, 100); /* USER CODE END WHILE */ diff --git a/diode_tester/Core/Src/stm32f1xx_it.c b/diode_tester/Core/Src/stm32f1xx_it.c index 23bd3bc..7d33653 100644 --- a/diode_tester/Core/Src/stm32f1xx_it.c +++ b/diode_tester/Core/Src/stm32f1xx_it.c @@ -223,7 +223,10 @@ void DMA1_Channel1_IRQHandler(void) void TIM2_IRQHandler(void) { /* USER CODE BEGIN TIM2_IRQn 0 */ - + Trace_MB_TIM_Enter(); + RS_TIM_Handler(&hmodbus1); + Trace_MB_TIM_Exit(); + return; /* USER CODE END TIM2_IRQn 0 */ HAL_TIM_IRQHandler(&htim2); /* USER CODE BEGIN TIM2_IRQn 1 */ @@ -251,7 +254,10 @@ void TIM3_IRQHandler(void) void USART1_IRQHandler(void) { /* USER CODE BEGIN USART1_IRQn 0 */ - + Trace_MB_UART_Enter(); + RS_UART_Handler(&hmodbus1); + Trace_MB_UART_Exit(); + return; /* USER CODE END USART1_IRQn 0 */ HAL_UART_IRQHandler(&huart1); /* USER CODE BEGIN USART1_IRQn 1 */ diff --git a/diode_tester/Core/Tester_main/tester_config.h b/diode_tester/Core/Tester_main/tester_config.h index f9ecec1..2682c6a 100644 --- a/diode_tester/Core/Tester_main/tester_config.h +++ b/diode_tester/Core/Tester_main/tester_config.h @@ -106,7 +106,7 @@ @{ */ //#define USE_HAL_GPIO_FUNCTIONS ///< По этому дефайну для переключения пинов будут использоваться HAL_GPIO функции -//#define RECONNECT_WITHOUT_DEADTIME ///< По этому дефайну дедтайм отключается. Если отключить и USE_HAL_GPIO_FUNCTIONS, то переключатся фазы будут почти синхронно (быстрее десятков мкс) +//#define RECONNECT_WITHOUT_DEADTIME ///< По этому дефайну дедтайм отключается. Если отключить и USE_HAL_GPIO_FUNCTIONS, то переключатся фазы будут почти синхронно (160 нс) /* Состояния ключей для подключения и откючения питания */ #define PHASE_CONNECT 1 ///< Ключ замкнут подключено в данном состоянии пина diff --git a/diode_tester/Core/Tester_main/tester_func.c b/diode_tester/Core/Tester_main/tester_func.c index fcfdfc2..5d4f90f 100644 --- a/diode_tester/Core/Tester_main/tester_func.c +++ b/diode_tester/Core/Tester_main/tester_func.c @@ -21,6 +21,8 @@ void TESTER_HandleInit(TESTER_TestHandleTypeDef *htest, TESTER_LEDsTypeDef *leds */ void TESTER_TestDiode_Forward(TESTER_TestHandleTypeDef *htest) { + /* Отключение питания от диода */ + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Очистка буферов каналов */ ClearStruct(htest->adc->chAdc.ADC_Buff); @@ -48,8 +50,7 @@ void TESTER_TestDiode_Forward(TESTER_TestHandleTypeDef *htest) } /* Отключение питания от диода */ - TESTER_Disconnect_Phase(&htest->SwPhaseForward); - TESTER_Disconnect_Phase(&htest->SwPhaseReverse); + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Выключение континиус АЦП */ HAL_ADC_Stop(htest->adc->hadc); @@ -64,6 +65,8 @@ void TESTER_TestDiode_Forward(TESTER_TestHandleTypeDef *htest) */ void TESTER_TestDiode_Reverse(TESTER_TestHandleTypeDef *htest) { + /* Отключение питания от диода */ + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Очистка буферов каналов */ ClearStruct(htest->adc->chAdc.ADC_Buff); @@ -85,8 +88,7 @@ void TESTER_TestDiode_Reverse(TESTER_TestHandleTypeDef *htest) TESTER_Delay(&htest->SwTimings.ticks_before_disconnect, &hmcstim); /* Отключение питания от диода */ - TESTER_Disconnect_Phase(&htest->SwPhaseReverse); - TESTER_Disconnect_Phase(&htest->SwPhaseForward); + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Обработка DMA */ ADC_DMA_ReadForPeak(htest->adc, ADC_READ_TIMEOUT_MS); @@ -102,6 +104,8 @@ void TESTER_TestDiode_Reverse(TESTER_TestHandleTypeDef *htest) */ void TESTER_TestDiode_SwitchConnection(TESTER_TestHandleTypeDef *htest) { + /* Отключение питания от диода */ + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Очистка буферов каналов */ ClearStruct(htest->adc->chAdc.ADC_Buff); @@ -125,8 +129,7 @@ void TESTER_TestDiode_SwitchConnection(TESTER_TestHandleTypeDef *htest) TESTER_Delay(&htest->SwTimings.ticks_before_disconnect, &hmcstim); /* Отключение питания от диода */ - TESTER_Disconnect_Phase(&htest->SwPhaseReverse); - TESTER_Disconnect_Phase(&htest->SwPhaseForward); + TESTER_Disconnect_AllPhases(&htest->SwPhaseReverse, &htest->SwPhaseForward); /* Обработка DMA */ ADC_DMA_ReadForPeak(htest->adc, ADC_READ_TIMEOUT_MS); @@ -136,37 +139,45 @@ void TESTER_TestDiode_SwitchConnection(TESTER_TestHandleTypeDef *htest) htest->DiodeReversePeakVolt = htest->adc->chAdc.U_Current; } + +/** + * @brief Тестирование одного ключа + */ +void TESTER_TestOneSwitch(GPIO_TypeDef *SwPort, uint32_t SwPin, uint8_t flag) +{ + if(flag) + { + TESTER_PhaseSwSingle_Set(SwPort, SwPin); + } + else + { + TESTER_PhaseSwSingle_Reset(SwPort, SwPin); + } +} + /** * @brief Подключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ -void TESTER_Connect_Phase(TESTER_PhaseSwitchTypeDef *DCSw) +void TESTER_Connect_Phase(TESTER_PhaseSwitchTypeDef *PhaseSw) { -#ifdef USE_HAL_GPIO_FUNCTIONS // in tester_config.h - HAL_GPIO_WritePin(DCSw->SW_Port, DCSw->SwHI_Pin | DCSw->SwLO_Pin, PHASE_CONNECT); -#else // USE_HAL_GPIO_FUNCTIONS - #if (PHASE_CONNECT == 1) - DCSw->SW_Port->BSRR = DCSw->SwHI_Pin | DCSw->SwLO_Pin; - #else //PHASE_CONNECT == 1 - DCSw->SW_Port->BSRR = (DCSw->SwHI_Pin | DCSw->SwLO_Pin) << 16; - #endif //PHASE_CONNECT == 1 -#endif //USE_HAL_GPIO_FUNCTIONS + TESTER_PhaseSw_Set(PhaseSw); } /** * @brief Отключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ -void TESTER_Disconnect_Phase(TESTER_PhaseSwitchTypeDef *DCSw) +void TESTER_Disconnect_Phase(TESTER_PhaseSwitchTypeDef *PhaseSw) { -#ifdef USE_HAL_GPIO_FUNCTIONS - HAL_GPIO_WritePin(DCSw->SW_Port, DCSw->SwHI_Pin | DCSw->SwLO_Pin, PHASE_DISCONNECT); -#else // USE_HAL_GPIO_FUNCTIONS - #if (PHASE_DISCONNECT == 0) - DCSw->SW_Port->BSRR = (DCSw->SwHI_Pin | DCSw->SwLO_Pin) << 16; - #else //PHASE_CONNECT == 1 - DCSw->SW_Port->BSRR = DCSw->SwHI_Pin | DCSw->SwLO_Pin; - #endif //PHASE_CONNECT == 1 -#endif //USE_HAL_GPIO_FUNCTIONS + TESTER_PhaseSw_Reset(PhaseSw); } +/** + * @brief Отключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef + */ +void TESTER_Disconnect_AllPhases(TESTER_PhaseSwitchTypeDef *SwPhaseA, TESTER_PhaseSwitchTypeDef *SwPhaseB) +{ + TESTER_PhaseSw_Reset(SwPhaseA); + TESTER_PhaseSw_Reset(SwPhaseB); +} /** * @brief Переключить две фазы с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ @@ -174,68 +185,40 @@ void TESTER_Reconnect_TwoPhases(TESTER_PhaseSwitchTypeDef *SwPhaseA, TESTER_Phas { /* Если дедтайм меньше 100 мкс, то сначала запускаем АЦП а потом дедтаймим */ /* Потому что эта функция по длительности порядка 30 мкс, поэтому дедтайм получается не может быть меньше 30 мкс*/ + #ifndef RECONNECT_WITHOUT_DEADTIME if(deadtime->msdelay == 0) { if(deadtime->ticks < 100) { + #endif //RECONNECT_WITHOUT_DEADTIME /* Включение АЦП */ - ADC_DMA_StartRead(hTestDiode.adc); + ADC_DMA_StartRead(hTestDiode.adc); + + /* Ожидается задержка, перед предполагаемым скачком */ + TESTER_Delay(&hTestDiode.SwTimings.ticks_before_expected_peak, &hmcstim); + #ifndef RECONNECT_WITHOUT_DEADTIME } } + #endif //RECONNECT_WITHOUT_DEADTIME - -#ifdef USE_HAL_GPIO_FUNCTIONS - - HAL_GPIO_WritePin(SwPhaseA->SW_Port, SwPhaseA->SwHI_Pin | SwPhaseA->SwLO_Pin, PHASE_DISCONNECT); + TESTER_PhaseSw_Reset(SwPhaseA); #ifndef RECONNECT_WITHOUT_DEADTIME /* Ожидается задержка дедтайм */ TESTER_Delay(deadtime, &hmcstim); - #endif //RECONNECT_WITHOUT_DEADTIME /* Включение АЦП */ ADC_DMA_StartRead(hTestDiode.adc); + /* Ожидается задержка, перед предполагаемым скачком */ TESTER_Delay(&hTestDiode.SwTimings.ticks_before_expected_peak, &hmcstim); - - HAL_GPIO_WritePin(SwPhaseB->SW_Port, SwPhaseB->SwHI_Pin | SwPhaseB->SwLO_Pin, PHASE_CONNECT); -#else // USE_HAL_GPIO_FUNCTIONS - #ifdef RECONNECT_WITHOUT_DEADTIME - /* Включение АЦП */ - ADC_DMA_StartRead(hTestDiode.adc); - /* Ожидается задержка, перед предполагаемым скачком */ - TESTER_Delay(&hTestDiode.SwTimings.ticks_before_expected_peak, &hmcstim); - - #if (PHASE_CONNECT == 1) && (PHASE_DISCONNECT == 0) - SwPhaseA->SW_Port->BSRR = ((SwPhaseB->SwHI_Pin | SwPhaseB->SwLO_Pin) | ((SwPhaseA->SwHI_Pin | SwPhaseA->SwLO_Pin) << 16)); - #elif (PHASE_CONNECT == 1) && (PHASE_DISCONNECT == 0) - SwPhaseA->SW_Port->BSRR = (((SwPhaseB->SwHI_Pin | SwPhaseB->SwLO_Pin) << 16)| (SwPhaseA->SwHI_Pin | SwPhaseA->SwLO_Pin)); - #endif //PHASE_CONNECT && PHASE_DISCONNECT - - #else //RECONNECT_WITHOUT_DEADTIME - #if (PHASE_DISCONNECT == 0) - SwPhaseA->SW_Port->BSRR = (SwPhaseA->SwHI_Pin | SwPhaseA->SwLO_Pin) << 16; - #else //PHASE_DISCONNECT == 1 - SwPhaseA->SW_Port->BSRR = SwPhaseA->SwHI_Pin | SwPhaseA->SwLO_Pin; - #endif //PHASE_DISCONNECT - - /* Ожидается задержка дедтайм */ - TESTER_Delay(deadtime, &hmcstim); - - /* Включение АЦП */ - ADC_DMA_StartRead(hTestDiode.adc); - /* Ожидается задержка, перед предполагаемым скачком */ - TESTER_Delay(&hTestDiode.SwTimings.ticks_before_expected_peak, &hmcstim); - - #if (PHASE_CONNECT == 1) - SwPhaseB->SW_Port->BSRR = SwPhaseB->SwHI_Pin | SwPhaseB->SwLO_Pin; - #else //PHASE_CONNECT == 0 - SwPhaseB->SW_Port->BSRR = (SwPhaseB->SwHI_Pin | SwPhaseB->SwLO_Pin) << 16; - #endif //PHASE_CONNECT #endif //RECONNECT_WITHOUT_DEADTIME -#endif //USE_HAL_GPIO_FUNCTIONS + + + TESTER_PhaseSw_Set(SwPhaseB); } + /** * @brief Формирование задержки (в микро или миллисекундная) */ diff --git a/diode_tester/Core/Tester_main/tester_func.h b/diode_tester/Core/Tester_main/tester_func.h index c9403de..5ce0d83 100644 --- a/diode_tester/Core/Tester_main/tester_func.h +++ b/diode_tester/Core/Tester_main/tester_func.h @@ -17,7 +17,33 @@ /** * @brief Хендл микросекундного таймера */ -#define hmcstim htim3 +#define hmcstim htim3 + + +#ifdef USE_HAL_GPIO_FUNCTIONS +#define TESTER_PhaseSw_Set(_sw_) HAL_GPIO_WritePin((_sw_)->SW_Port, (_sw_)->SwHI_Pin | (_sw_)->SwLO_Pin, PHASE_CONNECT) +#define TESTER_PhaseSw_Reset(_sw_) HAL_GPIO_WritePin((_sw_)->SW_Port, (_sw_)->SwHI_Pin | (_sw_)->SwLO_Pin, PHASE_DISCONNECT) + +#define TESTER_PhaseSwSingle_Set(_swport_, _swpin_) HAL_GPIO_WritePin((_swport_), (_swpin_), PHASE_CONNECT) +#define TESTER_PhaseSwSingle_Reset(_swport_, _swpin_) HAL_GPIO_WritePin((_swport_), (_swpin_), PHASE_DISCONNECT) +#else //USE_HAL_GPIO_FUNCTIONS + +#if (PHASE_CONNECT == 1) && (PHASE_DISCONNECT == 0) +#define TESTER_PhaseSw_Set(_sw_) (_sw_)->SW_Port->BSRR = (_sw_)->SwHI_Pin | (_sw_)->SwLO_Pin +#define TESTER_PhaseSw_Reset(_sw_) (_sw_)->SW_Port->BSRR = ((_sw_)->SwHI_Pin | (_sw_)->SwLO_Pin) << 16 + +#define TESTER_PhaseSwSingle_Set(_swport_, _swpin_) (_swport_)->BSRR = (_swpin_) +#define TESTER_PhaseSwSingle_Reset(_swport_, _swpin_) (_swport_)->BSRR = ((_swpin_) << 16) +#elif (PHASE_CONNECT == 0) && (PHASE_DISCONNECT == 1) +#define TESTER_PhaseSw_Set(_sw_) (_sw_)->SW_Port->BSRR = ((_sw_)->SwHI_Pin | _sw_->SwLO_Pin) << 16 +#define TESTER_PhaseSw_Reset(_sw_) (_sw_)->SW_Port->BSRR = (_sw_)->SwHI_Pin | (_sw_)->SwLO_Pin + +#define TESTER_PhaseSwSingle_Set(_swport_, _swpin_) (_swport_)->BSRR = ((_swpin_) << 16) +#define TESTER_PhaseSwSingle_Reset(_swport_, _swpin_) (_swport_)->BSRR = (_swpin_) +#endif //POWER_CONNECT + +#endif //USE_HAL_GPIO_FUNCTIONS + extern TIM_HandleTypeDef htim3; /** @@ -85,10 +111,15 @@ void TESTER_TestDiode_Reverse(TESTER_TestHandleTypeDef *htest); /* Тест диодов: подключение прямого, а потом обратного напряжения */ void TESTER_TestDiode_SwitchConnection(TESTER_TestHandleTypeDef *htest); +/* Тестирование одного ключа */ +void TESTER_TestOneSwitch(GPIO_TypeDef *SwPort, uint32_t SwPin, uint8_t flag); + /* Подключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ -void TESTER_Connect_Phase(TESTER_PhaseSwitchTypeDef *DCSw); +void TESTER_Connect_Phase(TESTER_PhaseSwitchTypeDef *PhaseSw); /* Отключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ -void TESTER_Disconnect_Phase(TESTER_PhaseSwitchTypeDef *DCSw); +void TESTER_Disconnect_Phase(TESTER_PhaseSwitchTypeDef *PhaseSw); +/* Отключить фазу с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ +void TESTER_Disconnect_AllPhases(TESTER_PhaseSwitchTypeDef *SwPhaseA, TESTER_PhaseSwitchTypeDef *SwPhaseB); /* Переключить две фазы с помощью ключей (пинов) в TESTER_PhaseSwitchTypeDef */ void TESTER_Reconnect_TwoPhases(TESTER_PhaseSwitchTypeDef *SwPhaseA, TESTER_PhaseSwitchTypeDef *SwPhaseB, TESTER_TicksDelayTypeDef *deadtime); /* Формирование задержки (в микро или миллисекундная) */ diff --git a/diode_tester/Core/Tester_main/tester_main.c b/diode_tester/Core/Tester_main/tester_main.c index cdb4fd5..4ea9688 100644 --- a/diode_tester/Core/Tester_main/tester_main.c +++ b/diode_tester/Core/Tester_main/tester_main.c @@ -49,6 +49,19 @@ void TESTER_main_while(TESTER_ProjectTypeDef *tester) if(tester->delay_en) msDelay(tester->delay); + + /* ПОДТЯГИВАНИЕ СОСТОЯНИЯ КЛЮЧЕЙ С МОДБАС */ + TESTER_TestOneSwitch(tester->htest->SwPhaseForward.SW_Port, tester->htest->SwPhaseForward.SwHI_Pin, + tester->mbdata->Coils.PhaseForwardHiTest); + TESTER_TestOneSwitch(tester->htest->SwPhaseForward.SW_Port, tester->htest->SwPhaseForward.SwLO_Pin, + tester->mbdata->Coils.PhaseForwardLoTest); + TESTER_TestOneSwitch(tester->htest->SwPhaseForward.SW_Port, tester->htest->SwPhaseReverse.SwHI_Pin, + tester->mbdata->Coils.PhaseReverseHiTest); + TESTER_TestOneSwitch(tester->htest->SwPhaseForward.SW_Port, tester->htest->SwPhaseReverse.SwLO_Pin, + tester->mbdata->Coils.PhaseReverseLoTest); + + + /* ТЕСТ В ОБРАТНОМ ВКЛЮЧЕНИИ */ if(tester->func.test_diode_reverse) { @@ -106,14 +119,13 @@ void TESTER_InterfaceHandle(TESTER_ProjectTypeDef *tester) return; - - /* считывание режима тестера с модбас */ - tester->mode = *((TESTER_TestModeTypeDef *)&tester->mbdata->Coils); + tester->mode = *((TESTER_TestModeTypeDef *)&tester->mbdata->Coils) & 0x3; /* если кнопка нажата или пришла соответствующая комманда модбас */ if(TESTER_ReadSwichStart(&tester->SwStart) || tester->mbdata->Coils.StartTest) { + tester->mbdata->Coils.StartTest = 0; /* Обновление настроек тестера */ TESTER_UpdateSettings(tester->htest, tester->mbdata); switch(tester->mode) diff --git a/diode_tester/MDK-ARM/diode_tester.uvoptx b/diode_tester/MDK-ARM/diode_tester.uvoptx index b1024a4..a2aa8ef 100644 --- a/diode_tester/MDK-ARM/diode_tester.uvoptx +++ b/diode_tester/MDK-ARM/diode_tester.uvoptx @@ -265,6 +265,10 @@ System Viewer\ADC1 35903 + + System Viewer\AFIO + 35905 + System Viewer\DMA1 35902 @@ -278,8 +282,8 @@ 35901 - System Viewer\GPIOC - 35905 + System Viewer\USART1 + 35900