Skip to content
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

pio_calculate_clkdiv_from_float is not rounding #1931

Open
lkesteloot opened this issue Sep 15, 2024 · 0 comments
Open

pio_calculate_clkdiv_from_float is not rounding #1931

lkesteloot opened this issue Sep 15, 2024 · 0 comments

Comments

@lkesteloot
Copy link

The pio_calculate_clkdiv_from_float() function is truncating the fractional result:

*div_frac = (uint8_t)((div - (float)*div_int) * (1u << 8u));

It should be rounding. One way to do this is to add half of 1/256 up front, as the very first line of the function, before the range check:

// Bump div by 1/512 so that we're rounding instead of truncating.
div += 0.001953125f;

This error caused an NTSC color burst to be far enough off in frequency to not be recognized by two different monitors.

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

No branches or pull requests

1 participant