diff --git a/.vscode/settings.json b/.vscode/settings.json index 3cc0298..aec3e6b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,6 +41,7 @@ "w25qxx.h": "c", "w25q256.h": "c", "gpio.h": "c", - "bl_usart.h": "c" + "bl_usart.h": "c", + "soc.h": "c" } } \ No newline at end of file diff --git a/APP/application/Src/start.c b/APP/application/Src/start.c index f5a8d33..209558a 100644 --- a/APP/application/Src/start.c +++ b/APP/application/Src/start.c @@ -63,7 +63,8 @@ void start(void) uartCommonInit(); -// setDutyRatio(0.15f); + // setDutyRatio(0.0001f); + // EN_PWMOUT_Eable(); task_Init(); diff --git a/APP/businessLogic/Inc/soc.h b/APP/businessLogic/Inc/soc.h new file mode 100644 index 0000000..e2edb41 --- /dev/null +++ b/APP/businessLogic/Inc/soc.h @@ -0,0 +1,8 @@ +#ifndef BL_SOC_H_ +#define BL_SOC_H_ + + +int find_soc(float voltage); + + +#endif \ No newline at end of file diff --git a/APP/businessLogic/Inc/task.h b/APP/businessLogic/Inc/task.h index 5bb6ca0..bbd4f11 100644 --- a/APP/businessLogic/Inc/task.h +++ b/APP/businessLogic/Inc/task.h @@ -17,6 +17,7 @@ void startShortCircuitProtection(void); void stopShortCircuitProtection(void); void startExcessiveLoadProtection(void); void startSoftShortCircuitProtection(void); +void startEXCHGSCProtection(void); void chargRunLed(uint8_t mode); diff --git a/APP/businessLogic/Src/Init.c b/APP/businessLogic/Src/Init.c index 31f6f09..d1fa58e 100644 --- a/APP/businessLogic/Src/Init.c +++ b/APP/businessLogic/Src/Init.c @@ -49,6 +49,15 @@ void Init(void) // POW_OUT_PCON_Open(); HAL_Delay(100); setPowerOutput(TRUE); + + // /* 判断有无电池 */ + // if (getOutputVoltage() > 11.0f) { + // setBatteryState(TRUE); + // setPowerOutput(TRUE); + // } else { + // setBatteryState(FALSE); + // } + resetCheckImpedanceState(); // setDutyRatio(0.5); diff --git a/APP/businessLogic/Src/SOE.c b/APP/businessLogic/Src/SOE.c index a780c01..ce5292b 100644 --- a/APP/businessLogic/Src/SOE.c +++ b/APP/businessLogic/Src/SOE.c @@ -85,6 +85,7 @@ void eventsOrderRecordStartInit(void) | stopTemperature | mos管温度 | | overchargCurr | 充电电流 | | hardwareShortCircuitProtection| 输出电流 | +| abnormalControl | 太阳能板输出电压 | */ void insertEventsOrderRecord(eventsOrderRecordMode mode) { @@ -145,6 +146,10 @@ void insertEventsOrderRecord(eventsOrderRecordMode mode) soeInfo.insertData->temp = 0; } + else if (mode == abnormalControl) { + soeInfo.insertData->temp = getSolarInCircuitVoltage(); + } + else { soeInfo.count++; return; diff --git a/APP/businessLogic/Src/abnormalManage.c b/APP/businessLogic/Src/abnormalManage.c index e21c9d0..637d621 100644 --- a/APP/businessLogic/Src/abnormalManage.c +++ b/APP/businessLogic/Src/abnormalManage.c @@ -356,8 +356,8 @@ void setOverLoad(void) startExcessiveLoadProtection(); } - /* 多次进入输出过载,关闭输出 */ - if (getExcessiveLoad() > 2) { + /* 多次进入输出过载,关闭输出 */ + if (getExcessiveLoad() >= 2) { zeroExcessiveLoad(); insertEventsOrderRecord(lowInputLoad); } @@ -373,7 +373,9 @@ void lowInputLoadDetection(void) { static int num = 0; - if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt) { + if (excessiveLoadInterruptFlag == TRUE + && getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt + && getDischargCurrent() < g_cfgParameter.thirdStageProtectionCurr) { num++; // setOverLoad(); } else { @@ -382,6 +384,7 @@ void lowInputLoadDetection(void) } if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.inputPowerLowDetectionDelay) { + num = 0; excessiveLoadInterruptFlag = FALSE; setOverLoad(); } @@ -466,16 +469,16 @@ void WORK_VOLT_Interrupt(void) void DSG_PROT_Interrupt(void) { setShortCircuit(); + setPowerOutput(FALSE); /* 第一次进入输出短路,启动短路任务 */ if (getShortCircuit() == 1) { - setShortCircuitFlag(TRUE); startShortCircuitProtection(); } /* 一定时间内第二次进入输出短路保护,关闭输出 */ else if (getShortCircuit() >= 2) { stopShortCircuitProtection(); - setPowerOutput(FALSE); + // setPowerOutput(FALSE); zeroShortCircuit(); insertEventsOrderRecord(hardwareShortCircuitProtection); } @@ -489,8 +492,18 @@ void DSG_PROT_Interrupt(void) */ void EXCHG_PROT_Interrupt(void) -{ +{ + setShortCircuit(); setPowerOutput(FALSE); - insertEventsOrderRecord(hardwareInputProtection); + /* 第一次进入输出短路,启动短路任务 */ + if (getShortCircuit() == 1) { + startEXCHGSCProtection(); + } + + /* 一定时间内第二次进入输出短路保护,关闭输出 */ + else if (getShortCircuit() >= 2) { + stopShortCircuitProtection(); + insertEventsOrderRecord(hardwareInputProtection); + } } diff --git a/APP/businessLogic/Src/bl_chargControl.c b/APP/businessLogic/Src/bl_chargControl.c index 5165cac..c9a4729 100644 --- a/APP/businessLogic/Src/bl_chargControl.c +++ b/APP/businessLogic/Src/bl_chargControl.c @@ -4,6 +4,7 @@ #include "comm_types.h" #include "FM_GPIO.h" #include "task.h" +#include "SOE.h" static BOOL stopChargConditions(void); @@ -410,8 +411,9 @@ void mppt_readJust(void) /* 一段时间内电流都很小则固定电压输出 */ static uint8_t currMinFlag = 0; static uint8_t currMinFlag1 = 0; + // if (getChargCurrent() < 0.8f) { - if (totalChargeCurr < 40) { + if (totalChargeCurr < 120) { // hysteresisValue1 = getChargCurrent() * 1.7f; // hysteresisValue2 = getChargCurrent() * 12; currMinFlag++; @@ -437,8 +439,8 @@ void mppt_readJust(void) currMinFlag = 0; // hysteresisValue1 = getChargCurrent() * 1.1f; // hysteresisValue2 = getChargCurrent() * 10; - hysteresisValue1 = totalChargeCurr / 45.0f; - hysteresisValue2 = totalChargeCurr / 5.0f; + hysteresisValue1 = totalChargeCurr / 40.0f; + hysteresisValue2 = totalChargeCurr / 4.0f; } // else if (getChargCurrent() < 20) { @@ -447,8 +449,8 @@ void mppt_readJust(void) currMinFlag = 0; // hysteresisValue1 = getChargCurrent() * 0.7f; // hysteresisValue2 = getChargCurrent() * 7; - hysteresisValue1 = totalChargeCurr / 70.0f; - hysteresisValue2 = totalChargeCurr / 7.0f; + hysteresisValue1 = totalChargeCurr / 60.0f; + hysteresisValue2 = totalChargeCurr / 6.0f; } // else if (getChargCurrent() < 25) { @@ -457,8 +459,8 @@ void mppt_readJust(void) currMinFlag = 0; // hysteresisValue1 = getChargCurrent() * 0.5f; // hysteresisValue2 = getChargCurrent() * 5; - hysteresisValue1 = totalChargeCurr / 100.0f; - hysteresisValue2 = totalChargeCurr / 10.0f; + hysteresisValue1 = totalChargeCurr / 90.0f; + hysteresisValue2 = totalChargeCurr / 9.0f; } else { @@ -466,8 +468,8 @@ void mppt_readJust(void) currMinFlag = 0; // hysteresisValue1 = getChargCurrent() * 0.3f; // hysteresisValue2 = getChargCurrent() * 3; - hysteresisValue1 = totalChargeCurr / 150.0f; - hysteresisValue2 = totalChargeCurr / 16.0f; + hysteresisValue1 = totalChargeCurr / 140.0f; + hysteresisValue2 = totalChargeCurr / 14.0f; } // else { @@ -505,6 +507,7 @@ void mppt_readJust(void) // } else if ((lPower - 0.8f > Power) && (lLPower - 0.8f > Power) && (lLLPower - 0.8f > Power)) { } else if ((lPower - hysteresisValue1 > Power) && (lLPower - hysteresisValue1 > Power)) { // } else if ((lPower - 0.3f > Power)) { + numFlag = 0; if (powerT > hysteresisValue2) { numFlag = 0; if (flag1) { @@ -567,7 +570,7 @@ void endChargWork(void) setChargControlFlag(FALSE); setDutyRatioToZero(); setMPPT_Mode(noWork); - beginStartControlTask(); + beginStartControlTask(); EN_PWMOUT_Diseable(); } @@ -625,6 +628,33 @@ BOOL stopChargConditions(void) return TRUE; } + /* 异常情况关闭充电 */ + static uint16_t flag = 0; + if ((getSolarInCircuitVoltage() < (g_cfgParameter.stopSolarOutputCircuitV + 1) + || 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++; + // } + // else { + // flag = 0; + // } + + if (flag > 20000) { + flag = 0; + insertEventsOrderRecord(abnormalControl); + return TRUE; + } + return FALSE; } diff --git a/APP/businessLogic/Src/bl_comm.c b/APP/businessLogic/Src/bl_comm.c index 9e2d6e4..3102473 100644 --- a/APP/businessLogic/Src/bl_comm.c +++ b/APP/businessLogic/Src/bl_comm.c @@ -2,6 +2,7 @@ #include "bl_comm.h" #include "uart_dev.h" #include "interruptSend.h" +#include "SOE.h" uint8_t rs485_buff[buffLen]={0x00}; diff --git a/APP/businessLogic/Src/parameter.c b/APP/businessLogic/Src/parameter.c index 1109042..4bfaca5 100644 --- a/APP/businessLogic/Src/parameter.c +++ b/APP/businessLogic/Src/parameter.c @@ -5,6 +5,7 @@ #include "capture.h" #include "bl_chargControl.h" #include +#include "soc.h" config_parameter g_cfgParameter = {0}; static otherParameter g_otherParameter = {0}; @@ -79,9 +80,9 @@ void setDutyRatio(float DutyRatio) */ void setDutyRatioToZero(void) { - EN_PWMOUT_Diseable(); dutyRatio = 0; set_pwmDutyRatio(dutyRatio); + EN_PWMOUT_Diseable(); } /** @@ -380,7 +381,7 @@ void setTotalChargCapacity(void) * @retval */ void totalChargCapacityInt(float totalPower) -{ +{ g_otherParameter.totalChargCapacity = totalPower; } @@ -401,7 +402,7 @@ float getSOC(void) */ void setSOC(void) { - + g_otherParameter.SOC = find_soc(getBatteryVoltage()) / 100.0f; } /** diff --git a/APP/businessLogic/Src/soc.c b/APP/businessLogic/Src/soc.c new file mode 100644 index 0000000..22c1307 --- /dev/null +++ b/APP/businessLogic/Src/soc.c @@ -0,0 +1,119 @@ + +#include "soc.h" + +// const float ocv_table[101] = { +// 2.80, 2.85, 2.90, 2.95, 3.00, 3.05, 3.10, 3.12, 3.14, 3.16, // 0-9% +// 3.18, 3.19, 3.20, 3.20, 3.20, 3.20, 3.21, 3.21, 3.21, 3.21, // 10-19% +// 3.22, 3.22, 3.22, 3.22, 3.22, 3.22, 3.23, 3.23, 3.23, 3.23, // 20-29% +// 3.23, 3.23, 3.23, 3.23, 3.23, 3.23, 3.23, 3.24, 3.24, 3.24, // 30-39% +// 3.24, 3.24, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, // 40-49% +// 3.25, 3.25, 3.25, 3.25, 3.25, 3.26, 3.26, 3.26, 3.26, 3.26, // 50-59% +// 3.26, 3.26, 3.26, 3.26, 3.26, 3.26, 3.27, 3.27, 3.27, 3.27, // 60-69% +// 3.28, 3.28, 3.28, 3.29, 3.29, 3.29, 3.30, 3.30, 3.31, 3.31, // 70-79% +// 3.32, 3.32, 3.33, 3.34, 3.35, 3.36, 3.38, 3.40, 3.42, 3.45, // 80-89% +// 3.48, 3.50, 3.52, 3.54, 3.56, 3.58, 3.60, 3.62, 3.63, 3.64, // 90-99% +// 3.65 // 100% +// }; + +// /** +// * 四节串联磷酸铁锂电池组 SOC-OCV 对应表 (SOC步长1%) +// * 电压范围:11.2V (0%) ~ 14.6V (100%) +// * 注意: +// * 1. 假设电池完全均衡,实际需考虑单体差异 +// * 2. 电压单位:伏特(V) +// */ +// const float ocv_table_4s[101] = { +// // 0-9% (单节2.80V~3.16V → 四节11.20V~12.64V) +// 11.20, 11.40, 11.60, 11.80, 12.00, 12.20, 12.40, 12.48, 12.56, 12.64, // 0-9% + +// // 10-19% (单节3.18V~3.21V → 四节12.72V~12.84V) +// 12.72, 12.76, 12.80, 12.80, 12.80, 12.80, 12.84, 12.84, 12.84, 12.84, // 10-19% + +// // 20-29% (单节3.22V~3.23V → 四节12.88V~12.92V) +// 12.88, 12.88, 12.88, 12.88, 12.88, 12.88, 12.92, 12.92, 12.92, 12.92, // 20-29% + +// // 30-39% (单节3.23V~3.24V → 四节12.92V~12.96V) +// 12.92, 12.92, 12.92, 12.92, 12.92, 12.92, 12.92, 12.96, 12.96, 12.96, // 30-39% + +// // 40-49% (单节3.24V~3.25V → 四节12.96V~13.00V) +// 12.96, 12.96, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, // 40-49% + +// // 50-59% (单节3.25V~3.26V → 四节13.00V~13.04V) +// 13.00, 13.00, 13.00, 13.00, 13.00, 13.04, 13.04, 13.04, 13.04, 13.04, // 50-59% + +// // 60-69% (单节3.26V~3.27V → 四节13.04V~13.08V) +// 13.04, 13.04, 13.04, 13.04, 13.04, 13.04, 13.08, 13.08, 13.08, 13.08, // 60-69% + +// // 70-79% (单节3.28V~3.31V → 四节13.12V~13.24V) +// 13.12, 13.12, 13.12, 13.16, 13.16, 13.16, 13.20, 13.20, 13.24, 13.24, // 70-79% + +// // 80-89% (单节3.32V~3.45V → 四节13.28V~13.80V) +// 13.28, 13.28, 13.32, 13.36, 13.40, 13.44, 13.52, 13.60, 13.68, 13.80, // 80-89% + +// // 90-100% (单节3.48V~3.65V → 四节13.92V~14.60V) +// 13.92, 14.00, 14.08, 14.16, 14.24, 14.32, 14.40, 14.48, 14.52, 14.56, // 90-99% +// 14.60 // 100% +// }; + + +/** + * 四节串联磷酸铁锂电池组 SOC-OCV 对应表 (SOC步长1%) + * 电压范围:11.2V (0%) ~ 14.6V (100%) + * 注意: + * 1. 假设电池完全均衡,实际需考虑单体差异 + * 2. 电压单位:伏特(V) + */ +const float ocv_table_4s[21] = { + // 0-9% (单节2.80V~3.16V → 四节11.20V~12.64V) + 12.00, 12.64, // 0-9% + + // 10-19% (单节3.18V~3.21V → 四节12.72V~12.84V) + 12.80, 12.84, // 10-19% + + // 20-29% (单节3.22V~3.23V → 四节12.88V~12.92V) + 12.88, 12.92, // 20-29% + + // 30-39% (单节3.23V~3.24V → 四节12.92V~12.96V) + 12.93, 12.96, // 30-39% + + // 40-49% (单节3.24V~3.25V → 四节12.96V~13.00V) + 12.98, 13.00, // 40-49% + + // 50-59% (单节3.25V~3.26V → 四节13.00V~13.04V) + 13.02, 13.04, // 50-59% + + // 60-69% (单节3.26V~3.27V → 四节13.04V~13.08V) + 13.05, 13.08, // 60-69% + + // 70-79% (单节3.28V~3.31V → 四节13.12V~13.24V) + 13.16, 13.24, // 70-79% + + // 80-89% (单节3.32V~3.45V → 四节13.28V~13.80V) + 13.40, 13.80, // 80-89% + + // 90-100% (单节3.48V~3.65V → 四节13.92V~14.60V) + 13.92, 14.24, // 90-99% + 14.60 // 100% +}; + + +/** + * @brief 得到通过电压得到当前SOC在数组中的位置 + * @param + * @retval soc*100 + */ +int find_soc(float voltage) +{ + // static volatile int soc = 0; + // for(soc = 0; soc <= 100; soc++) { + for(int soc = 0; soc <= 100; soc++) { + if(ocv_table_4s[soc] >= voltage) { + return soc * 5; + } + } + return 100; +} + + + + diff --git a/APP/businessLogic/Src/task.c b/APP/businessLogic/Src/task.c index 8f9a20e..f626c0a 100644 --- a/APP/businessLogic/Src/task.c +++ b/APP/businessLogic/Src/task.c @@ -15,7 +15,6 @@ #include "bl_usart.h" #include "SOE.h" - #include @@ -47,13 +46,13 @@ static STR_TimeSliceOffset m_startControl; static void Task_startControl(void); /* 软启动 */ -#define softStart_reloadVal 1 /* 任务执行间隔 */ +#define softStart_reloadVal 10 /* 任务执行间隔 */ #define softStart_offset 0 /* 任务执行偏移量 */ static STR_TimeSliceOffset m_softStart; static void Task_softStart(void); /* 回路阻抗检测 */ -#define impedanceCalculation_reloadVal 20 /* 任务执行间隔 */ +#define impedanceCalculation_reloadVal 100 /* 任务执行间隔 */ #define impedanceCalculation_offset 0 /* 任务执行偏移量 */ static STR_TimeSliceOffset m_impedanceCalculation; static void Task_impedanceCalculation(void); @@ -96,6 +95,12 @@ void Task_collectOpenCircuitVoltage(void); static STR_TimeSliceOffset m_shortCircuitProtection; static void Task_shortCircuitProtection(void); +/* 反向充电短路保护 */ +#define EXCHGSCProtection_reloadVal 1000 /* 任务执行间隔 */ +#define EXCHGSCProtection_offset 0 /* 任务执行偏移量 */ +static STR_TimeSliceOffset m_EXCHGSCProtection; +static void Task_EXCHGSCProtection(void); + /* 过载保护 */ #define excessiveLoad_reloadVal 1000 /* 任务执行间隔 */ #define excessiveLoad_offset 0 /* 任务执行偏移量 */ @@ -200,21 +205,20 @@ void Task_wdi(void) { feedDog(); -// debug_printf("chargCurrent:%f \n", getChargCurrent()); -// debug_printf("outputVoltage:%f \n", getOutputVoltage()); -// debug_printf("BatteryVoltage:%f \n", getBatteryVoltage()); -// debug_printf("dischargCurrent:%f \n", getDischargCurrent()); -// debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage()); -// debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature()); -// debug_printf("InputVoltage:%f \n", getInputVoltage()); -// debug_printf("DischargMosState:%d \n", getDischargMosState()); -// debug_printf("MPPT_Mode:%d \n", getMPPT_Mode()); -// debug_printf("loopImpedance:%f \n", getLoopImpedance()); -// debug_printf("DutyRatio:%f \n", getDutyRatio()); -// // debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN()); -// debug_printf("HAL_GetTick:%d \n", HAL_GetTick()); -// debug_printf("getExChargeCurr:%f \n", getExChargeCurr()); - + debug_printf("chargCurrent:%f \n", getChargCurrent()); + debug_printf("outputVoltage:%f \n", getOutputVoltage()); + debug_printf("BatteryVoltage:%f \n", getBatteryVoltage()); + debug_printf("dischargCurrent:%f \n", getDischargCurrent()); + debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage()); + debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature()); + debug_printf("InputVoltage:%f \n", getInputVoltage()); + debug_printf("DischargMosState:%d \n", getDischargMosState()); + debug_printf("MPPT_Mode:%d \n", getMPPT_Mode()); + debug_printf("loopImpedance:%f \n", getLoopImpedance()); + debug_printf("DutyRatio:%f \n", getDutyRatio()); +// debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN()); + debug_printf("HAL_GetTick:%d \n", HAL_GetTick()); + debug_printf("getExChargeCurr:%f \n", getExChargeCurr()); // char buf[100]; // sprintf(buf, "chargCurrent:%f \n", getChargCurrent()); @@ -351,6 +355,14 @@ void Task_refreshJudgeData(void) stopChargWork(); insertEventsOrderRecord(overInputVolt); } + + static uint8_t num = 0; + if (20 == num++) { + num = 0; + setSOC(); + } + + } /** @@ -364,12 +376,19 @@ void Task_refreshJudgeData(void) */ void Task_startControl(void) { + static uint8_t numStart = 0; + if (g_cfgParameter.checkCanStartTime > numStart++) { + return; + } + numStart = 0; + /* 是否达到启动条件 */ if (getSolarInCircuitVoltage() > g_cfgParameter.startSolarOpenCircuitV && getSolarInCircuitVoltage() < g_cfgParameter.maxOpenSolarOutputCircuitV) { + TimeSliceOffset_Unregister(&m_startControl); m_startControl.runFlag = 0; - + /* 判断有无电池 */ if (getOutputVoltage() > 11.0f) { setBatteryState(TRUE); @@ -378,15 +397,16 @@ void Task_startControl(void) } /* 启动软起动任务 */ - // TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset); - if (getBatteryState() == TRUE) { - setMPPT_Mode(MPPT); - } else { - setMPPT_Mode(floatCharg); - } + 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(); + // setChargControlFlag(TRUE); + // EN_PWMOUT_Eable(); } } /** @@ -408,22 +428,59 @@ void beginStartControlTask(void) */ void Task_softStart(void) { + // static uint16_t num = 0; + // static float dutyRatio = 0; + // num++; + + // if (num < 5) { + // set_pwmDutyRatio(0.1f); + // EN_PWMOUT_Eable(); + // } + + // else if (num > 70 || dutyRatio > 0.7f) { + // TimeSliceOffset_Unregister(&m_softStart); + // m_softStart.runFlag = 0; + + // dutyRatio = 0; + // num = 0; + // setDutyRatio(0.75f); + + // if (getBatteryState() == TRUE) { + // setMPPT_Mode(MPPT); + // } else { + // setMPPT_Mode(floatCharg); + // } + // setChargControlFlag(TRUE); + // } + + // else { + // setDutyRatio(getDutyRatio() + 0.01f); + // } + + static uint16_t num = 0; - static float dutyRatio = 0; + // static float dutyRatio = 0; num++; if (num < 5) { - set_pwmDutyRatio(0.1f); EN_PWMOUT_Eable(); + //最小占空比斩波 + setDutyRatio(0.0001f); } - else if (num > 70 || dutyRatio > 0.6f) { + else if (num > 80) { TimeSliceOffset_Unregister(&m_softStart); m_softStart.runFlag = 0; - - dutyRatio = 0; num = 0; - setDutyRatio(0.75f); + + // debug_printf("getSolarInCircuitVoltage : %f", getSolarInCircuitVoltage()); + + //电压过低时不启动 + if (getSolarInCircuitVoltage() < 18.5f) { + TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset); + setDutyRatioToZero(); + return; + } if (getBatteryState() == TRUE) { setMPPT_Mode(MPPT); @@ -433,9 +490,9 @@ void Task_softStart(void) setChargControlFlag(TRUE); } - else { - setDutyRatio(getDutyRatio() + 0.01f); - } + // else { + // setDutyRatio(0.01f); + // } } /** * @brief 启动软启动任务 @@ -691,10 +748,11 @@ void Task_shortCircuitProtection(void) static uint8_t num = 0; num++; + /* 设定输出短路保护时间 */ if (num == 2) { - setPowerOutput(FALSE); - setPowerOutput(TRUE); + // setPowerOutput(FALSE); + setPowerOutput(TRUE); } @@ -738,6 +796,53 @@ void stopShortCircuitProtection(void) m_shortCircuitProtection.runFlag = 0; } +/** + * @brief 反向充电短路保护任务,短路后启动该任务 + * @param + * @retval + */ +void Task_EXCHGSCProtection(void) +{ + static uint8_t num = 0; + num++; + + /* 设定输出短路保护时间 */ + if (num == 2) { + // setPowerOutput(FALSE); + setPowerOutput(TRUE); + } + + /* 设定输出短路保护时间 */ + if (num == g_cfgParameter.shortCircuitJudgmentDelay) { + num = 0; + zeroShortCircuit(); + TimeSliceOffset_Unregister(&m_EXCHGSCProtection); + m_EXCHGSCProtection.runFlag = 0; + } +} + +/** + * @brief 启动短路保护任务 + * @param + * @retval + */ +void startEXCHGSCProtection(void) +{ + TimeSliceOffset_Register(&m_EXCHGSCProtection, Task_EXCHGSCProtection + , EXCHGSCProtection_reloadVal, EXCHGSCProtection_offset); +} + +/** + * @brief 关闭短路保护任务 + * @param + * @retval + */ +void stopEXCHGSCProtection(void) +{ + TimeSliceOffset_Unregister(&m_EXCHGSCProtection); + m_EXCHGSCProtection.runFlag = 0; +} + /** * @brief 过载保护任务,输入不够供给输出后启动该任务 * @param @@ -786,6 +891,8 @@ void Task_excessiveLoad(void) /* 关闭输出后开始计时 */ if (readPOW_OUT_PCON_State() == FALSE) { numLong++; + } else { + numLong = 0; } /* 达到时间就重新尝试输出 */ @@ -860,7 +967,7 @@ void Task_softShortCircuit(void) if (num >= g_cfgParameter.shortCircuitJudgmentDelay) { num = 0; - if (getShortCircuit() == 1) { + if (getShortCircuit() == 1) { setShortCircuitFlag(FALSE); } zeroShortCircuit(); diff --git a/EWARM/chargeController.ewp b/EWARM/chargeController.ewp index 5a0778c..9469dea 100644 --- a/EWARM/chargeController.ewp +++ b/EWARM/chargeController.ewp @@ -1,1348 +1,1350 @@ - 4 - - chargeController - - ARM - - 1 - - General - 3 - - 36 - 1 + 4 + + chargeController + + ARM + 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ICCARM - 2 - - 38 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AARM - 2 - - 12 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OBJCOPY - 0 - - 1 - 1 - 1 - - - - - - - - - CUSTOM - 3 - - - - 1 - inputOutputBased - - - - ILINK - 0 - - 27 - 1 - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IARCHIVE - 0 - - 0 - 1 - 1 - - - - - - - BUILDACTION - 2 - - - - Coder - 0 - - - - - APP + + General + 3 + + 36 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 38 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 12 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + 1 + inputOutputBased + + + + ILINK + 0 + + 27 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BUILDACTION + 2 + + + + Coder + 0 + + + - application - - $PROJ_DIR$\..\APP\application\Src\chargControl.c - - - $PROJ_DIR$\..\APP\application\Src\start.c - + APP + + application + + $PROJ_DIR$\..\APP\application\Src\chargControl.c + + + $PROJ_DIR$\..\APP\application\Src\start.c + + + + businessLogic + + $PROJ_DIR$\..\APP\businessLogic\Src\abnormalManage.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\bl_chargControl.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\bl_usart.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\Init.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\interruptSend.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\soc.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\SOE.c + + + $PROJ_DIR$\..\APP\businessLogic\Src\task.c + + + + functionalModule + + $PROJ_DIR$\..\APP\functionalModule\Src\capture.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\checkTime.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\flash.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\FM_RTC.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c + + + $PROJ_DIR$\..\APP\functionalModule\Src\uart_dev.c + + + + hardwareDriver + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_ADC.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_COMM.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_RTC.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c + + + $PROJ_DIR$\..\APP\hardwareDriver\Src\w25qxx.c + + - businessLogic - - $PROJ_DIR$\..\APP\businessLogic\Src\abnormalManage.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\bl_chargControl.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\bl_usart.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\Init.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\interruptSend.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\SOE.c - - - $PROJ_DIR$\..\APP\businessLogic\Src\task.c - + Application + + EWARM + + $PROJ_DIR$\startup_stm32g431xx.s + + + + User + + Core + + $PROJ_DIR$\..\Core\Src\adc.c + + + $PROJ_DIR$\..\Core\Src\dma.c + + + $PROJ_DIR$\..\Core\Src\gpio.c + + + $PROJ_DIR$\..\Core\Src\main.c + + + $PROJ_DIR$\..\Core\Src\rtc.c + + + $PROJ_DIR$\..\Core\Src\spi.c + + + $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_msp.c + + + $PROJ_DIR$\..\Core\Src\stm32g4xx_it.c + + + $PROJ_DIR$\..\Core\Src\tim.c + + + $PROJ_DIR$\..\Core\Src\usart.c + + + - functionalModule - - $PROJ_DIR$\..\APP\functionalModule\Src\capture.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\checkTime.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\flash.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\FM_RTC.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c - - - $PROJ_DIR$\..\APP\functionalModule\Src\uart_dev.c - + Drivers + + CMSIS + + $PROJ_DIR$\..\Core\Src\system_stm32g4xx.c + + + + STM32G4xx_HAL_Driver + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c + + + $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c + + - hardwareDriver - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_ADC.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_COMM.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_RTC.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c - - - $PROJ_DIR$\..\APP\hardwareDriver\Src\w25qxx.c - - - - - Application - - EWARM - - $PROJ_DIR$\startup_stm32g431xx.s - + Middlewares + + Library + + DSP Library/DSP Library + + $PROJ_DIR$\..\Middlewares\ST\ARM\DSP\Lib\iar_cortexM4lf_math.a + + + - User - - Core + tools - $PROJ_DIR$\..\Core\Src\main.c + $PROJ_DIR$\..\tools\RingQueue\ring_queue.c - $PROJ_DIR$\..\Core\Src\gpio.c + $PROJ_DIR$\..\tools\TimeSliceOffset\timeSliceOffset.c - - $PROJ_DIR$\..\Core\Src\adc.c - - - $PROJ_DIR$\..\Core\Src\dma.c - - - $PROJ_DIR$\..\Core\Src\rtc.c - - - $PROJ_DIR$\..\Core\Src\spi.c - - - $PROJ_DIR$\..\Core\Src\tim.c - - - $PROJ_DIR$\..\Core\Src\usart.c - - - $PROJ_DIR$\..\Core\Src\stm32g4xx_it.c - - - $PROJ_DIR$\..\Core\Src\stm32g4xx_hal_msp.c - - - - - Drivers - - CMSIS - - $PROJ_DIR$\..\Core\Src\system_stm32g4xx.c - - - - STM32G4xx_HAL_Driver - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_adc_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_ll_adc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_flash_ramfunc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_gpio.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_exti.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_dma_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_pwr_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_cortex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim_ex.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart.c - - - $PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_uart_ex.c - - - - - tools - - $PROJ_DIR$\..\tools\RingQueue\ring_queue.c - - - $PROJ_DIR$\..\tools\TimeSliceOffset\timeSliceOffset.c - - - - Middlewares - - Library - - DSP Library/DSP Library - - $PROJ_DIR$/../Middlewares/ST/ARM/DSP/Lib/iar_cortexM4lf_math.a - - - - - diff --git a/EWARM/chargeController.ewt b/EWARM/chargeController.ewt index 8eb6877..c94d3f1 100644 --- a/EWARM/chargeController.ewt +++ b/EWARM/chargeController.ewt @@ -1463,6 +1463,9 @@ $PROJ_DIR$\..\APP\businessLogic\Src\parameter.c + + $PROJ_DIR$\..\APP\businessLogic\Src\soc.c + $PROJ_DIR$\..\APP\businessLogic\Src\SOE.c diff --git a/tools/chargControlTypes.h b/tools/chargControlTypes.h index cb171ca..80cc428 100644 --- a/tools/chargControlTypes.h +++ b/tools/chargControlTypes.h @@ -68,6 +68,7 @@ typedef enum { hardwareInputProtection, //硬件防反输入保护 InputProtection, //软件防反输入保护 startEvent, //启动 + abnormalControl, //异常控制 }eventsOrderRecordMode;