Przeglądaj źródła

打开被动均衡

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 lat temu
rodzic
commit
0f5b9c0370

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

@@ -59,13 +59,13 @@ static void init_current_voltage_task(void){
 }
 
 static u32 current_voltage_task_handler(void){
-	if (bms_state_get()->pack_balancing){ //if balance, do'nt sample cell voltage
-		return _current_voltage_task.delay;
-	}
 	/* 测量电流 */
 	_measure_value.load_current = get_pack_current();
 	_current_notify();//通知bms state 有新的电流数据
-	
+
+	if (bms_state_get()->pack_balancing){ //if balance, do'nt sample cell voltage
+		return _current_voltage_task.delay;
+	}	
 	//用内阻对cell的电压进行补偿,充电减,放电加
 	_measure_value.cell_vol[_current_voltage_task.index] = get_cell_voltage(_current_voltage_task.index) - bms_health()->internal_resistance[_current_voltage_task.index] * _measure_value.load_current/1000;
 	_current_voltage_task.index = (_current_voltage_task.index + 1) % CELLS_NUM;

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

@@ -15,7 +15,7 @@
 #define ALLOW_DEEP_SLEEP 1
 #define SLEEP_IGNORE_UNHEALTH 0
 #define ALLOW_POWER_DOWN 1 //disable power down for debug
-#define ALLOW_5238_BALANCE 0
+#define ALLOW_5238_BALANCE 1
 
 static void _current_notify(void);
 static void _voltage_notify(void);
@@ -395,6 +395,8 @@ static void _current_notify(void){
  * 充电过程中考虑balance,主要是希望cell 电压扩散后,保证1. 单电芯不能过压, 2. 单电芯不能比平均电压过低,导致
  * 木桶效应,目标是电压最高的那个cell,尽量压制,不让电压再升高,或者升高的尽量慢一些
 */
+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};
@@ -403,19 +405,25 @@ static void _balance_timer_handler(shark_timer_t *t){
 	ml5238_cell_start_balance(0);
 	_bms_state.pack_balancing = 0;
 }
+
+static uint32_t get_balance_mask(uint8_t current_max_index){
+	return BIT(current_max_index);
+}
+
 static void check_cell_balance(uint8_t current_max_index){
 	if (!_bms_state.charging){ //not charging, need not do balance
 		if (_bms_state.pack_balancing){
 			_bms_state.pack_balancing = 0;
 			_cell_balance.count = 10;
 			ml5238_cell_start_balance(0);
+			shark_timer_cancel(&_balance_timer);
 		}
 		return;
 	}
-	if (!_bms_state.pack_balancing && _bms_state.cell_min_vol < CELL_FUSION_VOLTAGE){
+	if ((!_bms_state.pack_balancing && _bms_state.cell_min_vol <= CELL_FUSION_VOLTAGE) || _bms_state.pack_balancing){
 		return;
 	}
-	if (_bms_state.cell_max_vol - _bms_state.cell_min_vol >= MAX_DIFF_BETWEEN_MIN_MAX_CELL){
+	if (_bms_state.cell_max_vol >= MAX_CELL_VOLTAGE_FOR_BALACNE){
 		debounce_inc(_cell_balance);
 	}else {
 		debounce_dec(_cell_balance);
@@ -426,9 +434,9 @@ static void check_cell_balance(uint8_t current_max_index){
 		_bms_state.pack_balancing = 0;
 		ml5238_cell_start_balance(0);
 	}
-	if (_bms_state.pack_balancing && (current_max_index != _bms_state.cell_index_of_max_vol)){
-		ml5238_cell_start_balance(BIT(current_max_index));
-		shark_timer_post(&_balance_timer, 60 * 1000); //stop balance after 1 minute
+	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
 	}
 	_bms_state.cell_index_of_max_vol = current_max_index;	
 }

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

@@ -18,6 +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 CELL_FUSION_VOLTAGE      3500 //LFP电池在3.5v的时候,开始发散,需要判断是否要balance
 #define SMALL_CURRENT_MIN_VOLTAGE (16.0f * 1000.0f) //判断小电流是否真实短路的,端口最小电压