3 Commits ea61ec65f1 ... 46c500d3b2

Author SHA1 Message Date
  simon bischof 46c500d3b2 Merge branch 'update_Connect_routine' of http://git.ipe.kit.edu/sbischof/Master_BMS 7 years ago
  simon bischof bc1ccb3c5b Projekt stand nach letztem treffen 7 years ago
  simon bischof 17d7ace5e8 test 14.3 7 years ago

+ 15 - 0
BMS Master/Project_Headers/BMS_Connect_Inverter.h

@@ -0,0 +1,15 @@
+/*
+ * BMS_Connect_Inverter.h
+ *
+ *  Created on: Mar 15, 2017
+ *      Author: le8041
+ */
+
+#ifndef BMS_CONNECT_INVERTER_H_
+#define BMS_CONNECT_INVERTER_H_
+
+float get_Norm(float value);
+uint32_t check_if_voltage_equal(MASTER_CAN0_STRUCT_t* s);
+uint32_t check_if_Ui_voltage_is_stable(MASTER_CAN0_STRUCT_t* s);
+
+#endif /* BMS_CONNECT_INVERTER_H_ */

+ 33 - 19
BMS Master/Project_Headers/BMS_Defines.h

@@ -135,7 +135,7 @@
 #define CAN1_RX_BATTERY_VOLTAGE						0x97E3A6F2
 
 
-#define CAN1_NR_OF_REQUEST_TELEGRAMS				3
+#define CAN1_NR_OF_REQUEST_TELEGRAMS				4
 
 // ***** SLAVE OPERATION MODE
 #define BMS_SLAVE_STAND_BY				0x1
@@ -179,22 +179,25 @@
 #define BMS_ERROR_STACK_UI_OVER_VOLTAGE					0x10
 #define BMS_ERROR_STACK_UI_SUPPLY_VOLTAGE				0x20
 #define BMS_ERROR_STACK_UI_OFFSET_ERROR					0x40
-
-#define BMS_ERROR_STACK_MASTER_OK						0
-#define BMS_ERROR_STACK_MASTER_VCC_12V					0x001
-#define BMS_ERROR_STACK_MASTER_VCC_3V3					0x002
-#define BMS_ERROR_STACK_MASTER_UMIN_1					0x004
-#define BMS_ERROR_STACK_MASTER_UMIN_2					0x008
-#define BMS_ERROR_STACK_MASTER_UMIN_3					0x010
-#define BMS_ERROR_STACK_MASTER_UMAX_1					0x020
-#define BMS_ERROR_STACK_MASTER_UMAX_2					0x040
-#define BMS_ERROR_STACK_MASTER_UMAX_SYSTEM				0x080
-#define BMS_ERROR_STACK_MASTER_VOLTAGE_INCONSIT			0x100
-#define BMS_ERROR_STACK_MASTER_EXTERN_CAN_ERROR			0x200
-#define BMS_ERROR_STACK_MASTER_FLASH					0x400
-#define BMS_ERROR_STACK_MASTER_I_MAX_DISCHARGE_OP		0x800
-#define BMS_ERROR_STACK_MASTER_I_MAX_CHARGE_OP			0x1000
-#define BMS_ERROR_STACK_MASTER_UMAX_3					0x2000
+#define BMS_ERROR_STACK_UI_RELAY_OPEN					0x80
+
+#define BMS_ERROR_STACK_MASTER_OK								0
+#define BMS_ERROR_STACK_MASTER_VCC_12V							0x001
+#define BMS_ERROR_STACK_MASTER_VCC_3V3							0x002
+#define BMS_ERROR_STACK_MASTER_UMIN_1							0x004
+#define BMS_ERROR_STACK_MASTER_UMIN_2							0x008
+#define BMS_ERROR_STACK_MASTER_UMIN_3							0x010
+#define BMS_ERROR_STACK_MASTER_UMAX_1							0x020
+#define BMS_ERROR_STACK_MASTER_UMAX_2							0x040
+#define BMS_ERROR_STACK_MASTER_UMAX_SYSTEM						0x080
+#define BMS_ERROR_STACK_MASTER_VOLTAGE_INCONSIT					0x100
+#define BMS_ERROR_STACK_MASTER_EXTERN_CAN_ERROR					0x200
+#define BMS_ERROR_STACK_MASTER_FLASH							0x400
+#define BMS_ERROR_STACK_MASTER_I_MAX_DISCHARGE_OP				0x800
+#define BMS_ERROR_STACK_MASTER_I_MAX_CHARGE_OP					0x1000
+#define BMS_ERROR_STACK_MASTER_UMAX_3							0x2000
+#define BMS_ERROR_STACK_MASTER_INVERTER_CONNECT_SHORT_CIRCUIT	0x4000
+#define BMS_ERROR_STACK_MASTER_INVERTER_CONNECT_LS_STUCK		0x8000
 
 
 // BMS ERROR HANDLING
@@ -217,7 +220,8 @@
 #define BMS_ERROR_RESTORE_TIMEOUT				300000 // 5 Minutes for Inverter to clear Error
 
 #define BMS_SOC_LOW_MARK						0.1
-#define BMS_SOC_UMIN_1							3000
+#define BMS_SOC_UMIN_1_DERATE					3000
+#define BMS_SOC_UMIN_1							2975
 #define BMS_SOC_UMIN_2							2900
 #define BMS_SOC_UMIN_3 							2800
 #define BMS_SOC_UMAX_1							3500
@@ -236,6 +240,9 @@
 #define BMS_CAN_ID_INIT_RETURN_ERROR			2
 
 
+#define BMS_CONNECT_VOLTAGE_EQUAL_MARGIN				0.05	// 5% Voltage difference is ok
+
+#define BMS_CONNECT_VOLTAGE_TEST_MARGIN_MV				10000	// 10V  difference is ok
 
 
 
@@ -359,7 +366,14 @@
 #define PWR_SUPPLY						8	
 #define VBAT_RELAIS						7
 	
- 
+// **** Inverter Connect Constants ***
+
+#define UI_VOLTAGE_STABILITY_CHECK						20		// nr of voltages to be checked for stability (5 seconds)
+#define UI_VOLTAGE_STABILITY_MAX_DEVIATION				3		// 3V min max
+#define CONNECT_INVERTER_MIN_WAIT_TIME_MS				5000	// 5s minimum wartezeit
+#define CONNECT_INVERTER_MAX_WAIT_TIME_MS				10000	// 10s maximum waittime
+#define CONNECT_INVERTER_WAIT_FOR_HS_TO_CLOSE_MS		2000	// 2s for HS relay to be closed
+#define CONNECT_INVERTER_SHORT_CIRCUIT_TEST_VOLTAGE		100000.0  // 100000mV 
 
 // ***** Cell Errors ***********************************************************
 #define ERROR_MAX_CELL_VOLTAGE			0x0001

+ 3 - 0
BMS Master/Project_Headers/BMS_Master.h

@@ -108,6 +108,7 @@ extern CAN_MAILBOX CAN_Rx_RCT_INVERTER;
 	uint16_t CAN2_update( void );
 	uint32_t set_balancer_off(MASTER_CAN0_STRUCT_t* s) ;
 	uint32_t BMS_set_Error_check_if_stable_discharge(MASTER_CAN0_STRUCT_t* s); 
+	uint32_t BMS_set_Error_check_if_active_stable_discharge(MASTER_CAN0_STRUCT_t* s);
 	
 	
 	uint8_t check_UI_data(BMS_CAN0_SLAVE_t* Slave, BMS_CAN0_SLAVE_t* tempSlave,BMS_CAN0_UI_t* ui,BMS_CAN0_UI_t* tempUI);
@@ -192,6 +193,7 @@ extern CAN_MAILBOX CAN_Rx_RCT_INVERTER;
 	uint32_t BMS_Set_Error_check_System_voltage_level_max(MASTER_CAN0_STRUCT_t* s);
 	uint32_t BMS_Set_Error_check_Voltage_level_max(MASTER_CAN0_STRUCT_t* s) ;
 	uint32_t BMS_set_Error_check_if_stable_charge(MASTER_CAN0_STRUCT_t* s) ;
+
 	
 	uint32_t BMS_Set_Error_Check_derating(MASTER_CAN0_STRUCT_t* s);
 	uint32_t BMS_Clear_Error_State_Slave(MASTER_CAN0_STRUCT_t* s,BMS_ERROR_STATE_t* error_state);
@@ -222,6 +224,7 @@ extern CAN_MAILBOX CAN_Rx_RCT_INVERTER;
 	
 	uint32_t initSoCFifo(MASTER_CAN0_STRUCT_t* s); 
 	uint32_t pushSoCFiFo(MASTER_SOC_ESTIMATOR_t* est);
+	uint32_t BMS_Set_Error_UI_Relais(MASTER_CAN0_STRUCT_t* s) ;
 
 	
 

+ 2 - 1
BMS Master/Project_Headers/BMS_SoC_estimator.h

