Try restating the problem with OR and AND statements:
- If
- something is true about sensor A
- OR/AND
- something else is true about 30s
- THEN
- something should happen with the light
Let's step back a bit, and note that the key thing to understand is that a PLC program's logic is
static, to first order, so the same rungs are scanned in left-to-right-top-to-bottom sequence, again and again and again.
Pretty much the only things that change from one program scan to the next program scan are
- the time
- the states of the inputs
- the states of the outputs
- the states of any ladder-internal memory
So one way to look at it is that the program logic makes decisions based on the states of the first two items (inputs)
at the start of the program scan, over which it has no (direct) control, and sets the state of the last two items (outputs, broadly speaking)
at the end of the program scan. And so you likely had little to no trouble constructing a ladder diagram that took note of a sensor's activation (an input) at the start of the program scan, and in response turned on a light (output) at the end of the program scan.
And now you can get no further thinking of ladder logic that way, i.e. like this:
Code:
inputs => [logic] => outputs
which is why you came here.
Don't be alarmed, because
- We all started there, and
- Nobody can get any further looking at it that way.
HOWEVER, that is only
one way to look at PLC programming.
A broader view
- recognizes that the program logic cannot change the first two (directly), but only react to them (same as above),
- recognizes that the program can change the last two (same as above),
- and recognizes that the last two persist from scan to scan (this is new!).
- This means that any output state that was set on the last scan can be used as an input in the current scan.
So the new model is
Code:
[inputs + previous outputs] => [logic] => new outputs*
^ |
| V
+-----------------------------------------+
* I am using the term [outputs] broadly enough to include any program-internal states such as bits, integers, and other memory, and even certain instructions which may maitain or even change their state automatically according to their nature from program scan to program scan.)
So our question to you is this: once you make the light come on when the sensor activates, can
you make anything happen (i.e. change internal or external output states) 30s later to make it go off?
We will add one caveat: make sure that you write to the output that goes to the light
only and exactly in one place in your program. There will be great temptation to break that rule: we have all done it, and can assure you with 100% confidence "lies madness that way" - it is indeed the dark side of the source.
We give you this secret handshake, to a higher plane, with but one condition: someday you must pass it on!