Skip to content

fix(hall sensor): initialise the state and don't fake a rotation at start-up - #577

Open
stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/hall-init
Open

stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/hall-init

Conversation

@stijncarelsbergh

Copy link
Copy Markdown

fix(hall sensor): initialise the state and don't fake a rotation at start-up

The constructor left hall_state, electric_sector, electric_rotations,
total_interrupts, pulse_diff, pulse_timestamp, direction, old_direction and
use_interrupt uninitialised - indeterminate values for any sensor that is not in
the BSS section, and wrong FOC start-up behaviour even for globals.

init() then called updateState(), which compares the measured sector against that
uninitialised/zeroed sector and, when the rotor happens to sit in sector 4 or 5 at
power-up, interprets the difference as an electrical underflow and starts with
electric_rotations = -1 (2 of the 6 power-up positions). The angle and the
accumulated full rotations are offset by one electrical rotation until something
resets them.

Instead of relying on updateState() the first time, the current hall state is
adopted directly.


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.

…tart-up

The constructor left hall_state, electric_sector, electric_rotations,
total_interrupts, pulse_diff, pulse_timestamp, direction, old_direction and
use_interrupt uninitialised - indeterminate values for any sensor that is not in
the BSS section, and wrong FOC start-up behaviour even for globals.

init() then called updateState(), which compares the measured sector against that
uninitialised/zeroed sector and, when the rotor happens to sit in sector 4 or 5 at
power-up, interprets the difference as an electrical underflow and starts with
electric_rotations = -1 (2 of the 6 power-up positions). The angle and the
accumulated full rotations are offset by one electrical rotation until something
resets them.

Instead of relying on updateState() the first time, the current hall state is
adopted directly.
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