Ladder Logic Help

Thank you everyone for your help! Sorry that there was such a delay in my responses, as I mentioned before I do also work full time so checking this thread hasn’t been my priority.

And also my apologies as it does look like I just want someone to do my homework, I promise I’m not I truly do just want to be able to understand what I’m looking!

Thanks again all
 
I can see how this looks like I’m trying to get someone to do my homework, I promise I’m not! This is only a practice to do in our own time and doesn’t go toward any mark.

The problem I’ve run into is getting each step to stop after the set amount of time. As it currently stands I can turn them on but they won’t stop. I assume something to do with how I’ve set up my counter. I don’t currently have any photos of the program I made but next time I have access to the portal I can attach some
Hey sorry for my rude comment then.
I know this kinda gives the answer but seems like you already have the timer sequence down but you have no way of stopping it once it starts.
A simple Blinking light timer is what you need. Im not sure how you have it going right now but. This is terminology from studio 5000, so might be pretty different in some parts but ladder logic tends to stay the same usually. OTE = regular Coil,
XIO = NC Contact, XIC = NO contact,


I PB1Start I --- (XIO) StepCounter.DN ---- I I (OTE) RUN
I. I
I. RUN I

(XIC) RUN--- (XIO) ---- REDTON.DN --(TON) REDTON
RUN --(XIO) REDTON.DN --- (OTE) RED

(XIC) REDTON.DN--- (TON) GreenTON
REDTON.DN--- (OTE) GREEN

(XIC)GREENTON.DN ---- (CTU) StepCounter

(XIO)Run ----(XIC)StepCounter.DN-----(RES) StepCounter
 
Let me guess: in all of your attempts that failed, you are mixing the output coils (Business Logic) with the Sequence Logic that decides which mode is active, and which step in the sequence of each mode is currently active, i.e.
  • Mode toggle-on: R+G- then R-G+, repeat, stop after 5 cycles
  • vs.
  • Mode toggle off: R+, G+ R- G-, repeat, stop after 5 cycles
and where the task is in each mode (repeats, counter). And you are using the Set and Reset instructions. Ah, sweet blush of youth;).

I am not saying ithat cannot be done, but in that case, each rung that drives an output will need all of the logic for all of the modes, plus all of the logic to keep track of the state/steps within those modes, and it will be a mess.

It would be better to learn good hygiene now, while you are starting out:
  • Rule 1: Each rung should do a single easily discernible, task*.
  • Rule 2: Segregate (i.e. separate) the Sequence Logic fromthe Business Logic;
    • Only write to PLC-user-owned memory bits to do this.
* I am the worst violator of this, as I think Code Golf is elegant, but that is not your problem;).

"PLC-user-owned" memory (let's call it "user memory" from here for simplicity) is memory that PLC can write to on one scan cycle and know that they will have the values on the next scan cycle, i.e. those memory bits; values are remembered; i.e. the PLC operating system (I/O Scan, communications, etc.) will not overwrite these bits while your program is not looking. In Siemens, the only memory bits for which this is true are
  • the Marker Memory a.k.a. Flag Memory (%M0.0, %MB1, %MW2, %MD4, etc.), and
  • Data Block Memory, e.g. MyDB.MyBoolean, MyDB.MyByte, MyDB.MyInt, MyDB.MyDint, etc.
  • The output memory bits (%Q0.0, etc.)**
** But be careful to only read from, and never to write to, any output memory in the Sequence Logic

The values of user memory bits plus the values*** of Input memory (%I0.0, %IB1, %IW2, etc.), compose a data model of the system, both of the PLC-external process and the PLC-internal control logic.

N.B. the PLC user program logic that you write interacts only with those memory bits. Specifically the PLC user program neither directly reads the electrical input signals (%I...), nor directly writes the electrical output signals (%Q...). Instead, the I/O scan cycle is the middleman between the electrical signals of the input and output modules and the input and output memory bits (%I... and %Q...), which memory bits' values the PLC user program reads and writes as proxies for the electrical signals they represent. This is a somewhat subtle point, rarely covered, and whose significance that rarely surfaces, but when it does, e.g. during diagnostics ans troubleshooting, having it in the back of your mind will be most useful. If you want to understand it better, you could do no better than watch @Ron Beaufort's PLC bootcamp video series, and watching it repeatedly until this point and a full understanding of the scan cycle become synonymous with breathing.

*** Typically updated between program scan cycles by the I/O scan cycle, as controlled by the PLC operating system

The harder part, though made easier by the segregation, will be the Sequence Logic. So if the Sequence Logic (modes, steps)
  • no longer needs to be mixed with the Business Logic, and
  • is completely contained in user memory that you, the user, define and control, and
  • even the different modes no longer need to be mixed with each other,
then that Sequence Logic is much, much easier to write.

For example, look again at @parky's notional latch circuit in Post #3 above

1786608084996-png.83329

and observe the following:
  • That rung executes, and encapsulates, exactly and only one task
    • specifically, controlling the value of user memory bit Latch1
  • That bit, Latch1, is part of a data model, residing in user memory, of the overall system
    • specifically, its value indicates whether the [R+G-, R-G+] x 5 sequence is active or not
  • That rung is well commented
  • That rung is a form of the canonical, and easily recognizable (give it time;)), Start/Stop Circuit pattern****
    • The Start condition is a press of Button 1
    • The Stop Conditions*****
      • Toggle 1 switch being off OR
      • Counter expired
    • The Seal-in/Run bit is the same bitin memory, Latch1
      • although that rung references essentially different temporal values between the Seal-In contact and the Run coil******
