chargeController/APP/businessLogic/Src/abnormalManage.c

445 lines
8.0 KiB
C
Raw Normal View History

#include "abnormalManage.h"
#include "parameter.h"
#include "capture.h"
#include "checkTime.h"
2024-12-11 09:51:48 +00:00
#include "FM_GPIO.h"
#include "task.h"
2024-12-26 03:48:54 +00:00
#include "configParameter.h"
#include "capture.h"
2024-12-27 10:14:28 +00:00
//static int checkMode = 0;
/* 软件输出过载标志位 */
static BOOL disChargOverLoad = FALSE;
/* 短路标志位 */
static uint8_t shortCircuit = 0;
static BOOL shortCircuitFlag = FALSE;
/* 硬件过载状态位 */
static uint8_t excessiveLoad = 0;
static BOOL excessiveLoadFlag = FALSE;
2024-12-26 03:48:54 +00:00
static BOOL excessiveLoadInterruptFlag = FALSE;
/**
* @brief
2024-12-24 06:43:20 +00:00
* @param
* @retval
*
*/
void setDisChargOverLoad(void)
{
2024-12-26 03:48:54 +00:00
/* 三段式保护中的第三段 */
2024-12-24 06:43:20 +00:00
static int num1 = 0;
2024-12-26 03:48:54 +00:00
if (getDischargCurrent() > thirdStageProtectionCurr) {
2024-12-24 06:43:20 +00:00
// disChargOverLoad = TRUE;
num1++;
} else {
// disChargOverLoad = FALSE;
num1 = 0;
}
2024-12-26 03:48:54 +00:00
/* 过载时间过长关闭输出 */
if (num1 >= thirdStageProtectionDelay) {
2024-12-24 06:43:20 +00:00
num1 = 0;
setPowerOutput(FALSE);
2024-12-27 10:14:28 +00:00
disChargOverLoad = TRUE;
2024-12-24 06:43:20 +00:00
}
2024-12-26 03:48:54 +00:00
/* 三段式保护中的第二段 */
2024-12-24 06:43:20 +00:00
static int num2 = 0;
2024-12-26 03:48:54 +00:00
if (getDischargCurrent() > secondStageProtectionCurr) {
2024-12-24 06:43:20 +00:00
num2++;
} else {
num2 = 0;
}
2024-12-26 03:48:54 +00:00
/* 过载时间过长关闭输出 */
if (num1 >= secondStageProtectionDelay) {
2024-12-24 06:43:20 +00:00
num1 = 0;
setPowerOutput(FALSE);
2024-12-27 10:14:28 +00:00
disChargOverLoad = TRUE;
2024-12-24 06:43:20 +00:00
}
}
/**
* @brief
* @param
* @retval
*
*/
2024-12-26 03:48:54 +00:00
void setSoftShortCircuit(uint16_t disChargCurrAdcNum)
2024-12-24 06:43:20 +00:00
{
2024-12-26 03:48:54 +00:00
// /* 三段式保护中的第一段 */
// static int num = 0;
// if (getDischargCurrent() > firstStageProtectionCurr) {
// num++;
// } else {
// num = 0;
// }
/* 三段式保护中的第一段 */
2024-12-24 06:43:20 +00:00
static int num = 0;
2024-12-27 10:14:28 +00:00
if (disChargCurrAdcNum > firstStageProtectionValue) {
2024-12-24 06:43:20 +00:00
num++;
} else {
2024-12-24 06:43:20 +00:00
num = 0;
}
2024-12-27 10:14:28 +00:00
/* 20uS内都短路则关闭输出 */
2024-12-26 03:48:54 +00:00
if (num >= firstStageProtectionDelay) {
2024-12-27 10:14:28 +00:00
setPowerOutput(FALSE);
2024-12-24 06:43:20 +00:00
shortCircuitFlag = TRUE;
shortCircuit++;
startSoftShortCircuitProtection();
}
}
2024-12-27 10:14:28 +00:00
void setSoftShortCircuit1(void)
{
// /* 三段式保护中的第一段 */
// static int num = 0;
// if (getDischargCurrent() > firstStageProtectionCurr) {
// num++;
// } else {
// num = 0;
// }
// /* 三段式保护中的第一段 */
// static int num = 0;
// if (getDischargCurrent() > firstStageProtectionCurr) {
// num++;
// } else {
// num = 0;
// }
// /* 200uS内都短路则关闭输出 */
// if (num >= firstStageProtectionDelay) {
// setPowerOutput(FALSE);
// shortCircuitFlag = TRUE;
// shortCircuit++;
// startSoftShortCircuitProtection();
// }
}
/**
* @brief
* @param
* @retval
*
*/
BOOL getChargOverLoad(void)
{
return disChargOverLoad;
}
/**
* @brief
* @param
* @retval
*
*/
void setShortCircuit(void)
{
shortCircuit++;
}
/**
* @brief
* @param
* @retval
*
*/
void zeroShortCircuit(void)
{
shortCircuit = 0;
}
/**
* @brief
* @param
* @retval
*
*/
uint8_t getShortCircuit(void)
{
return shortCircuit;
}
/**
* @brief
* @param state TRUE
* FALSE
* @retval
*
*/
void setShortCircuitFlag(BOOL state)
{
if (state == TRUE || state == FALSE) {
shortCircuitFlag = state;
2024-12-24 06:43:20 +00:00
}
}
/**
* @brief
* @param
* @retval
*
*/
BOOL getShortCircuitFlag(void)
{
return shortCircuitFlag;
}
/**
* @brief
* @param
* @retval
*
*/
void setExcessiveLoad(void)
{
excessiveLoad++;
}
/**
* @brief
* @param
* @retval
*
*/
void zeroExcessiveLoad(void)
{
excessiveLoad = 0;
}
/**
* @brief
* @param
* @retval
*
*/
uint8_t getExcessiveLoad(void)
{
return excessiveLoad;
}
/**
* @brief
* @param state TRUE
* FALSE
* @retval
*
*/
void setExcessiveLoadFlag(BOOL state)
{
if (state == TRUE || state == FALSE) {
excessiveLoadFlag = state;
2024-12-24 06:43:20 +00:00
}
}
/**
* @brief
* @param
* @retval
*
*/
BOOL getExcessiveLoadFlag(void)
{
return excessiveLoadFlag;
}
/**
* @brief
* @param
* @retval
*
*/
void setPowerOutput(BOOL state)
{
if (state == TRUE) {
2024-12-18 09:43:14 +00:00
if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) {
POW_FF_PCON_Open();
POW_OUT_PCON_Open();
2024-12-26 03:48:54 +00:00
}
} else {
POW_FF_PCON_Close();
POW_OUT_PCON_Close();
}
}
/**
* @brief
* @param
* @retval
*
*/
void checkFFMOS_CON(void)
{
if (get_CHG_CURR() > 2.0f) {
FFMOS_CON_Open();
}
else if (get_CHG_CURR() < 1.0f) {
FFMOS_CON_Close();
}
}
2024-12-24 06:43:20 +00:00
// /**
// * @brief 判断是否短路
// * @param
// * @retval
// *
// */
// void checkShortCircuit(void)
// {
// static num = 0;
// if (getChargCurrent() > 50.0f) {
// num++;
// } else {
// num = 0;
// }
// if (num == g_cfgParameter.softShortTime) {
// setPowerOutput(FALSE);
// }
2024-12-24 06:43:20 +00:00
// }
2024-12-26 03:48:54 +00:00
/**
* @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();
}
}
2024-12-27 10:14:28 +00:00
/**
* @brief
* @param
* @retval
*
*/
void judgeChargCurr(void)
{
if (getChargCurrent() > maxChargCurr) {
stopChargWork();
}
}
void checkAbnormal(void)
{
// checkTimeInit();
/* 滤波 */
adcCaptureFir();
/* 转换 */
setChargCurrent();
setDischargCurrent();
setOutputVoltage();
setSolarInCircuitVoltage();
2024-12-11 09:51:48 +00:00
/* 判断 */
checkFFMOS_CON();
2024-12-24 06:43:20 +00:00
setDisChargOverLoad();
2024-12-27 10:14:28 +00:00
setSoftShortCircuit1();
2024-12-26 03:48:54 +00:00
lowInputLoadDetection();
2024-12-27 10:14:28 +00:00
judgeChargCurr();
2024-12-24 06:43:20 +00:00
2024-12-11 09:51:48 +00:00
// checkAbnormalTime = getCheckTime();
}
/**
* @brief
* @param
* @retval
*
*/
void WORK_VOLT_Interrupt(void)
{
2024-12-26 03:48:54 +00:00
// setPowerOutput(FALSE);
// setExcessiveLoad();
// /* 第一次进入输出过载,启动过载保护任务 */
// if (getExcessiveLoad() == 1) {
// setExcessiveLoadFlag(TRUE);
// startExcessiveLoadProtection();
// }
// /* 多次进入输出过载,关闭输出 */
// if (getExcessiveLoad() > 2) {
// zeroExcessiveLoad();
// }
excessiveLoadInterruptFlag = TRUE;
}
/**
* @brief
* @param
* @retval
*
*/
void DSG_PROT_Interrupt(void)
{
setShortCircuit();
/* 第一次进入输出短路,启动短路任务 */
if (getShortCircuit() == 1) {
setShortCircuitFlag(TRUE);
startShortCircuitProtection();
2024-12-24 06:43:20 +00:00
}
/* 一定时间内第二次进入输出短路保护,关闭输出 */
else if (getShortCircuit() >= 2) {
stopShortCircuitProtection();
setPowerOutput(FALSE);
zeroShortCircuit();
}
}