Skip to content

Commit a34988a

Browse files
committed
BLDCDriver6PWM: use a single _constrain
1 parent 8a45d3a commit a34988a

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/drivers/BLDCDriver6PWM.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ int BLDCDriver6PWM::init() {
7878

7979
// Set voltage to the pwm pin
8080
void BLDCDriver6PWM::setPwm(float Ua, float Ub, float Uc) {
81-
// limit the voltage in driver
82-
Ua = _constrain(Ua, 0, voltage_limit);
83-
Ub = _constrain(Ub, 0, voltage_limit);
84-
Uc = _constrain(Uc, 0, voltage_limit);
81+
82+
const float max_duty = voltage_limit/voltage_power_supply;
8583
// calculate duty cycle
8684
// limited in [0,1]
87-
dc_a = _constrain(Ua / voltage_power_supply, 0.0f , 1.0f );
88-
dc_b = _constrain(Ub / voltage_power_supply, 0.0f , 1.0f );
89-
dc_c = _constrain(Uc / voltage_power_supply, 0.0f , 1.0f );
85+
dc_a = _constrain(Ua / voltage_power_supply, 0.0f , max_duty );
86+
dc_b = _constrain(Ub / voltage_power_supply, 0.0f , max_duty );
87+
dc_c = _constrain(Uc / voltage_power_supply, 0.0f , max_duty );
9088
// hardware specific writing
9189
// hardware specific function - depending on driver and mcu
9290
_writeDutyCycle6PWM(dc_a, dc_b, dc_c, phase_state, params);

0 commit comments

Comments
 (0)