Compare commits

...

2 Commits

Author SHA1 Message Date
起床就犯困 25af1a47ff 修改前端输入功率较低时的执行方式 2025-02-13 08:55:55 +08:00
起床就犯困 a31b9af810 MPPT算法异常 2025-02-11 08:57:47 +08:00
12 changed files with 250 additions and 88 deletions

View File

@ -62,6 +62,9 @@ void start(void)
uartCommonInit();
// setDutyRatio(0.15f);
task_Init();
startInfo();
@ -72,7 +75,7 @@ void start(void)
// HAL_Delay(1000);
// }
/* 启动事件 */
insertEventsOrderRecord(startEvent);
// insertEventsOrderRecord(startEvent);
TimeSliceOffset_Start();
}

View File

@ -49,8 +49,8 @@ void Init(void)
// POW_OUT_PCON_Open();
HAL_Delay(100);
setPowerOutput(TRUE);
resetCheckImpedanceState();
// EN_PWMOUT_Eable();
// setDutyRatio(0.5);
// while (1) {
// log_info("Init_debug_uart \n");

View File

@ -299,12 +299,23 @@ void checkFFMOS_CON(void)
// FFMOS_CON_Close();
// }
if (getChargCurrent() > 5.0f && FALSE == FFMOS_CON_read()) {
FFMOS_CON_Open();
static uint8_t num = 100;
if (getChargCurrent() > 8.0f && FALSE == FFMOS_CON_read()) {
num--;
if (!num) {
FFMOS_CON_Open();
}
}
else if (getChargCurrent() < 2.0f && TRUE == FFMOS_CON_read()) {
// num--;
// if (!num) {
// FFMOS_CON_Close();
// }
FFMOS_CON_Close();
}
else {
num = 100;
}
}
// /**
@ -364,12 +375,14 @@ void lowInputLoadDetection(void)
if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt) {
num++;
// setOverLoad();
} else {
num = 0;
excessiveLoadInterruptFlag = FALSE;
}
if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.inputPowerLowDetectionDelay) {
excessiveLoadInterruptFlag = FALSE;
setOverLoad();
}
}
@ -468,6 +481,13 @@ void DSG_PROT_Interrupt(void)
}
}
/**
* @brief
* @param
* @retval
*
*/
void EXCHG_PROT_Interrupt(void)
{
setPowerOutput(FALSE);

View File

@ -334,20 +334,34 @@ void mppt_readJust(void)
// return;
/* 调节电压,两个电压步调节 */
static float stepV1 = 0.2;
static float stepV2 = 0.05;
static float Power = 0;
static float totalPower = 0;
static float powerData[50] = {0};
static uint8_t powerIndex = 0;
// 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;
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;
}
// totalPower -= powerData[powerIndex];
// powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
// totalPower += powerData[powerIndex];
// powerIndex++;
// if (powerIndex >= 50) {
// powerIndex = 0;
// }
static float lPower = 0;
static float lLPower = 0;
// static float lLLPower = 0;
@ -356,9 +370,6 @@ void mppt_readJust(void)
// static float kp = 0.005;
// static float ki = 0.00001;
static float stepV1 = 0.2;
static float stepV2 = 0.1;
static uint8_t flag1 = 0; //表明上次运算是加还是减
/* 延时一段时间才判断 */
@ -378,12 +389,14 @@ void mppt_readJust(void)
}
if (getMosTemperState() == mosTemperReduce) {
SolarInCircuitV = 16;
SolarInCircuitV = 20;
}
flag = 0;
Power = totalPower / 50.0f;
// Power = totalPower / 30.0f;
// Power = totalPower;
Power = totalChargeCurr * getOutputVoltage();
static float powerT = 0;
powerT = Power - lPower;
@ -391,10 +404,88 @@ void mppt_readJust(void)
powerT = -powerT;
}
/* 滞环值 */
float hysteresisValue1;
float hysteresisValue2;
/* 一段时间内电流都很小则固定电压输出 */
static uint8_t currMinFlag = 0;
static uint8_t currMinFlag1 = 0;
// if (getChargCurrent() < 0.8f) {
if (totalChargeCurr < 40) {
// hysteresisValue1 = getChargCurrent() * 1.7f;
// hysteresisValue2 = getChargCurrent() * 12;
currMinFlag++;
if (currMinFlag == 8) {
currMinFlag = 0;
SolarInCircuitV = 18.0f;
currMinFlag1 = 1;
}
return;
}
// else if (getChargCurrent() < 3 && currMinFlag1) {
else if (totalChargeCurr < 150 && currMinFlag1) {
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 / 45.0f;
hysteresisValue2 = totalChargeCurr / 5.0f;
}
// else if (getChargCurrent() < 20) {
else if (totalChargeCurr < 1000) {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.7f;
// hysteresisValue2 = getChargCurrent() * 7;
hysteresisValue1 = totalChargeCurr / 70.0f;
hysteresisValue2 = totalChargeCurr / 7.0f;
}
// else if (getChargCurrent() < 25) {
else if (totalChargeCurr < 1250) {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.5f;
// hysteresisValue2 = getChargCurrent() * 5;
hysteresisValue1 = totalChargeCurr / 100.0f;
hysteresisValue2 = totalChargeCurr / 10.0f;
}
else {
currMinFlag1 = 0;
currMinFlag = 0;
// hysteresisValue1 = getChargCurrent() * 0.3f;
// hysteresisValue2 = getChargCurrent() * 3;
hysteresisValue1 = totalChargeCurr / 150.0f;
hysteresisValue2 = totalChargeCurr / 16.0f;
}
// else {
// currMinFlag1 = 0;
// currMinFlag = 0;
// hysteresisValue1 = 120;
// hysteresisValue2 = 100;
// }
static uint8_t numFlag = 0;
// 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.1f < Power) && (lLPower + 0.1f < Power)) {
if ((lPower + hysteresisValue1 < Power) && (lLPower + hysteresisValue1 < Power)) {
numFlag = 0;
// if ((lPower + 0.3f < Power)) {
if (powerT > 5) {
if (powerT > hysteresisValue2) {
if (flag1) {
SolarInCircuitV += stepV1;
flag1 = 1;
@ -412,9 +503,10 @@ void mppt_readJust(void)
}
}
// } 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 - hysteresisValue1 > Power) && (lLPower - hysteresisValue1 > Power)) {
// } else if ((lPower - 0.3f > Power)) {
if (powerT > 5) {
if (powerT > hysteresisValue2) {
numFlag = 0;
if (flag1) {
SolarInCircuitV -= stepV1;
flag1 = 0;
@ -431,11 +523,30 @@ void mppt_readJust(void)
flag1 = 1;
}
}
} else {
numFlag++;
}
if (SolarInCircuitV > 20.0f) {
SolarInCircuitV = 20.0f;
/* 一段时间内都未调节 */
if (numFlag == 10) {
if (Power < 300) {
SolarInCircuitV = 17.0f;
}
else if (flag1) {
SolarInCircuitV -= stepV2;
flag1 = 0;
}
else {
SolarInCircuitV += stepV2;
flag1 = 1;
}
}
if (SolarInCircuitV > 19.0f) {
SolarInCircuitV = 19.0f;
}
else if (SolarInCircuitV < 16.0f) {
SolarInCircuitV = 16.0f;
}
@ -457,6 +568,7 @@ void endChargWork(void)
setDutyRatioToZero();
setMPPT_Mode(noWork);
beginStartControlTask();
EN_PWMOUT_Diseable();
}
/**
@ -470,6 +582,7 @@ void stopChargWork(void)
setChargControlFlag(FALSE);
setDutyRatioToZero();
setMPPT_Mode(noWork);
EN_PWMOUT_Diseable();
}
/**
@ -481,6 +594,7 @@ void stopChargWork(void)
void beginChargWork(void)
{
beginStartControlTask();
EN_PWMOUT_Eable();
}
/**
@ -492,6 +606,7 @@ void beginChargWork(void)
void startChargWork(void)
{
beginSoftStartTask();
EN_PWMOUT_Eable();
}
@ -539,7 +654,7 @@ BOOL floatChargConditions(void)
BOOL mpptChargConditions(void)
{
if (((g_cfgParameter.constantVoltageChargeV - 0.2f) > getBatteryVoltage())
&& (getChargCurrent() > 0.1f)) {
&& (getChargCurrent() > 0.05f)) {
return TRUE;
}
@ -666,7 +781,8 @@ void BatteryChargControl(void)
case MPPT:
mpptCharge();
// mppt_constantVoltage(17.0f);
// mppt_constantVoltage(17.5f);
// setDutyRatio(0.1f);
break;
case constantVoltage:

View File

@ -658,6 +658,7 @@ void stateMachine(device_handle device)
#endif
}
/* 串口通信协议的初始化 */
void uartCommonInit(void)
{
#ifdef HY_ChargeControlBox_PROTOCOL_ENABLE
@ -1446,6 +1447,9 @@ uint16_t SL_ReadRegisterYearMonth(void *pMsg)
{
timeInfo time;
getRTC_Time(&time);
// debug_printf("%d-%d\n", time.year, time.month);
return (time.year << 8) | time.month;
}
@ -1458,6 +1462,9 @@ uint16_t SL_ReadRegisterDayHour(void *pMsg)
{
timeInfo time;
getRTC_Time(&time);
// debug_printf("%d-%d\n", time.day, time.hour);
return (time.day << 8) | time.hour;
}
@ -1470,6 +1477,9 @@ uint16_t SL_ReadRegisterMinuteSecond(void *pMsg)
{
timeInfo time;
getRTC_Time(&time);
// debug_printf("%d-%d\n", time.minute, time.second);
return (time.minute << 8) | time.second;
}
@ -1611,6 +1621,10 @@ uint16_t SL_WriteRegisterMinuteSecond(void *pMsg)
tempU8 = (uint8_t)(*(uint16_t*)pMsg);
writeTime.second = tempU8;
// debug_printf("%d-%d\n", writeTime.year, writeTime.month);
// debug_printf("%d-%d\n", writeTime.day, writeTime.hour);
// debug_printf("%d-%d\n", writeTime.minute, writeTime.second);
setRTC_Time(&writeTime);
return 0;

View File

@ -123,17 +123,17 @@ void cfgTest(void)
*/
void readFlashContent(config_info *configInfo)
{
read_config_info(configInfo);
/* 配置文件正确就返回 */
read_config_info(configInfo);
/* 配置文件正确就返回 */
// static volatile uint16_t tempCrc1, tempCrc2;
// tempCrc1 = configInfo->crc;
// tempCrc2 = checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2);
// if (tempCrc1 == tempCrc2) {
// return;
// }
if (configInfo->crc == checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2)) {
return;
}
if (configInfo->crc == checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2)) {
return;
}
// /* 更深处的配置文件正确就返回 */
@ -277,26 +277,25 @@ void config_info_start(void)
g_cfgParameter.reverseChargProtectionCurr = temp_configInfo.reverseChargProtectionCurr;
/* 读取的回路阻抗无效则回路阻抗设置为0 */
float fTemp;
// fTemp = 0.01f;
// saveLoopImpedance(&fTemp);
readLoopImpedance(&fTemp);
// setLoopImpedance(fTemp);
// if (getLoopImpedance() < 0 || getLoopImpedance() > 0.3f) {
if (!setLoopImpedance(fTemp)) {
setLoopImpedance(0.01f);
fTemp = getLoopImpedance();
saveLoopImpedance(&fTemp);
}
float fTemp;
// fTemp = 0.01f;
// saveLoopImpedance(&fTemp);
readLoopImpedance(&fTemp);
// setLoopImpedance(fTemp);
// if (getLoopImpedance() < 0 || getLoopImpedance() > 0.3f) {
if (!setLoopImpedance(fTemp)) {
setLoopImpedance(0);
fTemp = getLoopImpedance();
saveLoopImpedance(&fTemp);
}
readtotalElectricityConsumption(&fTemp);
totalElectricityConsumptionInt(fTemp);
readtotalChargCapacity(&fTemp);
totalChargCapacityInt(fTemp);
timeInfo time;
readTime(&time);
setLastTime(time);
// readtotalElectricityConsumption(&fTemp);
// totalElectricityConsumptionInt(fTemp);
// readtotalChargCapacity(&fTemp);
// totalChargCapacityInt(fTemp);
// timeInfo time;
// readTime(&time);
// setLastTime(time);
}

View File

@ -59,8 +59,8 @@ float getDutyRatio(void)
*/
void setDutyRatio(float DutyRatio)
{
if (DutyRatio > 0.95f) {
dutyRatio = 0.95f;
if (DutyRatio > 0.9f) {
dutyRatio = 0.9f;
}
else if (DutyRatio < 0.05f) {
dutyRatio = 0.05f;

View File

@ -268,14 +268,14 @@ void Task_wdi(void)
// static uint32_t temp = 60 * 30;
if (!(--temp)) {
temp = 0;
float tempF;
tempF = getTotalElectricityConsumption();
savetotalElectricityConsumption(&tempF);
tempF = getTotalChargCapacity();
savetotalChargCapacity(&tempF);
timeInfo time;
time = getLastTime();
saveTime(&time);
// float tempF;
// tempF = getTotalElectricityConsumption();
// savetotalElectricityConsumption(&tempF);
// tempF = getTotalChargCapacity();
// savetotalChargCapacity(&tempF);
// timeInfo time;
// time = getLastTime();
// saveTime(&time);
// NVIC_SystemReset();
resetCheckImpedanceState();
temp = 60 * 60 * 24;
@ -307,7 +307,7 @@ void Task_refreshJudgeData(void)
/* 有电池太阳能输出功率大电池电压低于14V同时回路阻抗未测试或需要重新测试 */
if ((getCheckImpedanceState() == FALSE || getLoopImpedance() == 0.0f)
&& (getBatteryState() == TRUE) && (getChargCurrent() > g_cfgParameter.maxChargCurr)
&& (getBatteryState() == TRUE) && (getChargCurrent() > g_cfgParameter.minCheckLoopImpedanceChargCurr)
&& (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14)
&& (getBatteryVoltage() < 14)) {
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
@ -378,7 +378,15 @@ void Task_startControl(void)
}
/* 启动软起动任务 */
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
// TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
if (getBatteryState() == TRUE) {
setMPPT_Mode(MPPT);
} else {
setMPPT_Mode(floatCharg);
}
setChargControlFlag(TRUE);
EN_PWMOUT_Eable();
}
}
/**
@ -409,7 +417,7 @@ void Task_softStart(void)
EN_PWMOUT_Eable();
}
else if (num > 70 || dutyRatio > 0.75f) {
else if (num > 70 || dutyRatio > 0.6f) {
TimeSliceOffset_Unregister(&m_softStart);
m_softStart.runFlag = 0;

View File

@ -182,25 +182,26 @@ BOOL readOnlyPowerOutputState(void)
{
// static volatile GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
// GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
GPIO_PinState gpioTemp1, gpioTemp2;
// GPIO_PinState gpioTemp1, gpioTemp2;
gpioTemp1 = HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
gpioTemp2 = HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin);
// gpioTemp1 = HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
// gpioTemp2 = HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin);
// gpioTemp3 = HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin);
if (gpioTemp1 == GPIO_PIN_SET
&& gpioTemp2 == GPIO_PIN_SET
// && gpioTemp3 == GPIO_PIN_SET) {
) {
return TRUE;
}
// if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
// && HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
// && HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
// return TRUE;
// if (gpioTemp1 == GPIO_PIN_SET
// && gpioTemp2 == GPIO_PIN_SET
// // && gpioTemp3 == GPIO_PIN_SET) {
// ) {
// return TRUE;
// }
if (!HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
&& HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
&& !HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)
&& !HAL_GPIO_ReadPin(EXCHG_CURR_GPIO_Port, EXCHG_CURR_Pin)) {
return TRUE;
}
return FALSE;
}

View File

@ -104,6 +104,7 @@ void MX_GPIO_Init(void)
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
/* USER CODE BEGIN 2 */

View File

@ -47,7 +47,7 @@ void MX_TIM3_Init(void)
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 720;
htim3.Init.Period = 719;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)

View File

@ -413,7 +413,7 @@ TIM16.PeriodNoDither=999
TIM16.Prescaler=71
TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM3.IPParameters=PeriodNoDither,Channel-PWM Generation4 CH4
TIM3.PeriodNoDither=720
TIM3.PeriodNoDither=719
TIM6.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger
TIM6.PeriodNoDither=9
TIM6.Prescaler=71