summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-11 11:25:25 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-11 11:25:25 -0400
commit77354e3964199306aabc7ea82c995e9e7f6b1335 (patch)
tree02feeed92fdb4f6ac7e963a12eac3dfb0f45f8ae
parent16497738fcaa16f68dae6b531bd693f8c69f22f4 (diff)
downloadnodeMCU_rf_source_lmx2487-77354e3964199306aabc7ea82c995e9e7f6b1335.tar.gz
nodeMCU_rf_source_lmx2487-77354e3964199306aabc7ea82c995e9e7f6b1335.zip
moved freq2regestersValues 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)