Explorar o código

1. 重新加入充电充满后的放电校准系数
2. SN第七byte为F,加速1.08倍放电,解决库存电池不显示2.5AH以内的最小容量的问题

Signed-off-by: kevin <huhui@sharkgulf.com>

kevin %!s(int64=2) %!d(string=hai) anos
pai
achega
7681b0e8eb
Modificáronse 3 ficheiros con 38 adicións e 7 borrados
  1. 13 0
      Application/app/nv_storage.c
  2. 1 0
      Application/app/nv_storage.h
  3. 24 7
      Application/app/sox/soc.c

+ 13 - 0
Application/app/nv_storage.c

@@ -208,3 +208,16 @@ int nv_restore_soc(void){
 	return ((success0 == 0) || (success1 == 0))?0:-1;
 }
 
+uint8_t nv_get_sn_byte7(void) {
+	uint8_t sn[30] = {0};
+	int try_cnt = 20;
+	while (nv_read_sn(sn, sizeof(sn)) < 7) {
+		if (try_cnt-- < 0) {
+			break;
+		}
+	}
+	if (sn[0] == 0) {
+		return 'N';
+	}
+	return sn[6];
+}

+ 1 - 0
Application/app/nv_storage.h

@@ -26,5 +26,6 @@ void nv_save_all_soc(void);
 void nv_storage_log(void);
 int nv_save_factory_result(uint8_t result);
 uint8_t nv_read_factory_result(void);
+uint8_t nv_get_sn_byte7(void);
 
 

+ 24 - 7
Application/app/sox/soc.c

@@ -22,6 +22,8 @@ static float _discharger_coefficient = 1.0f;
 static float _discharger_no_full_coef = 1.0f;
 static uint32_t charger_remain_time = 0;
 static uint8_t  version_changed = 0;
+static bool    b_sn_byte7_f = false;
+static float   small_20_dischr = 0;
 static const float _discharger_gain[] = {1.0f/*>0度*/, 1.03f/*-2<t<=0*/, 1.06f/*-5<t<=-2*/, 1.08f/*-10<t<=-5*/, 1.11f/*-15<t<=-10*/, 1.15f/*-20<t<=-15*/};
 #define MAX_TIME_FULL_TO_EMPTY (5 * 24 * 3600) //充满到欠压5天内达到,可以校准最小电量
 #define MAX_TIME_EMPTY_TO_FULL (24 * 3600) //欠压到充满24小时内达到,可以校准最小电量
@@ -54,6 +56,9 @@ void soc_init(void){
 		soc_warning("SOC: nv storage is not inited, use default value!!\n");
 		_soc_clear();
 	}
+	if (nv_get_sn_byte7() == 'F') {
+		b_sn_byte7_f = true;
+	}
 	//如果最大容量和默认不一致,需要重新校准
 	if (_soc.coulomb_max != DEFALUT_MAX_COULOMB) {
 		_soc_clear();
@@ -179,9 +184,13 @@ static void soc_update_discharger_coeff(void){
 		if ((abs(measure_value()->load_current) > 10.0f) && (abs(measure_value()->load_current) < 500)) {
 			coff = 1.05f;
 		}else {
-			//coff = _discharger_no_full_coef;
+			coff = _discharger_no_full_coef * coff;
 		}
+		
 		_discharger_coefficient = _discharger_coefficient * coff;
+		if (b_sn_byte7_f) {
+			_discharger_coefficient = _discharger_coefficient * 1.09f;
+		}
 	}
 }
 
@@ -229,12 +238,12 @@ void soc_log(void){
 	soc_debug("C min: %.4f\n", TOHA(_soc.coulomb_min));
 	soc_debug("C max: %.4f\n", TOHA(_soc.coulomb_max));
 	soc_debug("C char: %.4f\n", TOHA(_soc.charger_coulomb));
-	soc_debug("C dischar: %.4f\n", TOHA(_soc.dischrger_coulomb));
+	soc_debug("C dischar: %.4f, F:%c\n", TOHA(_soc.dischrger_coulomb), b_sn_byte7_f?'Y':'N');
 	soc_debug("C version: %d, %d\n", soc_get_version(), version_changed);
 	soc_debug("C tol: %.2f\n", _soc.total_coulomb);
 	soc_debug("C real_coulomb: %f\n", _soc.current_real_coulomb);
 	soc_debug("C delta time %f, %f, -- %d\n", max_soc_delta_time, soc_delta_time, force_full_ts);
-	soc_debug("C discharger coefficient = %f, %f\n", _discharger_coefficient, _discharger_no_full_coef);
+	soc_debug("C discharger coefficient = %f, %f, %f\n", _discharger_coefficient, _discharger_no_full_coef, small_20_dischr);
 	if (chargering){
 		soc_debug("C remain %d\n", charger_remain_time);
 	}
@@ -351,13 +360,15 @@ static void _force_capacity_full(void){
 		_soc.current_real_coulomb = _soc.coulomb_max - _soc.coulomb_min;
 		_discharger_no_full_coef = 1.0f;
 	}else if (bms_state_get()->pack_voltage >= (53000 - 200)) {
-		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.05f);
+		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.005f);
 	}else if (bms_state_get()->pack_voltage >= (53000 - 400)) {
-		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.1f);
+		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.01f);
 	}else if (bms_state_get()->pack_voltage >= (53000 - 800)) {
-		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.15f);
+		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.015f);
 	}else if (bms_state_get()->pack_voltage >= (53000 - 1000)) {
-		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.2f);
+		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.02f);
+	}else {
+		_discharger_no_full_coef = MIN(_discharger_no_full_coef, 1.03f);
 	}
 	push_event(Charger_no_full_ceof, (u32)(_discharger_no_full_coef * 10000));
 
@@ -555,6 +566,11 @@ static void soc_update_by_current_and_time(float current_now, float delta_time,
 			update_capticy = 1;
 		}
 	}else {
+		if (_soc.capacity > 20) {
+			small_20_dischr = 0;
+		}else {
+			small_20_dischr += abs(delta_q);
+		}
 		_soc.dischrger_coulomb += abs(delta_q);
 		_soc.current_real_coulomb -= abs(delta_q) / _discharger_no_full_coef;
 		if (_soc.current_real_coulomb < 0) {
@@ -618,6 +634,7 @@ void soc_update(void){
 		_soc.total_coulomb += _soc.pre_discharger_coulomb / 3600.0f;
 		chargering = 0;
 		charger_remain_time = 0;
+		small_20_dischr = 0;
 		if (_is_normal_charging() && (_soc.capacity != 100)) {
 			u32 charger_cap_x10 = (u32)(_soc.charger_coulomb / 3600.0f * 10);
 			u32 cur_cap_x10 = (u32)(_soc.coulomb_now / 3600.0f * 10);