-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add clock_configure_mhz function #2244
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
base: develop
Are you sure you want to change the base?
Conversation
As per new code in #2225 we should catch cases where the divider between 1 and 2. |
I guess that means you can't overclock the Pico to 66 GHz? 🤣 |
See also #2255 |
Trades off accuracy (only gets to +/- 1MHz) for reduced code size as it doesn't need 64 bit division
ca9e63e
to
6728e7e
Compare
Fixup for dividers 1.0-2.0 on RP2040 Improve docs
That's better than the normal clock_configure, which only lets you overclock to 4.3GHz 🤣 |
@kilograham do we want this function, or should I close this PR? |
no, it is good; i didn't look in detail at the accuracy; does it at least get you near to the right answer, vs 1Mhz away ;-) |
If the divider is an integer (ie |
uint32_t actual_freq = (uint32_t) ((((uint32_t) src_freq_mhz) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div) * MHZ; | ||
|
||
clock_configure_internal(clock, src, auxsrc, actual_freq, div); | ||
// Store the configured frequency |
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.
What does this comment mean? (and is it referring to the line below or the line above the comment?)
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’m not entirely sure (it was copied from the function above) - it’s related to the line above it as that’s what stores the configured frequency
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.
Perhaps it'd be less confusing if the comment was moved above the line it's referring to, as is done conventionally? 🙂
This adds a
clock_configure_mhz
function, which trades off accuracy compared toclock_configure
(only gets to +/- 1MHz) for reduced code size as it doesn't need 64 bit division.It takes the source and target frequencies in MHz as 16-bit numbers, to ensure they fit within the 32-bit division.
This is useful for example if you want to calibrate the ROSC using an XOSC and then run off the ROSC, in which case you don't need a very accurate frequency as the ROSC frequency isn't accurate.