Эх сурвалжийг харах

2022-02-07 / Eason Yang
Action
1. Improve: CCS & BS mode over current protection logic.
2. Added: Timer for recover over current protection.

File
1. Module_AlarmDetect.c
Action 1

2. Module_AlarmDetect.h & Makefile
Action 2

FIRMWARE VERSION: B0.61.XX.XXXX.PX

8009 3 жил өмнө
parent
commit
d45762793a

+ 1 - 1
EVSE/Projects/AW-CCS/Apps/Makefile

@@ -72,7 +72,7 @@ Module_AlarmDetect_Task:
 	@echo "===== Module_AlarmDetect_Task ===================================="
 	rm -f Module_AlarmDetect 
 	$(CC) -D $(Project) "-I../../" -O0  -Wall -c -fmessage-length=0 -o Module_AlarmDetect.o "./Module_AlarmDetect.c"
-	$(CC) -o Module_AlarmDetect Module_AlarmDetect.o 
+	$(CC) -lrt -o Module_AlarmDetect Module_AlarmDetect.o 
 	rm -f *.o
 	mv -f Module_AlarmDetect ../Images/root	
 	@echo \ 

+ 87 - 35
EVSE/Projects/AW-CCS/Apps/Module_AlarmDetect.c

@@ -26,6 +26,7 @@
 #include	<ctype.h>
 #include	"define.h"
 #include	"main.h"
+#include	"Module_AlarmDetect.h"
 
 #define FILTER_SPEC			2
 
@@ -49,7 +50,9 @@
 #define HYSTERETIC_OT		10
 #define HYSTERETIC_OC		10
 
-#define ALARM_OC_RETRY_COUNT 4
+#define ALARM_OC_RETRY_COUNT 		4
+#define FILTER_SPEC_FOR_CCS			60	// 6 seconds		
+#define	TIMEOUT_SPEC_OC_RECOVER 	60
 
 //#define isDebugPrint
 
@@ -86,6 +89,8 @@ struct Charger					*ShmCharger;
 unsigned long					previousAlarmCode[AC_QUANTITY];
 uint32_t OCP_Magnification = 0;		// Magnification
 
+struct timespec					startTime[TMR_IDX_CNT];
+
 int StoreLogMsg(const char *fmt, ...)
 {
 	char Buf[4096+256];
@@ -142,6 +147,20 @@ int DiffTimeb(struct timeb ST, struct timeb ET)
 	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
 }
 
+void refreshStartTimer(struct timespec *timer)
+{
+	clock_gettime(CLOCK_MONOTONIC, timer);
+}
+
+int getDiffSecNow(struct timespec timer)
+{
+	struct timespec timerNow;
+
+	clock_gettime(CLOCK_MONOTONIC, &timerNow);
+
+	return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
+}
+
 //==========================================
 // Init all share memory
 //==========================================
@@ -540,21 +559,31 @@ int main(void)
 			// Over current detection
 			//=====================================
 			ccsOverCurrentProtection(gun_index);
-			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == ON) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) > Over_Current[gun_index].OC_BegThreshold))
+			if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == ON)))
 			{
-				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[0] > 60):(Alarm_Counter[gun_index].OC[0] > FILTER_SPEC)))
+				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[0] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[0] > FILTER_SPEC)))
 				{
 					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
 					{
+						refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L1]);
 						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
 						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L1_OVER_CURRENT;
