Skip to content

Instantly share code, notes, and snippets.

@bungernut
Created April 30, 2024 15:51
Show Gist options
  • Save bungernut/dc14a868ab0992d1aadb58e8fb4b68a1 to your computer and use it in GitHub Desktop.
Save bungernut/dc14a868ab0992d1aadb58e8fb4b68a1 to your computer and use it in GitHub Desktop.
LabJackT4 BellowsPumpStepperControl
--[[
Name: BellowsPumpControl
USER Ram U16 address starts at 46180 (USER_RAM0_U16)
SPEED will be a slider from 0-2^16 resulting in a speed of 0-400 steps/sec
--]]
local MAX_SPEED = 800
local set_speed = 0 --this should execute ~1/second
local set_interval = 0
LJ.DIO_D_W(16,1)
--write 0 for startup speed to USER_RAM0_U16
MB.W(46180,0,set_speed)
-- This sets the read of user ram every second to update the speed
LJ.IntervalConfig(0, 1000.0)
-- Set the pulse time to maximum for now, will need to check b4 step
LJ.IntervalConfig(1,50000)
while true do
if LJ.CheckInterval(0) then
set_speed = MB.R(46180)
if set_speed > 0 then
set_interval = (2^16)/set_speed/MAX_SPEED*1000.0
print("Pulse_Interval = ",set_interval, "\n")
LJ.IntervalConfig(1,set_interval)
end
end
if LJ.CheckInterval(1) then
-- pulse a DIO pin, probably CIO0
if set_speed > 0 then
print(LJ.DIO_S_R(16)," ")
if LJ.DIO_S_R(16) == 1 then
print("Hi2Lo")
LJ.DIO_S_W(16, 0)
print(LJ.DIO_S_R(16)," ")
else
LJ.DIO_S_W(16, 1)
print("else: ",LJ.DIO_S_R(16)," ")
end
print(LJ.DIO_S_R(16),"\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment