Help with AND statement

During SET OP8[2000] 1
If the previous state was 0, it will be set to 1, also set timer of 2000.
Then it will check every 100mS to see if that timer passed, if so, it will reset the output state.
 
However, in your above code, it executed many more often than 100mS, so that when the OP8 RESET to 0, it almost immediately sets OP8 to 1 again.
 
Please also note, when GET OP8[x] or TSTEQ OP8[x], If your PLC never called non-blocking delay on that OPy pin, it will return the pin state. If your PLC code set OPy[x], it will depend on the x value, if x value not met yet, it will return previous state, if x value met, it will return current state.
 
TY CAI support,
but, I am not understanding it.
 
SET OP8[2000] 1  - what is this code saying?
                             - is it saying: in 2 secs, turn OP1 on, or is it saying: turn OP8 on and after 2 secs turn it off?
 
This I don't understand at all: "However, in your code above.... repeats more thn every 100ms... will turn to 1 immediately"
 
And finally, I do not understand the 3rd paragraph: "Please also note ....." - is this saying that the statement with [] has to be in a loop to be called continuously?

Rainer
 
SET OP8[2000] 1 - what is this code saying?
- is it saying: in 2 secs, turn OP1 on, or is it saying: turn OP8 on and after 2 secs turn it off?



This I don't understand at all: "However, in your code above.... repeats more thn every 100ms... will turn to 1 immediately"


I have never used this syntax so I am only stating what I understand from the manual.
 
The code turns on the OP8 to 1 and after 2000msec turns it off.
 
     BUT....
Your main routine calls the subroutine as fast as the PLC code can go and starts the OP*=1 cycle again before it can complete.
 
I believe CAI is telling us that the PLC subroutine will run re-entrant meaning that many, many reincarnations of the subroutine will be executing simultaneously and when any one turns the OP8=0 off again, the main routine, by calling the subroutine repetitively, will turn it back on again immediately.
 
I really doubt that the WC8 could do this with it's limited memory. If it could the subroutine stack would run out in a very short time and hang the PLC engine.
 
Ah got it!
ty support and LarrylLix!!

So, if I wanted op8 to be on only 2 secs I could set a ram flag to 1 to end the stack,yes?

Start
Tsteq ram1 0
Callsub one
end

One:
Set ram1 1
Set op8 [2000] 1
Ret

Would this set op8 on for 2 secs?

Rainer
 
Every time "SET OP8[2000] 1" runs, it sets output OP8 to 1. It also setup a timer to turn it off 2 seconds later.
That timer is with each OPx, so that if you called it once, then called again 10mS later, the timer will be set  then again, if you called it a second later, 2 second timer will be set to that called time again.  So that it will turn it off, after the timer expired, if it is not called again.
 
Your original code was called so often, almost none stop, so that it never had chance for the 2 seconds to expire.
 
I think I got it :)
 
I am working on a little sample and will post for review when I think I have it correct.
THanks for hanging in there with me

Rainer
 
Start
Tsteq ram1 0 # right idea using a semaphore but not based on job done
Callsub one
end

One:
Set ram1 1
Set op8 [2000] 1 # nothing tests to see if this is done
Ret

You could actually test the OP8 to see if it off again.
 
START
    TSTEQ OP8 0
    CALLSUB
END
 
Or you could do it on the negative and give attention to other things.
 
START
     TSTEQ OP8 1
     GOTO OTHER
     CALLSUB
OTHER: 
     ....
     do a bunch of other stuff
     ....
END
 
Don't forget to flash your debugging LED!
 
Getting your programming brain excited? Don't forget to sleep! :)
 
LarrylLix - TY so much - it is making more and more sense!
Certainly thinking programming a lot lately :)
 
So, the two relevations I had last night:
1- the ZeroBit is really ONLY checking on if the LAST interpretable statement is 0 or 1
2 - timed non-blocking commands need to be in a loop so they actually will be called again until they have completed their time frame.
 
Both the above had been explained by you and CAI support, I just had to find my own words, I guess. Now it is making more sense and I can start thinking logic instead of trial and error.
 
I actually went with attaching a voltmeter to the OP as the command SETLED does not seem to support a non-blocking timed function such as SETLED[2000].
 
I will keep working on this. The little program I wrote a few months ago was done with multiple delay statements which I will re-write also.
I do appreciate all the time and help!
Rainer
 
We have been using the similar syntax  SET OP8[200] 1 on one of our gate control. 
 
Whenever the RFID receiver detected a matching employee badge, it sends a signal to the WC8 controller. Instead of use many lines of logic to set and reset OPx, our control PLC code only need to set once with 200mS on pulse to the gate opener motor controller.  It has been working reliably for many years so far.
 
Excellent!!!!
 
I do have a sample code I cam up with (a revision of an already existing sample): (For some reason Clipboard text does not copy into this filed):
Will this work:
 
START
 TSTEQ RAM1 0
 CALLSUB CPSTRT
 TSTEQ RAM1 1
 CALLSUB COOPTIME
 TSTEQ  CH 18 RAM1 1                 at the 18th hour, program can start checking again
END
 
COOPTIME:
 TSTEQ CH 19
 CALLSUB COOPMIN
RET
 
COOPMIN:
 TSTNE CM 27
RET
LOOP:
 SET OP8[3000] 1
 SET RAM1 2                                loop is closed after 3 secs and RAM1 2 will stop checking until 6p
 GOTO LOOP
RET
CPSTART:
 SET OP8 0
 SET RAM1 1
RET
 
 
Your code

TSTEQ CH 18 RAM1 1

has four parameters, that does not work.
 
In addition, that is last line before END, what that would do is that if TSTEQ result is false, it will skip next line.  The next line will be the first line after START, that may not be the line you want to skip.
 
So, if you do not want to skip anything after TSTxy, add a NOP line, so that it simply skip NOP line after TSTxy result is not true.
 
Correct,
so, would the code #25 above work/ does it make sense, with the correction of the last two lines before the END statement?
 
Rainer
 
I am sorry for not sure exactly what do you plan to do with this code. To make it more readable, you can use "#" or ";" as delimiter in each line to put some comment in the PLC code. When you paste that code to WebControl PLC window, the comments will be automatically filter out. In that way, it will be easier for yourself to remember what you wanted to do, or others to understand.
 
It seems your code want to turn off OP8 for certain action.  When it started, it sets RAM1 to 1 as a flag to prevent further turn off the OP8.
Then you check to see if the time is 18:27, if so, it will go into LOOP, set OP8 to on, then set RAM1 to 2, then go back to LOOP again forever.  There is no condition for getting out that LOOP.  Maybe I did not understand your code correctly. it seems that section code was not intended.
 
Back
Top