@@ -78,15 +78,13 @@ int BLDCDriver6PWM::init() {
7878
7979// Set voltage to the pwm pin
8080void 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