Jelajahi Sumber

调整充满逻辑,如果电压大于53.5由充电变为不充电,同时充电能量大于5安秒也认为充满

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 tahun lalu
induk
melakukan
746a30902e
1 mengubah file dengan 41 tambahan dan 27 penghapusan
  1. 41 27
      Application/app/sox/soc.c

+ 41 - 27
Application/app/sox/soc.c

@@ -22,7 +22,8 @@ uint32_t charger_remain_time = 0;
 #define MAX_TIME_FULL_TO_EMPTY (5 * 24 * 3600) //充满到欠压5天内达到,可以校准最小电量
 #define MAX_TIME_FULL_TO_EMPTY (5 * 24 * 3600) //充满到欠压5天内达到,可以校准最小电量
 #define DEFALUT_MAX_COULOMB (MAX_HA * 3600.0f)
 #define DEFALUT_MAX_COULOMB (MAX_HA * 3600.0f)
 #define DEFALUT_MIN_COULOMB (25.0f * 3600.0f)
 #define DEFALUT_MIN_COULOMB (25.0f * 3600.0f)
-#define FULL_MAX_VOLTAGE (53500)//mV
+#define FULL_MAX_VOLTAGE_CHARGING (53000)//mV
+#define FULL_MAX_VOLTAGE (53500) //mV
 #define FULL_MIN_CURRENT (500.0f) //mA
 #define FULL_MIN_CURRENT (500.0f) //mA
 static void calibrate_soc_by_ocv(void);
 static void calibrate_soc_by_ocv(void);
 
 
@@ -164,35 +165,39 @@ static void _force_capacity_full(void){
 	force_full_ts = shark_get_seconds();
 	force_full_ts = shark_get_seconds();
 }
 }
 
 
