From 3f9bcbfebbea2c3b2f85f461ce0a577af6953188 Mon Sep 17 00:00:00 2001 From: Yury Shuvakin Date: Wed, 14 Dec 2022 15:29:27 +0300 Subject: [PATCH] Output logic implemented --- Core/Inc/modConfig.h | 13 +++- Core/Src/main.c | 143 +++++++++++++++++++++++++++++++++-------- Core/Src/modCommands.c | 25 +++++++ Core/Src/modConfig.c | 12 ++++ 4 files changed, 163 insertions(+), 30 deletions(-) diff --git a/Core/Inc/modConfig.h b/Core/Inc/modConfig.h index 1a4d888..c496061 100644 --- a/Core/Inc/modConfig.h +++ b/Core/Inc/modConfig.h @@ -139,10 +139,19 @@ typedef struct { char GSM_PWD[50]; uint64_t serialNumber; - uint64_t PC_Time; - + bool chargeBatteryOutputChecked; + bool brushOrShuntOutputChecked; + bool brushOrShuntMode; // shunt -> false, brush -> true + uint16_t brushUsageSocThreshold; + uint16_t shuntChargingContactorDelay; + bool coolingOutputChecked; + int16_t coolingStartThreshold; + int16_t coolingStopThreshold; + bool heatingOutputChecked; + int16_t heatingStartThreshold; + int16_t heatingStopThreshold; } modConfigGeneralConfigStructTypedef; modConfigGeneralConfigStructTypedef* modConfigInit(void); diff --git a/Core/Src/main.c b/Core/Src/main.c index 27d18a0..4c2bdb4 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -272,6 +272,9 @@ uint16_t load_current = 0; uint16_t charge_current = 0; float float_current = 0; +bool need_shunt_charging_contractor = false; +uint64_t shunt_charging_contractor_clock = 0; + #define __MA_WIN_SIZE (500) #define __MA_ARRAY_QTY 2 @@ -977,19 +980,101 @@ void updateLimitsFromMem(){ maxTemperature_Hyst = generalConfig->allowedTempBattChargingMin; } -void Brush_Control() { - //Output_2_Pin GPIO_PIN_2 - //Output_2_GPIO_Port GPIOE +//void Brush_Control() { +// //Output_2_Pin GPIO_PIN_2 +// //Output_2_GPIO_Port GPIOE +// +// Brush_Minimum_SoC = generalConfig->minimalPrechargePercentage; +// Brush_Default_State = generalConfig->timeoutLCPreCharge; +// +// if(packState.SoC < Brush_Minimum_SoC) { +// HAL_GPIO_WritePin(Output_2_GPIO_Port, Output_2_Pin, !Brush_Default_State); +// Brush_Status = 1; //Brush is Up +// } else { +// HAL_GPIO_WritePin(Output_2_GPIO_Port, Output_2_Pin, Brush_Default_State); +// Brush_Status = 0; //Brush is down +// } +//} - Brush_Minimum_SoC = generalConfig->minimalPrechargePercentage; - Brush_Default_State = generalConfig->timeoutLCPreCharge; +void outputControl() +{ + // 2 output handle + if (generalConfig->chargeBatteryOutputChecked) + { + GPIO_PinState chargeContactorState = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_0); + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, chargeContactorState); + } + else + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); + } - if(packState.SoC < Brush_Minimum_SoC) { - HAL_GPIO_WritePin(Output_2_GPIO_Port, Output_2_Pin, !Brush_Default_State); - Brush_Status = 1; //Brush is Up - } else { - HAL_GPIO_WritePin(Output_2_GPIO_Port, Output_2_Pin, Brush_Default_State); - Brush_Status = 0; //Brush is down + // 3 output handle + if (!generalConfig->brushOrShuntMode) // brush mode + { + if (packState.SoC <= generalConfig->brushUsageSocThreshold) + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, generalConfig->brushOrShuntOutputChecked ? GPIO_PIN_RESET : GPIO_PIN_SET); + else + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, generalConfig->brushOrShuntOutputChecked ? GPIO_PIN_SET : GPIO_PIN_RESET); + + Brush_Status = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_3); + } + else // shunt mode + { + if (generalConfig->brushOrShuntOutputChecked) + { + GPIO_PinState loadContactorState = HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_1); + if (loadContactorState == GPIO_PIN_SET && !need_shunt_charging_contractor) + { + need_shunt_charging_contractor = true; + shunt_charging_contractor_clock = TIM_Clock; + } + + if (loadContactorState == GPIO_PIN_SET && need_shunt_charging_contractor && + (TIM_Clock - shunt_charging_contractor_clock) >= generalConfig->shuntChargingContactorDelay * 1000) + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); + } + + if (loadContactorState == GPIO_PIN_RESET) + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET); + need_shunt_charging_contractor = false; + } + } + else + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET); + need_shunt_charging_contractor = false; + } + } + + // 4 output handle + if (generalConfig->coolingOutputChecked) + { + if (packState.tempBatteryHigh <= generalConfig->coolingStopThreshold) + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET); + + if (packState.tempBatteryHigh >= generalConfig->coolingStartThreshold) + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET); + } + else + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET); + } + + // 5 output handle + if (generalConfig->heatingOutputChecked) + { + if (packState.tempBatteryLow >= generalConfig->heatingStopThreshold) + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_RESET); + + if (packState.tempBatteryLow <= generalConfig->heatingStartThreshold) + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_SET); + } + else + { + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_RESET); } } @@ -2081,29 +2166,31 @@ int main(void) charge_switch_state = 0; load_switch_state = 0; } - - Brush_Control(); + + //Brush_Control(); - // try to comment out state task !!! - // modPowerStateTask(); + // try to comment out state task !!! + // modPowerStateTask(); - // try to comment out state task !!! - // modOperationalStateTask(); + // try to comment out state task !!! + // modOperationalStateTask(); - //modPowerElectronicsCellMonitorsEnableBalanceResistors(0x00); - //modPowerElectronicsCellMonitorsEnableBalanceResistors(0x00000f80); + //modPowerElectronicsCellMonitorsEnableBalanceResistors(0x00); + //modPowerElectronicsCellMonitorsEnableBalanceResistors(0x00000f80); - // balance is disable - if(modPowerElectronicsTask()){ - // !!! check how works eeprom save !!! // Handle power electronics task - if (packState.serial_number!=0){ - Battery_Serial = packState.serial_number; - } - modStateOfChargeProcess(); + // balance is disable + if(modPowerElectronicsTask()){ + // !!! check how works eeprom save !!! // Handle power electronics task + if (packState.serial_number!=0){ + Battery_Serial = packState.serial_number; } - // If there is new data handle SoC estimation - // mainWatchDogReset(); + modStateOfChargeProcess(); + } + // If there is new data handle SoC estimation + // mainWatchDogReset(); + + outputControl(); } /* USER CODE END 3 */ diff --git a/Core/Src/modCommands.c b/Core/Src/modCommands.c index 7533352..35817fb 100644 --- a/Core/Src/modCommands.c +++ b/Core/Src/modCommands.c @@ -277,6 +277,18 @@ void modCommandsProcessPacket(unsigned char *data, unsigned int len) { modCommandsGeneralConfig->powerDownDelay = libBufferGet_uint32(data,&ind);// 4 modCommandsGeneralConfig->humidityICType = libBufferGet_uint8(data,&ind); // 1 + modCommandsGeneralConfig->chargeBatteryOutputChecked = libBufferGet_uint8(data, &ind); + modCommandsGeneralConfig->brushOrShuntOutputChecked = libBufferGet_uint8(data, &ind); + modCommandsGeneralConfig->brushOrShuntMode = libBufferGet_uint8(data, &ind); + modCommandsGeneralConfig->brushUsageSocThreshold = libBufferGet_uint16(data, &ind); + modCommandsGeneralConfig->shuntChargingContactorDelay = libBufferGet_uint16(data, &ind); + modCommandsGeneralConfig->coolingOutputChecked = libBufferGet_uint8(data, &ind); + modCommandsGeneralConfig->coolingStartThreshold = libBufferGet_int16(data, &ind); + modCommandsGeneralConfig->coolingStopThreshold = libBufferGet_int16(data, &ind); + modCommandsGeneralConfig->heatingOutputChecked = libBufferGet_uint8(data, &ind); + modCommandsGeneralConfig->heatingStartThreshold = libBufferGet_int16(data, &ind); + modCommandsGeneralConfig->heatingStopThreshold = libBufferGet_int16(data, &ind); + // RawSerialPtr = modCommandsGeneralConfig->displayTimeoutBatteryDead; // RawSerial = *RawSerialPtr; // RawSerial = RawSerial<<32; @@ -410,6 +422,19 @@ void modCommandsProcessPacket(unsigned char *data, unsigned int len) { libBufferAppend_uint32( modCommandsSendBuffer,modCommandsToBeSendConfig->powerDownDelay ,&ind); // 4 libBufferAppend_uint8( modCommandsSendBuffer,modCommandsToBeSendConfig->humidityICType ,&ind); // 1 //libBufferAppend_uint64( modCommandsSendBuffer,modCommandsToBeSendConfig->serialNumber , &ind); // 8 + + libBufferAppend_uint8(modCommandsSendBuffer, modCommandsToBeSendConfig->chargeBatteryOutputChecked, &ind); + libBufferAppend_uint8(modCommandsSendBuffer, modCommandsToBeSendConfig->brushOrShuntOutputChecked, &ind); + libBufferAppend_uint8(modCommandsSendBuffer, modCommandsToBeSendConfig->brushOrShuntMode, &ind); + libBufferAppend_uint16(modCommandsSendBuffer, modCommandsToBeSendConfig->brushUsageSocThreshold, &ind); + libBufferAppend_uint16(modCommandsSendBuffer, modCommandsToBeSendConfig->shuntChargingContactorDelay, &ind); + libBufferAppend_uint8(modCommandsSendBuffer, modCommandsToBeSendConfig->coolingOutputChecked, &ind); + libBufferAppend_int16(modCommandsSendBuffer, modCommandsToBeSendConfig->coolingStartThreshold, &ind); + libBufferAppend_int16(modCommandsSendBuffer, modCommandsToBeSendConfig->coolingStopThreshold, &ind); + libBufferAppend_uint8(modCommandsSendBuffer, modCommandsToBeSendConfig->heatingOutputChecked, &ind); + libBufferAppend_int16(modCommandsSendBuffer, modCommandsToBeSendConfig->heatingStartThreshold, &ind); + libBufferAppend_int16(modCommandsSendBuffer, modCommandsToBeSendConfig->heatingStopThreshold, &ind); + modCommandsSendPacket(modCommandsSendBuffer, ind); break; diff --git a/Core/Src/modConfig.c b/Core/Src/modConfig.c index 603d932..a28ea9d 100644 --- a/Core/Src/modConfig.c +++ b/Core/Src/modConfig.c @@ -221,6 +221,18 @@ void modConfigLoadDefaultConfig(modConfigGeneralConfigStructTypedef *configLocat configLocation->PC_Time=0; + configLocation->chargeBatteryOutputChecked = false; + configLocation->brushOrShuntOutputChecked = false; + configLocation->brushOrShuntMode = false; + configLocation->brushUsageSocThreshold = 10; + configLocation->shuntChargingContactorDelay = 5; + configLocation->coolingOutputChecked = false; + configLocation->coolingStartThreshold = 50; + configLocation->coolingStopThreshold = 40; + configLocation->heatingOutputChecked = false; + configLocation->heatingStartThreshold = 0; + configLocation->heatingStopThreshold = 20; + #elif ENNOID_HV configLocation->noOfCellsSeries = 8; // Total number of cells in series in the battery pack