Kaynağa Gözat

ML5238 calibrate when temp changed beyond 5度

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 yıl önce
ebeveyn
işleme
45614ae652

+ 1 - 1
Application/app/protocol_old.c

@@ -162,7 +162,7 @@ void protocol_old_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 			printf("laohua OK!\n");
 		}else if (memcmp(data + 4, "tuichu", 6) == 0){
 			if (bms_work_is_aging_test()){
-				bms_work_mode_set(WORK_MODE_AGING_TEST, 1);
+				bms_work_mode_set(WORK_MODE_AGING_TEST, 0);
 				bms_state_get()->user_request = USER_REQUEST_PENDING | USER_REQUEST_SMALLCURRENT_ON | USER_REQUEST_DISCHARGER_OFF | USER_REQUEST_CHARGER_OFF;
 				printf("tuichu OK!\n");
 			}

+ 8 - 8
Application/app/sox/health.c

@@ -173,7 +173,7 @@ static int judge_debounce(int input, debounce_t *d){
 }
 
 static int _can_powerdown(void){
-	if (io_state()->charger_detect || bms_state_get()->charging || !bms_work_is_normal()){
+	if (io_state()->charger_detect_irq || bms_state_get()->charging || !bms_work_is_normal()){
 		return 0;
 	}
 	if ((bms_state_get()->pack_voltage <= min_discharger_pdown_vol[_health.is_work_temp_normal] ||
@@ -260,13 +260,13 @@ void check_voltage_state(void) {
 
 /* 检测温度情况,看是否过高温,或者过低温 */
 
-static debounce_t _charger_over_temp      = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _charger_lower_temp     = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _charger_normal_temp    = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _discharger_over_temp   = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _discharger_lower_temp  = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _discharger_normal_temp = {.count = 0, .max_count = 10, .init_count = 0};
-static debounce_t _work_lower_temp = 		{.count = 0, .max_count = 5, .init_count = 0};
+static debounce_t _charger_over_temp      = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _charger_lower_temp     = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _charger_normal_temp    = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _discharger_over_temp   = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _discharger_lower_temp  = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _discharger_normal_temp = {.count = 0, .max_count = 8, .init_count = 0};
+static debounce_t _work_lower_temp = 		{.count = 0, .max_count = 8, .init_count = 0};
 
 static int _is_over_temp(int8_t *temps){
 	for (int i = 0; i < PACK_TEMPS_NUM; i++){

+ 1 - 1
Application/app/sox/measure_task.c

@@ -80,7 +80,7 @@ static struct means_task _temp_task;
 static u32 temp_task_handler(void);
 static void init_temp_task(void){
 	_temp_task._task.handler = temp_task_handler;
-	_temp_task.delay = 1 * 1000;
+	_temp_task.delay = 500;
 	_temp_task.index = 0;
 	for (int i = 0; i < PACK_TEMPS_NUM; i++){
 		_measure_value.pack_temp[i] = get_pack_temperature(i);

+ 9 - 6
Application/app/sox/soc.c

@@ -99,15 +99,18 @@ int soc_update_by_ocv(void){
 	
 	int changed = 0;
 	if (_soc.flags & SOC_FLAG_CALIBRATED){
-		if (!chargering && bms_health()->powerdown_lower_voltage){
-			_soc.coulomb_min = _soc.coulomb_now; //已经校准过了,而且电池进入powerdown,最小容量修正为当前容量
-			_soc.capacity = 0;
-			soc_warning("current coulomb %f\n", _soc.coulomb_now);
+		if (!chargering){
+			if (bms_health()->powerdown_lower_voltage && bms_health()->is_work_temp_normal) {
+				_soc.coulomb_min = _soc.coulomb_now; //已经校准过了,而且电池在常温下进入powerdown,最小容量修正为当前容量
+				_soc.capacity = 0;
+				soc_warning("current coulomb %f\n", _soc.coulomb_now);
+			}
 			changed = 1;
 		}
 		if (chargering){
-			if (bms_state_get()->pack_voltage >= (54000) || ((measure_value()->load_current > 0.0f) && (measure_value()->load_current <= 500.0f))){
+			if (bms_state_get()->pack_voltage >= (53500) && (measure_value()->load_current <= 500.0f)){
 				_soc.capacity = 100;
+				is_force_full = 1;
 				changed = 1;
 			}
 		}
@@ -129,7 +132,7 @@ static void soc_calibrate(uint8_t prev_charge_status){
 				}
 			}
 		}else if (prev_charge_status){
-			if(bms_state_get()->pack_voltage >= 54000){
+			if(bms_state_get()->pack_voltage >= 53500){
 				soc_debug("calibrate Capacity to 100\n");
 				_soc.capacity = 100;
 				is_force_full = 1;

+ 14 - 13
Application/app/sox/state.c

@@ -24,8 +24,10 @@ static u32 _bms_main_task_handler(void);
 static void _debug_timer_handler(shark_timer_t *t);
 
 static bms_state_t _bms_state;
+static int8_t pcb_temp = 100;
+static int pcb_temp_count = 0;
+static int ml5238_cali_count = 0;
 static shark_task_t _bms_main_task = {.handler = _bms_main_task_handler};
-
 static shark_timer_t _debug_timer = {.handler = _debug_timer_handler};
 
 void bms_state_init(void){
@@ -40,6 +42,8 @@ void bms_state_init(void){
 	_bms_state.user_request = USER_REQUEST_PENDING | USER_REQUEST_SMALLCURRENT_ON;
 	shark_task_add(&_bms_main_task);
 	shark_timer_post(&_debug_timer, 2000);
+
+	pcb_temp = measure_value()->pack_temp[PCB_TEMP_INDEX];
 }
 
 bms_state_t *bms_state_get(void){
@@ -82,6 +86,7 @@ int bms_work_mode_set(int mode, int start){
 void bms_state_log(void){
 	state_warning("Life Time: %d\n", shark_get_seconds());
 	state_warning("Sleep Time: %ds\n", get_system_sleep_time());
+	state_warning("ml5238 cali: %d\n", ml5238_cali_count);
 	state_debug("Charging: %d\n", _bms_state.charging);
 	state_debug("WorkMode %d\n", _bms_state.work_mode);
 	state_debug("DMos: %d\n", ml5238_is_discharging());
@@ -492,20 +497,16 @@ static void _voltage_notify(void){
 }
 
 static void _temperature_notify(void){
-	static int8_t pcb_temp = 100;
-	static int pcb_temp_count = 0;
-	if (pcb_temp == 100) {
-		pcb_temp = measure_value()->pack_temp[PCB_TEMP_INDEX];
-	}else {
-		if (abs(pcb_temp - measure_value()->pack_temp[PCB_TEMP_INDEX]) >= 5){//pcb温度变化超过5度,需要重新校准ML5238
-			if (pcb_temp_count ++ >= 5) {
-				current_calibrate();
-				pcb_temp = measure_value()->pack_temp[PCB_TEMP_INDEX];
-				state_warning("ML5238 calibrate!!\n");
-			}
-		}else {
+	if (abs(pcb_temp - measure_value()->pack_temp[PCB_TEMP_INDEX]) >= 5){//pcb温度变化超过5度,需要重新校准ML5238
+		if (pcb_temp_count ++ >= 5) {
+			current_calibrate();
+			pcb_temp = measure_value()->pack_temp[PCB_TEMP_INDEX];
+			state_warning("ML5238 calibrate!!\n");
 			pcb_temp_count = 0;
+			ml5238_cali_count ++;
 		}
+	}else {
+		pcb_temp_count = 0;
 	}
 	check_temp_state(); //check health of cell/pcb temperature
 }

+ 1 - 1
Application/bsp/cs1180.c

@@ -31,7 +31,7 @@ static void cs1180_reset(void);
 
 void cs_delay(void)
 {
-	uint32_t  count = 60;
+	uint32_t  count = 1;
 	while(count--); 
 }
 static int _cs1180_ready = 0;