Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISL94202 driver init and Kconfig fixes #45

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ config CELL_TYPE
default 3 if CELL_TYPE_NMC_HV
default 4 if CELL_TYPE_LTO

config NUM_CELLS_IN_SERIES
int "Number of cells for single battery"
default 3 if CELL_TYPE_NMC || CELL_TYPE_NMC_HV
default 4 if CELL_TYPE_LFP
default 5 if CELL_TYPE_LTO
range 3 16
help
Typical choices:
- 3 for 12V NMC Li-Ion battery
- 4 for 12V LiFePO4 battery
- 5 for 12V Titanate battery

endmenu

# include main Zephyr menu entries from Zephyr root directory
Expand Down
3 changes: 0 additions & 3 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ CONFIG_THINGSET_NODE_NAME="Libre Solar BMS"

# Select cell type for initial configuration: LFP (default), NMC, NMC_HV or LTO
#CONFIG_CELL_TYPE_???=y

# Manually define number of cells connected in series (only necessary for boards with ISL94202)
#CONFIG_NUM_CELLS_IN_SERIES=?
5 changes: 2 additions & 3 deletions docs/src/dev/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ By default, the BMS is configured for LiFePO4 cells (``CONFIG_CELL_TYPE_LFP``).
Possible other pre-defined options are ``CONFIG_BAT_TYPE_NMC``, ``CONFIG_BAT_TYPE_NMC_HV`` and
``CONFIG_BAT_TYPE_LTO``.

The number of cells only has to be specified via ``CONFIG_NUM_CELLS_IN_SERIES`` for boards with the
ISL94202 chip. For all other chips it is detected automatically and the setting is ignored.
The number of cells only has to be specified via ``CONFIG_BMS_IC_ISL94202_NUM_CELLS`` for boards
with the ISL94202 chip. For all other chips it is detected automatically.

To compile the firmware with default settings e.g. for a 24V LiFePO4 battery with a nominal capacity
of 100Ah, add the following to ``prj.conf`` or the board-specific ``.conf`` file:
Expand All @@ -48,7 +48,6 @@ of 100Ah, add the following to ``prj.conf`` or the board-specific ``.conf`` file

CONFIG_BAT_CAPACITY_AH=100
CONFIG_CELL_TYPE_LFP=y
CONFIG_NUM_CELLS_IN_SERIES=8

Configure serial interface
""""""""""""""""""""""""""
Expand Down
13 changes: 13 additions & 0 deletions drivers/bms_ic/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ config BMS_IC_ISL94202
help
Driver for Intersil/Renesas ISL94202.

config BMS_IC_ISL94202_NUM_CELLS
int "Exact number of cells in series"
range 3 8
default 8
help
The exact number of cells used by the application is needed for configuration of the chip.

Typical choices:
- 3 for 12V NMC Li-Ion battery
- 4 for 12V LiFePO4 battery
- 5 for 12V Titanate battery
- 8 for 24V LiFePO4 battery

config BMS_IC_CURRENT_MONITORING
bool "Use BMS IC current monitoring"
depends on BMS_IC_HAS_CURRENT_MONITORING
Expand Down
67 changes: 41 additions & 26 deletions drivers/bms_ic/isl94202/isl94202.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,70 +590,85 @@ static int bms_ic_isl94202_balance(const struct device *dev, uint32_t cells)
return err;
}

static int bms_ic_isl94202_set_mode(const struct device *dev, enum bms_ic_mode mode)
{
uint8_t reg;

switch (mode) {
case BMS_IC_MODE_OFF:
reg = ISL94202_CTRL3_PDWN_Msk;
isl94202_write_bytes(dev, ISL94202_CTRL3, &reg, 1);
return 0;
default:
return -ENOTSUP;
}
}

