summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 10:01:33 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-02 10:01:33 -0400
commit981413b1aee00dd143fdab08b4fa983f801d652e (patch)
tree0943042b3cf5ef6d2984cdc39e8c268a8b6352fd
parent059f99917703078c94489b8fd023058f64e95cc7 (diff)
downloadnodeMCU_rf_source_lmx2487-981413b1aee00dd143fdab08b4fa983f801d652e.tar.gz
nodeMCU_rf_source_lmx2487-981413b1aee00dd143fdab08b4fa983f801d652e.zip
more files written with Charris
-rw-r--r--[-rwxr-xr-x]lmx2487lib.lua19
-rw-r--r--main.lua15
-rw-r--r--microwire.lua18
3 files changed, 37 insertions, 15 deletions
diff --git a/lmx2487lib.lua b/lmx2487lib.lua
index 1034e0f..9250f72 100755..100644
--- a/lmx2487lib.lua
+++ b/lmx2487lib.lua
@@ -1,8 +1,13 @@
+ --[[
+Eugeniy Mikhailov
+1 June 2021
+ (copied over from past work)]]
+
-- there are 8 registers to track for lmx2487
-- labeled R0, R1, ..., R7 in the manual
lmx2487_registers = {0, 0, 0, 0, 0, 0, 0, 0}
-- if need update set to true updater script will resend this register
-lmx2487_need_update = {false, false, false, false, false, false, false, false}
+lmx2487_need_update = {false, false, false, false, false, false, false, false}
function set_lmx2487register(value, register)
-- register labeled 0, 1, 2, ..., 7
@@ -10,28 +15,30 @@ function set_lmx2487register(value, register)
-- this is new value and thus needs to be updated in hardware
lmx2487_registers[register+1] = value
lmx2487_need_update[register+1] = true
- print("updating register " .. register .. " with value " .. value)
+ --print("updating register " .. register .. " with value " .. value)
end
-- otherwise we do nothing
end
function get_lmx2487register(register)
-- register labeled 0, 1, 2, ..., 7
- local value = (lmx2487_registers[register+1])
- print("register " .. register .. " is set to " .. value)
+ local value = (lmx2487_registers[register+1])
+ --print("register " .. register .. " is set to " .. value)
return value
end
-function send_register_lmx2487(register)
+function send_register_lmx2487( register)
if ( lmx2487_need_update[register +1] ) then
+ --print(tmr.now())
print("sending register " .. register .. " with value " .. get_lmx2487register( register ) )
+ --print(tmr.now())
-- do hardware talking
microwire_send_data( get_lmx2487register( register ) )
lmx2487_need_update[register+1]=false
end
end
-function update_lmx2487state()
+function update_lmx2487state()
for register=7,0,-1 do
-- going over registers
-- manual suggest to send R0 as last one
diff --git a/main.lua b/main.lua
index 3636958..0d22c58 100644
--- a/main.lua
+++ b/main.lua
@@ -1,5 +1,12 @@
+ --[[
+Eugeniy Mikhailov
+1 June 2021
+ ]]
+
+dofile("binaryLib.lua")
+dofile("microwire.lua")
+dofile("lmx2487lib.lua")
+dofile("freq2lmx2487settings.lua")
-dofile("microwire.lc")
-dofile("lmx2487lib.lc")
-collectgarbage()
-
+settings=initSettings()
+setFreq(6.834e9)
diff --git a/microwire.lua b/microwire.lua
index d6c1ff4..ef64a2f 100644
--- a/microwire.lua
+++ b/microwire.lua
@@ -1,3 +1,8 @@
+ --[[
+Eugeniy Mikhailov
+1 June 2021
+(copied over from past work) ]]
+
-- functions to write registers over microwire interface
-- it resembles SPI but need extra pin which sends Load Enable (LE) pulse
-- otherwise SPI sequence is sent into 24 bit FIFO latch register on chip
@@ -8,7 +13,11 @@ microwire_spiID = 1; -- ID=1 --> HSPI in nodemcu language
microwire_databits=24; -- LMX2487 loads 24 bits sequence per write into a register
-- lmx2487 can handle up to 20 MHz speed (50 nS per clock) but optocoupler is good for 240kHz
-- so let's aim for 100 kHz
-microwire_interface_speed = 100000; -- in Hz
+-- value of 1000 Hz is too slow and does not engage the spi clock
+-- values of 10 kHz is not sensed by lmx2487 chip
+-- 100 kHz is shown to work reliably
+-- 1 MHz works too
+microwire_interface_speed = 1000000; -- in Hz
-- we will use SPI ChipSelect pin for LoadEnable pin
microwire_LE_pin = 8; -- microwire Load Enable pin. 8 --> GPIO15
@@ -28,7 +37,7 @@ function microwire_setup_interface ()
-- HSPI /CS | 8 | GPIO15
-- HSPI MOSI | 7 | GPIO13
-- HSPI MISO | 6 | GPIO12
-
+
-- Load Enable pin settings
-- note that it overwrite unused ChipSelect if pin=8, i.e. GPIO15
gpio.mode(microwire_LE_pin, gpio.OUTPUT)
@@ -39,14 +48,14 @@ end
function microwire_send_data( data )
-- essentially send data via spi interface
-- and raise Load Enable pin for a bit (at least for 25 nS) at the end of transmission
-
+
-- first low LE pin, it should be low but just to be sure
gpio.write(microwire_LE_pin, gpio.LOW)
-- second send the data
local nBytes = spi.send(microwire_spiID, data)
-
+
-- finally raise LE pin for at least 25 ns,
-- note that it takes about 300 uS on ESP8266 before LE will be HIGH after spi.send
-- Note manual toggle like below is quite slow, the shortest duration is 160 uS
@@ -55,4 +64,3 @@ function microwire_send_data( data )
end
microwire_setup_interface()
-