From bd25bf509925e5683f09d8f85169c2d507d350c0 Mon Sep 17 00:00:00 2001 From: AlexKlimaj Date: Thu, 18 Jul 2019 10:04:45 -0600 Subject: [PATCH] More updates (#26) * Overvoltage work * Update firmware rev to 1.2 --- Inc/battery.h | 3 ++- Inc/bq25703a_regulator.h | 2 +- Inc/main.h | 2 +- Src/battery.c | 38 +++++++++++++++++++++++--------------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Inc/battery.h b/Inc/battery.h index fbe08a4..d96a62c 100644 --- a/Inc/battery.h +++ b/Inc/battery.h @@ -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 ) diff --git a/Inc/bq25703a_regulator.h b/Inc/bq25703a_regulator.h index f962d33..2a8545c 100644 --- a/Inc/bq25703a_regulator.h +++ b/Inc/bq25703a_regulator.h @@ -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 diff --git a/Inc/main.h b/Inc/main.h index b288cfa..ca2681b 100644 --- a/Inc/main.h +++ b/Inc/main.h @@ -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 */ diff --git a/Src/battery.c b/Src/battery.c index 7d45b06..a2c8775 100644 --- a/Src/battery.c +++ b/Src/battery.c @@ -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; } @@ -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<= ((float)CELL_BALANCING_HYSTERESIS_V * scalar))) { + battery_state.cell_balance_bitmask |= (1<= CELL_OVER_VOLTAGE_ENABLE_DISCHARGE) { + battery_state.cell_balance_bitmask |= (1<