-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make all float->int/frac conversions round to nearest by default #2065
Conversation
…nearest (which is a backwards incompatible change, but I think OK), and add ability to turn it off
All looks sensible, and |
@@ -155,6 +160,9 @@ static inline void pwm_config_set_phase_correct(pwm_config *c, bool phase_correc | |||
*/ | |||
static inline void pwm_config_set_clkdiv(pwm_config *c, float div) { | |||
valid_params_if(HARDWARE_PWM, div >= 1.f && div < 256.f); | |||
#if PICO_PWM_CLKDIV_ROUND_NEAREST | |||
div += 0.5f / (1 << PWM_CH0_DIV_INT_LSB); // round to the nearest fraction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - why are we using PWM_CH0_DIV_INT_LSB here rather than PWM_CH0_DIV_FRAC_MSB+1 - PWM_CH0_DIV_FRAC_LSB. Isn't it coincidence that it's the right value? It confuses me because there are 8 bits for the pwm int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's (almost) exactly what I asked earlier - see my resolved comments above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i used what was used in the code in the rest of the function... feel free to commit a new change to this PR to fix all of them to be more sensible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but see that the original code still uses the "wrong" values, we should fix all.
Perhaps worth adding a "const int frac_bit_count = (BLAH);" to each function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wish I hadn't asked!
…oping that INT_LSB is in the right place
Latest commit just pushed. Let me know if it goes "too far" ( 🫣 ) and I'll revert it and push a simpler version without the |
nice; i think I'd prefer REG_FIELD_WIDTH() and as such it probably belongs in |
…k-dividers more consistent
87255fb
to
4b84880
Compare
Done! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome
Under control of specific vars, but defaulted by
PICO_CLKDIV_ROUND_NEAREST
which now defaults to1
This fixes #1931 which was PIO specific, but it seemed sensible to be consistent across all APIs