Hello Guest it is January 22, 2020, 11:19:31 PM

Author Topic: How to Emulate a Momentary switch?  (Read 1951 times)

0 Members and 1 Guest are viewing this topic.

Re: How to Emulate a Momentary switch?
« Reply #10 on: June 04, 2017, 10:34:27 AM »
Don't know if it will work here but a trick I havr often used for a toggle button in PLCs is to increment a Word value and the use lowest  bit as the output. Each time you increment that bit changes state and remains that way.

Offline CRS

*
  •  61 61
    • View Profile
Re: How to Emulate a Momentary switch?
« Reply #11 on: June 04, 2017, 04:20:09 PM »
Hi garyhlucas, thanks for chiming in.  Appreciate that.  But my knowledge of all things Lua and programming is very limited, so I don't understand a thing you said.

Thanks anyway.

Craig.
Re: How to Emulate a Momentary switch?
« Reply #12 on: June 04, 2017, 06:24:01 PM »
Here is another idea, using the millisecond #3001 variable
just need to add output condition
as I am just showing the time value in the history.
can be set to any time and all jogging or other functions are still active
with some additional coding should be able to use these functions for other timers

Code: [Select]
--add to PLC Script
function Timer(varnum)
    local inst = mc.mcGetInstance() -- Get the current instance
    varvalue1 = mc.mcCntlGetPoundVar(inst, varnum); -- Get MiliSecond Time
    return varvalue1
end
function TimedOut(varnum,varvalue,ontime)
    local inst = mc.mcGetInstance() -- Get the current instance
    varvalue2 = mc.mcCntlGetPoundVar(inst, varnum); -- Get MiliSecond Time again
    increment=(varvalue2-varvalue) -- current milisecond increment
    if (varvalue2>(varvalue+ontime)) then
        timerupFlag=0 -- be sure to set this global variable flag set in screen load cript
        mc.mcCntlSetLastError(inst, "Times Up "..tostring(increment))
    else
        timerupFlag=1
    end
    return increment
end
if (timerupFlag==1) then
    increment = TimedOut(milisecondVar,varvalue1,ontime)
end


-- Add to Left up Button Script
timerupFlag=1 -- set global that timer routine is in use
milisecondVar=3001 --the Milisecond # Register
ontime=5000 -- miliseconds on time so its 5 seconds minimum
valvalue1 = Timer(milisecondVar) --set start time