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();