-int soc_update_by_ocv(void){
+static int _soc_update_by_ocv(uint8_t prev_charge_status){
 	static int ocv_full_count = 0;
 	static int ocv_full_count = 0;
 	int changed = 0;
 	int changed = 0;
-	if (_soc.flags & SOC_FLAG_CALIBRATED){
-		if (!chargering){
-			if (bms_health()->is_work_temp_normal) {
-				if (_soc.capacity && (bms_health()->powerdown_lower_voltage || bms_health()->sigle_cell_lower_voltage || bms_health()->discharger_lower_voltage)) {
-					if (can_modify_min_cap()){
-						_soc.coulomb_min = _soc.coulomb_now; //已经校准过了,而且电池在常温下进入powerdown,最小容量修正为当前容量
-						soc_warning("calicablite coulomb_min %f\n", _soc.coulomb_min);
-					}else {
-						_soc.coulomb_now = _soc.coulomb_min;
-					}
-					_soc.capacity = 0;
-					changed = 1;
+	if ((_soc.flags & SOC_FLAG_CALIBRATED) == 0){
+		return 0;
+	}
+	if (!chargering){
+		if (bms_health()->is_work_temp_normal) {
+			if (_soc.capacity && (bms_health()->powerdown_lower_voltage || bms_health()->sigle_cell_lower_voltage || bms_health()->discharger_lower_voltage)) {
+				if (can_modify_min_cap()){
+					_soc.coulomb_min = _soc.coulomb_now; //已经校准过了,而且电池在常温下进入powerdown,最小容量修正为当前容量
+					soc_warning("calicablite coulomb_min %f\n", _soc.coulomb_min);
+				}else {
+					_soc.coulomb_now = _soc.coulomb_min;
 				}
 				}
+				_soc.capacity = 0;
+				return 1;
 			}
 			}
 		}
 		}
-		if (chargering && _soc.capacity != 100){
-			if (bms_health()->sigle_cell_over_voltage) {
-				_force_capacity_full();
-				ocv_full_count = 0;
-				changed = 1;
-			}else if (bms_state_get()->pack_voltage >= (FULL_MAX_VOLTAGE) && (measure_value()->load_current <= FULL_MIN_CURRENT)){
-				if (bms_state_get()->ps_charger_mask && !bms_state_get()->ps_charger_in) { //ps100 上报无充电器,不做处理
-					ocv_full_count = 0;
-					return changed;
-				}
-				if (ocv_full_count++ >= 100) {
+	}
+	if (chargering || prev_charge_status) {
+		if (bms_state_get()->ps_charger_mask && !bms_state_get()->ps_charger_in) { //ps100 上报无充电器,不做处理
+			ocv_full_count = 0;
+			return changed;
+		}
+		if (bms_health()->sigle_cell_over_voltage) { //单电芯过压强制充满
+			_force_capacity_full();
+			ocv_full_count = 0;
+			return 1;
+		}
+		if (chargering && (_soc.capacity != 100)) {
+			if (bms_state_get()->pack_voltage >= (FULL_MAX_VOLTAGE_CHARGING) && (measure_value()->load_current <= FULL_MIN_CURRENT)){
+				if (ocv_full_count++ >= 100) { //连续100次(小电流采集30ms一次,就是3s时间)电压和电流满足条件,强制充满
 					_force_capacity_full();
 					_force_capacity_full();
 					ocv_full_count = 0;
 					ocv_full_count = 0;
 					changed = 1;
 					changed = 1;
@@ -200,18 +205,27 @@ int soc_update_by_ocv(void){
 			}else {
 			}else {
 				ocv_full_count = 0;
 				ocv_full_count = 0;
 			}
 			}
+		}else if (!chargering && prev_charge_status && (_soc.capacity != 100)){
+			if ((bms_state_get()->pack_voltage >= FULL_MAX_VOLTAGE) && (_soc.charger_coulomb >= 5.0f)){//充电容量大于5安秒
+				_force_capacity_full();
+				changed = 1;
+			}
 		}
 		}
 	}
 	}
 	return changed;
 	return changed;
 }
 }
 
 
+int soc_update_by_ocv(void){
+	return _soc_update_by_ocv(0);
+}
+
 
 
 static void soc_calibrate(uint8_t prev_charge_status){
 static void soc_calibrate(uint8_t prev_charge_status){
 	static int cali_full_count = 0;
 	static int cali_full_count = 0;
 	if (!(_soc.flags & SOC_FLAG_CALIBRATED)){
 	if (!(_soc.flags & SOC_FLAG_CALIBRATED)){
 		if (chargering){//用ocv进行严格校准
 		if (chargering){//用ocv进行严格校准
 			if (_soc.capacity != 100){
 			if (_soc.capacity != 100){
-				if ((measure_value()->load_current <= FULL_MIN_CURRENT) && (bms_state_get()->pack_voltage >= FULL_MAX_VOLTAGE)){
+				if ((measure_value()->load_current <= FULL_MIN_CURRENT) && (bms_state_get()->pack_voltage >= FULL_MAX_VOLTAGE_CHARGING)){
 					cali_full_count ++;
 					cali_full_count ++;
 				}
 				}
 				if (cali_full_count == 10 || bms_health()->sigle_cell_over_voltage) {
 				if (cali_full_count == 10 || bms_health()->sigle_cell_over_voltage) {
@@ -289,7 +303,7 @@ static void soc_update_by_current_and_time(float current_now, float delta_time,
 	}
 	}
 	_soc.coulomb_now = est_coulomb;
 	_soc.coulomb_now = est_coulomb;
 	//通过电压校准SOC,只能在电压范围的两端校准
 	//通过电压校准SOC,只能在电压范围的两端校准
-	update_capticy |= soc_update_by_ocv();
+	update_capticy |= _soc_update_by_ocv(prev_charge_status);
 	soc_calibrate(prev_charge_status);
 	soc_calibrate(prev_charge_status);
 
 
 	//如果没有校准过,充电过程中,电量100%后,设置校准标志位
 	//如果没有校准过,充电过程中,电量100%后,设置校准标志位