chargeController/APP/businessLogic/Src/bl_chargControl.c

914 lines
23 KiB
C
Raw Normal View History

2024-12-06 09:38:25 +00:00
#include "bl_chargControl.h"
#include "parameter.h"
#include "comm_types.h"
2024-12-09 14:07:40 +00:00
#include "FM_GPIO.h"
2024-12-10 14:25:55 +00:00
#include "task.h"
#include "SOE.h"
2024-12-09 14:07:40 +00:00
2024-12-06 09:38:25 +00:00
2024-12-06 13:23:28 +00:00
static BOOL stopChargConditions(void);
static BOOL floatChargConditions(void);
static BOOL mpptChargConditions(void);
static BOOL constantVChargConditions(void);
2024-12-06 09:38:25 +00:00
static void mpptCharge(void);
static void constantVoltageCharge(void);
static void floatCharge(void);
2024-12-09 14:07:40 +00:00
static void mppt_constantVoltage(float InVoltage);
static void mppt_constantVoltageNoBatteryO(float OutVoltage);
static void mppt_constantVoltageO(float OutVoltage);
static void judgeYNBattery(void);
static void chargControlMode(void);
static void BatteryChargControl(void);
static void noBatteryChargControl(void);
2025-01-10 03:43:43 +00:00
static void setPIControlStep(float *PI_step);
static BOOL chargControlFlag = FALSE;
2024-12-11 14:11:05 +00:00
// static BOOL getChargControlFlag(void);
void setChargControlFlag(BOOL state);
2025-01-10 03:43:43 +00:00
void setPIControlStep(float *PI_step)
{
if (*PI_step > PI_CONTROL_MAX) {
*PI_step = PI_CONTROL_MAX;
}
else if (*PI_step < PI_CONTROL_MIN) {
*PI_step = PI_CONTROL_MIN;
}
}
2024-12-09 14:07:40 +00:00
/**
* @brief
* @param InVoltage
* @retval
*
*/
void mppt_constantVoltage(float InVoltage)
{
2025-02-20 08:24:49 +00:00
static float kp = 0.005f;
// static float ki = 0.00001;
// static float ki = 0.1f;
static float ki = 10.0f;
2024-12-11 09:51:48 +00:00
// static float solarInCircuitVoltage;
2024-12-09 14:07:40 +00:00
static float error;
2024-12-26 03:48:54 +00:00
static float stepPwm;
2024-12-09 14:07:40 +00:00
2024-12-11 09:51:48 +00:00
// solarInCircuitVoltage = getSolarInCircuitVoltage();
// error = InVoltage - getSolarInCircuitVoltage();
error = getSolarInCircuitVoltage() - InVoltage;
2025-02-20 08:24:49 +00:00
// static float Ierror;
// Ierror += error;
// stepPwm = kp * error + ki * getSolarInCircuitVoltage();
stepPwm = kp * error + ki * error * 0.00001f;
2024-12-09 14:07:40 +00:00
2025-01-10 03:43:43 +00:00
setPIControlStep(&stepPwm);
2024-12-24 06:43:20 +00:00
2024-12-09 14:07:40 +00:00
setDutyRatio((getDutyRatio() + stepPwm));
2025-02-20 08:24:49 +00:00
// if (getMosTemperState() == mosTemperEnd) {
2024-12-24 06:43:20 +00:00
// setDutyRatio((getDutyRatio() + stepPwm - 0.1));
// } else {
// setDutyRatio((getDutyRatio() + stepPwm));
// }
2024-12-09 14:07:40 +00:00
}
/**
* @brief ()
* @param
* @retval
*
*/
void mppt_constantVoltageNoBatteryO(float OutVoltage)
{
2025-02-20 08:24:49 +00:00
static float kp = 0.005f;
// static float ki = 0.00001;
// static float ki = 0.1f;
static float ki = 10.0f;
2024-12-09 14:07:40 +00:00
static float outVolt;
static float error;
static float stepPwm;
outVolt = getOutputVoltage();
error = OutVoltage - outVolt;
2025-02-20 08:24:49 +00:00
// static float Ierror;
// Ierror += error;
// stepPwm = kp * error + ki * outVolt;
stepPwm = kp * error + ki * error * 0.00001f;
2025-01-10 03:43:43 +00:00
setPIControlStep(&stepPwm);
2024-12-09 14:07:40 +00:00
setDutyRatio((getDutyRatio() + stepPwm));
}
/**
* @brief
* @param
* @retval
*
*/
void mppt_constantVoltageO(float OutVoltage)
{
// static float lastVolt = 0;
// static float lastStepPwm = 0;
static float lastDutyRatio = 0;
2025-02-20 08:24:49 +00:00
static float kp = 0.005f;
// static float ki = 0.00001;
// static float ki = 0.1f;
static float ki = 10.0f;
2024-12-09 14:07:40 +00:00
static float outVolt;
static float error;
static float StepPwm;
outVolt = getOutputVoltage();
error = OutVoltage - outVolt;
2025-02-20 08:24:49 +00:00
// static float Ierror;
// Ierror += error;
// StepPwm = kp * error + ki * outVolt;
StepPwm = kp * error + ki * error * 0.00001f;
2025-01-10 03:43:43 +00:00
setPIControlStep(&StepPwm);
2024-12-09 14:07:40 +00:00
/* 当有电池时,输出电压的曲线是先上升后下降 */
if (lastDutyRatio >= getDutyRatio()) {
// if (lastVolt >= outVolt) {
setDutyRatio((getDutyRatio() + StepPwm));
2024-12-24 06:43:20 +00:00
// if (getMosTemperState() == mosTemperEnd) {
// setDutyRatio((getDutyRatio() + StepPwm - 0.1));
// } else {
// setDutyRatio((getDutyRatio() + StepPwm));
// }
2024-12-09 14:07:40 +00:00
// } else {
// g_controlParameter.dutyRatio -= StepPwm;
// }
} else {
// if (lastVolt >= outVolt) {
// g_controlParameter.dutyRatio -= StepPwm;
// } else {
// g_controlParameter.dutyRatio += StepPwm;
// }
2024-12-24 06:43:20 +00:00
setDutyRatio((getDutyRatio() - StepPwm));
// if (getMosTemperState() == mosTemperEnd) {
// setDutyRatio((getDutyRatio() + StepPwm - 0.1));
// } else {
// setDutyRatio((getDutyRatio() + StepPwm));
// }
2024-12-09 14:07:40 +00:00
}
// lastVolt = outVolt;
// lastStepPwm = StepPwm;
lastDutyRatio = getDutyRatio();
}
/**
* @brief
* @param
* @retval
*
*/
void mppt_readJust(void)
{
/* 调节占空比 */
// static float_t step1 = 0.01;
// static float_t step2 = 0.003;
// static float_t tempV = 0.2;
// static float_t i = 0.005;
// static uint16_t flag = 0;
// static float_t lastSolarInCircuitVoltage = 0;
// static float_t lastPower = 0;
// flag++;
// if (flag < 500) {
// return;
// }
// flag = 0;
//
// float_t SolarInCircuitVoltage = get_PV1_VOLT_IN();
// float_t power = g_otherParameter.Output_Voltage * g_otherParameter.Charg_Current;
//
// float_t voltageDifference = SolarInCircuitVoltage - lastSolarInCircuitVoltage;
//
// /* 输出电压随占空比增加电压减小 */
// if (power <= lastPower) {
// if (lastSolarInCircuitVoltage <= SolarInCircuitVoltage) {
// if (voltageDifference > tempV) {
// g_controlParameter.dutyRatio += step2 + voltageDifference / i;
// } else {
// g_controlParameter.dutyRatio += step1 + voltageDifference / i;
// }
// } else {
// if (voltageDifference < -tempV) {
// g_controlParameter.dutyRatio -= step2 + voltageDifference / i;
// } else {
// g_controlParameter.dutyRatio -= step1 + voltageDifference / i;
// }
// }
// } else {
// if (lastSolarInCircuitVoltage <= SolarInCircuitVoltage) {
// if (voltageDifference > tempV) {
// g_controlParameter.dutyRatio -= step2 - voltageDifference / i;
// } else {
// g_controlParameter.dutyRatio -= step1 - voltageDifference / i;
// }
// } else {
// if (voltageDifference < -tempV) {
// g_controlParameter.dutyRatio += step2 - voltageDifference / i;
// } else {
// g_controlParameter.dutyRatio += step1 - voltageDifference / i;
// }
// }
// }
//
// lastPower = power;
// lastSolarInCircuitVoltage = SolarInCircuitVoltage;
//
// Set_duty_ratio(&g_controlParameter.dutyRatio);
/* 调节电压,变步长调节 */
// static float_t Power3 = 0; //上上次功率
// static float_t Power2 = 0; //上次功率
// static float_t Power1 = 0; //当前功率
// static float_t power23 = 0; //上次和上上次功率的绝对值
// static float_t power12 = 0; //当前功率和上次功率的绝对值
//// static float_t SolarInCircuitVoltage3 = 0; //上上次太阳能板电压
// static float_t SolarInCircuitVoltage2 = 0; //上次太阳能板电压
// static float_t SolarInCircuitVoltage1 = 0; //当前太阳能板电压
// static float_t SolarInCircuitVoltage12 = 0; //当前太阳能板电压和上次太阳能板电压的绝对值
// SolarInCircuitVoltage1 = get_PV1_VOLT_IN();
// Power1 = g_otherParameter.Output_Voltage * g_otherParameter.Charg_Current;
// static float_t power12Abs = 0;
// static float_t power23Abs = 0;
// static float_t SolarInCircuitVoltage12Abs = 0;
// static float_t dk = 0; //变步长因子
// static float_t stepV = 0;
// static float_t SolarInCircuitV = 18; //控制太阳能板的输出电压稳定在该值
//
// static float_t kp = 0.005;
// static float_t ki = 0.00001;
//
// /* 延时一段时间才判断 */
// static uint16_t flag = 0;
// flag++;
// if (flag < 1000) {
//// float_t pv1Volt = g_otherParameter.Solar_In_Circuit_Voltage;
// float_t pv1Volt = SolarInCircuitVoltage1;
// float_t error = pv1Volt - SolarInCircuitV;
// float_t stepPwm = kp * error + ki * pv1Volt;
//
// g_controlParameter.dutyRatio += stepPwm;
//
// /* 过温保护 */
// if (g_otherParameter.overTemperature == 0) {
//
// } else if (g_otherParameter.overTemperature == 1) {
// g_controlParameter.dutyRatio -= 0.1;
// } else if (g_otherParameter.overTemperature == 2) {
// g_controlParameter.dutyRatio -= 0.2;
// } else if (g_otherParameter.overTemperature == 3) {
// g_controlParameter.dutyRatio -= 0.3;
// }
//
// Set_duty_ratio(&g_controlParameter.dutyRatio);
//
// return;
// }
// flag = 0;
//
// power23 = Power2 - Power3;
// if (power23 < 0) {
// power23Abs = -power23;
// } else {
// power23Abs = power23;
// }
//
// power12 = Power1 - Power2;
// if (power12 < 0) {
// power12Abs = -power12;
// } else {
// power12Abs = power12;
// }
//
//// SolarInCircuitVoltage23 = SolarInCircuitVoltage2 - SolarInCircuitVoltage3;
//
// SolarInCircuitVoltage12 = SolarInCircuitVoltage1 - SolarInCircuitVoltage2;
//
// dk = power12Abs / power23Abs;
// stepV = dk * SolarInCircuitVoltage12Abs;
//
//// printf(" dk : %d/10000 \n", (int)(dk * 10000));
//
// if (power12 > 0) {
// if (SolarInCircuitVoltage12 > 0) {
// SolarInCircuitV = SolarInCircuitVoltage1 + stepV;
// } else {
// SolarInCircuitV = SolarInCircuitVoltage1 - stepV;
// }
// } else {
// if (SolarInCircuitVoltage12 > 0) {
// SolarInCircuitV = SolarInCircuitVoltage1 - stepV;
// } else {
// SolarInCircuitV = SolarInCircuitVoltage1 + stepV;
// }
// }
//
// printf(" SolarInCircuitV : %d/100 \n", (int)(SolarInCircuitV * 100));
//
// if (SolarInCircuitV > 21) {
// SolarInCircuitV = 21;
// }
// else if (SolarInCircuitV < 15) {
// SolarInCircuitV = 15;
// }
//
// printf(" SolarInCircuitV : %d/100 \n", (int)(SolarInCircuitV * 100));
//
// Power3 = Power2;
// Power2 = Power1;
//// SolarInCircuitVoltage3 = SolarInCircuitVoltage2;
// SolarInCircuitVoltage2 = SolarInCircuitVoltage1;
//
//// float_t pv1Volt = g_otherParameter.Solar_In_Circuit_Voltage;
// float_t pv1Volt = SolarInCircuitVoltage1;
// float_t error = pv1Volt - SolarInCircuitV;
// float_t stepPwm = kp * error + ki * pv1Volt;
//
// g_controlParameter.dutyRatio += stepPwm;
//
// /* 过温保护 */
// if (g_otherParameter.overTemperature == 0) {
//
// } else if (g_otherParameter.overTemperature == 1) {
// g_controlParameter.dutyRatio -= 0.1;
// } else if (g_otherParameter.overTemperature == 2) {
// g_controlParameter.dutyRatio -= 0.2;
// } else if (g_otherParameter.overTemperature == 3) {
// g_controlParameter.dutyRatio -= 0.3;
// }
//
// Set_duty_ratio(&g_controlParameter.dutyRatio);
//
// return;
/* 调节电压,两个电压步调节 */
static float stepV1 = 0.2;
static float stepV2 = 0.05;
2024-12-09 14:07:40 +00:00
static float Power = 0;
// static float totalPower = 0;
// static float powerData[50] = {0};
// static uint8_t powerIndex = 0;
static float totalChargeCurr = 0;
static float chargeCurrData[50] = {0};
static uint8_t chargeCurrIndex = 0;
/* 获取50次值的和 */
totalChargeCurr -= chargeCurrData[chargeCurrIndex];
chargeCurrData[chargeCurrIndex] = getChargCurrent();
totalChargeCurr += chargeCurrData[chargeCurrIndex];
chargeCurrIndex++;
if (chargeCurrIndex >= 50) {
chargeCurrIndex = 0;
2024-12-18 09:43:14 +00:00
}
2024-12-24 06:43:20 +00:00
// totalPower -= powerData[powerIndex];
// powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
// totalPower += powerData[powerIndex];
// powerIndex++;
// if (powerIndex >= 50) {
// powerIndex = 0;
// }
2024-12-09 14:07:40 +00:00
static float lPower = 0;
2024-12-16 09:28:12 +00:00
static float lLPower = 0;
2024-12-18 09:43:14 +00:00
// static float lLLPower = 0;
2024-12-09 14:07:40 +00:00
static float SolarInCircuitV = 17; //控制太阳能板的输出电压稳定在该值,初始为17V
// static float kp = 0.005;
// static float ki = 0.00001;
static uint8_t flag1 = 0; //表明上次运算是加还是减
/* 延时一段时间才判断 */
static uint16_t flag = 0;
flag++;
2024-12-18 09:43:14 +00:00
if (flag < 200) {
2024-12-09 14:07:40 +00:00
// float pv1Volt = getSolarInCircuitVoltage();
// float error = pv1Volt - SolarInCircuitV;
// float stepPwm = kp * error + ki * pv1Volt;
// setDutyRatio((getDutyRatio() + stepPwm));
// set_pwmDutyRatio(getDutyRatio());
mppt_constantVoltage(SolarInCircuitV);
return;
}
2024-12-24 06:43:20 +00:00
if (getMosTemperState() == mosTemperReduce) {
2025-02-18 08:47:04 +00:00
SolarInCircuitV = g_cfgParameter.MPPTReduceConstantVoltage;
mppt_constantVoltage(SolarInCircuitV);
return;
2024-12-24 06:43:20 +00:00
}
2024-12-09 14:07:40 +00:00
flag = 0;
2025-02-11 00:57:47 +00:00
// Power = totalPower / 30.0f;
// Power = totalPower;
Power = totalChargeCurr * getOutputVoltage();
2024-12-09 14:07:40 +00:00
static float powerT = 0;
powerT = Power - lPower;
if (powerT < 0) {
powerT = -powerT;
}
/* 滞环值 */
float hysteresisValue1;
float hysteresisValue2;
/* 一段时间内电流都很小则固定电压输出 */
static uint8_t currMinFlag = 0;
static uint8_t currMinFlag1 = 0;
// if (getChargCurrent() < 0.8f) {
if (totalChargeCurr < 120) {
// hysteresisValue1 = getChargCurrent() * 1.7f;
// hysteresisValue2 = getChargCurrent() * 12;
currMinFlag++;
2025-02-18 08:47:04 +00:00
if (currMinFlag == 5) {
currMinFlag = 0;
2025-02-18 08:47:04 +00:00
SolarInCircuitV = g_cfgParameter.MPPTConstantVoltage;
currMinFlag1 = 1;
}
return;
}
// else if (getChargCurrent() < 3 && currMinFlag1) {
else if (totalChargeCurr < 150 && currMinFlag1) {
2025-02-18 08:47:04 +00:00
// currMinFlag1 = 0;
currMinFlag = 0;
return;
}
// else if (getChargCurrent() < 7) {
else if (totalChargeCurr < 350) {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 1.1f;
// hysteresisValue2 = getChargCurrent() * 10;
hysteresisValue1 = totalChargeCurr / 40.0f;
hysteresisValue2 = totalChargeCurr / 4.0f;
}
// else if (getChargCurrent() < 20) {
else if (totalChargeCurr < 1000) {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.7f;
// hysteresisValue2 = getChargCurrent() * 7;
hysteresisValue1 = totalChargeCurr / 60.0f;
hysteresisValue2 = totalChargeCurr / 6.0f;
}
// else if (getChargCurrent() < 25) {
else if (totalChargeCurr < 1250) {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.5f;
// hysteresisValue2 = getChargCurrent() * 5;
hysteresisValue1 = totalChargeCurr / 90.0f;
hysteresisValue2 = totalChargeCurr / 9.0f;
}
else {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.3f;
// hysteresisValue2 = getChargCurrent() * 3;
hysteresisValue1 = totalChargeCurr / 140.0f;
hysteresisValue2 = totalChargeCurr / 14.0f;
}
// else {
// currMinFlag1 = 0;
// currMinFlag = 0;
// hysteresisValue1 = 120;
// hysteresisValue2 = 100;
// }
2025-02-11 00:57:47 +00:00
static uint8_t numFlag = 0;
2024-12-18 09:43:14 +00:00
// if ((lPower + 0.8f < Power) && (lLPower + 0.8f < Power) && (lLLPower + 0.8f < Power)) {
2025-02-11 00:57:47 +00:00
// if ((lPower + 0.1f < Power) && (lLPower + 0.1f < Power)) {
if ((lPower + hysteresisValue1 < Power) && (lLPower + hysteresisValue1 < Power)) {
2025-02-11 00:57:47 +00:00
numFlag = 0;
2024-12-18 09:43:14 +00:00
// if ((lPower + 0.3f < Power)) {
if (powerT > hysteresisValue2) {
2024-12-09 14:07:40 +00:00
if (flag1) {
SolarInCircuitV += stepV1;
flag1 = 1;
} else {
SolarInCircuitV -= stepV1;
flag1 = 0;
}
} else {
if (flag1) {
SolarInCircuitV += stepV2;
flag1 = 1;
} else {
SolarInCircuitV -= stepV2;
flag1 = 0;
}
}
2024-12-18 09:43:14 +00:00
// } else if ((lPower - 0.8f > Power) && (lLPower - 0.8f > Power) && (lLLPower - 0.8f > Power)) {
} else if ((lPower - hysteresisValue1 > Power) && (lLPower - hysteresisValue1 > Power)) {
2024-12-18 09:43:14 +00:00
// } else if ((lPower - 0.3f > Power)) {
numFlag = 0;
if (powerT > hysteresisValue2) {
2025-02-11 00:57:47 +00:00
numFlag = 0;
2024-12-09 14:07:40 +00:00
if (flag1) {
SolarInCircuitV -= stepV1;
flag1 = 0;
} else {
SolarInCircuitV += stepV1;
flag1 = 1;
}
} else {
if (flag1) {
SolarInCircuitV -= stepV2;
flag1 = 0;
} else {
SolarInCircuitV += stepV2;
flag1 = 1;
}
}
2025-02-11 00:57:47 +00:00
} else {
numFlag++;
2024-12-09 14:07:40 +00:00
}
2025-02-11 00:57:47 +00:00
/* 一段时间内都未调节 */
if (numFlag == 10) {
2025-02-11 00:57:47 +00:00
if (Power < 300) {
2025-02-18 08:47:04 +00:00
SolarInCircuitV = g_cfgParameter.MPPTConstantVoltage;
2025-02-11 00:57:47 +00:00
}
else if (flag1) {
SolarInCircuitV -= stepV2;
flag1 = 0;
}
else {
SolarInCircuitV += stepV2;
flag1 = 1;
}
}
if (SolarInCircuitV > 19.0f) {
SolarInCircuitV = 19.0f;
2024-12-09 14:07:40 +00:00
}
2024-12-09 14:07:40 +00:00
else if (SolarInCircuitV < 16.0f) {
SolarInCircuitV = 16.0f;
}
2024-12-18 09:43:14 +00:00
// lLLPower = lLPower;
2024-12-16 09:28:12 +00:00
lLPower = lPower;
2024-12-09 14:07:40 +00:00
lPower = Power;
2025-02-18 08:47:04 +00:00
mppt_constantVoltage(SolarInCircuitV);
2024-12-09 14:07:40 +00:00
}
2024-12-06 09:38:25 +00:00
/**
2024-12-11 09:51:48 +00:00
* @brief
2024-12-06 09:38:25 +00:00
* @param
* @retval
*
*/
2024-12-11 09:51:48 +00:00
void endChargWork(void)
2024-12-06 09:38:25 +00:00
{
2024-12-11 14:11:05 +00:00
setChargControlFlag(FALSE);
setDutyRatioToZero();
2024-12-10 14:25:55 +00:00
setMPPT_Mode(noWork);
beginStartControlTask();
EN_PWMOUT_Diseable();
2024-12-06 09:38:25 +00:00
}
2024-12-11 09:51:48 +00:00
/**
* @brief
* @param
* @retval
*
*/
void stopChargWork(void)
{
2024-12-11 14:11:05 +00:00
setChargControlFlag(FALSE);
setDutyRatioToZero();
2024-12-11 09:51:48 +00:00
setMPPT_Mode(noWork);
EN_PWMOUT_Diseable();
2024-12-11 09:51:48 +00:00
}
2024-12-11 14:11:05 +00:00
/**
* @brief
* @param
* @retval
*
*/
void beginChargWork(void)
{
beginStartControlTask();
EN_PWMOUT_Eable();
2024-12-11 14:11:05 +00:00
}
2024-12-11 09:51:48 +00:00
/**
* @brief
* @param
* @retval
*
*/
void startChargWork(void)
{
beginSoftStartTask();
EN_PWMOUT_Eable();
2024-12-11 09:51:48 +00:00
}
2024-12-06 09:38:25 +00:00
/**
* @brief
* @param
* @retval TRUE
* FALSE
*
*/
2024-12-24 06:43:20 +00:00
BOOL stopChargConditions(void)
2024-12-06 09:38:25 +00:00
{
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOutputCircuitV
2024-12-24 06:43:20 +00:00
&& getChargCurrent() < 1) {
// log_info("in stopChargConditions stopChargWork");
2024-12-24 06:43:20 +00:00
return TRUE;
}
2024-12-06 09:38:25 +00:00
/* 异常情况关闭充电 */
static uint16_t flag = 0;
if ((getSolarInCircuitVoltage() < (g_cfgParameter.stopSolarOutputCircuitV + 1)
2025-02-18 08:47:04 +00:00
// || getSolarInCircuitVoltage() > (g_cfgParameter.startSolarOpenCircuitV))
|| getSolarInCircuitVoltage() > 18.5f)
&& getChargCurrent() < 0.1f
&& getMPPT_Mode() == MPPT) {
// return TRUE;
flag++;
}
// if ((getSolarInCircuitVoltage() < 17.8f
// || getSolarInCircuitVoltage() > 20)
// && getChargCurrent() < 0.1f
// && getMPPT_Mode() == MPPT) {
// // return TRUE;
// flag++;
// }
2025-02-18 08:47:04 +00:00
else {
flag = 0;
}
2025-02-18 08:47:04 +00:00
if (flag > 10000) {
flag = 0;
insertEventsOrderRecord(abnormalControl);
return TRUE;
}
2024-12-06 09:38:25 +00:00
return FALSE;
}
/**
* @brief
* @param
* @retval TRUE
* FALSE
*
*/
BOOL floatChargConditions(void)
{
2024-12-10 14:25:55 +00:00
if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage() && g_cfgParameter.floatI > getChargCurrent())) {
2024-12-09 14:07:40 +00:00
return TRUE;
2024-12-10 14:25:55 +00:00
}
2024-12-09 14:07:40 +00:00
2024-12-06 09:38:25 +00:00
return FALSE;
}
/**
* @brief
* @param
* @retval TRUE
* FALSE
*
*/
BOOL mpptChargConditions(void)
{
2024-12-10 14:25:55 +00:00
if (((g_cfgParameter.constantVoltageChargeV - 0.2f) > getBatteryVoltage())
&& (getChargCurrent() > 0.05f)) {
2024-12-10 14:25:55 +00:00
return TRUE;
}
2024-12-06 09:38:25 +00:00
return FALSE;
}
/**
* @brief
* @param
* @retval TRUE
* FALSE
*
*/
BOOL constantVChargConditions(void)
{
2024-12-24 06:43:20 +00:00
if ((g_cfgParameter.constantVoltageV < getBatteryVoltage())
&& ((g_cfgParameter.floatI + 0.1f) <= getChargBatteryCurrent())) {
2024-12-10 14:25:55 +00:00
return TRUE;
}
2024-12-06 09:38:25 +00:00
return FALSE;
}
/**
* @brief
* @param
2024-12-06 13:23:28 +00:00
* @retval
2024-12-06 09:38:25 +00:00
*
*/
2024-12-06 13:23:28 +00:00
void chargControlMode(void)
2024-12-06 09:38:25 +00:00
{
if (stopChargConditions()) {
2024-12-11 09:51:48 +00:00
endChargWork();
2024-12-06 09:38:25 +00:00
}
2024-12-26 03:48:54 +00:00
else if (getBatteryState() == FALSE) {
setMPPT_Mode(noBattery);
}
2024-12-18 09:43:14 +00:00
else if (floatChargConditions()) {
setMPPT_Mode(floatCharg);
2024-12-06 09:38:25 +00:00
}
2024-12-18 09:43:14 +00:00
else if (constantVChargConditions()) {
setMPPT_Mode(constantVoltage);
2024-12-06 09:38:25 +00:00
}
2024-12-18 09:43:14 +00:00
else if (mpptChargConditions()) {
setMPPT_Mode(MPPT);
2024-12-26 03:48:54 +00:00
}
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
2024-12-24 06:43:20 +00:00
* @retval
2024-12-06 09:38:25 +00:00
*
*/
void judgeYNBattery(void)
{
2024-12-11 14:11:05 +00:00
if (getBatteryVoltage() > 16 || getBatteryVoltage() < 10) {
2024-12-09 14:07:40 +00:00
setBatteryState(FALSE);
return;
}
2024-12-11 14:11:05 +00:00
// if (getOutputVoltage() > 16 || getOutputVoltage() < 10) {
// setBatteryState(FALSE);
// return;
// }
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
* @retval
*
*/
void noBatteryChargControl(void)
{
mppt_constantVoltageNoBatteryO(g_cfgParameter.FloatChargeV);
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
* @retval
*
*/
void mpptCharge(void)
{
2024-12-09 14:07:40 +00:00
mppt_readJust();
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
* @retval
*
*/
void constantVoltageCharge(void)
{
2024-12-09 14:07:40 +00:00
mppt_constantVoltageO(g_cfgParameter.constantVoltageChargeV);
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
* @retval
*
*/
void floatCharge(void)
{
mppt_constantVoltageO(g_cfgParameter.FloatChargeV);
2024-12-06 09:38:25 +00:00
}
/**
* @brief
* @param
* @retval
*
*/
void BatteryChargControl(void)
{
switch(getMPPT_Mode()) {
2024-12-06 09:38:25 +00:00
2024-12-06 13:23:28 +00:00
case MPPT:
2024-12-06 09:38:25 +00:00
mpptCharge();
2025-02-11 00:57:47 +00:00
// mppt_constantVoltage(17.5f);
// setDutyRatio(0.1f);
2024-12-06 09:38:25 +00:00
break;
2024-12-06 13:23:28 +00:00
case constantVoltage:
2024-12-06 09:38:25 +00:00
constantVoltageCharge();
break;
2024-12-06 13:23:28 +00:00
case floatCharg:
2024-12-06 09:38:25 +00:00
floatCharge();
break;
default:
setMPPT_Mode(noWork);
// stopChargWork();
endChargWork();
2024-12-06 09:38:25 +00:00
break;
}
}
BOOL getChargControlFlag(void)
{
return chargControlFlag;
}
2024-12-11 14:11:05 +00:00
/**
* @brief
* @param TRUE
* FALSE
* @retval
*
*/
void setChargControlFlag(BOOL state)
{
if (state == TRUE || state == FALSE) {
chargControlFlag = state;
// debug_printf("chargControlFlag : %d", state);
2024-12-24 06:43:20 +00:00
}
if (state == TRUE) {
chargRunLed(runLedChargMode);
// debug_printf("setChargControlFlag is true");
2024-12-24 06:43:20 +00:00
} else if (state == FALSE) {
chargRunLed(runLedOtherMode);
// debug_printf("setChargControlFlag is false");
2024-12-24 06:43:20 +00:00
}
}
/**
* @brief
* @param
* @retval
*
*/
void bl_chargControl(void)
{
setBatteryVoltage();
if (getChargControlFlag() == FALSE) {
return;
}
// getCVData();
judgeYNBattery();
chargControlMode();
if (getMPPT_Mode() == noWork) {
return;
}
if (getBatteryState()) {
BatteryChargControl();
} else {
noBatteryChargControl();
}
// noBatteryChargControl();
}