Fixing load overvoltage protection (closes #27)

This commit is contained in:
Martin Jaeger
2019-06-25 09:14:57 +02:00
parent 14faa1f0e8
commit 26ae254ec4
11 changed files with 29 additions and 19 deletions
+4 -2
View File
@@ -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);