|
|
@@ -656,29 +656,28 @@ static void _balance_timer_handler(shark_timer_t *t){
|
|
|
|
|
|
|
|
|
static u16 _search_direct(u16 *delta_v, u8 current_cell, u8 *depth, u8 dir) {
|
|
|
- u16 delta_next = 0;
|
|
|
- u16 delta_prev = 0;
|
|
|
- u8 idx_prev = 255;
|
|
|
- u8 idx_next = 255;
|
|
|
+ u16 delta_next, delta_prev;
|
|
|
+ u8 idx_prev, idx_next;
|
|
|
u8 balance_idx = 255;
|
|
|
- for (int i = 0; i < CELLS_NUM/2 + 1 ; i++) {
|
|
|
+
|
|
|
+ for (int i = 0; i < CELLS_NUM/2 + 1; i++) {
|
|
|
*depth ++;
|
|
|
//get the delta v of the prev and current
|
|
|
if (current_cell == 0) {
|
|
|
- delta_prev = delta_v[CELLS_NUM - 1];
|
|
|
idx_prev = CELLS_NUM - 1;
|
|
|
}else {
|
|
|
- delta_prev = delta_v[current_cell - 1];
|
|
|
idx_prev = current_cell - 1;
|
|
|
}
|
|
|
+ delta_prev = delta_v[idx_prev];
|
|
|
+
|
|
|
//get the delta v of the next and current
|
|
|
if (current_cell == CELLS_NUM - 1) {
|
|
|
- delta_next = delta_v[0];
|
|
|
idx_next = 0;
|
|
|
}else {
|
|
|
- delta_next = delta_v[current_cell + 1];
|
|
|
idx_next = current_cell + 1;
|
|
|
}
|
|
|
+ delta_next = delta_v[idx_next];
|
|
|
+
|
|
|
//use the max delta v of the prev and next
|
|
|
if (delta_prev >= delta_next) {
|
|
|
if(delta_prev >= MAX_DIFF_BETWEEN_MIN_MAX_CELL){
|
|
|
@@ -710,11 +709,11 @@ static u32 get_balance_maskV2(void) {
|
|
|
//calc the delta v of the Neighboring cells
|
|
|
delta_v[CELLS_NUM - 1] = abs(pcellv[CELLS_NUM-1] - pcellv[0]);
|
|
|
for (int i = 0; i < CELLS_NUM - 1; i++) {
|
|
|
- delta_v[i] = pcellv[i] - pcellv[i + 1];
|
|
|
+ delta_v[i] = abs(pcellv[i] - pcellv[i + 1]);
|
|
|
}
|
|
|
u8 depth_next, depth_prev;
|
|
|
u8 idx_next = _search_direct(delta_v, _bms_state.cell_index_of_max_vol, &depth_next, 1);// search from max to next....
|
|
|
- u8 idx_prev = _search_direct(delta_v, _bms_state.cell_index_of_max_vol, &depth_next, 0);// search from max to prev
|
|
|
+ u8 idx_prev = _search_direct(delta_v, _bms_state.cell_index_of_max_vol, &depth_prev, 0);// search from max to prev
|
|
|
//chose the min depth whitch near from max voltage cell
|
|
|
if (depth_next < depth_prev) {
|
|
|
return BIT(idx_next);
|