Compare commits
2 Commits
3d4f9eab74
...
e3a226be54
| Author | SHA1 | Date | |
|---|---|---|---|
| e3a226be54 | |||
| 8b0ca85f3d |
@ -12,6 +12,7 @@
|
||||
|
||||
#include "stm32g441xx.h"
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
#define TS_INACTIVE 0
|
||||
#define TS_PRECHARGE 2
|
||||
@ -51,4 +52,8 @@ void AIR_Discharge_Position();
|
||||
void AIR_Active_Position();
|
||||
void AIR_Error_Position();
|
||||
|
||||
typedef enum { RELAY_AIR_NEG, RELAY_AIR_POS, RELAY_PRECHARGE } Relay;
|
||||
|
||||
void Set_Relay_Position(Relay relay, GPIO_PinState position);
|
||||
|
||||
#endif /* INC_AIR_STATE_MASCHINE_H_ */
|
||||
|
||||
@ -60,6 +60,7 @@ void FDCAN1_IT0_IRQHandler(void);
|
||||
void FDCAN1_IT1_IRQHandler(void);
|
||||
void TIM1_UP_TIM16_IRQHandler(void);
|
||||
void SPI1_IRQHandler(void);
|
||||
void TIM8_UP_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
@ -7,7 +7,10 @@
|
||||
|
||||
#include "AIR_State_Maschine.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
DMA_HandleTypeDef* air_current_dma = {0};
|
||||
DMA_HandleTypeDef* sdc_voltage_dma = {0};
|
||||
@ -178,48 +181,67 @@ void Deactivate_TS(AIRStateHandler* airstate) {
|
||||
}
|
||||
|
||||
void AIR_Precharge_Position() {
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Inactive_Position() {
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Discharge_Position() {
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void AIR_Active_Position() // TODO Deactivate Precharge after a while to
|
||||
// decrease current Consumption
|
||||
{
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_SET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void AIR_Error_Position() {
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_NEG, GPIO_PIN_RESET);
|
||||
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void Set_Relay_Position(Relay relay, GPIO_PinState position) {
|
||||
static GPIO_PinState neg = 0;
|
||||
static GPIO_PinState pos = 0;
|
||||
static GPIO_PinState precharge = 0;
|
||||
// Add a small delay after closing relays in order to not draw too much
|
||||
// current
|
||||
switch (relay) {
|
||||
case RELAY_AIR_NEG:
|
||||
HAL_GPIO_WritePin(AIR_negative_Control_GPIO_Port, AIR_negative_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && neg == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
neg = position;
|
||||
break;
|
||||
case RELAY_AIR_POS:
|
||||
HAL_GPIO_WritePin(AIR_Positive_Control_GPIO_Port, AIR_Positive_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && pos == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
pos = position;
|
||||
break;
|
||||
case RELAY_PRECHARGE:
|
||||
HAL_GPIO_WritePin(PreCharge_Control_GPIO_Port, PreCharge_Control_Pin,
|
||||
position);
|
||||
if (position == GPIO_PIN_SET && precharge == GPIO_PIN_RESET) {
|
||||
HAL_Delay(10);
|
||||
}
|
||||
precharge = position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,6 +322,9 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM8_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||
/* TIM8 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM8_UP_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM8_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM8_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM8_MspInit 1 */
|
||||
@ -358,6 +361,9 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM8_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM8_CLK_DISABLE();
|
||||
|
||||
/* TIM8 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(TIM8_UP_IRQn);
|
||||
/* USER CODE BEGIN TIM8_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM8_MspDeInit 1 */
|
||||
|
||||
@ -60,6 +60,7 @@
|
||||
extern FDCAN_HandleTypeDef hfdcan1;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim8;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
@ -259,6 +260,20 @@ void SPI1_IRQHandler(void)
|
||||
/* USER CODE END SPI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM8 update interrupt.
|
||||
*/
|
||||
void TIM8_UP_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim8);
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Mon Aug 01 08:27:49 CEST 2022]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Tue Aug 02 18:31:31 CEST 2022]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
||||
@ -65,6 +65,7 @@ NVIC.SPI1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.SVCall_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:false
|
||||
NVIC.TIM1_UP_TIM16_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.TIM8_UP_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:4\:0\:true\:false\:true\:false\:false\:false
|
||||
PA10.GPIOParameters=GPIO_Label
|
||||
PA10.GPIO_Label=Status_LED
|
||||
@ -151,7 +152,7 @@ ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=Makefile
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_CRC_Init-CRC-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_CRC_Init-CRC-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM8_Init-TIM8-false-HAL-true
|
||||
RCC.ADC12Freq_Value=16000000
|
||||
RCC.AHBFreq_Value=16000000
|
||||
RCC.APB1Freq_Value=16000000
|
||||
|
||||
Reference in New Issue
Block a user