From e94fd88a5e1b566f417faa0ee699c1fa06577d2e Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Tue, 19 Mar 2019 10:11:52 +0100 Subject: [PATCH] Implemented maximum voltage check for DC/DC --- src/dcdc.cpp | 12 ++++++++++-- src/dcdc.h | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/dcdc.cpp b/src/dcdc.cpp index 00f45c6..ab752dc 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -28,8 +28,8 @@ void dcdc_init(dcdc_t *dcdc) dcdc->mode = DCDC_MODE_INIT; dcdc->ls_current_max = DCDC_CURRENT_MAX; dcdc->ls_current_min = 0.05; // A if lower, charger is switched off - dcdc->hs_voltage_max = 55.0; // V - dcdc->ls_voltage_max = 30.0; // V + dcdc->hs_voltage_max = HIGH_SIDE_VOLTAGE_MAX; // V + dcdc->ls_voltage_max = LOW_SIDE_VOLTAGE_MAX; // V //dcdc->offset_voltage_start = 4.0; // V charging switched on if Vsolar > Vbat + offset //dcdc->offset_voltage_stop = 1.0; // V charging switched off if Vsolar < Vbat + offset dcdc->restart_interval = 60; // s --> when should we retry to start charging after low solar power cut-off? @@ -109,8 +109,16 @@ void dcdc_control(dcdc_t *dcdc, power_port_t *hs, power_port_t *ls) dcdc->off_timestamp = time(NULL); printf("DC/DC stop.\n"); } + if (ls->voltage > dcdc->ls_voltage_max || hs->voltage > dcdc->hs_voltage_max) { + half_bridge_stop(); + dcdc->off_timestamp = time(NULL); + printf("DC/DC emergency stop (voltage limits exceeded).\n"); + } } else { + if (ls->voltage > dcdc->ls_voltage_max || hs->voltage > dcdc->hs_voltage_max) { + return; + } if (_dcdc_check_start_conditions(dcdc, ls, hs)) { // Vmpp at approx. 0.8 * Voc --> take 0.9 as starting point for MPP tracking half_bridge_start(ls->voltage / (hs->voltage * 0.9)); diff --git a/src/dcdc.h b/src/dcdc.h index 5f6497b..814c184 100644 --- a/src/dcdc.h +++ b/src/dcdc.h @@ -46,11 +46,11 @@ enum dcdc_control_mode * actual measurements and calibration parameters. */ typedef struct { - dcdc_control_mode mode; + dcdc_control_mode mode; ///< DC/DC mode (buck, boost or nanogrid) // actual measurements float ls_current; ///< Low-side (inductor) current - float temp_mosfets; + float temp_mosfets; ///< MOSFET temperature measurement (if existing) // current state float power; ///< Power at low-side (calculated by dcdc controller) @@ -60,8 +60,8 @@ typedef struct { // maximum allowed values float ls_current_max; ///< Maximum low-side (inductor) current float ls_current_min; ///< Minimum low-side current (if lower, charger is switched off) - float hs_voltage_max; - float ls_voltage_max; + float hs_voltage_max; ///< Maximum high-side voltage + float ls_voltage_max; ///< Maximum low-side voltage // calibration parameters //float offset_voltage_start; // V charging switched on if Vsolar > Vbat + offset