From 5742e1f66c4e70151865de7092547223898bbf6b Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 18 Apr 2021 16:00:54 -0700 Subject: Support a proper PDP-8 assembler. --- tool/pll.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tool/pll.rb (limited to 'tool/pll.rb') diff --git a/tool/pll.rb b/tool/pll.rb new file mode 100755 index 0000000..49464d4 --- /dev/null +++ b/tool/pll.rb @@ -0,0 +1,23 @@ +#!/usr/bin/ruby -w + +TARGET_FREQ = ARGV.shift.to_f +NATIVE_FREQ = 50.0 + +CLOCK_WIDTH = 5 + +best = nil +best_mult = nil +best_div = nil +1.upto(2**CLOCK_WIDTH) do | mult | + 1.upto(2**CLOCK_WIDTH) do | div | + new = NATIVE_FREQ * mult / div + 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)) + best = new + best_mult = mult + best_div = div + end + end +end + +error = (best - TARGET_FREQ).abs / TARGET_FREQ +$stdout.write("Closest I can get is #{best}: *#{best_mult} /#{best_div} (#{(error * 100).round}% error)\n") -- cgit v1.2.3