Improve Kconfig and docs for battery type setup

This commit is contained in:
Martin Jäger
2021-04-14 11:41:50 +02:00
parent fac325d423
commit 8d8a8f06ad
3 changed files with 51 additions and 32 deletions
+15 -2
View File
@@ -136,9 +136,22 @@ In order to overwrite the default devicetree specification, so-called overlays c
For configuration of the application-specific features, Zephyr uses the [Kconfig system](https://docs.zephyrproject.org/latest/guides/kconfig/index.html).
The configuration can be changed using `west build -t menuconfig` command or manually by changing the prj.conf file.
The configuration can be changed using `west build -t menuconfig` command or manually by changing the prj.conf file (see `Kconfig` file for possible options).
Similar to DTS overlays, the Kconfig can also be customized for each board. Copy the default `prj.conf` to a file `prj_board_name.conf` to use this file instead of `prj.conf`. Please not that, in contrast to overlays, the board-specific Kconfig files are not **added** to the default `prj.conf`, but they **replace** the default configuration instead.
Similar to DTS overlays, Kconfig can also be customized per board. Create a folder `zephyr/boards` and a file `board_name.conf` in that folder. The configuration from this file will be merged with the `prj.conf` automatically.
#### Change the battery type
By default, the charge controller is configured for maintainance-free VRLA gel battery (`CONFIG_BAT_TYPE_GEL`). Possible other pre-defined options are `CONFIG_BAT_TYPE_FLOODED`, `CONFIG_BAT_TYPE_AGM`, `CONFIG_BAT_TYPE_LFP`, `CONFIG_BAT_TYPE_NMC` and `CONFIG_BAT_TYPE_NMC_HV`.
The number of cells is automatically selected by Kconfig to get 12V nominal voltage. It can also be manually specified via `CONFIG_BAT_NUM_CELLS`.
To compile the firmware with default settings for 12V LiFePO4 batteries, add the following to `prj.conf` or the board-specific `.conf` file:
```
CONFIG_BAT_TYPE_LFP=y
CONFIG_BAT_NUM_CELLS=4
```
### Custom functions (separate C/C++ files)
+4
View File
@@ -149,6 +149,7 @@ void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capa
break;
case BAT_TYPE_CUSTOM:
#ifdef CONFIG_BAT_TYPE_CUSTOM
bat->voltage_absolute_max = 0.001F *
static_cast<float>(CONFIG_BAT_NUM_CELLS * CONFIG_CELL_ABS_MAX_VOLTAGE_MV);
@@ -198,6 +199,9 @@ void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capa
bat->charge_temp_min = CONFIG_BAT_CHARGE_TEMP_MIN;
bat->discharge_temp_max = CONFIG_BAT_DISCHARGE_TEMP_MAX;
bat->discharge_temp_min = CONFIG_BAT_DISCHARGE_TEMP_MIN;
#else
LOG_ERR("Custom battery type cannot be initialized at runtime.");
#endif
break;
}
}
+32 -30
View File
@@ -87,6 +87,13 @@ endchoice
menu "Battery default settings"
config BAT_CAPACITY_AH
int "Battery nominal capacity in Ah"
range 10 1000
default 50
help
Nominal battery capacity or sum of parallel cells capacity
choice
prompt "Battery type"
default BAT_TYPE_GEL
@@ -128,15 +135,8 @@ config BAT_TYPE
default 5 if BAT_TYPE_NMC
default 6 if BAT_TYPE_NMC_HV
config BAT_CAPACITY_AH
int "Battery nominal capacity in Ah"
range 10 200
default 50
help
Nominal battery capacity or sum of parallel cells capacity
config BAT_NUM_CELLS
int "Number of cells for single battery" if BAT_TYPE_CUSTOM
int "Number of cells for single battery"
default 6 if BAT_TYPE_FLOODED || BAT_TYPE_GEL || BAT_TYPE_AGM
default 4 if BAT_TYPE_LFP
default 3 if BAT_TYPE_NMC || BAT_TYPE_NMC_HV
@@ -154,67 +154,68 @@ config BAT_NUM_CELLS
is not exceeded.
menu "Custom cell-level settings"
depends on BAT_TYPE_CUSTOM
config CELL_ABS_MAX_VOLTAGE_MV
int "Absolute maximum voltage (mV)" if BAT_TYPE_CUSTOM
int "Absolute maximum voltage (mV)"
default 2450
help
Above this voltage the battery or loads might get damaged.
config CELL_TOPPING_VOLTAGE_MV
int "Topping voltage (mV)" if BAT_TYPE_CUSTOM
int "Topping voltage (mV)"
default 2400
help
Charger target voltage, switching from CC to CV at this voltage threshold.
config CELL_RECHARGE_VOLTAGE_MV
int "Recharge voltage (mV)" if BAT_TYPE_CUSTOM
int "Recharge voltage (mV)"
default 2300
help
Start charging again if voltage of fully charged battery drops below this threshold.
config CELL_RECONNECT_VOLTAGE_MV
int "Load reconnect cell voltage (mV)" if BAT_TYPE_CUSTOM
int "Load reconnect cell voltage (mV)"
default 2100
help
Re-enable the load only after charged beyond this value.
config CELL_DISCONNECT_VOLTAGE_MV
int "Load disconnect cell voltage (mV)" if BAT_TYPE_CUSTOM
int "Load disconnect cell voltage (mV)"
default 1950
help
Load output is disabled if battery voltage is below this threshold.
config CELL_ABS_MIN_VOLTAGE_MV
int "Topping voltage (mV)" if BAT_TYPE_CUSTOM
int "Topping voltage (mV)"
default 1600
help
Below this voltage the battery is considered damaged.
config CELL_OCV_FULL_MV
int "OCV full cell (mV)" if BAT_TYPE_CUSTOM
int "OCV full cell (mV)"
default 2150
help
Voltages during idle (no charging/discharging current)
config CELL_OCV_EMPTY_MV
int "OCV empty cell (mV)" if BAT_TYPE_CUSTOM
int "OCV empty cell (mV)"
default 1900
help
Voltages during idle (no charging/discharging current)
config CELL_TRICKLE
bool "Enable trickle charging phase" if BAT_TYPE_CUSTOM
bool "Enable trickle charging phase"
default y
config CELL_TRICKLE_VOLTAGE_MV
int "Trickle charging cell voltage (mV)" if BAT_TYPE_CUSTOM && CELL_TRICKLE
int "Trickle charging cell voltage (mV)" if CELL_TRICKLE
default 2300
help
Charger target voltage for trickle charging of lead-acid batteries
config CELL_TRICKLE_RECHARGE_TIME
int "Trickle recharge time (s)" if BAT_TYPE_CUSTOM && CELL_TRICKLE
int "Trickle recharge time (s)" if CELL_TRICKLE
default 1800
help
If the trickle voltage is not reached anymore (e.g. because of lack of solar
@@ -222,68 +223,69 @@ config CELL_TRICKLE_RECHARGE_TIME
into CC/bulk charging mode.
config CELL_EQUALIZATION
bool "Enable equalization phase" if BAT_TYPE_CUSTOM
bool "Enable equalization phase"
default n
help
Enable for flooded batteries only.
config CELL_EQUALIZATION_VOLTAGE_MV
int "Equalization phase cell voltage (mV)" if BAT_TYPE_CUSTOM && CELL_EQUALIZATION
int "Equalization phase cell voltage (mV)" if CELL_EQUALIZATION
default 2450
help
Charger target voltage for equalization charging of lead-acid batteries
config CELL_EQUALIZATION_DURATION
int "Equalization duration (seconds)" if BAT_TYPE_CUSTOM && CELL_EQUALIZATION
int "Equalization duration (seconds)" if CELL_EQUALIZATION
default 3600
help
After this time, equalization charging is stopped.
config CELL_EQUALIZATION_TRIGGER_DAYS
int "Equalization time trigger (days)" if BAT_TYPE_CUSTOM && CELL_EQUALIZATION
int "Equalization time trigger (days)" if CELL_EQUALIZATION
default 60
help
After passing specified amount of days, an equalization charge is triggered.
config CELL_EQUALIZATION_TRIGGER_DEEP_CYCLES
int "Equalization deep cycle count trigger" if BAT_TYPE_CUSTOM && CELL_EQUALIZATION
int "Equalization deep cycle count trigger" if CELL_EQUALIZATION
default 10
help
After specified number of deep discharges, an equalization charge is triggered.
config CELL_TEMP_COMPENSATION_MV_K
int "Cell voltage temperature compenstaion (mV/K)" if BAT_TYPE_CUSTOM
int "Cell voltage temperature compenstaion (mV/K)"
range -5 0
default -3
help
Suggested value: -3 mV/K/cell for lead-acid batteries, 0 for Li-ion batteries
config CELL_INTERNAL_RESISTANCE_MOHM
int "Cell internal resistance (mOhm)" if BAT_TYPE_CUSTOM
int "Cell internal resistance (mOhm)"
range 1 30
default 5
endmenu # Custom cell-level settings
menu "Custom temperature settings"
depends on BAT_TYPE_CUSTOM
config BAT_CHARGE_TEMP_MAX
int "Maximum charge temperature (°C)" if BAT_TYPE_CUSTOM
int "Maximum charge temperature (°C)"
range 0 60
default 50
config BAT_CHARGE_TEMP_MIN
int "Minimum charge temperature (°C)" if BAT_TYPE_CUSTOM
int "Minimum charge temperature (°C)"
range -10 20
default 0
config BAT_DISCHARGE_TEMP_MAX
int "Maximum discharge temperature (°C)" if BAT_TYPE_CUSTOM
int "Maximum discharge temperature (°C)"
range 0 60
default 50
config BAT_DISCHARGE_TEMP_MIN
int "Minimum discharge temperature (°C)" if BAT_TYPE_CUSTOM
int "Minimum discharge temperature (°C)"
range -20 20
default -10