**** see list item 3. here.
***** coded in the negative as not-Stop per De Morgan's Law (see here) are
****** Sidebar: can you see why I say that? Hint: watch the PLC bootcamp video series until you do.

And now consider how much that simplifies everything else: encapsulated (modeled) in the vallue of that single bit, Latch1, is all the information needed for all other rungs to know whether the (R+G-, R-G+)x5 sequence is active or not. For example, say in your data model,
  • for the alternating sequence (when Latch1value is 1),
    • Assume you have other, timer-based logic that controls whether the Red light is on or off,
    • So Green is the inverse of Red
  • for the other sequence (R+,G+,R-,G-)x5,
    • you data model has a boolean tag, 4steps,
      • using logic similar to Latch1,
        • I.e. the same logic, but with a -]/[- contact under Toggle1
      • that indicates when this sequence is active
    • you have four TON timers, T1 - T4, in the data model
    • those timers are set up in a cascade,
      • as a 4-timer extension the canonical, and easily recognizable, item 5. (two-)Flasher pattern here
    • so
      • when the value of 4steps is 1 and the value of T1.Q is 0:: R+; G-
      • when the value of T1.Q is 1 and the value of T2.Q is 0: R+; G+
      • when the value of T2.Q is 1 and the value of T3.Q is 0: R-; G+
      • when the value of T3.Q is 1: R-; G-
      • N.B.
        • we only need check 4steps for the first step,
          • because T1 has -] [-4steps on its feed rung, along with -]/[-T4.Q for the repeat
          • so the timers are all reset, and all .Q value are 0 when the value of 4steps is 0
        • for Green, we don't need 4steps at all:
          • Green will be on from the expiry of T1 until the expiry of T3
            • i.e. Green witl be on whenever T1.Q value is 1 and T3.Q value is 0
For the Business Logic, the Green output is then as simple as this:


In prose: IF
  • the alternating sequence is active (Latch1) AND7 the Red light is off,********
  • OR8
  • the (4steps) T1 timer is expired AND7 the T3 timer is not expired,*******
THEN Green light is ON; otherwise Green light is OFF. Note that when the alternating sequence is not active, the Green light will be OFF because of Latch1 (value of 0) even though the -]/[-Red contact evaluates to True on its own.

7 Logic elements arranged in series implement a Boolean AND operation
8 Logic elements (or groups of elements) arranged in parallel (branches) implement a Boolean OR operation

Three final bonus hints

(i) There are only three Boolean operators:
  • AND - ladder elements in series;
  • OR - ladder elements in parallel branches;
  • NOT - the -]/[- contact
Any relay ladder logic beyond that is a combination of those three.

(ii) PLC programming is primarily about time, and the scan cycle is the clock; when something happens is more important that what happens.

(iii) The PLC cares not whit what you want it to do, but it will mercilessly and inexorably do exactly what you tell it to do.

This may seem a longish post, but @Ron Beaufort's video series, plus the Contact and Coil patterns website, plus the above (including others' posts, not just mine), composes about 95% of what you need to know to write a program in relay ladder logic. The rest is probably experience.
Please excuse the rough mark-up as I don't have access to the Portal at the moment, however I've drawn up this Ladder for the first stage, (R+G-, R-G+)x5. To me this looks like it should work, but would you mind taking a look and pointing out anything that may cause it to fail?

1787015349343.png
 
Please excuse the rough mark-up as I don't have access to the Portal at the moment,

Take a look at plcfiddle.com; it is pretty handy for sketching out and testing logic when you don't have access to TIAP (TIA Portal).

however I've drawn up this Ladder for the first stage, (R+G-, R-G+)x5. To me this looks like it should work, but would you mind taking a look and pointing out anything that may cause it to fail?

