Skip to content

fix(magnetic sensor pwm): scale the pulseIn() timeout with the PWM frequency - #582

Open
stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/pwm-timeout
Open

stijncarelsbergh wants to merge 1 commit into
simplefoc:devfrom
stijncarelsbergh:fix/pwm-timeout

Conversation

@stijncarelsbergh

Copy link
Copy Markdown

fix(magnetic sensor pwm): scale the pulseIn() timeout with the PWM frequency

The frequency-aware constructor documents the AS5600 PWM modes (115/230/460/920 Hz)
and computes the raw counts from them, but left the read timeout at the default
1200 us. One period at 115 Hz is ~8.7 ms and the high pulse can be ~8.4 ms, so
pulseIn() times out, returns 0 and the reported angle sticks at min_raw_count:
a silently dead sensor for an officially supported configuration. Only 920 Hz
(max pulse ~1.05 ms) fitted into the old timeout.

The timeout is now 1.2 periods, i.e. ~1.2 ms at 920 Hz (compatible with the
behaviour before) and ~10 ms at 115 Hz.


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.

…equency

The frequency-aware constructor documents the AS5600 PWM modes (115/230/460/920 Hz)
and computes the raw counts from them, but left the read timeout at the default
1200 us. One period at 115 Hz is ~8.7 ms and the high pulse can be ~8.4 ms, so
pulseIn() times out, returns 0 and the reported angle sticks at min_raw_count:
a silently dead sensor for an officially supported configuration. Only 920 Hz
(max pulse ~1.05 ms) fitted into the old timeout.

The timeout is now 1.2 periods, i.e. ~1.2 ms at 920 Hz (compatible with the
behaviour before) and ~10 ms at 115 Hz.
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