478 lines
9.5 KiB
C
478 lines
9.5 KiB
C
|
|
#include "abnormalManage.h"
|
|
#include "parameter.h"
|
|
#include "capture.h"
|
|
#include "checkTime.h"
|
|
#include "FM_GPIO.h"
|
|
#include "task.h"
|
|
#include "configParameter.h"
|
|
#include "capture.h"
|
|
#include "bl_chargControl.h"
|
|
#include "SOE.h"
|
|
|
|
//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;
|
|
static BOOL excessiveLoadInterruptFlag = FALSE;
|
|
|
|
/**
|
|
* @brief 设定放电过载状态
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void setDisChargOverLoad(void)
|
|
{
|
|
/* 三段式保护中的第三段 */
|
|
static int num1 = 0;
|
|
if (getDischargCurrent() > g_cfgParameter.thirdStageProtectionCurr) {
|
|
// disChargOverLoad = TRUE;
|
|
num1++;
|
|
} else {
|
|
// disChargOverLoad = FALSE;
|
|
num1 = 0;
|
|
}
|
|
|
|
/* 过载时间过长关闭输出 */
|
|
if (num1 >= g_cfgParameter.thirdStageProtectionDelay) {
|
|
num1 = 0;
|
|
setPowerOutput(FALSE);
|
|
disChargOverLoad = TRUE;
|
|
insertEventsOrderRecord(thirdStageProtection);
|
|
}
|
|
|
|
|
|
/* 三段式保护中的第二段 */
|
|
static int num2 = 0;
|
|
if (getDischargCurrent() > g_cfgParameter.secondStageProtectionCurr) {
|
|
num2++;
|
|
} else {
|
|
num2 = 0;
|
|
}
|
|
|
|
/* 过载时间过长关闭输出 */
|
|
if (num2 >= g_cfgParameter.secondStageProtectionDelay) {
|
|
num2 = 0;
|
|
// debug_printf("in secondStageProtection \n");
|
|
setPowerOutput(FALSE);
|
|
disChargOverLoad = TRUE;
|
|
insertEventsOrderRecord(secondStageProtection);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 软件短路保护
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void setSoftShortCircuit(uint16_t disChargCurrAdcNum)
|
|
{
|
|
// /* 三段式保护中的第一段 */
|
|
// static int num = 0;
|
|
// if (getDischargCurrent() > firstStageProtectionCurr) {
|
|
// num++;
|
|
// } else {
|
|
// num = 0;
|
|
// }
|
|
|
|
/* 三段式保护中的第一段 */
|
|
static int num = 0;
|
|
if (disChargCurrAdcNum > g_cfgParameter.firstStageProtectionValue) {
|
|
num++;
|
|
} else {
|
|
num = 0;
|
|
}
|
|
|
|
/* 20uS内都短路则关闭输出 */
|
|
if (num >= g_cfgParameter.firstStageProtectionDelay) {
|
|
num = 0;
|
|
setPowerOutput(FALSE);
|
|
// shortCircuitFlag = TRUE;
|
|
// shortCircuit++;
|
|
// debug_printf("in firstStageProtection %d \n", g_cfgParameter.firstStageProtectionValue);
|
|
// debug_printf("in firstStageProtection %d \n", disChargCurrAdcNum);
|
|
insertEventsOrderRecord(firstStageProtection);
|
|
// startSoftShortCircuitProtection();
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 得到硬件过载标志位
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
BOOL getExcessiveLoadFlag(void)
|
|
{
|
|
return excessiveLoadFlag;
|
|
}
|
|
|
|
/**
|
|
* @brief 设置输出状态
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void setPowerOutput(BOOL state)
|
|
{
|
|
// static volatile float temp_OUT_VOLT_IN;
|
|
// static volatile float temp_PV_VOLT_OUT;
|
|
// temp_PV_VOLT_OUT = get_PV_VOLT_OUT();
|
|
// temp_OUT_VOLT_IN = get_OUT_VOLT_IN();
|
|
if (state == TRUE) {
|
|
// if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) {
|
|
// if (temp_OUT_VOLT_IN < (temp_PV_VOLT_OUT - 0.5f)) {
|
|
POW_FF_PCON_Open();
|
|
POW_OUT_PCON_Open();
|
|
// }
|
|
} else {
|
|
POW_FF_PCON_Close();
|
|
POW_OUT_PCON_Close();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief 判断是否打开充电理想二极管
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void checkFFMOS_CON(void)
|
|
{
|
|
// if (get_CHG_CURR() > 5.0f && FALSE == FFMOS_CON_read()) {
|
|
// FFMOS_CON_Open();
|
|
// }
|
|
// else if (get_CHG_CURR() < 2.0f && TRUE == FFMOS_CON_read()) {
|
|
// FFMOS_CON_Close();
|
|
// }
|
|
|
|
if (getChargCurrent() > 5.0f && FALSE == FFMOS_CON_read()) {
|
|
FFMOS_CON_Open();
|
|
}
|
|
else if (getChargCurrent() < 2.0f && TRUE == FFMOS_CON_read()) {
|
|
FFMOS_CON_Close();
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * @brief 判断是否短路
|
|
// * @param
|
|
// * @retval
|
|
// *
|
|
// */
|
|
// void checkShortCircuit(void)
|
|
// {
|
|
// static num = 0;
|
|
// if (getChargCurrent() > 50.0f) {
|
|
// num++;
|
|
// } else {
|
|
// num = 0;
|
|
// }
|
|
|
|
// if (num == g_cfgParameter.softShortTime) {
|
|
// setPowerOutput(FALSE);
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
/**
|
|
* @brief 输入功率过低保护
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void setOverLoad(void)
|
|
{
|
|
setPowerOutput(FALSE);
|
|
setExcessiveLoad();
|
|
/* 第一次进入输出过载,启动过载保护任务 */
|
|
if (getExcessiveLoad() == 1) {
|
|
setExcessiveLoadFlag(TRUE);
|
|
startExcessiveLoadProtection();
|
|
}
|
|
|
|
/* 多次进入输出过载,关闭输出 */
|
|
if (getExcessiveLoad() > 2) {
|
|
zeroExcessiveLoad();
|
|
insertEventsOrderRecord(lowInputLoad);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 判断是否输入功率过低
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void lowInputLoadDetection(void)
|
|
{
|
|
static int num = 0;
|
|
|
|
if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt) {
|
|
num++;
|
|
} else {
|
|
num = 0;
|
|
excessiveLoadInterruptFlag = FALSE;
|
|
}
|
|
|
|
if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.inputPowerLowDetectionDelay) {
|
|
setOverLoad();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief 判断充电电流是否过高,过高则关闭充电
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void judgeChargCurr(void)
|
|
{
|
|
static uint16_t num = 0;
|
|
if (getChargCurrent() > g_cfgParameter.maxChargCurr) {
|
|
num++;
|
|
} else {
|
|
num = 0;
|
|
}
|
|
|
|
if (num > 500) {
|
|
num = 0;
|
|
stopChargWork();
|
|
insertEventsOrderRecord(overchargCurr);
|
|
}
|
|
}
|
|
|
|
void checkAbnormal(void)
|
|
{
|
|
// checkTimeInit();
|
|
/* 滤波 */
|
|
adcCaptureFir();
|
|
|
|
/* 转换 */
|
|
setChargCurrent();
|
|
setDischargCurrent();
|
|
setOutputVoltage();
|
|
setSolarInCircuitVoltage();
|
|
|
|
/* 判断 */
|
|
checkFFMOS_CON();
|
|
setDisChargOverLoad();
|
|
setSoftShortCircuit1();
|
|
lowInputLoadDetection();
|
|
judgeChargCurr();
|
|
|
|
|
|
|
|
// checkAbnormalTime = getCheckTime();
|
|
}
|
|
|
|
/**
|
|
* @brief 工作电压异常中断,过载(输入大于输出)
|
|
* @param
|
|
* @retval
|
|
*
|
|
*/
|
|
void WORK_VOLT_Interrupt(void)
|
|
{
|
|
// 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) {
|
|
setPowerOutput(FALSE);
|
|
setShortCircuitFlag(TRUE);
|
|
startShortCircuitProtection();
|
|
}
|
|
|
|
/* 一定时间内第二次进入输出短路保护,关闭输出 */
|
|
else if (getShortCircuit() >= 2) {
|
|
stopShortCircuitProtection();
|
|
setPowerOutput(FALSE);
|
|
zeroShortCircuit();
|
|
insertEventsOrderRecord(hardwareShortCircuitProtection);
|
|
}
|
|
}
|
|
|
|
void EXCHG_PROT_Interrupt(void)
|
|
{
|
|
setPowerOutput(FALSE);
|
|
insertEventsOrderRecord(hardwareInputProtection);
|
|
}
|
|
|