Skip to content

Commit

Permalink
[Bridge] Change input from inverting low side PWM to enable
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-kale committed Jan 7, 2024
1 parent 4cc64f0 commit ceb44bd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions control_loop/bldc/6step/6step_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion control_loop/bldc/6step/brushless_6step_control_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions control_loop/bldc/foc/foc_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 8 additions & 12 deletions hwbridge/3phase/bridge_3phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,38 @@ class Bridge3Phase {
virtual ~Bridge3Phase() = default;

/**
* @brief Phase command typedef to hold the duty cycle and invert low side flag
* @brief Phase command typedef to hold the duty cycle and enable flag
*/
class phase_command_t {
public:
phase_command_t() = default;
/**
* @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
* pwm)
*/
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;
}
};

Expand Down
4 changes: 2 additions & 2 deletions test/brushless_6step_control_loop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions test/brushless_6step_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ TEST(Bldc6StepUtils, test_6_step_duty_cycle) {
if (expected_commutation_signal.signals[j] == CommutationSignal::HIGH) {
// 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 the low side to be enabled
EXPECT_FLOAT_EQ(phase_command[j].enable, true);
}

// Check the low signal duty cycle
if (expected_commutation_signal.signals[j] == CommutationSignal::LOW) {
// 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 the low side to be enabled
EXPECT_FLOAT_EQ(phase_command[j].enable, true);
}

const bool is_high_z = (expected_commutation_signal.signals[j] == CommutationSignal::Z_FALLING) ||
(expected_commutation_signal.signals[j] == CommutationSignal::Z_RISING);
if (is_high_z) {
// 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 the low side to be enabled
EXPECT_FLOAT_EQ(phase_command[j].enable, false);
}
}
}
Expand Down

0 comments on commit ceb44bd

Please sign in to comment.