View attachment 83368

Weel done, that is pretty good; you messed up the RED/GREEN logic a bit, but your flashing timer logic is solid and you are well on your way.

One likely bug I see is that the counter will reach 5 when the GREEN light comes on halfway through the fifth (R+G-, R-G+) cycle and unlatches L1 to early and stops everything.

The first rung and the last three rungs are the Sequence Logic: they don't set any outputs, but they keep track of the current state of the sequence. You can know everything you need to know about the sequence from those rungs; you don't need the lights, just the state of L1, TON1.Q (T1Q), and TON2.Q (T2Q). As such, I would put those four rungs together.

The other two rungs, the RED and GREEN output rungs, are Business Logic; you will find your life is much easier when you separate Sequence Logic from Business Logic.

The other bugs I see are in the Business Logic i.e. the RED and GREEN logic:
  • The GREEN value should be 1 for the second half of each of the five cycles i.e. when TON1 is expired i.e. TON1.Q (T1Q) value is 1
    • You have this in the bottom branch of the GREEN rung,
    • but the top branch of the GREEN rung could also mess things up,
      • because on the first scan cycle (you watched the PLC bootcamp video, I hope) when L1 transitions to 1
      • RED will be 0,
      • so the -] [L1----]/[RED- upper branch fo the GREEN coil will evaluate to True
      • so the coil will write a value of 1 to the GREEN output, when it should write a 0,
        • which will prevent RED output value from being 1 on the next rung
        • so RED value will be 0
      • and since RED value is written as 0 on this scan cycle,
        • the same thing will happen again on the next scan cycle
      • Note that the -]/[T1Q---] [T2Q- lower branch of the RED rung can never evaluate to True
        • because for TON2 to be expired, TON1 must be expired,
        • and anyway the flasher circuit make T2Q behave a one-shot
        • i.e. T2Q will never be on for more than one scan cycle at a time
  • Eventually, on the second half of the cycle, TON1 will expired,
    • and the -] [T1Q----]/[T2Q- lower branch to the GREEN coil will evaluate to True,
      • This logic is correct, and all you need for GREEN
    • which will make the coil write a value of 1 to the GREEN output
    • which will again prevent RED from ever being 1.
So basically GREEN will be on the whole time.

You might need some logic to reset the counter, after CTU expires, to set up for the next cycle, but that should be easy to do.

Are T1Q and T2Q actually TON1.Q and TON2.Q? I am going to assume they are.

A few comments: a TON .Q bit value of 1 for a timer means the TON is expired (its accumulator* value is equal to, or greater than, its preset** value).

More importantly, when the input run to a TON evaluates to False, that timer resets; reset means accumulator value returns to 0, and expired bit .Q value resets to 0. If you want to see how most TONs are implemented, look at the flowchart example in this (large) PDF: https://literature.rockwellautomati...re/documents/rm/1756-rm003_-en-p.pdf#page=122

The relevant application of that to your code is that, when TON2 expires, which can only happen after TON1 expires (since -] [-TON1 is on the feedrung to TON2), the value of TON2.Q (T2Q) becomes 1, so on the next scan cycle the -]/[-TON2 contact evaluates to False, which resets TON1 and TON1.Q (T1Q), which in turn resets TON2 and and TON2.Q (T2Q). So the value of TON2.Q (T2Q) is only ever 1 for 1 scan cycle, so using it in contacts on the GREEN and RED rungs is pointless***. Certainly the bottom branch feeding the RED light can be removed: GREEN will be on when TON1 is expired and TON2 is timing (accumulator is accumulating but not yet reaching preset), and RED is the opposite of GREEN for this pattern.

* accumulator Current Value is timername.CV in TIAP, timername.ACC in plcfiddle and Logix
** Preset Value is timername.PV in TIAP, timername.PRE in plcfiddle and Logic
*** There is also a subtlety about TON .Q values in TIAP, and in practice -] [-TON2.Q almost never evaluates to True, but let's ignore that for now until you try to use TON2.Q to reset CTU1 and it makes you question your life choices (Siemens does that. A lot. ;)).
 
Whoops, I missed something: because GREEN value is 1 for both halves of each flasher cycle, i.e. GREEN is always on when L1 is on, there is never a subsequent GREEN rising edge, so the counter counts to 1 when GREEN values becomes 1 on the first scan cycle when L1 value becomes 1, and never counts to 2. You can see this behavior on PLC fiddle here.; N.B. you will need to
  • open up CTU1 and put a value of 5 in its PRE attribut, and
  • open up TON1 and TON2 and put a 1 (or 0.5) value into their PRE attributes.
So, to fix that, we can feed TON2.Q to separate boolean tag T2Q, and use that to trigger the counter. See here; that does indeed cause CTU1 to now count to 5, which eventually unlatches L1 and stops everything, but as predicted, GREEN is on for both halves of the flasher cycle when the L1 value is 1.

You have everything you need to finish this assignment; she'll be right.

Four more hints:

If you remove several items from what you have now, and add nothing, then that will almost work. And if you then swap the order of two rungs, then the whole thing will work.

The only thing you will need to do after that is add the counter reset, to ensure that when L1 value transitions from 0 to 1, that the CTU.ACC value has been initialized to 0.

The PLC cares not a whit what you want it to do, but is will mercilessly and inexorably do exactly what you tell it to do. This is important for debugging: if you assume you told it to do behavior you did not want but are seeing, then you are in the best mindset for figuring out what the problem actually is; whinging about how the PLC is not doing what it should will get you nowhere, as decades of countless threads on this formum will prove.

Rubber Duck Debugging.
 
Take a look at plcfiddle.com; it is pretty handy for sketching out and testing logic when you don't have access to TIAP (TIA Portal).
This website has been incredibly handy, thanks!
One likely bug I see is that the counter will reach 5 when the GREEN light comes on halfway through the fifth (R+G-, R-G+) cycle and unlatches L1 to early and stops everything.
Absolutely correct, I changed this to T2.Q and that has sorted that one out
you will find your life is much easier when you separate Sequence Logic from Business Logic.
Putting them this way has definitely eased the headache
So basically GREEN will be on the whole time.
Once again 100% correct.

Looks like I had been over complicating a lot, but the relief I felt when it all started to click into place I can't even explain.
Here's what I ended up with for the 1st stage of light sequence:
https://www.plcfiddle.com/fiddles

This is also where I'm at with the motor run, though I know there's an issue somewhere as its starting with off 3s > on 3s > etc x3 rather than on 3s > off 3s > etc x3 after the button push.
https://www.plcfiddle.com/fiddles


I think I'm starting to get there!
 
This website has been incredibly handy, thanks!

Absolutely correct, I changed this to T2.Q and that has sorted that one out

Putting them this way has definitely eased the headache

Once again 100% correct.

Looks like I had been over complicating a lot, but the relief I felt when it all started to click into place I can't even explain.
Here's what I ended up with for the 1st stage of light sequence:
https://www.plcfiddle.com/fiddles

This is also where I'm at with the motor run, though I know there's an issue somewhere as its starting with off 3s > on 3s > etc x3 rather than on 3s > off 3s > etc x3 after the button push.
https://www.plcfiddle.com/fiddles


I think I'm starting to get there!
1787069853824.png

Being Thorough will go a long way in making sure something works consistently.
I'm not familiar with the plc fiddle website, but I only added L2 to the Outputs to make sure they only run when they need to since it says they Flash in the R-G-R-G order and stop after 5 times.
I can't seem to add any new rungs to this, but the only thing you are missing Is the Green Light Flashing on but not the full 1 Second.

Easiest Solution is replace the CTU2.Q that unlatches L2, with another BOOL.
Use your Timer and Counter Bits in series to activate that Bool to Unlatch L2. Pretty Much a "SequenceDone" Bit.
 
This is also where I'm at with the motor run, though I know there's an issue somewhere as its starting with off 3s > on 3s > etc x3 rather than on 3s > off 3s > etc x3 after the button push.

Relay ladder logic is a syntax for creating expressions in Boolean Algebra that are evaluated, with updated input proxies in memory, once per scan cycle.

Boolean Algebra has only three operations:

AND - ladder logic "expressions" in series on a rung or branch

OR - ladder logic expressions on parallel branches

NOT - the -]/[- instruction

Almost everyone picks up AND and OR pretty quickly; beginners become competent novices when they grok the power of NOT; if your logic is inverted, there's a simple solution! Figure out why later.

Also, the permanent solution involves learning De Morgan's Laws (search for the wiki).

That's the ball game.
 

Similar Topics

Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
13
Replies
1,840
Views
Working on project will update after it is completed.
2
Replies
864
Views
Can someone help me piece this problem together. I have a lot of it down I think but cannot seem to get it right. Probably an easy one for most on...
1
Replies
1,449
Views
Hi everyone, I'm working on a project that involves using a Keyence LR-X100 sensor in Studio 5000 V35 ladder logic to determine the object's...
4
Replies
1,887
Views
Hey. I am new to PLCs and LogixPro. A friend and I have been trying to build this diagram and instructions using LogixPro500. Could anyone help us...
15
Replies
3,821
Views
Top