|
@@ -304,9 +304,48 @@ void MC_Protect_VoltageChange_Process(uint16_t Voltage, uint16_t Current, MC_Err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//软件过流保护检测
|
|
|
+void MC_OverCurrent_SoftProtect_Process(uint16_t BusCurrent, uint16_t MaxCurrent, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
|
|
|
+{
|
|
|
+ static uint32_t Protect_TimeCnt = 0;
|
|
|
+ static uint32_t Fault_TimeCnt = 0;
|
|
|
+ uint16_t Current_Th;
|
|
|
+
|
|
|
+ Current_Th = (MaxCurrent * 3) >> 1;//1.5倍
|
|
|
+
|
|
|
+ if(p_MC_ErrorCode->ERROR_Bit.Protect_OverCurrent == 0)
|
|
|
+ {
|
|
|
+ if(BusCurrent < Current_Th)
|
|
|
+ {
|
|
|
+ Protect_TimeCnt = HAL_GetTick();
|
|
|
+ }
|
|
|
+ if((HAL_GetTick() - Protect_TimeCnt) > 5000)
|
|
|
+ {
|
|
|
+ p_MC_ErrorCode->ERROR_Bit.Protect_OverCurrent = 1;
|
|
|
+ //记录故障日志
|
|
|
+ MC_ErrorLogSaveInfo.NotesInfo1 = 2;
|
|
|
+ MC_ErrorLogSaveInfo.NotesInfo2 = Current_Th;
|
|
|
+ ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
|
|
|
+ IsErrorLogSaveInfoUpdateFlag = TRUE;
|
|
|
+ //存储故障次数
|
|
|
+ MC_RunLog1.OC_ProtectCnt++;
|
|
|
+ RunLogSaveIndex = 1;
|
|
|
+ Fault_TimeCnt = HAL_GetTick();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //过流保护恢复
|
|
|
+ if((HAL_GetTick() - Fault_TimeCnt) > 5000)
|
|
|
+ {
|
|
|
+ MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/******************************全局函数定义******************************/
|
|
|
#define OC_CLEARFLAG_DELAYTIME 15 //过流标志间隔清零延时,单位ms
|
|
|
-#define OC_COUNTER_TH 100 //过流保护计数判断阈值
|
|
|
+#define OC_COUNTER_TH 1000 //过流保护计数判断阈值
|
|
|
//过流保护检测
|
|
|
/*
|
|
|
检测原理:
|
|
@@ -314,79 +353,42 @@ void MC_Protect_VoltageChange_Process(uint16_t Voltage, uint16_t Current, MC_Err
|
|
|
2、在过流触发计数达到OC_COUNTER_TH 次之前,如果存在两次过流触发间隔时间超过OC_CLEARFLAG_DELAYTIME ms,清除过流触发计数;
|
|
|
3、如果每两次过流触发间隔时间都不超过OC_CLEARFLAG_DELAYTIME ms,当过流触发计数达到OC_COUNTER_TH 次,则进入过流保护;
|
|
|
4、进入过流保护后,超时5s解除。
|
|
|
+
|
|
|
+更改处理方式20210630
|
|
|
+1、关闭过流告警;
|
|
|
+2、出现过流信号时,封闭PWM2个周期
|
|
|
*/
|
|
|
void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
|
|
|
{
|
|
|
static uint8_t OffPwmCnt = 0; //过流信号触发后,关闭PWM延时计数
|
|
|
static uint8_t StarPwmCnt = 0; //关闭PWM后启动PWM延时计数
|
|
|
- static uint16_t ocCnt = 0; //过流信号触发计数
|
|
|
- static uint32_t ocTimeCnt = 0; //过流信号触发计时
|
|
|
- static uint32_t ocFaultTimeCnt = 0; //过流保护后计时
|
|
|
|
|
|
- if(p_MC_ErrorCode->ERROR_Bit.Protect_OverCurrent == 0)
|
|
|
+ if(*OverCurrentTrigFlag == RESET)
|
|
|
{
|
|
|
- if(*OverCurrentTrigFlag == RESET)
|
|
|
+ //关闭PWM计数清零
|
|
|
+ OffPwmCnt = 0;
|
|
|
+ //开启PWM
|
|
|
+ if(StarPwmCnt == 0)
|
|
|
{
|
|
|
- //关闭PWM计数清零
|
|
|
- OffPwmCnt = 0;
|
|
|
- //两次过流触发间隔超时OC_CLEARFLAG_DELAYTIME ms,过流次数未达到OC_COUNTER_TH 次,过流计数清零
|
|
|
- if(ocCnt < OC_COUNTER_TH)
|
|
|
- {
|
|
|
- if((HAL_GetTick() - ocTimeCnt) >= OC_CLEARFLAG_DELAYTIME)
|
|
|
- {
|
|
|
- ocTimeCnt = HAL_GetTick();
|
|
|
- ocCnt = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- //开启PWM
|
|
|
- if(StarPwmCnt == 0)
|
|
|
- {
|
|
|
- StarPwmCnt++;
|
|
|
- Enable_PwmGpio_Out();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //开启PWM计数清零
|
|
|
- StarPwmCnt = 0;
|
|
|
- //关闭PWM
|
|
|
- Disable_PwmGpio_Out();
|
|
|
- //2个PWM周期后,过流触发标志复位
|
|
|
- if(OffPwmCnt >= 1)
|
|
|
- {
|
|
|
- *OverCurrentTrigFlag = RESET;
|
|
|
- }
|
|
|
- //过流次数计数
|
|
|
- if(ocCnt < OC_COUNTER_TH)
|
|
|
- {
|
|
|
- ocCnt++;
|
|
|
- }
|
|
|
- //过流标志计数次数达到OC_COUNTER_TH 次,启动过流保护
|
|
|
- else
|
|
|
- {
|
|
|
- ocCnt = 0;
|
|
|
- p_MC_ErrorCode->ERROR_Bit.Protect_OverCurrent = 1;
|
|
|
- ocFaultTimeCnt = HAL_GetTick();
|
|
|
- //记录故障日志
|
|
|
- ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
|
|
|
- IsErrorLogSaveInfoUpdateFlag = TRUE;
|
|
|
- //存储故障次数
|
|
|
- MC_RunLog1.OC_ProtectCnt++;
|
|
|
- RunLogSaveIndex = 1;
|
|
|
- }
|
|
|
- OffPwmCnt++;
|
|
|
- ocTimeCnt = HAL_GetTick();
|
|
|
+ StarPwmCnt++;
|
|
|
+ Enable_PwmGpio_Out();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //过流恢复
|
|
|
- if((HAL_GetTick() - ocFaultTimeCnt) > 5000)
|
|
|
+ //开启PWM计数清零
|
|
|
+ StarPwmCnt = 0;
|
|
|
+ //2个PWM周期后,过流触发标志复位
|
|
|
+ if(OffPwmCnt >= 1)
|
|
|
{
|
|
|
- MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 0;
|
|
|
- ocFaultTimeCnt = HAL_GetTick();
|
|
|
*OverCurrentTrigFlag = RESET;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //关闭PWM
|
|
|
+ Disable_PwmGpio_Out();
|
|
|
+ }
|
|
|
+ OffPwmCnt++;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -411,4 +413,6 @@ void MC_Protect_Check_Process(void)
|
|
|
//电压波动异常保护检测
|
|
|
MC_Protect_VoltageChange_Process(MC_RunInfo.BusVoltage, MC_RunInfo.BusCurrent, &MC_ErrorCode);
|
|
|
|
|
|
+ //软件过流保护检测
|
|
|
+ MC_OverCurrent_SoftProtect_Process(MC_RunInfo.BusCurrent, MC_ConfigParam1.CurrentLimit * 1000, &MC_ErrorCode);
|
|
|
}
|