Browse Source

test 14.3

simon bischof 7 years ago
parent
commit
17d7ace5e8

+ 2 - 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);

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

@@ -21,7 +21,8 @@ uint32_t bms_SoC_running_fsm(MASTER_SOC_ESTIMATOR_t* est, int16_t I_batt, uint16
 float bms_SoC_get_norm(float value);
 float bms_calc_charge_derating(float SoC);
 float bms_calc_discharge_derating(float SoC);
-uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t maxTemp);
+float bms_calc_discharge_Umin1(uint16_t Umin);
+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);

+ 2 - 0
BMS Master/Project_Headers/BMS_Typedefs.h

@@ -1059,6 +1059,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;

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

@@ -1041,13 +1041,14 @@ uint16_t saveSlaveX7_Master_telegram(BMS_CAN0_SLAVE_t* Slave){
 }
 
 uint16_t saveSlaveUI_Master_telegram(BMS_CAN0_SLAVE_t* Slave,BMS_CAN0_UI_t* UI_Board){
+	uint8_t test = Master_Rx7_buff[5] & 0x04 ;
 	Slave->SlaveAliveCnt[0]=Master_Rx7_buff[0] >> 5;
 	Slave->SlaveMode=Master_Rx7_buff[0] & 0x1F;
 	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;
 }

+ 26 - 0
BMS Master/Sources/BMS_Master.c

@@ -221,6 +221,8 @@ 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;
 
 	BMS_RCT_init_fsm(s);
 	initUIFifo(s);
@@ -416,6 +418,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;
 }
@@ -1695,6 +1698,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

+ 26 - 0
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

+ 19 - 3
BMS Master/Sources/BMS_SoC_estimator.c

@@ -392,7 +392,7 @@ 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;
 			return 0;	
 		break;
@@ -585,7 +585,7 @@ 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; 
 			return 0;
 		break;
@@ -644,7 +644,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 +653,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 +678,8 @@ 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
 	
@@ -691,6 +694,10 @@ uint32_t bms_set_derating(MASTER_SOC_ESTIMATOR_t* est, int8_t minTemp, int8_t ma
 		output_derate = derating_discharge_SoC;
 	}
 	
+	if(output_derate > derating_discharge_Umin1) {
+		output_derate = derating_discharge_Umin1;
+	}
+	
 	est->MaxBatteryDischargeCurrent=output_derate;
 	
 	return 0;
@@ -747,6 +754,15 @@ float bms_calc_discharge_derating(float SoC) {
 	
 }
 
+float bms_calc_discharge_Umin1(uint16_t Umin) {
+	if(Umin <= BMS_SOC_UMIN_1 ) {
+		return 0.0 ;
+	}
+	else {
+		return 25.0;
+	}
+}
+
 /*
  * @ brief derate maximum charge current
  */

+ 21 - 4
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;
 	
 	
 	
@@ -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);
 
+		}
+		
+*/
 		
 	}