diff --git a/app/src/dcdc.cpp b/app/src/dcdc.cpp index 3a78542..43bc34d 100644 --- a/app/src/dcdc.cpp +++ b/app/src/dcdc.cpp @@ -232,6 +232,12 @@ bool Dcdc::startup_inhibit(bool reset) __weak void Dcdc::control() { + if (dev_stat.has_error(ERR_DCDC_HS_MOSFET_SHORT)) { + // DC/DC must not be operated anymore and the low-side switch might be forced on to blow + // the fuse, so don't touch the half bridge + return; + } + if (half_bridge_is_enabled(half_bridge) == false) { if (check_hs_mosfet_short()) { @@ -375,13 +381,14 @@ void Dcdc::fuse_destruction() static int counter = 0; if (counter > 20) { // wait 20s to be able to send out data - LOG_ERR("Charge controller fuse destruction called!\n"); - thingset_storage_save(); - half_bridge_stop(half_bridge); - // reset safety limits to allow 0% duty cycle - half_bridge_set_duty_limits(half_bridge, 0, 0.98); - half_bridge_set_duty_cycle(half_bridge, 0); - half_bridge_start(half_bridge); + if (counter == 21) { + LOG_ERR("Charge controller fuse destruction called!\n"); +#ifdef CONFIG_THINGSET_STORAGE + thingset_storage_save(); +#endif + } + // repeated in case the half bridge was stopped in the meantime + half_bridge_force_low_side(half_bridge); // now the fuse should be triggered and we disappear } counter++; diff --git a/tests/src/tests_dcdc.cpp b/tests/src/tests_dcdc.cpp index 38f3a34..6bb96ce 100644 --- a/tests/src/tests_dcdc.cpp +++ b/tests/src/tests_dcdc.cpp @@ -415,6 +415,36 @@ void boost_correct_mppt_operation() TEST_ASSERT(pwm3 > pwm2); } +void fuse_destruction_forces_low_side_on() +{ + start_buck(); + dev_stat.set_error(ERR_DCDC_HS_MOSFET_SHORT); + + // fuse destruction is delayed by 21 calls (seconds) to be able to send out data + for (int i = 0; i < 21; i++) { + dcdc.fuse_destruction(); + } + TEST_ASSERT_NOT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + dcdc.fuse_destruction(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + // control loop must not override the forced low side + dcdc.control(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + // forced state is restored after the half bridge was stopped + dcdc.stop(); + dcdc.fuse_destruction(); + TEST_ASSERT_TRUE(half_bridge_is_enabled(dcdc.half_bridge)); + TEST_ASSERT_EQUAL(0, half_bridge_get_compare(dcdc.half_bridge)); + + dcdc.stop(); + dev_stat.clear_error(ERR_DCDC_HS_MOSFET_SHORT); +} + int dcdc_tests() { UNITY_BEGIN(); @@ -474,5 +504,7 @@ int dcdc_tests() RUN_TEST(boost_stop_high_voltage_emergency); RUN_TEST(boost_correct_mppt_operation); + RUN_TEST(fuse_destruction_forces_low_side_on); + return UNITY_END(); }