diff --git a/APP/application/Src/start.c b/APP/application/Src/start.c index 2d73a71..ec22c9b 100644 --- a/APP/application/Src/start.c +++ b/APP/application/Src/start.c @@ -59,7 +59,7 @@ void start(void) startInfo(); - HAL_Delay(5000); +// HAL_Delay(5000); TimeSliceOffset_Start(); } diff --git a/APP/businessLogic/Inc/abnormalManage.h b/APP/businessLogic/Inc/abnormalManage.h index d9af49a..a8593e6 100644 --- a/APP/businessLogic/Inc/abnormalManage.h +++ b/APP/businessLogic/Inc/abnormalManage.h @@ -20,6 +20,8 @@ uint8_t getExcessiveLoad(void); void setExcessiveLoadFlag(BOOL state); BOOL getExcessiveLoadFlag(void); +void setSoftShortCircuit(uint16_t disChargCurrAdcNum); + void setPowerOutput(BOOL state); void checkAbnormal(void); diff --git a/APP/businessLogic/Inc/inFlash.h b/APP/businessLogic/Inc/inFlash.h index 3ef8401..87eacd0 100644 --- a/APP/businessLogic/Inc/inFlash.h +++ b/APP/businessLogic/Inc/inFlash.h @@ -111,4 +111,12 @@ void readtotalChargCapacity(float *totalChargCapacity); void saveTime(timeInfo *time); void readTime(timeInfo *time); + +#define eventsOrderRecordStartAddr 200 +void setEventsOrderRecord(eventsOrderRecordMode mode); +void printfEventsOrderRecord(void); + + + + #endif diff --git a/APP/businessLogic/Src/abnormalManage.c b/APP/businessLogic/Src/abnormalManage.c index 2b97327..57e3bb5 100644 --- a/APP/businessLogic/Src/abnormalManage.c +++ b/APP/businessLogic/Src/abnormalManage.c @@ -5,8 +5,10 @@ #include "checkTime.h" #include "FM_GPIO.h" #include "task.h" +#include "configParameter.h" +#include "capture.h" - +static int checkMode = 0; /* 软件输出过载标志位 */ static BOOL disChargOverLoad = FALSE; @@ -18,7 +20,7 @@ static BOOL shortCircuitFlag = FALSE; /* 硬件过载状态位 */ static uint8_t excessiveLoad = 0; static BOOL excessiveLoadFlag = FALSE; - +static BOOL excessiveLoadInterruptFlag = FALSE; /** * @brief 设定放电过载状态 @@ -28,9 +30,9 @@ static BOOL excessiveLoadFlag = FALSE; */ void setDisChargOverLoad(void) { - /* 三段式保护中的两段 */ + /* 三段式保护中的第三段 */ static int num1 = 0; - if (getDischargCurrent() > 30.0f) { + if (getDischargCurrent() > thirdStageProtectionCurr) { // disChargOverLoad = TRUE; num1++; } else { @@ -38,22 +40,24 @@ void setDisChargOverLoad(void) num1 = 0; } - /* 过载时间过长关闭输出(120S) */ - if (num1 >= 1200000) { + /* 过载时间过长关闭输出 */ + if (num1 >= thirdStageProtectionDelay) { num1 = 0; disChargOverLoad = TRUE; setPowerOutput(FALSE); } + + /* 三段式保护中的第二段 */ static int num2 = 0; - if (getDischargCurrent() > 35.0f) { + if (getDischargCurrent() > secondStageProtectionCurr) { num2++; } else { num2 = 0; } - /* 过载时间过长关闭输出(5S) */ - if (num1 >= 50000) { + /* 过载时间过长关闭输出 */ + if (num1 >= secondStageProtectionDelay) { num1 = 0; disChargOverLoad = TRUE; setPowerOutput(FALSE); @@ -66,17 +70,26 @@ void setDisChargOverLoad(void) * @retval * */ -void setSoftShortCircuit(void) +void setSoftShortCircuit(uint16_t disChargCurrAdcNum) { + // /* 三段式保护中的第一段 */ + // static int num = 0; + // if (getDischargCurrent() > firstStageProtectionCurr) { + // num++; + // } else { + // num = 0; + // } + + /* 三段式保护中的第一段 */ static int num = 0; - if (getDischargCurrent() > 50.0f) { + if (disChargCurrAdcNum > firstStageProtectionCurr) { num++; } else { num = 0; } /* 200uS内都短路则关闭输出 */ - if (num >= 2) { + if (num >= firstStageProtectionDelay) { shortCircuitFlag = TRUE; shortCircuit++; setPowerOutput(FALSE); @@ -223,7 +236,7 @@ BOOL getExcessiveLoadFlag(void) if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) { POW_FF_PCON_Open(); POW_OUT_PCON_Open(); - } + } } else { POW_FF_PCON_Close(); POW_OUT_PCON_Close(); @@ -269,6 +282,50 @@ void checkFFMOS_CON(void) // } +/** + * @brief 输入功率过低保护 + * @param + * @retval + * + */ +void setOverLoad(void) +{ + setPowerOutput(FALSE); + setExcessiveLoad(); + /* 第一次进入输出过载,启动过载保护任务 */ + if (getExcessiveLoad() == 1) { + setExcessiveLoadFlag(TRUE); + startExcessiveLoadProtection(); + } + + /* 多次进入输出过载,关闭输出 */ + if (getExcessiveLoad() > 2) { + zeroExcessiveLoad(); + } +} + +/** + * @brief 判断是否输入功率过低 + * @param + * @retval + * + */ +void lowInputLoadDetection(void) +{ + static int num = 0; + + if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < lowInputLoadDetectionVolt) { + num++; + } else { + num = 0; + excessiveLoadInterruptFlag = FALSE; + } + + if (excessiveLoadInterruptFlag == TRUE && num == lowInputLoadDetectionDelay) { + setOverLoad(); + } +} + void checkAbnormal(void) { @@ -285,8 +342,8 @@ void checkAbnormal(void) /* 判断 */ checkFFMOS_CON(); setDisChargOverLoad(); - setSoftShortCircuit(); - + // setSoftShortCircuit(); + lowInputLoadDetection(); @@ -302,18 +359,19 @@ void checkAbnormal(void) */ void WORK_VOLT_Interrupt(void) { - setPowerOutput(FALSE); - setExcessiveLoad(); - /* 第一次进入输出过载,启动过载保护任务 */ - if (getExcessiveLoad() == 1) { - setExcessiveLoadFlag(TRUE); - startExcessiveLoadProtection(); - } + // setPowerOutput(FALSE); + // setExcessiveLoad(); + // /* 第一次进入输出过载,启动过载保护任务 */ + // if (getExcessiveLoad() == 1) { + // setExcessiveLoadFlag(TRUE); + // startExcessiveLoadProtection(); + // } - /* 多次进入输出过载,关闭输出 */ - if (getExcessiveLoad() > 2) { - zeroExcessiveLoad(); - } + // /* 多次进入输出过载,关闭输出 */ + // if (getExcessiveLoad() > 2) { + // zeroExcessiveLoad(); + // } + excessiveLoadInterruptFlag = TRUE; } /** diff --git a/APP/businessLogic/Src/bl_chargControl.c b/APP/businessLogic/Src/bl_chargControl.c index 0d687d1..7ac4995 100644 --- a/APP/businessLogic/Src/bl_chargControl.c +++ b/APP/businessLogic/Src/bl_chargControl.c @@ -38,7 +38,7 @@ void mppt_constantVoltage(float InVoltage) static float ki = 0.00001; // static float solarInCircuitVoltage; static float error; - static float stepPwm; + static float stepPwm; // solarInCircuitVoltage = getSolarInCircuitVoltage(); // error = InVoltage - getSolarInCircuitVoltage(); @@ -557,6 +557,10 @@ void chargControlMode(void) endChargWork(); } + else if (getBatteryState() == FALSE) { + setMPPT_Mode(noBattery); + } + else if (floatChargConditions()) { setMPPT_Mode(floatCharg); } @@ -567,7 +571,7 @@ void chargControlMode(void) else if (mpptChargConditions()) { setMPPT_Mode(MPPT); - } + } } /** diff --git a/APP/businessLogic/Src/inFlash.c b/APP/businessLogic/Src/inFlash.c index 501d159..9a92608 100644 --- a/APP/businessLogic/Src/inFlash.c +++ b/APP/businessLogic/Src/inFlash.c @@ -289,4 +289,57 @@ void saveTime(timeInfo *time) void readTime(timeInfo *time) { read_Flash((uint8_t *)time, time_SAVE_addr, sizeof(timeInfo)); -} \ No newline at end of file +} + + +/** + * @brief 将事件顺序记录在flash中 + * @param + */ +void setEventsOrderRecord(eventsOrderRecordMode mode) +{ + static uint32_t len = sizeof(int); + float temp; + write_Flash((uint8_t *)&mode, eventsOrderRecordStartAddr + len, sizeof(mode)); + len += sizeof(mode); + temp = getDischargCurrent(); + write_Flash((uint8_t *)&temp, eventsOrderRecordStartAddr + len, sizeof(float)); + len += sizeof(float); + temp = getOutputVoltage(); + write_Flash((uint8_t *)&temp, eventsOrderRecordStartAddr + len, sizeof(float)); + + int count = 0; + read_Flash((uint8_t *)&count, eventsOrderRecordStartAddr, sizeof(count)); + count++; + write_Flash((uint8_t *)&count, eventsOrderRecordStartAddr, sizeof(count)); +} + +/** + * @brief 将事件从flash中依次读取出来 + * @param + */ + +void printfEventsOrderRecord(void) +{ + int count = 0; + read_Flash((uint8_t *)&count, eventsOrderRecordStartAddr, sizeof(count)); + + float temp; + eventsOrderRecordMode mode; + + for (int i = 0; i < count; i++) { + read_Flash((uint8_t *)&temp, eventsOrderRecordStartAddr + sizeof(int) + + i * (sizeof(float) + sizeof(float)), sizeof(mode)); + log_info("eventsOrderRecordMode:%d\n", mode); + + read_Flash((uint8_t *)&temp, eventsOrderRecordStartAddr + sizeof(int) + + i * (sizeof(float) + sizeof(float)) + sizeof(mode), sizeof(float)); + log_info("dischargCurrent:%f\n", temp); + + read_Flash((uint8_t *)&temp, eventsOrderRecordStartAddr + sizeof(int) + + i * (sizeof(float) + sizeof(float)) + sizeof(mode) + sizeof(float), sizeof(float)); + log_info("OutputVoltage:%f\n", temp); + } +} + + diff --git a/APP/businessLogic/Src/parameter.c b/APP/businessLogic/Src/parameter.c index 13f03ee..20cda5a 100644 --- a/APP/businessLogic/Src/parameter.c +++ b/APP/businessLogic/Src/parameter.c @@ -3,6 +3,7 @@ #include "FM_TIM.h" #include "FM_GPIO.h" #include "capture.h" +#include "bl_chargControl.h" config_parameter g_cfgParameter = {0}; static otherParameter g_otherParameter = {0}; diff --git a/APP/businessLogic/Src/task.c b/APP/businessLogic/Src/task.c index 7c55abf..87fb90e 100644 --- a/APP/businessLogic/Src/task.c +++ b/APP/businessLogic/Src/task.c @@ -10,6 +10,7 @@ #include "uart_dev.h" #include "abnormalManage.h" #include "interruptSend.h" +#include "configParameter.h" #include @@ -273,7 +274,7 @@ void Task_refreshJudgeData(void) /* 有电池,太阳能输出功率大,电池电压低于14V,同时回路阻抗未测试或需要重新测试 */ if ((getCheckImpedanceState() == FALSE || g_cfgParameter.loopImpedance == 0.0f) - && (getBatteryState() == TRUE) && (getChargCurrent() > 3.0f) + && (getBatteryState() == TRUE) && (getChargCurrent() > checkLoopImpedanceChargCurr) && (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14) && (getBatteryVoltage() < 14)) { TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation @@ -477,7 +478,7 @@ void Task_collectOpenCircuitVoltage(void) if (getBatteryState()) { collectOpenCircuitVoltageYesFlag = TRUE; stopChargWork(); - /* 设置延时为1000-500ms */ + /* 设置延时为(1000-500)ms */ m_collectOpenCircuitVoltage.count = 500; } collectOpenCircuitVoltageYesNUM = 0; @@ -485,9 +486,12 @@ void Task_collectOpenCircuitVoltage(void) /* 检测开路电压 */ if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) { - setSolarOpenCircuitVoltage(); - beginChargWork(); - collectOpenCircuitVoltageYesFlag = FALSE; + /* 有电池才进行开路电压检测 */ + if (getBatteryState()) { + setSolarOpenCircuitVoltage(); + beginChargWork(); + collectOpenCircuitVoltageYesFlag = FALSE; + } } } diff --git a/APP/functionalModule/Inc/capture.h b/APP/functionalModule/Inc/capture.h index e86e824..c965103 100644 --- a/APP/functionalModule/Inc/capture.h +++ b/APP/functionalModule/Inc/capture.h @@ -34,4 +34,6 @@ float get_OUT_VOLT_IN(void); void adcCaptureFir(); +extern void setSoftShortCircuit(uint16_t disChargCurrAdcNum); + #endif \ No newline at end of file diff --git a/APP/functionalModule/Src/capture.c b/APP/functionalModule/Src/capture.c index 95309c2..4cf3010 100644 --- a/APP/functionalModule/Src/capture.c +++ b/APP/functionalModule/Src/capture.c @@ -475,6 +475,8 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma) DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size; PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size; CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size; + + setSoftShortCircuit(DSG_CURR_capture.inData16[pointer - 1]); } } diff --git a/tools/chargControlTypes.h b/tools/chargControlTypes.h index fd24bb5..26d9ed0 100644 --- a/tools/chargControlTypes.h +++ b/tools/chargControlTypes.h @@ -8,7 +8,8 @@ typedef enum _chargMode{ noWork = 0, /* 未进行充电 */ MPPT = 1, /* 最大功率充电 */ constantVoltage = 2, /* 恒压充电 */ - floatCharg = 3 /* 浮充充电 */ + floatCharg = 3, /* 浮充充电 */ + noBattery = 4, /* 无电池 */ }chargMode; typedef enum { @@ -50,8 +51,20 @@ typedef struct _timeInfo { /* 方式 */ typedef enum { - runLedChargMode = 1, - runLedOtherMode = 2, + runLedChargMode = 1, //充电模式 + runLedOtherMode = 2, //其他模式 }runLedMode; + +/* 顺序事件记录 */ +typedef enum { + firstStageProtection = 1, //第一段保护,短路保护 + secondStageProtection = 2, //第二段保护,介于过载和短路之间 + thirdStageProtection = 3, //第三段保护,过载保护 + excessiveLoadIn = 4, //进入了电压降低中断 + lowInputLoad = 5, //输入功率不足保护 +}eventsOrderRecordMode; + + + #endif diff --git a/tools/configParameter.h b/tools/configParameter.h new file mode 100644 index 0000000..6a60985 --- /dev/null +++ b/tools/configParameter.h @@ -0,0 +1,56 @@ +#ifndef CONFIG_PARAMETER_ +#define CONFIG_PARAMETER_ + +#include "comm_types.h" + + + +// /* 第一段保护的延时时间(单位100uS) */ +// const uint32_t firstStageProtectionDelay = 2; // 200uS +// /* 第一段保护的电流(单位A) */ +// const float_t firstStageProtectionCurr = 50.0f; + +// /* 第二段保护的延时时间(单位100uS) */ +// const uint32_t secondStageProtectionDelay = 50000; // 5S +// /* 第二段保护的电流(单位A) */ +// const float_t secondStageProtectionCurr = 30.0f; + +// /* 第三段保护的延时时间(单位100uS) */ +// const uint32_t thirdStageProtectionDelay = 1200000; // 120S +// /* 第三段保护的电流(单位A) */ +// const uint32_t thirdStageProtectionCurr = 35.0f; + +// /* 检测回路阻抗时的充电电流要大于该值(单位A) */ +// const float_t checkLoopImpedanceChargCurr = 10.0f; + + +// /* 第三段保护的延时时间(单位100uS) */ +// const uint32_t lowInputLoadDetectionDelay = 30; // 120S + + +/* 第一段保护的延时时间(单位100uS) */ +#define firstStageProtectionDelay 2 // 200uS +/* 第一段保护的电流(单位A) */ +#define firstStageProtectionCurr 50.0f + +/* 第二段保护的延时时间(单位100uS) */ +#define secondStageProtectionDelay 50000 // 5S +/* 第二段保护的电流(单位A) */ +#define secondStageProtectionCurr 30.0f + +/* 第三段保护的延时时间(单位100uS) */ +#define thirdStageProtectionDelay 1200000 // 120S +/* 第三段保护的电流(单位A) */ +#define thirdStageProtectionCurr 35.0f + +/* 检测回路阻抗时的充电电流要大于该值(单位A) */ +#define checkLoopImpedanceChargCurr 10.0f + +/* 输入功率较低延时(单位100uS) */ +#define lowInputLoadDetectionDelay 30 // 120S +/* 输入功率较低延时电流(单位A) */ +#define lowInputLoadDetectionVolt 10.0f + + + +#endif