forked from tomojitakasu/PocketSDR
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TG-239] Add script to estimate closest divider ratios targeting a ce…
…ntral frequency (tomojitakasu#2)
- Loading branch information
1 parent
af78526
commit 4e4e91d
Showing
1 changed file
with
63 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import sys | ||
|
||
# Compute the best divider values for a given target frequency | ||
Ftarget = 1573.42e6 # DESIRED TARGET local frequency | ||
|
||
### CONSTANTS | ||
Ftcxo = 16.368e6 # MAX2771 EVK is preconfigured to 16.368MHz TCXO signal | ||
|
||
# R-divider range | ||
Rmin = 1 | ||
Rmax = 1023 | ||
|
||
# N-divider range | ||
Nmin = 36 | ||
Nmax = 32767 | ||
|
||
# F-divider range | ||
Fmin = 0 | ||
Fmax = 1048575 | ||
|
||
Fint = 0 | ||
Ncloser = 0 | ||
Rcloser = 0 | ||
for R in range(Rmin, Rmax): | ||
for N in range(Nmin, Nmax): | ||
Freq = Ftcxo / R * N | ||
if abs(Freq-Ftarget) < abs(Fint-Ftarget): | ||
Fint = Freq | ||
Ncloser = N | ||
Rcloser = R | ||
if (Ftarget-Freq) > 0: | ||
Ffrac = Freq | ||
Nfrac = N | ||
Rfrac = R | ||
if Fint == Ftarget: | ||
break | ||
if Fint == Ftarget: | ||
break | ||
|
||
# Integer mode closer results | ||
print(f'Target frequency: {Ftarget/1e6} MHz') | ||
print(f' Integer mode results:') | ||
print(f' Closer frequency: {Fint/1e6:.6f} MHz (offset: {(Fint-Ftarget):.6f}) Hz') | ||
print(f' N: {Ncloser}') | ||
print(f' R: {Rcloser}') | ||
if Fint == Ftarget: | ||
sys.exit(0) | ||
|
||
# Fractional mode final adjustment, if needed | ||
Fcloser = 0 | ||
for F in range(Fmin, Fmax): | ||
Freq = Ftcxo / Rfrac * ( Nfrac + F / 2**20 ) | ||
if abs(Freq-Ftarget) < abs(Ffrac-Ftarget): | ||
Ffrac = Freq | ||
Fcloser = F | ||
if Ffrac == Ftarget: | ||
break | ||
|
||
print(f' Fractional mode results:') | ||
print(f' Closer frequency: {Ffrac/1e6:.6f} MHz (offset: {(Ffrac-Ftarget):.6f}) Hz') | ||
print(f' N: {Nfrac}') | ||
print(f' R: {Rfrac}') | ||
print(f' F: {Fcloser}') |