@@ -221,7 +221,6 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
221221 case FOCModulationType::SinePWM :
222222 case FOCModulationType::SpaceVectorPWM :
223223
224- if (modulation_centered) {
225224 // Sinusoidal PWM modulation
226225 // Inverse Park + Clarke transformation
227226 _sincos (angle_el, &_sa, &_ca);
@@ -243,6 +242,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
243242 // - The part of the duty cycle in which all phases are
244243 // off is longer than in centered modulation
245244 // - Both SinePWM and SpaceVectorPWM have the same form for non-centered modulation
245+ if (modulation_centered) {
246246 center = driver->voltage_limit /2 ;
247247 if (foc_modulation == FOCModulationType::SpaceVectorPWM){
248248 // discussed here: https://community.simplefoc.com/t/embedded-world-2023-stm32-cordic-co-processor/3107/165?u=candas1
@@ -256,41 +256,10 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
256256 Ub += center;
257257 Uc += center;
258258 }else {
259- angle_el = _normalizeAngle (angle_el + _PI_2);
260- _sincos (angle_el, &_sa, &_ca);
261-
262-
263-
264- // Inverse park transform
265- Ualpha = _ca * Uq;// - _sa * Uq; // -sin(angle) * Uq;
266- Ubeta = _sa * Uq;// + _ca * Uq; // cos(angle) * Uq;
267-
268- // Clarke transform
269-
270- // determine the segment I, II, III
271- if ((angle_el >= 0 ) && (angle_el < _120_D2R)) {
272- // section I
273- Ua = Ualpha + _1_SQRT3 * Ubeta;
274- Ub = _2_SQRT3 * Ubeta;
275- Uc = 0 ;
276-
277- } else if ((angle_el >= _120_D2R) && (angle_el < (2 * _120_D2R))) {
278- // section III
279- Ua = 0 ;
280- Ub = _1_SQRT3 * Ubeta - Ualpha;
281- Uc = -_1_SQRT3 * Ubeta - Ualpha;
282-
283- } else if ((angle_el >= (2 * _120_D2R)) && (angle_el < (3 * _120_D2R))) {
284- // section II
285- Ua = Ualpha - _1_SQRT3 * Ubeta;
286- Ub = 0 ;
287- Uc = - _2_SQRT3 * Ubeta;
288- }
289-
290- Ua = Ua*1.5 ;
291- Ub = Ub*1.5 ;
292- Uc = Uc*1.5 ;
293-
259+ float Umin = min (Ua, min (Ub, Uc));
260+ Ua -= Umin;
261+ Ub -= Umin;
262+ Uc -= Umin;
294263 }
295264 break ;
296265 }
0 commit comments