-
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
vcocalc.py improvements #1773
Closed
Closed
vcocalc.py improvements #1773
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,32 @@ | |
|
||
import argparse | ||
|
||
# Fixed hardware parameters | ||
fbdiv_range = range(16, 320 + 1) | ||
postdiv_range = range(1, 7 + 1) | ||
ref_min = 5 | ||
refdiv_min = 1 | ||
refdiv_max = 63 | ||
|
||
def validRefdiv(string): | ||
if ((int(string) < refdiv_min) or (int(string) > refdiv_max)): | ||
raise ValueError("REFDIV must be in the range {} to {}".format(refdiv_min, refdiv_max)) | ||
return int(string) | ||
|
||
parser = argparse.ArgumentParser(description="PLL parameter calculator") | ||
parser.add_argument("--input", "-i", default=12, help="Input (reference) frequency. Default 12 MHz", type=float) | ||
parser.add_argument("--ref-min", default=5, help="Override minimum reference frequency. Default 5 MHz", type=float) | ||
parser.add_argument("--vco-max", default=1600, help="Override maximum VCO frequency. Default 1600 MHz", type=float) | ||
parser.add_argument("--vco-min", default=750, help="Override minimum VCO frequency. Default 750 MHz", type=float) | ||
parser.add_argument("--lock-refdiv", help="Lock REFDIV to specified number in the range {} to {}".format(refdiv_min, refdiv_max), type=validRefdiv) | ||
parser.add_argument("--low-vco", "-l", action="store_true", help="Use a lower VCO frequency when possible. This reduces power consumption, at the cost of increased jitter") | ||
parser.add_argument("output", help="Output frequency in MHz.", type=float) | ||
args = parser.parse_args() | ||
|
||
# Fixed hardware parameters | ||
fbdiv_range = range(16, 320 + 1) | ||
postdiv_range = range(1, 7 + 1) | ||
ref_min = 5 | ||
refdiv_min = 1 | ||
refdiv_max = 63 | ||
|
||
refdiv_range = range(refdiv_min, max(refdiv_min, min(refdiv_max, int(args.input / args.ref_min))) + 1) | ||
if args.lock_refdiv: | ||
print("Locking REFDIV to", args.lock_refdiv) | ||
refdiv_range = [args.lock_refdiv] | ||
|
||
best = (0, 0, 0, 0, 0) | ||
best_margin = args.output | ||
|
@@ -33,13 +42,33 @@ | |
for pd1 in postdiv_range: | ||
out = vco / pd1 / pd2 | ||
margin = abs(out - args.output) | ||
if margin < best_margin: | ||
if ((vco * 1000) % (pd1 * pd2)): | ||
continue | ||
elif margin < best_margin: | ||
best = (out, fbdiv, pd1, pd2, refdiv) | ||
best_margin = margin | ||
|
||
print("Requested: {} MHz".format(args.output)) | ||
print("Achieved: {} MHz".format(best[0])) | ||
print("REFDIV: {}".format(best[4])) | ||
print("FBDIV: {} (VCO = {} MHz)".format(best[1], args.input / best[4] * best[1])) | ||
print("PD1: {}".format(best[2])) | ||
print("PD2: {}".format(best[3])) | ||
if best[0] > 0: | ||
print("Requested: {} MHz".format(args.output)) | ||
print("Achieved: {} MHz".format(best[0])) | ||
print("REFDIV: {}".format(best[4])) | ||
print("FBDIV: {} (VCO = {} MHz)".format(best[1], args.input / best[4] * best[1])) | ||
print("PD1: {}".format(best[2])) | ||
print("PD2: {}".format(best[3])) | ||
if best[4] != 1: | ||
print( | ||
""" | ||
As the requires a non-standard refdiv, this will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "As the requires" -> "As this requires" ? |
||
need to be set as a compile definition | ||
Add the following to your CMakeLists.txt file to | ||
configure the clocks as calculated above | ||
|
||
target_compile_definitions(executable_name PRIVATE | ||
PLL_SYS_REFDIV={} | ||
PLL_SYS_VCO_FREQ_HZ={} | ||
PLL_SYS_POSTDIV1={} | ||
PLL_SYS_POSTDIV2={} | ||
)\ | ||
""".format(best[4], int((args.input * 1_000_000) / best[4] * best[1]), best[2], best[3])) | ||
else: | ||
print("UNABLE TO COME UP WITH A SOLUTION....") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😂 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Only a minor nit, but I think personally I'd do the
int(string)
once, rather than three separate times?