@@ -20,8 +20,9 @@ int32_t bms_SoC_init_estimator(MASTER_SOC_ESTIMATOR_t* cell_SoC, uint16_t voltag
 uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16_t U_batt_max,uint16_t U_batt_min, int8_t temp_min, int8_t temp_max);
 float bms_SoC_get_norm(float value);
 float bms_calc_charge_derating(float SoC);
+float bms_calc_discharge_Umin1(uint16_t Umin);
 float bms_calc_discharge_derating(float SoC);
-uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t maxTemp);
+uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t maxTemp, uint16_t Umin); 
 float bms_calc_charge_temp_derating(int8_t Temp) ;
 float bms_calc_discharge_temp_derating(int8_t Temp);
 float linear_interpolate(int8_t x1,int8_t x2,int8_t x,float y1,float y2);

+ 72 - 15
BMS Master/Project_Headers/BMS_Typedefs.h

@@ -538,8 +538,25 @@ typedef enum {
 typedef enum{
 	OP_MODE_INIT=0,
 	OP_MODE_CHECK_STARTUP_CONDITIONS,
-	OP_MODE_SET_PRECHARGE_RELAY,
-	OP_MODE_SET_MAIN_RELAY,
+	BAT_CONNECT_CHECK_SHORTCIRCUIT_REQUEST_RELAY_TEST,
+	BAT_CONNECT_CHECK_SHORTCIRCUIT_NET_DISCONNECTED,
+	BAT_CONNECT_CHECK_SHORTCIRCUIT_CHECK_CLAMPS,
+	BAT_CONNECT_CHECK_IF_LS_STUCK,
+	BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN,
+	BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN_OK,
+	BAT_CONNECT_CHECK_IF_HS_STUCK,
+	BAT_CONNECT_TEST_COMPLETE,
+	BAT_CONNECT_READY_FOR_STARTUP,
+	BAT_CONNECT_CLOSE_LS,
+	BAT_CONNECT_CLOSE_PC,
+	BAT_CONNECT_WAIT_FOR_READY_TO_START_ACK,
+	BAT_CONNECT_WAIT_FOR_VOLTAGE_IS_EQUAL,
+	BAT_CONNECT_CHECK_IF_VOLTAGE_IS_STABLE,
+	BAT_CONNECT_CLOSE_HS,
+	BAT_CONNECT_OPEN_PC,
+	BAT_CONNECT_ERROR_SHORTCIRCUIT_DETECTED,
+	BAT_CONNECT_ERROR_LS_STUCK,
+	BAT_CONNECT_ERROR_HS_STUCK,
 	OP_MODE_NORMAL,
 	OP_MODE_SOC_LOW,
 	OP_MODE_ERROR
@@ -676,19 +693,7 @@ typedef enum  {
 	BMS_BALANCE_OFF
 }BMS_BALANCE_STATE_t;
 
-// fsm struct for running mode fsm
 
-typedef struct {
-	MASTER_RUNNING_MODE RunningMode;
-	MASTER_CAN0_OPERATION_MODE OperationMode;
-	uint64_t OperationModeTimestamp;
-	MASTER_CAN0_ES1_STATE ErrorState1fsm;
-	uint64_t ErrorState2Timestamp;
-	uint64_t ErrorState3Timestamp;
-	MASTER_CAN0_ES2_STATE ErrorState2fsm;
-	MASTER_CAN0_ES3_STATE ErrorState3fsm;
-	uint32_t onCounter; // counter for relay closed time
-}BMS_RUNNING_MODE_t;
 
 // connection status of cells
 
@@ -731,11 +736,57 @@ typedef struct {
 	uint8_t		byte7;
 }BMS_CAN1_INVERTER_BATTERY_STATUS_t;
 
+typedef struct {
+	uint32_t	valueId;
+	union {
+		uint32_t value;
+		struct{
+			uint16_t	reserved2;
+			uint8_t 	reserved1;
+			uint8_t reserved:5;
+			uint8_t readyToStart:1;
+			uint8_t requestRelayTest:1;
+			uint8_t batteryDisconnected:1;
+		};
+	};
+}BMS_CAN1_INVERTER_BATTERY_EXTRA_STATUS_t;
+
+typedef struct {
+	union{
+		uint32_t value;
+		struct {
+			uint8_t 	reserved1;
+			uint8_t		reserved2;
+			uint8_t		reserved3;	
+			uint8_t reserved:4;
+			uint8_t	batteryCalibration:1;
+			uint8_t readyToStart:1;
+			uint8_t	relayTestPermitted:1;
+			uint8_t batteryDisconnected:1;
+		};
+	};	
+}BMS_CAN1_RX_BATTERY_CONTROL_STATUS_t;
+
+// fsm struct for running mode fsm
+
+typedef struct {
+	MASTER_RUNNING_MODE RunningMode;
+	MASTER_CAN0_OPERATION_MODE OperationMode;
+	uint64_t OperationModeTimestamp;
+	BMS_CAN1_INVERTER_BATTERY_EXTRA_STATUS_t BatteryExtraStatus;
+	MASTER_CAN0_ES1_STATE ErrorState1fsm;
+	uint64_t ErrorState2Timestamp;
+	uint64_t ErrorState3Timestamp;
+	MASTER_CAN0_ES2_STATE ErrorState2fsm;
+	MASTER_CAN0_ES3_STATE ErrorState3fsm;
+	uint32_t onCounter; // counter for relay closed time
+}BMS_RUNNING_MODE_t;
+
 typedef struct {
 	union {
 		uint8_t Byte[14][8];
 		struct {
-			BMS_CAN1_INVERTER_INTEGER_32_t batteryModeExtra;
+			BMS_CAN1_INVERTER_BATTERY_EXTRA_STATUS_t batteryModeExtra;
 			BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeCurrent;
 			BMS_CAN1_INVERTER_FLOAT_t maxBatteryChargeVoltage;
 			BMS_CAN1_INVERTER_FLOAT_t maxBatteryDischargeCurrent;
@@ -825,6 +876,7 @@ typedef struct {
 	float expectedInputPower;
 	float batteryVoltage;
 	float batteryCurrent;
+	BMS_CAN1_RX_BATTERY_CONTROL_STATUS_t BatteryControlStatus;
 }BMS_CAN1_INVERTER_RX;
 
 typedef struct {
@@ -851,6 +903,9 @@ typedef struct {
 	float I_max_discharge_SoC	;
 	float I_max_charge_derate;
 	float I_max_discharge_derate; 
+	float test_SoC;
+	float I_max_discharge_SoC_test;
+	float test_SoC_actual;
 }MASTER_OVER_CURRENT_LIMITS_t;
 
 
@@ -1059,6 +1114,8 @@ typedef struct {
 	uint64_t timestamp;
 	uint64_t time;
 	uint64_t cycleTimestamp;
+	uint64_t test_timestamp;
+	uint8_t shutdown_initiated;
 	uint8_t transmission_pending;
 	uint8_t cycleCounter;
 	uint32_t systemVoltage;

+ 102 - 102
BMS Master/ReferencedRSESystems.xml

@@ -1,103 +1,103 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- This file stores a copy of all RSE Systems referenced by the project 
-so the systems can be automatically recreated when the project is imported in a new workspace. 
-This file is automatically generated and updated by the Eclipse IDE.-->
-<APSC_Memento>
-<host>
-<properties>
-<property key="hidden.applicator.com.freescale.debugger.applicator.launchconfiguration.lc.BMS Master FLASH.proj.BMS Master" value="com.freescale.debugger.applicator.launchconfiguration.lc.BMS Master FLASH.proj.BMS Master"/>
-<property key="host.address" value=""/>
-<property key="host.defaultEncoding" value=""/>
-<property key="host.defaultUser" value="le8041"/>
-<property key="host.description" value=""/>
-<property key="host.name" value="Flash_debug"/>
-<property key="host.promptable" value="false"/>
-<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware"/>
-<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
-<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.CW_SHADOWED_PREF.Embedded Initialization.simulator" value=""/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.PhysicalConnectionAttributeBase" value="com.pemicro.mcu.debug.connections.pne.eppc."/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.SimulatorConnectionAttributeBase" value=""/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.CommandLineArgs" value="eppc_icd "/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.ConfigFile" value=""/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.Library" value="eppc_pne_gdi"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ALTERNATIVE_ALGORITHM_CHECKBOX" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ALTERNATIVE_ALGORITHM_PATH" value=""/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_AUTO_SYNC" value="1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_CURRENT_ALGORITHM_INDEX" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ENABLE_FLASH_PROGRAMMING_DIALOG" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ERASE_PROGRAM_WITHOUT_ASKING" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_PowerDownDelay" value="250"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_PowerUpDelay" value="250"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_currentvoltage" value="255"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_poweroffonexit" value="1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_CYCLONE" value="3"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_FX" value="4"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_NORMAL" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_OSJTAG" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_Multilink_PowerDownDelay" value="250"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_Multilink_PowerUpDelay" value="1000"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_PORT" value="21"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_PORT_NAME_STRING" value="PE5655057"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_RESET_DELAY" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_IP" value="127.0.0.1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_IP_ENABLED" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_NETWORKCARD" value="127.0.0.1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_NETWORKCARD_ENABLED" value="0"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_USE_CYCLONEPRO_RELAYS" value="1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_interface_selection" value="1"/>
-<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.UUID" value="5ceeed42-818d-4b19-a220-3600a3bfcb96"/>
-<property key="propertySet.[cw.dbg.conn].rseSystemId" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.140207081647+0100.1"/>
-<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryConnectionOn" value="false"/>
-<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryTimeout" value="20"/>
-<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryWithTimeoutOn" value="false"/>
-<property key="propertySet.[cw.dbg.ct.targetConnLost].TerminateConnectionOn" value="false"/>
-<property key="propertySet.[cw.dbg.ct.targetConnLost].retryPromptUserActionOn" value="true"/>
-<property key="propertySet.[cw.dbg.ct].Connection Type" value="com.pemicro.mcu.debug.connections.pne.eppc"/>
-<property key="propertySet.[cw.dbg.main].templateId" value="None"/>
-<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.170203142503+0100"/>
-<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1486128577361"/>
-</properties>
-</host>
-<host>
-<properties>
-<property key="host.address" value=""/>
-<property key="host.defaultEncoding" value=""/>
-<property key="host.defaultUser" value="mb0005"/>
-<property key="host.description" value=""/>
-<property key="host.name" value="Test_FLASH_PnE U-MultiLink Target"/>
-<property key="host.promptable" value="false"/>
-<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system"/>
-<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
-<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.initPath" value="${ProjDirPath}/Project_Settings/Debugger/MPC5646C_VLE.tcl"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.memConfigPath" value="${ProjDirPath}/Project_Settings/Debugger/MPC5646C.mem"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.runOutOfReset" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.useInitFile" value="true"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.useMemoryConfigFile" value="true"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.1.e200z0h.runOutOfReset" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.useInitFile" value="true"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.useMemoryConfigFile" value="true"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].enableHSSTIOModelConfig" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].enableNetworkIOModelConfig" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].enableSerialIOModelConfig" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].enableStopTransferIOModelConfig" value="true"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].ethernetController" value="UEC1"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].executeReset" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkDebuggerAddress" value="127.0.0.1"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkGateway" value="127.0.0.1"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkMACAddress" value="**-**-**-**-**-**"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkNetMask" value="255.255.255.255"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkTargetAddress" value="127.0.0.1"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].networkUDPPort" value="1234"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].noIOModelConfig" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].targetIsPalladium" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkGateway" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkMACAddress" value="false"/>
-<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkUDPPort" value="false"/>
-<property key="propertySet.[cw.dbg.main].systemType" value="com.freescale.cw.system.eppc.MPC56xxB.MPC5646C"/>
-<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.140207081647+0100.1"/>
-<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1391757409961"/>
-</properties>
-</host>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This file stores a copy of all RSE Systems referenced by the project 
+so the systems can be automatically recreated when the project is imported in a new workspace. 
+This file is automatically generated and updated by the Eclipse IDE.-->
+<APSC_Memento>
+<host>
+<properties>
+<property key="hidden.applicator.com.freescale.debugger.applicator.launchconfiguration.lc.BMS Master FLASH.proj.BMS Master" value="com.freescale.debugger.applicator.launchconfiguration.lc.BMS Master FLASH.proj.BMS Master"/>
+<property key="host.address" value=""/>
+<property key="host.defaultEncoding" value=""/>
+<property key="host.defaultUser" value="le8041"/>
+<property key="host.description" value=""/>
+<property key="host.name" value="Flash_debug"/>
+<property key="host.promptable" value="false"/>
+<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware"/>
+<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
+<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.CW_SHADOWED_PREF.Embedded Initialization.simulator" value=""/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.PhysicalConnectionAttributeBase" value="com.pemicro.mcu.debug.connections.pne.eppc."/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.freescale.cdt.debug.cw.core.settings.GdiConnection.Common.SimulatorConnectionAttributeBase" value=""/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.CommandLineArgs" value="eppc_icd "/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.ConfigFile" value=""/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.Library" value="eppc_pne_gdi"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ALTERNATIVE_ALGORITHM_CHECKBOX" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ALTERNATIVE_ALGORITHM_PATH" value=""/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_AUTO_SYNC" value="1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_CURRENT_ALGORITHM_INDEX" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ENABLE_FLASH_PROGRAMMING_DIALOG" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.PEDEBUG_ERASE_PROGRAM_WITHOUT_ASKING" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_PowerDownDelay" value="250"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_PowerUpDelay" value="250"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_currentvoltage" value="255"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_CyclonePro_poweroffonexit" value="1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_CYCLONE" value="3"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_FX" value="4"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_NORMAL" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_FREQ_OSJTAG" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_Multilink_PowerDownDelay" value="250"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_Multilink_PowerUpDelay" value="1000"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_PORT" value="21"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_PORT_NAME_STRING" value="PE5655057"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_RESET_DELAY" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_IP" value="127.0.0.1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_IP_ENABLED" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_NETWORKCARD" value="127.0.0.1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_SPECIFY_NETWORKCARD_ENABLED" value="0"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_USE_CYCLONEPRO_RELAYS" value="1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.STARTUP_interface_selection" value="1"/>
+<property key="propertySet.[com.pemicro.mcu.debug.connections.pne.eppc].com.pemicro.mcu.debug.connections.pne.eppc.UUID" value="5ceeed42-818d-4b19-a220-3600a3bfcb96"/>
+<property key="propertySet.[cw.dbg.conn].rseSystemId" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.140207081647+0100.1"/>
+<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryConnectionOn" value="false"/>
+<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryTimeout" value="20"/>
+<property key="propertySet.[cw.dbg.ct.targetConnLost].RetryWithTimeoutOn" value="false"/>
+<property key="propertySet.[cw.dbg.ct.targetConnLost].TerminateConnectionOn" value="false"/>
+<property key="propertySet.[cw.dbg.ct.targetConnLost].retryPromptUserActionOn" value="true"/>
+<property key="propertySet.[cw.dbg.ct].Connection Type" value="com.pemicro.mcu.debug.connections.pne.eppc"/>
+<property key="propertySet.[cw.dbg.main].templateId" value="None"/>
+<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.170203142503+0100"/>
+<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1486128577361"/>
+</properties>
+</host>
+<host>
+<properties>
+<property key="host.address" value=""/>
+<property key="host.defaultEncoding" value=""/>
+<property key="host.defaultUser" value="mb0005"/>
+<property key="host.description" value=""/>
+<property key="host.name" value="Test_FLASH_PnE U-MultiLink Target"/>
+<property key="host.promptable" value="false"/>
+<property key="host.type" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system"/>
+<property key="propertySet.[OptionalPropertySet].enableConnectorServicesPropertyPage" value="false"/>
+<property key="propertySet.[OptionalPropertySet].enableGenericHostPropertyPage" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.initPath" value="${ProjDirPath}/Project_Settings/Debugger/MPC5646C_VLE.tcl"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.memConfigPath" value="${ProjDirPath}/Project_Settings/Debugger/MPC5646C.mem"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.runOutOfReset" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.useInitFile" value="true"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.0.e200z4.useMemoryConfigFile" value="true"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.1.e200z0h.runOutOfReset" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.useInitFile" value="true"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].com.freescale.cw.system.eppc.MPC56xxB.MPC5646C.useMemoryConfigFile" value="true"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].enableHSSTIOModelConfig" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].enableNetworkIOModelConfig" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].enableSerialIOModelConfig" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].enableStopTransferIOModelConfig" value="true"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].ethernetController" value="UEC1"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].executeReset" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkDebuggerAddress" value="127.0.0.1"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkGateway" value="127.0.0.1"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkMACAddress" value="**-**-**-**-**-**"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkNetMask" value="255.255.255.255"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkTargetAddress" value="127.0.0.1"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].networkUDPPort" value="1234"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].noIOModelConfig" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].targetIsPalladium" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkGateway" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkMACAddress" value="false"/>
+<property key="propertySet.[cw.dbg.ct.bareboard].useNetworkUDPPort" value="false"/>
+<property key="propertySet.[cw.dbg.main].systemType" value="com.freescale.cw.system.eppc.MPC56xxB.MPC5646C"/>
+<property key="propertySet.[cw.ide.settingscache].hidden.HostID" value="com.freescale.cdt.debug.cw.core.ui.rse.systemtype.bareboard.hardware.system.140207081647+0100.1"/>
+<property key="propertySet.[cw.ide.settingscache].hidden.TimeStamp" value="1391757409961"/>
+</properties>
+</host>
 </APSC_Memento>

