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"
|
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);
|
|
|
|
|
|
2024-12-10 10:29:05 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
2024-12-10 10:29:05 +00:00
|
|
|
|
static BOOL chargControlFlag = FALSE;
|
2024-12-11 14:11:05 +00:00
|
|
|
|
// static BOOL getChargControlFlag(void);
|
2024-12-10 10:29:05 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
static float kp = 0.005;
|
|
|
|
|
static float ki = 0.00001;
|
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;
|
|
|
|
|
stepPwm = kp * error + ki * getSolarInCircuitVoltage();
|
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));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 恒定输出电压(无电池)
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void mppt_constantVoltageNoBatteryO(float OutVoltage)
|
|
|
|
|
{
|
|
|
|
|
static float kp = 0.005;
|
|
|
|
|
static float ki = 0.00001;
|
|
|
|
|
static float outVolt;
|
|
|
|
|
static float error;
|
|
|
|
|
static float stepPwm;
|
|
|
|
|
|
|
|
|
|
outVolt = getOutputVoltage();
|
|
|
|
|
error = OutVoltage - outVolt;
|
|
|
|
|
stepPwm = kp * error + ki * outVolt;
|
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;
|
|
|
|
|
static float kp = 0.005;
|
|
|
|
|
static float ki = 0.00001;
|
|
|
|
|
static float outVolt;
|
|
|
|
|
static float error;
|
|
|
|
|
static float StepPwm;
|
|
|
|
|
|
|
|
|
|
outVolt = getOutputVoltage();
|
|
|
|
|
error = OutVoltage - outVolt;
|
|
|
|
|
StepPwm = kp * error + ki * outVolt;
|
2025-01-10 03:43:43 +00:00
|
|
|
|
setPIControlStep(&StepPwm);
|
2024-12-09 14:07:40 +00:00
|
|
|
|
|
|
|
|
|
/* 当有电池时,输出电压的曲线是先上升后下降 */
|
|
|
|
|
if (lastDutyRatio >= getDutyRatio()) {
|
2024-12-10 10:29:05 +00:00
|
|
|
|
// if (lastVolt >= outVolt) {
|
2024-12-12 10:00:30 +00:00
|
|
|
|
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 Power = 0;
|
2024-12-18 09:43:14 +00:00
|
|
|
|
static float totalPower = 0;
|
|
|
|
|
static float powerData[50] = {0};
|
|
|
|
|
static uint8_t powerIndex = 0;
|
|
|
|
|
|
|
|
|
|
/* 获取50次的平均值 */
|
|
|
|
|
totalPower -= powerData[powerIndex];
|
|
|
|
|
powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
|
|
|
|
|
totalPower += powerData[powerIndex];
|
|
|
|
|
powerIndex++;
|
|
|
|
|
if (powerIndex >= 50) {
|
|
|
|
|
powerIndex = 0;
|
|
|
|
|
}
|
2024-12-24 06:43:20 +00:00
|
|
|
|
|
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;
|
|
|
|
|
|
2024-12-12 10:00:30 +00:00
|
|
|
|
static float stepV1 = 0.2;
|
|
|
|
|
static float stepV2 = 0.1;
|
2024-12-09 14:07:40 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2025-01-08 09:50:37 +00:00
|
|
|
|
if (getMosTemperState() == mosTemperReduce) {
|
2024-12-24 06:43:20 +00:00
|
|
|
|
SolarInCircuitV = 16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-09 14:07:40 +00:00
|
|
|
|
flag = 0;
|
2024-12-18 09:43:14 +00:00
|
|
|
|
Power = totalPower / 50.0f;
|
2024-12-09 14:07:40 +00:00
|
|
|
|
|
|
|
|
|
static float powerT = 0;
|
|
|
|
|
powerT = Power - lPower;
|
|
|
|
|
if (powerT < 0) {
|
|
|
|
|
powerT = -powerT;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 09:43:14 +00:00
|
|
|
|
// if ((lPower + 0.8f < Power) && (lLPower + 0.8f < Power) && (lLLPower + 0.8f < Power)) {
|
|
|
|
|
if ((lPower + 0.1f < Power) && (lLPower + 0.1f < Power)) {
|
|
|
|
|
// if ((lPower + 0.3f < Power)) {
|
2024-12-09 14:07:40 +00:00
|
|
|
|
if (powerT > 5) {
|
|
|
|
|
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 - 0.1f > Power) && (lLPower - 0.1f > Power)) {
|
|
|
|
|
// } else if ((lPower - 0.3f > Power)) {
|
2024-12-09 14:07:40 +00:00
|
|
|
|
if (powerT > 5) {
|
|
|
|
|
if (flag1) {
|
|
|
|
|
SolarInCircuitV -= stepV1;
|
|
|
|
|
flag1 = 0;
|
|
|
|
|
} else {
|
|
|
|
|
SolarInCircuitV += stepV1;
|
|
|
|
|
flag1 = 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (flag1) {
|
|
|
|
|
SolarInCircuitV -= stepV2;
|
|
|
|
|
flag1 = 0;
|
|
|
|
|
} else {
|
|
|
|
|
SolarInCircuitV += stepV2;
|
|
|
|
|
flag1 = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 10:00:30 +00:00
|
|
|
|
if (SolarInCircuitV > 20.0f) {
|
|
|
|
|
SolarInCircuitV = 20.0f;
|
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;
|
|
|
|
|
}
|
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();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 14:11:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 启动充电,开启启动任务
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void beginChargWork(void)
|
|
|
|
|
{
|
|
|
|
|
beginStartControlTask();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 09:51:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 启动充电,直接软启动
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void startChargWork(void)
|
|
|
|
|
{
|
|
|
|
|
beginSoftStartTask();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2025-01-08 09:50:37 +00:00
|
|
|
|
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOutputCircuitV
|
2024-12-24 06:43:20 +00:00
|
|
|
|
&& getChargCurrent() < 1) {
|
|
|
|
|
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.1f)) {
|
|
|
|
|
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()) {
|
2024-12-07 09:52:46 +00:00
|
|
|
|
setMPPT_Mode(floatCharg);
|
2024-12-06 09:38:25 +00:00
|
|
|
|
}
|
2024-12-10 10:29:05 +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-10 10:29:05 +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)
|
|
|
|
|
{
|
2025-01-08 09:50:37 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2025-01-08 09:50:37 +00:00
|
|
|
|
mppt_constantVoltageO(g_cfgParameter.FloatChargeV);
|
2024-12-06 09:38:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 有电池时控制
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void BatteryChargControl(void)
|
|
|
|
|
{
|
2024-12-07 09:52:46 +00:00
|
|
|
|
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();
|
2024-12-11 09:51:48 +00:00
|
|
|
|
// mppt_constantVoltage(17.0f);
|
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:
|
2024-12-07 09:52:46 +00:00
|
|
|
|
setMPPT_Mode(noWork);
|
2024-12-06 09:38:25 +00:00
|
|
|
|
stopChargWork();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 10:29:05 +00:00
|
|
|
|
BOOL getChargControlFlag(void)
|
|
|
|
|
{
|
|
|
|
|
return chargControlFlag;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 14:11:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 设置充电控制的标志位
|
|
|
|
|
* @param TRUE 启动充电控制
|
|
|
|
|
* FALSE 关闭充电控制
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-12-10 10:29:05 +00:00
|
|
|
|
void setChargControlFlag(BOOL state)
|
|
|
|
|
{
|
|
|
|
|
if (state == TRUE || state == FALSE) {
|
|
|
|
|
chargControlFlag = state;
|
2024-12-24 06:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state == TRUE) {
|
|
|
|
|
chargRunLed(runLedChargMode);
|
|
|
|
|
} else if (state == FALSE) {
|
|
|
|
|
chargRunLed(runLedOtherMode);
|
|
|
|
|
}
|
2024-12-10 10:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 完成充电控制
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void bl_chargControl(void)
|
|
|
|
|
{
|
2024-12-14 09:52:26 +00:00
|
|
|
|
setBatteryVoltage();
|
|
|
|
|
|
2024-12-10 10:29:05 +00:00
|
|
|
|
if (getChargControlFlag() == FALSE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// getCVData();
|
|
|
|
|
judgeYNBattery();
|
|
|
|
|
|
|
|
|
|
chargControlMode();
|
|
|
|
|
|
|
|
|
|
if (getMPPT_Mode() == noWork) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getBatteryState()) {
|
|
|
|
|
BatteryChargControl();
|
|
|
|
|
} else {
|
|
|
|
|
noBatteryChargControl();
|
2025-01-21 10:02:52 +00:00
|
|
|
|
}
|
|
|
|
|
// noBatteryChargControl();
|
2024-12-10 10:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|