Skip to content

fix(current sense): swap the measured currents, not a variable with itself - #573

Open
stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/cs-swap
Open

stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/cs-swap

Conversation

@stijncarelsbergh

Copy link
Copy Markdown

fix(current sense): swap the measured currents, not a variable with itself

The alignment routine relabels the pins when the highest current was measured on
another channel, but the corresponding sample swap was written as
_swap(c_a.b, c_a.b) - a no-op. The polarity check that follows
(_sign(c_a.a) < 0) therefore inspects the sample of the wrong channel and can
invert the gain of the phase it just repaired, which turns the current feedback
into positive feedback at low currents.

Also fixed the same pattern in the 'A-(C)NC' branch, which swapped c_a.b with
c_a.c while the pins swapped were A and C.

Reported in the alignment audit; trigger is exactly the miswiring this feature
exists to correct.


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.

…tself

The alignment routine relabels the pins when the highest current was measured on
another channel, but the corresponding sample swap was written as
`_swap(c_a.b, c_a.b)` - a no-op. The polarity check that follows
(`_sign(c_a.a) < 0`) therefore inspects the sample of the wrong channel and can
invert the gain of the phase it just repaired, which turns the current feedback
into positive feedback at low currents.

Also fixed the same pattern in the 'A-(C)NC' branch, which swapped c_a.b with
c_a.c while the pins swapped were A and C.

Reported in the alignment audit; trigger is exactly the miswiring this feature
exists to correct.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:04

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.

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.

2 participants