Spaghetti code

The Plc Kid

Member
Join Date
Feb 2009
Location
Macon, Georgia
Posts
3,233
Can anyone offer some help with this spaghetti code?

I am trying to remove bits B3:5/0,1,2 from this logic and I am in dire straits

I can’t seem to understand the high level logic and why the selector switches fro each bin in parallel with the high level switch.

Secondly I need to have the mezz tvalves open with the sequencer and they currently are open now only one at a time with the bits that I need to remove I need the mezz valve to turn on the same time as the corresponding bin valve does but I need the previously opened valve to stay open for about 2 seconds after the active valve from the sequence fires or it will not physically open due to the high amount of vacuum.

Can anyone help me make sense of this? This is my first program of this complexity and the indirect addressing is not helping me much either.

The attached file is the ladder code.rss file just changed the extension to .txt
 
Can you point out specific Files and Rungs that you need help interpreting? There are multiple stations with multiple high level switches. They seem relatively straight forward but I am not sure about which in particular you are talking about.
 
One thing stands out to me right away, and that's the fact that the Old high level logic and the New high level logic both exist in the program, including duplicate coils (B3:4/6, B3:4/7).
That's a good way to make sure that neither high level logic rung works.
 
You can also go to

View --> Properties
Click on the Address Display tab
Check "Display Value for Indirect Address"

This might make it easier if you are online with the controller to see what he indirect is pointing to. But I would not recommend it if the are actively looping though addresses, since it is always changing and it is not guaranteed that the value you are looking at is what is being used for that particular place in the logic.
 
Sorry guys

I am only working and concerned with ladder 4-station 2.

The 2 sets of logic is my new logic and old logic i have the new block with an always off bit. the old logic is in rung 5 .

Also there is a high level pointer that i do not understand what it is doing.

This is my first stab at anything with indirect addressing plus the code is a mess IMO.

I don't understand the point of the silo select switch being in parallel with the high level switch.
 
Sorry guys

I am only working and concerned with ladder 4-station 2.

The 2 sets of logic is my new logic and old logic i have the new block with an always off bit. the old logic is in rung 5 .
.


The always off bit will not prevent the second OTE from overwriting the status of the first.

To quote Alaric (from another active thread):
An OTE evaluates as
IF RUNG IS TRUE THEN SET OUT TO TRUE ELSE SET OUT TO FALSE

AN OTL evauates as
IF RUNG IS TRUE THEN SET OUT TO TRUE

An OTU evaluates as
IF RUNG IS TRUE THEN SET OUT TO FALSE

So the instruction OTL and OTU will leave the address value as is if the rung is false, but OTE will always write some value to the address.
 
The always off bit will not prevent the second OTE from overwriting the status of the first.

To quote Alaric (from another active thread):

Correct me if I am wrong, but I was always of the impression that the last OTE executed "wins." That is, if in one scan the program encounters two OTEs with the same address, and the first one is TRUE, and the second is FALSE, the FALSE is effectively retained at the end of the scan (and vice versa).

Regardless, having two OTEs using the same address is bad practice. You should have the "old" OTEs use a dummy (unused) variable, this way you don't have to remove the old code if you don't want to.
 
I thought the last output state wins also? Have i been Trained wrong all this time ?

Also i have the always off bit in my new logic so that it is not used as it is not complete.

I might add all of this i am having to do online because the other parts of this system can't be shut down.

I can remove all my new logic if need be?
 
Most of the time you can make online rung edits and not have to shut anything down.

After you accept and verify edits, you Test them, then Assemble (there is an edit toolbar at the top of the ladder window).

Let me stress though that you really should not use the same OTE more than once. Even if "the last one wins" you can still get flaky behavior in the program, especially if someone down to road decides to reactivate the old (intentionally or unintentionally) code without removing the new code first. As I said, it is considered bad practice.

It is easy enough to edit the address of the "old" OTEs to some other address that you are not using. Just double click the address and put in the new one.

Better yet, just delete the old code, just save the program and archive it prior to doing so, so that you have a copy of the old code for reference.
 
Well my plan was to delete the old code when i have the new code in place and working.

I never had any intention of leaving the old stuff in there.

I am trying to get this program working but i also want to clean it up and simplify it if possible.
 
Well my plan was to delete the old code when i have the new code in place and working.

I never had any intention of leaving the old stuff in there.

I am trying to get this program working but i also want to clean it up and simplify it if possible.


You are correct that the last one will win when you have multiple coils. It is a bad practice though.

In your case, with your "Never On" bit on all of the new High level logic (after the old high level logic), those high level bits will (effectively) always be off.

It looks to me that if someone puts that pump station into auto fill for any of the four bins, the vacuum pump will never stop because the shutdown timer (T4:10) relies on the high level bit to start the pump shutdown cycle.
 
Last edited:

Similar Topics

Is it just me or is this the worst hack-job you have ever seen? I tend to believe that Fanuc PalletTool is sort of a turd, but if you R.T.M...
Replies
10
Views
5,439
hello, I'm a student and for my final grade I have to repare a sepro robot. the only problem I have for now is that i have an error code 3...
Replies
0
Views
34
I received an email from a student with the following code attached. This is supposed to control a floodgate system, and supposed to be written...
Replies
23
Views
778
I have a machine which is undergoing upgradation. As part of the process two SEW drives are being replaced., existing Gen B with new Gen C. The...
Replies
3
Views
192
I want to set user security level based on the value of a tag in my PLC called "ActiveUser". That tag will contain the A-P code which we use for...
Replies
6
Views
207
Back
Top Bottom