Skip to content

fix(trapezoid commutation): non-centred modulation produced no output for Uq < 0 - #580

Open
stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/trap-negative
Open

stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/trap-negative

Conversation

@stijncarelsbergh

Copy link
Copy Markdown

fix(trapezoid commutation): non-centred modulation produced no output for Uq < 0

The trapezoid branches used center = Uq for non-centred modulation, which works
for Uq > 0 but makes all three phase voltages <= 0 for Uq < 0; setPwm() clamps
them to 0, so the motor gets no voltage at all in one direction. The sine/SVPWM
branches handle this by shifting the phases up by their minimum, which is what
non-centred modulation means for every mode.

Using the same min-clamp for the trapezoid modes is exactly equivalent for
Uq > 0 (every sector map contains a -1, so min = -Uq and the result is
map*Uq + Uq as before) and gives the correct shifted waveform for Uq < 0.


Split out of #571 at your request: one fix per PR, against dev. The branch contains
nothing else, so it can be reviewed, amended or dropped on its own.

The CI board matrix runs automatically; I did not run any hardware test, so the behavioural
claims are from reading the code plus the compiler. Happy to adjust the wording, split it
differently or drop it - no attachment to this one.

… for Uq < 0

The trapezoid branches used `center = Uq` for non-centred modulation, which works
for Uq > 0 but makes all three phase voltages <= 0 for Uq < 0; setPwm() clamps
them to 0, so the motor gets no voltage at all in one direction. The sine/SVPWM
branches handle this by shifting the phases up by their minimum, which is what
non-centred modulation means for every mode.

Using the same min-clamp for the trapezoid modes is exactly equivalent for
Uq > 0 (every sector map contains a -1, so min = -Uq and the result is
map*Uq + Uq as before) and gives the correct shifted waveform for Uq < 0.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Candas1

Candas1 commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

I once had Claude check the library for bugs and it also mentioned this case.
It's some code I changed so I was surprised.

Nobody probably experienced the bug because it only happens with trapezoidal commutation/non centered/negative torque but it's worth fixing/testing it.

Claude is telling me there is a simpler and equivalent fix:
center = modulation_centered ? (driver->voltage_limit)/2 : fabsf(Uq);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants