Output logic implemented
This commit is contained in:
143
Core/Src/main.c
143
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 */
|
||||
|
||||
Reference in New Issue
Block a user