Skip to content

Commit

Permalink
More updates (#26)
Browse files Browse the repository at this point in the history
* Overvoltage work

* Update firmware rev to 1.2
  • Loading branch information
AlexKlimaj committed Jul 18, 2019
1 parent 467c6fb commit bd25bf5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Inc/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ extern "C" {
#define VOLTAGE_CONNECTED_THRESHOLD (uint32_t)( 0.1 * BATTERY_ADC_MULTIPLIER )
#define CELL_DELTA_V_ENABLE_BALANCING (uint32_t)( 0.015 * BATTERY_ADC_MULTIPLIER )
#define CELL_BALANCING_HYSTERESIS_V (uint32_t)( 0.010 * BATTERY_ADC_MULTIPLIER )
#define CELL_BALANCING_SCALAR_MAX (uint8_t)30
#define CELL_BALANCING_SCALAR_MAX (uint8_t)25
#define MIN_CELL_V_FOR_BALANCING (uint32_t)( 3.0 * BATTERY_ADC_MULTIPLIER )
#define CELL_VOLTAGE_TO_ENABLE_CHARGING (uint32_t)( 4.18 * BATTERY_ADC_MULTIPLIER )
#define CELL_OVER_VOLTAGE_ENABLE_DISCHARGE (uint32_t)( 4.205 * BATTERY_ADC_MULTIPLIER )
#define CELL_OVER_VOLTAGE_DISABLE_CHARGING (uint32_t)( 4.22 * BATTERY_ADC_MULTIPLIER )
#define MIN_CELL_VOLTAGE_SAFE_LIMIT (uint32_t)( 2.0 * BATTERY_ADC_MULTIPLIER )

Expand Down
2 changes: 1 addition & 1 deletion Inc/bq25703a_regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern "C" {
#define IIN_ADC_SCALE (uint32_t)(0.050 * REG_ADC_MULTIPLIER)

#define MAX_CHARGE_CURRENT_MA 6000
#define ASSUME_EFFICIENCY 0.9f
#define ASSUME_EFFICIENCY 0.85f
#define BATTERY_DISCONNECT_THRESH (uint32_t)(4.215 * REG_ADC_MULTIPLIER)
#define MAX_CHARGING_POWER 60000
#define NON_USB_PD_CHARGE_POWER 2500
Expand Down
2 changes: 1 addition & 1 deletion Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void Error_Handler(void);
/* USER CODE BEGIN Private defines */

#define LIPOW_MAJOR_VERION (uint8_t)1
#define LIPOW_MINOR_VERION (uint8_t)1
#define LIPOW_MINOR_VERION (uint8_t)2

/* USER CODE END Private defines */

Expand Down
38 changes: 23 additions & 15 deletions Src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ void Balance_Battery()
}
}

float scalar = 0.0f;

// Scale the balancing thresholds tighter as the battery voltage increases. Allows for faster charging.
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)));
if (scalar < 1.0f) {
if (battery_state.xt60_connected == CONNECTED) {
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)));
if (scalar < 1.0f) {
scalar = 1.0f;
}
}
else {
scalar = 1.0f;
}

Expand All @@ -64,21 +71,22 @@ void Balance_Battery()
battery_state.balancing_enabled = 0;
}

if (battery_state.balancing_enabled == 1) {

for(int i = 0; i < battery_state.number_of_cells; i++) {
if ( (Get_Cell_Voltage(i) - min_cell_voltage) >= ((float)CELL_BALANCING_HYSTERESIS_V * scalar)) {
battery_state.cell_balance_bitmask |= (1<<i);
}
else {
battery_state.cell_balance_bitmask &= ~(1<<i);
}
//Check each cell voltage. If XT60 is connected, then allow larger voltage differences that tighten as the battery voltage increases.
//If just the balance port is connected, then use the tightest balancing thresholds
//If a cell is over CELL_OVER_VOLTAGE_ENABLE_DISCHARGE, then the discharging resistor will turn on
for(int i = 0; i < battery_state.number_of_cells; i++) {
if ( (battery_state.balancing_enabled == 1) && ((Get_Cell_Voltage(i) - min_cell_voltage) >= ((float)CELL_BALANCING_HYSTERESIS_V * scalar))) {
battery_state.cell_balance_bitmask |= (1<<i);
}
else if (Get_Cell_Voltage(i) >= CELL_OVER_VOLTAGE_ENABLE_DISCHARGE) {
battery_state.cell_balance_bitmask |= (1<<i);
}
else {
battery_state.cell_balance_bitmask &= ~(1<<i);
}
Balancing_GPIO_Control(battery_state.cell_balance_bitmask);
}
else {
Balancing_GPIO_Control(0);
}
Balancing_GPIO_Control(battery_state.cell_balance_bitmask);

}
else {
Balancing_GPIO_Control(0);
Expand Down

0 comments on commit bd25bf5

Please sign in to comment.