static int isl94202_init(const struct device *dev)
static int isl94202_activate(const struct device *dev)
{
const struct bms_ic_isl94202_config *dev_config = dev->config;
uint8_t reg;
int err;

if (!i2c_is_ready_dt(&dev_config->i2c)) {
LOG_ERR("I2C device not ready");
return -ENODEV;
}
if (!gpio_is_ready_dt(&dev_config->i2c_pullup)) {
LOG_ERR("I2C pull-up GPIO not ready");
return -ENODEV;
}

/* Datasheet: 3 seconds wake-up delay from shutdown or initial power-up */
k_sleep(K_SECONDS(3));
k_sleep(K_TIMEOUT_ABS_MS(3000));

/* activate pull-up at I2C SDA and SCL */
gpio_pin_configure_dt(&dev_config->i2c_pullup, GPIO_OUTPUT_ACTIVE);

err = set_num_cells(dev, CONFIG_NUM_CELLS_IN_SERIES);
err = set_num_cells(dev, CONFIG_BMS_IC_ISL94202_NUM_CELLS);
if (err) {
LOG_ERR("Failed to set number of cells: %d", err);
return err;
}

// xTemp2 monitoring MOSFETs and not cells
reg = ISL94202_SETUP0_XT2M_Msk;
err = isl94202_write_bytes(dev, ISL94202_SETUP0, &reg, 1);
if (err) {
LOG_ERR("Failed to set xTemp2 MOSFET monitoring: %d", err);
return err;
}

// Enable balancing during charging and EOC conditions
reg = ISL94202_SETUP1_CBDC_Msk | ISL94202_SETUP1_CB_EOC_Msk;
err = isl94202_write_bytes(dev, ISL94202_SETUP1, &reg, 1);
if (err) {
LOG_ERR("Failed to set balancing setup: %d", err);
return err;
}

// Enable FET control via microcontroller
reg = ISL94202_CTRL2_UCFET_Msk;
err = isl94202_write_bytes(dev, ISL94202_CTRL2, &reg, 1);
if (err) {
LOG_ERR("Failed to enable MCU FET control: %d", err);
return err;
}

// Remark: Ideal diode control via DFODOV and DFODUV bits of SETUP1 register doesn't have any
// effect because of FET control via microcontroller.

LOG_INF("Activated ISL94202");

return 0;
}

static int bms_ic_isl94202_set_mode(const struct device *dev, enum bms_ic_mode mode)
{
uint8_t reg;

switch (mode) {
case BMS_IC_MODE_ACTIVE:
return isl94202_activate(dev);
case BMS_IC_MODE_OFF:
reg = ISL94202_CTRL3_PDWN_Msk;
isl94202_write_bytes(dev, ISL94202_CTRL3, &reg, 1);
return 0;
default:
return -ENOTSUP;
}
}

static int isl94202_init(const struct device *dev)
{
const struct bms_ic_isl94202_config *dev_config = dev->config;

if (!i2c_is_ready_dt(&dev_config->i2c)) {
LOG_ERR("I2C device not ready");
return -ENODEV;
}
if (!gpio_is_ready_dt(&dev_config->i2c_pullup)) {
LOG_ERR("I2C pull-up GPIO not ready");
return -ENODEV;
}

return 0;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ CONFIG_BAT_CAPACITY_AH=100
# Select cell type for initial configuration: LFP (default), NMC, NMC_HV or LTO
CONFIG_CELL_TYPE_LFP=y

# Change number of cells connected in series (matching 12V battery by default if not set)
CONFIG_NUM_CELLS_IN_SERIES=8

CONFIG_BMS_IC=y
CONFIG_BMS_IC_MAX_THERMISTORS=2
2 changes: 2 additions & 0 deletions tests/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void setup()
{
bms_ic_assign_data(bms_ic, &bms.ic_data);

bms_ic_set_mode(bms_ic, BMS_IC_MODE_ACTIVE);

bms.ic_conf.dis_sc_limit = 35.0;
bms.ic_conf.dis_sc_delay_us = 200;

Expand Down
Loading