From 77354e3964199306aabc7ea82c995e9e7f6b1335 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Fri, 11 Jun 2021 11:25:25 -0400 Subject: moved freq2regestersValues to lmx2487lib.lua --- lmx2487lib.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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) -- cgit v1.2.3