@@ -51,9 +51,16 @@ void Balance_Battery()
51
51
}
52
52
}
53
53
54
+ float scalar = 0.0f ;
55
+
54
56
// Scale the balancing thresholds tighter as the battery voltage increases. Allows for faster charging.
55
- float scalar = (float )CELL_BALANCING_SCALAR_MAX * (1.0f - (((float )max_cell_voltage - (float )MIN_CELL_V_FOR_BALANCING )/((float )CELL_VOLTAGE_TO_ENABLE_CHARGING - (float )MIN_CELL_V_FOR_BALANCING )));
56
- if (scalar < 1.0f ) {
57
+ if (battery_state .xt60_connected == CONNECTED ) {
58
+ scalar = (float )CELL_BALANCING_SCALAR_MAX * (1.0f - (((float )max_cell_voltage - (float )MIN_CELL_V_FOR_BALANCING )/((float )CELL_VOLTAGE_TO_ENABLE_CHARGING - (float )MIN_CELL_V_FOR_BALANCING )));
59
+ if (scalar < 1.0f ) {
60
+ scalar = 1.0f ;
61
+ }
62
+ }
63
+ else {
57
64
scalar = 1.0f ;
58
65
}
59
66
@@ -64,21 +71,22 @@ void Balance_Battery()
64
71
battery_state .balancing_enabled = 0 ;
65
72
}
66
73
67
- if (battery_state .balancing_enabled == 1 ) {
68
-
69
- for (int i = 0 ; i < battery_state .number_of_cells ; i ++ ) {
70
- if ( (Get_Cell_Voltage (i ) - min_cell_voltage ) >= ((float )CELL_BALANCING_HYSTERESIS_V * scalar )) {
71
- battery_state .cell_balance_bitmask |= (1 <<i );
72
- }
73
- else {
74
- battery_state .cell_balance_bitmask &= ~(1 <<i );
75
- }
74
+ //Check each cell voltage. If XT60 is connected, then allow larger voltage differences that tighten as the battery voltage increases.
75
+ //If just the balance port is connected, then use the tightest balancing thresholds
76
+ //If a cell is over CELL_OVER_VOLTAGE_ENABLE_DISCHARGE, then the discharging resistor will turn on
77
+ for (int i = 0 ; i < battery_state .number_of_cells ; i ++ ) {
78
+ if ( (battery_state .balancing_enabled == 1 ) && ((Get_Cell_Voltage (i ) - min_cell_voltage ) >= ((float )CELL_BALANCING_HYSTERESIS_V * scalar ))) {
79
+ battery_state .cell_balance_bitmask |= (1 <<i );
80
+ }
81
+ else if (Get_Cell_Voltage (i ) >= CELL_OVER_VOLTAGE_ENABLE_DISCHARGE ) {
82
+ battery_state .cell_balance_bitmask |= (1 <<i );
83
+ }
84
+ else {
85
+ battery_state .cell_balance_bitmask &= ~(1 <<i );
76
86
}
77
- Balancing_GPIO_Control (battery_state .cell_balance_bitmask );
78
- }
79
- else {
80
- Balancing_GPIO_Control (0 );
81
87
}
88
+ Balancing_GPIO_Control (battery_state .cell_balance_bitmask );
89
+
82
90
}
83
91
else {
84
92
Balancing_GPIO_Control (0 );
0 commit comments