Output logic implemented
This commit is contained in:
@@ -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);
|
||||
|
||||
111
Core/Src/main.c
111
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2082,7 +2167,7 @@ int main(void)
|
||||
load_switch_state = 0;
|
||||
}
|
||||
|
||||
Brush_Control();
|
||||
//Brush_Control();
|
||||
|
||||
|
||||
// try to comment out state task !!!
|
||||
@@ -2105,6 +2190,8 @@ int main(void)
|
||||
// If there is new data handle SoC estimation
|
||||
// mainWatchDogReset();
|
||||
|
||||
outputControl();
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user