@@ -573,29 +573,29 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
573573 Ub = -0 .5f * Ualpha + _SQRT3_2 * Ubeta;
574574 Uc = -0 .5f * Ualpha - _SQRT3_2 * Ubeta;
575575
576- center = driver->voltage_limit /2 ;
577- if (foc_modulation == FOCModulationType::SpaceVectorPWM){
578- // discussed here: https://community.simplefoc.com/t/embedded-world-2023-stm32-cordic-co-processor/3107/165?u=candas1
579- // a bit more info here: https://microchipdeveloper.com/mct5001:which-zsm-is-best
580- // Midpoint Clamp
581- float Umin = min (Ua, min (Ub, Uc));
582- float Umax = max (Ua, max (Ub, Uc));
583- center -= (Umax+Umin) / 2 ;
584- }
585-
586- if (!modulation_centered) {
576+ // centering the voltages around either
577+ // modulation_centered == true > driver.voltage_limit/2
578+ // modulation_centered == false > or Adaptable centering, all phases drawn to 0 when Uq=0
579+ if (modulation_centered) {
580+ center = driver->voltage_limit /2 ;
581+ if (foc_modulation == FOCModulationType::SpaceVectorPWM){
582+ // discussed here: https://community.simplefoc.com/t/embedded-world-2023-stm32-cordic-co-processor/3107/165?u=candas1
583+ // a bit more info here: https://microchipdeveloper.com/mct5001:which-zsm-is-best
584+ // Midpoint Clamp
585+ float Umin = min (Ua, min (Ub, Uc));
586+ float Umax = max (Ua, max (Ub, Uc));
587+ center -= (Umax+Umin) / 2 ;
588+ }
589+ Ua += center;
590+ Ub += center;
591+ Uc += center;
592+ }else {
587593 float Umin = min (Ua, min (Ub, Uc));
588594 Ua -= Umin;
589595 Ub -= Umin;
590596 Uc -= Umin;
591- }else {
592- Ua += center;
593- Ub += center;
594- Uc += center;
595597 }
596-
597598 break ;
598-
599599 }
600600
601601 // set the voltages in driver
0 commit comments