From 4e6f6c7365798aef31fec43b272ccddbbbab63c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Sun, 5 Apr 2020 10:55:51 +0200 Subject: [PATCH] Move thermal model parameters to DTS --- boards/Kconfig | 167 +++++++++++++++++- boards/Kconfig.hidden | 67 ------- boards/Kconfig.user | 146 --------------- .../mppt_1210_hus_0v4/mppt_1210_hus_0v4.dts | 2 +- .../mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts | 2 +- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 2 +- .../mppt_2420_lc_0v10/mppt_2420_lc_0v10.dts | 2 +- boards/arm/pwm_2420_lus_0v3/board.h | 6 - .../arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts | 7 +- src/dcdc.cpp | 4 +- src/load.cpp | 15 +- test/board.h | 10 +- test/tests_load.cpp | 2 +- zephyr/dts/bindings/charge-controller.yaml | 31 ++++ 14 files changed, 220 insertions(+), 243 deletions(-) delete mode 100644 boards/Kconfig.hidden delete mode 100644 boards/Kconfig.user diff --git a/boards/Kconfig b/boards/Kconfig index 15e4eeb..05f2b41 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -1,9 +1,170 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (c) 2019 Martin Jäger (Libre Solar) + # -# Generic Libre Solar Charge Controller configuration +# Invisible (board-specific) Kconfig symbols # -rsource "Kconfig.hidden" +config HAS_LOAD_OUTPUT + bool + help + PCB has a load output. -rsource "Kconfig.user" +config HAS_USB_PWR_OUTPUT + bool + help + PCB has a USB power output. + +config CONTROL_FREQUENCY + int + default 10 + help + Main control function frequency (Hz) + + Frequencies higher than 10 Hz caused issues with MPPT control during lab test with + PV simulator. Might be different with actual solar panel. + + +# +# Visible (user-configurable) Kconfig symbols +# + +choice + prompt "High-voltage terminal" + depends on $(dt_compat_enabled,dcdc) + help + Select the device connected to the high-voltage + side terminal of the DC/DC converter. + + config HV_TERMINAL_SOLAR + bool "Solar panel" + + config HV_TERMINAL_NANOGRID + bool "DC nanogrid" + + config HV_TERMINAL_GENERATOR + bool "DC generator, e.g. wind turbine" + + config HV_TERMINAL_BATTERY + bool "Battery, e.g. electric bicycle" +endchoice + + +choice + prompt "Low-voltage terminal" + help + Select the device connected to the low-voltage side + of the charge controller (usually battery terminal). + + config LV_TERMINAL_BATTERY + depends on !HV_TERMINAL_BATTERY + bool "Battery 12V/24V" + + config LV_TERMINAL_SOLAR + depends on HV_TERMINAL_BATTERY || HV_TERMINAL_NANOGRID + bool "Solar panel" +endchoice + + +choice + prompt "PWM terminal" + depends on $(dt_compat_enabled,pwm-switch) + help + Select the device connected to the PWM switch (currently + only solar panel possible) + + config PWM_TERMINAL_SOLAR + depends on LV_TERMINAL_BATTERY && !HV_TERMINAL_SOLAR + bool "Solar panel" +endchoice + + +menu "Battery configuration" + +choice + prompt "Default battery cell type" + default BAT_DEFAULT_TYPE_GEL + help + Select the type of the single cells inside the battery + to determine voltage set points. Total voltage set points + are multiplied with the selected number of cells. + + config BAT_DEFAULT_TYPE_FLOODED + bool "Flooded (wet) lead-acid" + + config BAT_DEFAULT_TYPE_GEL + bool "VRLA gel, maintainance-free" + + config BAT_DEFAULT_TYPE_AGM + bool "AGM, maintainance-free" + + config BAT_DEFAULT_TYPE_LFP + bool "LiFePO4 Li-ion, 3.3V nominal" + + config BAT_DEFAULT_TYPE_NMC + bool "NMC/Graphite Li-ion, 3.7V nominal, 4.2V max" + + config BAT_DEFAULT_TYPE_NMC_HV + bool "NMC/Graphite High Voltage Li-ion, 3.7V nominal, 4.35 max" + +endchoice + +config BAT_DEFAULT_NUM_CELLS + int "Default number of battery cells" + default 6 + range 3 16 + help + Typical choices: + - 6 for 12V lead-acid battery + - 4 for 12V LiFePO4 battery + - 3 for 12V NMC Li-ion battery + + Remarks: + - If you choose settings for 12V system, 24V systems + (2 batteries in series) are recognized automatically + - Make sure the voltage of the used charge controller + is not exceeded. + +config BAT_DEFAULT_CAPACITY_AH + int "Default battery capacity in Ah" + range 10 200 + default 50 + +endmenu + + +menu "Extensions and interfaces" + +config EXT_OLED_DISPLAY + bool "OLED display at UEXT" + +config EXT_OLED_BRIGHTNESS + depends on EXT_OLED_DISPLAY + int "OLED display brightness" + range 1 255 + default 1 + +config EXT_THINGSET_SERIAL + bool "ThingSet serial interface" + +config EXT_THINGSET_SERIAL_RX_BUF_SIZE + depends on EXT_THINGSET_SERIAL + int "ThingSet serial RX buffer size" + range 64 2048 + default 512 + +config EXT_THINGSET_SERIAL_TX_BUF_SIZE + depends on EXT_THINGSET_SERIAL + int "ThingSet serial TX buffer size" + range 256 2048 + default 1024 + +config EXT_THINGSET_CAN + depends on CAN + bool "ThingSet CAN interface" + +config DEVICE_ID + int "Initial device ID for communication interfaces" + default 0 + +endmenu diff --git a/boards/Kconfig.hidden b/boards/Kconfig.hidden deleted file mode 100644 index 8dabc84..0000000 --- a/boards/Kconfig.hidden +++ /dev/null @@ -1,67 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright (c) 2019 Martin Jäger (Libre Solar) -# -# Invisible (hardware-specific) Kconfig symbols -# - -config DEVICE_TYPE - string - help - Device type name, e.g. MPPT-2420-LC - -config HARDWARE_VERSION - string - help - Version of the PCB - -config HAS_LOAD_OUTPUT - bool - help - PCB has a load output. - -config HAS_USB_PWR_OUTPUT - bool - help - PCB has a USB power output. - -config CONTROL_FREQUENCY - int - default 10 - help - Main control function frequency (Hz) - - Frequencies higher than 10 Hz caused issues with MPPT control during lab test with - PV simulator. Might be different with actual solar panel. - -config MOSFET_MAX_JUNCTION_TEMP - int - default 120 - help - Maximum Tj of MOSFETs (°C) - - This value is used for model-based control of overcurrent protection. It represents - the steady-state junction temperature for max. continuous current at ambient - temperature of 25°C. - -config INTERNAL_MAX_REFERENCE_TEMP - int - default 50 - help - Internal reference temperature at full load (°C) - - This value is used for model-based control of overcurrent protection. It represents - the steady-state internal temperature for max. continuous current at ambient - temperature of 25°C. Value here is conservative and can be overwritten in PCB - configuration. - -config MOSFET_THERMAL_TIME_CONSTANT - int - default 5 - help - Thermal time constant junction to ambient (s) - - This value is used for model-based control of overcurrent protection. It does not reflect - the much lower MOSFET-internal time constant junction to case, but includes thermal - inertia of the board. - - Around 5s seems to be a good conservative estimation for 5x6 type SMD MOSFETs diff --git a/boards/Kconfig.user b/boards/Kconfig.user deleted file mode 100644 index f2e2713..0000000 --- a/boards/Kconfig.user +++ /dev/null @@ -1,146 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright (c) 2019 Martin Jäger (Libre Solar) -# -# Visible (user-configurable) Kconfig symbols -# - - -choice - prompt "High-voltage terminal" - depends on $(dt_compat_enabled,dcdc) - help - Select the device connected to the high-voltage - side terminal of the DC/DC converter. - - config HV_TERMINAL_SOLAR - bool "Solar panel" - - config HV_TERMINAL_NANOGRID - bool "DC nanogrid" - - config HV_TERMINAL_GENERATOR - bool "DC generator, e.g. wind turbine" - - config HV_TERMINAL_BATTERY - bool "Battery, e.g. electric bicycle" -endchoice - - -choice - prompt "Low-voltage terminal" - help - Select the device connected to the low-voltage side - of the charge controller (usually battery terminal). - - config LV_TERMINAL_BATTERY - depends on !HV_TERMINAL_BATTERY - bool "Battery 12V/24V" - - config LV_TERMINAL_SOLAR - depends on HV_TERMINAL_BATTERY || HV_TERMINAL_NANOGRID - bool "Solar panel" -endchoice - - -choice - prompt "PWM terminal" - depends on $(dt_compat_enabled,pwm-switch) - help - Select the device connected to the PWM switch (currently - only solar panel possible) - - config PWM_TERMINAL_SOLAR - depends on LV_TERMINAL_BATTERY && !HV_TERMINAL_SOLAR - bool "Solar panel" -endchoice - - -menu "Battery configuration" - -choice - prompt "Default battery cell type" - default BAT_DEFAULT_TYPE_GEL - help - Select the type of the single cells inside the battery - to determine voltage set points. Total voltage set points - are multiplied with the selected number of cells. - - config BAT_DEFAULT_TYPE_FLOODED - bool "Flooded (wet) lead-acid" - - config BAT_DEFAULT_TYPE_GEL - bool "VRLA gel, maintainance-free" - - config BAT_DEFAULT_TYPE_AGM - bool "AGM, maintainance-free" - - config BAT_DEFAULT_TYPE_LFP - bool "LiFePO4 Li-ion, 3.3V nominal" - - config BAT_DEFAULT_TYPE_NMC - bool "NMC/Graphite Li-ion, 3.7V nominal, 4.2V max" - - config BAT_DEFAULT_TYPE_NMC_HV - bool "NMC/Graphite High Voltage Li-ion, 3.7V nominal, 4.35 max" - -endchoice - -config BAT_DEFAULT_NUM_CELLS - int "Default number of battery cells" - default 6 - range 3 16 - help - Typical choices: - - 6 for 12V lead-acid battery - - 4 for 12V LiFePO4 battery - - 3 for 12V NMC Li-ion battery - - Remarks: - - If you choose settings for 12V system, 24V systems - (2 batteries in series) are recognized automatically - - Make sure the voltage of the used charge controller - is not exceeded. - -config BAT_DEFAULT_CAPACITY_AH - int "Default battery capacity in Ah" - range 10 200 - default 50 - -endmenu - - -menu "Extensions and interfaces" - -config EXT_OLED_DISPLAY - bool "OLED display at UEXT" - -config EXT_OLED_BRIGHTNESS - depends on EXT_OLED_DISPLAY - int "OLED display brightness" - range 1 255 - default 1 - -config EXT_THINGSET_SERIAL - bool "ThingSet serial interface" - -config EXT_THINGSET_SERIAL_RX_BUF_SIZE - depends on EXT_THINGSET_SERIAL - int "ThingSet serial RX buffer size" - range 64 2048 - default 512 - -config EXT_THINGSET_SERIAL_TX_BUF_SIZE - depends on EXT_THINGSET_SERIAL - int "ThingSet serial TX buffer size" - range 256 2048 - default 1024 - -config EXT_THINGSET_CAN - depends on CAN - bool "ThingSet CAN interface" - -config DEVICE_ID - int "Initial device ID for communication interfaces" - default 0 - -endmenu diff --git a/boards/arm/mppt_1210_hus_0v4/mppt_1210_hus_0v4.dts b/boards/arm/mppt_1210_hus_0v4/mppt_1210_hus_0v4.dts index a4191e2..28ec1f7 100755 --- a/boards/arm/mppt_1210_hus_0v4/mppt_1210_hus_0v4.dts +++ b/boards/arm/mppt_1210_hus_0v4/mppt_1210_hus_0v4.dts @@ -11,7 +11,7 @@ model = "Libre Solar MPPT 1210 HUS v0.4"; compatible = "st,stm32l073"; - charge-controller { + pcb { compatible = "charge-controller"; hs-voltage-max = <40>; ls-voltage-max = <16>; diff --git a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts index 4f70769..83b6c7e 100755 --- a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts +++ b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts @@ -11,7 +11,7 @@ model = "Libre Solar MPPT 1210 HUS v0.7"; compatible = "st,stm32l073"; - charge-controller { + pcb { compatible = "charge-controller"; hs-voltage-max = <40>; ls-voltage-max = <16>; diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index 6a5bd71..07c8c09 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -42,7 +42,7 @@ }; }; - charge-controller { + pcb { compatible = "charge-controller"; hs-voltage-max = <80>; ls-voltage-max = <32>; diff --git a/boards/arm/mppt_2420_lc_0v10/mppt_2420_lc_0v10.dts b/boards/arm/mppt_2420_lc_0v10/mppt_2420_lc_0v10.dts index f4f829b..86643f3 100755 --- a/boards/arm/mppt_2420_lc_0v10/mppt_2420_lc_0v10.dts +++ b/boards/arm/mppt_2420_lc_0v10/mppt_2420_lc_0v10.dts @@ -11,7 +11,7 @@ model = "Libre Solar MPPT 2420 LC v0.10"; compatible = "st,stm32f072"; - charge-controller { + pcb { compatible = "charge-controller"; hs-voltage-max = <55>; ls-voltage-max = <32>; diff --git a/boards/arm/pwm_2420_lus_0v3/board.h b/boards/arm/pwm_2420_lus_0v3/board.h index 9e3b274..fb93229 100644 --- a/boards/arm/pwm_2420_lus_0v3/board.h +++ b/boards/arm/pwm_2420_lus_0v3/board.h @@ -17,12 +17,6 @@ #define LOAD_CURRENT_MAX 15 // PCB maximum load switch current -// The MCU, where internal temperature is measured, is close to the MOSFETs. Tests showed that -// temperature at heat sink is only 10-20°C above measured internal temp. As PWM CC doesn't -// use electrolytic cap for core charging function, internal temperature of 70°C can be allowed. -// This value is used for thermal overcurrent model. -#define INTERNAL_MAX_REFERENCE_TEMP 70 - #define PIN_UEXT_TX PA_2 #define PIN_UEXT_RX PA_3 #define PIN_UEXT_SCL PB_6 diff --git a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts index 1964a0d..612187c 100644 --- a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts +++ b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts @@ -11,10 +11,15 @@ model = "Libre Solar PWM 2420 LUS v0.3"; compatible = "st,stm32l073"; - charge-controller { + pcb { compatible = "charge-controller"; hs-voltage-max = <55>; ls-voltage-max = <32>; + // The MCU, where internal temperature is measured, is close to the MOSFETs. Tests + // showed that temperature at heat sink is only 10-20°C above measured internal + // temp. As PWM CC doesn't use electrolytic cap for core charging function, + // internal temperature of 70°C can be allowed (instead of default 50°C). + internal-tref-max = <70>; }; pwm-switch { diff --git a/src/dcdc.cpp b/src/dcdc.cpp index a10afd4..fa8de6b 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -39,8 +39,8 @@ Dcdc::Dcdc(PowerPort *hv_side, PowerPort *lv_side, DcdcOperationMode op_mode) lvs->neg_current_limit = -DT_INST_0_DCDC_CURRENT_MAX; lvs->pos_current_limit = DT_INST_0_DCDC_CURRENT_MAX; ls_current_max = DT_INST_0_DCDC_CURRENT_MAX; - hs_voltage_max = DT_INST_0_CHARGE_CONTROLLER_HS_VOLTAGE_MAX; - ls_voltage_max = DT_INST_0_CHARGE_CONTROLLER_LS_VOLTAGE_MAX; + hs_voltage_max = DT_CHARGE_CONTROLLER_PCB_HS_VOLTAGE_MAX; + ls_voltage_max = DT_CHARGE_CONTROLLER_PCB_LS_VOLTAGE_MAX; ls_voltage_min = 9.0; output_power_min = 1; // switch off if power < 1 W restart_interval = 60; diff --git a/src/load.cpp b/src/load.cpp index d9023eb..a57c9b7 100644 --- a/src/load.cpp +++ b/src/load.cpp @@ -43,13 +43,12 @@ void LoadOutput::control() // junction temperature calculation model for overcurrent detection junction_temperature = junction_temperature + ( - dev_stat.internal_temp - junction_temperature + - current * current / - (LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * - (CONFIG_MOSFET_MAX_JUNCTION_TEMP - CONFIG_INTERNAL_MAX_REFERENCE_TEMP) - ) / (CONFIG_MOSFET_THERMAL_TIME_CONSTANT * CONFIG_CONTROL_FREQUENCY); + dev_stat.internal_temp - junction_temperature + current * current / + (LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * + (DT_CHARGE_CONTROLLER_PCB_MOSFETS_TJ_MAX - DT_CHARGE_CONTROLLER_PCB_INTERNAL_TREF_MAX) + ) / (DT_CHARGE_CONTROLLER_PCB_MOSFETS_TAU_JA * CONFIG_CONTROL_FREQUENCY); - if (junction_temperature > CONFIG_MOSFET_MAX_JUNCTION_TEMP || + if (junction_temperature > DT_CHARGE_CONTROLLER_PCB_MOSFETS_TJ_MAX || current > LOAD_CURRENT_MAX * 2) { flags_set(&error_flags, ERR_LOAD_OVERCURRENT); @@ -69,7 +68,7 @@ void LoadOutput::control() // long-term overvoltage (overvoltage transients are detected as an ADC alert and switch // off the solar input instead of the load output) if (bus->voltage > overvoltage || bus->voltage > - DT_INST_0_CHARGE_CONTROLLER_LS_VOLTAGE_MAX) + DT_CHARGE_CONTROLLER_PCB_LS_VOLTAGE_MAX) { ov_debounce_counter++; if (ov_debounce_counter > CONFIG_CONTROL_FREQUENCY) { @@ -108,7 +107,7 @@ void LoadOutput::control() if (flags_check(&error_flags, ERR_LOAD_OVERVOLTAGE) && bus->voltage < (overvoltage - ov_hysteresis) && - bus->voltage < (DT_INST_0_CHARGE_CONTROLLER_LS_VOLTAGE_MAX - ov_hysteresis)) + bus->voltage < (DT_CHARGE_CONTROLLER_PCB_LS_VOLTAGE_MAX - ov_hysteresis)) { flags_clear(&error_flags, ERR_LOAD_OVERVOLTAGE); } diff --git a/test/board.h b/test/board.h index 495a9a9..c849212 100644 --- a/test/board.h +++ b/test/board.h @@ -42,14 +42,14 @@ // Values that are otherwise defined by Kconfig #define CONFIG_CONTROL_FREQUENCY 10 // Hz -#define CONFIG_MOSFET_MAX_JUNCTION_TEMP 120 -#define CONFIG_INTERNAL_MAX_REFERENCE_TEMP 50 -#define CONFIG_MOSFET_THERMAL_TIME_CONSTANT 5 +#define DT_CHARGE_CONTROLLER_PCB_MOSFETS_TJ_MAX 120 +#define DT_CHARGE_CONTROLLER_PCB_INTERNAL_TREF_MAX 50 +#define DT_CHARGE_CONTROLLER_PCB_MOSFETS_TAU_JA 5 #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current -#define DT_INST_0_CHARGE_CONTROLLER_LS_VOLTAGE_MAX 32 // Maximum voltage at battery port (V) -#define DT_INST_0_CHARGE_CONTROLLER_HS_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) +#define DT_CHARGE_CONTROLLER_PCB_LS_VOLTAGE_MAX 32 // Maximum voltage at battery port (V) +#define DT_CHARGE_CONTROLLER_PCB_HS_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) #define PIN_UEXT_TX 0 #define PIN_UEXT_RX 0 diff --git a/test/tests_load.cpp b/test/tests_load.cpp index be3670d..ea37822 100644 --- a/test/tests_load.cpp +++ b/test/tests_load.cpp @@ -106,7 +106,7 @@ void control_on_to_off_overcurrent() TEST_ASSERT_EQUAL(LOAD_STATE_ON, load_out.state); // almost 2x current = 4x heat generation: Should definitely trigger after waiting one time constant - int trigger_steps = CONFIG_MOSFET_THERMAL_TIME_CONSTANT * CONFIG_CONTROL_FREQUENCY; + int trigger_steps = DT_CHARGE_CONTROLLER_PCB_MOSFETS_TAU_JA * CONFIG_CONTROL_FREQUENCY; for (int i = 0; i <= trigger_steps; i++) { load_out.control(); } diff --git a/zephyr/dts/bindings/charge-controller.yaml b/zephyr/dts/bindings/charge-controller.yaml index 80d480a..080643c 100644 --- a/zephyr/dts/bindings/charge-controller.yaml +++ b/zephyr/dts/bindings/charge-controller.yaml @@ -14,3 +14,34 @@ properties: type: int required: true description: Maximum voltage at low-side (typically battery) in volts + internal-tref-max: + type: int + default: 50 + description: | + Internal reference temperature at full load (°C) + + This value is used for model-based control of overcurrent protection. It represents + the steady-state internal temperature for max. continuous current at ambient + temperature of 25°C. Default value is conservative and can be overwritten in PCB + configuration. + mosfets-tj-max: + type: int + default: 120 + description: | + Maximum Tj of MOSFETs (°C) + + This value is used for model-based control of overcurrent protection. It represents + the steady-state junction temperature for max. continuous current at ambient + temperature of 25°C. + mosfets-tau-ja: + type: int + default: 5 + description: | + Thermal time constant junction to ambient (s) + + This value is used for model-based control of overcurrent protection. It does not reflect + the much lower MOSFET-internal time constant junction to case, but includes thermal + inertia of the board. + + Around 5s seems to be a good conservative estimation for 5x6 type SMD MOSFETs. Take larger + values for big heat sinks.