-						if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC_Retry[0]++):(Alarm_Counter[gun_index].OC_Retry[0]==0)));
+						
+						if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
+						{
+							Alarm_Counter[gun_index].OC_Retry[0]++;
+							
+							DEBUG_INFO("Gun-[%d] PresentChargingCurrent: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0));
+							DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
+							DEBUG_INFO("Gun-[%d] OC_Retry[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[0]);
+							//DEBUG_INFO("Gun-[%d] OC_Connter[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC[0]);
+						}
+						else
+						{
+							Alarm_Counter[gun_index].OC_Retry[0] = 0;
+						}
 						
 						DEBUG_INFO("ALARM_L1_OVER_CURRENT : alarm \n");
-						DEBUG_INFO("Gun-[%d] PresentChargingCurrent: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0));
-						DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
-						DEBUG_INFO("Gun-[%d] OC_Connter[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC[0]);
-						DEBUG_INFO("Gun-[%d] OC_Retry[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[0]);
 					}
 				}
 				else
@@ -562,18 +591,18 @@ int main(void)
 					Alarm_Counter[gun_index].OC[0]++;
 				}
 			}
-			else if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == OFF) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) < Over_Current[gun_index].OC_EndThreshold))
+			else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == OFF)))
 			{
 				Alarm_Counter[gun_index].OC[0] = 0;
 				if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
 				{
-					if(Alarm_Counter[gun_index].OC_Retry[0] <= ALARM_OC_RETRY_COUNT)
+					if((Alarm_Counter[gun_index].OC_Retry[0] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L1]) >= TIMEOUT_SPEC_OC_RECOVER))
 					{
 						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
 						{
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_OVER_CURRENT;
-							DEBUG_INFO("ALARM_L1_OVER_CURRENT : recover \n");
+							DEBUG_INFO("ALARM_L1_OVER_CURRENT : Automatically recover \n");
 						}
 					}
 					else
@@ -581,11 +610,12 @@ int main(void)
 						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
 						{
 							Alarm_Counter[gun_index].OC_Retry[0] = 0;
+							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L1]);
 							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
 							{
 								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
 								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_OVER_CURRENT;
-								DEBUG_INFO("ALARM_L1_OVER_CURRENT : recover latch \n");
+								DEBUG_INFO("ALARM_L1_OVER_CURRENT : Latched and recover by unplugging the gun  \n");
 							}
 						}
 					}
@@ -603,21 +633,31 @@ int main(void)
 
 			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
 			{
-				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == ON) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) > Over_Current[gun_index].OC_BegThreshold))
+				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == ON)))
 				{
-					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[1] > 60):(Alarm_Counter[gun_index].OC[1] > FILTER_SPEC)))
+					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[1] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[1] > FILTER_SPEC)))
 					{
 						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == OFF)
 						{
+							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L2]);
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L2_OVER_CURRENT;
-							if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC_Retry[1]++):(Alarm_Counter[gun_index].OC_Retry[1]==0)));
+							
+							if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
+							{
+								Alarm_Counter[gun_index].OC_Retry[1]++;
+								
+								DEBUG_INFO("Gun-[%d] PresentChargingCurrentL2: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0));
+								DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
+								DEBUG_INFO("Gun-[%d] OC_Retry[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[1]);
+								//DEBUG_INFO("Gun-[%d] OC_Connter[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC[1]);
+							}
+							else
+							{
+								Alarm_Counter[gun_index].OC_Retry[1] = 0;
+							}
 							
 							DEBUG_INFO("ALARM_L2_OVER_CURRENT : alarm \n");
-							DEBUG_INFO("Gun-[%d] PresentChargingCurrentL2: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0));
-							DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
-							DEBUG_INFO("Gun-[%d] OC_Connter[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC[1]);
-							DEBUG_INFO("Gun-[%d] OC_Retry[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[1]);
 						}
 					}
 					else
@@ -626,18 +666,18 @@ int main(void)
 					}
 					
 				}
-				else if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == OFF) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) < Over_Current[gun_index].OC_EndThreshold))
+				else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == OFF)))
 				{
 					Alarm_Counter[gun_index].OC[1] = 0;
 					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
 					{
-						if(Alarm_Counter[gun_index].OC_Retry[1] <= ALARM_OC_RETRY_COUNT)
+						if((Alarm_Counter[gun_index].OC_Retry[1] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L2]) >= TIMEOUT_SPEC_OC_RECOVER))
 						{
 							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
 							{
 								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = OFF;
 								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_OVER_CURRENT;
-								DEBUG_INFO("ALARM_L2_OVER_CURRENT : recover \n");
+								DEBUG_INFO("ALARM_L2_OVER_CURRENT : Automatically recover \n");
 							}
 						}
 						else
