Explorar o código

修改被动均衡

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=5) %!d(string=hai) anos
pai
achega
6e5eba0342
Modificáronse 2 ficheiros con 5 adicións e 9 borrados
  1. 4 8
      Application/app/sox/state.c
  2. 1 1
      Application/app/sox/state.h

+ 4 - 8
Application/app/sox/state.c

@@ -485,7 +485,7 @@ static void _balance_timer_handler(shark_timer_t *t);
 
 static shark_timer_t _balance_timer = {.handler = _balance_timer_handler};
 
-static debounce_t _cell_balance = {.count = 10, .max_count = 20};
+static debounce_t _cell_balance = {.count = 0, .max_count = 10, .init_count = 0};
 
 static void _balance_timer_handler(shark_timer_t *t){
 	ml5238_cell_start_balance(0);
@@ -506,23 +506,19 @@ static void check_cell_balance(uint8_t current_max_index){
 		}
 		return;
 	}
-	if ((!_bms_state.pack_balancing && _bms_state.cell_min_vol <= CELL_FUSION_VOLTAGE) || _bms_state.pack_balancing){
+	if ((!_bms_state.pack_balancing && _bms_state.cell_max_vol < MAX_CELL_VOLTAGE_FOR_BALACNE) || _bms_state.pack_balancing){
 		return;
 	}
 	if (_bms_state.cell_max_vol >= MAX_CELL_VOLTAGE_FOR_BALACNE){
 		debounce_inc(_cell_balance);
 	}else {
-		debounce_dec(_cell_balance);
+		debounce_reset(_cell_balance);
 	}
 	if (!_bms_state.pack_balancing && debounce_reach_max(_cell_balance)){
 		_bms_state.pack_balancing = 1;
-	}else if (_bms_state.pack_balancing && debounce_reach_zero(_cell_balance)){
-		_bms_state.pack_balancing = 0;
-		ml5238_cell_start_balance(0);
-	}
-	if (_bms_state.pack_balancing){
 		ml5238_cell_start_balance(get_balance_mask(current_max_index));
 		shark_timer_post(&_balance_timer, 30 * 1000); //stop balance after 30s
+		debounce_reset(_cell_balance);
 	}
 	_bms_state.cell_index_of_max_vol = current_max_index;	
 }

+ 1 - 1
Application/app/sox/state.h

@@ -18,7 +18,7 @@
 #define MIN_START_LOADING_CURRENT 5  //ma, 如果有反向小于 MIN_START_LOADING_CURRENT的电流,认为在放电
 #define MAX_DIFF_BETWEEN_MIN_MAX_CELL 150 //0.15v ,压差超过这个值,开始balance
 #define MIN_DIFF_BETWEEN_MIN_MAX_CELL 050 //0.05v, 牙差低于这个数据,停止balance
-#define MAX_CELL_VOLTAGE_FOR_BALACNE 3700
+#define MAX_CELL_VOLTAGE_FOR_BALACNE 3650
 #define CELL_FUSION_VOLTAGE      3500 //LFP电池在3.5v的时候,开始发散,需要判断是否要balance