From 3b72694deb99b6db0f4327d28dbddd98d069d0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Wed, 14 Jul 2021 15:39:22 +0200 Subject: [PATCH] DC/DC: Add some safety functions to test mode --- src/dcdc.cpp | 19 ++++++++++++++++--- src/dcdc.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/dcdc.cpp b/src/dcdc.cpp index d903b7b..073521e 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -286,11 +286,24 @@ __weak void Dcdc::control() void Dcdc::test() { if (half_bridge_enabled()) { - if (half_bridge_get_duty_cycle() > 0.5) { - half_bridge_set_ccr(half_bridge_get_ccr() - 1); + const char *stop_reason = NULL; + if (lvb->voltage > ls_voltage_max || hvb->voltage > hs_voltage_max) { + stop_reason = "emergency (voltage limits exceeded)"; + } + else if (enable == false) { + stop_reason = "disabled"; } else { - half_bridge_set_ccr(half_bridge_get_ccr() + 1); + if (half_bridge_get_duty_cycle() > 0.50) { + half_bridge_set_ccr(half_bridge_get_ccr() - 1); + } + else { + half_bridge_set_ccr(half_bridge_get_ccr() + 1); + } + } + if (stop_reason != NULL) { + stop(); + printf("DC/DC Stop: %s.\n", stop_reason); } } else { diff --git a/src/dcdc.h b/src/dcdc.h index 2c2a7ca..bc26367 100644 --- a/src/dcdc.h +++ b/src/dcdc.h @@ -110,7 +110,7 @@ public: void control(); /** - * Test mode for DC/DC, ramping up to 50% duty cycle + * Test mode for DC/DC, ramping up/down to 50% duty cycle */ void test();