diff --git a/src/load.cpp b/src/load.cpp index 854588e..7492fba 100644 --- a/src/load.cpp +++ b/src/load.cpp @@ -296,7 +296,7 @@ extern log_data_t log_data; extern float mcu_temp; // this function is called more often than the state machine -void load_control(load_output_t *load) +void load_control(load_output_t *load, float load_max_voltage) { if (short_circuit) { load->switch_state = LOAD_STATE_OFF_SHORT_CIRCUIT; @@ -317,7 +317,9 @@ void load_control(load_output_t *load) } static int debounce_counter = 0; - if (load->bus->voltage > LOW_SIDE_VOLTAGE_MAX) { + if (load->bus->voltage > load_max_voltage || + load->bus->voltage > LOW_SIDE_VOLTAGE_MAX) + { debounce_counter++; if (debounce_counter > CONTROL_FREQUENCY) { // waited 1s before setting the flag load_switch_set(false); diff --git a/src/load.h b/src/load.h index fa1dd8c..5d98106 100644 --- a/src/load.h +++ b/src/load.h @@ -79,6 +79,6 @@ void load_state_machine(load_output_t *load, bool source_enabled); * * Performs time-critical checks like overcurrent and overvoltage */ -void load_control(load_output_t *load); +void load_control(load_output_t *load, float load_max_voltage); #endif /* LOAD_H */ diff --git a/src/main.cpp b/src/main.cpp index d6fd128..9fa8115 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,7 @@ void system_control() leds_set_charging(half_bridge_enabled()); #endif - load_control(&load); + load_control(&load, bat_conf.voltage_absolute_max * charger.num_batteries); if (counter % CONTROL_FREQUENCY == 0) { // called once per second (this timer is much more accurate than time(NULL) based on LSI) @@ -137,7 +137,7 @@ int main() #ifdef UART_SERIAL_ENABLED thingset_serial_init(&serial); #endif - + #ifdef CAN_ENABLED ts_can.enable(); #endif diff --git a/src/pcb.h b/src/pcb.h index f429714..456c645 100644 --- a/src/pcb.h +++ b/src/pcb.h @@ -26,14 +26,6 @@ // generic settings (for all charge controller boards) /////////////////////////////////////////////////////////////////////////////// -/** Maximum voltage at battery port (V) - */ -#define LOW_SIDE_VOLTAGE_MAX 32 - -/** Maximum voltage at PV input port (V) - */ -#define HIGH_SIDE_VOLTAGE_MAX 55 - /** Main control function frequency (Hz) * * Frequencies higher than 10 Hz caused issues with MPPT control during lab test with diff --git a/src/pcbs/mppt_1210_hus_0v2.h b/src/pcbs/mppt_1210_hus_0v2.h index 6d97075..20b6677 100644 --- a/src/pcbs/mppt_1210_hus_0v2.h +++ b/src/pcbs/mppt_1210_hus_0v2.h @@ -29,6 +29,9 @@ #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 diff --git a/src/pcbs/mppt_1210_hus_0v4.h b/src/pcbs/mppt_1210_hus_0v4.h index 1e82984..98609ed 100644 --- a/src/pcbs/mppt_1210_hus_0v4.h +++ b/src/pcbs/mppt_1210_hus_0v4.h @@ -29,6 +29,9 @@ #define DCDC_CURRENT_MAX 10 // 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 diff --git a/src/pcbs/mppt_1210_hus_0v6.h b/src/pcbs/mppt_1210_hus_0v6.h index e41426a..d8c07f4 100644 --- a/src/pcbs/mppt_1210_hus_0v6.h +++ b/src/pcbs/mppt_1210_hus_0v6.h @@ -29,6 +29,9 @@ #define DCDC_CURRENT_MAX 10 // 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 diff --git a/src/pcbs/mppt_2420_lc_0v10.h b/src/pcbs/mppt_2420_lc_0v10.h index a83b556..39a927b 100644 --- a/src/pcbs/mppt_2420_lc_0v10.h +++ b/src/pcbs/mppt_2420_lc_0v10.h @@ -29,6 +29,9 @@ #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current +#define LOW_SIDE_VOLTAGE_MAX 32 // Maximum voltage at battery port (V) +#define HIGH_SIDE_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) + #define PIN_UEXT_DIS PC_14 // starting from rev. 0.10 #define PIN_UEXT_TX PA_2 #define PIN_UEXT_RX PA_3 @@ -60,6 +63,7 @@ #define PIN_EEPROM_SDA PB_11 #define EEPROM_24AA32 +#define HAS_CAN 1 enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; @@ -120,10 +124,4 @@ enum { ADC_CHSELR_CHSEL17 \ ) -// defines for CAN BUS SUPPORT -#define HAS_CAN 1 -#define PIN_CAN_RX PB_8 -#define PIN_CAN_TX PB_9 -#define PIN_CAN_STB PA_15 - #endif diff --git a/src/pcbs/pcb_stub.h b/src/pcbs/pcb_stub.h index bc0df62..c80f972 100644 --- a/src/pcbs/pcb_stub.h +++ b/src/pcbs/pcb_stub.h @@ -25,6 +25,9 @@ #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current +#define LOW_SIDE_VOLTAGE_MAX 32 // Maximum voltage at battery port (V) +#define HIGH_SIDE_VOLTAGE_MAX 55 // Maximum voltage at PV input port (V) + #define PIN_UEXT_TX 0 #define PIN_UEXT_RX 0 #define PIN_UEXT_SCL 0 diff --git a/src/pcbs/pwm_2420_lus_0v1.h b/src/pcbs/pwm_2420_lus_0v1.h index f5efd4a..739749b 100644 --- a/src/pcbs/pwm_2420_lus_0v1.h +++ b/src/pcbs/pwm_2420_lus_0v1.h @@ -29,6 +29,9 @@ #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current +#define LOW_SIDE_VOLTAGE_MAX 30 // 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 diff --git a/src/pcbs/pwm_2420_lus_0v2.h b/src/pcbs/pwm_2420_lus_0v2.h index 767ff95..ef843a8 100644 --- a/src/pcbs/pwm_2420_lus_0v2.h +++ b/src/pcbs/pwm_2420_lus_0v2.h @@ -29,6 +29,9 @@ #define DCDC_CURRENT_MAX 20 // PCB maximum DCDC output current #define LOAD_CURRENT_MAX 20 // PCB maximum load switch current +#define LOW_SIDE_VOLTAGE_MAX 30 // 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