diff options
| author | Julian Blake Kongslie | 2021-04-15 09:10:48 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-04-15 09:10:48 -0700 |
| commit | d5b05bc1b6b9fe6885991c3b49c1f3b1df594660 (patch) | |
| tree | b6e2659243628a5aed711edcc56b9b199150b75c | |
| parent | Tell Quartus that we're using a scaled clock. (diff) | |
| download | noncpu-d5b05bc1b6b9fe6885991c3b49c1f3b1df594660.tar.xz | |
Add a quick and dirty script for computing PLL parameters.
Diffstat (limited to '')
| -rwxr-xr-x | pll.rb | 23 |
1 files changed, 23 insertions, 0 deletions
| @@ -0,0 +1,23 @@ | |||
| 1 | #!/usr/bin/ruby -w | ||
| 2 | |||
| 3 | TARGET_FREQ = ARGV.shift.to_f | ||
| 4 | NATIVE_FREQ = 50.0 | ||
| 5 | |||
| 6 | CLOCK_WIDTH = 5 | ||
| 7 | |||
| 8 | best = nil | ||
| 9 | best_mult = nil | ||
| 10 | best_div = nil | ||
| 11 | 1.upto(2**CLOCK_WIDTH) do | mult | | ||
| 12 | 1.upto(2**CLOCK_WIDTH) do | div | | ||
| 13 | new = NATIVE_FREQ * mult / div | ||
| 14 | if not best or (new - TARGET_FREQ).abs < (best - TARGET_FREQ).abs or ((new - TARGET_FREQ).abs == (best - TARGET_FREQ).abs and (mult + div) < (best_mult + best_div)) | ||
| 15 | best = new | ||
| 16 | best_mult = mult | ||
| 17 | best_div = div | ||
| 18 | end | ||
| 19 | end | ||
| 20 | end | ||
| 21 | |||
| 22 | error = (best - TARGET_FREQ).abs / TARGET_FREQ | ||
| 23 | $stdout.write("Closest I can get is #{best}: *#{best_mult} /#{best_div} (#{(error * 100).round}% error)\n") | ||
