diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-06-28 16:42:21 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-06-28 16:42:21 +0200 |
commit | 5d1cff57f9f5acd740a8b5f8c941beefdcc00176 (patch) | |
tree | bdfd0e394d6333aead7d3a0295ba3457bd68275d /freqplan.py | |
parent | 93220f99a52dc93f9a2d5b11074f60156ef70210 (diff) | |
download | picardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.tar.gz picardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.tar.bz2 picardy-5d1cff57f9f5acd740a8b5f8c941beefdcc00176.zip |
sw: configure si5351
Diffstat (limited to 'freqplan.py')
-rw-r--r-- | freqplan.py | 66 |
1 files changed, 66 insertions, 0 deletions
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 |