From d292ad425a881bf5e16e934b62b95fc9c45f1ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Thu, 30 Apr 2020 11:49:08 +0200 Subject: [PATCH] Add PWM switch off inhibit --- src/pwm_switch.cpp | 10 ++++++++-- src/pwm_switch.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pwm_switch.cpp b/src/pwm_switch.cpp index fd6450b..49cf74b 100644 --- a/src/pwm_switch.cpp +++ b/src/pwm_switch.cpp @@ -64,14 +64,19 @@ void PwmSwitch::test() void PwmSwitch::control() { if (pwm_active()) { + if (current < -0.1) { + power_good_timestamp = uptime(); // reset the time + } + if (neg_current_limit == 0 - || current > -0.1 // discharging battery into solar panel --> stop + || (uptime() - power_good_timestamp > 10) // low power since 10s + || current > 0.5 // discharging battery into solar panel --> stop || bus->voltage < 9.0 // not enough voltage for MOSFET drivers anymore || enable == false) { pwm_signal_stop(); off_timestamp = uptime(); - print_info("PWM charger stop.\n"); + print_info("PWM charger stop, current = %.3fA\n", current); } else if (bus->voltage > bus->sink_control_voltage() // bus voltage above target || current < neg_current_limit // port current limit exceeded @@ -117,6 +122,7 @@ void PwmSwitch::control() // turning the PWM switch on creates a short voltage rise, so inhibit alerts by 50 ms adc_upper_alert_inhibit(ADC_POS_V_LOW, 50); pwm_signal_start(1); + power_good_timestamp = uptime(); print_info("PWM charger start.\n"); } } diff --git a/src/pwm_switch.h b/src/pwm_switch.h index 398c71e..27c69f3 100644 --- a/src/pwm_switch.h +++ b/src/pwm_switch.h @@ -68,6 +68,7 @@ public: float offset_voltage_start; ///< Offset voltage of solar panel vs. battery to start charging (V) int restart_interval; ///< Interval to wait before retrying charging after low solar power cut-off (s) time_t off_timestamp; ///< Time when charger was switched off last time + time_t power_good_timestamp; ///< Last time the current through the switch was above minimum }; #endif