Page 1 of 1

General output

Posted: Sun Nov 05, 2023 8:22 pm
by zed65
Hi, I want to control my exhaust cut-out valve.
I want it to open over 110kpa and close again 1 second after MAP goes under 100kpa.

Is there a way to do that? Do I need to use a LUA script?

Re: General output

Posted: Sun Nov 05, 2023 9:06 pm
by AndreyB
You have two options. general purpose PWM option would not have the one second delay.

To get the one second logic yes you would need a Lua script.

Re: General output

Posted: Mon Nov 13, 2023 7:02 pm
by zed65
So I've done my first LUA script and it works but not as I want.
Can someone please take a look and give me some feedback/pointer to make it simpler/better.
It's the curve thing that don't work as intended. I want to be able to set the on/off kpa and the delay time in Tunerstudio.

Code: Select all

t = Timer.new()
startPwm(1, 100, 0)
res = 0		-- init res flag
val = 0		-- init val
on = 115	-- Turn on kpa
off = 110	-- Turn off kpa
curve1 = findCurveIndex("time")		-- ????
function onTick()
	kpa = getSensor("Map")		-- get kpa
	time = curve(curve1, kpa)	-- get time from curve

	if kpa > on then
		res = 1					-- set res flag to 1
		output = 1
		setPwmDuty(1, 1)		-- set PWM to 100%
	end

	if res > 0 and kpa < off then	-- check flag and kpa
		res = 0					-- set flag to 0
		t : reset()				-- reset timer
	end
	val = t : getElapsedSeconds()
	if res < 1 and val < time then	-- check flag and time
		output = 1
		setPwmDuty(1, 1)		-- keep PWM at 100%
	elseif
	kpa < off then				-- check kpa
		output = 0
		setPwmDuty(1, 0)		-- set PWM to 0%
	end
	print(output .." " ..res .." " ..val)
end


Re: General output

Posted: Mon Nov 13, 2023 11:07 pm
by AndreyB
you need a bunch of print statements that's really the primary way to debug Lua