diff --git a/.travis.yml b/.travis.yml index 9b1a0f4..634fa74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ addons: script: # check for trailing white spaces (comparing with first commit in git log) - git diff --check `git rev-list HEAD | tail -n 1`..$TRAVIS_BRANCH - - cp src/config.h_template src/config.h - platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 - platformio test -e unit-test-native - platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 diff --git a/README.md b/README.md index 88c819b..5db2e39 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ It is suggested to use Visual Studio Code and PlatformIO for firmware developmen 1. Install Visual Studio Code and [PlatformIO](https://platformio.org/platformio-ide) to build the firmware. -2. Copy `src/config.h_template` to `src/config.h`, and adjust basic settings. `config.h` is ignored by git, so your changes are kept after software updates using `git pull`. +2. Adjust configuration in `zephyr/prj.conf` if necessary. 3. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` or create a file `custom.ini` with your personal settings. diff --git a/boards/Kconfig.hidden b/boards/Kconfig.hidden index bc65285..8560c0a 100644 --- a/boards/Kconfig.hidden +++ b/boards/Kconfig.hidden @@ -62,3 +62,45 @@ config HIGH_SIDE_VOLTAGE_MAX int help High side (usually solar panel) voltage maximum. + +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/arm/mppt_1210_hus_0v4/CMakeLists.txt b/boards/arm/mppt_1210_hus_0v4/CMakeLists.txt index d1b8108..ac5a362 100755 --- a/boards/arm/mppt_1210_hus_0v4/CMakeLists.txt +++ b/boards/arm/mppt_1210_hus_0v4/CMakeLists.txt @@ -5,3 +5,5 @@ zephyr_library() zephyr_library_sources(pinmux.c) zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) endif() + +zephyr_include_directories(.) diff --git a/src/pcbs/mppt_1210_hus_0v4.h b/boards/arm/mppt_1210_hus_0v4/board.h similarity index 88% rename from src/pcbs/mppt_1210_hus_0v4.h rename to boards/arm/mppt_1210_hus_0v4/board.h index 19e1d9f..33aa45c 100644 --- a/src/pcbs/mppt_1210_hus_0v4.h +++ b/boards/arm/mppt_1210_hus_0v4/board.h @@ -7,21 +7,11 @@ #ifndef MPPT_1210_HUS_0V4_H #define MPPT_1210_HUS_0V4_H -#ifdef __MBED__ -#include "mbed.h" -#elif defined(__ZEPHYR__) #include -#endif #define DEVICE_TYPE "MPPT-1210-HUS" #define HARDWARE_VERSION "v0.4" -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 1 -#define CONFIG_HAS_PWM_SWITCH 0 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 1 - // DC/DC converter settings #define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency #define PWM_DEADTIME 230 // ns @@ -64,16 +54,9 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; // LED pins and pin state configuration to switch above LEDs on #define NUM_LED_PINS 5 -#ifdef __MBED__ -static const PinName led_pins[NUM_LED_PINS] = { - // GND SOC12 SOC3 RXTX LOAD - PB_14, PB_13, PB_2, PB_11, PB_10 -}; -#elif defined(__ZEPHYR__) // defined in board definition pinmux.c extern const char *led_ports[CONFIG_NUM_LED_PINS]; extern const int led_pins[CONFIG_NUM_LED_PINS]; -#endif // MBED or ZEPHYR const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { { PIN_HIGH, PIN_LOW, PIN_LOW, PIN_LOW, PIN_LOW }, // LED1 diff --git a/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt b/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt index d1b8108..ac5a362 100755 --- a/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt +++ b/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt @@ -5,3 +5,5 @@ zephyr_library() zephyr_library_sources(pinmux.c) zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) endif() + +zephyr_include_directories(.) diff --git a/src/pcbs/mppt_1210_hus_0v7.h b/boards/arm/mppt_1210_hus_0v7/board.h similarity index 88% rename from src/pcbs/mppt_1210_hus_0v7.h rename to boards/arm/mppt_1210_hus_0v7/board.h index c1ca049..1c9fc09 100644 --- a/src/pcbs/mppt_1210_hus_0v7.h +++ b/boards/arm/mppt_1210_hus_0v7/board.h @@ -7,21 +7,11 @@ #ifndef MPPT_1210_HUS_0V7_H #define MPPT_1210_HUS_0V7_H -#ifdef __MBED__ -#include "mbed.h" -#elif defined(__ZEPHYR__) #include -#endif #define DEVICE_TYPE "MPPT-1210-HUS" #define HARDWARE_VERSION "v0.7.1" -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 1 -#define CONFIG_HAS_PWM_SWITCH 0 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 1 - // DC/DC converter settings #define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency #define PWM_DEADTIME 230 // ns @@ -73,16 +63,9 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; // LED pins and pin state configuration to switch above LEDs on #define NUM_LED_PINS 3 -#ifdef __MBED__ -static const PinName led_pins[NUM_LED_PINS] = { - // A B C - PB_13, PB_2, PB_14 -}; -#elif defined(__ZEPHYR__) // defined in board definition pinmux.c extern const char *led_ports[CONFIG_NUM_LED_PINS]; extern const int led_pins[CONFIG_NUM_LED_PINS]; -#endif // MBED or ZEPHYR static const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { { PIN_HIGH, PIN_LOW, PIN_FLOAT }, // LED1 diff --git a/boards/arm/mppt_2420_hpx/CMakeLists.txt b/boards/arm/mppt_2420_hpx/CMakeLists.txt index d1b8108..ac5a362 100644 --- a/boards/arm/mppt_2420_hpx/CMakeLists.txt +++ b/boards/arm/mppt_2420_hpx/CMakeLists.txt @@ -5,3 +5,5 @@ zephyr_library() zephyr_library_sources(pinmux.c) zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) endif() + +zephyr_include_directories(.) diff --git a/boards/arm/mppt_2420_hpx/Kconfig.defconfig b/boards/arm/mppt_2420_hpx/Kconfig.defconfig index e406bb4..e201b37 100644 --- a/boards/arm/mppt_2420_hpx/Kconfig.defconfig +++ b/boards/arm/mppt_2420_hpx/Kconfig.defconfig @@ -18,8 +18,8 @@ config DCDC_PWM_DEADTIME_NS config HAS_LOAD_OUTPUT default y -#config HAS_PWM_SWITCH -# default y +config HAS_PWM_SWITCH + default y config NUM_LED_PINS default 1 diff --git a/src/pcbs/mppt_2420_hpx_0v1.h b/boards/arm/mppt_2420_hpx/board.h similarity index 92% rename from src/pcbs/mppt_2420_hpx_0v1.h rename to boards/arm/mppt_2420_hpx/board.h index d49cc8a..75ac4cf 100644 --- a/src/pcbs/mppt_2420_hpx_0v1.h +++ b/boards/arm/mppt_2420_hpx/board.h @@ -7,21 +7,11 @@ #ifndef MPPT_2420_HPX_0V1_H #define MPPT_2420_HPX_0V1_H -#ifdef __MBED__ -#include "mbed.h" -#elif defined(__ZEPHYR__) #include -#endif #define DEVICE_TYPE "MPPT-2420-HPX" #define HARDWARE_VERSION "v0.1" -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 1 -#define CONFIG_HAS_PWM_SWITCH 0 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 0 - // DC/DC converter settings #define PWM_FREQUENCY 70 // kHz #define PWM_DEADTIME 300 // ns @@ -29,6 +19,7 @@ #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current +#define PWM_CURRENT_MAX 20 // PCB maximum PWM switch (solar) current #define LOW_SIDE_VOLTAGE_MAX 16 // Maximum voltage at battery port (V) #define HIGH_SIDE_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) diff --git a/boards/arm/mppt_2420_lc_0v10/CMakeLists.txt b/boards/arm/mppt_2420_lc_0v10/CMakeLists.txt index d1b8108..ac5a362 100755 --- a/boards/arm/mppt_2420_lc_0v10/CMakeLists.txt +++ b/boards/arm/mppt_2420_lc_0v10/CMakeLists.txt @@ -5,3 +5,5 @@ zephyr_library() zephyr_library_sources(pinmux.c) zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) endif() + +zephyr_include_directories(.) diff --git a/src/pcbs/mppt_2420_lc_0v10.h b/boards/arm/mppt_2420_lc_0v10/board.h similarity index 89% rename from src/pcbs/mppt_2420_lc_0v10.h rename to boards/arm/mppt_2420_lc_0v10/board.h index 335e290..46410c2 100644 --- a/src/pcbs/mppt_2420_lc_0v10.h +++ b/boards/arm/mppt_2420_lc_0v10/board.h @@ -10,17 +10,7 @@ #define DEVICE_TYPE "MPPT-2420-LC" #define HARDWARE_VERSION "v0.10" -#ifdef __MBED__ -#include "mbed.h" -#elif defined(__ZEPHYR__) #include -#endif - -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 1 -#define CONFIG_HAS_PWM_SWITCH 0 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 0 // DC/DC converter settings #define PWM_FREQUENCY 70 // kHz 70 = good compromise between output ripple and efficiency @@ -77,16 +67,9 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; // LED pins and pin state configuration to switch above LEDs on #define NUM_LED_PINS 2 -#ifdef __MBED__ -static const PinName led_pins[NUM_LED_PINS] = { - // PWR LOAD - PB_14, PB_15 -}; -#elif defined(__ZEPHYR__) // defined in board definition pinmux.c extern const char *led_ports[CONFIG_NUM_LED_PINS]; extern const int led_pins[CONFIG_NUM_LED_PINS]; -#endif // MBED or ZEPHYR static const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { { PIN_HIGH, PIN_LOW }, // LED1 diff --git a/boards/arm/pwm_2420_lus_0v3/CMakeLists.txt b/boards/arm/pwm_2420_lus_0v3/CMakeLists.txt index d1b8108..ac5a362 100644 --- a/boards/arm/pwm_2420_lus_0v3/CMakeLists.txt +++ b/boards/arm/pwm_2420_lus_0v3/CMakeLists.txt @@ -5,3 +5,5 @@ zephyr_library() zephyr_library_sources(pinmux.c) zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) endif() + +zephyr_include_directories(.) diff --git a/src/pcbs/pwm_2420_lus.h b/boards/arm/pwm_2420_lus_0v3/board.h similarity index 91% rename from src/pcbs/pwm_2420_lus.h rename to boards/arm/pwm_2420_lus_0v3/board.h index fb2fc32..753b171 100644 --- a/src/pcbs/pwm_2420_lus.h +++ b/boards/arm/pwm_2420_lus_0v3/board.h @@ -7,11 +7,7 @@ #ifndef PWM_2420_LUS_H #define PWM_2420_LUS_H -#ifdef __MBED__ -#include "mbed.h" -#elif defined(__ZEPHYR__) #include -#endif #define DEVICE_TYPE "PWM-2420-LUS" @@ -21,12 +17,6 @@ #define HARDWARE_VERSION "v0.3" #endif -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 0 -#define CONFIG_HAS_PWM_SWITCH 1 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 1 - #define PWM_TIM 3 // use TIM3 timer #define PWM_FREQUENCY 50 // Hz @@ -82,16 +72,9 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; // LED pins and pin state configuration to switch above LEDs on #define NUM_LED_PINS 3 -#ifdef __MBED__ -static const PinName led_pins[NUM_LED_PINS] = { - // A B C - PB_13, PB_14, PB_15 -}; -#elif defined(__ZEPHYR__) // defined in board definition pinmux.c extern const char *led_ports[CONFIG_NUM_LED_PINS]; extern const int led_pins[CONFIG_NUM_LED_PINS]; -#endif // MBED or ZEPHYR #ifndef LEDS_WRONG_POLARITY static const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { diff --git a/check.bat b/check.bat index 1fe3a4d..6b2535b 100644 --- a/check.bat +++ b/check.bat @@ -10,18 +10,10 @@ if errorlevel 1 ( exit /b %errorlevel% ) -echo "---------- Preparation of config -------------" -if exist "src/config.h" ( - echo "Making backup of existing config" - move src\config.h src\config.h_backup_checksh -) -copy src\config.h_template src\config.h - echo "---------- Running compile check -------------" platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 -e pwm-2420-lus-v0.3-zephyr if errorlevel 1 ( echo Failure Reason is %errorlevel% - move src\config.h_backup_checksh src\config.h exit /b %errorlevel% ) @@ -29,7 +21,6 @@ echo "---------- Running unit-tests -------------" platformio test -e unit-test-native if errorlevel 1 ( echo Failure Reason is %errorlevel% - move src\config.h_backup_checksh src\config.h exit /b %errorlevel% ) @@ -37,10 +28,7 @@ echo "---------- Running static code checks -------------" platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 if errorlevel 1 ( echo Failure Reason is %errorlevel% - move src\config.h_backup_checksh src\config.h exit /b %errorlevel% ) -move src\config.h_backup_checksh src\config.h - echo "---------- All tests passed -------------" \ No newline at end of file diff --git a/check.sh b/check.sh index da26d3f..ea370d3 100755 --- a/check.sh +++ b/check.sh @@ -10,34 +10,22 @@ if [ $? != 0 ]; then exit 1; fi -echo "---------- Preparation of config -------------" -if [ -f "src/config.h" ]; then - echo "Making backup of existing config" - mv src/config.h src/config.h_backup_checksh -fi -cp src/config.h_template src/config.h - echo "---------- Running compile check -------------" platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 if [ $? != 0 ]; then - mv src/config.h_backup_checksh src/config.h exit 1; fi echo "---------- Running unit-tests -------------" platformio test -e unit-test-native if [ $? != 0 ]; then - mv src/config.h_backup_checksh src/config.h exit 1; fi echo "---------- Running static code checks -------------" platformio check -e mppt-1210-hus-v0.7 -e pwm-2420-lus-v0.3 if [ $? != 0 ]; then - mv src/config.h_backup_checksh src/config.h exit 1; fi -mv src/config.h_backup_checksh src/config.h - echo "---------- All tests passed -------------" diff --git a/platformio.ini b/platformio.ini index 6930809..2737a5e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -94,6 +94,7 @@ build_flags = -D UNIT_TEST -D __STDC_FORMAT_MACROS -D DEBUG_PRINT_FLAGS=0xF + -I test # include src directory (otherwise unit-tests will only include lib directory) test_build_project_src = true extra_scripts = diff --git a/src/bat_charger.cpp b/src/bat_charger.cpp index b4586a3..3416fde 100644 --- a/src/bat_charger.cpp +++ b/src/bat_charger.cpp @@ -9,8 +9,7 @@ #include // for fabs function #include -#include "config.h" -#include "pcb.h" +#include "board.h" #include "helper.h" #include "device_status.h" diff --git a/src/bl_support.h b/src/bl_support.h index a0c964f..13862d6 100644 --- a/src/bl_support.h +++ b/src/bl_support.h @@ -11,8 +11,6 @@ #ifdef BOOTLOADER_ENABLED -#include "config.h" - #include /** Length of the bootloader name string (including \0 termination) */ diff --git a/src/config.h_template b/src/config.h_template deleted file mode 100644 index e644f26..0000000 --- a/src/config.h_template +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef CONFIG_H -#define CONFIG_H - -#ifndef __ZEPHYR__ - -#include "pcb.h" - -/** @file - * - * @brief - * Used to define personal settings, e.g. which type of interface at the UEXT port should be used. - */ - -// PWM charge controller -#define CONFIG_PWM_TERMINAL_SOLAR CONFIG_HAS_PWM_SWITCH - -// MPPT buck/boost or nanogrid mode -#define CONFIG_HV_TERMINAL_SOLAR CONFIG_HAS_DCDC_CONVERTER -#define CONFIG_HV_TERMINAL_NANOGRID 0 - -// battery always assumed to be at low-voltage terminal (might need to be changed for boost mode) -#define CONFIG_LV_TERMINAL_BATTERY 1 - -// basic battery configuration -#define BATTERY_TYPE BAT_TYPE_GEL ///< GEL most suitable for general batteries (see bat_charger.h for other types) -#define BATTERY_NUM_CELLS 6 ///< For lead-acid batteries: 6 for 12V system, 12 for 24V system -#define BATTERY_CAPACITY 40 ///< Cell capacity or sum of parallel cells capacity (Ah) - -#define CONFIG_DEVICE_ID 12345678 - -// This enables a safety-feature for the MPPT charge controllers to blow the fuse and disable -// charging in case the HS MOSFET was shorted (e.g. by someone connecting a solar panel with -// too high voltage). -#define CONFIG_HS_MOSFET_FAIL_SAFE_PROTECTION 1 - -#define THINGSET_USER_PASSWORD "user123" -#define THINGSET_MAKER_PASSWORD "maker456" - -// can be used to configure custom data objects in separate file instead (e.g. data_objects_custom.cpp) -//#define CUSTOM_DATA_OBJECTS_FILE - -// OLED display at UEXT port -#define CONFIG_EXT_OLED_DISPLAY 1 -// OLED Brightness (value 0x01-0xff or 1-255) -// leave undefined to use default -#define OLED_BRIGHTNESS 0x1 - -// UART serial at SWD connector -#define CONFIG_EXT_THINGSET_SERIAL 1 - -// CAN bus drivers (not supported by all charge controllers) -#define CONFIG_EXT_THINGSET_CAN 0 - -// LoRa board RFM9x connected to UEXT port -// https://github.com/LibreSolar/UEXT_LoRa -//#define LORA_ENABLED - -// GSM board based on SIM800L connected to UEXT port -// https://github.com/LibreSolar/UEXT_GSM -//#define GSM_ENABLED -#define GSM_APN "internet.t-d1.de" // Access point name of network provider -#define GSM_NUMBER "" // empty if not needed -#define GSM_PIN "1234" // empty if not needed -#define GSM_USER "" // empty if not needed -#define GSM_PASS "" // empty if not needed - -// WiFi board based on ESP32 connected to UEXT port -//#define WIFI_ENABLED -#define WIFI_SSID "ssid" -#define WIFI_PASS "pass" - -// OpenEnergyMonitor emoncms configuration (used in WiFi interface) -#define EMONCMS_ENABLED -#define EMONCMS_HOST "" -#define EMONCMS_APIKEY "" // get from emoncms webinterface -#define EMONCMS_NODE "mppt" // name of your device - -// MQTT server configuration (used in GSM or WiFi interface) -#define MQTT_ENABLED -#define MQTT_HOST "your-host-or-ip" -#define MQTT_PORT "1883" -#define MQTT_USER "you" -#define MQTT_PASS "pass" -#define MQTT_PUBLISH_TOPIC "nodes2server/report" -#define MQTT_SUBSCRIBE_TOPIC "server2node/state-req" - -#endif - -#endif /* CONFIG_H */ diff --git a/src/daq.cpp b/src/daq.cpp index 546b51f..86641fa 100644 --- a/src/daq.cpp +++ b/src/daq.cpp @@ -9,18 +9,10 @@ #include // log for thermistor calculation #include -#ifdef __MBED__ -#include "mbed.h" -#endif - #include "mcu.h" #include "setup.h" #include "debug.h" -#include "pcb.h" // contains defines for pins - -#if defined(__MBED__) && defined(PIN_REF_I_DCDC) -AnalogOut ref_i_dcdc(PIN_REF_I_DCDC); -#endif +#include "board.h" // contains defines for pins static float solar_current_offset; static float load_current_offset; diff --git a/src/daq_driver.c b/src/daq_driver.c index 06d95ff..0814809 100644 --- a/src/daq_driver.c +++ b/src/daq_driver.c @@ -34,7 +34,7 @@ #include #endif -#include "pcb.h" +#include "board.h" #include "debug.h" #if !defined(CONFIG_SOC_SERIES_STM32F0X) && !defined(CONFIG_SOC_SERIES_STM32L0X) diff --git a/src/data_objects.cpp b/src/data_objects.cpp index 7c0053b..a9a8602 100644 --- a/src/data_objects.cpp +++ b/src/data_objects.cpp @@ -8,8 +8,7 @@ #include "setup.h" -#include "pcb.h" -#include "config.h" +#include "board.h" #include "version.h" // can be used to configure custom data objects in separate file instead diff --git a/src/dcdc.cpp b/src/dcdc.cpp index e8061e0..3de0b76 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -10,7 +10,7 @@ #include // for min/max function #include -#include "pcb.h" +#include "board.h" #include "device_status.h" #include "debug.h" #include "helper.h" @@ -190,7 +190,7 @@ void Dcdc::control() // high-side MOSFET must be broken --> set flag and let main() decide // what to do... (e.g. call dcdc_self_destruction) current_debounce_counter++; - if (current_debounce_counter > CONTROL_FREQUENCY) { // waited 1s before setting the flag + if (current_debounce_counter > CONFIG_CONTROL_FREQUENCY) { // waited 1s before setting the flag dev_stat.set_error(ERR_DCDC_HS_MOSFET_SHORT); } } @@ -201,7 +201,7 @@ void Dcdc::control() // wait at least 100 ms for voltages to settle static const int num_wait_calls = - (CONTROL_FREQUENCY / 10 >= 1) ? (CONTROL_FREQUENCY / 10) : 1; + (CONFIG_CONTROL_FREQUENCY / 10 >= 1) ? (CONFIG_CONTROL_FREQUENCY / 10) : 1; int startup_mode = check_start_conditions(); @@ -246,7 +246,7 @@ void Dcdc::test() // wait at least 100 ms for voltages to settle static const int num_wait_calls = - (CONTROL_FREQUENCY / 10 >= 1) ? (CONTROL_FREQUENCY / 10) : 1; + (CONFIG_CONTROL_FREQUENCY / 10 >= 1) ? (CONFIG_CONTROL_FREQUENCY / 10) : 1; if (startup_delay_counter > num_wait_calls) { if (check_start_conditions() != 0) { diff --git a/src/device_status.cpp b/src/device_status.cpp index a81c012..6f15cc5 100644 --- a/src/device_status.cpp +++ b/src/device_status.cpp @@ -9,8 +9,7 @@ #include // for fabs function #include -#include "config.h" -#include "pcb.h" +#include "board.h" #include "setup.h" #include "helper.h" diff --git a/src/eeprom.cpp b/src/eeprom.cpp index 9b10933..dba3ebd 100644 --- a/src/eeprom.cpp +++ b/src/eeprom.cpp @@ -9,7 +9,7 @@ #include #include "mcu.h" -#include "pcb.h" +#include "board.h" #include "thingset.h" #include "helper.h" diff --git a/src/ext/can.cpp b/src/ext/can.cpp index 3d5ae21..1b12582 100644 --- a/src/ext/can.cpp +++ b/src/ext/can.cpp @@ -6,8 +6,6 @@ #ifndef UNIT_TEST -#include "config.h" - #if CONFIG_EXT_THINGSET_CAN #include "ext.h" @@ -22,7 +20,7 @@ #include "mbed.h" #endif -#include "pcb.h" +#include "board.h" #include "thingset.h" #include "data_objects.h" #include "can_msg_queue.h" diff --git a/src/ext/can_msg_queue.cpp b/src/ext/can_msg_queue.cpp index bec4f7b..fddcfe8 100644 --- a/src/ext/can_msg_queue.cpp +++ b/src/ext/can_msg_queue.cpp @@ -6,8 +6,6 @@ #ifndef UNIT_TEST -#include "config.h" - #if CONFIG_EXT_THINGSET_CAN #include "ext/can_msg_queue.h" diff --git a/src/ext/oled.cpp b/src/ext/oled.cpp index 1ba0430..39c08c8 100644 --- a/src/ext/oled.cpp +++ b/src/ext/oled.cpp @@ -6,8 +6,6 @@ #ifndef UNIT_TEST -#include "config.h" - #if CONFIG_EXT_OLED_DISPLAY // otherwise don't compile code to reduce firmware size #include "ext/ext.h" @@ -21,7 +19,7 @@ #include "setup.h" #include "half_bridge.h" -#include "pcb.h" +#include "board.h" #include "oled_ssd1306.h" // implement specific extension inherited from ExtInterface diff --git a/src/ext/serial.cpp b/src/ext/serial.cpp index eea0804..c85d615 100644 --- a/src/ext/serial.cpp +++ b/src/ext/serial.cpp @@ -6,8 +6,6 @@ #ifndef UNIT_TEST -#include "config.h" - #if CONFIG_EXT_THINGSET_SERIAL // otherwise don't compile code to reduce firmware size #include "ext.h" diff --git a/src/ext/template.cpp b/src/ext/template.cpp index 0c5b198..931ed8d 100644 --- a/src/ext/template.cpp +++ b/src/ext/template.cpp @@ -4,8 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "config.h" - /** EXT interface description template * * The UEXT port can be used to connect several different extension modules to the charge controller. diff --git a/src/ext/wifi.cpp b/src/ext/wifi.cpp index bd95008..2325b79 100644 --- a/src/ext/wifi.cpp +++ b/src/ext/wifi.cpp @@ -6,15 +6,13 @@ #ifndef UNIT_TEST -#include "config.h" - #ifdef WIFI_ENABLED #include #include "load.h" #include "thingset.h" -#include "pcb.h" +#include "board.h" #include "ESP32.h" UARTSerial uext_serial(PIN_UEXT_TX, PIN_UEXT_RX, 115200); diff --git a/src/half_bridge.cpp b/src/half_bridge.cpp index b0df139..ffefd23 100644 --- a/src/half_bridge.cpp +++ b/src/half_bridge.cpp @@ -9,8 +9,7 @@ #include #include "mcu.h" -#include "pcb.h" -#include "config.h" +#include "board.h" static int _pwm_resolution; static float _min_duty; diff --git a/src/hardware.cpp b/src/hardware.cpp index dca24b0..12b4051 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -7,7 +7,7 @@ #include "hardware.h" #include "mcu.h" -#include "pcb.h" +#include "board.h" #include "load.h" #include "half_bridge.h" #include "leds.h" diff --git a/src/leds.cpp b/src/leds.cpp index 7ddec33..6d287ee 100644 --- a/src/leds.cpp +++ b/src/leds.cpp @@ -6,7 +6,7 @@ #include "leds.h" -#include "pcb.h" +#include "board.h" static int led_states[NUM_LEDS]; // must be one of enum LedState static int trigger_timeout[NUM_LEDS]; // seconds until trigger should end diff --git a/src/load.cpp b/src/load.cpp index 373c9dd..48008d5 100644 --- a/src/load.cpp +++ b/src/load.cpp @@ -6,8 +6,7 @@ #include "load.h" -#include "pcb.h" -#include "config.h" +#include "board.h" #include "leds.h" #include "device_status.h" #include "debug.h" @@ -43,10 +42,10 @@ void LoadOutput::control() dev_stat.internal_temp - junction_temperature + current * current / (LOAD_CURRENT_MAX * LOAD_CURRENT_MAX) * - (MOSFET_MAX_JUNCTION_TEMP - INTERNAL_MAX_REFERENCE_TEMP) - ) / (MOSFET_THERMAL_TIME_CONSTANT * CONTROL_FREQUENCY); + (CONFIG_MOSFET_MAX_JUNCTION_TEMP - CONFIG_INTERNAL_MAX_REFERENCE_TEMP) + ) / (CONFIG_MOSFET_THERMAL_TIME_CONSTANT * CONFIG_CONTROL_FREQUENCY); - if (junction_temperature > MOSFET_MAX_JUNCTION_TEMP || current > LOAD_CURRENT_MAX * 2) { + if (junction_temperature > CONFIG_MOSFET_MAX_JUNCTION_TEMP || current > LOAD_CURRENT_MAX * 2) { flags_set(&error_flags, ERR_LOAD_OVERCURRENT); oc_timestamp = uptime(); } @@ -65,7 +64,7 @@ void LoadOutput::control() // off the solar input instead of the load output) if (bus->voltage > overvoltage || bus->voltage > LOW_SIDE_VOLTAGE_MAX) { ov_debounce_counter++; - if (ov_debounce_counter > CONTROL_FREQUENCY) { // waited 1s before setting the flag + if (ov_debounce_counter > CONFIG_CONTROL_FREQUENCY) { // waited 1s before setting the flag flags_set(&error_flags, ERR_LOAD_OVERVOLTAGE); } } diff --git a/src/load_drv.cpp b/src/load_drv.cpp index ea7a080..8f0f114 100644 --- a/src/load_drv.cpp +++ b/src/load_drv.cpp @@ -29,8 +29,7 @@ static struct device *dev_usb; #endif // UNIT_TEST -#include "pcb.h" -#include "config.h" +#include "board.h" #include "hardware.h" #include "leds.h" #include "device_status.h" diff --git a/src/main.cpp b/src/main.cpp index cdc5323..b3fc4b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,8 +12,7 @@ #include #include "thingset.h" // handles access to internal data via communication interfaces -#include "pcb.h" // hardware-specific settings -#include "config.h" // user-specific configuration +#include "board.h" // hardware-specific settings #include "setup.h" #include "helper.h" diff --git a/src/pcb.h b/src/pcb.h deleted file mode 100644 index 097bc97..0000000 --- a/src/pcb.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2017 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef PCB_H -#define PCB_H - -/** @file - * - * @brief - * Includes PCB hardware specific settings like pin names depending on the compiler flags set in platformio.ini. - */ - -// specific board settings -/////////////////////////////////////////////////////////////////////////////// - -#if defined(CONFIG_BOARD_MPPT_2420_LC_0V10) - #include "pcbs/mppt_2420_lc_0v10.h" -#elif defined(CONFIG_BOARD_MPPT_1210_HUS_0V2) - #include "pcbs/mppt_1210_hus_0v2.h" -#elif defined(CONFIG_BOARD_MPPT_1210_HUS_0V4) - #include "pcbs/mppt_1210_hus_0v4.h" -#elif defined(CONFIG_BOARD_MPPT_1210_HUS_0V7) - #include "pcbs/mppt_1210_hus_0v7.h" -#elif defined(CONFIG_BOARD_MPPT_2420_HPX) - #include "pcbs/mppt_2420_hpx_0v1.h" -#elif defined(CONFIG_BOARD_PWM_2420_LUS_0V2) || defined(CONFIG_BOARD_PWM_2420_LUS_0V3) - #include "pcbs/pwm_2420_lus.h" -#elif defined(UNIT_TEST) - #include "pcbs/pcb_stub.h" -#else - #error "PCB has to be specified!" -#endif - -// generic default settings (if not defined different in board config) -/////////////////////////////////////////////////////////////////////////////// - -/** 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. - */ -#ifndef CONTROL_FREQUENCY -#define CONTROL_FREQUENCY 10 -#endif - -/** 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. - */ -#ifndef MOSFET_MAX_JUNCTION_TEMP -#define MOSFET_MAX_JUNCTION_TEMP 120 -#endif - -/** 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. - */ -#ifndef INTERNAL_MAX_REFERENCE_TEMP -#define INTERNAL_MAX_REFERENCE_TEMP 50 -#endif - -/** 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 - */ -#ifndef MOSFET_THERMAL_TIME_CONSTANT -#define MOSFET_THERMAL_TIME_CONSTANT 5 -#endif - -#endif /* PCB_H */ diff --git a/src/pcbs/mppt_1210_hus_0v2.h b/src/pcbs/mppt_1210_hus_0v2.h deleted file mode 100644 index 79a3960..0000000 --- a/src/pcbs/mppt_1210_hus_0v2.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2018 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef MPPT_1210_HUS_0V2_H -#define MPPT_1210_HUS_0V2_H - -#define DEVICE_TYPE "MPPT-1210-HUS" -#define HARDWARE_VERSION "v0.2" - -#include "mbed.h" - -// specify features of charge controller -#define CONFIG_HAS_DCDC_CONVERTER 1 -#define CONFIG_HAS_PWM_SWITCH 0 -#define CONFIG_HAS_LOAD_OUTPUT 1 -#define CONFIG_HAS_USB_PWR_OUTPUT 1 - -// DC/DC converter settings -#define PWM_FREQUENCY 50 // kHz 50 = better for cloud solar to increase efficiency -#define PWM_DEADTIME 300 // ns -#define PWM_TIM 1 // use TIM1 timer - -#define DCDC_CURRENT_MAX 8 // PCB maximum DCDC output current -#define LOAD_CURRENT_MAX 10 // PCB maximum load switch current - -#define LOW_SIDE_VOLTAGE_MAX 16 // Maximum voltage at battery port (V) -#define HIGH_SIDE_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) - -#define PIN_UEXT_TX PA_2 -#define PIN_UEXT_RX PA_3 -#define PIN_UEXT_SCL PB_6 -#define PIN_UEXT_SDA PB_7 -#define PIN_UEXT_MISO PB_4 -#define PIN_UEXT_MOSI PB_5 -#define PIN_UEXT_SCK PB_3 -#define PIN_UEXT_SSEL PA_15 // different than 20A MPPT - -#define PIN_SWD_TX PA_9 -#define PIN_SWD_RX PA_10 -/* -#define PIN_LED_PWR PB_14 // LED1 -//#define PIN_LED_DCDC PB_15 // LED2 -#define PIN_LED_RXTX PB_15 // LED2 -#define PIN_LED_LOAD PB_12 // LED3 -*/ -#define PIN_LOAD_DIS PB_2 -#define PIN_USB_PWR_EN PC_13 -#define PIN_USB_PWR_FLG PC_14 - -#define PIN_REF_I_DCDC PA_4 - -#define PIN_EEPROM_SCL PB_10 -#define PIN_EEPROM_SDA PB_11 - -#define EEPROM_24AA32 - -enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; - -// assignment LED numbers on PCB to their meaning -#define NUM_LEDS 3 - -#define LED_PWR 0 // LED1 -#define LED_RXTX 1 // LED2, used to indicate when sending data -#define LED_LOAD 2 // LED3 - -// LED pins and pin state configuration to switch above LEDs on -#define NUM_LED_PINS 3 -static const PinName led_pins[NUM_LED_PINS] = { - // PWR RXTX LOAD - PB_14, PB_15, PB_12 -}; -static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { - { PIN_HIGH, PIN_LOW, PIN_LOW }, // LED1 - { PIN_LOW, PIN_HIGH, PIN_LOW }, // LED2 - { PIN_LOW, PIN_LOW, PIN_HIGH } // LED3 -}; - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 10000.0 - -#define ADC_GAIN_V_LOW (110.0 / 10 ) // battery voltage divider 100k + 10k -#define ADC_GAIN_V_HIGH (105.6 / 5.6) // solar voltage divider: 100k + 5.6k -#define ADC_GAIN_I_LOAD (1000 / 4 / (1500.0 / 22.0)) // op amp gain: 150/2.2 = 68.2, resistor: 4 mOhm -#define ADC_GAIN_I_DCDC (1000 / 4 / (1500.0 / 22.0)) - -// position in the array written by the DMA controller -enum { - ADC_POS_TEMP_BAT, // ADC 0 - ADC_POS_TEMP_FETS, // ADC 1 - ADC_POS_V_REF, // ADC 5 - ADC_POS_V_LOW, // ADC 6 - ADC_POS_V_HIGH, // ADC 7 - ADC_POS_I_LOAD, // ADC 8 - ADC_POS_I_DCDC, // ADC 9 - ADC_POS_TEMP_MCU, // ADC 16 - ADC_POS_VREF_MCU, // ADC 17 - NUM_ADC_CH // trick to get the number of enums -}; - -#define NUM_ADC_1_CH NUM_ADC_CH - -// selected ADC channels (has to match with above enum) -#define ADC_CHSEL ( \ - ADC_CHSELR_CHSEL0 | \ - ADC_CHSELR_CHSEL1 | \ - ADC_CHSELR_CHSEL5 | \ - ADC_CHSELR_CHSEL6 | \ - ADC_CHSELR_CHSEL7 | \ - ADC_CHSELR_CHSEL8 | \ - ADC_CHSELR_CHSEL9 | \ - ADC_CHSELR_CHSEL16 | \ - ADC_CHSELR_CHSEL17 \ -) - -#endif diff --git a/src/pwm_switch.cpp b/src/pwm_switch.cpp index e49812f..1de268c 100644 --- a/src/pwm_switch.cpp +++ b/src/pwm_switch.cpp @@ -9,8 +9,7 @@ #include #include -#include "config.h" -#include "pcb.h" +#include "board.h" #include "daq.h" #include "debug.h" #include "helper.h" diff --git a/src/setup.cpp b/src/setup.cpp index b6dda97..93ed4db 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -10,8 +10,7 @@ */ #include "thingset.h" // handles access to internal data via communication interfaces -#include "pcb.h" // hardware-specific settings -#include "config.h" // user-specific configuration +#include "board.h" // hardware-specific settings #include "half_bridge.h" // PWM generation for DC/DC converter #include "hardware.h" // hardware-related functions like load switch, LED control, watchdog, etc. diff --git a/src/setup.h b/src/setup.h index b6de3c4..4cdd230 100644 --- a/src/setup.h +++ b/src/setup.h @@ -4,8 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "config.h" - #include #include "bat_charger.h" @@ -14,6 +12,7 @@ #include "power_port.h" #include "pwm_switch.h" #include "thingset.h" +#include "board.h" extern DcBus lv_bus; extern PowerPort lv_terminal; diff --git a/src/pcbs/pcb_stub.h b/test/board.h similarity index 75% rename from src/pcbs/pcb_stub.h rename to test/board.h index d179ae2..a905ace 100644 --- a/src/pcbs/pcb_stub.h +++ b/test/board.h @@ -7,6 +7,23 @@ #ifndef PCB_STUB_H #define PCB_STUB_H +// PWM charge controller +#define CONFIG_PWM_TERMINAL_SOLAR CONFIG_HAS_PWM_SWITCH + +// MPPT buck/boost or nanogrid mode +#define CONFIG_HV_TERMINAL_SOLAR CONFIG_HAS_DCDC_CONVERTER +#define CONFIG_HV_TERMINAL_NANOGRID 0 + +// battery always assumed to be at low-voltage terminal (might need to be changed for boost mode) +#define CONFIG_LV_TERMINAL_BATTERY 1 + +// basic battery configuration +#define BATTERY_TYPE BAT_TYPE_GEL ///< GEL most suitable for general batteries (see battery.h for other types) +#define BATTERY_NUM_CELLS 6 ///< For lead-acid batteries: 6 for 12V system, 12 for 24V system +#define BATTERY_CAPACITY 40 ///< Cell capacity or sum of parallel cells capacity (Ah) + +#define CONFIG_DEVICE_ID 12345678 + #define DEVICE_TYPE "PCB-STUB" #define HARDWARE_VERSION "v0.1" @@ -16,6 +33,12 @@ #define CONFIG_HAS_LOAD_OUTPUT 1 #define CONFIG_HAS_USB_PWR_OUTPUT 1 +// 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 PWM_FREQUENCY 50 // kHz #define PWM_DEADTIME 230 // ns diff --git a/test/daq_stub.h b/test/daq_stub.h index b0357fe..1f7feb4 100644 --- a/test/daq_stub.h +++ b/test/daq_stub.h @@ -7,8 +7,6 @@ #ifndef DAQ_STUB_H_ #define DAQ_STUB_H_ -#include "config.h" - /** Data to fill adc_filtered array during unit-tests */ typedef struct { diff --git a/test/tests_load.cpp b/test/tests_load.cpp index 1e00f90..be3670d 100644 --- a/test/tests_load.cpp +++ b/test/tests_load.cpp @@ -83,7 +83,7 @@ void control_on_to_off_overvoltage() bus.voltage = bus.sink_voltage_bound + 0.6; // increase debounce counter to 1 before limit - for (int i = 0; i < CONTROL_FREQUENCY; i++) { + for (int i = 0; i < CONFIG_CONTROL_FREQUENCY; i++) { load_out.control(); } @@ -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 = MOSFET_THERMAL_TIME_CONSTANT * CONTROL_FREQUENCY; + int trigger_steps = CONFIG_MOSFET_THERMAL_TIME_CONSTANT * CONFIG_CONTROL_FREQUENCY; for (int i = 0; i <= trigger_steps; i++) { load_out.control(); }