From 5d1cff57f9f5acd740a8b5f8c941beefdcc00176 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 28 Jun 2020 16:42:21 +0200 Subject: sw: configure si5351 --- freqplan.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 freqplan.py (limited to 'freqplan.py') diff --git a/freqplan.py b/freqplan.py new file mode 100644 index 0000000..8ad520f --- /dev/null +++ b/freqplan.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +from fractions import Fraction +from math import floor + +xtal = 25 + +print() +print("# 160MHz and 4.915 MHz on PLLa") + +PLLa = xtal * 32 +print(f"PLLa = xtal * 32 = {PLLa} MHz") + +# x/y = a + b/y +# a = floor(x/y) +# b = x - (a * y) + +f1 = 116 +a = floor(PLLa / f1) +b = PLLa - (a * f1) +div1 = Fraction(b, f1) +print(f"CLK1: f1 = PLLa / ({a} + {div1.numerator} / {div1.denominator}) = {f1}") + +f2 = 4.91521 +a = floor(PLLa / f2) +b = PLLa - (a * f2) +div1 = Fraction(round(b * 10000), round(f2 * 10000)) +print(f"CLK2: f2 = PLLa / ({a} + {div1.numerator} / {div1.denominator}) = {f2}") + + +print() +print("# VFO between 23 and 25 MHz on PLLb") + +def calculate(frequency): + divider = floor(900000000 / frequency) # Calculate the division ratio. 900,000,000 is the maximum internal + + if divider % 2: + divider -= 1 # Ensure an even integer division ratio + + pllFreq = round(divider * frequency) # Calculate the pllFrequency: the divider * desired output frequency + + xtalFreq = xtal * 1000000 + mult = floor(pllFreq / xtalFreq) # Determine the multiplier to get to the required pllFrequency + + l = pllFreq % xtalFreq # It has three parts: + + f = floor(l) # mult is an integer that must be in the range 15..90 + denom = 1048575 + f *= denom # num and denom are the fractional parts, the numerator and denominator + f /= xtalFreq # each is 20 bits (range 0..1048575) + + num = floor(f) # the actual multiplier is mult + num / denom + return (divider, mult, num, denom) + +vfo = 23000000 +for i in range(10): + divider, mult, num, denom = calculate(vfo) + + PLLb = xtal * 1000000 * (mult + num/denom) + + freq = PLLb / divider + + delta = vfo - freq + + print(f"CLK0: VFO {vfo}, PLLb = xtal * ({mult} + {num} / {denom}) = {PLLb}, PLLb / {divider} = {freq}, delta = {delta:.03} Hz") + vfo += 100000 -- cgit v1.2.3