+ 2 - 2
BMS Master/Sources/BMS_CAN0_Mail_Box.c

@@ -1046,8 +1046,8 @@ uint16_t saveSlaveUI_Master_telegram(BMS_CAN0_SLAVE_t* Slave,BMS_CAN0_UI_t* UI_B
 	UI_Board->Ubatt=(Master_Rx7_buff[1] << 8 )+ Master_Rx7_buff[2];
 	UI_Board->Ibatt=(Master_Rx7_buff[3] << 8 )+ Master_Rx7_buff[4];
 	UI_Board->Errors.OffsetError=(Master_Rx7_buff[5] & 0x01 );
-	UI_Board->Errors.SupplyError=(Master_Rx7_buff[5] & 0x02 );
-	UI_Board->Errors.RelayOpen=(Master_Rx7_buff[5] & 0x04 );
+	UI_Board->Errors.SupplyError=((Master_Rx7_buff[5] & 0x02 )>> 1);
+	UI_Board->Errors.RelayOpen=((Master_Rx7_buff[5] & 0x04 )>> 2);
 	UI_Board->Checksum=Master_Rx7_buff[7];	
 	return TRUE;
 }

+ 2 - 1
BMS Master/Sources/BMS_CAN1_Mail_Box.c

@@ -173,8 +173,9 @@ uint16_t CAN1_init_tx_structure(BMS_CAN1_INVERTER_TX* tx_struct) {
 	
 	tx_struct->Values.batteryModeExtra.valueId				=CAN1_TX_BATTERY_STATUS_EXTRA;
 	shuffle_lsb_msb_can1((uint8_t*)&(tx_struct->Values.batteryModeExtra.valueId));
-	tx_struct->Values.batteryModeExtra.value						=1;
+	tx_struct->Values.batteryModeExtra.value				=1;
 	shuffle_lsb_msb_can1((uint8_t*)&(tx_struct->Values.batteryModeExtra.value));
+	
 }
 
 

