Open precharge 1000ms after closing AIR+

This commit is contained in:
jazzpi 2022-08-05 00:17:23 +02:00
parent e3080b1f6e
commit 72c26fb758
2 changed files with 27 additions and 13 deletions

View File

@ -25,6 +25,7 @@
#define ADC_READ_TIMEOUT 500 // in ms
#define SDC_LOWER_THRESHOLD 2500 // in ADC Values
#define PRECHARGE_95_DURATION 1000 // in ms
#define PRECHARGE_OPEN_AFTER 1000 // in ms
// FIXME
#define LOWER_VEHICLE_SIDE_VOLTAGE_LIMIT 150000 // in mV

View File

@ -18,6 +18,10 @@ DMA_HandleTypeDef* sdc_voltage_dma = {0};
uint8_t air_adc_complete = 0;
uint8_t sdc_adc_complete = 0;
static uint32_t pos_air_change_timestamp, neg_air_change_timestamp,
precharge_change_timestamp;
static GPIO_PinState neg_air_state, pos_air_state, precharge_state;
AIRStateHandler init_AIR_State_Maschine() {
AIRStateHandler airstate = {0};
@ -204,10 +208,13 @@ void AIR_Discharge_Position() {
Set_Relay_Position(RELAY_AIR_POS, GPIO_PIN_RESET);
}
void AIR_Active_Position() // TODO Deactivate Precharge after a while to
// decrease current Consumption
{
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_SET);
void AIR_Active_Position() {
if (pos_air_state == GPIO_PIN_SET &&
HAL_GetTick() - pos_air_change_timestamp > PRECHARGE_OPEN_AFTER) {
Set_Relay_Position(RELAY_PRECHARGE, GPIO_PIN_RESET);
} else {
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);
}
@ -219,35 +226,41 @@ void AIR_Error_Position() {
}
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) {
if (position != neg_air_state) {
neg_air_change_timestamp = HAL_GetTick();
}
if (position == GPIO_PIN_SET && neg_air_state == GPIO_PIN_RESET) {
HAL_Delay(10);
}
neg = position;
neg_air_state = 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) {
if (position != pos_air_state) {
pos_air_change_timestamp = HAL_GetTick();
}
if (position == GPIO_PIN_SET && pos_air_state == GPIO_PIN_RESET) {
HAL_Delay(10);
}
pos = position;
pos_air_state = 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) {
if (position != precharge_state) {
precharge_change_timestamp = HAL_GetTick();
}
if (position == GPIO_PIN_SET && precharge_state == GPIO_PIN_RESET) {
HAL_Delay(10);
}
precharge = position;
precharge_state = position;
break;
}
}