Skip to content

Commit bd25bf5

Browse files
authored
More updates (#26)
* Overvoltage work * Update firmware rev to 1.2
1 parent 467c6fb commit bd25bf5

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

Inc/battery.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ extern "C" {
2020
#define VOLTAGE_CONNECTED_THRESHOLD (uint32_t)( 0.1 * BATTERY_ADC_MULTIPLIER )
2121
#define CELL_DELTA_V_ENABLE_BALANCING (uint32_t)( 0.015 * BATTERY_ADC_MULTIPLIER )
2222
#define CELL_BALANCING_HYSTERESIS_V (uint32_t)( 0.010 * BATTERY_ADC_MULTIPLIER )
23-
#define CELL_BALANCING_SCALAR_MAX (uint8_t)30
23+
#define CELL_BALANCING_SCALAR_MAX (uint8_t)25
2424
#define MIN_CELL_V_FOR_BALANCING (uint32_t)( 3.0 * BATTERY_ADC_MULTIPLIER )
2525
#define CELL_VOLTAGE_TO_ENABLE_CHARGING (uint32_t)( 4.18 * BATTERY_ADC_MULTIPLIER )
26+
#define CELL_OVER_VOLTAGE_ENABLE_DISCHARGE (uint32_t)( 4.205 * BATTERY_ADC_MULTIPLIER )
2627
#define CELL_OVER_VOLTAGE_DISABLE_CHARGING (uint32_t)( 4.22 * BATTERY_ADC_MULTIPLIER )
2728
#define MIN_CELL_VOLTAGE_SAFE_LIMIT (uint32_t)( 2.0 * BATTERY_ADC_MULTIPLIER )
2829

Inc/bq25703a_regulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ extern "C" {
9090
#define IIN_ADC_SCALE (uint32_t)(0.050 * REG_ADC_MULTIPLIER)
9191

9292
#define MAX_CHARGE_CURRENT_MA 6000
93-
#define ASSUME_EFFICIENCY 0.9f
93+
#define ASSUME_EFFICIENCY 0.85f
9494
#define BATTERY_DISCONNECT_THRESH (uint32_t)(4.215 * REG_ADC_MULTIPLIER)
9595
#define MAX_CHARGING_POWER 60000
9696
#define NON_USB_PD_CHARGE_POWER 2500

Inc/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void Error_Handler(void);
136136
/* USER CODE BEGIN Private defines */
137137

138138
#define LIPOW_MAJOR_VERION (uint8_t)1
139-
#define LIPOW_MINOR_VERION (uint8_t)1
139+
#define LIPOW_MINOR_VERION (uint8_t)2
140140

141141
/* USER CODE END Private defines */
142142

Src/battery.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,16 @@ void Balance_Battery()
5151
}
5252
}
5353

54+
float scalar = 0.0f;
55+
5456
// 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 {
5764
scalar = 1.0f;
5865
}
5966

@@ -64,21 +71,22 @@ void Balance_Battery()
6471
battery_state.balancing_enabled = 0;
6572
}
6673

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);
7686
}
77-
Balancing_GPIO_Control(battery_state.cell_balance_bitmask);
78-
}
79-
else {
80-
Balancing_GPIO_Control(0);
8187
}
88+
Balancing_GPIO_Control(battery_state.cell_balance_bitmask);
89+
8290
}
8391
else {
8492
Balancing_GPIO_Control(0);

0 commit comments

Comments
 (0)