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