@@ -645,11 +685,12 @@ int main(void)
 							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
 							{
 								Alarm_Counter[gun_index].OC_Retry[1] = 0;
+								refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L2]);
 								if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
 								{
 									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = OFF;
 									ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_OVER_CURRENT;
-									DEBUG_INFO("ALARM_L2_OVER_CURRENT : recover latch \n");
+									DEBUG_INFO("ALARM_L2_OVER_CURRENT : Latched and recover by unplugging the gun \n");
 								}
 							}
 						}
@@ -665,21 +706,31 @@ int main(void)
 					}
 				}
 
-				if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == ON) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) > Over_Current[gun_index].OC_BegThreshold))
+				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == ON)))
 				{
-					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[2] > 60):(Alarm_Counter[gun_index].OC[2] > FILTER_SPEC)))
+					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[2] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[2] > FILTER_SPEC)))
 					{
 						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == OFF)
 						{
+							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L3]);
 							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = ON;
 							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L3_OVER_CURRENT;
-							if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC_Retry[2]++):(Alarm_Counter[gun_index].OC_Retry[2]==0)));
 							
+							if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
+							{
+								Alarm_Counter[gun_index].OC_Retry[2]++;
+								
+								DEBUG_INFO("Gun-[%d] PresentChargingCurrentL3: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0));
+								DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
+								DEBUG_INFO("Gun-[%d] OC_Retry[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[2]);
+								//DEBUG_INFO("Gun-[%d] OC_Connter[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC[2]);
+							}
+							else
+							{
+								Alarm_Counter[gun_index].OC_Retry[2] = 0;
+							}
+
 							DEBUG_INFO("ALARM_L3_OVER_CURRENT : alarm \n");
-							DEBUG_INFO("Gun-[%d] PresentChargingCurrentL3: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0));
-							DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
-							DEBUG_INFO("Gun-[%d] OC_Connter[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC[2]);
-							DEBUG_INFO("Gun-[%d] OC_Retry[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[2]);
 						}
 					}
 					else
@@ -687,30 +738,31 @@ int main(void)
 						Alarm_Counter[gun_index].OC[2]++;
 					}
 				}
-				else if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == OFF) || ((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) < Over_Current[gun_index].OC_EndThreshold))
+				else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == OFF)))
 				{
 					Alarm_Counter[gun_index].OC[2] = 0;
 					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
 					{
-						if(Alarm_Counter[gun_index].OC_Retry[2] <= ALARM_OC_RETRY_COUNT)
+						if((Alarm_Counter[gun_index].OC_Retry[2] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L3]) >= TIMEOUT_SPEC_OC_RECOVER))
 						{
 							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
 							{
 								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = OFF;
 								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_OVER_CURRENT;
-								DEBUG_INFO("ALARM_L3_OVER_CURRENT : recover \n");
-							}
+								DEBUG_INFO("ALARM_L3_OVER_CURRENT : Automatically recover \n");
+							}	
 						}
 						else
 						{
 							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
 							{
 								Alarm_Counter[gun_index].OC_Retry[2] = 0;
+								refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L3]);
 								if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
 								{
 									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = OFF;
 									ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_OVER_CURRENT;
-									DEBUG_INFO("ALARM_L3_OVER_CURRENT : recover latch \n");
+									DEBUG_INFO("ALARM_L3_OVER_CURRENT : Latched and recover by unplugging the gun \n");
 								}
 							}
 						}

+ 8 - 2
EVSE/Projects/AW-CCS/Apps/Module_AlarmDetect.h

@@ -1,13 +1,19 @@
 /*
  * Module_AlarmDetect.h
  *
- *  Created on: 2020¦~01¤ë15¤é
+ *  Created on: 2020/01/15
  *      Author: Eason Yang
  */
 
 #ifndef MODULE_ALARMDETECT_H_
 #define MODULE_ALARMDETECT_H_
 
-
+enum ALARM_TIMER_IDX
+{
+	ALARM_TMR_IDX_OCP_L1=0,
+	ALARM_TMR_IDX_OCP_L2,
+	ALARM_TMR_IDX_OCP_L3,
+	ALARM_TMR_IDX_CNT
+};
 
 #endif /* MODULE_ALARMDETECT_H_ */