summaryrefslogtreecommitdiff
path: root/lmx2487lib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lmx2487lib.lua')
-rw-r--r--lmx2487lib.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/lmx2487lib.lua b/lmx2487lib.lua
index 4a0e48c..bfaf717 100644
--- a/lmx2487lib.lua
+++ b/lmx2487lib.lua
@@ -63,6 +63,34 @@ function set_lmx2487_board_to_default_state()
update_lmx2487state()
end
+function freq2regestersValues(freq)
+
+ local F_COMP = 5000000 -- magic number
+ local N = freq / F_COMP
+
+ local RF_N = math.floor(N)
+
+ local frac = math.abs(N - RF_N)
+
+ local RF_FD = 4000000 --magic number
+ local RF_FN = math.floor( (frac * RF_FD) + 0.5)
+
+ return freq, RF_N, RF_FN, RF_FD
+end
+-- test freq2regestersValues
+fIn = 6.834e9
+freq, RF_N, RF_FN, RF_FD = freq2regestersValues(fIn)
+if freq ~= fIn and RF_N ~= 1366 and RF_FN ~= 3200000 and 4000000 then
+ print("ERROR in freq2regestersValues")
+end
+fIn=nil
+freq=nil
+RF_N=nil
+RF_FN=nil
+RF_FD=nil
+-- end of freq2regestersValues test
+
+
-- bits in mask counted starting from position 1,
-- i.e. 1 sets bit in 1st pos, 2 sets bit in 2nd pos
mask_bits14to24=bit.lshift( bit.bit(11)-1, 13)