From cc64c1e6ca7ac553226f56a5d2b98e9917cef34f Mon Sep 17 00:00:00 2001 From: Sahil Kale Date: Sun, 7 Jan 2024 12:31:02 +0100 Subject: [PATCH] [Bridge] Change input from inverting low side PWM to enable --- control_loop/bldc/6step/6step_util.cpp | 6 +++--- .../6step/brushless_6step_control_loop.cpp | 2 +- control_loop/bldc/foc/foc_util.cpp | 6 +++--- hwbridge/3phase/bridge_3phase.hpp | 18 +++++++----------- test/brushless_6step_control_loop_test.cpp | 4 ++-- test/brushless_6step_utils_test.cpp | 6 +++--- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/control_loop/bldc/6step/6step_util.cpp b/control_loop/bldc/6step/6step_util.cpp index 71895fa..cca9426 100644 --- a/control_loop/bldc/6step/6step_util.cpp +++ b/control_loop/bldc/6step/6step_util.cpp @@ -55,13 +55,13 @@ void determine_inverter_duty_cycles_trap(hwbridge::Bridge3Phase::phase_command_t const float duty_cycle = (abs_speed + 1.0f) / 2.0f; phase_command[i].duty_cycle_high_side = duty_cycle; - phase_command[i].invert_low_side = true; + phase_command[i].enable = true; } else if (current_commutation_step.signals[i] == Bldc6Step::CommutationSignal::LOW) { phase_command[i].duty_cycle_high_side = 0.0f; - phase_command[i].invert_low_side = true; + phase_command[i].enable = true; } else { phase_command[i].duty_cycle_high_side = 0.0f; - phase_command[i].invert_low_side = false; + phase_command[i].enable = false; } } } diff --git a/control_loop/bldc/6step/brushless_6step_control_loop.cpp b/control_loop/bldc/6step/brushless_6step_control_loop.cpp index 612e382..507ddce 100644 --- a/control_loop/bldc/6step/brushless_6step_control_loop.cpp +++ b/control_loop/bldc/6step/brushless_6step_control_loop.cpp @@ -58,7 +58,7 @@ ControlLoop::ControlLoopBaseStatus Brushless6StepControlLoop::run(float speed) { if (status_.status == ControlLoop::ControlLoopBaseStatus::ERROR) { hwbridge::Bridge3Phase::phase_command_t zero_duty_cycle; zero_duty_cycle.duty_cycle_high_side = 0.0f; - zero_duty_cycle.invert_low_side = false; + zero_duty_cycle.enable = false; phase_command_[0] = zero_duty_cycle; phase_command_[1] = zero_duty_cycle; diff --git a/control_loop/bldc/foc/foc_util.cpp b/control_loop/bldc/foc/foc_util.cpp index a7047a7..8709e43 100644 --- a/control_loop/bldc/foc/foc_util.cpp +++ b/control_loop/bldc/foc/foc_util.cpp @@ -61,11 +61,11 @@ FocDutyCycleResult determine_inverter_duty_cycles_foc(float theta, math::direct_ if (phase_commands != nullptr) { // Set the duty cycles phase_commands[0].duty_cycle_high_side = result.duty_cycle_u_h; - phase_commands[0].invert_low_side = true; + phase_commands[0].enable = true; phase_commands[1].duty_cycle_high_side = result.duty_cycle_v_h; - phase_commands[1].invert_low_side = true; + phase_commands[1].enable = true; phase_commands[2].duty_cycle_high_side = result.duty_cycle_w_h; - phase_commands[2].invert_low_side = true; + phase_commands[2].enable = true; } return result; diff --git a/hwbridge/3phase/bridge_3phase.hpp b/hwbridge/3phase/bridge_3phase.hpp index 7b1d823..e2309d3 100644 --- a/hwbridge/3phase/bridge_3phase.hpp +++ b/hwbridge/3phase/bridge_3phase.hpp @@ -25,11 +25,10 @@ class Bridge3Phase { /** * @brief Construct a phase command * @param duty_cycle_high_side Duty cycle for the high side PWM channel assuming complementary PWM - * @param invert_low_side Invert the low side PWM channel (used to High-Z the bridge output) + * @param enable Enable the phase output. If false, the phase output should be High-Z * @note The duty cycle is between 0.0f and 1.0f, where 0.5 is 50% duty cycle and represents 0V (assumes complementary */ - phase_command_t(float duty_cycle_high_side, bool invert_low_side) - : duty_cycle_high_side(duty_cycle_high_side), invert_low_side(invert_low_side) {} + phase_command_t(float duty_cycle_high_side, bool enable) : duty_cycle_high_side(duty_cycle_high_side), enable(enable) {} /** * @brief Duty cycle for the high side PWM channel assuming complementary PWM * @note The duty cycle is between 0.0f and 1.0f, where 0.5 is 50% duty cycle and represents 0V (assumes complementary @@ -37,22 +36,19 @@ class Bridge3Phase { */ float duty_cycle_high_side = 0.0f; /** - * @brief Invert the low side PWM channel - * @note The invert low side flag is used to invert the low side PWM channel (if complementary PWM is used) - * @note Note that the invert low side flag, if set to false, is used to High-Z the bridge output. Caution should be used - * in allowing an abstracted bridge to allow a non-inverted output to be commanded to a duty cycle that is not 0.0f + * @brief Enable the phase output. If false, the phase output should be High-Z */ - bool invert_low_side = false; + bool enable = false; /** * @brief Equal operator * @param rhs The right hand side of the operator - * @return bool True if the duty cycles and invert low side flags are equal + * @return bool True if the duty cycles and enable side flags are equal */ bool operator==(const phase_command_t& rhs) const { const bool duty_cycle_high_side_equal = math::float_equals(this->duty_cycle_high_side, rhs.duty_cycle_high_side); - const bool low_side_inversion_signal_equal = this->invert_low_side == rhs.invert_low_side; - return duty_cycle_high_side_equal && low_side_inversion_signal_equal; + const bool enable_bridge_output = this->enable == rhs.enable; + return duty_cycle_high_side_equal && enable_bridge_output; } }; diff --git a/test/brushless_6step_control_loop_test.cpp b/test/brushless_6step_control_loop_test.cpp index ac3df72..7a5fe4b 100644 --- a/test/brushless_6step_control_loop_test.cpp +++ b/test/brushless_6step_control_loop_test.cpp @@ -67,7 +67,7 @@ TEST(Brushless6StepControlLoopTest, test_rotor_position_estimator_failure) { // Expect a call to set the duty cycles to 0 hwbridge::Bridge3Phase::phase_command_t zero_duty_cycle; zero_duty_cycle.duty_cycle_high_side = 0.0f; - zero_duty_cycle.invert_low_side = false; + zero_duty_cycle.enable = false; EXPECT_CALL(bridge, set_phase(zero_duty_cycle, zero_duty_cycle, zero_duty_cycle)) .WillOnce(Return(app_hal_status_E::APP_HAL_OK)); @@ -99,7 +99,7 @@ TEST(Brushless6StepControlLoopTest, test_rotor_position_estimator_get_angle_fail // Expect a call to set the duty cycles to 0 hwbridge::Bridge3Phase::phase_command_t zero_duty_cycle; zero_duty_cycle.duty_cycle_high_side = 0.0f; - zero_duty_cycle.invert_low_side = false; + zero_duty_cycle.enable = false; EXPECT_CALL(bridge, set_phase(zero_duty_cycle, zero_duty_cycle, zero_duty_cycle)) .WillOnce(Return(app_hal_status_E::APP_HAL_OK)); diff --git a/test/brushless_6step_utils_test.cpp b/test/brushless_6step_utils_test.cpp index 5c61ddc..39e8dfd 100644 --- a/test/brushless_6step_utils_test.cpp +++ b/test/brushless_6step_utils_test.cpp @@ -56,7 +56,7 @@ TEST(Bldc6StepUtils, test_6_step_duty_cycle) { // Expect the duty cycle to be 1 EXPECT_FLOAT_EQ(phase_command[j].duty_cycle_high_side, expected_high_side_duty_cycle); // Expect the low side to be inverted - EXPECT_FLOAT_EQ(phase_command[j].invert_low_side, true); + EXPECT_FLOAT_EQ(phase_command[j].enable, true); } // Check the low signal duty cycle @@ -64,7 +64,7 @@ TEST(Bldc6StepUtils, test_6_step_duty_cycle) { // Expect the duty cycle to be 0 EXPECT_FLOAT_EQ(phase_command[j].duty_cycle_high_side, 0.0f); // Expect the low side to be inverted - EXPECT_FLOAT_EQ(phase_command[j].invert_low_side, true); + EXPECT_FLOAT_EQ(phase_command[j].enable, true); } const bool is_high_z = (expected_commutation_signal.signals[j] == CommutationSignal::Z_FALLING) || @@ -73,7 +73,7 @@ TEST(Bldc6StepUtils, test_6_step_duty_cycle) { // Expect the duty cycle to be 0 EXPECT_FLOAT_EQ(phase_command[j].duty_cycle_high_side, 0.0f); // Expect the low side to be inverted - EXPECT_FLOAT_EQ(phase_command[j].invert_low_side, false); + EXPECT_FLOAT_EQ(phase_command[j].enable, false); } } }