Move PCB and user config to board Kconfig

Files in src/pcbs/xyz.h are moved to boards/xyz/board.h. User settings from
src/config.h are also configured via Kconfig, so the file is removed.
This commit is contained in:
Martin Jäger
2020-04-30 10:53:58 +02:00
parent 2d74a3a554
commit 2a71d02aeb
46 changed files with 108 additions and 463 deletions
-1
View File
@@ -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
+1 -1
View File
@@ -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.
+42
View File
@@ -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
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
@@ -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 <zephyr.h>
#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
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
@@ -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 <zephyr.h>
#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
+2
View File
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
+2 -2
View File
@@ -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
@@ -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 <zephyr.h>
#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)
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
@@ -10,17 +10,7 @@
#define DEVICE_TYPE "MPPT-2420-LC"
#define HARDWARE_VERSION "v0.10"
#ifdef __MBED__
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#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
@@ -5,3 +5,5 @@ zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()
zephyr_include_directories(.)
@@ -7,11 +7,7 @@
#ifndef PWM_2420_LUS_H
#define PWM_2420_LUS_H
#ifdef __MBED__
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#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] = {
-12
View File
@@ -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 -------------"
-12
View File
@@ -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 -------------"
+1
View File
@@ -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 =
+1 -2
View File
@@ -9,8 +9,7 @@
#include <math.h> // for fabs function
#include <stdio.h>
#include "config.h"
#include "pcb.h"
#include "board.h"
#include "helper.h"
#include "device_status.h"
-2
View File
@@ -11,8 +11,6 @@
#ifdef BOOTLOADER_ENABLED
#include "config.h"
#include <cstdint>
/** Length of the bootloader name string (including \0 termination) */
-95
View File
@@ -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 */
+1 -9
View File
@@ -9,18 +9,10 @@
#include <math.h> // log for thermistor calculation
#include <assert.h>
#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;
+1 -1
View File
@@ -34,7 +34,7 @@
#include <stm32g4xx_ll_bus.h>
#endif
#include "pcb.h"
#include "board.h"
#include "debug.h"
#if !defined(CONFIG_SOC_SERIES_STM32F0X) && !defined(CONFIG_SOC_SERIES_STM32L0X)
+1 -2
View File
@@ -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
+4 -4
View File
@@ -10,7 +10,7 @@
#include <stdlib.h> // for min/max function
#include <stdio.h>
#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) {
+1 -2
View File
@@ -9,8 +9,7 @@
#include <math.h> // for fabs function
#include <stdio.h>
#include "config.h"
#include "pcb.h"
#include "board.h"
#include "setup.h"
#include "helper.h"
+1 -1
View File
@@ -9,7 +9,7 @@
#include <stdio.h>
#include "mcu.h"
#include "pcb.h"
#include "board.h"
#include "thingset.h"
#include "helper.h"
+1 -3
View File
@@ -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"
-2
View File
@@ -6,8 +6,6 @@
#ifndef UNIT_TEST
#include "config.h"
#if CONFIG_EXT_THINGSET_CAN
#include "ext/can_msg_queue.h"
+1 -3
View File
@@ -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
-2
View File
@@ -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"
-2
View File
@@ -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.
+1 -3
View File
@@ -6,15 +6,13 @@
#ifndef UNIT_TEST
#include "config.h"
#ifdef WIFI_ENABLED
#include <inttypes.h>
#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);
+1 -2
View File
@@ -9,8 +9,7 @@
#include <stdio.h>
#include "mcu.h"
#include "pcb.h"
#include "config.h"
#include "board.h"
static int _pwm_resolution;
static float _min_duty;
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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
+5 -6
View File
@@ -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);
}
}
+1 -2
View File
@@ -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"
+1 -2
View File
@@ -12,8 +12,7 @@
#include <drivers/gpio.h>
#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"
-81
View File
@@ -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 */
-119
View File
@@ -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
+1 -2
View File
@@ -9,8 +9,7 @@
#include <stdio.h>
#include <time.h>
#include "config.h"
#include "pcb.h"
#include "board.h"
#include "daq.h"
#include "debug.h"
#include "helper.h"
+1 -2
View File
@@ -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.
+1 -2
View File
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "config.h"
#include <stdio.h>
#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;
+23
View File
@@ -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
-2
View File
@@ -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 {
+2 -2
View File
@@ -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();
}