Skip to content

fix(magnetic sensor i2c): mask and shift the left-aligned LSB bits correctly - #579

Open
stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/i2c-lsb
Open

stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/i2c-lsb

Conversation

@stijncarelsbergh

Copy link
Copy Markdown

fix(magnetic sensor i2c): mask and shift the left-aligned LSB bits correctly

For a left-aligned sensor the remaining bits sit in the upper part of the low
byte, so both the mask and the shift have to account for the unused low bits.
The constructor applied the right-aligned mask (0x3F for 6 remaining bits) and
then shifted the result right by 8-lsb_used, so it kept the status/parity bits and
dropped the real data - the angle is wrong for every sensor configured through
this constructor. The preset configurations in the header (e.g. MT6701 with
lsb_mask 0xFC, lsb_shift 2) show the intended convention.


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.

…rrectly

For a left-aligned sensor the remaining bits sit in the *upper* part of the low
byte, so both the mask and the shift have to account for the unused low bits.
The constructor applied the right-aligned mask (0x3F for 6 remaining bits) and
then shifted the result right by 8-lsb_used, so it kept the status/parity bits and
dropped the real data - the angle is wrong for every sensor configured through
this constructor. The preset configurations in the header (e.g. MT6701 with
lsb_mask 0xFC, lsb_shift 2) show the intended convention.
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.

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