+ 42 - 42
BMS Master/Sources/BMS_Cell_Config.c

@@ -267,27 +267,27 @@ void initCellConfig(BMS_SLAVE_CONFIGURATION_t* cellConfig) {
 	cellConfig->tempSensConnectionState[0]=	TEMP_SENSOR_CONNECTED;
 	cellConfig->tempSensConnectionState[1]=	TEMP_SENSOR_CONNECTED;
 	cellConfig->tempSensConnectionState[2]=	TEMP_SENSOR_CONNECTED;
-	cellConfig->tempSensConnectionState[3]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[4]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[5]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[6]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[7]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[8]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[9]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[10]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[11]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[12]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[13]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[14]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[15]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[16]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[17]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[18]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[19]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[20]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[21]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[22]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[23]=TEMP_SENSOR_NOT_CONNECTED;
+	cellConfig->tempSensConnectionState[3]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[4]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[5]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[6]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[7]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[8]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[9]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[10]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[11]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[12]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[13]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[14]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[15]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[16]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[17]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[18]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[19]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[20]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[21]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[22]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[23]=TEMP_SENSOR_CONNECTED;
 	
 	// Slave 5
 	cellConfig++;
@@ -322,27 +322,27 @@ void initCellConfig(BMS_SLAVE_CONFIGURATION_t* cellConfig) {
 	cellConfig->tempSensConnectionState[0]=	TEMP_SENSOR_CONNECTED;
 	cellConfig->tempSensConnectionState[1]=	TEMP_SENSOR_CONNECTED;
 	cellConfig->tempSensConnectionState[2]=	TEMP_SENSOR_CONNECTED;
-	cellConfig->tempSensConnectionState[3]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[4]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[5]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[6]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[7]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[8]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[9]=	TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[10]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[11]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[12]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[13]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[14]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[15]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[16]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[17]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[18]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[19]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[20]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[21]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[22]=TEMP_SENSOR_NOT_CONNECTED;
-	cellConfig->tempSensConnectionState[23]=TEMP_SENSOR_NOT_CONNECTED;
+	cellConfig->tempSensConnectionState[3]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[4]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[5]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[6]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[7]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[8]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[9]=	TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[10]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[11]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[12]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[13]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[14]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[15]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[16]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[17]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[18]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[19]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[20]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[21]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[22]=TEMP_SENSOR_CONNECTED;
+	cellConfig->tempSensConnectionState[23]=TEMP_SENSOR_CONNECTED;
 	
 	// Slave 6
 	cellConfig++;

+ 458 - 0
BMS Master/Sources/BMS_Connect_Inverter.c

@@ -0,0 +1,458 @@
+/*
+ * BMS_Connect_Inverter.c
+ *
+ *  Created on: Mar 14, 2017
+ *      Author: le8041
+ */
+
+#include "BMS_Master.h"
+#include "BMS_Connect_Inverter.h"
+
+float get_Norm(float value) {
+	if(value >=0) {
+		return value;
+	}
+	else {
+		return (-1)*value;
+	}	
+}
+
+uint32_t check_if_voltage_equal(MASTER_CAN0_STRUCT_t* s) {
+	float U_ui=(float)s->UI_Board.Ubatt *100 ;
+	float U_cells=(float)s->systemVoltage ;
+	
+	if(get_Norm(U_ui - U_cells) < U_cells *BMS_CONNECT_VOLTAGE_EQUAL_MARGIN) {
+		return TRUE;
+	}
+	else {
+		return FALSE;
+	}
+}
+
+uint32_t check_if_Ui_voltage_is_stable(MASTER_CAN0_STRUCT_t* s) {
+	// find highest and lowest UI-Voltage
+	uint8_t i=0;
+	uint32_t Umin=s->UI_Board.UbattFiFo[0];
+	uint32_t Umax=s->UI_Board.UbattFiFo[0];
+	
+	for(i=0;i<UI_VOLTAGE_STABILITY_CHECK;i++) {
+		if(Umin > s->UI_Board.UbattFiFo[i] ) {
+			Umin = s->UI_Board.UbattFiFo[i];
+		}
+		if(Umax < s->UI_Board.UbattFiFo[i]) {
+			Umax = s->UI_Board.UbattFiFo[i];
+		}
+	}
+	if ((Umax - Umin) *100 > UI_VOLTAGE_STABILITY_MAX_DEVIATION*1000) {
+		// max deviation reached
+		return FALSE;
+	}
+	else {
+		return TRUE;
+	}
+}
+
+/*
+ * @brief check if expected voltage is at clamps
+ * if return = FALSE shortcircuit at clamps
+ */
+
+uint32_t check_if_expected_clamp_voltage_occures(MASTER_CAN0_STRUCT_t* s) {
+	float U_ui=(float)s->UI_Board.Ubatt *100 ;
+	if(get_Norm(U_ui - CONNECT_INVERTER_SHORT_CIRCUIT_TEST_VOLTAGE) < CONNECT_INVERTER_SHORT_CIRCUIT_TEST_VOLTAGE *BMS_CONNECT_VOLTAGE_TEST_MARGIN_MV) {
+		return TRUE;
+	}
+	else {
+		return FALSE;
+	}
+}
+
+
+uint32_t OPModeFSM(MASTER_CAN0_STRUCT_t* s){
+	float SoC=s->SoC_estimator.SoC_percentage_smooth;
+	// check if Inverster still allows startup
+	if(s->inverter.rxStruct.BatteryControlStatus.batteryDisconnected == 1 && \
+			s->inverter.rxStruct.BatteryControlStatus.relayTestPermitted==0 && \
+			s->inverter.rxStruct.BatteryControlStatus.readyToStart ==0) {
+		if(s->RunMode.OperationMode == OP_MODE_INIT ||\
+				s->RunMode.OperationMode ==	OP_MODE_CHECK_STARTUP_CONDITIONS || \
+				s->RunMode.OperationMode == BAT_CONNECT_CHECK_SHORTCIRCUIT_REQUEST_RELAY_TEST) {	
+		}
+		else {
+			// FSM  not in first 3 states => go back to initial state
+			s->RunMode.OperationMode = OP_MODE_INIT;
+			// open all relays
+			SwitchRelais( HS_RELAIS, 0);
+			s->relayState.HS_closed=FALSE;
+			SwitchRelais( LS_RELAIS, 0);
+			s->relayState.LS_closed=FALSE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			s->relayState.PRECHARGE_closed=FALSE;	
+		}
+	}
+		
+	
+	switch(s->RunMode.OperationMode) {
+		case OP_MODE_INIT:
+			// just jump to checkup startup conditions
+			s->RunMode.OperationMode=OP_MODE_CHECK_STARTUP_CONDITIONS;
+			s->RunMode.BatteryExtraStatus.value=1;
+			CLEAR_OUTPIN(PIN_REGNR_LED4);
+			return TRUE;
+		break;
+		case OP_MODE_CHECK_STARTUP_CONDITIONS:
+			if(s->allValuesInitialized==TRUE) {
+				// all values initalized and no error occured
+				// => Startup conditions apply => start startup
+				
+				// check if all relays are open
+				if(s->relayState.HS_closed==FALSE && s->relayState.LS_closed == FALSE && s->relayState.PRECHARGE_closed ==FALSE) {
+					// everything ok oll relay open
+				}
+				else{
+					// relays somehow closed open relays
+					SwitchRelais( HS_RELAIS, 0);
+					s->relayState.HS_closed=FALSE;
+					SwitchRelais( LS_RELAIS, 0);
+					s->relayState.LS_closed=FALSE;
+					SwitchRelais( PRE_CHARGE_RELAIS, 0);
+					s->relayState.PRECHARGE_closed=FALSE;
+				}
+				
+				// set battery status
+				s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+				s->RunMode.BatteryExtraStatus.readyToStart=0;
+				s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+				
+				s->RunMode.OperationModeTimestamp=Global_1msCounter;
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_SHORTCIRCUIT_REQUEST_RELAY_TEST;
+				s->RunMode.onCounter=0;
+				return TRUE;
+			}
+			else {
+				// wait till all values are initialiezd
+				s->RunMode.OperationMode=OP_MODE_CHECK_STARTUP_CONDITIONS;
+				return TRUE;
+			}
+		break;
+		case BAT_CONNECT_CHECK_SHORTCIRCUIT_REQUEST_RELAY_TEST:
+			// set battery status - request relay test by inverter
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+			s->RunMode.BatteryExtraStatus.readyToStart=0;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=1;
+			if(s->inverter.rxStruct.BatteryControlStatus.relayTestPermitted == TRUE) {
+				// relay tests are enabled for inverter side
+				// inverter does its own relais tests
+				// inverter sets Voltage at clamps to 100V
+				// inverter disconnects from grid - Power from PV
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_SHORTCIRCUIT_NET_DISCONNECTED;
+				return TRUE;
+			}
+			else {
+				// wait for relay test permmited flag from inverter
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_SHORTCIRCUIT_REQUEST_RELAY_TEST;
+				return TRUE;
+			}
+			
+			return TRUE;
+		break;
+		case BAT_CONNECT_CHECK_SHORTCIRCUIT_NET_DISCONNECTED:
+			// grid is now disconnected
+			s->RunMode.OperationMode=BAT_CONNECT_CHECK_SHORTCIRCUIT_CHECK_CLAMPS;
+			return TRUE;
+		break;	
+		case BAT_CONNECT_CHECK_SHORTCIRCUIT_CHECK_CLAMPS:
+			if(check_if_expected_clamp_voltage_occures(s) == FALSE) {
+				// voltage is not as expected, therefore shorcircuit exitsts
+				// DONT TURN ON BATTERY
+				s->RunMode.OperationMode=BAT_CONNECT_ERROR_SHORTCIRCUIT_DETECTED;
+				return TRUE;
+			}
+			else {
+				// everything ok,proceed
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_LS_STUCK;
+				s->RunMode.OperationModeTimestamp=Global_1msCounter;
+				return TRUE;
+			}
+			return TRUE;
+		break;	
+		case BAT_CONNECT_CHECK_IF_LS_STUCK:
+			// close PC RELAIS
+			// IF PC Relays is closed and LS relay is stuck closed Battery voltage should be detectet
+			SwitchRelais( PRE_CHARGE_RELAIS, 1);
+			s->relayState.PRECHARGE_closed=TRUE;
+			if(s->RunMode.OperationModeTimestamp + CONNECT_INVERTER_MIN_WAIT_TIME_MS <= Global_1msCounter) {
+				// everything ok, proceed
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN;
+				return TRUE;
+			}
+			else if(check_if_voltage_equal(s)) {
+				// Battery voltage == clamp voltage => LS is stuck close: ERROR
+				s->RunMode.OperationMode=BAT_CONNECT_ERROR_LS_STUCK;
+				return TRUE;
+			}
+			else {
+				//wait
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_LS_STUCK;
+				return TRUE;
+			}
+			
+			return TRUE;
+		break;
+		case BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN:
+			// close LS and PRECHARGE
+			// expected current dependend on Battery voltage, therefore not clear yet
+			// skip
+			SwitchRelais( LS_RELAIS, 1);
+			s->relayState.LS_closed=TRUE;
+			
+			s->RunMode.OperationModeTimestamp=Global_1msCounter;
+			s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN_OK;
+			return TRUE;
+		break;
+		case BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN_OK:
+			// open PC RELAIS AGAIN
+			
+			SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			s->relayState.PRECHARGE_closed=FALSE;
+			
+			if(s->RunMode.OperationModeTimestamp + 1000 <= Global_1msCounter) {
+				// wait for LS to be open everything ok, proceed
+				s->RunMode.OperationModeTimestamp=Global_1msCounter;
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_HS_STUCK;
+				return TRUE;
+			}
+			else {
+				//wait
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_LS_OR_PC_BROKEN_OK;
+			}
+			
+			return TRUE;
+		break;
+		case BAT_CONNECT_CHECK_IF_HS_STUCK:
+			// check if 100V is at clamps again
+			if(check_if_expected_clamp_voltage_occures(s)) {
+				// everything ok
+				s->RunMode.OperationMode=BAT_CONNECT_TEST_COMPLETE;
+				s->RunMode.OperationModeTimestamp=Global_1msCounter;
+				return TRUE;
+			}
+			else if(s->RunMode.OperationModeTimestamp + CONNECT_INVERTER_MAX_WAIT_TIME_MS <= Global_1msCounter) {
+				// timeout, error occured, HS relays is stuck
+				s->RunMode.OperationMode=BAT_CONNECT_ERROR_HS_STUCK;
+				return TRUE;
+			}
+			else {
+				//wait
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_HS_STUCK;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_TEST_COMPLETE:
+			// all tests are complete
+			// close PC AND LS
+			SwitchRelais( HS_RELAIS, 0);
+			s->relayState.HS_closed=FALSE;
+			SwitchRelais( LS_RELAIS, 1);
+			s->relayState.LS_closed=TRUE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 1);
+			s->relayState.PRECHARGE_closed=TRUE;
+			
+			//disable relays test mode
+			
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+			s->RunMode.BatteryExtraStatus.readyToStart=1;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+			
+			// wait for relays to open
+			
+			if(s->RunMode.OperationModeTimestamp + 1000 <= Global_1msCounter) {
+				s->RunMode.OperationMode=BAT_CONNECT_WAIT_FOR_READY_TO_START_ACK;
+				return TRUE;
+			}
+			else {
+				//wait
+				s->RunMode.OperationMode=BAT_CONNECT_TEST_COMPLETE;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_CLOSE_LS:
+			// set Low Side relays unnecessary state because ls already closed
+			s->relayState.LS_closed=TRUE;
+			SwitchRelais( LS_RELAIS, 1);
+					
+			if(s->RunMode.OperationModeTimestamp + 1000 <= Global_1msCounter) {
+				s->RunMode.OperationMode=BAT_CONNECT_CLOSE_PC;
+				s->RunMode.OperationModeTimestamp = Global_1msCounter;
+				return TRUE;
+			}
+			else {
+				s->RunMode.OperationMode= BAT_CONNECT_CLOSE_LS;
+				return TRUE;
+			}
+		break;
+		case BAT_CONNECT_CLOSE_PC:
+			// close precharge relays
+			s->relayState.PRECHARGE_closed=TRUE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 1);
+			
+			if(s->RunMode.OperationModeTimestamp + 1000 <= Global_1msCounter) {
+				s->RunMode.OperationMode=BAT_CONNECT_WAIT_FOR_READY_TO_START_ACK;
+				s->RunMode.OperationModeTimestamp = Global_1msCounter;
+				return TRUE;
+			}
+			else {
+				s->RunMode.OperationMode= BAT_CONNECT_CLOSE_PC;
+				return TRUE;
+			}			
+			return TRUE;
+		break;
+		case BAT_CONNECT_WAIT_FOR_READY_TO_START_ACK:
+			//set ready to start bit
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+			s->RunMode.BatteryExtraStatus.readyToStart=1;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+			// wait till inverter has connected
+			if(s->inverter.rxStruct.BatteryControlStatus.readyToStart ==TRUE) {
+				s->RunMode.OperationMode=BAT_CONNECT_WAIT_FOR_VOLTAGE_IS_EQUAL;
+				return TRUE;
+			}
+			else {
+				//wait;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_WAIT_FOR_VOLTAGE_IS_EQUAL:
+			if(check_if_voltage_equal(s)== TRUE) {
+				// go to voltage stability check
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_VOLTAGE_IS_STABLE;
+				s->RunMode.OperationModeTimestamp = Global_1msCounter;
+				return TRUE;
+			}
+			else {
+				// wait for voltage to equalize
+				s->RunMode.OperationMode=BAT_CONNECT_WAIT_FOR_VOLTAGE_IS_EQUAL;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_CHECK_IF_VOLTAGE_IS_STABLE:
+			if(check_if_voltage_equal(s)== FALSE) {
+				// return to BAT_CONNECT_CLOSE_PC and try again
+				s->RunMode.OperationMode= BAT_CONNECT_CLOSE_PC;
+				return TRUE;		
+			}
+			
+			else if((s->RunMode.OperationModeTimestamp + CONNECT_INVERTER_MIN_WAIT_TIME_MS > Global_1msCounter) && check_if_Ui_voltage_is_stable(s)) {
+				// Voltages are equal Highside relays can be closed
+				s->RunMode.OperationMode= BAT_CONNECT_CLOSE_HS;
+				s->RunMode.OperationModeTimestamp=Global_1msCounter;
+				return TRUE;
+			}
+			else if(s->RunMode.OperationModeTimestamp + CONNECT_INVERTER_MAX_WAIT_TIME_MS > Global_1msCounter) {
+				s->RunMode.OperationMode= BAT_CONNECT_WAIT_FOR_VOLTAGE_IS_EQUAL;
+				return TRUE;
+			}
+			else {
+				// just wait
+				s->RunMode.OperationMode=BAT_CONNECT_CHECK_IF_VOLTAGE_IS_STABLE;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_CLOSE_HS:
+			// Switch Highside relais
+			SwitchRelais( HS_RELAIS, 1);
+			s->relayState.HS_closed=TRUE;
+			if(s->RunMode.OperationModeTimestamp + CONNECT_INVERTER_WAIT_FOR_HS_TO_CLOSE_MS > Global_1msCounter) {
+				s->RunMode.OperationMode= BAT_CONNECT_OPEN_PC;
+				return TRUE;
+			}
+			else {
+				// do nothing
+				s->RunMode.OperationMode= BAT_CONNECT_CLOSE_HS;
+				return TRUE;
+			}
+			return TRUE;
+		break;
+		case BAT_CONNECT_OPEN_PC:
+			s->RunMode.OperationMode=OP_MODE_NORMAL;
+			s->relayState.PRECHARGE_closed=FALSE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 0);			
+			return TRUE;
+		break;
+		case OP_MODE_NORMAL:
+			// do nothing until SoC becomes low
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 0;
+			s->RunMode.BatteryExtraStatus.readyToStart=0;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+			s->RunMode.onCounter++;
+			if ( SoC < BMS_SOC_LOW_MARK) {
+				s->RunMode.OperationMode=OP_MODE_SOC_LOW;
+				return TRUE;
+			}
+			else {
+				s->RunMode.OperationMode=OP_MODE_NORMAL;
+				return TRUE;
+			}				
+			return TRUE;
+		break;
+		case OP_MODE_SOC_LOW:
+			s->RunMode.onCounter++;
+			// do nothing until SoC becomes high again
+			if ( SoC > BMS_SOC_LOW_MARK) {
+				s->RunMode.OperationMode=OP_MODE_NORMAL;
+				return TRUE;
+			}
+			else {
+				s->RunMode.OperationMode=OP_MODE_SOC_LOW;
+				return TRUE;
+			}	
+		break;	
+		
+		case BAT_CONNECT_ERROR_SHORTCIRCUIT_DETECTED:
+			// stay here and don't turn on anything
+			// just to be sure open everything
+			SwitchRelais( HS_RELAIS, 0);
+			s->relayState.HS_closed=FALSE;
+			SwitchRelais( LS_RELAIS, 0);
+			s->relayState.LS_closed=FALSE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			s->relayState.PRECHARGE_closed=FALSE;
+			ErrorStackPushMasterError(s,BMS_ERROR_STACK_MASTER_INVERTER_CONNECT_SHORT_CIRCUIT,BMS_ERROR_CLASS_3);
+			
+			// set battery status
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+			s->RunMode.BatteryExtraStatus.readyToStart=0;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+			s->RunMode.OperationMode=BAT_CONNECT_ERROR_SHORTCIRCUIT_DETECTED;
+			
+			return TRUE;
+		break;	
+		case BAT_CONNECT_ERROR_LS_STUCK:
+			// stay here and don't turn on anything
+			// just to be sure open everything
+			SwitchRelais( HS_RELAIS, 0);
+			s->relayState.HS_closed=FALSE;
+			SwitchRelais( LS_RELAIS, 0);
+			s->relayState.LS_closed=FALSE;
+			SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			s->relayState.PRECHARGE_closed=FALSE;
+			ErrorStackPushMasterError(s,BMS_ERROR_STACK_MASTER_INVERTER_CONNECT_LS_STUCK,BMS_ERROR_CLASS_3);
+			
+			// set battery status
+			s->RunMode.BatteryExtraStatus.batteryDisconnected = 1;
+			s->RunMode.BatteryExtraStatus.readyToStart=0;
+			s->RunMode.BatteryExtraStatus.requestRelayTest=0;
+			return TRUE;
+		break;	
+		default:
+			// something went horribly wrong
+			return FALSE;
+		break;
+	}
+	
+}

+ 46 - 89
BMS Master/Sources/BMS_Master.c

@@ -200,6 +200,7 @@ uint16_t init_master_CAN0_fsm(MASTER_CAN0_STRUCT_t* s,BMS_SLAVE_CONFIGURATION_t*
 	s->RunMode.ErrorState1fsm=ES1_FSM_INIT;
 	s->RunMode.ErrorState2fsm=ES2_FSM_INIT;
 	s->RunMode.ErrorState3fsm=ES3_FSM_INIT;
+	s->RunMode.BatteryExtraStatus.value=1;
 	// init master temp sensor
 	s->masterTemp=18;
 	s->MasterTempSensState=BMS_MASTER_TEMP_SENSOR_INITIATE_MEASUREMENT;
@@ -221,6 +222,13 @@ uint16_t init_master_CAN0_fsm(MASTER_CAN0_STRUCT_t* s,BMS_SLAVE_CONFIGURATION_t*
 	s->relayState.reseved=0;
 	
 	s->reset_test_timestamp=0;
+	s->test_timestamp=0;
+	s->shutdown_initiated=0;
+	
+	// set battery status
+
+	s->RunMode.BatteryExtraStatus.batteryDisconnected=1;
+	s->RunMode.BatteryExtraStatus.reserved2=0;
 
 	BMS_RCT_init_fsm(s);
 	initUIFifo(s);
@@ -416,6 +424,7 @@ uint8_t check_UI_data(BMS_CAN0_SLAVE_t* Slave, BMS_CAN0_SLAVE_t* tempSlave,BMS_C
 	
 	ui->Ubatt=tempUI->Ubatt;
 	ui->Ibatt=tempUI->Ibatt;
+	ui->Errors=tempUI->Errors;
 	ui->Checksum=tempUI->Checksum;
 	return BMS_SLAVE_DATA_OK;
 }
@@ -675,14 +684,12 @@ void refresh_inverter_tx_data(MASTER_CAN0_STRUCT_t* s) {
 	inv->Values.minBatteryDischargeVoltage.value=s->startupConfig.minBatteryVoltage;
 	shuffle_lsb_msb_can1((uint8_t*)&(inv->Values.minBatteryDischargeVoltage.value));
 	
-	if(s->relayState.HS_closed == TRUE && s->relayState.LS_closed == TRUE && s->relayState.PRECHARGE_closed == TRUE) {
-		inv->Values.batteryModeExtra.value = 0;
-		
-	}
-	else {
-		inv->Values.batteryModeExtra.value = 1;
-		shuffle_lsb_msb_can1((uint8_t*)&(inv->Values.batteryModeExtra.value));
+	if(!(s->relayState.HS_closed == TRUE && s->relayState.LS_closed == TRUE && s->relayState.PRECHARGE_closed ==FALSE)) {
+		s->RunMode.BatteryExtraStatus.batteryDisconnected=1; // Battery is disconnected
 	}
+	inv->Values.batteryModeExtra.value = s->RunMode.BatteryExtraStatus.value;
+	shuffle_lsb_msb_can1((uint8_t*)&(inv->Values.batteryModeExtra.value));
+
 	//inv->Values.batteryMode.value=(uint32_t)(s->RunMode);
 	//shuffle_lsb_msb_can1((uint8_t*)&(inv->Values.batteryMode.value));
 }
@@ -942,6 +949,9 @@ uint16_t Master_CAN0_fsm(MASTER_CAN0_STRUCT_t* s,uint64_t time) {
 				
 
 				
+				if(s->UI_Board.Errors.RelayOpen==TRUE) {
+					BMS_Set_Error_UI_Relais(s) ;
+				}
 				// Check for "Soft" Errors and set Error states
 				
 
@@ -1485,11 +1495,12 @@ uint32_t Master_CAN1_Inverter_fsm(MASTER_CAN0_STRUCT_t* s,MASTER_CAN1_INVERTER_S
 				return TRUE;						
 			}
 			else if(fsmStruct->requestTelegramNr==3) {
-				CAN1_send_request_telegram(CAN1_RX_DC_INPUT_A_POWER);
+				CAN1_send_request_telegram(CAN1_RX_BATTERY_CONTROL_STATUS);
 				fsmStruct->fsmState= CAN1_FSM_WAIT_FOR_RESPONSE;
 				return TRUE;						
 			}
 			else if(fsmStruct->requestTelegramNr==4) {
+				// not enabled
 				CAN1_send_request_telegram(CAN1_RX_DC_INPUT_B_POWER);
 				fsmStruct->fsmState= CAN1_FSM_WAIT_FOR_RESPONSE;
 				return TRUE;						
@@ -1512,8 +1523,7 @@ uint32_t Master_CAN1_Inverter_fsm(MASTER_CAN0_STRUCT_t* s,MASTER_CAN1_INVERTER_S
 				rx_ptr=&(s->inverter.rxStruct.DCinputB_power);
 			}
 			else if(fsmStruct->requestTelegramNr==3)  {
-				// not valid anymore
-				rx_ptr=&(s->inverter.rxStruct.DCinputA_power);
+				rx_ptr=(float*)&((s->inverter.rxStruct.BatteryControlStatus.value));
 			}
 			else {
 				// not valid anymore
@@ -1695,6 +1705,29 @@ uint8_t get_nr_of_connected_slaves(MASTER_CAN0_STRUCT_t* s){
 }
 
 uint32_t RunningModeFSM(MASTER_CAN0_STRUCT_t* s){
+	
+	// debugging stuff
+	/*
+	if(BMS_set_Error_check_if_active_stable_discharge(s) && s->shutdown_initiated== 0 ) {
+		s->test_timestamp=Global_1msCounter ;
+		s->shutdown_initiated = 1;
+	}
+	if(s->shutdown_initiated == 1 && s->test_timestamp+20000 < Global_1msCounter) {
+		
+		SwitchRelais( LS_RELAIS, 0);
+	SwitchRelais( PRE_CHARGE_RELAIS, 0);
+		SwitchRelais( HS_RELAIS, 0);
+
+	}
+	
+	if(s->shutdown_initiated == 1 && s->test_timestamp+25000 < Global_1msCounter) {
+		
+		SwitchRelais( LS_RELAIS, 0);
+	SwitchRelais( PRE_CHARGE_RELAIS, 0);
+		SwitchRelais( HS_RELAIS, 0);
+
+	}
+	*/
 
 	
 	// check for active Error States
@@ -1722,85 +1755,7 @@ uint32_t RunningModeFSM(MASTER_CAN0_STRUCT_t* s){
 
 }
 
-uint32_t OPModeFSM(MASTER_CAN0_STRUCT_t* s){
-	float SoC=s->SoC_estimator.SoC_percentage_smooth;
-	switch(s->RunMode.OperationMode) {
-		case OP_MODE_INIT:
-			// just jump to checkup startup conditions
-			s->RunMode.OperationMode=OP_MODE_CHECK_STARTUP_CONDITIONS;
-			
-			CLEAR_OUTPIN(PIN_REGNR_LED4);
-			return TRUE;
-		break;
-		case OP_MODE_CHECK_STARTUP_CONDITIONS:
-			if(s->allValuesInitialized==TRUE) {
-				// all values initalized and no error occured
-				// => Startup conditions apply => start startup
-				s->RunMode.OperationModeTimestamp=Global_1msCounter;
-				s->RunMode.OperationMode=OP_MODE_SET_PRECHARGE_RELAY;
-				s->RunMode.onCounter=0;
-				return TRUE;
-			}
-			else {
-				// wait till all values are initialiezd
-				s->RunMode.OperationMode=OP_MODE_CHECK_STARTUP_CONDITIONS;
-				return TRUE;
-			}
-		break;
-		case OP_MODE_SET_PRECHARGE_RELAY:
-			// set Low Side and Precharge Relais
-			s->relayState.LS_closed=TRUE;
-			s->relayState.PRECHARGE_closed=TRUE;
-			SwitchRelais( LS_RELAIS, 1);
-			SwitchRelais( PRE_CHARGE_RELAIS, 1);			
-			if(s->RunMode.OperationModeTimestamp + 3000 <= Global_1msCounter) {
-				s->RunMode.OperationMode=OP_MODE_SET_MAIN_RELAY;
-				return TRUE;
-			}
-			else {
-				s->RunMode.OperationMode= OP_MODE_SET_PRECHARGE_RELAY;
-				return TRUE;
-			}
-		break;
-		case OP_MODE_SET_MAIN_RELAY:
-			// Switch Highside relais
-			SwitchRelais( HS_RELAIS, 1);
-			s->relayState.HS_closed=TRUE;
-			s->RunMode.OperationMode=OP_MODE_NORMAL;
-			return TRUE;
-		break;
-		case OP_MODE_NORMAL:
-			// do nothing until SoC becomes low
-			s->RunMode.onCounter++;
-			if ( SoC < BMS_SOC_LOW_MARK) {
-				s->RunMode.OperationMode=OP_MODE_SOC_LOW;
-				return TRUE;
-			}
-			else {
-				s->RunMode.OperationMode=OP_MODE_NORMAL;
-				return TRUE;
-			}				
-			return TRUE;
-		break;
-		case OP_MODE_SOC_LOW:
-			s->RunMode.onCounter++;
-			// do nothing until SoC becomes high again
-			if ( SoC > BMS_SOC_LOW_MARK) {
-				s->RunMode.OperationMode=OP_MODE_NORMAL;
-				return TRUE;
-			}
-			else {
-				s->RunMode.OperationMode=OP_MODE_SOC_LOW;
-				return TRUE;
-			}	
-		break;	
-		default:
-			// something went horribly wrong
-			return FALSE;
-		break;
-	}
-	
-}
+
 /*
  * @brief Statemachine which handles Class 1 Errors
  */
@@ -2028,4 +1983,6 @@ uint32_t pushInverterCurrentFIFO(MASTER_CAN0_STRUCT_t* s) {
 }
 
 
+
+
 // *** End BMS_Master.c ******************************************************

+ 48 - 3
BMS Master/Sources/BMS_Set_Error_States.c

@@ -30,6 +30,30 @@ uint32_t BMS_set_Error_check_if_stable_discharge(MASTER_CAN0_STRUCT_t* s) {
 	//stable discharge
 	return FALSE;
 	
+}
+
+/*
+ * @brief check if Battery is charged or discharged
+ * return true if discharged false if charged
+ */
+uint32_t BMS_set_Error_check_if_active_stable_discharge(MASTER_CAN0_STRUCT_t* s) {
+	// stable when mean value is bigger than -150mA
+	uint8_t i;
+	float Current=0;
+	for(i=0;i<UI_CURRENT_FIFO_SIZE;i++) {
+		Current=Current + s->UI_Board.IbattFiFo[i] ;
+	}
+	
+	Current = (Current*10) /UI_CURRENT_FIFO_SIZE ;
+	
+	if(Current > 150) {
+		// stable discharge
+		return TRUE;
+	}
+	
+	//stable discharge
+	return FALSE;
+	
 }
 /*
  * @brief ceck if battery is charged stable over given amount of samples
@@ -48,6 +72,8 @@ uint32_t BMS_set_Error_check_if_stable_charge(MASTER_CAN0_STRUCT_t* s) {
 	return TRUE;
 	
 }
+
+
 /*
  * @brief check voltage levels Umin1 Umin2 Umin3 and set Error states accordingly
  * return True if everything is of return false if error occured
@@ -241,10 +267,14 @@ uint32_t BMS_Set_Error_Check_derating(MASTER_CAN0_STRUCT_t* s) {
 	s->currentLimits.I_max_charge_temp_min = BMS_Set_Error_generate_Fcn(temp_charge_x,temp_charge_y,5,minTemp)*25*1000;
 	s->currentLimits.I_max_charge_SoC      = BMS_Set_Error_generate_Fcn(SoC_charge_x,SoC_charge_y,5,SoC)*1000 *1.1 ;
 	
+	// at derating use most current SOC
 	s->currentLimits.I_max_discharge_temp_max 	= BMS_Set_Error_generate_Fcn(temp_discharge_x,temp_discharge_y,4,maxTemp)*25*1000;
 	s->currentLimits.I_max_discharge_temp_min 	= BMS_Set_Error_generate_Fcn(temp_discharge_x,temp_discharge_y,4,minTemp)*25*1000;
-	s->currentLimits.I_max_discharge_SoC		= BMS_Set_Error_generate_Fcn(SoC_discharge_x,SoC_discharge_y,5,SoC)*1000 *1.1 ;	
-
+	s->currentLimits.I_max_discharge_SoC		= BMS_Set_Error_generate_Fcn(SoC_discharge_x,SoC_discharge_y,5,s->SoC_estimator.SoC_percentage_smooth)*1000 *1.1 ;	
+	s->currentLimits.I_max_discharge_SoC_test=BMS_Set_Error_generate_Fcn(SoC_discharge_x,SoC_discharge_y,5,s->SoC_estimator.SoC_percentage_smooth)*1000 ;
+	s->currentLimits.test_SoC = SoC;
+	s->currentLimits.test_SoC_actual=s->SoC_estimator.SoC_percentage_smooth;
+	
 	if(Current < -100) {
 		// Battery is charged
 		
@@ -351,6 +381,21 @@ uint32_t BMS_Set_Error_Check_derating(MASTER_CAN0_STRUCT_t* s) {
 	return TRUE;
 }
 
+/*
+ * @brief check if UI has opend relays
+ */
+uint32_t BMS_Set_Error_UI_Relais(MASTER_CAN0_STRUCT_t* s) {
+	ErrorStackPushUiError(s,BMS_ERROR_STACK_UI_RELAY_OPEN,BMS_ERROR_CLASS_2);
+	// Kill Relays
+	SwitchRelais( LS_RELAIS, 0);
+	SwitchRelais( PRE_CHARGE_RELAIS, 0);
+	SwitchRelais( HS_RELAIS, 0);
+	s->relayState.HS_closed=FALSE;
+	s->relayState.LS_closed=FALSE;
+	s->relayState.PRECHARGE_closed=FALSE;
+	
+	return TRUE;
+}
 uint32_t BMS_Set_Error_CAN1_Timeout(MASTER_CAN0_STRUCT_t* s) {
 	// CAN 1 Timeout Has occured
 	ErrorStackPushMasterError(s,BMS_ERROR_STACK_MASTER_EXTERN_CAN_ERROR,BMS_ERROR_CLASS_1);
@@ -427,7 +472,7 @@ uint32_t BMS_Set_Error_Check_voltage_inconsitency(MASTER_CAN0_STRUCT_t* s) {
 	
 	// if voltage error is bigger than threshold and All relais are closed kill relays
 	if((s->UiSlaveInconsistency > (addedCellVoltage_mean * 0.05) && s->RunMode.onCounter > (UI_VOLTAGE_FIFO_SIZE* CAN0_MAX_NR_OF_SLAVES)) &&
-			(s->relayState.HS_closed==TRUE &&		s->relayState.LS_closed==TRUE && s->relayState.PRECHARGE_closed==TRUE && s->UI_Board.Errors.RelayOpen == FALSE) ){
+			(s->relayState.HS_closed==TRUE &&		s->relayState.LS_closed==TRUE && s->relayState.PRECHARGE_closed==FALSE && s->UI_Board.Errors.RelayOpen == FALSE) ){
 		ErrorStackPushUiError(s,BMS_ERROR_STACK_UI_VOLTAGE_INCONSIST,BMS_ERROR_CLASS_1);
 		// Kill Relays
 		SwitchRelais( LS_RELAIS, 0);

+ 25 - 4
BMS Master/Sources/BMS_SoC_estimator.c

@@ -269,6 +269,7 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 			// set Flag to prevent SOC from falling in case of relaxation
 			est->flags=BMS_SOC_FLAG_SOC_100;
 			est->state=BMS_SOC_READY;
+			pushSoCFiFo(est); 
 			return 0;
 		break;
 		case BMS_SOC_CHARGE_WAIT_FOR_RELAXATION:
@@ -316,6 +317,7 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 				est->ChargeSmoothFlags=0;
 				est->SoC_percentage_smooth=est->SoC_percentage ;
 				est->state=BMS_SOC_READY;  
+				pushSoCFiFo(est); 
 				return 0;							   ; 
 			}
 			else if(est->SoC_percentage > 0.99 && est->flags != BMS_SOC_FLAG_SOC_100) {
@@ -392,8 +394,9 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 		break;	
 		case BMS_SOC_CHARGE_DERATE:
 			// derate SoC depending on the SoC and temperature
-			bms_set_derating(est, temp_min, temp_max);
+			bms_set_derating(est, temp_min, temp_max,U_batt_min);
 			est->state=BMS_SOC_READY;
+			pushSoCFiFo(est); 
 			return 0;	
 		break;
 		case BMS_SOC_DISCHARGE:
@@ -508,7 +511,8 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 			if(est->flags == BMS_SOC_FLAG_SOC_0) {
 				est->ChargeSmoothFlags=0;
 				est->SoC_percentage_smooth=est->SoC_percentage ;
-				est->state=BMS_SOC_READY;  
+				est->state=BMS_SOC_READY;
+				pushSoCFiFo(est); 
 				return 0;							   ; 
 			}
 			else if(est->SoC_percentage <= 0.01 && est->flags != BMS_SOC_FLAG_SOC_0) {
@@ -585,13 +589,16 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 		break;			
 		case BMS_SOC_DISCHARGE_DERATE:
 			// derate SoC depending on the SoC and temperature
-			bms_set_derating(est, temp_min, temp_max);
+			bms_set_derating(est, temp_min, temp_max,U_batt_min);
 			est->state=BMS_SOC_READY; 
+			pushSoCFiFo(est); 
 			return 0;
 		break;
 		case BMS_SOC_REST:
 			// no charging or discharging => do nothing
+			bms_set_derating(est, temp_min, temp_max,U_batt_min);
 			est->state=BMS_SOC_READY;
+			pushSoCFiFo(est); 
 			return 0;
 		break;
 		case BMS_SOC_READY:
@@ -644,7 +651,7 @@ float bms_SoC_get_norm(float value) {
 /*
  * @brief set Derating
  */
-uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t maxTemp) {
+uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t maxTemp, uint16_t Umin) {
 	float derating_charge_temp_high;
 	float derating_charge_temp_low;
 	float derating_charge_SoC;
@@ -653,6 +660,7 @@ uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t ma
 	float derating_discharge_temp_high;
 	float derating_discharge_temp_low;
 	float derating_discharge_SoC;
+	float derating_discharge_Umin1;
 
 	// charging
 	derating_charge_SoC=bms_calc_charge_derating(est->SoC_percentage_smooth);
@@ -677,6 +685,7 @@ uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t ma
 	derating_discharge_SoC= bms_calc_discharge_derating(est->SoC_percentage_smooth);
 	derating_discharge_temp_high = bms_calc_discharge_temp_derating(maxTemp);
 	derating_discharge_temp_low = bms_calc_discharge_temp_derating(minTemp);
+	derating_discharge_Umin1 = bms_calc_discharge_Umin1(Umin);
 	
 	// lowest current is choosen to be set as max charge current
 	
@@ -690,6 +699,9 @@ uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t ma
 	if(output_derate > derating_discharge_SoC ) {
 		output_derate = derating_discharge_SoC;
 	}
+	if(output_derate >= derating_discharge_Umin1) {
+		output_derate =derating_discharge_Umin1;
+	}
 	
 	est->MaxBatteryDischargeCurrent=output_derate;
 	
@@ -721,6 +733,15 @@ float bms_calc_charge_derating(float SoC) {
 	
 }
 
+float bms_calc_discharge_Umin1(uint16_t Umin) {
+	if(Umin < BMS_SOC_UMIN_1_DERATE) {
+		return 0.0;
+	}
+	else {
+		return 25.0;
+	}
+}
+
 float bms_calc_discharge_derating(float SoC) {
 	float delta_I=0;
 	float I_C_10=2.5;	// Current at C tens

+ 22 - 5
BMS Master/Sources/main.c

@@ -104,6 +104,7 @@ void main(void)
 	static BMS_UI_CONFIGURATION_t uiConfig;
 	static uint8_t fram_test[8] ={1,2,3,4,5,6,7,8};
 	static uint8_t fram_rx_text[8] ={0,0,0,0,0,0,0,0};
+	static uint8_t shutdown_initiated =0;
 	
 	
 	
@@ -164,7 +165,7 @@ void main(void)
 	while(BMS_Can_ID_init_fsm (&CAN0_fsm_state) == BMS_CAN_ID_INIT_RETURN_RUNNING ) {
 		// wait
 	}
-	write_fram_clear_startup_state(&CAN0_fsm_state); 
+	//write_fram_clear_startup_state(&CAN0_fsm_state); 
 	write_fram_clear_error_buffer(&CAN0_fsm_state); 
 	//write_fram_set_SoC(0.03); 
 	
@@ -183,13 +184,29 @@ void main(void)
 		
 		Master_CAN0_fsm(&CAN0_fsm_state,Global_1msCounter);
 		//Master_operation_fsm(&CAN0_fsm_state,Global_1msCounter,&operation_Fsm);
-		
+/*		
 		//Master_CAN1_fsm(&CAN0_fsm_state,&CAN1_fsm_state,Global_1msCounter);
-		//if(Global_1msCounter > 20000 + test_timestamp) {
-		//	SwitchRelais( PWR_SUPPLY, 1);
-		//}
+		if(BMS_set_Error_check_if_active_stable_discharge(&CAN0_fsm_state) && shutdown_initiated== 0 ) {
+			test_timestamp=Global_1msCounter ;
+			shutdown_initiated = 1;
+		}
+		if(shutdown_initiated == 1 && test_timestamp+20000 < Global_1msCounter) {
+			
+			SwitchRelais( LS_RELAIS, 0);
+		SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			SwitchRelais( HS_RELAIS, 0);
+
+		}
 		
+		if(shutdown_initiated == 1 && test_timestamp+25000 < Global_1msCounter) {
+			
+			SwitchRelais( LS_RELAIS, 0);
+		SwitchRelais( PRE_CHARGE_RELAIS, 0);
+			SwitchRelais( HS_RELAIS, 0);
 
+		}
+		
+*/
 		
 	}